ソースを参照

Merge branch 'dev' of yeshijie/patient-co-management into dev

lyr 8 年 前
コミット
25a76e4256

+ 71 - 21
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/message/MessageService.java

@ -29,10 +29,7 @@ import org.springside.modules.persistence.SearchFilter;
import org.springside.modules.persistence.SearchFilter.Operator;
import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
 * 消息业务处理类
@ -276,38 +273,91 @@ public class MessageService extends BaseService {
     */
    public List<Map<String, Object>> getHealthIndexMessage(String doctor) throws Exception {
        List<Map<String, Object>> re = new ArrayList<>();
        String sql = "select a.sender,a.tz_type,count(1) count,max(date_format(a.create_time,'%Y-%c-%d %H:%i:%s')) last_time from wlyy_Message a where a.receiver='" + doctor + "' and a.has_read='1' and a.type='2' group by a.sender,a.tz_type order by last_time desc";
        String sql = "select a.sender,a.tz_type,count(1) count,max(date_format(a.create_time,'%Y-%c-%d %H:%i:%s')) last_time,a.has_read from wlyy_Message a where a.receiver='" + doctor + "' and a.type='2' group by a.sender,a.tz_type,a.has_read order by last_time desc";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        Map<String,Map<String, Object>> map = new HashMap<>();
        for (Map<String, Object> item : list) {
            Map<String, Object> obj = new HashMap<>();
            Map<String, Object> obj = null;
            String patientCode = String.valueOf(item.get("sender"));
            //获取患者信息
            Patient patient = patientDao.findByCode(patientCode);
            if (patient != null) {
                String type = String.valueOf(item.get("tz_type")); //1血糖,2血压,3体重,4腰
                obj.put("patient", patientCode);
                obj.put("type", type);
                obj.put("time", item.get("last_time"));
                obj.put("name", patient.getName());
                obj.put("sex", patient.getSex());
                obj.put("birthday", DateUtil.dateToStrShort(patient.getBirthday()));
                obj.put("sex", patient.getSex());
                obj.put("photo", patient.getPhoto());
                if ("1".equals(type)) {
                    obj.put("message", "有" + item.get("count") + "条血糖异常未读消息");
                } else if ("2".equals(type)) {
                    obj.put("message", "有" + item.get("count") + "条血压异常未读消息");
                } else {
                    obj.put("message", "暂无未读消息");
                String read = String.valueOf(item.get("has_read")); //0已读,1未读
                String patientType = patientCode + type;
                if(map.containsKey(patientType)){
                    obj = map.get(patientType);
                    if(obj.get("time").toString().compareTo(item.get("last_time").toString())<0){
                        obj.put("time", item.get("last_time"));
                    }
                }else{
                    obj = new HashMap<>();
                    obj.put("patient", patientCode);
                    obj.put("type", type);
                    obj.put("time", item.get("last_time"));
                    obj.put("name", patient.getName());
                    obj.put("sex", patient.getSex());
                    obj.put("birthday", DateUtil.dateToStrShort(patient.getBirthday()));
                    obj.put("photo", patient.getPhoto());
                }
                if("1".equals(read)){
                    obj.put("count1", item.get("count"));
                }else{
                    obj.put("count0", item.get("count"));
                }
                re.add(obj);
                map.put(patientType,obj);
//                if ("1".equals(type)) {
//                    obj.put("message", "有" + item.get("count") + "条血糖异常未读消息");
//                } else if ("2".equals(type)) {
//                    obj.put("message", "有" + item.get("count") + "条血压异常未读消息");
//                } else {
//                    break;
//                }
//                re.add(obj);
            } else {
                System.out.print("not exit patient!code:" + patientCode);
            }
        }
        for (Map<String, Object> item : map.values()) {
            Map<String, Object> obj = new HashMap<>();
            String type = String.valueOf(item.get("type")); //1血糖,2血压,3体重,4腰
            Integer count1 = item.get("count1")==null?0:Integer.parseInt(item.get("count1").toString());
            obj.put("patient", item.get("patient"));
            obj.put("type", type);
            obj.put("time", item.get("time"));
            obj.put("name", item.get("name"));
            obj.put("sex", item.get("sex"));
            obj.put("birthday", item.get("birthday"));
            obj.put("photo", item.get("photo"));
            if ("1".equals(type)) {
                if(count1>0){
                    obj.put("message", "有" + count1 + "条血糖异常未读消息");
                }else{
                    obj.put("message", "暂无血糖未读消息");
                }
            } else if ("2".equals(type)) {
                if(count1>0){
                    obj.put("message", "有" + count1 + "条血压异常未读消息");
                }else{
                    obj.put("message", "暂无血压未读消息");
                }
            } else {
                break;
            }
            re.add(obj);
        }
        Collections.sort(re, new Comparator<Map<String, Object>>() {
            public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                String time1 = o1.get("time").toString();
                String time2 = o2.get("time").toString();
                return time2.compareTo(time1);
            }
        });
        return re;
    }