|  | @ -7,9 +7,14 @@ import com.alibaba.fastjson.serializer.SerializerFeature;
 | 
												
													
														
															|  | import com.fasterxml.jackson.databind.ObjectMapper;
 |  | import com.fasterxml.jackson.databind.ObjectMapper;
 | 
												
													
														
															|  | import com.yihu.jw.care.dao.device.PatientDeviceDao;
 |  | import com.yihu.jw.care.dao.device.PatientDeviceDao;
 | 
												
													
														
															|  | import com.yihu.jw.care.dao.security.*;
 |  | import com.yihu.jw.care.dao.security.*;
 | 
												
													
														
															|  | 
 |  | import com.yihu.jw.care.dao.team.BaseTeamMemberDao;
 | 
												
													
														
															|  | 
 |  | import com.yihu.jw.care.service.consult.ConsultTeamService;
 | 
												
													
														
															|  | import com.yihu.jw.care.service.device.PatientDeviceService;
 |  | import com.yihu.jw.care.service.device.PatientDeviceService;
 | 
												
													
														
															|  | import com.yihu.jw.care.service.sign.ServicePackageService;
 |  | import com.yihu.jw.care.service.sign.ServicePackageService;
 | 
												
													
														
															|  | import com.yihu.jw.care.util.CountDistance;
 |  | import com.yihu.jw.care.util.CountDistance;
 | 
												
													
														
															|  | 
 |  | import com.yihu.jw.entity.base.im.ConsultDo;
 | 
												
													
														
															|  | 
 |  | import com.yihu.jw.im.dao.ConsultDao;
 | 
												
													
														
															|  | 
 |  | import com.yihu.jw.im.util.ImUtil;
 | 
												
													
														
															|  | import com.yihu.jw.util.common.GpsUtil;
 |  | import com.yihu.jw.util.common.GpsUtil;
 | 
												
													
														
															|  | import com.yihu.jw.care.util.MessageUtil;
 |  | import com.yihu.jw.care.util.MessageUtil;
 | 
												
													
														
															|  | import com.yihu.jw.doctor.dao.BaseDoctorDao;
 |  | import com.yihu.jw.doctor.dao.BaseDoctorDao;
 | 
												
											
												
													
														
															|  | @ -74,10 +79,18 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
												
													
														
															|  |     private GpsUtil gpsUtil;
 |  |     private GpsUtil gpsUtil;
 | 
												
													
														
															|  |     @Autowired
 |  |     @Autowired
 | 
												
													
														
															|  |     private CountDistance countDistance;
 |  |     private CountDistance countDistance;
 | 
												
													
														
															|  | 
 |  |     @Autowired
 | 
												
													
														
															|  | 
 |  |     private ConsultTeamService consultTeamService;
 | 
												
													
														
															|  | 
 |  |     @Autowired
 | 
												
													
														
															|  | 
 |  |     private ConsultDao consultDao;
 | 
												
													
														
															|  | 
 |  |     @Autowired
 | 
												
													
														
															|  | 
 |  |     private BaseTeamMemberDao baseTeamMemberDao;
 | 
												
													
														
															|  | 
 |  |     @Autowired
 | 
												
													
														
															|  | 
 |  |     private ImUtil imUtil;
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     private Logger logger = LoggerFactory.getLogger(SecurityMonitoringOrderService.class);
 |  |     private Logger logger = LoggerFactory.getLogger(SecurityMonitoringOrderService.class);
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     public JSONObject createOrder(String jsonData){
 |  | 
 | 
												
													
														
															|  | 
 |  |     public JSONObject createOrder(String jsonData,Integer orderSource) throws Exception {
 | 
												
													
														
															|  |         logger.info("创建安防工单jsonData参数:" + jsonData);
 |  |         logger.info("创建安防工单jsonData参数:" + jsonData);
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |         JSONObject result = new JSONObject();
 |  |         JSONObject result = new JSONObject();
 | 
												
											
												
													
														
															|  | @ -101,12 +114,14 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
												
													
														
															|  |             logger.error(failMsg);
 |  |             logger.error(failMsg);
 | 
												
													
														
															|  |             return result;
 |  |             return result;
 | 
												
													
														
															|  |         }
 |  |         }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |         orderDO.setStatus(1);
 |  |         orderDO.setStatus(1);
 | 
												
													
														
															|  |         orderDO.setNumber(getRandomIntStr());
 |  |         orderDO.setNumber(getRandomIntStr());
 | 
												
													
														
															|  |         orderDO.setCreateTime(new Date());
 |  |         orderDO.setCreateTime(new Date());
 | 
												
													
														
															|  |         orderDO.setCreateUser(orderDO.getCreateUser());
 |  |         orderDO.setCreateUser(orderDO.getCreateUser());
 | 
												
													
														
															|  |         orderDO.setCreateUserName(orderDO.getCreateUserName());
 |  |         orderDO.setCreateUserName(orderDO.getCreateUserName());
 | 
												
													
														
															|  |         orderDO.setOrderInfo("0");
 |  |         orderDO.setOrderInfo("0");
 | 
												
													
														
															|  | 
 |  |         orderDO.setOrderSource(orderSource);
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |         if(StringUtils.isEmpty(orderDO.getPatient())){
 |  |         if(StringUtils.isEmpty(orderDO.getPatient())){
 | 
												
													
														
															|  |             result.put("resultFlag", 0);
 |  |             result.put("resultFlag", 0);
 | 
												
											
												
													
														
															|  | @ -126,10 +141,10 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
												
													
														
															|  |         }
 |  |         }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |         //签约防走失服务包
 |  |         //签约防走失服务包
 | 
												
													
														
															|  |         String sql ="SELECT i.code from base_service_package_sign_record sr,base_service_package_record r, base_service_package_item i  \n" +
 |  | 
 | 
												
													
														
															|  | 
 |  |         String sql ="SELECT i.code,i.team_code,i.org_code,i.org_name from base_service_package_sign_record sr,base_service_package_record r, base_service_package_item i  \n" +
 | 
												
													
														
															|  |                 "where  sr.id = r.sign_id and sr.status=1 and r.service_package_id = i.service_package_id   and i.del = 1 and sr.`status`=1 \n" +
 |  |                 "where  sr.id = r.sign_id and sr.status=1 and r.service_package_id = i.service_package_id   and i.del = 1 and sr.`status`=1 \n" +
 | 
												
													
														
															|  |                 "and  sr.patient  = '"+orderDO.getPatient()+"' and i.code='preventLost' ";
 |  |                 "and  sr.patient  = '"+orderDO.getPatient()+"' and i.code='preventLost' ";
 | 
												
													
														
															|  |        List<String> items = jdbcTemplate.queryForList(sql,String.class);
 |  | 
 | 
												
													
														
															|  | 
 |  |         List<Map<String,Object>> items = jdbcTemplate.queryForList(sql);
 | 
												
													
														
															|  |         if (items.size()==0) {
 |  |         if (items.size()==0) {
 | 
												
													
														
															|  |             result.put("resultFlag", 0);
 |  |             result.put("resultFlag", 0);
 | 
												
													
														
															|  |             String failMsg = "当前服务对象未签约防走失服务,请签约后再发起预警!";
 |  |             String failMsg = "当前服务对象未签约防走失服务,请签约后再发起预警!";
 | 
												
											
												
													
														
															|  | @ -154,11 +169,40 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
												
													
														
															|  |             logger.error(failMsg);
 |  |             logger.error(failMsg);
 | 
												
													
														
															|  |             return result;
 |  |             return result;
 | 
												
													
														
															|  |         }
 |  |         }
 | 
												
													
														
															|  | 
 |  |         Map<String,Object> mapTmp = items.get(0);
 | 
												
													
														
															|  | 
 |  |         List<BaseDoctorDO> doctorDOS = baseTeamMemberDao.findAllMembers(mapTmp.get("team_code").toString());
 | 
												
													
														
															|  | 
 |  |         if (doctorDOS.size()==0){
 | 
												
													
														
															|  | 
 |  |             String failMsg = "安防警报服务项服务医生为空,不可发起救助";
 | 
												
													
														
															|  | 
 |  |             result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
												
													
														
															|  | 
 |  |             result.put(ResponseContant.resultMsg,failMsg);
 | 
												
													
														
															|  | 
 |  |             return result;
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |         orderDO.setCreateTime(new Date());
 |  |         orderDO.setCreateTime(new Date());
 | 
												
													
														
															|  |         //判断创建预警服务类型,发起类型(1本人发起 2家人待预约 3医生代预约)
 |  |         //判断创建预警服务类型,发起类型(1本人发起 2家人待预约 3医生代预约)
 | 
												
													
														
															|  |         orderDO.setType(3);//发起类型
 |  |         orderDO.setType(3);//发起类型
 | 
												
													
														
															|  |         orderDO.setServiceStatus("2");
 |  |         orderDO.setServiceStatus("2");
 | 
												
													
														
															|  |         this.save(orderDO);
 |  |         this.save(orderDO);
 | 
												
													
														
															|  | 
 |  |         //创建im会话  安防警报咨询的sessionid  为居民code+(wlyy_consult_team表consult)+20
 | 
												
													
														
															|  | 
 |  |         JSONObject IMObj = consultTeamService.addSecurityMoConsult(orderDO.getId(),orderDO.getPatient(),null,null);
 | 
												
													
														
															|  | 
 |  |         String sessionId=orderDO.getPatient()+"_"+ IMObj.getJSONObject("resultMsg").getString("consult") + "_22";
 | 
												
													
														
															|  | 
 |  |         //推送socket给医生  推送紧急预警
 | 
												
													
														
															|  | 
 |  |         for (BaseDoctorDO doctorDO:doctorDOS){
 | 
												
													
														
															|  | 
 |  |             JSONObject message = new JSONObject();
 | 
												
													
														
															|  | 
 |  |             message.put("session_id",sessionId);
 | 
												
													
														
															|  | 
 |  |             message.put("sender_name",orderDO.getPatientName());
 | 
												
													
														
															|  | 
 |  |             message.put("content_notice",orderDO.getPatientName()+" 疑似离开安全区域!");
 | 
												
													
														
															|  | 
 |  |             message.put("sender_code",orderDO.getPatient());
 | 
												
													
														
															|  | 
 |  |             message.put("OrderType",22);
 | 
												
													
														
															|  | 
 |  |             message.put("order_id",orderDO.getId());
 | 
												
													
														
															|  | 
 |  |             message.put("content_type",40);
 | 
												
													
														
															|  | 
 |  |             try {
 | 
												
													
														
															|  | 
 |  |                 imUtil.sendMDTSocketMessageToDoctor(doctorDO.getId(),message.toString());
 | 
												
													
														
															|  | 
 |  |             }catch (Exception e){
 | 
												
													
														
															|  | 
 |  |                 e.printStackTrace();
 | 
												
													
														
															|  | 
 |  |             }
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |         result.put("resultFlag", 1);
 |  |         result.put("resultFlag", 1);
 | 
												
													
														
															|  |         result.put("resultMsg",orderDO);
 |  |         result.put("resultMsg",orderDO);
 | 
												
													
														
															|  | 
 |  | 
 | 
												
											
												
													
														
															|  | @ -210,6 +254,15 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
												
													
														
															|  |             jsonObject.put("patientAddress",null);
 |  |             jsonObject.put("patientAddress",null);
 | 
												
													
														
															|  |         }
 |  |         }
 | 
												
													
														
															|  |         jsonObject.put("statusName",statusName);
 |  |         jsonObject.put("statusName",statusName);
 | 
												
													
														
															|  | 
 |  |         //获取咨询
 | 
												
													
														
															|  | 
 |  |         ConsultDo consult = consultDao.queryByRelationCode(orderID);
 | 
												
													
														
															|  | 
 |  |         if (null != consult) {
 | 
												
													
														
															|  | 
 |  |             String sessionId = orderDO.getPatient() + "_" + consult.getId() + "_" + consult.getType();
 | 
												
													
														
															|  | 
 |  |             jsonObject.put("sessionId",sessionId);
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         else {
 | 
												
													
														
															|  | 
 |  |             jsonObject.put("sessionId",null);
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |         result.put("resultFlag", 1);
 |  |         result.put("resultFlag", 1);
 | 
												
													
														
															|  |         result.put("resultMsg",jsonObject);
 |  |         result.put("resultMsg",jsonObject);
 | 
												
											
												
													
														
															|  | @ -536,6 +589,13 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
												
													
														
															|  |             logger.error(failMsg);
 |  |             logger.error(failMsg);
 | 
												
													
														
															|  |             return result;
 |  |             return result;
 | 
												
													
														
															|  |         }
 |  |         }
 | 
												
													
														
															|  | 
 |  |         if (!consultTeamService.finishConsult(orderDO.getId(),orderDO.getPatient(),orderDO.getPatient(),1)){
 | 
												
													
														
															|  | 
 |  |             String failMsg = "咨询结束失败 无法取消工单";
 | 
												
													
														
															|  | 
 |  |             result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
												
													
														
															|  | 
 |  |             result.put(ResponseContant.resultMsg,failMsg);
 | 
												
													
														
															|  | 
 |  |             return result;
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |         orderDO.setDoctor(doctor);
 |  |         orderDO.setDoctor(doctor);
 | 
												
													
														
															|  |         orderDO.setDoctorName(doctorDO.getName());
 |  |         orderDO.setDoctorName(doctorDO.getName());
 | 
												
													
														
															|  |         orderDO.setCancelType(type);
 |  |         orderDO.setCancelType(type);
 | 
												
											
												
													
														
															|  | @ -782,11 +842,17 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
												
													
														
															|  |         one.setCompleteTime(one.getDoctorConfirmFinishTime());
 |  |         one.setCompleteTime(one.getDoctorConfirmFinishTime());
 | 
												
													
														
															|  |         // 更新记录
 |  |         // 更新记录
 | 
												
													
														
															|  |         this.setUpdateColumnInfo(one);
 |  |         this.setUpdateColumnInfo(one);
 | 
												
													
														
															|  | 
 |  |         if (!consultTeamService.finishConsult(one.getId(),one.getPatient(),one.getPatient(),1)){
 | 
												
													
														
															|  | 
 |  |             String failMsg = "咨询结束失败 无法结束工单";
 | 
												
													
														
															|  | 
 |  |             throw new Exception(failMsg);
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  |         securityMonitoringOrderDao.save(one);
 |  |         securityMonitoringOrderDao.save(one);
 | 
												
													
														
															|  |         SecurityMonitoringOrderDO doorServiceOrderDO = this.getDoorServiceOrderById(orderId);
 |  |         SecurityMonitoringOrderDO doorServiceOrderDO = this.getDoorServiceOrderById(orderId);
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |         // 发送微信通知  待付款
 |  |         // 发送微信通知  待付款
 | 
												
													
														
															|  |         BasePatientDO patient = basePatientDao.findById(one.getPatient());
 |  |         BasePatientDO patient = basePatientDao.findById(one.getPatient());
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |         // 获取微信模板 smfwdwk-上门服务待付款
 |  |         // 获取微信模板 smfwdwk-上门服务待付款
 | 
												
													
														
															|  | //        Consult consult = consultDao.queryByRelationCode(orderId);
 |  | //        Consult consult = consultDao.queryByRelationCode(orderId);
 | 
												
													
														
															|  |         try {
 |  |         try {
 |