| 
					
				 | 
			
			
				@ -1,7 +1,9 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				package com.yihu.jw.care.service.security; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSON; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSONArray; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.serializer.SerializerFeature; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.fasterxml.jackson.databind.ObjectMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.dao.device.PatientDeviceDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.dao.security.*; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -29,10 +31,7 @@ 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; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * Created by Bing on 2021/4/6. 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -106,11 +105,20 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        BasePatientDO patientDO = basePatientDao.findById(orderDO.getPatient()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (patientDO==null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put("resultFlag", 0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String failMsg = "当前服务对象未建档"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put("resultMsg", failMsg); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            logger.error(failMsg); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //签约防走失服务包 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<ServicePackageRecordDO> signRecords = servicePackageService.servicePackageByPatient(orderDO.getPatient(),"3"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (signRecords.size()<0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (signRecords.size()==0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put("resultFlag", 0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String failMsg = "当前服务对象未完成签约,请完成签约后再预约服务!"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String failMsg = "当前服务对象未签约防走失服务包,请完成签约后再发起工单!"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put("resultMsg", failMsg); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            logger.error(failMsg); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return result; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -132,31 +140,59 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put("resultFlag", 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put("resultMsg",orderDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //创建咨询 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        org.json.JSONObject successOrNot = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            successOrNot = consultTeamService.addDoorServiceConsult(orderDO.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            successOrNot = null;//TODO 接单时创建两个人聊天 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String failMsg = "创建咨询时异常: " + e.getMessage(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject getSecurityOrderDetail(String orderID){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject result = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        SecurityMonitoringOrderDO orderDO = securityMonitoringOrderDao.findOne(orderID); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (orderDO==null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String failMsg = "工单不存在!"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            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()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Integer conclusionStatus = Integer.valueOf(orderDO.getConclusionStatus()==null?"0":(orderDO.getConclusionStatus()+"")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String conclusionStatusName = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        switch (conclusionStatus){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            case 1:conclusionStatusName="待补录";break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            case 2:conclusionStatusName="已登记";break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (conclusionStatus==2){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            SecurityMonitoringConclusionDO conclusionDO = securityMonitoringConclusionDao.findByOrderId(orderDO.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (conclusionDO!=null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                orderDO.setMonitoringConclusion(conclusionDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(orderDO, SerializerFeature.WriteMapNullValue)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        jsonObject.put("conclusionStatusName",conclusionStatusName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Integer statustemp = Integer.valueOf(orderDO.getStatus()+""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        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; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        jsonObject.put("statusName",statusName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put("resultFlag", 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put("resultMsg",jsonObject); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONArray getSecurityOrderList(String doctor, String patient, String status, Integer page, Integer pageSize){ 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -172,7 +208,7 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (StringUtils.isNotBlank(status)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sql+=" and ord.status='"+Integer.parseInt(status)+"' "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (StringUtils.isBlank(status)&&status.equals("1")){//状态为空或待处置时 查询该医生签约团队居民的预警 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (StringUtils.isBlank(status)||status.equals("1")){//状态为空或待处置时 查询该医生签约团队居民的预警 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        sql+=" order by ord.create_time desc limit " + (page*pageSize) + "," + pageSize; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -195,7 +231,7 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            tmp.put("doctorName",one.get("doctor_ame")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            tmp.put("patientPhone",one.get("patient_phone")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            tmp.put("conclusionStatus",one.get("conclusion_status")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Integer conclusionStatus = Integer.valueOf(one.get("conclusion_status")+""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Integer conclusionStatus = Integer.valueOf(one.get("conclusion_status")==null?"0":(one.get("conclusion_status")+"")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String conclusionStatusName = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            switch (conclusionStatus){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                case 1:conclusionStatusName="待补录";break; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -419,13 +455,10 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 取消工单 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param orderId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param type 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param reason 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param dispatcher 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param dispatcherName 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject cancelOrder(String orderId,int type,String reason,String dispatcher,String dispatcherName){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject cancelOrder(String orderId,int type,String reason,String doctor){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject result = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        SecurityMonitoringOrderDO orderDO = securityMonitoringOrderDao.findOne(orderId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(null == orderDO){ 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -436,6 +469,14 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //接单前可取消工单 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        BaseDoctorDO doctorDO = baseDoctorDao.findById(doctor); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (doctorDO==null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            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); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -443,6 +484,8 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            logger.error(failMsg); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        orderDO.setDoctor(doctor); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        orderDO.setDoctorName(doctorDO.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        orderDO.setCancelType(type); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        orderDO.setCancelTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        orderDO.setCancelReason(reason); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -494,7 +537,7 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        pushMsgTask.putWxMsg(tokenUtils.getAccessToken(), 30, patient.getOpenid(), patient.getName(), json); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put("resultFlag", 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put("resultMsg", "工单服务已取消!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put("resultMsg", orderDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -580,15 +623,17 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 编辑保存服务工单小结 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param model 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @throws Exception 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public SecurityMonitoringConclusionDO updateDoorConclusion(String model, Integer examPapeStatus) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public SecurityMonitoringConclusionDO updateDoorConclusion(Integer manageStatus,String orderId,String conclusion,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()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        SecurityMonitoringConclusionDO doorConclusion = new SecurityMonitoringConclusionDO(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        SecurityMonitoringOrderDO one = securityMonitoringOrderDao.findOne(orderId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (one==null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        BaseDoctorDO doctorVO = baseDoctorDao.findById(one.getDoctor()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (doorConclusion != null && org.apache.commons.lang.StringUtils.isNotEmpty(doorConclusion.getId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            doorConclusion.setUpdateTime(new Date()); 
			 |