Browse Source

完成消息推送

xiaochan 3 years ago
parent
commit
4a51c83932

+ 21 - 5
src/main/java/thyyxxk/webserver/dao/his/PublicDao.java

@@ -2,14 +2,12 @@ package thyyxxk.webserver.dao.his;
 
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.toolkit.Constants;
-import org.apache.ibatis.annotations.Mapper;
-import org.apache.ibatis.annotations.Param;
-import org.apache.ibatis.annotations.Select;
-import org.apache.ibatis.annotations.Update;
+import org.apache.ibatis.annotations.*;
 import thyyxxk.webserver.entity.casefrontsheet.YshHzRecord;
 import thyyxxk.webserver.entity.datamodify.GetDropdownBox;
 import thyyxxk.webserver.entity.datamodify.ZyDetailCharge;
 import thyyxxk.webserver.entity.login.UserInfo;
+import thyyxxk.webserver.entity.socketmessage.SocketMessage;
 import thyyxxk.webserver.entity.yibao.ZyActpatient;
 import thyyxxk.webserver.entity.zhuyuanyisheng.caoyaoyizhu.YzActOrderCy;
 import thyyxxk.webserver.entity.zhuyuanyisheng.jianyanjiancha.YshYjReq;
@@ -375,7 +373,25 @@ public interface PublicDao {
     @Select("select code " +
             "from a_employee_mi " +
             "where dept_code = #{wardCode} " +
-            "  and isnull(del_flag, '0') <> '1'")
+            "  and isnull(del_flag, 0) <> 1 ")
     List<String> huoQuHuanZheBingFangDeHuShi(String wardCode);
 
+
+    @Insert({"<script>" +
+            "insert t_socket_message (id,sender, title, content,  pat_id) values " +
+            "<foreach collection='list' item='item' separator=','>" +
+            "(#{item.id},#{item.sender},#{item.title},#{item.content},#{item.patId})" +
+            "</foreach>" +
+            "</script>"})
+    void chaRuTongZhiXinXi(@Param("list") List<SocketMessage> list);
+
+
+    @Insert({"<script>" +
+            "insert into t_socket_message_consumer (msg_id, sender, receiver) values " +
+            "<foreach collection='list' item='item' separator=','>" +
+            " (#{item.msgId}, #{item.sender}, #{item.receiver})" +
+            "</foreach>" +
+            "</script>"})
+    void chaRuJieShouShuJu(@Param("list") List<SocketMessage> list);
+
 }

+ 7 - 5
src/main/java/thyyxxk/webserver/dao/his/zhuyuanyisheng/YiZhuLuRuDao.java

@@ -457,14 +457,16 @@ public interface YiZhuLuRuDao {
     List<XinZhenYzActOrder> huoQuXiangMuXinXi(Set<String> code);
 
 
-    @Select("select inpatient_no, " +
-            "       admiss_times, " +
-            "       dept dept_code, " +
-            "       zk_ward ward_code, " +
+    @Select("select rtrim(inpatient_no) inpatient_no, " +
+            "       admiss_times," +
+            "       rtrim(name) name, " +
+            "       rtrim(dept) dept_code, " +
+            "       rtrim(zk_ward) ward_code, " +
             "       refer_physician," +
             "       times_billed," +
             "       admiss_date," +
-            "       small_dept " +
+            "       small_dept," +
+            "       bed_no  " +
             "from zy_actpatient with (NOLOCK) " +
             "where inpatient_no = #{patNo} " +
             "  and admiss_times = #{times} ")

+ 7 - 5
src/main/java/thyyxxk/webserver/entity/socketmessage/SocketMessage.java

@@ -2,14 +2,16 @@ package thyyxxk.webserver.entity.socketmessage;
 
 import lombok.Data;
 
+import java.io.Serializable;
 import java.util.Date;
 
 @Data
-public class SocketMessage {
+public class SocketMessage implements Serializable {
+    private static final long serialVersionUID = -4378278558126695269L;
     /**
-     * websocket通知 主键 id
+     * 雪花算法 主键
      */
-    private Integer id;
+    private String id;
     /**
      * 等级 0-普通通知 1-重要通知
      */
@@ -39,13 +41,13 @@ public class SocketMessage {
      */
     private String patId;
     /**
-     * 接受消息 自增id
+     * 雪花算法 消息外键
      */
     private Integer tid;
     /**
      * 消息外键
      */
-    private Integer msgId;
+    private String msgId;
     /**
      * 消息接受人
      */

+ 4 - 0
src/main/java/thyyxxk/webserver/entity/zhuyuanyisheng/yizhuluru/XinZhenYiZhu.java

@@ -16,6 +16,10 @@ import java.util.List;
  */
 @Data
 public class XinZhenYiZhu {
+    /**
+     * 患者姓名
+     */
+    private String name;
     private String inpatientNo;
     private Integer admissTimes;
     /**

+ 30 - 4
src/main/java/thyyxxk/webserver/service/PublicServer.java

@@ -17,6 +17,7 @@ import thyyxxk.webserver.entity.casefrontsheet.YshHzRecord;
 import thyyxxk.webserver.entity.datamodify.GetDropdownBox;
 import thyyxxk.webserver.entity.datamodify.ZyDetailCharge;
 import thyyxxk.webserver.entity.login.UserInfo;
+import thyyxxk.webserver.entity.socketmessage.SocketMessage;
 import thyyxxk.webserver.entity.yibao.ZyActpatient;
 import thyyxxk.webserver.entity.zhuyuanyisheng.caoyaoyizhu.YzActOrderCy;
 import thyyxxk.webserver.entity.zhuyuanyisheng.jianyanjiancha.YshYjReq;
@@ -533,17 +534,42 @@ public class PublicServer {
      * @param title    标题
      * @param patId    患者组合id(住院号_住院次数)
      */
-    public void faSongXiaoXi(String wardCode, List<String> content, String title, String patId) {
+    public void faSongXiaoXi(String wardCode, List<String> content, String title, String patId, String userCode) {
         List<String> huShiBianMa = dao.huoQuHuanZheBingFangDeHuShi(wardCode);
         JSONObject obj = new JSONObject();
         obj.put("name", "systemNotification");
         obj.put("type", "error");
         obj.put("message", "您有新的通知请及时查看。");
         String message = obj.toJSONString();
-        for (String s : huShiBianMa) {
-            WebSocketServer.sendMessageByUserCode(s, message);
+        // 发送通知类
+        List<SocketMessage> socketMessage1 = new ArrayList<>();
+        List<SocketMessage> socketMessage2 = new ArrayList<>();
+        for (String s : content) {
+            SocketMessage faSongNeiRong = new SocketMessage();
+            faSongNeiRong.setSender(userCode);
+            faSongNeiRong.setContent(s);
+            // 雪花算法
+            faSongNeiRong.setId(SnowFlakeId.instance().nextId());
+            faSongNeiRong.setPatId(patId);
+            faSongNeiRong.setTitle(title);
+            socketMessage1.add(faSongNeiRong);
+            for (String huShi : huShiBianMa) {
+                SocketMessage jieShouFang = new SocketMessage();
+                jieShouFang.setMsgId(faSongNeiRong.getId());
+                jieShouFang.setSender(faSongNeiRong.getSender());
+                jieShouFang.setReceiver(huShi);
+                socketMessage2.add(jieShouFang);
+            }
         }
-
+        List<List<SocketMessage>> fenGeFaSongFang = ListUtils.partition(socketMessage1, 20);
+        List<List<SocketMessage>> fenGeJieShouFang = ListUtils.partition(socketMessage2, 20);
+        for (List<SocketMessage> item : fenGeFaSongFang) {
+            dao.chaRuTongZhiXinXi(item);
+        }
+        for (List<SocketMessage> item : fenGeJieShouFang) {
+            dao.chaRuJieShouShuJu(item);
+        }
+        huShiBianMa.forEach(code -> WebSocketServer.sendMessageByUserCode(code, message));
 
     }
 

+ 1 - 1
src/main/java/thyyxxk/webserver/service/zhuyuanyisheng/CaoYaoYiZhuServer.java

@@ -152,7 +152,7 @@ public class CaoYaoYiZhuServer {
         param.setOrderNo(BigDecimal.valueOf(publicServer.getActOrderNo()));
         dao.chaRuCaoYaoYiZhu(param, huanZheXinXi.getDeptCode(), huanZheXinXi.getDeptCode(), huanZheXinXi.getSmallDept());
         dao.chaRuCaoYaoXiangQing(param.getList(), param.getOrderNo());
-        dao.chaRuYiZhu(param, "草药医嘱:" + param.getOrderName() + param.getQuantity() + "剂", huanZheXinXi.getDeptCode(), huanZheXinXi.getWardCode(), huanZheXinXi.getSmallDept(), publicServer.getInfantFlag(huanZheXinXi.getInpatientNo()));
+        dao.chaRuYiZhu(param, "草药医嘱:" + param.getOrderName() + param.getQuantity() + "剂", huanZheXinXi.getDeptCode(), huanZheXinXi.getDeptCode(), huanZheXinXi.getSmallDept(), publicServer.getInfantFlag(huanZheXinXi.getInpatientNo()));
         return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
     }
 

+ 2 - 2
src/main/java/thyyxxk/webserver/service/zhuyuanyisheng/JianYanJianChaShenQingServer.java

@@ -415,8 +415,8 @@ public class JianYanJianChaShenQingServer {
         }
         String userCode = TokenUtil.getTokenUserId();
         dao.chaRuShenQing(param.getList(), param.getInpatientNo(), param.getName(), param.getAge() + "岁", param.getAdmissTimes(),
-                param.getBedNo(), userCode, huanZheXinXi.getDeptCode(), huanZheXinXi.getWardCode(), param.getReqType());
-        dao.chaRuShenQingYiZhu(param.getList(), param.getInpatientNo(), param.getAdmissTimes(), userCode, huanZheXinXi.getDeptCode(), huanZheXinXi.getWardCode(),
+                param.getBedNo(), userCode, huanZheXinXi.getDeptCode(), huanZheXinXi.getDeptCode(), param.getReqType());
+        dao.chaRuShenQingYiZhu(param.getList(), param.getInpatientNo(), param.getAdmissTimes(), userCode, huanZheXinXi.getDeptCode(), huanZheXinXi.getDeptCode(),
                 publicServer.getInfantFlag(param.getInpatientNo()));
         log.info("数据:{}", param.getList());
         return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);

+ 2 - 2
src/main/java/thyyxxk/webserver/service/zhuyuanyisheng/ShouShuShenQingServer.java

@@ -126,11 +126,11 @@ public class ShouShuShenQingServer {
         XinZhenYiZhu huanZheXinXi = yiZhuLuRuDao.huoQuHuanZheXinXi(param.getInpatientNo(), param.getAdmissTimes());
         dao.chaRuShouShuYiSheng(param.getList());
         dao.chaRuShouShu(param.getList(), param.getInpatientNo(), param.getName(), param.getAdmissTimes(),
-                huanZheXinXi.getDeptCode(), huanZheXinXi.getWardCode(), userCode, param.getBedNo(), param.getAdmissWard());
+                huanZheXinXi.getDeptCode(), huanZheXinXi.getDeptCode(), userCode, param.getBedNo(), param.getAdmissWard());
 
         if (ListUtil.notBlank(shenChengYiZhu)) {
             dao.chaRuYiZhu(shenChengYiZhu, publicServer.getInfantFlag(param.getInpatientNo()),
-                    userCode, param.getInpatientNo(), param.getAdmissTimes(), huanZheXinXi.getDeptCode(), huanZheXinXi.getWardCode(), param.getExecDept());
+                    userCode, param.getInpatientNo(), param.getAdmissTimes(), huanZheXinXi.getDeptCode(), huanZheXinXi.getDeptCode(), param.getExecDept());
         }
         return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
     }

+ 28 - 4
src/main/java/thyyxxk/webserver/service/zhuyuanyisheng/YiZhuLuRuServer.java

@@ -36,10 +36,12 @@ import java.util.stream.Collectors;
 @Slf4j
 public class YiZhuLuRuServer {
 
+
     private final YiZhuLuRuDao dao;
     private final PatientService patientService;
     private final PublicServer publicServer;
 
+
     public YiZhuLuRuServer(YiZhuLuRuDao dao, PatientService service, PublicServer publicServer) {
         this.dao = dao;
         this.patientService = service;
@@ -504,16 +506,22 @@ public class YiZhuLuRuServer {
         if (huanZheXinXi == null) {
             throw new BizException(ExceptionEnum.LOGICAL_ERROR, "没有查询到患者的在院信息。");
         }
+
         huanZheXinXi.setInfantFlag(publicServer.getInfantFlag(huanZheXinXi.getInpatientNo()));
         publicServer.huanZheJieSuan(param.getInpatientNo(), param.getAdmissTimes());
         if (ListUtil.notBlank(kssList)) {
             dao.shanChuYuanKuangJunYaoWu(kssList);
             dao.chaRuKuangJunYaoWuXinXi(huanZheXinXi.getInpatientNo(), huanZheXinXi.getAdmissTimes(), inputCode, kssList);
         }
+        List<String> content = new ArrayList<>();
         dao.chaRuYiZhu(huanZheXinXi.getInpatientNo(), huanZheXinXi.getAdmissTimes(), inputCode, huanZheXinXi.getInfantFlag(), publicServer.getGroupNo(),
-                huanZheXinXi.getWardCode(), huanZheXinXi.getWardCode(), huanZheXinXi.getReferPhysician(), param.getList());
-
-
+                huanZheXinXi.getDeptCode(), huanZheXinXi.getDeptCode(), huanZheXinXi.getReferPhysician(), param.getList());
+        for (XinZhenYzActOrder item : param.getList()) {
+            content.add(String.format("医嘱名:<span style='color:#409eff'>【%s】</span><br>医嘱时间:<span style='color:#409eff'>【%tF %<tT】</span><br>患者姓名:<span style='color:#409eff'>【%s】</span><br>床位:<span style='color:#409eff'>【%s】</span><br>频次:<span style='color:#409eff'>【%s】</span>",
+                    item.getOrderName(), item.getOrderTime(), huanZheXinXi.getName(), huanZheXinXi.getBedNo(), item.getFrequCode()));
+        }
+        FaSongXiaoXi faSongXiaoXi = new FaSongXiaoXi(content, huanZheXinXi, inputCode);
+        new Thread(faSongXiaoXi).start();
         return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "医嘱保存成功。");
     }
 
@@ -709,7 +717,6 @@ public class YiZhuLuRuServer {
         return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "你想干什么?");
     }
 
-
     public ResultVo<String> sheZhiJinJi(YzActOrder yz) {
         String emergencyFlag = null;
         if (yz.getEmergencyFlag() == null || !yz.getEmergencyFlag().trim().equals("1")) {
@@ -807,5 +814,22 @@ public class YiZhuLuRuServer {
         return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
     }
 
+    class FaSongXiaoXi implements Runnable {
+        private final List<String> content;
+        private final XinZhenYiZhu yiZhu;
+        private final String userCode;
+
+        public FaSongXiaoXi(List<String> content, XinZhenYiZhu yiZhu, String userCode) {
+            this.content = content;
+            this.yiZhu = yiZhu;
+            this.userCode = userCode;
+        }
+
+        @Override
+        public void run() {
+            publicServer.faSongXiaoXi(yiZhu.getDeptCode(), content, "新增医嘱", yiZhu.getInpatientNo() + "_" + yiZhu.getAdmissTimes(), userCode);
+        }
+    }
+
 
 }

+ 1 - 1
src/main/java/thyyxxk/webserver/utils/BigUtils.java

@@ -4,7 +4,7 @@ import java.math.BigDecimal;
 
 /**
  * <p>
- * 描述: BigDecimal 的一些工具
+ * 描述: BigDecimal 判断大小
  * </p>
  *
  * @author xc

+ 15 - 18
src/main/java/thyyxxk/webserver/utils/SnowFlakeId.java

@@ -4,23 +4,18 @@ package thyyxxk.webserver.utils;
  * @author dj
  */
 public class SnowFlakeId {
+    private static SnowFlakeId INSTANCE;
     //下面两个每个5位,加起来就是10位的工作机器id
     private final long workerId;
     private final long datacenterId;
+    //长度为5位
+    private final long workerIdBits = 5L;
+    private final long datacenterIdBits = 5L;
     //12位的序列号
     private long sequence;
-    private static SnowFlakeId INSTANCE;
-
-    public static SnowFlakeId instance() {
-        synchronized (SnowFlakeId.class) {
-            if (null == INSTANCE) {
-                INSTANCE = new SnowFlakeId(1, 1, 2011140217L);
-            }
-        }
-        return INSTANCE;
-    }
-
-    private SnowFlakeId(long workerId, long datacenterId, long sequence){
+    //上次时间戳,初始值为负数
+    private long lastTimestamp = -1L;
+    private SnowFlakeId(long workerId, long datacenterId, long sequence) {
         //最大值
         long maxWorkerId = ~(-1L << workerIdBits);
         if (workerId > maxWorkerId || workerId < 0) {
@@ -37,12 +32,14 @@ public class SnowFlakeId {
         this.sequence = sequence;
     }
 
-    //长度为5位
-    private final long workerIdBits = 5L;
-    private final long datacenterIdBits = 5L;
-
-    //上次时间戳,初始值为负数
-    private long lastTimestamp = -1L;
+    public static SnowFlakeId instance() {
+        synchronized (SnowFlakeId.class) {
+            if (null == INSTANCE) {
+                INSTANCE = new SnowFlakeId(1, 1, 2011140217L);
+            }
+        }
+        return INSTANCE;
+    }
 
     //下一个ID生成算法
     public synchronized String nextId() {