|  | @ -8,12 +8,15 @@ import com.yihu.jw.doctor.dao.BaseDoctorDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.doctor.dao.BaseDoctorHospitalDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.door.dao.*;
 | 
	
		
			
				|  |  | import com.yihu.jw.door.service.consult.ConsultTeamService;
 | 
	
		
			
				|  |  | import com.yihu.jw.door.util.MessageUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
 | 
	
		
			
				|  |  | 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.door.*;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.hospital.message.SystemMessageDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.message.dao.SystemMessageDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.im.dao.ConsultDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.im.util.ImUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.org.dao.BaseOrgDao;
 | 
	
	
		
			
				|  | @ -160,6 +163,12 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
 | 
	
		
			
				|  |  |     private WlyyDoorOrderItemDao doorOrderItemDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private DoorServiceApplicationService doorServiceApplicationService;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private MessageUtil messageUtil;
 | 
	
		
			
				|  |  |     @Value("${wechat.id}")
 | 
	
		
			
				|  |  |     private String wxId;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private SystemMessageDao systemMessageDao;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 上门服务工单服务基本信息
 | 
	
	
		
			
				|  | @ -639,7 +648,7 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
 | 
	
		
			
				|  |  |             //新增工单医生关联关系
 | 
	
		
			
				|  |  |             if (orderWithDoctorAdd(result, jsonObjectParam, wlyyDoorServiceOrder)) {return result;}
 | 
	
		
			
				|  |  |             // 给服务医生发接单消息
 | 
	
		
			
				|  |  |             this.createMessage(orderDO.getId(),orderDO.getProxyPatient(),orderDO.getDoctor(),407,"服务工单待接单","您有新的服务工单,请前往处理");
 | 
	
		
			
				|  |  |             this.createMessage("服务工单待接单","407",orderDO.getProxyPatient(),orderDO.getProxyPatientName(), orderDO.getId(), orderDO.getDoctor(),orderDO.getDoctorName() ,null, "您有新的服务工单,请前往处理");
 | 
	
		
			
				|  |  |             //发送智能助手消息
 | 
	
		
			
				|  |  | //            sendWeixinMessage(4,orderDO.getDoctor(),orderDO.getPatient());
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -658,10 +667,11 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
 | 
	
		
			
				|  |  |         List<Map<String,Object>> dispatcherInfoList = (List)dispatcherJson.get(ResponseContant.resultMsg);
 | 
	
		
			
				|  |  |         for(Map<String,Object> map: dispatcherInfoList){
 | 
	
		
			
				|  |  |             String dispatcher = map.get("code").toString();
 | 
	
		
			
				|  |  |             BaseDoctorDO doctorVO = doctorDao.findById(dispatcher);
 | 
	
		
			
				|  |  |             // 派单消息-首页
 | 
	
		
			
				|  |  |             this.createMessage(orderDO.getId(),"system",dispatcher,402,"新增居民预约服务申请",orderDO.getPatientName() + "提交了服务预约申请,请您前往处理");
 | 
	
		
			
				|  |  |             this.createMessage("新增居民预约服务申请","402","system","system", orderDO.getId(), dispatcher,doctorVO.getName() ,doctorVO.getIdcard(), orderDO.getPatientName() + "提交了服务预约申请,请您前往处理");
 | 
	
		
			
				|  |  |             // 派单-实时工单消息  430 居民提交工单申请-- 张三提交了服务工单12345678申请
 | 
	
		
			
				|  |  |             this.createMessage(orderDO.getId(),"system",dispatcher,430,"居民提交工单申请",orderDO.getPatientName() + "提交了服务工单"+orderDO.getNumber()+"申请");
 | 
	
		
			
				|  |  |             this.createMessage("居民提交工单申请","430","system","system", orderDO.getId(), dispatcher,doctorVO.getName() ,doctorVO.getIdcard(), orderDO.getPatientName() + "提交了服务工单"+orderDO.getNumber()+"申请");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         //给机构调度员发送医生助手消息
 | 
	
		
			
				|  |  | /*        String  dispatcherSql = "SELECT m.doctor_code FROM base_doctor_role m " +
 | 
	
	
		
			
				|  | @ -1354,9 +1364,57 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
 | 
	
		
			
				|  |  |             orderDO.setDispatcher(dispatcher);
 | 
	
		
			
				|  |  |             orderDO.setDispatcherName(dispatcherName);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         //如果是调度员取消,推送IM取消工单json消息,
 | 
	
		
			
				|  |  |         orderDO.setStatus(WlyyDoorServiceOrderDO.Status.cancel.getType());
 | 
	
		
			
				|  |  |         this.save(orderDO);
 | 
	
		
			
				|  |  |         if(type == WlyyDoorServiceOrderDO.CancelType.dispatcher.getType()){
 | 
	
		
			
				|  |  |             List<SystemMessageDO> messages = systemMessageDao.queryByRelationCodeAndTypeIn(orderId,new String[]{"402","403","430"});
 | 
	
		
			
				|  |  |             if(CollectionUtils.isEmpty(messages)){
 | 
	
		
			
				|  |  |                 logger.error("当前工单没有系统消息!!orderId:" + orderId);
 | 
	
		
			
				|  |  |             } else {
 | 
	
		
			
				|  |  |                 // 432 调度员拒单即取消工单-- 李四拒绝了张三的服务工单12345678
 | 
	
		
			
				|  |  |                 messages.forEach(
 | 
	
		
			
				|  |  |                         message -> {
 | 
	
		
			
				|  |  |                             if (message.getType() .equals("430")) {
 | 
	
		
			
				|  |  |                                 String msg=orderDO.getDispatcherName() + "拒绝了"+ orderDO.getPatientName() +"的服务工单" + orderDO.getNumber();
 | 
	
		
			
				|  |  |                                 messageUtil.saveSystemMessage(message.getId(),message.getRelationCode(),"调度员拒单","432",dispatcher,dispatcherName,
 | 
	
		
			
				|  |  |                                         dispatcher,dispatcherName,null,msg,message.getOver());
 | 
	
		
			
				|  |  |                             }else{
 | 
	
		
			
				|  |  |                                 message.setOver("0");
 | 
	
		
			
				|  |  |                                 systemMessageDao.save(message);
 | 
	
		
			
				|  |  |                             }
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                 );
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         else if(type == WlyyDoorServiceOrderDO.CancelType.patient.getType()){                   //居民取消,消息列表也应该不显示
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             List<SystemMessageDO> messages = systemMessageDao.queryByRelationCodeAndTypeIn(orderId,new String[]{"402","403"});
 | 
	
		
			
				|  |  |             if(CollectionUtils.isEmpty(messages)){
 | 
	
		
			
				|  |  |                 logger.error("当前工单没有系统消息!!orderId:" + orderId);
 | 
	
		
			
				|  |  |             } else {
 | 
	
		
			
				|  |  |                 messages.forEach(
 | 
	
		
			
				|  |  |                         message -> {
 | 
	
		
			
				|  |  |                             message.setOver("0");
 | 
	
		
			
				|  |  |                             systemMessageDao.save(message);
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                 );
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | //        else if(type == WlyyDoorServiceOrderDO.CancelType.patient.getType()){                   //居民取消,消息列表也应该不显示
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //            List<Message> messages = messageDao.queryByRelationCodeAndTypeIn(orderId,new Integer[]{402,403});
 | 
	
		
			
				|  |  | //            if(CollectionUtils.isEmpty(messages)){
 | 
	
		
			
				|  |  | //                logger.error("当前工单没有系统消息!!orderId:" + orderId);
 | 
	
		
			
				|  |  | //            } else {
 | 
	
		
			
				|  |  | //                messages.forEach(
 | 
	
		
			
				|  |  | //                        message -> {
 | 
	
		
			
				|  |  | //                            message.setOver("0");
 | 
	
		
			
				|  |  | //                            messageDao.save(message);
 | 
	
		
			
				|  |  | //                        }
 | 
	
		
			
				|  |  | //                );
 | 
	
		
			
				|  |  | //            }
 | 
	
		
			
				|  |  | //        }
 | 
	
		
			
				|  |  |         //如果是调度员取消,推送IM取消工单json消息,
 | 
	
		
			
				|  |  | /*        if(type == WlyyDoorServiceOrderDO.CancelType.dispatcher.getType()){
 | 
	
		
			
				|  |  |             JSONObject content = this.queryOrderCardInfo(orderDO);
 | 
	
	
		
			
				|  | @ -1419,6 +1477,27 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
 | 
	
		
			
				|  |  |         JSONObject confirmInfoJson = new JSONObject();
 | 
	
		
			
				|  |  |         confirmInfoJson.put("confirmInfo",confirmInfo);
 | 
	
		
			
				|  |  |         this.orderWithConfirmLogAdd(result,confirmInfo,orderId);
 | 
	
		
			
				|  |  |         ConsultDo consult = consultDao.queryByRelationCode(orderId);
 | 
	
		
			
				|  |  |         // 发送微信模板消息,通知居民工单已取消(smyyyqx-上门预约已取消)
 | 
	
		
			
				|  |  |         String first = "key1,您好,您的上门预约服务已退回,点击查看原因";
 | 
	
		
			
				|  |  |         BasePatientDO patient = patientDao.findById(orderDO.getPatient());
 | 
	
		
			
				|  |  |         first  = first.replace("key1", null != patient.getName() ? patient.getName() : "");
 | 
	
		
			
				|  |  | //        if(consult != null) {
 | 
	
		
			
				|  |  | //            json.put("consult", consult.getCode());
 | 
	
		
			
				|  |  | //        }else {
 | 
	
		
			
				|  |  | //            json.put("id", orderDO.getId());
 | 
	
		
			
				|  |  | //        }
 | 
	
		
			
				|  |  | //        if(json.has("consult")) {
 | 
	
		
			
				|  |  | //            temp.setUrl(url + json.getString("url") + "?openid=" + openid + "&consult=" + json.getString("consult"));
 | 
	
		
			
				|  |  | //        }else if (json.has("id")){
 | 
	
		
			
				|  |  | //            temp.setUrl(url + json.getString("url") + "?openid=" + openid + "&id=" + json.getString("id"));
 | 
	
		
			
				|  |  | //        }else if(json.has("relationCode")){
 | 
	
		
			
				|  |  | //            temp.setUrl(url + json.getString("url") + "?openid=" + openid );
 | 
	
		
			
				|  |  | //        }else if(json.has("resultCode")){
 | 
	
		
			
				|  |  | //            temp.setUrl(url + json.getString("url") + "?resultCode=" + json.getString("resultCode"));
 | 
	
		
			
				|  |  | //        }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         messageUtil.putTemplateWxMessage(wxId,"template_process_feedback","smyyyqx",patient.getOpenid(),first,null,null,DateUtil.dateToStrShort(new Date()),"上门预约已取消");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | /*        Consult consult = consultDao.queryByRelationCode(orderId);
 | 
	
		
			
				|  |  |         // 发送微信模板消息,通知居民工单已取消(smyyyqx-上门预约已取消)
 | 
	
	
		
			
				|  | @ -1456,6 +1535,18 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
 | 
	
		
			
				|  |  |         WlyyDoorServiceOrderDO orderDO = wlyyDoorServiceOrderDao.findOne(orderId);
 | 
	
		
			
				|  |  |         ConsultDo consult = consultDao.queryByRelationCode(orderId);
 | 
	
		
			
				|  |  |         // 发送微信模板消息,通知居民工单已取消(smyyyqx-上门预约已取消)
 | 
	
		
			
				|  |  |         BasePatientDO patient = patientDao.findById(orderDO.getPatient());
 | 
	
		
			
				|  |  |         String first="key1,您好,您的上门预约服务已退回,点击查看原因";
 | 
	
		
			
				|  |  |         first = first.replace("key1", null != patient.getName() ? patient.getName() : "");
 | 
	
		
			
				|  |  | //        json.put("url", "appoint_service/html/appoint-serviceDetail.html?id="+orderId);
 | 
	
		
			
				|  |  | //        json.put("remark", templateConfig.getRemark());
 | 
	
		
			
				|  |  | //        if(consult != null) {
 | 
	
		
			
				|  |  | //            json.put("consult", consult.getCode());
 | 
	
		
			
				|  |  | //        }else {
 | 
	
		
			
				|  |  | //            json.put("id", orderDO.getId());
 | 
	
		
			
				|  |  | //        }
 | 
	
		
			
				|  |  |         messageUtil.putTemplateWxMessage(wxId,"template_process_feedback","smyyyqx",patient.getOpenid(),first,null,null,DateUtil.dateToStrShort(new Date()),"知情同意书已推送");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | /*        BasePatientDO patient = patientDao.findById(orderDO.getPatient());
 | 
	
		
			
				|  |  |         WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_process_feedback","smyyyqx");
 | 
	
		
			
				|  |  |         String first = templateConfig.getFirst().replace("key1", null != patient.getName() ? patient.getName() : "");
 | 
	
	
		
			
				|  | @ -1745,6 +1836,24 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
 | 
	
		
			
				|  |  |         }else if (StringUtils.isNoneBlank(phone)){
 | 
	
		
			
				|  |  |             buffer.append(" AND o.`proxy_patient_phone` like '%"+phone+"%'");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String applicationSql = "";
 | 
	
		
			
				|  |  |         String patientTypeTemp = "";
 | 
	
		
			
				|  |  |         if("1".equals(isApplication)){
 | 
	
		
			
				|  |  |             applicationSql +=                 " JOIN ( " +
 | 
	
		
			
				|  |  |                     "         select a.patient, group_concat(v.type) as type " +
 | 
	
		
			
				|  |  |                     "         from wlyy_door_service_voucher v " +
 | 
	
		
			
				|  |  |                     "                  JOIN (select t.id, t.patient, max(t.create_time) " +
 | 
	
		
			
				|  |  |                     "                        from wlyy_door_service_application t " +
 | 
	
		
			
				|  |  |                     "                        where t.status in (2, 3) " +
 | 
	
		
			
				|  |  |                     "                        group by t.patient) as a " +
 | 
	
		
			
				|  |  |                     "                       on a.id = v.service_id " +
 | 
	
		
			
				|  |  |                     "         where v.status = 1 " +
 | 
	
		
			
				|  |  |                     "         group by a.patient " +
 | 
	
		
			
				|  |  |                     "        ) as t1 on o.patient = t1.patient" ;
 | 
	
		
			
				|  |  |             patientTypeTemp = " ,t1.`type` as patientType ";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String sql = "SELECT " +
 | 
	
		
			
				|  |  |                 "  p.name AS patientName, " +
 | 
	
		
			
				|  |  |                 "  p.photo AS photo, " +
 | 
	
	
		
			
				|  | @ -1764,23 +1873,12 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
 | 
	
		
			
				|  |  |                 "  o.serve_lat as lat, " +
 | 
	
		
			
				|  |  |                 "  o.`status` as status, " +
 | 
	
		
			
				|  |  |                 "  o.`dispatcher_name` as dispatcherName, " +
 | 
	
		
			
				|  |  |                 "  concat( o.patient,'_' ,c.id, '_',o.`number`,'_11' ) as sessionId, " +
 | 
	
		
			
				|  |  |                 "   t1.`type` as patientType " +
 | 
	
		
			
				|  |  |                 "  concat( o.patient,'_' ,c.id, '_',o.`number`,'_11' ) as sessionId " +
 | 
	
		
			
				|  |  |                 patientTypeTemp +
 | 
	
		
			
				|  |  |                 " FROM " +
 | 
	
		
			
				|  |  |                 " ( wlyy_door_service_order o " +
 | 
	
		
			
				|  |  |                 " LEFT JOIN base_patient p ON o.patient = p.id ) LEFT JOIN wlyy_consult c on o.id = c.relation_code" +
 | 
	
		
			
				|  |  |                 " JOIN ( " +
 | 
	
		
			
				|  |  |                 "         select a.patient, group_concat(v.type) as type " +
 | 
	
		
			
				|  |  |                 "         from wlyy_door_service_voucher v " +
 | 
	
		
			
				|  |  |                 "                  JOIN (select t.id, t.patient, max(t.create_time) " +
 | 
	
		
			
				|  |  |                 "                        from wlyy_door_service_application t " +
 | 
	
		
			
				|  |  |                 "                        where t.status in (2, 3) " +
 | 
	
		
			
				|  |  |                 "                        group by t.patient) as a " +
 | 
	
		
			
				|  |  |                 "                       on a.id = v.service_id " +
 | 
	
		
			
				|  |  |                 "         where v.status = 1 " +
 | 
	
		
			
				|  |  |                 "         group by a.patient " +
 | 
	
		
			
				|  |  |                 "        ) as t1 on o.patient = t1.patient" +
 | 
	
		
			
				|  |  |                 " WHERE " +
 | 
	
		
			
				|  |  |                 " LEFT JOIN base_patient p ON o.patient = p.id ) LEFT JOIN wlyy_consult c on o.id = c.relation_code"+
 | 
	
		
			
				|  |  |                 applicationSql+" WHERE " +
 | 
	
		
			
				|  |  |                 "  o.hospital = '{hospital}' and o.type != 3 " +buffer+
 | 
	
		
			
				|  |  |                 " AND ( o.`status` = {status} OR -100 = {status} ) " +
 | 
	
		
			
				|  |  |                 " ORDER BY o.create_time desc " +
 | 
	
	
		
			
				|  | @ -1797,17 +1895,7 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
 | 
	
		
			
				|  |  |                 " FROM  " +
 | 
	
		
			
				|  |  |                 "   wlyy_door_service_order o  " +
 | 
	
		
			
				|  |  |                 " LEFT JOIN base_patient p ON o.patient = p.id " +
 | 
	
		
			
				|  |  |                 " JOIN  ( " +
 | 
	
		
			
				|  |  |                 "         select a.patient, group_concat(v.type) as type " +
 | 
	
		
			
				|  |  |                 "         from wlyy_door_service_voucher v " +
 | 
	
		
			
				|  |  |                 "                  JOIN (select t.id, t.patient, max(t.create_time) " +
 | 
	
		
			
				|  |  |                 "                        from wlyy_door_service_application t " +
 | 
	
		
			
				|  |  |                 "                        where t.status in (2, 3) " +
 | 
	
		
			
				|  |  |                 "                        group by t.patient) as a " +
 | 
	
		
			
				|  |  |                 "                       on a.id = v.service_id " +
 | 
	
		
			
				|  |  |                 "         where v.status = 1 " +
 | 
	
		
			
				|  |  |                 "         group by a.patient " +
 | 
	
		
			
				|  |  |                 "        ) as t1 on o.patient = t1.patient" +
 | 
	
		
			
				|  |  |                 applicationSql +
 | 
	
		
			
				|  |  |                 " WHERE  " +
 | 
	
		
			
				|  |  |                 "  o.hospital = '{hospital}' " +buffer+
 | 
	
		
			
				|  |  |                 " AND (o.`status` = {status} or -100 = {status})";
 | 
	
	
		
			
				|  | @ -1852,7 +1940,7 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
 | 
	
		
			
				|  |  |                     JSONArray parArray = imUtill.getParticipants(sessionId);
 | 
	
		
			
				|  |  |                     parArray.forEach(
 | 
	
		
			
				|  |  |                             oneParObj -> {
 | 
	
		
			
				|  |  |                                 org.json.JSONObject oneParJson = (org.json.JSONObject)oneParObj;
 | 
	
		
			
				|  |  |                                 JSONObject oneParJson = (com.alibaba.fastjson.JSONObject)oneParObj;
 | 
	
		
			
				|  |  |                                 if(StringUtils.equalsIgnoreCase(oneParJson.getString("id"),dispatcher)){
 | 
	
		
			
				|  |  |                                     oneMap.put("isInSession",true);
 | 
	
		
			
				|  |  |                                 }
 | 
	
	
		
			
				|  | @ -2046,7 +2134,7 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
 | 
	
		
			
				|  |  |         int start = 0 == page ? page++ : (page - 1) * size;
 | 
	
		
			
				|  |  |         int end = 0 == size ? 15 : page * size;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String sql = "select ds.doctor,d.name, d.job_name as jobName, 1 as sortFlag " +
 | 
	
		
			
				|  |  |         String sql = "select ds.doctor,d.name, d.job_title_name as jobName, 1 as sortFlag " +
 | 
	
		
			
				|  |  |                 " from wlyy_door_doctor_status ds " +
 | 
	
		
			
				|  |  |                 "        JOIN (select b.* from base_doctor b,base_doctor_hospital dh where b.id=dh.doctor_code and dh.del = 1 and dh.org_code='" + hospital + "')  d on ds.doctor = d.id " +
 | 
	
		
			
				|  |  |                 " where ds.status in (1,2,3,4)" +
 | 
	
	
		
			
				|  | @ -2054,7 +2142,7 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String countSql = "select count(ds.id) " +
 | 
	
		
			
				|  |  |                 "from wlyy_door_doctor_status ds " +
 | 
	
		
			
				|  |  |                 "         JOIN (select b.* from base_doctor b,base_doctor_hospital dh where b.id=dh.doctor_code and dh.del = 1 and dh.org_code= '" + hospital + "') d on ds.doctor = d.code " +
 | 
	
		
			
				|  |  |                 "         JOIN (select b.* from base_doctor b,base_doctor_hospital dh where b.id=dh.doctor_code and dh.del = 1 and dh.org_code= '" + hospital + "') d on ds.doctor = d.id " +
 | 
	
		
			
				|  |  |                 "where ds.status in (1,2,3,4)";
 | 
	
		
			
				|  |  |         List<Map<String,Object>> doctorList = new ArrayList<>();
 | 
	
		
			
				|  |  |         try {
 | 
	
	
		
			
				|  | @ -2172,11 +2260,11 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 给医生发派单消息
 | 
	
		
			
				|  |  |         if(WlyyDoorServiceOrderDO.IsTransOtherOrg.yes.getType().equals(doorServiceOrderDO.getIsTransOtherOrg())){
 | 
	
		
			
				|  |  |             this.createMessage(orderId,doorServiceOrderDO.getTransedDispatcher(),doctor,407,"服务工单待接单","您有新的服务工单,请前往处理");
 | 
	
		
			
				|  |  |             this.createMessage("服务工单待接单","407",doorServiceOrderDO.getTransedDispatcher(),doorServiceOrderDO.getTransedDispatcherName(), orderId,doctor,doctorName, null,"您有新的服务工单,请前往处理");
 | 
	
		
			
				|  |  |         }else{
 | 
	
		
			
				|  |  |             this.createMessage(orderId,doorServiceOrderDO.getDispatcher(),doctor,407,"服务工单待接单","您有新的服务工单,请前往处理");
 | 
	
		
			
				|  |  |             this.createMessage("服务工单待接单","407",doorServiceOrderDO.getDispatcher(),doorServiceOrderDO.getDispatcherName(), orderId,doctor,doctorName, null,"您有新的服务工单,请前往处理");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         //发送智能助手消息
 | 
	
		
			
				|  |  |         //发送智能助手消息//·
 | 
	
		
			
				|  |  |         sendWeixinMessage(4,doctor,doorServiceOrderDO.getPatient());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 派单时,把医生拉入会话,作为其中一个成员,医生拒单时,退出会话
 | 
	
	
		
			
				|  | @ -2185,7 +2273,7 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
 | 
	
		
			
				|  |  |         imUtill.updateParticipant(sessionId,doctor,null);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 调度员处理完该单(新增预约的,或者是拒单重新派单的)
 | 
	
		
			
				|  |  | /*        List<Message> messages = messageDao.queryByRelationCodeAndTypeIn(orderId,new Integer[]{402,404,430,435});
 | 
	
		
			
				|  |  |         List<SystemMessageDO> messages = systemMessageDao.queryByRelationCodeAndTypeIn(orderId,new String[]{"402","404","430","435"});
 | 
	
		
			
				|  |  |         if(CollectionUtils.isEmpty(messages)){
 | 
	
		
			
				|  |  |             logger.error("当前工单没有 居民新增预约 消息!!orderId:" + orderId);
 | 
	
		
			
				|  |  |         }else{
 | 
	
	
		
			
				|  | @ -2196,20 +2284,19 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
 | 
	
		
			
				|  |  |                         if("system".equals(dispatcher)){
 | 
	
		
			
				|  |  |                             title = "系统派单(派给服务医生)";
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                         if (message.getType() == 430) {
 | 
	
		
			
				|  |  |                         if (message.getType() .equals("430")) {
 | 
	
		
			
				|  |  |                             message.setTitle(title);
 | 
	
		
			
				|  |  |                             message.setContent(doorServiceOrderDO.getDispatcherName() + "已将服务工单" + doorServiceOrderDO.getNumber() + "指派给" + doctorName + "医生");
 | 
	
		
			
				|  |  |                             message.setType(431);
 | 
	
		
			
				|  |  |                             message.setReceiver(dispatcher);
 | 
	
		
			
				|  |  |                             message.setSender(dispatcher);
 | 
	
		
			
				|  |  |                             message.setCreateTime(new Date());
 | 
	
		
			
				|  |  |                             String msg = doorServiceOrderDO.getDispatcherName() + "已将服务工单" + doorServiceOrderDO.getNumber() + "指派给" + doctorName + "医生";
 | 
	
		
			
				|  |  |                             messageUtil.saveSystemMessage(message.getId(),message.getRelationCode(),title,"431",dispatcher,dispathcherName,
 | 
	
		
			
				|  |  |                                     dispatcher,dispathcherName,null,msg,message.getOver());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                         }else{
 | 
	
		
			
				|  |  |                             message.setOver("0");
 | 
	
		
			
				|  |  |                             systemMessageDao.save(message);
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                         messageDao.save(message);
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |             );
 | 
	
		
			
				|  |  |         }*/
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 工单状态变更记录
 | 
	
		
			
				|  |  |         WlyyDoorProcessLogDO processLogDO = new WlyyDoorProcessLogDO();
 | 
	
	
		
			
				|  | @ -2273,9 +2360,9 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 给医生发派单消息
 | 
	
		
			
				|  |  |         if(WlyyDoorServiceOrderDO.IsTransOtherOrg.yes.getType().equals(doorServiceOrderDO.getIsTransOtherOrg())){
 | 
	
		
			
				|  |  |             this.createMessage(orderId,doorServiceOrderDO.getTransedDispatcher(),doctor,407,"服务工单待接单","您有新的服务工单,请前往处理");
 | 
	
		
			
				|  |  |             this.createMessage("服务工单待接单","407",doorServiceOrderDO.getTransedDispatcher(),doorServiceOrderDO.getTransedDispatcherName(), orderId,doctor,doctorName, null,"您有新的服务工单,请前往处理");
 | 
	
		
			
				|  |  |         }else{
 | 
	
		
			
				|  |  |             this.createMessage(orderId,doorServiceOrderDO.getDispatcher(),doctor,407,"服务工单待接单","您有新的服务工单,请前往处理");
 | 
	
		
			
				|  |  |             this.createMessage("服务工单待接单","407",doorServiceOrderDO.getDispatcher(),doorServiceOrderDO.getDispatcherName(), orderId,doctor,doctorName, null,"您有新的服务工单,请前往处理");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         //发送智能助手消息
 | 
	
		
			
				|  |  |         sendWeixinMessage(4,doctor,doorServiceOrderDO.getPatient());
 | 
	
	
		
			
				|  | @ -2386,28 +2473,33 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 添加【工单派单,转单】等系统消息
 | 
	
		
			
				|  |  |      * @param orderId
 | 
	
		
			
				|  |  |      * @param sender
 | 
	
		
			
				|  |  |      * @param receiver
 | 
	
		
			
				|  |  |      * @param Content
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public void createMessage(String orderId,String sender,String receiver,int type,String title,String Content){
 | 
	
		
			
				|  |  | /*        Message message=new Message();
 | 
	
		
			
				|  |  |         message.setCzrq(new Date());
 | 
	
		
			
				|  |  |         message.setCreateTime(new Date());
 | 
	
		
			
				|  |  |         message.setRead(1);
 | 
	
		
			
				|  |  |         message.setState(1);
 | 
	
		
			
				|  |  |         message.setRelationCode(orderId);
 | 
	
		
			
				|  |  |         message.setOver("1");
 | 
	
		
			
				|  |  |         message.setReceiver(receiver);
 | 
	
		
			
				|  |  |         message.setSender(sender);
 | 
	
		
			
				|  |  |         message.setCode(getCode());
 | 
	
		
			
				|  |  |         message.setTitle(title);
 | 
	
		
			
				|  |  |         message.setContent(Content);
 | 
	
		
			
				|  |  |         //消息类型:401为资质申请审核
 | 
	
		
			
				|  |  |         message.setType(type);
 | 
	
		
			
				|  |  |         message.setDel("1");
 | 
	
		
			
				|  |  |         messageDao.save(message);*/
 | 
	
		
			
				|  |  |     public void createMessage(String title,String type,String sender,String senderName,String relationCode,String Receiver,String ReceiverName,String idCard,String msg){
 | 
	
		
			
				|  |  |         SystemMessageDO messageDO = new SystemMessageDO();
 | 
	
		
			
				|  |  |         messageDO.setTitle(title);
 | 
	
		
			
				|  |  |         messageDO.setType(type);//401为资质申请审核
 | 
	
		
			
				|  |  |         messageDO.setSender(sender);
 | 
	
		
			
				|  |  |         messageDO.setSenderName(senderName);
 | 
	
		
			
				|  |  |         messageDO.setRelationCode(relationCode);
 | 
	
		
			
				|  |  |         messageDO.setReceiver(Receiver);
 | 
	
		
			
				|  |  |         messageDO.setReceiverName(ReceiverName);
 | 
	
		
			
				|  |  |         messageDO.setOver("1");
 | 
	
		
			
				|  |  |         net.sf.json.JSONObject data = new net.sf.json.JSONObject();
 | 
	
		
			
				|  |  |         data.put("name", ReceiverName);
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             if(StringUtils.isNoneBlank(idCard)){
 | 
	
		
			
				|  |  |                 data.put("age", IdCardUtil.getAgeForIdcard(idCard));
 | 
	
		
			
				|  |  |                 data.put("gender", IdCardUtil.getSexForIdcard(idCard));
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             e.printStackTrace();
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         data.put("msg", msg);
 | 
	
		
			
				|  |  |         messageDO.setData(msg);
 | 
	
		
			
				|  |  |         messageDO.setDel("1");
 | 
	
		
			
				|  |  |         messageDO.setCreateTime(new Date());
 | 
	
		
			
				|  |  |         systemMessageDao.save(messageDO);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
	
		
			
				|  | @ -2533,6 +2625,26 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
 | 
	
		
			
				|  |  |         return res;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 互联网医院开方后 关联上门工单
 | 
	
		
			
				|  |  |      * @param orderId
 | 
	
		
			
				|  |  |      * @param prescriptionCode
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public void savePrescription(String orderId,String prescriptionCode){
 | 
	
		
			
				|  |  |         WlyyDoorServiceOrderDO orderDO = wlyyDoorServiceOrderDao.findOne(orderId);
 | 
	
		
			
				|  |  |         orderDO.setPrescriptionCode(prescriptionCode);
 | 
	
		
			
				|  |  |         orderDO.setPrescriptionTime(new Date());
 | 
	
		
			
				|  |  |         orderDO.setPrescriptionStatus(1);
 | 
	
		
			
				|  |  |         wlyyDoorServiceOrderDao.save(orderDO);
 | 
	
		
			
				|  |  |         //非代预约才发送im消息
 | 
	
		
			
				|  |  |         if(orderDO.getType() != null && orderDO.getType() != 3) {
 | 
	
		
			
				|  |  |             //发送 预约卡片信息(2101类型)
 | 
	
		
			
				|  |  |             JSONObject orderInfoContent = this.queryOrderCardInfo(orderDO);
 | 
	
		
			
				|  |  |             orderInfoContent.put("re_msg_type", 2);//开方完成消息
 | 
	
		
			
				|  |  |             this.qucikSendIM(orderDO.getId(), orderDO.getDispatcher(), "智能助手", "2101", orderInfoContent.toJSONString());
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      *  更新医生地理位置状态
 | 
	
	
		
			
				|  | @ -2657,15 +2769,6 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         //判断工单是否已存在,新建或者编辑
 | 
	
		
			
				|  |  |         if(StringUtils.isBlank(orderDO.getId())) {
 | 
	
		
			
				|  |  | /*            SignFamily signFamily = signFamilyDao.findSignFamilyByPatient(orderDO.getPatient());
 | 
	
		
			
				|  |  |             if (signFamily == null) {
 | 
	
		
			
				|  |  |                 result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |                 String failMsg = "当前服务对象未完成家庭医生签约,请完成签约后再预约上门服务!";
 | 
	
		
			
				|  |  |                 result.put(ResponseContant.resultMsg, failMsg);
 | 
	
		
			
				|  |  |                 logger.error(failMsg);
 | 
	
		
			
				|  |  |                 return result;
 | 
	
		
			
				|  |  |             }*/
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             //已取消的订单也可以申请
 | 
	
		
			
				|  |  |             boolean bool = wlyyDoorServiceOrderDao.existsByPatientAndStatusIn(orderDO.getPatient(),
 | 
	
		
			
				|  |  |                     new Integer[]{WlyyDoorServiceOrderDO.Status.waitForAccept.getType(),
 | 
	
	
		
			
				|  | @ -2721,9 +2824,6 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
 | 
	
		
			
				|  |  |                 sql += " and d.id = '"+orderDO.getDoctor()+"'";
 | 
	
		
			
				|  |  |                 List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | /*                BaseDoctorDO doctor = doctorDao.findById(orderDO.getDoctor());
 | 
	
		
			
				|  |  |                 Hospital hospital = hospitalDao.findByCode(doctor.getHospital());
 | 
	
		
			
				|  |  |                 doorOrderService.acceptOrder1(orderDO.getId(), doctor.getJob(), doctor.getJobName(), hospital.getLevel());*/
 | 
	
		
			
				|  |  |                 doorOrderService.acceptOrder1(orderDO.getId(), list.get(0).get("job_title_code").toString(),
 | 
	
		
			
				|  |  |                         list.get(0).get("job_title_name").toString(), Integer.valueOf(list.get(0).get("org_level").toString()));
 | 
	
		
			
				|  |  |             }catch (Exception e){
 | 
	
	
		
			
				|  | @ -2732,7 +2832,7 @@ public class WlyyDoorServiceOrderService extends BaseJpaService<WlyyDoorServiceO
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         }else{
 | 
	
		
			
				|  |  |             // 给服务医生发接单消息
 | 
	
		
			
				|  |  |             this.createMessage(orderDO.getId(),orderDO.getProxyPatient(),orderDO.getDoctor(),407,"服务工单待接单","您有新的服务工单,请前往处理");
 | 
	
		
			
				|  |  |             this.createMessage("服务工单待接单","407",orderDO.getProxyPatient(),orderDO.getProxyPatientName(), orderDO.getId(),orderDO.getDoctor(),orderDO.getDoctorName(), null,"您有新的服务工单,请前往处理");
 | 
	
		
			
				|  |  |             //发送智能助手消息
 | 
	
		
			
				|  |  |             sendWeixinMessage(4,orderDO.getDoctor(),orderDO.getPatient());
 | 
	
		
			
				|  |  |         }
 |