Quellcode durchsuchen

add 新增监控所有主题

A17404李放 vor 3 Jahren
Ursprung
Commit
4a85200509

+ 5 - 1
coffee-common/src/main/java/com/coffee/common/config/websocket/DefaultMessageListener.java

@@ -1,7 +1,9 @@
 package com.coffee.common.config.websocket;
 
 import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
+import com.coffee.common.cache.value.Value;
 import com.coffee.common.config.websocket.handler.Subscribe;
 import com.coffee.common.config.websocket.handler.TopicWrapper;
 import com.fasterxml.jackson.core.JsonProcessingException;
@@ -44,7 +46,9 @@ public class DefaultMessageListener implements MessageListener {
                         }
                         String json = null;
                         try {
-                            json = objectMapper.writeValueAsString(MessageResponse.of(id, "result", topicWrapper.getParam(), JSONUtil.parse(message.toString())));
+                            JSONObject jsonObject = JSONUtil.parseObj(message.toString());
+                            json = objectMapper.writeValueAsString(MessageResponse.of(id, "result", Value.simple( jsonObject.get("param")).asString(),
+                                    JSONUtil.parse(jsonObject.get("message"))));
                             Tio.send(channel,WsResponse.fromText(json,"utf-8"));
                         } catch (JsonProcessingException e) {
                             log.error("ws消息订阅,解析失败,message:【】",message.toString());

+ 16 - 0
coffee-common/src/main/java/com/coffee/common/config/websocket/WebSocketConstant.java

@@ -15,11 +15,18 @@ public class WebSocketConstant {
 
     public static final String MONITOR_STATE_COUNT ="monitor-state-count";
 
+    /**
+     * 病人监控数量订阅
+     */
+    public static final String MONITOR_TOTAL_COUNT ="monitor-total-count";
+
     public static final String PATIENT_ADD ="patient-add";
 
     public static final String DEVICE_REPEAT ="device-repeat";
 
     public static final String DEVICE_NONE ="device-none";
+
+
     /**
      * 病人监控订阅
      */
@@ -53,6 +60,15 @@ public class WebSocketConstant {
         return getTopic(MONITOR_STATE_COUNT,null,null,tenantId);
     }
 
+    /**
+     * 获取 监控总数主题
+     * @param tenantId 设备所属医院
+     * @return
+     */
+    public static TopicWrapper getMonitorTotalCount(String tenantId){
+        return getTopic(MONITOR_TOTAL_COUNT,null,null,tenantId);
+    }
+
     /**
      * 获取 病人监护变化主题
      * @param productName

+ 3 - 1
coffee-system/src/main/java/com/coffee/bus/controller/BusPatientController.java

@@ -113,7 +113,9 @@ public class BusPatientController  implements BaseQueryController<BusPatientEnti
                       @RequestBody MonitorFinishedVo monitorFinishedVo,
                       @RequestAttribute("tenantId")@ApiParam(hidden = true) String tenantId){
         if(haveDevice){
-            return monitorFinished(monitorFinishedVo,tenantId);
+            R<Boolean> result = monitorFinished(monitorFinishedVo, tenantId);
+            wsPublishUtils.publishMonitorTotalCount(tenantId);
+            return result;
         }else {
             return manualFinished(monitorFinishedVo);
         }

+ 3 - 3
coffee-system/src/main/java/com/coffee/bus/service/LocalBusPatientService.java

@@ -91,7 +91,8 @@ public class LocalBusPatientService extends BaseService<BusPatientMapper, BusPat
         super.postSave(entity);
         //新增病人后推送主题,延迟推送,保证处理逻辑已全部完成
         executorService.schedule(()->{
-            wsPublishUtils.publishPatientAdd(entity.getCode(),entity.getTenantId());
+                    wsPublishUtils.publishPatientAdd(entity.getCode(),entity.getTenantId());
+                    wsPublishUtils.publishMonitorTotalCount(entity.getTenantId());
                 }
                 ,2, TimeUnit.SECONDS);
     }
@@ -205,8 +206,7 @@ public class LocalBusPatientService extends BaseService<BusPatientMapper, BusPat
         patientOperator.setWard(clinic.getWard());
 
         CompletableFuture.runAsync(()->{
-            wsPublishUtils.publish(WebSocketConstant.getPatientMonitor(null,patient.getCode(), patient.getTenantId()).getTopic(),
-                    patientService.lookMonitorByPatientCode(patient.getCode(),patient.getTenantId()));
+            wsPublishUtils.publishPatientMonitor(patient.getCode(),patient.getTenantId());
         });
     }
 

+ 102 - 9
coffee-system/src/main/java/com/coffee/bus/utils/WsPublishUtils.java

@@ -3,9 +3,13 @@ package com.coffee.bus.utils;
 
 import cn.hutool.json.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.coffee.bus.entity.BusClinicEntity;
 import com.coffee.bus.entity.BusPatientEntity;
 import com.coffee.bus.enums.PatientAlarmEnum;
+import com.coffee.bus.service.LocalBusClinicService;
 import com.coffee.bus.service.LocalBusPatientService;
+import com.coffee.bus.service.dto.MonitorStatusStatsCountResult;
+import com.coffee.bus.service.dto.PatientMonitorResult;
 import com.coffee.common.config.websocket.WebSocketConstant;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -14,6 +18,8 @@ import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Component;
 import org.springframework.util.Assert;
 
+import java.io.Serializable;
+
 /**
  * @author lifang
  * @version 1.0.0
@@ -27,8 +33,9 @@ import org.springframework.util.Assert;
 public class WsPublishUtils {
     private final RedisTemplate redisTemplate;
     private final LocalBusPatientService patientService;
-    @Async
-    public void publish(String topic,Object msg){
+    private final LocalBusClinicService clinicService;
+
+    private void publish(String topic,TopicMessage msg){
         redisTemplate.convertAndSend(topic,msg);
     }
 
@@ -43,8 +50,19 @@ public class WsPublishUtils {
     @Async
     public void publishPatientMonitor(String patientCode,String tenantId){
         Assert.hasText(tenantId,"医院id不能为空");
+        PatientMonitorResult message = patientService.lookMonitorByPatientCode(patientCode, tenantId);
         this.publish(WebSocketConstant.getPatientMonitor(null, patientCode, tenantId).getTopic(),
-                patientService.lookMonitorByPatientCode(patientCode,tenantId));
+                new TopicMessage<PatientMonitorResult>() {
+                    @Override
+                    public PatientMonitorResult getMessage() {
+                        return message;
+                    }
+                    @Override
+                    public String getParam() {
+                        return patientCode;
+                    }
+                }
+        );
     }
 
     /**
@@ -57,7 +75,17 @@ public class WsPublishUtils {
     @Async
     public void publishMonitorStateCount(String tenantId){
         Assert.hasText(tenantId,"医院id不能为空");
-        this.publish(WebSocketConstant.getMonitorStateCount(tenantId).getTopic(),patientService.statusStats(tenantId));
+        MonitorStatusStatsCountResult message = patientService.statusStats(tenantId);
+        this.publish(WebSocketConstant.getMonitorStateCount(tenantId).getTopic(),  new TopicMessage<MonitorStatusStatsCountResult>() {
+            @Override
+            public MonitorStatusStatsCountResult getMessage() {
+                return message;
+            }
+            @Override
+            public String getParam() {
+                return tenantId;
+            }
+        });
     }
 
     /**
@@ -70,8 +98,18 @@ public class WsPublishUtils {
     @Async
     public void publishPatientAdd(String patientCode,String tenantId){
         Assert.hasText(tenantId,"医院id不能为空");
+        JSONObject message = new JSONObject().putOpt("patientCode", patientCode);
         this.publish(WebSocketConstant.getPatientAdd(tenantId).getTopic(),
-                new JSONObject().putOpt("patientCode",patientCode));
+                new TopicMessage<JSONObject>() {
+                    @Override
+                    public JSONObject getMessage() {
+                        return message;
+                    }
+                    @Override
+                    public String getParam() {
+                        return tenantId;
+                    }
+                });
     }
     /**
      * 描述: 推送医院临床设备重复数量统计
@@ -83,9 +121,19 @@ public class WsPublishUtils {
     @Async
     public void publishDeviceRepeat(String tenantId){
         Assert.hasText(tenantId,"医院id不能为空");
+        JSONObject message = new JSONObject().putOpt("count", patientService.count(new QueryWrapper<BusPatientEntity>().lambda().eq(BusPatientEntity::getTenantId, tenantId)
+                .eq(BusPatientEntity::getAlarm, PatientAlarmEnum.DEVICE_REPEAT)));
         this.publish(WebSocketConstant.getDeviceRepeat(tenantId).getTopic(),
-                new JSONObject().putOpt("count",   patientService.count(new QueryWrapper<BusPatientEntity>().lambda().eq(BusPatientEntity::getTenantId,tenantId)
-                        .eq(BusPatientEntity::getAlarm, PatientAlarmEnum.DEVICE_REPEAT)))
+                new TopicMessage<JSONObject>() {
+                    @Override
+                    public JSONObject getMessage() {
+                        return message;
+                    }
+                    @Override
+                    public String getParam() {
+                        return tenantId;
+                    }
+                }
         );
     }
 
@@ -99,9 +147,54 @@ public class WsPublishUtils {
     @Async
     public void publishDeviceNone(String tenantId){
         Assert.hasText(tenantId,"医院id不能为空");
+        JSONObject message = new JSONObject().putOpt("count", patientService.count(new QueryWrapper<BusPatientEntity>()
+                .lambda().eq(BusPatientEntity::getTenantId, tenantId)
+                .eq(BusPatientEntity::getAlarm, PatientAlarmEnum.DEVICE_NONE)));
         this.publish(WebSocketConstant.getDeviceNone(tenantId).getTopic(),
-                new JSONObject().putOpt("count",  patientService.count(new QueryWrapper<BusPatientEntity>().lambda().eq(BusPatientEntity::getTenantId,tenantId)
-                        .eq(BusPatientEntity::getAlarm, PatientAlarmEnum.DEVICE_NONE)))
+                new TopicMessage<JSONObject>() {
+                    @Override
+                    public JSONObject getMessage() {
+                        return message;
+                    }
+                    @Override
+                    public String getParam() {
+                        return tenantId;
+                    }
+                }
+        );
+    }
+
+
+    /**
+     * 描述: 推送临床设备总数量统计
+     * @author lifang
+     * @date 2022/5/13 9:39
+     * @param
+     * @return void
+     */
+    @Async
+    public void publishMonitorTotalCount(String tenantId){
+        Assert.hasText(tenantId,"医院id不能为空");
+        JSONObject message = new JSONObject().putOpt("count", clinicService.count(new QueryWrapper<BusClinicEntity>().lambda()
+                .eq(BusClinicEntity::getMonitorType,true)
+                .eq(BusClinicEntity::getTenantId,tenantId)
+                .eq(BusClinicEntity::getFinished,false)));
+        this.publish(WebSocketConstant.getMonitorTotalCount(tenantId).getTopic(),
+                new TopicMessage<JSONObject>() {
+                    @Override
+                    public JSONObject getMessage() {
+                        return message;
+                    }
+                    @Override
+                    public String getParam() {
+                        return tenantId;
+                    }
+                }
         );
     }
+
+    public interface TopicMessage<T> extends Serializable {
+        T getMessage();
+        String getParam();
+    }
 }

+ 32 - 0
coffee-system/src/main/java/com/coffee/bus/websocket/MonitorTotalCountHandler.java

@@ -0,0 +1,32 @@
+package com.coffee.bus.websocket;
+
+import com.coffee.common.config.websocket.WebSocketConstant;
+import com.coffee.common.config.websocket.handler.Subscribe;
+import org.springframework.stereotype.Component;
+import org.tio.core.ChannelContext;
+
+/**
+ * @author lifang
+ * @version 1.0.0
+ * @ClassName DeviceStateCountHandler.java
+ * @Description 监控总数量变化订阅
+ * @createTime 2022年03月25日 14:21:00
+ */
+@Component
+public class MonitorTotalCountHandler extends Subscribe {
+
+    @Override
+    public String getId() {
+        return WebSocketConstant.MONITOR_TOTAL_COUNT;
+    }
+
+    @Override
+    public void close(ChannelContext channelContext) {
+
+    }
+
+    @Override
+    public boolean needParam() {
+        return false;
+    }
+}

+ 1 - 1
coffee-system/src/main/resources/mapper/bus/BusPatientMapper.xml

@@ -94,7 +94,7 @@
     </resultMap>
     <select id="selectRepeatDevice" resultMap="repeatDeviceResult">
                  SELECT
-         p.code,
+         p.code as code,
          c.patient_gender  as gender,
          c.`patient_name` as name,
          c.patient_age as age,

+ 32 - 0
pom.xml

@@ -37,6 +37,7 @@
         <tio.version>3.6.0.v20200315-RELEASE</tio.version>
         <jython.version>2.7.1</jython.version>
         <knife4j.version>2.0.7</knife4j.version>
+        <docker.location>192.168.100.32</docker.location>
     </properties>
 
     <modules>
@@ -222,6 +223,37 @@
         </resources>
         <pluginManagement>
             <plugins>
+                <!--docker 打包插件-->
+                <plugin>
+                    <groupId>com.spotify</groupId>
+                    <artifactId>docker-maven-plugin</artifactId>
+                    <version>1.2.2</version>
+                    <executions>
+                        <execution>
+                            <id>build-image</id>
+                            <phase>package</phase>
+                            <goals>
+                                <goal>build</goal>
+                            </goals>
+                        </execution>
+                    </executions>
+                    <configuration>
+                        <imageTags>
+                            <imageTag>latest</imageTag>
+                        </imageTags>
+                        <imageName>${project.artifactId}</imageName>
+                        <dockerHost>${docker.location}</dockerHost>
+                        <dockerDirectory>${project.basedir}</dockerDirectory>
+                        <!-- 这里是复制 jar 包到 docker 容器指定目录配置,也可以写到 Docokerfile 中 -->
+                        <!--                    <resources>
+                                                <resource>
+                                                    <targetPath>/</targetPath>
+                                                    <directory>${project.build.directory}</directory>
+                                                    <include>${project.build.finalName}.jar</include>
+                                                </resource>
+                                            </resources>-->
+                    </configuration>
+                </plugin>
                 <plugin>
                     <groupId>org.springframework.boot</groupId>
                     <artifactId>spring-boot-maven-plugin</artifactId>