|  | @ -27,6 +27,7 @@ import com.yihu.jw.entity.base.im.ConsultDo;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.im.ConsultTeamDo;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.org.BaseOrgDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.patient.BasePatientDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.care.assistance.EmergencyAssistanceDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.care.contacts.PatientSosContactsDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.care.device.*;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.care.securitymonitoring.*;
 | 
	
	
		
			
				|  | @ -135,6 +136,8 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
	
		
			
				|  |  |     private DoctorServicePermissionsService doctorServicePermissionsService;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BaseOrgDao orgDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private DeviceDetailDao deviceDetailDao;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     private Logger logger = LoggerFactory.getLogger(SecurityMonitoringOrderService.class);
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -162,6 +165,18 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
	
		
			
				|  |  |             logger.error(failMsg);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         //V1.4 同一类型的安防工单 距离上次发起小于6小时不可重复发起
 | 
	
		
			
				|  |  |         String sql = " select count(id) from base_security_monitoring_order where `status`=1  " +
 | 
	
		
			
				|  |  |                 "  and TIMESTAMPDIFF(HOUR,create_time,NOW())<=6 " +
 | 
	
		
			
				|  |  |                 " and patient='"+orderDO.getPatient()+"' and serve_desc ='"+orderDO.getServeDesc()+"' ";
 | 
	
		
			
				|  |  |         Integer count = jdbcTemplate.queryForObject(sql,Integer.class);
 | 
	
		
			
				|  |  |         if (count>0){
 | 
	
		
			
				|  |  |             result.put("resultFlag", 0);
 | 
	
		
			
				|  |  |             String failMsg = "居民六小时内已存在该预警类型工单,无法重复发起";
 | 
	
		
			
				|  |  |             result.put("resultMsg", failMsg);
 | 
	
		
			
				|  |  |             logger.error(failMsg);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         orderDO.setStatus(1);
 | 
	
		
			
				|  |  |         orderDO.setNumber(getRandomIntStr());
 | 
	
	
		
			
				|  | @ -189,7 +204,7 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //签约防走失服务包
 | 
	
		
			
				|  |  |         String sql ="SELECT i.code,r.team_code,pack.org_code,pack.org_name from base_service_package_sign_record sr,base_service_package_record r, base_service_package_item i,base_service_package pack    \n" +
 | 
	
		
			
				|  |  |         sql ="SELECT i.code,r.team_code,pack.org_code,pack.org_name from base_service_package_sign_record sr,base_service_package_record r, base_service_package_item i,base_service_package pack    \n" +
 | 
	
		
			
				|  |  |                 "where  sr.id = r.sign_id and sr.status=1 and r.service_package_id = i.service_package_id and r.service_package_id = pack.id  and i.del = 1 and sr.`status`=1 \n" +
 | 
	
		
			
				|  |  |                 "and  sr.patient  = '"+orderDO.getPatient()+"' and i.code='preventLost' ";
 | 
	
		
			
				|  |  |         List<Map<String,Object>> items = jdbcTemplate.queryForList(sql);
 | 
	
	
		
			
				|  | @ -239,6 +254,8 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         //推送socket给医生  推送紧急预警
 | 
	
		
			
				|  |  |         JSONObject message = new JSONObject();
 | 
	
		
			
				|  |  |         String latLon = orderDO.getServeLat()+","+orderDO.getServeLon();
 | 
	
		
			
				|  |  |         message.put("latLon",latLon);
 | 
	
		
			
				|  |  |         message.put("session_id",sessionId);
 | 
	
		
			
				|  |  |         message.put("sender_name",orderDO.getPatientName());
 | 
	
		
			
				|  |  |         message.put("content_notice",orderDO.getPatientName()+" "+warnStr+"!");
 | 
	
	
		
			
				|  | @ -247,6 +264,28 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
	
		
			
				|  |  |         message.put("OrderStatus","new");
 | 
	
		
			
				|  |  |         message.put("order_id",orderDO.getId());
 | 
	
		
			
				|  |  |         message.put("content_type",40);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         message.put("serverDesc",orderDO.getServeDesc());
 | 
	
		
			
				|  |  |         message.put("categoryCode","");
 | 
	
		
			
				|  |  |         message.put("orgType","");
 | 
	
		
			
				|  |  |         message.put("contactStatus","");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if (null!=orderDO.getDeviceSn()){
 | 
	
		
			
				|  |  |             String device_sn = orderDO.getDeviceSn();
 | 
	
		
			
				|  |  |             if (org.apache.commons.lang.StringUtils.isNotBlank(device_sn)){
 | 
	
		
			
				|  |  |                 DeviceDetail deviceDetail = deviceDetailDao.findBySn(device_sn);
 | 
	
		
			
				|  |  |                 if (null!=deviceDetail){
 | 
	
		
			
				|  |  |                     message.put("contactStatus",deviceDetail.getContactStatus());
 | 
	
		
			
				|  |  |                     message.put("categoryCode",deviceDetail.getCategoryCode());
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         String orgCode = orderDO.getHospital();
 | 
	
		
			
				|  |  |         BaseOrgDO orgDO = orgDao.findByCode(orgCode);
 | 
	
		
			
				|  |  |         if (null!=orgDO){
 | 
	
		
			
				|  |  |             message.put("orgType",orgDO.getType());
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         for (BaseDoctorDO doctorDO:doctorDOS){
 | 
	
		
			
				|  |  |             try {
 | 
	
		
			
				|  |  |                 if (StringUtils.isNotBlank(doctorDO.getMobile())){
 | 
	
	
		
			
				|  | @ -326,6 +365,10 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
	
		
			
				|  |  |         for (BaseEmergencyWarnLogDO tmp:logDOS){
 | 
	
		
			
				|  |  |             tmp.setTimeInfo(DateUtil.getDifferentTimeInfo(new Date(),tmp.getCreateTime(),0));
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (logDOS.size()==0&&1==emergencyOrderVO.getStatus()){//未响应
 | 
	
		
			
				|  |  |             emergencyOrderVO.setOverTimeNotResponse(DateUtil.getDifferentTimeInfo1(new Date(),orderDO.getCreateTime()));
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         emergencyOrderVO.setOrderLogInfo(logDOS);
 | 
	
		
			
				|  |  |         List<PatientSosContactsDO> contactsDOS = contactsService.getPatientSosContacts(orderDO.getPatient());
 | 
	
		
			
				|  |  |         emergencyOrderVO.setSosContacts(contactsDOS);
 | 
	
	
		
			
				|  | @ -370,24 +413,25 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
	
		
			
				|  |  |             map.put("inFenceName","疑似超出安全区域");
 | 
	
		
			
				|  |  |             emergencyOrderVO.setInformation(map);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if(4==orderDO.getOrderSource()){//报警器
 | 
	
		
			
				|  |  |         if(4==orderDO.getOrderSource()){//监控器
 | 
	
		
			
				|  |  |             List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByUserAndCategoryCode(orderDO.getPatient(),"12");
 | 
	
		
			
				|  |  |             if (devicePatientDeviceDos.size()==0){
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             try {
 | 
	
		
			
				|  |  |                 JSONObject monitorUrl = ysDeviceServicel.getDeviceLiveAddress(orderDO.getPatient(),devicePatientDeviceDos.get(0).getDeviceSn(),1,null);
 | 
	
		
			
				|  |  |                 Map<String,Object> map = new HashMap<>();
 | 
	
		
			
				|  |  |                 map.put("monitorInfoStatus",monitorUrl.getIntValue(ResponseContant.resultFlag));
 | 
	
		
			
				|  |  |                 map.put("patientAddress",devicePatientDeviceDos.get(0).getSosAddress());
 | 
	
		
			
				|  |  |                 if (monitorUrl.getIntValue(ResponseContant.resultFlag) == ResponseContant.fail){
 | 
	
		
			
				|  |  |                     map.put("monitorInfo",monitorUrl.getString(ResponseContant.resultMsg));
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 else {
 | 
	
		
			
				|  |  |                     map.put("monitorInfo",monitorUrl.getJSONObject(ResponseContant.resultMsg));
 | 
	
		
			
				|  |  |             }else {
 | 
	
		
			
				|  |  |                 try {
 | 
	
		
			
				|  |  |                     JSONObject monitorUrl = ysDeviceServicel.getDeviceLiveAddress(orderDO.getPatient(),devicePatientDeviceDos.get(0).getDeviceSn(),1,null);
 | 
	
		
			
				|  |  |                     Map<String,Object> map = new HashMap<>();
 | 
	
		
			
				|  |  |                     map.put("monitorInfoStatus",monitorUrl.getIntValue(ResponseContant.resultFlag));
 | 
	
		
			
				|  |  |                     map.put("patientAddress",devicePatientDeviceDos.get(0).getSosAddress());
 | 
	
		
			
				|  |  |                     if (monitorUrl.getIntValue(ResponseContant.resultFlag) == ResponseContant.fail){
 | 
	
		
			
				|  |  |                         map.put("monitorInfo",monitorUrl.getString(ResponseContant.resultMsg));
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                     else {
 | 
	
		
			
				|  |  |                         map.put("monitorInfo",monitorUrl.getJSONObject(ResponseContant.resultMsg));
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                     emergencyOrderVO.setInformation(map);
 | 
	
		
			
				|  |  |                 }catch (Exception e){
 | 
	
		
			
				|  |  |                     e.printStackTrace();
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 emergencyOrderVO.setInformation(map);
 | 
	
		
			
				|  |  |             }catch (Exception e){
 | 
	
		
			
				|  |  |                 e.printStackTrace();
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (5==orderDO.getOrderSource()){//睡眠带工单
 | 
	
	
		
			
				|  | @ -574,6 +618,8 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //完成工单向pc管理端发送消息
 | 
	
		
			
				|  |  |         JSONObject message = new JSONObject();
 | 
	
		
			
				|  |  |         String latLon = orderDO.getServeLat()+","+orderDO.getServeLon();
 | 
	
		
			
				|  |  |         message.put("latLon",latLon);
 | 
	
		
			
				|  |  |         message.put("session_id",orderDO.getSessionId());
 | 
	
		
			
				|  |  |         message.put("sender_name",orderDO.getPatientName());
 | 
	
		
			
				|  |  |         message.put("content_notice","完成安防服务工单");
 | 
	
	
		
			
				|  | @ -583,6 +629,27 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
	
		
			
				|  |  |         message.put("order_id",orderDO.getId());
 | 
	
		
			
				|  |  |         message.put("content_type",40);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         message.put("serverDesc",orderDO.getServeDesc());
 | 
	
		
			
				|  |  |         message.put("categoryCode","");
 | 
	
		
			
				|  |  |         message.put("orgType","");
 | 
	
		
			
				|  |  |         message.put("contactStatus","");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if (null!=orderDO.getDeviceSn()){
 | 
	
		
			
				|  |  |             String device_sn = orderDO.getDeviceSn();
 | 
	
		
			
				|  |  |             if (org.apache.commons.lang.StringUtils.isNotBlank(device_sn)){
 | 
	
		
			
				|  |  |                 DeviceDetail deviceDetail = deviceDetailDao.findBySn(device_sn);
 | 
	
		
			
				|  |  |                 if (null!=deviceDetail){
 | 
	
		
			
				|  |  |                     message.put("contactStatus",deviceDetail.getContactStatus());
 | 
	
		
			
				|  |  |                     message.put("categoryCode",deviceDetail.getCategoryCode());
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         String orgCode = orderDO.getHospital();
 | 
	
		
			
				|  |  |         BaseOrgDO orgDO = orgDao.findByCode(orgCode);
 | 
	
		
			
				|  |  |         if (null!=orgDO){
 | 
	
		
			
				|  |  |             message.put("orgType",orgDO.getType());
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         imUtil.sendPcManageMessageToPc("cloudCare_pcManage",message.toString());
 | 
	
		
			
				|  |  |         result = getSecurityOrderDetail(orderId,null);
 | 
	
		
			
				|  |  |         return result;
 | 
	
	
		
			
				|  | @ -976,6 +1043,8 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //完成工单向pc管理端发送消息
 | 
	
		
			
				|  |  |         JSONObject message = new JSONObject();
 | 
	
		
			
				|  |  |         String latLon = orderDO.getServeLat()+","+orderDO.getServeLon();
 | 
	
		
			
				|  |  |         message.put("latLon",latLon);
 | 
	
		
			
				|  |  |         message.put("session_id",orderDO.getSessionId());
 | 
	
		
			
				|  |  |         message.put("sender_name",orderDO.getPatientName());
 | 
	
		
			
				|  |  |         message.put("content_notice","完成安防服务工单");
 | 
	
	
		
			
				|  | @ -985,6 +1054,27 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
	
		
			
				|  |  |         message.put("order_id",orderDO.getId());
 | 
	
		
			
				|  |  |         message.put("content_type",40);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         message.put("serverDesc",orderDO.getServeDesc());
 | 
	
		
			
				|  |  |         message.put("categoryCode","");
 | 
	
		
			
				|  |  |         message.put("orgType","");
 | 
	
		
			
				|  |  |         message.put("contactStatus","");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if (null!=orderDO.getDeviceSn()){
 | 
	
		
			
				|  |  |             String device_sn = orderDO.getDeviceSn();
 | 
	
		
			
				|  |  |             if (org.apache.commons.lang.StringUtils.isNotBlank(device_sn)){
 | 
	
		
			
				|  |  |                 DeviceDetail deviceDetail = deviceDetailDao.findBySn(device_sn);
 | 
	
		
			
				|  |  |                 if (null!=deviceDetail){
 | 
	
		
			
				|  |  |                     message.put("contactStatus",deviceDetail.getContactStatus());
 | 
	
		
			
				|  |  |                     message.put("categoryCode",deviceDetail.getCategoryCode());
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         String orgCode = orderDO.getHospital();
 | 
	
		
			
				|  |  |         BaseOrgDO orgDO = orgDao.findByCode(orgCode);
 | 
	
		
			
				|  |  |         if (null!=orgDO){
 | 
	
		
			
				|  |  |             message.put("orgType",orgDO.getType());
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         imUtil.sendPcManageMessageToPc("cloudCare_pcManage",message.toString());
 | 
	
		
			
				|  |  | //        Consult consult = consultDao.queryByRelationCode(orderId);
 | 
	
		
			
				|  |  | //        // 发送微信模板消息,通知居民工单已取消(smyyyqx-上门预约已取消)
 | 
	
	
		
			
				|  | @ -1121,6 +1211,8 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //完成工单向pc管理端发送消息
 | 
	
		
			
				|  |  |         JSONObject message = new JSONObject();
 | 
	
		
			
				|  |  |         String latLon = one.getServeLat()+","+one.getServeLon();
 | 
	
		
			
				|  |  |         message.put("latLon",latLon);
 | 
	
		
			
				|  |  |         message.put("session_id",one.getSessionId());
 | 
	
		
			
				|  |  |         message.put("sender_name",one.getPatientName());
 | 
	
		
			
				|  |  |         message.put("content_notice","完成安防服务工单");
 | 
	
	
		
			
				|  | @ -1130,6 +1222,27 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
	
		
			
				|  |  |         message.put("order_id",one.getId());
 | 
	
		
			
				|  |  |         message.put("content_type",40);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         message.put("serverDesc",one.getServeDesc());
 | 
	
		
			
				|  |  |         message.put("categoryCode","");
 | 
	
		
			
				|  |  |         message.put("orgType","");
 | 
	
		
			
				|  |  |         message.put("contactStatus","");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if (null!=one.getDeviceSn()){
 | 
	
		
			
				|  |  |             String device_sn = one.getDeviceSn();
 | 
	
		
			
				|  |  |             if (org.apache.commons.lang.StringUtils.isNotBlank(device_sn)){
 | 
	
		
			
				|  |  |                 DeviceDetail deviceDetail = deviceDetailDao.findBySn(device_sn);
 | 
	
		
			
				|  |  |                 if (null!=deviceDetail){
 | 
	
		
			
				|  |  |                     message.put("contactStatus",deviceDetail.getContactStatus());
 | 
	
		
			
				|  |  |                     message.put("categoryCode",deviceDetail.getCategoryCode());
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         String orgCode = one.getHospital();
 | 
	
		
			
				|  |  |         BaseOrgDO orgDO = orgDao.findByCode(orgCode);
 | 
	
		
			
				|  |  |         if (null!=orgDO){
 | 
	
		
			
				|  |  |             message.put("orgType",orgDO.getType());
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         imUtil.sendPcManageMessageToPc("cloudCare_pcManage",message.toString());
 | 
	
		
			
				|  |  |         return getSecurityOrderDetail(orderId,null);
 | 
	
		
			
				|  |  |     }
 | 
	
	
		
			
				|  | @ -1285,6 +1398,7 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
	
		
			
				|  |  |         result.put("fall",null);
 | 
	
		
			
				|  |  |         result.put("sleep",null);
 | 
	
		
			
				|  |  |         result.put("deviceSn",null);
 | 
	
		
			
				|  |  |         result.put("emeAssistance",false);
 | 
	
		
			
				|  |  |         result.put("monitorInfo",null);
 | 
	
		
			
				|  |  |         String sql = " select dict.code,count(ord.id) total from base_system_dict_entry dict LEFT JOIN base_security_monitoring_order ord " +
 | 
	
		
			
				|  |  |                 " on dict.code = ord.topic_item COLLATE utf8_unicode_ci and ord.status="+SecurityMonitoringOrderDO.Status.apply.getType()+" where dict.dict_code='service_item' " +
 | 
	
	
		
			
				|  | @ -1326,6 +1440,11 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
	
		
			
				|  |  |                     break;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         sql = " select count(id) from base_emergency_assistance_order  where patient='"+patient+"' and status="+ EmergencyAssistanceDO.Status.apply.getType();
 | 
	
		
			
				|  |  |         Integer counnt = jdbcTemplate.queryForObject(sql,Integer.class);
 | 
	
		
			
				|  |  |         if (counnt>0){
 | 
	
		
			
				|  |  |             result.put("emeAssistance",true);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         result = patientSignTopicInfo(result,patient,topicItem,null);
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 |