| 
					
				 | 
			
			
				@@ -1,5 +1,6 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 package thyyxxk.webserver.service.triage; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.alibaba.fastjson.JSON; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.baomidou.mybatisplus.core.metadata.IPage; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import lombok.extern.slf4j.Slf4j; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -16,6 +17,8 @@ import thyyxxk.webserver.entity.triage.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import thyyxxk.webserver.utils.ResultVoUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import thyyxxk.webserver.utils.StringUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import thyyxxk.webserver.utils.TokenUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import thyyxxk.webserver.utils.VoiceUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import thyyxxk.webserver.websocket.WebSocketServer; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -53,6 +56,11 @@ public class TriageService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return ResultVoUtil.success(dao.getTriagedPatients(depts)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public ResultVo<List<MzfzPatientOrder>> getTreatedPatients() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String[] depts = StringUtil.triageDeptString2Array(dao.selectChosenDepts(TokenUtil.getTokenUserId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return ResultVoUtil.success(dao.getTreatedPatients(depts)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public ResultVo<List<FloorScreen>> getBigScreenData(Boolean fullName) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         String[] depts = StringUtil.triageDeptString2Array(dao.selectChosenDepts(TokenUtil.getTokenUserId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         List<MzfzPatientOrder> list = dao.getBigScreenData(depts); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -123,17 +131,18 @@ public class TriageService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         dao.updatePatientNum(room.getDeptCode(), room.getRoomCode(), patientNum); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         dao.fenZhen(room); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        log.info("分诊:update mzfz_patient_order set status_flag=1, slow_flag=0, " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        "dept_code={}, room_code={}, doctor_code={}, fz_no={} where serial_no={}", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        log.info("分诊:update mzfz_patient_order set status_flag=1, slow_flag=0, dept_code={}, room_code={}, " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        "doctor_code={}, fz_no={}, fz_flag={} where serial_no={}", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 room.getDeptCode(), room.getRoomCode(), room.getDoctorCode(), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                room.getPatientNum(), room.getSerialNo()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        PatientSidContainer.getInstance().put(room.getSerialNo(), TokenUtil.getTokenUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                room.getPatientNum(), room.getFuzhenFlag(), room.getSerialNo()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        dao.deleteNotifyRelation(room.getSerialNo()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        dao.insertNotifyRelation(room.getSerialNo(), TokenUtil.getTokenUserId(), room.getRoomCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return ResultVoUtil.success("分诊成功。"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public ResultVo<Boolean> notifyComplete(Integer serialNo) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void notifyComplete(Integer serialNo) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         log.info("通知完毕>>> {}", serialNo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return ResultVoUtil.success(PatientSidContainer.getInstance().delete(serialNo)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        dao.updateNotifyDatetime(serialNo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public ResultVo<Integer> fuZhen(Integer serialNo) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -142,7 +151,7 @@ public class TriageService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public ResultVo<Integer> cancelTriage(Integer serialNo) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         Integer ret = dao.cancelTriage(serialNo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        PatientSidContainer.getInstance().delete(serialNo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        dao.deleteNotifyRelation(serialNo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return ResultVoUtil.success(ret); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -179,26 +188,37 @@ public class TriageService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public ResultVo<String> notifyMessage(MessageForPush param) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        MessageForPush prm = dao.selectMessageForPush(param.getSerialNo()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (null == prm) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        MessageForPush messageForPush = dao.selectMessageForPush(param.getSerialNo()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (null == messageForPush) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "没有找到此患者的分诊信息!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        prm.setAction(param.getAction()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        log.info("消息推送>>> {}", prm); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        RestTemplate template = new RestTemplate(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        String result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            result = template.postForObject(triageNotifyUrl, prm, String.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (param.getAction() == 1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (null != result && result.equals("0")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                dao.updateStatus(param.getSerialNo()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                log.error("消息推送失败,没有找到在线的分诊台连接。{}", prm); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        return ResultVoUtil.success(result); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        messageForPush.setAction(param.getAction()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String text = String.format("请%s号%s,到%s%s号诊室就诊。", messageForPush.getFzNo(), messageForPush.getName(), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                messageForPush.getDeptName(), messageForPush.getRoomNo()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        log.info("消息推送>>> {}\n{}", messageForPush, text); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // todo 下面这部分在完成迁移后启用 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        VoiceUtil.textToSpeech(text, String.valueOf(param.getSerialNo())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        final String msg = JSON.toJSONString(messageForPush); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        TriageNotifyRelation notifyRelation = dao.selectTriageNotifyRelation(messageForPush.getSerialNo()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        WebSocketServer.sendFloorTriageMessage(notifyRelation.getSocketSid(), msg); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        WebSocketServer.sendRoomTriageMessage(notifyRelation.getRoomCode(), msg); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        dao.updateNotifyDatetime(param.getSerialNo()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return ResultVoUtil.success(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // todo 下面这一部分在完成迁移后删除 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//        RestTemplate template = new RestTemplate(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//        String result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            result = template.postForObject(triageNotifyUrl, messageForPush, String.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//        } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//        if (param.getAction() == 1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            if (null != result && result.equals("0")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                dao.updateStatus(param.getSerialNo()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                log.error("消息推送失败,没有找到在线的分诊台连接。{}", messageForPush); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//        return ResultVoUtil.success(result); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |