|  | @ -0,0 +1,757 @@
 | 
	
		
			
				|  |  | package com.yihu.jw.care.service.security;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONArray;
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  | import com.fasterxml.jackson.databind.ObjectMapper;
 | 
	
		
			
				|  |  | import com.yihu.jw.care.dao.device.PatientDeviceDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.care.dao.security.*;
 | 
	
		
			
				|  |  | import com.yihu.jw.care.service.sign.ServicePackageService;
 | 
	
		
			
				|  |  | import com.yihu.jw.care.util.MessageUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.doctor.dao.BaseDoctorDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.patient.BasePatientDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.servicePackage.ServicePackageRecordDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.care.device.PatientDevice;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.care.securitymonitoring.*;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.message.dao.SystemMessageDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.patient.dao.BasePatientDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.ResponseContant;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.common.IdCardUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.date.DateUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.entity.EntityUtils;
 | 
	
		
			
				|  |  | import com.yihu.mysql.query.BaseJpaService;
 | 
	
		
			
				|  |  | import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  | import org.slf4j.Logger;
 | 
	
		
			
				|  |  | import org.slf4j.LoggerFactory;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | import org.springframework.jdbc.core.JdbcTemplate;
 | 
	
		
			
				|  |  | import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import java.text.SimpleDateFormat;
 | 
	
		
			
				|  |  | import java.util.Date;
 | 
	
		
			
				|  |  | import java.util.List;
 | 
	
		
			
				|  |  | import java.util.Map;
 | 
	
		
			
				|  |  | import java.util.Random;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | /**
 | 
	
		
			
				|  |  |  * Created by Bing on 2021/4/6.
 | 
	
		
			
				|  |  |  */
 | 
	
		
			
				|  |  | @Service
 | 
	
		
			
				|  |  | public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonitoringOrderDO, SecurityMonitoringOrderDao> {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private SecurityMonitoringOrderDao securityMonitoringOrderDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private JdbcTemplate jdbcTemplate;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private PatientDeviceDao patientDeviceDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private ServicePackageService servicePackageService;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private SecurityMonitoringOrderCancelLogDao securityMonitoringOrderCancelLogDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private MessageUtil messageUtil;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private SecurityMonitoringOrderPatientConfirmLogDao securityMonitoringOrderPatientConfirmLogDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private SecurityMonitoringDoctorStatusDao doctorStatusDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private SystemMessageDao systemMessageDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BasePatientDao basePatientDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BaseDoctorDao baseDoctorDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private SecurityMonitoringConclusionDao securityMonitoringConclusionDao;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     private Logger logger = LoggerFactory.getLogger(SecurityMonitoringOrderService.class);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public JSONObject createOrder(String jsonData){
 | 
	
		
			
				|  |  |         logger.info("创建上门服务jsonData参数:" + jsonData);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         JSONObject result = new JSONObject();
 | 
	
		
			
				|  |  |         JSONObject jsonObjectParam;
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             jsonObjectParam = JSONObject.parseObject(jsonData);
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             result.put("resultFlag", 0);
 | 
	
		
			
				|  |  |             String failMsg = "参数转换成JSON对象异常:" + e.getMessage();
 | 
	
		
			
				|  |  |             result.put("resultMsg", failMsg);
 | 
	
		
			
				|  |  |             logger.error(failMsg);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         SecurityMonitoringOrderDO orderDO = null;
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             orderDO = EntityUtils.jsonToEntity(jsonObjectParam.get("order").toString(), SecurityMonitoringOrderDO.class);
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             result.put("resultFlag", 0);
 | 
	
		
			
				|  |  |             String failMsg = "服务工单服务基本信息:" + e.getMessage();
 | 
	
		
			
				|  |  |             result.put("resultMsg", failMsg);
 | 
	
		
			
				|  |  |             logger.error(failMsg);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         orderDO.setStatus(1);
 | 
	
		
			
				|  |  |         orderDO.setNumber(getRandomIntStr());
 | 
	
		
			
				|  |  |         orderDO.setCreateTime(new Date());
 | 
	
		
			
				|  |  |         orderDO.setCreateUser(orderDO.getCreateUser());
 | 
	
		
			
				|  |  |         orderDO.setCreateUserName(orderDO.getCreateUserName());
 | 
	
		
			
				|  |  |         orderDO.setOrderInfo("0");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if(StringUtils.isEmpty(orderDO.getPatient())){
 | 
	
		
			
				|  |  |             result.put("resultFlag", 0);
 | 
	
		
			
				|  |  |             String failMsg = "当前服务对象code为空,请联系管理员检查参数!patient = " + orderDO.getPatient();
 | 
	
		
			
				|  |  |             result.put("resultMsg", failMsg);
 | 
	
		
			
				|  |  |             logger.error(failMsg);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //签约防走失服务包
 | 
	
		
			
				|  |  |         List<ServicePackageRecordDO> signRecords = servicePackageService.servicePackageByPatient(orderDO.getPatient(),"3");
 | 
	
		
			
				|  |  |         if (signRecords.size()<0) {
 | 
	
		
			
				|  |  |             result.put("resultFlag", 0);
 | 
	
		
			
				|  |  |             String failMsg = "当前服务对象未完成签约,请完成签约后再预约服务!";
 | 
	
		
			
				|  |  |             result.put("resultMsg", failMsg);
 | 
	
		
			
				|  |  |             logger.error(failMsg);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //已取消的订单也可以申请
 | 
	
		
			
				|  |  |         boolean bool = securityMonitoringOrderDao.existsByPatientAndStatusIn(orderDO.getPatient(),
 | 
	
		
			
				|  |  |                 new Integer[]{SecurityMonitoringOrderDO.Status.waitForSend.getType(),
 | 
	
		
			
				|  |  |                         SecurityMonitoringOrderDO.Status.waitForArrive.getType(),
 | 
	
		
			
				|  |  |                         SecurityMonitoringOrderDO.Status.signed.getType(),
 | 
	
		
			
				|  |  |                         SecurityMonitoringOrderDO.Status.registerSummary.getType(),
 | 
	
		
			
				|  |  |                         SecurityMonitoringOrderDO.Status.waitForAdded.getType(),
 | 
	
		
			
				|  |  |                 });
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if(bool){
 | 
	
		
			
				|  |  |             String failMsg = "当前服务对象存在未完成的服务,请先完成该服务!";
 | 
	
		
			
				|  |  |             result.put("resultFlag", 0);
 | 
	
		
			
				|  |  |             result.put("resultMsg", failMsg);
 | 
	
		
			
				|  |  |             logger.error(failMsg);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         orderDO.setHospital(jsonObjectParam.getJSONObject("hospital").get("code").toString());
 | 
	
		
			
				|  |  |         orderDO.setCreateTime(new Date());
 | 
	
		
			
				|  |  |         //判断创建预警服务类型,发起类型(1本人发起 2家人待预约 3医生代预约)
 | 
	
		
			
				|  |  |         orderDO.setType(3);//发起类型
 | 
	
		
			
				|  |  |         orderDO.setServiceStatus("2");
 | 
	
		
			
				|  |  |         this.save(orderDO);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //创建咨询
 | 
	
		
			
				|  |  |         org.json.JSONObject successOrNot = null;
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  | //            successOrNot = consultTeamService.addDoorServiceConsult(orderDO.getId());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             successOrNot = null;//TODO 接单时创建两个人聊天
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             String failMsg = "创建咨询时异常: " + e.getMessage();
 | 
	
		
			
				|  |  |             result.put("resultFlag", 0);
 | 
	
		
			
				|  |  |             result.put("resultMsg", failMsg);
 | 
	
		
			
				|  |  |             logger.error(failMsg);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (Integer.parseInt(successOrNot.get("resultFlag").toString()) == 0) {
 | 
	
		
			
				|  |  |             return JSONObject.parseObject(successOrNot.toString());
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public JSONArray getSecurityOrderList(String doctor, String patient, String status, Integer page, Integer pageSize){
 | 
	
		
			
				|  |  |         String sql = " select p.id patientCode,p.name,p.sex,p.idcard,ord.id orderId,ord.number,ord.serve_desc,ord.create_time,ord.`status`,ord.doctor," +
 | 
	
		
			
				|  |  |                 "ord.doctor_name,ord.patient_phone from base_security_monitoring_order ord INNER JOIN base_patient p on p.id = ord.patient " +
 | 
	
		
			
				|  |  |                 "where 1=1 ";
 | 
	
		
			
				|  |  |         if (StringUtils.isNotBlank(doctor)){
 | 
	
		
			
				|  |  |             sql +=" and ord.doctor = '"+doctor+"' ";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (StringUtils.isNotBlank(patient)){
 | 
	
		
			
				|  |  |             sql+=" and ord.patient='"+patient+"' ";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (StringUtils.isNotBlank(status)){
 | 
	
		
			
				|  |  |             sql+=" and ord.status='"+Integer.parseInt(status)+"' ";
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         sql+=" order by ord.create_time desc limit " + (page*pageSize) + "," + pageSize;
 | 
	
		
			
				|  |  |         List<Map<String,Object>> sqlResult = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         JSONArray result = new JSONArray();
 | 
	
		
			
				|  |  |         for (Map<String,Object>one:sqlResult){
 | 
	
		
			
				|  |  |             JSONObject tmp = new JSONObject();
 | 
	
		
			
				|  |  |             tmp.put("patientCode",one.get("patientCode"));
 | 
	
		
			
				|  |  |             tmp.put("patientName",one.get("name"));
 | 
	
		
			
				|  |  |             tmp.put("sex",one.get("sex"));
 | 
	
		
			
				|  |  |             tmp.put("idcard",one.get("idcard"));
 | 
	
		
			
				|  |  |             tmp.put("number",one.get("number"));
 | 
	
		
			
				|  |  |             tmp.put("id",one.get("orderId"));
 | 
	
		
			
				|  |  |             tmp.put("serveDesc",one.get("serve_desc"));
 | 
	
		
			
				|  |  |             Date date = (Date)one.get("create_time");
 | 
	
		
			
				|  |  |             tmp.put("createTime", DateUtil.dateToStr(date,"yyyy-MM-dd hh:mm:ss"));
 | 
	
		
			
				|  |  |             tmp.put("status",one.get("status"));
 | 
	
		
			
				|  |  |             tmp.put("doctor",one.get("doctor"));
 | 
	
		
			
				|  |  |             tmp.put("doctorName",one.get("doctor_ame"));
 | 
	
		
			
				|  |  |             tmp.put("patientPhone",one.get("patient_phone"));
 | 
	
		
			
				|  |  |             Integer statustemp = Integer.valueOf(one.get("status")+"");
 | 
	
		
			
				|  |  |             String statusName = "";
 | 
	
		
			
				|  |  |             switch (statustemp){
 | 
	
		
			
				|  |  |                 case -1:statusName="已取消";break;
 | 
	
		
			
				|  |  |                 case 1:statusName="待处置";break;
 | 
	
		
			
				|  |  |                 case 2:statusName="前往居民定位";break;
 | 
	
		
			
				|  |  |                 case 3:statusName="已签到";break;
 | 
	
		
			
				|  |  |                 case 4:statusName="已登记小结";break;
 | 
	
		
			
				|  |  |                 case 5:statusName="待补录";break;
 | 
	
		
			
				|  |  |                 case 6:statusName="待评价";break;
 | 
	
		
			
				|  |  |                 case 7:statusName="已完成";break;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             tmp.put("statusName",statusName);
 | 
	
		
			
				|  |  |             result.add(tmp);
 | 
	
		
			
				|  |  |             Integer age  = IdCardUtil.getAgeForIdcard(tmp.getString("idcard"));
 | 
	
		
			
				|  |  |             tmp.put("age",age);
 | 
	
		
			
				|  |  |             //患者设备
 | 
	
		
			
				|  |  |             List<PatientDevice> devices = patientDeviceDao.findAllByUser(tmp.get("patientCode").toString());
 | 
	
		
			
				|  |  |             if (devices.size()>0){
 | 
	
		
			
				|  |  |                 tmp.put("deviceFlag","1");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             else {
 | 
	
		
			
				|  |  |                 tmp.put("deviceFlag","0");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 系统更新医生上门服务工单状态
 | 
	
		
			
				|  |  |      * @param doctor
 | 
	
		
			
				|  |  |      * @param dispatchOrderStatus
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public void updateDispatchStatusBySystem(String doctor, Integer dispatchOrderStatus) {
 | 
	
		
			
				|  |  |         SecurityMonitoringDoctorStatusDo doctorSwitch = doctorStatusDao.findByDoctor(doctor);
 | 
	
		
			
				|  |  |         if (null != doctorSwitch) {
 | 
	
		
			
				|  |  |             doctorSwitch.setStatus(dispatchOrderStatus);
 | 
	
		
			
				|  |  |             doctorSwitch.setUpdateTime(new Date());
 | 
	
		
			
				|  |  |             doctorSwitch.setCreateUser("System");
 | 
	
		
			
				|  |  |             doctorSwitch.setCreateUserName("System");
 | 
	
		
			
				|  |  |         } else {
 | 
	
		
			
				|  |  |             doctorSwitch = new SecurityMonitoringDoctorStatusDo();
 | 
	
		
			
				|  |  |             doctorSwitch.setDoctor(doctor);
 | 
	
		
			
				|  |  |             doctorSwitch.setStatus(dispatchOrderStatus);
 | 
	
		
			
				|  |  |             doctorSwitch.setCreateTime(new Date());
 | 
	
		
			
				|  |  |             doctorSwitch.setCreateUser("System");
 | 
	
		
			
				|  |  |             doctorSwitch.setCreateUserName("System");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         doctorStatusDao.save(doctorSwitch);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public SecurityMonitoringOrderDO acceptOrder1(String orderId,String doctor) throws Exception{
 | 
	
		
			
				|  |  |         SecurityMonitoringOrderDO doorServiceOrder = securityMonitoringOrderDao.findOne(orderId);
 | 
	
		
			
				|  |  |         if (null == doorServiceOrder) {
 | 
	
		
			
				|  |  |             throw new Exception("该工单不存在");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         doorServiceOrder.setStatus(SecurityMonitoringOrderDO.Status.waitForArrive.getType()); //
 | 
	
		
			
				|  |  |         this.updateDispatchStatusBySystem(doorServiceOrder.getDoctor(), 3);//待服务
 | 
	
		
			
				|  |  |         doorServiceOrder.setServiceResponseTime(new Date());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //新增工单医生关联关系
 | 
	
		
			
				|  |  | //        JSONObject jsonObjectParam = new JSONObject();
 | 
	
		
			
				|  |  | //        JSONObject doc = new JSONObject();
 | 
	
		
			
				|  |  | //        doc.put("doctor",doorServiceOrder.getDoctor());
 | 
	
		
			
				|  |  | //        doc.put("doctorName",doorServiceOrder.getDoctorName());
 | 
	
		
			
				|  |  | //        doc.put("hospitalLevel",hospitalLevel);
 | 
	
		
			
				|  |  | //        doc.put("doctorJobCode",jobCode);
 | 
	
		
			
				|  |  | //        doc.put("doctorJobName",jobCodeName);
 | 
	
		
			
				|  |  | //        JSONArray docArr = new JSONArray();
 | 
	
		
			
				|  |  | //        docArr.add(doc);
 | 
	
		
			
				|  |  | //        jsonObjectParam.put("doctorArr",docArr);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 无费用
 | 
	
		
			
				|  |  | //        if (wlyyDoorServiceOrderService.orderWithDoctorAdd(new JSONObject(), jsonObjectParam, doorServiceOrder)) return null;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         securityMonitoringOrderDao.save(doorServiceOrder);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         systemMessageDao.orderMessageDelByType(doorServiceOrder.getDoctor(),orderId,"607");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if(doorServiceOrder.getType() == null|| doorServiceOrder.getType() != 3) {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | //            //获取咨询
 | 
	
		
			
				|  |  | //            ConsultTeam consultTeam = consultTeamDao.queryByRelationCode(orderId);
 | 
	
		
			
				|  |  | //            consultTeam.setDoctor(doorServiceOrder.getDoctor());
 | 
	
		
			
				|  |  | //            consultTeam.setDoctorName(doorServiceOrder.getDoctorName());
 | 
	
		
			
				|  |  | //            consultTeamDao.save(consultTeam);
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //            String sessionId = doorServiceOrder.getPatient() + "_" + consultTeam.getConsult() + "_" + doorServiceOrder.getNumber() + "_" + consultTeam.getType();
 | 
	
		
			
				|  |  | //            //成功创建服务工单后,居民所在机构调度员向居民发起一条通知服务消息
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //            // 发送IM消息通知患者医生已接单
 | 
	
		
			
				|  |  | //            String noticeContent = "我已接受您的服务工单预约," + doorServiceOrder.getDoctorName() + "医生正在为您服务!";
 | 
	
		
			
				|  |  | ////        imUtill.sendIntoTopicIM(doorServiceOrder.getDoctor(), sessionId, consultTeam.getConsult(), noticeContent, doorServiceOrder.getProxyPatient(), doorServiceOrder.getProxyPatientName());
 | 
	
		
			
				|  |  | //            wlyyDoorServiceOrderService.qucikSendIM(doorServiceOrder.getId(), doorServiceOrder.getDispatcher(), "智能助手", "1", noticeContent);
 | 
	
		
			
				|  |  | //            // 发送居民上门服务简要信息
 | 
	
		
			
				|  |  | //            JSONObject orderInfoContent = wlyyDoorServiceOrderService.queryOrderCardInfo(doorServiceOrder);
 | 
	
		
			
				|  |  | //            orderInfoContent.put("re_msg_type", 0);
 | 
	
		
			
				|  |  | //            wlyyDoorServiceOrderService.qucikSendIM(doorServiceOrder.getId(), doorServiceOrder.getDispatcher(), "智能助手", "2101", orderInfoContent.toJSONString());
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         return doorServiceOrder;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 接单
 | 
	
		
			
				|  |  |      * @param orderId
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  |     public JSONObject acceptOrder(String orderId,String doctor) throws Exception {
 | 
	
		
			
				|  |  |         JSONObject result = new JSONObject();
 | 
	
		
			
				|  |  |         SecurityMonitoringOrderDO doorServiceOrderDO = securityMonitoringOrderDao.findOne(orderId);
 | 
	
		
			
				|  |  |         if(null == doorServiceOrderDO){
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |             String failMsg = "当前工单不存在,id:" + orderId;
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultMsg, failMsg);
 | 
	
		
			
				|  |  |             logger.error(failMsg);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         SecurityMonitoringDoctorStatusDo doorDoctorStatusDO = doctorStatusDao.queryByDoctorAndStatusIn(doctor,new Integer[]{SecurityMonitoringDoctorStatusDo.Status.waitForSend.getType(),
 | 
	
		
			
				|  |  |                 SecurityMonitoringDoctorStatusDo.Status.waitForAccept.getType(),
 | 
	
		
			
				|  |  |                 SecurityMonitoringDoctorStatusDo.Status.waitForServe.getType(),
 | 
	
		
			
				|  |  |                 SecurityMonitoringDoctorStatusDo.Status.serving.getType(),
 | 
	
		
			
				|  |  |         });
 | 
	
		
			
				|  |  |         if(null == doorDoctorStatusDO){
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |             String failMsg = "当前接单的医生不存在或禁止接单,doctor:" + doctor;
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultMsg, failMsg);
 | 
	
		
			
				|  |  |             logger.error(failMsg);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         BaseDoctorDO doctorDO= baseDoctorDao.findById(doctor);
 | 
	
		
			
				|  |  |         doorServiceOrderDO.setDoctor(doctor);
 | 
	
		
			
				|  |  |         doorServiceOrderDO.setDoctorName(doctorDO.getName());
 | 
	
		
			
				|  |  |         doorServiceOrderDO.setDoctorType("医生");
 | 
	
		
			
				|  |  |         doorServiceOrderDO.setStatus(SecurityMonitoringOrderDO.Status.waitForArrive.getType());//前往居民定位
 | 
	
		
			
				|  |  |         doorServiceOrderDO.setUpdateUser(doctor);
 | 
	
		
			
				|  |  |         doorServiceOrderDO.setUpdateUserName(doctorDO.getName());
 | 
	
		
			
				|  |  |         securityMonitoringOrderDao.save(doorServiceOrderDO);
 | 
	
		
			
				|  |  |         // 派单时,把医生拉入会话,作为其中一个成员,医生拒单时,退出会话
 | 
	
		
			
				|  |  |         //TODO 接单时创建两个人聊天
 | 
	
		
			
				|  |  | //        ConsultDo consult = consultDao.queryByRelationCode(orderId);
 | 
	
		
			
				|  |  | //        String sessionId = doorServiceOrderDO.getPatient() + "_" + consult.getId() + "_" + doorServiceOrderDO.getNumber() + "_" + consult.getType();
 | 
	
		
			
				|  |  | //        imUtill.updateParticipantNew(sessionId,doctor,null);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 工单状态变更记录
 | 
	
		
			
				|  |  | //        WlyyDoorProcessLogDO processLogDO = new WlyyDoorProcessLogDO();
 | 
	
		
			
				|  |  | //        processLogDO.setOrderId(orderId);
 | 
	
		
			
				|  |  | //        processLogDO.setStatus(WlyyDoorServiceOrderDO.Status.waitForAccept.getType());
 | 
	
		
			
				|  |  | //        processLogDO.setDispatcher(dispatcher);
 | 
	
		
			
				|  |  | //        processLogDO.setDispatcherName(dispathcherName);
 | 
	
		
			
				|  |  | //        processLogDO.setCreateTime(new Date());
 | 
	
		
			
				|  |  | //        wlyyDoorProcessLogDao.save(processLogDO);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 发送IM消息通知患者医生已派单
 | 
	
		
			
				|  |  | //        String noticeContent = "已转派"+doorServiceOrderDO.getDoctorName()+"医生为您服务,请耐心等待医生接单";
 | 
	
		
			
				|  |  | //        this.qucikSendIM(doorServiceOrderDO.getId(), dispatcher, "智能助手","1", noticeContent);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         SecurityMonitoringOrderDO doorServiceOrder = acceptOrder1(orderId, doctor);
 | 
	
		
			
				|  |  |         if(doorServiceOrder==null){
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultFlag, ResponseContant.fail);
 | 
	
		
			
				|  |  |             String failMsg = "当前接单的医生不存在或禁止接单,doctor:" + doctor;
 | 
	
		
			
				|  |  |             result.put(ResponseContant.resultMsg, failMsg);
 | 
	
		
			
				|  |  |             logger.error(failMsg);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         result.put(ResponseContant.resultFlag, ResponseContant.success);
 | 
	
		
			
				|  |  |         result.put(ResponseContant.resultMsg, doorServiceOrder);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 发送微信模板消息通知患者医生已接单
 | 
	
		
			
				|  |  | //        BasePatientDO patient = basePatientDao.findById(doorServiceOrder.getPatient());//
 | 
	
		
			
				|  |  |         // 获取微信模板
 | 
	
		
			
				|  |  | //        ConsultDo consult = consultDao.queryByRelationCode(orderId);
 | 
	
		
			
				|  |  | //        try {
 | 
	
		
			
				|  |  | //            JSONObject json = new JSONObject();
 | 
	
		
			
				|  |  | //            if(consult != null) {
 | 
	
		
			
				|  |  | //                json.put("consult", consult.getId());
 | 
	
		
			
				|  |  | //            }
 | 
	
		
			
				|  |  | //            String first = "key1,您好!您的上门预约服务已由【key2】医生接单了";
 | 
	
		
			
				|  |  | //            first = first.replace("key1",(patient.getName()==null?"":patient.getName()));
 | 
	
		
			
				|  |  | //            first = first.replace("key2", null != doorServiceOrder.getDoctorName() ? doorServiceOrder.getDoctorName() : "");
 | 
	
		
			
				|  |  | //            List<BasePatientWechatDo> basePatientWechatDos = basePatientWechatDao.findByWechatIdAndPatientId(wxId,patient.getId());
 | 
	
		
			
				|  |  | //            String openId = basePatientWechatDos.get(0).getOpenid();
 | 
	
		
			
				|  |  | //            messageUtil.putTemplateWxMessage(wxId,"template_process_feedback","smyyyjjd",openId,first,null,null,30,json,DateUtil.dateToChineseDate(new Date()),"上门服务已接单");
 | 
	
		
			
				|  |  | //        }catch (Exception e){
 | 
	
		
			
				|  |  | //            e.printStackTrace();
 | 
	
		
			
				|  |  | //            logger.error(e.getMessage());
 | 
	
		
			
				|  |  | //        }
 | 
	
		
			
				|  |  |         //  待接单消息设为已操作, 434 医生接单-- 王五接受了服务工单12345678
 | 
	
		
			
				|  |  |         messageUtil.createMessage("医生接单","634",doorServiceOrder.getPatient(),doorServiceOrder.getPatientName(),
 | 
	
		
			
				|  |  |                 doorServiceOrder.getId(), doorServiceOrder.getDoctor(),doorServiceOrder.getDoctorName() ,null, doorServiceOrder.getDoctor() + "接受了服务工单"+ doorServiceOrder.getNumber());
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 取消工单
 | 
	
		
			
				|  |  |      * @param orderId
 | 
	
		
			
				|  |  |      * @param type
 | 
	
		
			
				|  |  |      * @param reason
 | 
	
		
			
				|  |  |      * @param dispatcher
 | 
	
		
			
				|  |  |      * @param dispatcherName
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public JSONObject cancelOrder(String orderId,int type,String reason,String dispatcher,String dispatcherName){
 | 
	
		
			
				|  |  |         JSONObject result = new JSONObject();
 | 
	
		
			
				|  |  |         SecurityMonitoringOrderDO orderDO = securityMonitoringOrderDao.findOne(orderId);
 | 
	
		
			
				|  |  |         if(null == orderDO){
 | 
	
		
			
				|  |  |             String failMsg = "【取消工单】该工单不存在:," + orderId;
 | 
	
		
			
				|  |  |             result.put("resultFlag", 0);
 | 
	
		
			
				|  |  |             result.put("resultMsg", failMsg);
 | 
	
		
			
				|  |  |             logger.error(failMsg);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         //接单前可取消工单
 | 
	
		
			
				|  |  |         if(orderDO.getStatus() > SecurityMonitoringOrderDO.Status.waitForSend.getType()){
 | 
	
		
			
				|  |  |             String failMsg = "只有医生接单前的工单才可取消:," + orderId;
 | 
	
		
			
				|  |  |             result.put("resultFlag", 0);
 | 
	
		
			
				|  |  |             result.put("resultMsg", failMsg);
 | 
	
		
			
				|  |  |             logger.error(failMsg);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         orderDO.setCancelType(type);
 | 
	
		
			
				|  |  |         orderDO.setCancelTime(new Date());
 | 
	
		
			
				|  |  |         orderDO.setCancelReason(reason);
 | 
	
		
			
				|  |  |         orderDO.setStatus(SecurityMonitoringOrderDO.Status.cancel.getType());
 | 
	
		
			
				|  |  |         this.save(orderDO);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |        if(type == SecurityMonitoringOrderDO.CancelType.patient.getType()){                   //居民取消,消息列表也应该不显示
 | 
	
		
			
				|  |  |            messageUtil.updateSecurityMonitoringOrderMessage(orderDO,new String[]{"602","603"},"patientCancel");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //保存取消记录
 | 
	
		
			
				|  |  |         SecurityMonitoringOrderCancelLog cancelLogDO = new SecurityMonitoringOrderCancelLog();
 | 
	
		
			
				|  |  |         cancelLogDO.setOrderId(orderId);
 | 
	
		
			
				|  |  |         cancelLogDO.setPatient(orderDO.getPatient());
 | 
	
		
			
				|  |  |         cancelLogDO.setCancelType(type);
 | 
	
		
			
				|  |  |         cancelLogDO.setCancelReason(reason);
 | 
	
		
			
				|  |  |         cancelLogDO.setTime(orderDO.getCancelTime());
 | 
	
		
			
				|  |  |         securityMonitoringOrderCancelLogDao.save(cancelLogDO);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //保存居民确认取消记录
 | 
	
		
			
				|  |  |         JSONObject confirmInfo = new JSONObject();
 | 
	
		
			
				|  |  |         confirmInfo.put("orderId",orderId);
 | 
	
		
			
				|  |  |         confirmInfo.put("patient",orderDO.getPatient());
 | 
	
		
			
				|  |  |         confirmInfo.put("patientName",orderDO.getPatientName());
 | 
	
		
			
				|  |  |         confirmInfo.put("type",4);
 | 
	
		
			
				|  |  |         confirmInfo.put("description",reason);
 | 
	
		
			
				|  |  |         JSONObject confirmInfoJson = new JSONObject();
 | 
	
		
			
				|  |  |         confirmInfoJson.put("confirmInfo",confirmInfo);
 | 
	
		
			
				|  |  |         this.orderWithConfirmLogAdd(result,confirmInfo,orderId);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | //        Consult consult = consultDao.queryByRelationCode(orderId);
 | 
	
		
			
				|  |  | //        // 发送微信模板消息,通知居民工单已取消(smyyyqx-上门预约已取消)
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //        Patient patient = patientInfoService.findByCode(orderDO.getPatient());
 | 
	
		
			
				|  |  | //        WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_process_feedback","smyyyqx");
 | 
	
		
			
				|  |  | //        String first = templateConfig.getFirst().replace("key1", null != patient.getName() ? patient.getName() : "");
 | 
	
		
			
				|  |  | //        org.json.JSONObject json = new org.json.JSONObject();
 | 
	
		
			
				|  |  | //        json.put("first", first);
 | 
	
		
			
				|  |  | //        json.put("keyword1", DateUtil.dateToStrShort(new Date()));
 | 
	
		
			
				|  |  | //        json.put("keyword2", "上门预约已取消");
 | 
	
		
			
				|  |  | //        json.put("url", templateConfig.getUrl());
 | 
	
		
			
				|  |  | //        json.put("remark", templateConfig.getRemark());
 | 
	
		
			
				|  |  | //        if(consult != null) {
 | 
	
		
			
				|  |  | //            json.put("consult", consult.getCode());
 | 
	
		
			
				|  |  | //        }else {
 | 
	
		
			
				|  |  | //            json.put("id", orderDO.getId());
 | 
	
		
			
				|  |  | //        }
 | 
	
		
			
				|  |  | //        pushMsgTask.putWxMsg(tokenUtils.getAccessToken(), 30, patient.getOpenid(), patient.getName(), json);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         result.put("resultFlag", 1);
 | 
	
		
			
				|  |  |         result.put("resultMsg", "工单服务已取消!");
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  |     public boolean orderWithConfirmLogAdd(JSONObject result, JSONObject jsonObjectParam, String orderId) {
 | 
	
		
			
				|  |  |         // 确认信息
 | 
	
		
			
				|  |  |         JSONObject confirmInfo = jsonObjectParam.getJSONObject("confirmInfo");
 | 
	
		
			
				|  |  |         if (null != confirmInfo) {
 | 
	
		
			
				|  |  |             SecurityMonitoringOrderPatientConfirmLog confirmLogDO = null;
 | 
	
		
			
				|  |  |             try {
 | 
	
		
			
				|  |  |                 confirmLogDO = EntityUtils.jsonToEntity(confirmInfo.toString(), SecurityMonitoringOrderPatientConfirmLog.class);
 | 
	
		
			
				|  |  |             } catch (Exception e) {
 | 
	
		
			
				|  |  |                 String failMsg = "工单关联【居民确认操作日志记录】时," + e.getMessage();
 | 
	
		
			
				|  |  |                 result.put("resultFlag", 0);
 | 
	
		
			
				|  |  |                 result.put("resultMsg", failMsg);
 | 
	
		
			
				|  |  |                 logger.error(failMsg);
 | 
	
		
			
				|  |  |                 return true;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             confirmLogDO.setOrderId(orderId);
 | 
	
		
			
				|  |  |             confirmLogDO.setCreateTime(new Date());
 | 
	
		
			
				|  |  |             try {
 | 
	
		
			
				|  |  |                 securityMonitoringOrderPatientConfirmLogDao.save(confirmLogDO);
 | 
	
		
			
				|  |  |             } catch (Exception e) {
 | 
	
		
			
				|  |  |                 String failMsg = "保存工单关联的【居民确认操作日志记录】时:," + e.getMessage();
 | 
	
		
			
				|  |  |                 result.put("resultFlag", 0);
 | 
	
		
			
				|  |  |                 result.put("resultMsg", failMsg);
 | 
	
		
			
				|  |  |                 logger.error(failMsg);
 | 
	
		
			
				|  |  |                 return true;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return false;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 签到保存
 | 
	
		
			
				|  |  |      * @param orderId
 | 
	
		
			
				|  |  |      * @param signTime
 | 
	
		
			
				|  |  |      * @param signWay
 | 
	
		
			
				|  |  |      * @param signLocation
 | 
	
		
			
				|  |  |      * @param signImg
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public SecurityMonitoringOrderDO signIn(String orderId, String signTime, Integer signWay, String signLocation,
 | 
	
		
			
				|  |  |                                          String signImg, String twoDimensionalCode,String doctorId) throws Exception {
 | 
	
		
			
				|  |  |         SecurityMonitoringOrderDO doorServiceOrder = securityMonitoringOrderDao.findOne(orderId);
 | 
	
		
			
				|  |  |         doorServiceOrder.setDoctorSignTime(DateUtil.strToDate(signTime));
 | 
	
		
			
				|  |  |         doorServiceOrder.setDoctorSignWay(signWay);
 | 
	
		
			
				|  |  |         // 签到方式-2扫码时,需要去解析地址
 | 
	
		
			
				|  |  |         doorServiceOrder.setDoctorSignLocation(signLocation);
 | 
	
		
			
				|  |  |         doorServiceOrder.setDoctorSignImg(org.apache.commons.lang.StringUtils.isEmpty(signImg) ? null : signImg);
 | 
	
		
			
				|  |  |         doorServiceOrder.setStatus(SecurityMonitoringOrderDO.Status.signed.getType());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if(signWay == 4 ){//扫码签到
 | 
	
		
			
				|  |  |             if (twoDimensionalCode.equals(doorServiceOrder.getNumber())){
 | 
	
		
			
				|  |  |                 this.setUpdateColumnInfo(doorServiceOrder);
 | 
	
		
			
				|  |  |                 doorServiceOrder = securityMonitoringOrderDao.save(doorServiceOrder);
 | 
	
		
			
				|  |  |                 // 修改医生上门服务工单状态 4服务中
 | 
	
		
			
				|  |  |                 this.updateDispatchStatusBySystem(doorServiceOrder.getDoctor(), 4);//服务中
 | 
	
		
			
				|  |  |                 return doorServiceOrder;
 | 
	
		
			
				|  |  |             }else {
 | 
	
		
			
				|  |  |                 logger.info("扫码签到失败");
 | 
	
		
			
				|  |  |                 return null;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }else {
 | 
	
		
			
				|  |  |             this.setUpdateColumnInfo(doorServiceOrder);
 | 
	
		
			
				|  |  |             doorServiceOrder = securityMonitoringOrderDao.save(doorServiceOrder);
 | 
	
		
			
				|  |  |             // 修改医生上门服务工单状态 4服务中
 | 
	
		
			
				|  |  |             this.updateDispatchStatusBySystem(doorServiceOrder.getDoctor(), 4);
 | 
	
		
			
				|  |  |             return doorServiceOrder;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 根据接单医生code获取最近一次服务orderId
 | 
	
		
			
				|  |  |      * @param doctor
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public String getOrderIdByDoctor(String doctor) {
 | 
	
		
			
				|  |  |         String sql = "SELECT id as orderId from base_security_monitoring_order where doctor=? and status in(2,3,4,5,6,7) ORDER BY update_time desc,create_time desc, status ASC limit 1";
 | 
	
		
			
				|  |  |         String orderId = jdbcTemplate.queryForObject(sql, String.class, new Object[]{doctor});
 | 
	
		
			
				|  |  |         return orderId;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 编辑保存服务工单小结
 | 
	
		
			
				|  |  |      * @param model
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      * @throws Exception
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public SecurityMonitoringConclusionDO updateDoorConclusion(String model, Integer examPapeStatus) throws Exception {
 | 
	
		
			
				|  |  |         ObjectMapper objectMapper = new ObjectMapper();
 | 
	
		
			
				|  |  |         objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd"));
 | 
	
		
			
				|  |  |         SecurityMonitoringConclusionDO doorConclusion = objectMapper.readValue(model, SecurityMonitoringConclusionDO.class);
 | 
	
		
			
				|  |  |         SecurityMonitoringOrderDO one = securityMonitoringOrderDao.findOne(doorConclusion.getOrderId());
 | 
	
		
			
				|  |  |         BaseDoctorDO doctorVO = baseDoctorDao.findById(one.getDoctor());
 | 
	
		
			
				|  |  |         if (doorConclusion != null && org.apache.commons.lang.StringUtils.isNotEmpty(doorConclusion.getId())) {
 | 
	
		
			
				|  |  |             doorConclusion.setUpdateTime(new Date());
 | 
	
		
			
				|  |  |             doorConclusion.setUpdateUser(one.getDoctor());
 | 
	
		
			
				|  |  |             doorConclusion.setUpdateUserName(null != doctorVO ? doctorVO.getName() : null);
 | 
	
		
			
				|  |  |         } else {
 | 
	
		
			
				|  |  |             doorConclusion.setCreateTime(new Date());
 | 
	
		
			
				|  |  |             doorConclusion.setUpdateTime(new Date());
 | 
	
		
			
				|  |  |             doorConclusion.setCreateUser(one.getDoctor());
 | 
	
		
			
				|  |  |             doorConclusion.setCreateUserName(null != doctorVO ? doctorVO.getName() : null);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         securityMonitoringConclusionDao.save(doorConclusion);
 | 
	
		
			
				|  |  |         // 设置是否需要上传补录报告
 | 
	
		
			
				|  |  |         one.setStatus(SecurityMonitoringOrderDO.Status.registerSummary.getType());//已登记服务小结
 | 
	
		
			
				|  |  |         one.setExamPaperStatus(examPapeStatus);
 | 
	
		
			
				|  |  |         one.setConclusionStatus(2);
 | 
	
		
			
				|  |  |         securityMonitoringOrderDao.save(one);
 | 
	
		
			
				|  |  |         return doorConclusion;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 跳过登记服务小结
 | 
	
		
			
				|  |  |      * @param orderId
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public void cancelConclusion(String orderId) {
 | 
	
		
			
				|  |  |         securityMonitoringOrderDao.updateConclusionStatus(orderId);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 统计居民已经服务的次数
 | 
	
		
			
				|  |  |      * @param patient
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public Integer countPatientDoorTimes(String patient){
 | 
	
		
			
				|  |  |         Integer count = 0;
 | 
	
		
			
				|  |  |         String sql = "SELECT count(d.id) as count FROM base_security_monitoring_order o  where  o.patient = '" + patient + "' and status>3 ";
 | 
	
		
			
				|  |  |         count = jdbcTemplate.queryForObject(sql,Integer.class);
 | 
	
		
			
				|  |  |         return count;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 根据orderId获取工单服务小结
 | 
	
		
			
				|  |  |      * @param orderId
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public SecurityMonitoringConclusionDO getDoorConclusion(String orderId){
 | 
	
		
			
				|  |  |         SecurityMonitoringConclusionDO doorConclusion = securityMonitoringConclusionDao.findByOrderId(orderId);
 | 
	
		
			
				|  |  |         SecurityMonitoringOrderDO one = securityMonitoringOrderDao.findOne(orderId);
 | 
	
		
			
				|  |  |         if (doorConclusion==null&&one!=null) {
 | 
	
		
			
				|  |  |             doorConclusion = new SecurityMonitoringConclusionDO();
 | 
	
		
			
				|  |  |             doorConclusion.setOrderId(one.getId());
 | 
	
		
			
				|  |  |             doorConclusion.setPatient(one.getPatient());
 | 
	
		
			
				|  |  |             doorConclusion.setPatientName(one.getPatientName());
 | 
	
		
			
				|  |  |             doorConclusion.setDoctor(one.getDoctor());
 | 
	
		
			
				|  |  |             doorConclusion.setDoctorName(one.getDoctorName());
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return doorConclusion;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public SecurityMonitoringOrderDO saveOrderFinishBydoctor(String orderId ,String finishImg) throws Exception {
 | 
	
		
			
				|  |  |         SecurityMonitoringOrderDO one = securityMonitoringOrderDao.findOne(orderId);
 | 
	
		
			
				|  |  |         one.setDoctorConfirmFinishImg(finishImg);
 | 
	
		
			
				|  |  |         one.setStatus(SecurityMonitoringOrderDO.Status.complete.getType());
 | 
	
		
			
				|  |  |         one.setDoctorConfirmFinishFinishTime(new Date());
 | 
	
		
			
				|  |  |         // 更新记录
 | 
	
		
			
				|  |  |         this.setUpdateColumnInfo(one);
 | 
	
		
			
				|  |  |         // 计算保存服务总的支付费用
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         securityMonitoringOrderDao.save(one);
 | 
	
		
			
				|  |  |         SecurityMonitoringOrderDO doorServiceOrderDO = this.getDoorServiceOrderById(orderId);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 发送微信通知  待付款
 | 
	
		
			
				|  |  |         BasePatientDO patient = basePatientDao.findById(one.getPatient());
 | 
	
		
			
				|  |  |         // 获取微信模板 smfwdwk-上门服务待付款
 | 
	
		
			
				|  |  | //        Consult consult = consultDao.queryByRelationCode(orderId);
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  | //            WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_process_feedback","fwyspf");
 | 
	
		
			
				|  |  | //            String first = templateConfig.getFirst();
 | 
	
		
			
				|  |  | //            first = first.replace("key1", DateUtil.dateToStr(new Date(), "yyyy-MM-dd HH:mm"));
 | 
	
		
			
				|  |  | //            first = first .replace("key2", null != one.getDoctorName() ? one.getDoctorName() : "");
 | 
	
		
			
				|  |  | //            org.json.JSONObject json = new org.json.JSONObject();
 | 
	
		
			
				|  |  | //            json.put("first", first);
 | 
	
		
			
				|  |  | //            json.put("keyword1", DateUtil.dateToStrShort(new Date()));
 | 
	
		
			
				|  |  | //            json.put("keyword2", "服务医生评分");
 | 
	
		
			
				|  |  | //            json.put("url", templateConfig.getUrl());
 | 
	
		
			
				|  |  | //            json.put("remark", templateConfig.getRemark());
 | 
	
		
			
				|  |  | //            json.put("id",orderId);
 | 
	
		
			
				|  |  | //            //json.put("consult",consult.getCode());
 | 
	
		
			
				|  |  | //            WlyyDoorCommentDO wlyyDoorCommentDO = this.DoorCommentDao.selectCommentDoctor(patient.getCode(),orderId);
 | 
	
		
			
				|  |  | //            String finish="";
 | 
	
		
			
				|  |  | //            if(wlyyDoorCommentDO!=null){
 | 
	
		
			
				|  |  | //                finish = "0";
 | 
	
		
			
				|  |  | //                json.put("finish",finish);
 | 
	
		
			
				|  |  | //            }else {
 | 
	
		
			
				|  |  | //                finish = "1";
 | 
	
		
			
				|  |  | //                json.put("finish",finish);
 | 
	
		
			
				|  |  | //            }
 | 
	
		
			
				|  |  | //            pushMsgTask.putWxMsg(tokenUtils.getAccessToken(), 31, patient.getOpenid(), patient.getName(), json);
 | 
	
		
			
				|  |  |         }catch (Exception e){
 | 
	
		
			
				|  |  |             logger.error(e.getMessage());
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return doorServiceOrderDO;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 根据id获取服务工单信息
 | 
	
		
			
				|  |  |      * @param id
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public SecurityMonitoringOrderDO getDoorServiceOrderById(String id) throws Exception {
 | 
	
		
			
				|  |  |         SecurityMonitoringOrderDO doorServiceOrder = securityMonitoringOrderDao.findOne(id);
 | 
	
		
			
				|  |  |         if (null == doorServiceOrder) {
 | 
	
		
			
				|  |  |             return null;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         BasePatientDO patient = basePatientDao.findById(doorServiceOrder.getPatient());
 | 
	
		
			
				|  |  |         if (patient != null) {
 | 
	
		
			
				|  |  |             String sex = IdCardUtil.getSexForIdcard_new(patient.getIdcard());
 | 
	
		
			
				|  |  |             int age = IdCardUtil.getAgeByIdcardOrBirthday(patient.getIdcard(),patient.getBirthday());
 | 
	
		
			
				|  |  |             doorServiceOrder.setSex("1".equals(sex) ? "男" : "2".equals(sex) ? "女" : "未知");
 | 
	
		
			
				|  |  |             doorServiceOrder.setAge(age);
 | 
	
		
			
				|  |  |             doorServiceOrder.setPhoto(patient.getPhoto());
 | 
	
		
			
				|  |  | //            String typeValues = this.getTypeValueByPatientCode(patient.getCode());
 | 
	
		
			
				|  |  | //            doorServiceOrder.setTypeValue(typeValues);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         // 获取服务次数
 | 
	
		
			
				|  |  |         Integer count = 1;//本年服务次数 一年只能1次
 | 
	
		
			
				|  |  |         Integer times = countPatientDoorTimes(doorServiceOrder.getPatient());//服务次数
 | 
	
		
			
				|  |  | //        List<WlyyDoorDoctorDO> djDetailList = this.djDetailList(id,level,times);
 | 
	
		
			
				|  |  | //        doorServiceOrder.setDjDetailList(djDetailList);
 | 
	
		
			
				|  |  | //        List<Map<String, Object>> feeDetailDOS = this.getDoorFeeDetailGroupByStatus(id);
 | 
	
		
			
				|  |  | //        String jsonData = this.serverPackagePriceByOrderId(id);
 | 
	
		
			
				|  |  | //        if (null != feeDetailDOS && feeDetailDOS.size() > 0) {
 | 
	
		
			
				|  |  | //            // 设置服务项及费用信息
 | 
	
		
			
				|  |  | //            doorServiceOrder.setDoorFeeDetailList(feeDetailDOS);
 | 
	
		
			
				|  |  | //            //计算扣服务包后应付的服务项费用
 | 
	
		
			
				|  |  | //            /*Map<String, Object> map = this.countServerPackagePrice(jsonData, doorServiceOrder.getPatient());
 | 
	
		
			
				|  |  | //            BigDecimal cashPrice = this.calculateCash(String.valueOf(map.get("cashPrice")), id, level, times);
 | 
	
		
			
				|  |  | //            WlyyDoorServiceOrderDO wlyyDoorServiceOrderDO = this.doorServiceOrderDao.findOne(id);
 | 
	
		
			
				|  |  | //            if(wlyyDoorServiceOrderDO.getTotalFee()!=cashPrice){
 | 
	
		
			
				|  |  | //                wlyyDoorServiceOrderDO.setTotalFee(cashPrice);
 | 
	
		
			
				|  |  | //                wlyyDoorServiceOrderService.save(wlyyDoorServiceOrderDO);
 | 
	
		
			
				|  |  | //            }
 | 
	
		
			
				|  |  | //            map.put("cashPrice", cashPrice);
 | 
	
		
			
				|  |  | //            doorServiceOrder.setServiceCost(map);*/
 | 
	
		
			
				|  |  | //        }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 服务工单关联的医护人员
 | 
	
		
			
				|  |  | //        List<Map<String, Object>> doorServiceDoctors = this.getDoorServiceDoctor(id);
 | 
	
		
			
				|  |  | //        if (null != doorServiceDoctors && doorServiceDoctors.size() > 0) {
 | 
	
		
			
				|  |  | //            doorServiceOrder.setDoctors(doorServiceDoctors);
 | 
	
		
			
				|  |  | //        }
 | 
	
		
			
				|  |  |         // 设置医生出诊费信息,先获取工单出诊医生
 | 
	
		
			
				|  |  |         /*List<WlyyDoorDoctorDO> doorDoctorDOList = doorDoctorDao.findByOrderId(id);
 | 
	
		
			
				|  |  |         if (doorDoctorDOList != null && doorDoctorDOList.size() > 0) {
 | 
	
		
			
				|  |  |             Map<String,String> jobName = new HashMap<>();
 | 
	
		
			
				|  |  |             Map<String,String> jobCode = new HashMap<>();
 | 
	
		
			
				|  |  |             List<Integer> levels = new ArrayList<>();
 | 
	
		
			
				|  |  |             for(WlyyDoorDoctorDO doorDoctorDO : doorDoctorDOList){
 | 
	
		
			
				|  |  |                 jobName.put(doorDoctorDO.getDoctor(),doorDoctorDO.getDoctorJobName());
 | 
	
		
			
				|  |  |                 jobName.put(doorDoctorDO.getDoctor(),doorDoctorDO.getDoctorJobCode());
 | 
	
		
			
				|  |  |                 levels.add(doorDoctorDO.getHospitalLevel());
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             List<Map<String, Object>> jobFeeList = dmJobService.getJobFeeList(jobCode, jobName, levels, times);
 | 
	
		
			
				|  |  |             doorServiceOrder.setVisitCost(jobFeeList);
 | 
	
		
			
				|  |  |         }*/
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //获取咨询 //TODO 获取咨询
 | 
	
		
			
				|  |  | //        Consult consult = consultDao.queryByRelationCode(id);
 | 
	
		
			
				|  |  | //        if (null != consult) {
 | 
	
		
			
				|  |  | //            doorServiceOrder.setSessionId(doorServiceOrder.getPatient() + "_" + consult.getCode() + "_"  + doorServiceOrder.getNumber() +  "_" +  consult.getType());
 | 
	
		
			
				|  |  | //        }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 设置服务小结
 | 
	
		
			
				|  |  |         SecurityMonitoringConclusionDO doorConclusion = this.getDoorConclusion(id);
 | 
	
		
			
				|  |  |         doorServiceOrder.setMonitoringConclusion(doorConclusion);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         return doorServiceOrder;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     private String getRandomIntStr(){
 | 
	
		
			
				|  |  |         Random rand = new Random();
 | 
	
		
			
				|  |  |         int i = rand.nextInt(); //int范围类的随机数
 | 
	
		
			
				|  |  |         i = rand.nextInt(100); //生成0-100以内的随机数
 | 
	
		
			
				|  |  |         i = (int)(Math.random() * 100000000); //0-100以内的随机数,用Matn.random()方式
 | 
	
		
			
				|  |  |         return String.valueOf(i);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     private void setUpdateColumnInfo(SecurityMonitoringOrderDO one) {
 | 
	
		
			
				|  |  |         one.setUpdateTime(new Date());
 | 
	
		
			
				|  |  |         one.setUpdateUser(one.getDoctor());
 | 
	
		
			
				|  |  |         one.setUpdateUserName(one.getDoctorName());
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | }
 |