|  | @ -240,9 +240,10 @@ public class SignPatientLabelInfoService extends BaseService {
 | 
	
		
			
				|  |  |      * @param labelType 标签类型
 | 
	
		
			
				|  |  |      * @param page      第几页
 | 
	
		
			
				|  |  |      * @param pagesize  页大小
 | 
	
		
			
				|  |  |      * @param sortByStandardStatus
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public JSONArray getPatientByLabel(String doctor, String labelCode, String labelType, Long teamCode, int page, int pagesize) throws Exception {
 | 
	
		
			
				|  |  |     public JSONArray getPatientByLabel(String doctor, String labelCode, String labelType, Long teamCode, int page, int pagesize, boolean sortByStandardStatus) throws Exception {
 | 
	
		
			
				|  |  |         Doctor doc = doctorDao.findByCode(doctor);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if (doc == null) {
 | 
	
	
		
			
				|  | @ -251,6 +252,8 @@ public class SignPatientLabelInfoService extends BaseService {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         Map<String, JSONObject> result = new TreeMap<>();
 | 
	
		
			
				|  |  |         List<Map<String, Object>> signList = new ArrayList<>();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         Map<String,Object> patientDeviceTypeMap = new HashMap<>();//用于存储患者设备绑定情况
 | 
	
		
			
				|  |  |         int start = page * pagesize;
 | 
	
		
			
				|  |  |         String sql = "";
 | 
	
		
			
				|  |  |         Object[] args = null;
 | 
	
	
		
			
				|  | @ -349,6 +352,12 @@ public class SignPatientLabelInfoService extends BaseService {
 | 
	
		
			
				|  |  |         sql += " limit " + start + "," + pagesize;
 | 
	
		
			
				|  |  |         signList = jdbcTemplate.queryForList(sql, args);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //查询患者设备绑定情况
 | 
	
		
			
				|  |  |         if(sortByStandardStatus){
 | 
	
		
			
				|  |  |             String _pdsql = "SELECT p.code,(SELECT sum(d.category_code)  from wlyy_patient_device d WHERE p.code = d.`user`) device from wlyy_patient p";
 | 
	
		
			
				|  |  |             patientDeviceTypeMap = jdbcTemplate.queryForMap(_pdsql);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if (signList != null && signList.size() > 0) {
 | 
	
		
			
				|  |  |             for (Map<String, Object> sign : signList) {
 | 
	
		
			
				|  |  |                 Patient p = patientDao.findByCode(sign.get("patient") == null ? "" : sign.get("patient").toString());
 | 
	
	
		
			
				|  | @ -454,6 +463,20 @@ public class SignPatientLabelInfoService extends BaseService {
 | 
	
		
			
				|  |  |                     // 缴费情况
 | 
	
		
			
				|  |  |                     json.put("expensesStatus", "1");
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 //病情类型:0健康,1高血压,2糖尿病,3高血压+糖尿病
 | 
	
		
			
				|  |  |                 json.put("disease",p.getDisease());
 | 
	
		
			
				|  |  |                 // 病情:0绿标,1黄标,2红标,
 | 
	
		
			
				|  |  |                 json.put("diseaseCondition",p.getDiseaseCondition());
 | 
	
		
			
				|  |  |                 //预警状态
 | 
	
		
			
				|  |  |                 json.put("standardStatus",p.getStandardStatus());
 | 
	
		
			
				|  |  |                 //设备状态:0未绑定,1血糖仪,2血压仪,3血糖仪+血压仪
 | 
	
		
			
				|  |  |                 Integer deviceType = 0;
 | 
	
		
			
				|  |  |                 if(!patientDeviceTypeMap.isEmpty() && patientDeviceTypeMap.keySet().contains(p.getCode())){
 | 
	
		
			
				|  |  |                     deviceType = (Integer) patientDeviceTypeMap.get(p.getCode());
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 json.put("deviceType",deviceType);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 boolean epTime = false;
 | 
	
		
			
				|  |  |                 try {
 | 
	
		
			
				|  |  |                     epTime = redisTemplate.opsForSet().isMember("wechat:focus:remind:set", p.getCode());
 | 
	
	
		
			
				|  | @ -480,7 +503,24 @@ public class SignPatientLabelInfoService extends BaseService {
 | 
	
		
			
				|  |  |                 public int compare(JSONObject o1, JSONObject o2) {
 | 
	
		
			
				|  |  |                     String openid1 = o1.has("openid") ? o1.getString("openid") : "";
 | 
	
		
			
				|  |  |                     String openid2 = o2.has("openid") ? o2.getString("openid") : "";
 | 
	
		
			
				|  |  |                     int re = openid1.compareTo(openid2);
 | 
	
		
			
				|  |  |                     int re = 0;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     //是否根据预警字段优先排序
 | 
	
		
			
				|  |  |                     if(sortByStandardStatus){
 | 
	
		
			
				|  |  |                         int standardStatus1 = o1.has("standardStatus")?o1.getInt("standardStatus"):0;
 | 
	
		
			
				|  |  |                         int standardStatus2 = o2.has("standardStatus")?o2.getInt("standardStatus"):0;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                         if(standardStatus1 == standardStatus2){
 | 
	
		
			
				|  |  |                             re = openid1.compareTo(openid2);
 | 
	
		
			
				|  |  |                         }else{
 | 
	
		
			
				|  |  |                             re = standardStatus1 - standardStatus1;
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     }else{
 | 
	
		
			
				|  |  |                         re = openid1.compareTo(openid2);
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     if (re > 0) {
 | 
	
		
			
				|  |  |                         return -1;
 | 
	
		
			
				|  |  |                     } else if (re < 0) {
 | 
	
	
		
			
				|  | @ -3511,13 +3551,15 @@ public class SignPatientLabelInfoService extends BaseService {
 | 
	
		
			
				|  |  |      * @param teamCode
 | 
	
		
			
				|  |  |      * @param page
 | 
	
		
			
				|  |  |      * @param pagesize
 | 
	
		
			
				|  |  |      * @param sortByStandardStatus 是否根据预警状态排序,如果true, 需要附带查询患者设备绑定情况
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      * @throws Exception
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public JSONArray getPatientByTeamCodeExitDoctor(long teamCode, String labelCode, String labelType, int page, int pagesize) throws Exception {
 | 
	
		
			
				|  |  |     public JSONArray getPatientByTeamCodeExitDoctor(long teamCode, String labelCode, String labelType, int page, int pagesize, boolean sortByStandardStatus) throws Exception {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         Map<String, JSONObject> result = new TreeMap<>();
 | 
	
		
			
				|  |  |         List<Map<String, Object>> signList = new ArrayList<>();
 | 
	
		
			
				|  |  |         Map<String,Object> patientDeviceTypeMap = new HashMap<>();//用于存储患者设备绑定情况
 | 
	
		
			
				|  |  |         int start = page * pagesize;
 | 
	
		
			
				|  |  |         String sql = "";
 | 
	
		
			
				|  |  |         Object[] args = null;
 | 
	
	
		
			
				|  | @ -3621,6 +3663,13 @@ public class SignPatientLabelInfoService extends BaseService {
 | 
	
		
			
				|  |  |         sql = sql + " limit " + start + "," + pagesize;
 | 
	
		
			
				|  |  |         signList = jdbcTemplate.queryForList(sql, args);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //查询患者设备绑定情况
 | 
	
		
			
				|  |  |         if(sortByStandardStatus){
 | 
	
		
			
				|  |  |             String _pdsql = "SELECT p.code,(SELECT sum(d.category_code)  from wlyy_patient_device d WHERE p.code = d.`user`) device from wlyy_patient p";
 | 
	
		
			
				|  |  |             patientDeviceTypeMap = jdbcTemplate.queryForMap(_pdsql);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if (signList != null && signList.size() > 0) {
 | 
	
		
			
				|  |  |             for (Map<String, Object> sign : signList) {
 | 
	
		
			
				|  |  |                 Patient p = patientDao.findByCode(sign.get("patient") == null ? "" : sign.get("patient").toString());
 | 
	
	
		
			
				|  | @ -3629,49 +3678,49 @@ public class SignPatientLabelInfoService extends BaseService {
 | 
	
		
			
				|  |  |                     continue;
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 if (result.containsKey(p.getCode())) {
 | 
	
		
			
				|  |  |                     JSONObject jsonP = result.get(p.getCode());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     if (!String.valueOf(jsonP.get("signType")).equals(String.valueOf(sign.get("type")))) {
 | 
	
		
			
				|  |  |                         jsonP.put("signType", 3);
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                     if (String.valueOf(sign.get("type")).equals("2")) {
 | 
	
		
			
				|  |  |                         jsonP.put("qyrq", sign.get("apply_date") != null ? DateUtil.dateToStr((Date) sign.get("apply_date"), DateUtil.YYYY_MM_DD) : "");
 | 
	
		
			
				|  |  |                         // 缴费情况
 | 
	
		
			
				|  |  |                         jsonP.put("expensesStatus", sign.get("expenses_status") != null ? String.valueOf(sign.get("expenses_status")) : "0");
 | 
	
		
			
				|  |  |                         // 缴费时间
 | 
	
		
			
				|  |  |                         jsonP.put("expensesTime", sign.get("expenses_time") != null ? DateUtil.dateToStr((Date) sign.get("expenses_time"), DateUtil.YYYY_MM_DD_HH_MM) : "");
 | 
	
		
			
				|  |  |                         // 缴费类型
 | 
	
		
			
				|  |  |                         jsonP.put("expensesType", sign.get("expenses_type") != null ? String.valueOf(sign.get("expenses_type")) : "");
 | 
	
		
			
				|  |  |                         if (StringUtils.isEmpty(String.valueOf(jsonP.get("expensesStatus"))) || String.valueOf(jsonP.get("expensesStatus")).equals("0")) {
 | 
	
		
			
				|  |  |                             boolean epTime = false;
 | 
	
		
			
				|  |  |                             try {
 | 
	
		
			
				|  |  |                                 epTime = redisTemplate.opsForSet().isMember("expenses:remind:set", p.getCode());
 | 
	
		
			
				|  |  |                             } catch (Exception e) {
 | 
	
		
			
				|  |  |                                 e.printStackTrace();
 | 
	
		
			
				|  |  |                             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                             if (!epTime) {
 | 
	
		
			
				|  |  |                                 jsonP.put("expensesRemindStatus", 0);
 | 
	
		
			
				|  |  |                             } else {
 | 
	
		
			
				|  |  |                                 jsonP.put("expensesRemindStatus", 1);
 | 
	
		
			
				|  |  |                             }
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                         boolean epTime = false;
 | 
	
		
			
				|  |  |                         try {
 | 
	
		
			
				|  |  |                             epTime = redisTemplate.opsForSet().isMember("wechat:focus:remind:set", p.getCode());
 | 
	
		
			
				|  |  |                         } catch (Exception e) {
 | 
	
		
			
				|  |  |                             e.printStackTrace();
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                         if (!epTime) {
 | 
	
		
			
				|  |  |                             jsonP.put("wechatFocusRemind", 0);
 | 
	
		
			
				|  |  |                         } else {
 | 
	
		
			
				|  |  |                             jsonP.put("wechatFocusRemind", 1);
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     continue;
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  | //                if (result.containsKey(p.getCode())) {
 | 
	
		
			
				|  |  | //                    JSONObject jsonP = result.get(p.getCode());
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //                    if (!String.valueOf(jsonP.get("signType")).equals(String.valueOf(sign.get("type")))) {
 | 
	
		
			
				|  |  | //                        jsonP.put("signType", 3);
 | 
	
		
			
				|  |  | //                    }
 | 
	
		
			
				|  |  | //                    if (String.valueOf(sign.get("type")).equals("2")) {
 | 
	
		
			
				|  |  | //                        jsonP.put("qyrq", sign.get("apply_date") != null ? DateUtil.dateToStr((Date) sign.get("apply_date"), DateUtil.YYYY_MM_DD) : "");
 | 
	
		
			
				|  |  | //                        // 缴费情况
 | 
	
		
			
				|  |  | //                        jsonP.put("expensesStatus", sign.get("expenses_status") != null ? String.valueOf(sign.get("expenses_status")) : "0");
 | 
	
		
			
				|  |  | //                        // 缴费时间
 | 
	
		
			
				|  |  | //                        jsonP.put("expensesTime", sign.get("expenses_time") != null ? DateUtil.dateToStr((Date) sign.get("expenses_time"), DateUtil.YYYY_MM_DD_HH_MM) : "");
 | 
	
		
			
				|  |  | //                        // 缴费类型
 | 
	
		
			
				|  |  | //                        jsonP.put("expensesType", sign.get("expenses_type") != null ? String.valueOf(sign.get("expenses_type")) : "");
 | 
	
		
			
				|  |  | //                        if (StringUtils.isEmpty(String.valueOf(jsonP.get("expensesStatus"))) || String.valueOf(jsonP.get("expensesStatus")).equals("0")) {
 | 
	
		
			
				|  |  | //                            boolean epTime = false;
 | 
	
		
			
				|  |  | //                            try {
 | 
	
		
			
				|  |  | //                                epTime = redisTemplate.opsForSet().isMember("expenses:remind:set", p.getCode());
 | 
	
		
			
				|  |  | //                            } catch (Exception e) {
 | 
	
		
			
				|  |  | //                                e.printStackTrace();
 | 
	
		
			
				|  |  | //                            }
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //                            if (!epTime) {
 | 
	
		
			
				|  |  | //                                jsonP.put("expensesRemindStatus", 0);
 | 
	
		
			
				|  |  | //                            } else {
 | 
	
		
			
				|  |  | //                                jsonP.put("expensesRemindStatus", 1);
 | 
	
		
			
				|  |  | //                            }
 | 
	
		
			
				|  |  | //                        }
 | 
	
		
			
				|  |  | //                        boolean epTime = false;
 | 
	
		
			
				|  |  | //                        try {
 | 
	
		
			
				|  |  | //                            epTime = redisTemplate.opsForSet().isMember("wechat:focus:remind:set", p.getCode());
 | 
	
		
			
				|  |  | //                        } catch (Exception e) {
 | 
	
		
			
				|  |  | //                            e.printStackTrace();
 | 
	
		
			
				|  |  | //                        }
 | 
	
		
			
				|  |  | //                        if (!epTime) {
 | 
	
		
			
				|  |  | //                            jsonP.put("wechatFocusRemind", 0);
 | 
	
		
			
				|  |  | //                        } else {
 | 
	
		
			
				|  |  | //                            jsonP.put("wechatFocusRemind", 1);
 | 
	
		
			
				|  |  | //                        }
 | 
	
		
			
				|  |  | //                    }
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //                    continue;
 | 
	
		
			
				|  |  | //                }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 //List<SignPatientLabelInfo> labels = labelInfoDao.findByPatientAndStatus(sign.get("patient").toString(), 1);
 | 
	
		
			
				|  |  |                 JSONObject json = new JSONObject();
 | 
	
	
		
			
				|  | @ -3727,6 +3776,21 @@ public class SignPatientLabelInfoService extends BaseService {
 | 
	
		
			
				|  |  |                     // 缴费情况
 | 
	
		
			
				|  |  |                     json.put("expensesStatus", "1");
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 //病情类型:0健康,1高血压,2糖尿病,3高血压+糖尿病
 | 
	
		
			
				|  |  |                 json.put("disease",p.getDisease());
 | 
	
		
			
				|  |  |                 // 病情:0绿标,1黄标,2红标,
 | 
	
		
			
				|  |  |                 json.put("diseaseCondition",p.getDiseaseCondition());
 | 
	
		
			
				|  |  |                 //预警状态
 | 
	
		
			
				|  |  |                 json.put("standardStatus",p.getStandardStatus());
 | 
	
		
			
				|  |  |                 //设备状态:0未绑定,1血糖仪,2血压仪,3血糖仪+血压仪
 | 
	
		
			
				|  |  |                 Integer deviceType = 0;
 | 
	
		
			
				|  |  |                 if(!patientDeviceTypeMap.isEmpty() && patientDeviceTypeMap.keySet().contains(p.getCode())){
 | 
	
		
			
				|  |  |                     deviceType = (Integer) patientDeviceTypeMap.get(p.getCode());
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 json.put("deviceType",deviceType);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 boolean epTime = false;
 | 
	
		
			
				|  |  |                 try {
 | 
	
		
			
				|  |  |                     epTime = redisTemplate.opsForSet().isMember("wechat:focus:remind:set", p.getCode());
 | 
	
	
		
			
				|  | @ -3753,7 +3817,25 @@ public class SignPatientLabelInfoService extends BaseService {
 | 
	
		
			
				|  |  |                 public int compare(JSONObject o1, JSONObject o2) {
 | 
	
		
			
				|  |  |                     String openid1 = o1.has("openid") ? o1.getString("openid") : "";
 | 
	
		
			
				|  |  |                     String openid2 = o2.has("openid") ? o2.getString("openid") : "";
 | 
	
		
			
				|  |  |                     int re = openid1.compareTo(openid2);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     int re = 0;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     //是否根据预警字段优先排序
 | 
	
		
			
				|  |  |                     if(sortByStandardStatus){
 | 
	
		
			
				|  |  |                         int standardStatus1 = o1.has("standardStatus")?o1.getInt("standardStatus"):0;
 | 
	
		
			
				|  |  |                         int standardStatus2 = o2.has("standardStatus")?o2.getInt("standardStatus"):0;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                         if(standardStatus1 == standardStatus2){
 | 
	
		
			
				|  |  |                             re = openid1.compareTo(openid2);
 | 
	
		
			
				|  |  |                         }else{
 | 
	
		
			
				|  |  |                             re = standardStatus1 - standardStatus1;
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     }else{
 | 
	
		
			
				|  |  |                         re = openid1.compareTo(openid2);
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     if (re > 0) {
 | 
	
		
			
				|  |  |                         return -1;
 | 
	
		
			
				|  |  |                     } else if (re < 0) {
 |