Bladeren bron

add:
阿里云多数据源订阅

18339543638 1 jaar geleden
bovenliggende
commit
1a908c1ed7
32 gewijzigde bestanden met toevoegingen van 423 en 1044 verwijderingen
  1. 5 54
      nb-admin/pom.xml
  2. 27 13
      nb-admin/src/main/resources/application-dev.yml
  3. 3 2
      nb-admin/src/main/resources/application.yml
  4. 1 5
      nb-admin/src/test/java/com/nb/admin/BusNetpumpTest.java
  5. 6 0
      nb-service-api/web-service-api/src/main/java/com/nb/web/api/entity/common/BusDeviceRunningEntity.java
  6. 1 1
      nb-service-api/web-service-api/src/main/java/com/nb/web/api/enums/DeviceTypeEnum.java
  7. 5 5
      nb-service-api/web-service-api/src/main/java/com/nb/web/api/utils/DeviceTypeUtils.java
  8. 6 0
      nb-service/iot-service/pom.xml
  9. 47 0
      nb-service/iot-service/src/main/java/com/nb/aliyun/service/AliConsumerAutoConfiguration.java
  10. 0 205
      nb-service/iot-service/src/main/java/com/nb/aliyun/service/AliyunIotSubscribeClient.java
  11. 0 33
      nb-service/iot-service/src/main/java/com/nb/aliyun/service/PlatformLog.java
  12. 0 12
      nb-service/iot-service/src/main/java/com/nb/aliyun/service/PlatformType.java
  13. 0 18
      nb-service/iot-service/src/main/java/com/nb/aliyun/service/bean/AliIotConfig.java
  14. 25 0
      nb-service/iot-service/src/main/java/com/nb/aliyun/service/consumer/AbstractAliConsumer.java
  15. 161 0
      nb-service/iot-service/src/main/java/com/nb/aliyun/service/consumer/AliIotSubscribeClient.java
  16. 30 57
      nb-service/iot-service/src/main/java/com/nb/aliyun/service/consumer/NBAndFourGConsumerGroupService.java
  17. 24 0
      nb-service/iot-service/src/main/java/com/nb/aliyun/service/pojo/AliIotConfigPojo.java
  18. 27 0
      nb-service/iot-service/src/main/java/com/nb/aliyun/service/pojo/AliIotConsumerPojo.java
  19. 16 0
      nb-service/iot-service/src/main/java/com/nb/aliyun/service/pojo/AliIotProperties.java
  20. 0 16
      nb-service/iot-service/src/main/java/com/nb/aliyun/service/utils/Constants.java
  21. 0 48
      nb-service/iot-service/src/main/java/com/nb/aliyun/service/utils/DeviceAlarmUtils.java
  22. 0 32
      nb-service/iot-service/src/main/java/com/nb/aliyun/service/utils/DeviceRunStatusUtils.java
  23. 0 25
      nb-service/iot-service/src/main/java/com/nb/aliyun/service/utils/DeviceTypeUtils.java
  24. 0 67
      nb-service/iot-service/src/main/java/com/nb/aliyun/service/utils/PumpParams.java
  25. 0 36
      nb-service/iot-service/src/main/java/com/nb/aliyun/service/utils/WarnFlowUtils.java
  26. 0 134
      nb-service/iot-service/src/main/java/com/nb/mq/entity/PcAnalgesicScoreEntity.java
  27. 0 107
      nb-service/iot-service/src/main/java/com/nb/mq/entity/PcPatientEntity.java
  28. 0 173
      nb-service/iot-service/src/main/java/com/nb/mq/entity/PcPumpEntity.java
  29. 1 1
      nb-service/web-service/src/main/java/com/nb/web/service/bus/listener/DeviceInfoListener.java
  30. 2 0
      nb-service/web-service/src/main/java/com/nb/web/service/bus/registry/constant/DeviceKeyConstant.java
  31. 31 0
      nb-service/web-service/src/main/java/com/nb/web/service/bus/registry/device/ClusterDeviceOperator.java
  32. 5 0
      nb-service/web-service/src/main/java/com/nb/web/service/bus/registry/device/DeviceOperator.java

+ 5 - 54
nb-admin/pom.xml

@@ -102,62 +102,13 @@
             <groupId>org.yaml</groupId>
             <artifactId>snakeyaml</artifactId>
         </dependency>
-    </dependencies>
 
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-autoconfigure-processor</artifactId>
+        </dependency>
+    </dependencies>
 
-    <!--<build>-->
-        <!--<resources>-->
-            <!--<resource>-->
-                <!--<directory>src/main/resources</directory>-->
-                <!--<includes>-->
-                    <!--&lt;!&ndash; **/* &ndash;&gt;-->
-                    <!--<include>**/*.xml</include>-->
-                    <!--<include>**/*.yml</include>-->
-                <!--</includes>-->
-                <!--<filtering>true</filtering>-->
-            <!--</resource>-->
-        <!--</resources>-->
-        <!--<plugins>-->
-            <!--<plugin>-->
-                <!--<groupId>org.apache.maven.plugins</groupId>-->
-                <!--<artifactId>maven-compiler-plugin</artifactId>-->
-                <!--<version>3.6.2</version>-->
-                <!--<configuration>-->
-                    <!--<source>${maven.compile.source}</source>-->
-                    <!--<target>${maven.compile.target}</target>-->
-                    <!--<encoding>${project.build.sourceEncoding}</encoding>-->
-                <!--</configuration>-->
-            <!--</plugin>-->
-
-            <!--&lt;!&ndash;<plugin>&ndash;&gt;-->
-                <!--&lt;!&ndash;<artifactId>maven-assembly-plugin</artifactId>&ndash;&gt;-->
-                <!--&lt;!&ndash;<configuration>&ndash;&gt;-->
-                    <!--&lt;!&ndash;<archive>&ndash;&gt;-->
-                        <!--&lt;!&ndash;<manifest>&ndash;&gt;-->
-                            <!--&lt;!&ndash;<mainClass>com.nb.admin.AdminApplication</mainClass>&ndash;&gt;-->
-                        <!--&lt;!&ndash;</manifest>&ndash;&gt;-->
-                        <!--&lt;!&ndash;<manifestEntries>&ndash;&gt;-->
-                            <!--&lt;!&ndash;<Class-Path>.</Class-Path>&ndash;&gt;-->
-                        <!--&lt;!&ndash;</manifestEntries>&ndash;&gt;-->
-                    <!--&lt;!&ndash;</archive>&ndash;&gt;-->
-                <!--&lt;!&ndash;</configuration>&ndash;&gt;-->
-                <!--&lt;!&ndash;<executions>&ndash;&gt;-->
-                    <!--&lt;!&ndash;<execution>&ndash;&gt;-->
-                        <!--&lt;!&ndash;<id>make-assembly</id>&ndash;&gt;-->
-                        <!--&lt;!&ndash;<phase>package</phase>&ndash;&gt;-->
-                        <!--&lt;!&ndash;<goals>&ndash;&gt;-->
-                            <!--&lt;!&ndash;<goal>single</goal>&ndash;&gt;-->
-                        <!--&lt;!&ndash;</goals>&ndash;&gt;-->
-                        <!--&lt;!&ndash;<configuration>&ndash;&gt;-->
-                            <!--&lt;!&ndash;<descriptors>&ndash;&gt;-->
-                                <!--&lt;!&ndash;<descriptor>src/main/resources/assembly.xml</descriptor>&ndash;&gt;-->
-                            <!--&lt;!&ndash;</descriptors>&ndash;&gt;-->
-                        <!--&lt;!&ndash;</configuration>&ndash;&gt;-->
-                    <!--&lt;!&ndash;</execution>&ndash;&gt;-->
-                <!--&lt;!&ndash;</executions>&ndash;&gt;-->
-            <!--&lt;!&ndash;</plugin>&ndash;&gt;-->
-        <!--</plugins>-->
-    <!--</build>-->
 
     <build>
         <finalName>${project.name}</finalName>

+ 27 - 13
nb-admin/src/main/resources/application-dev.yml

@@ -110,20 +110,34 @@ request:
     # 请求不可重复接收时间 10分钟
     repeat-interval: 600
 
+
 # 阿里云对接配置
-#aliyun:
-#  accessKey: "LTAI4FhB19MgQuviGxwA3aod"
-#  accessSecret: "cQQVkATR0yv2G9CEtfjAhEGBepPDRs"
-#  consumerGroupId: "nalavzBm4RuVJc0BUij7000100"
-#  aliyunUid: "1177450762772738"
-#  regionId: "cn-shanghai"
-#  # iotInstanceId:企业版实例请填写实例ID,公共实例请填空字符串""。
-#  iotInstanceId: ""
-#  server-subscription:
-#    enable: true  # 是否开启阿里云物联网服务端订阅
-#  product:
-#    productKey: a1ALlsBa2ZK
-# 阿里云对接配置
+iot:
+  consumers:
+    - enable: true
+      consumer: com.nb.aliyun.service.consumer.NBAndFourGConsumerGroupService
+      name: NB
+      config:
+        accessKey: "LTAI4G7FA9ytMc76oNkJ45YJ"
+        accessSecret: "R7hOvMfiHb0PYroDqUDXAYgB9htQss"
+        consumerGroupId: "NZKDBbvhxUqtcF5VqDb2000100"
+        aliyunUid: "1238892013759131"
+        regionId: "cn-shanghai"
+        iotInstanceId: "iot-060a0bgd"
+        enable: true
+        productKey: he1fACg7ySx
+    - enable: true
+      consumer: com.nb.aliyun.service.consumer.NBAndFourGConsumerGroupService
+      name: 4G
+      config:
+        accessKey: "LTAI5tRaK95AqvWiQ9LspZ3q"
+        accessSecret: "wZUpYGeztNcV4tGbBLfK2OvxnZzZF3"
+        consumerGroupId: "0na0olXpWEmWgMucxIH1000100"
+        aliyunUid: "1777492656465771"
+        regionId: "cn-shanghai"
+        iotInstanceId: "iot-06z00hi2guq5qi3"
+        enable: true
+        productKey: k0g9w9xRhhi
 aliyun:
   accessKey: "LTAI4G7FA9ytMc76oNkJ45YJ"
   accessSecret: "R7hOvMfiHb0PYroDqUDXAYgB9htQss"

+ 3 - 2
nb-admin/src/main/resources/application.yml

@@ -7,7 +7,7 @@ spring:
   application:
     name: nb
   profiles:
-    active: prod
+    active: dev
   jackson:
     time-zone: GMT+8
 
@@ -80,7 +80,7 @@ mybatis-plus:
       logic-not-delete-value: 0
       logic-delete-value: 1
   configuration:
-    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
+    log-impl: org.apache.ibatis.logging.nologging.NoLoggingImpl
     default-enum-type-handler: com.baomidou.mybatisplus.core.handlers.MybatisEnumTypeHandler
   type-aliases-package: com.nb.bus.entity
 
@@ -89,6 +89,7 @@ captcha:
   width: 140
   height: 38
   #验证码过期时间 5min
+
   expire: 300
 management:
   endpoints:

+ 1 - 5
nb-admin/src/test/java/com/nb/admin/BusNetpumpTest.java

@@ -2,11 +2,8 @@ package com.nb.admin;
 
 import cn.hutool.core.util.RandomUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.nb.aliyun.service.AliyunConsumerGroupService;
 import com.nb.web.api.entity.BusDeviceEntity;
 import com.nb.web.api.enums.DeviceStatusEnum2;
-import com.nb.web.api.enums.HospitalLogEnum;
-import com.nb.web.api.utils.EnumUtils;
 import com.nb.web.service.bus.service.LocalBusDeviceService;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -118,8 +115,7 @@ public class BusNetpumpTest {
     public void queryRegistry(){
 
     }
-    @Autowired
-    private AliyunConsumerGroupService consumerGroupService;
+
     @Test
     public void alias(){
         BusDeviceEntity device = new BusDeviceEntity();

+ 6 - 0
nb-service-api/web-service-api/src/main/java/com/nb/web/api/entity/common/BusDeviceRunningEntity.java

@@ -151,6 +151,12 @@ public class BusDeviceRunningEntity extends CommonDeviceParam<String,String> {
     @TableField(exist = false)
     @JsonIgnoreProperties
     private boolean flowRestricted;
+
+    /**
+     * 4G 传输时会带上医院编码
+     */
+    private String hospitalCode;
+
     /**
      * @author 龙三郎
      * 根据阿里云传回数据的items,设置输注的属性

+ 1 - 1
nb-service-api/web-service-api/src/main/java/com/nb/web/api/enums/DeviceTypeEnum.java

@@ -20,7 +20,7 @@ public enum DeviceTypeEnum implements IEnum<Integer> {
     continuous(1,"持续型"),
     intelligent(2,"智能型"),
     pulse(3,"脉冲型"),
-    other(4,"其他");
+    chemistry(4,"化疗泵");
 
     @Getter
     @ApiModelProperty("设备编码")

+ 5 - 5
nb-service-api/web-service-api/src/main/java/com/nb/web/api/utils/DeviceTypeUtils.java

@@ -10,16 +10,16 @@ import com.nb.web.api.enums.DeviceTypeEnum;
  */
 public class DeviceTypeUtils {
     public static DeviceTypeEnum getDeviceType(Integer i){
-        if (i == 0){
-            return DeviceTypeEnum.no;
-        }else if (i == 1){
+        if (i == 1){
             return DeviceTypeEnum.continuous;
         }else if (i == 2){
             return DeviceTypeEnum.pulse;
         }else if (i == 3){
             return DeviceTypeEnum.intelligent;
-        }else {
-            return DeviceTypeEnum.other;
+        } else if (i == 4){
+            return DeviceTypeEnum.chemistry;
+        } else {
+            return DeviceTypeEnum.no;
         }
     }
 }

+ 6 - 0
nb-service/iot-service/pom.xml

@@ -27,5 +27,11 @@
             <artifactId>web-service-api</artifactId>
             <version>1.0</version>
         </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-autoconfigure-processor</artifactId>
+            <optional>true</optional>
+        </dependency>
     </dependencies>
 </project>

+ 47 - 0
nb-service/iot-service/src/main/java/com/nb/aliyun/service/AliConsumerAutoConfiguration.java

@@ -0,0 +1,47 @@
+package com.nb.aliyun.service;
+
+import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.util.ObjectUtil;
+import com.nb.aliyun.service.consumer.AbstractAliConsumer;
+import com.nb.aliyun.service.consumer.AliIotSubscribeClient;
+import com.nb.aliyun.service.consumer.NBAndFourGConsumerGroupService;
+import com.nb.aliyun.service.pojo.AliIotConsumerPojo;
+import com.nb.aliyun.service.pojo.AliIotProperties;
+import jodd.util.ClassUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+
+import javax.annotation.PostConstruct;
+import java.lang.reflect.InvocationTargetException;
+import java.util.List;
+
+/**
+ * @ClassName : AliConsumerAutoConfiguration
+ * @Description :
+ * @Author : LF
+ * @Date: 2024年02月18日
+ */
+@Configuration
+@EnableConfigurationProperties(AliIotProperties.class)
+public class AliConsumerAutoConfiguration {
+    @Autowired
+    private  AliIotProperties iotProperties;
+
+    @PostConstruct
+    public void init() throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
+        if(ObjectUtil.isNotNull(iotProperties)){
+            List<AliIotConsumerPojo> consumers = iotProperties.getConsumers();
+            if(CollectionUtil.isNotEmpty(consumers)){
+                for (AliIotConsumerPojo consumer : consumers) {
+                    if(!Boolean.TRUE.equals(consumer.getEnable())){
+                        continue;
+                    }
+                    AliIotSubscribeClient client = new AliIotSubscribeClient(consumer.getName(), consumer.getConfig());
+                    AbstractAliConsumer consumerGroup = ClassUtil.newInstance(consumer.getConsumer(), client, consumer);
+                    consumerGroup.doSubscribe();
+                }
+            }
+        }
+    }
+}

+ 0 - 205
nb-service/iot-service/src/main/java/com/nb/aliyun/service/AliyunIotSubscribeClient.java

@@ -1,205 +0,0 @@
-package com.nb.aliyun.service;
-
-import com.baomidou.mybatisplus.core.toolkit.IdWorker;
-import com.nb.aliyun.api.bean.PlatformAccount;
-import lombok.Getter;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.codec.binary.Base64;
-import org.apache.qpid.jms.JmsConnection;
-import org.apache.qpid.jms.JmsConnectionListener;
-import org.apache.qpid.jms.message.JmsInboundMessageDispatch;
-import org.springframework.boot.context.properties.EnableConfigurationProperties;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.scheduling.annotation.Async;
-
-import javax.crypto.Mac;
-import javax.crypto.spec.SecretKeySpec;
-import javax.jms.*;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import java.net.InetAddress;
-import java.net.URI;
-import java.net.UnknownHostException;
-import java.util.ArrayList;
-import java.util.Hashtable;
-import java.util.List;
-
-/**
- * @Author 龙三郎
- * @Date 2021-06-17 10:53:30
- * @Version 1.0
- * @Description XXX
- */
-@Configuration
-@EnableConfigurationProperties(PlatformAccount.class)
-@Slf4j
-public class AliyunIotSubscribeClient {
-
-    private final PlatformAccount platformAccount;
-
-    public AliyunIotSubscribeClient(PlatformAccount platformAccount) {
-        this.platformAccount = platformAccount;
-        this.accessKey = platformAccount.getAccessKey();
-        this.accessSecret = platformAccount.getAccessSecret();
-        this.regionId = platformAccount.getRegionId();
-        this.consumerGroupId = platformAccount.getConsumerGroupId();
-        this.aliyunUid = platformAccount.getAliyunUid();
-        this.iotInstanceId = platformAccount.getIotInstanceId();
-
-        this.host = aliyunUid+".iot-amqp."+ regionId +".aliyuncs.com";
-        // 设置客户端id
-        setClientIdAndHost();
-    }
-
-    // 设置客户端id
-    private void setClientIdAndHost(){
-        // 获取ip地址
-        InetAddress addr = null;
-        try {
-            addr = InetAddress.getLocalHost();
-        } catch (UnknownHostException e) {
-            e.printStackTrace();
-        }
-        this.clientId = IdWorker.getIdStr();
-    }
-
-    private String accessKey;
-    private String accessSecret;
-    private String consumerGroupId;
-    private String aliyunUid;
-    private String regionId;
-
-    //iotInstanceId:企业版实例请填写实例ID,公共实例请填空字符串""。
-    private String iotInstanceId;
-
-    //控制台服务端订阅中消费组状态页客户端ID一栏将显示clientId参数。
-    //建议使用机器UUID、MAC地址、IP等唯一标识等作为clientId。便于您区分识别不同的客户端。
-    private String clientId;
-
-    //${YourHost}为接入域名,请参见AMQP客户端接入说明文档。
-    private String host;
-
-    // 指定单个进程启动的连接数
-    // 单个连接消费速率有限,请参考使用限制,最大64个连接
-    // 连接数和消费速率及rebalance相关,建议每500QPS增加一个连接
-    private static int connectionCount = 1;
-
-    @Getter
-    private List<Connection> connections = null;
-
-    @Async
-    public void start(MessageListener messageListener) throws Exception {
-        // 先关闭一下
-        close();
-        connections = new ArrayList<>();
-        //参数说明,请参见AMQP客户端接入说明文档。
-        for (int i = 0; i < connectionCount; i++) {
-            long timeStamp = System.currentTimeMillis();
-            //签名方法:支持hmacmd5、hmacsha1和hmacsha256。
-            String signMethod = "hmacsha1";
-
-            //userName组装方法,请参见AMQP客户端接入说明文档。
-            String userName = clientId + "-" + i + "|authMode=aksign"
-                    + ",signMethod=" + signMethod
-                    + ",timestamp=" + timeStamp
-                    + ",authId=" + accessKey
-                    + ",iotInstanceId=" + iotInstanceId
-                    + ",consumerGroupId=" + consumerGroupId
-                    + "|";
-            //计算签名,password组装方法,请参见AMQP客户端接入说明文档。
-            String signContent = "authId=" + accessKey + "&timestamp=" + timeStamp;
-            String password = doSign(signContent, accessSecret, signMethod);
-            String connectionUrl = "failover:(amqps://" + host + ":5671?amqp.idleTimeout=80000)"
-                    + "?failover.reconnectDelay=30";
-
-            Hashtable<String, String> hashtable = new Hashtable<>();
-            hashtable.put("connectionfactory.SBCF", connectionUrl);
-            hashtable.put("queue.QUEUE", "default");
-            hashtable.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.qpid.jms.jndi.JmsInitialContextFactory");
-            Context context = new InitialContext(hashtable);
-            ConnectionFactory cf = (ConnectionFactory)context.lookup("SBCF");
-            Destination queue = (Destination)context.lookup("QUEUE");
-            // 创建连接。
-            Connection connection = cf.createConnection(userName, password);
-            connections.add(connection);
-
-            ((JmsConnection)connection).addConnectionListener(myJmsConnectionListener);
-            // 创建会话。
-            // Session.CLIENT_ACKNOWLEDGE: 收到消息后,需要手动调用message.acknowledge()。
-            // Session.AUTO_ACKNOWLEDGE: SDK自动ACK(推荐)。
-            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
-            connection.start();
-            // 创建Receiver连接。
-            MessageConsumer consumer = session.createConsumer(queue);
-            consumer.setMessageListener(messageListener);
-        }
-    }
-
-    public void close() throws Exception {
-        if (connections == null){
-            return;
-        }
-        connections.forEach(c-> {
-            try {
-                c.close();
-            } catch (JMSException e) {
-                log.error("连接关闭失败", e);
-            }
-        });
-    }
-
-
-    private static JmsConnectionListener myJmsConnectionListener = new JmsConnectionListener() {
-        /**
-         * 连接成功建立。
-         */
-        @Override
-        public void onConnectionEstablished(URI remoteURI) {
-            log.info("连接成功, remoteUri:{}", remoteURI);
-        }
-        /**
-         * 尝试过最大重试次数之后,最终连接失败。
-         */
-        @Override
-        public void onConnectionFailure(Throwable error) {
-            log.error("连接失败, {}", error.getMessage());
-        }
-        /**
-         * 连接中断。
-         */
-        @Override
-        public void onConnectionInterrupted(URI remoteURI) {
-            log.info("连接中断, remoteUri:{}", remoteURI);
-        }
-        /**
-         * 连接中断后又自动重连上。
-         */
-        @Override
-        public void onConnectionRestored(URI remoteURI) {
-            log.info("自动重连, remoteUri:{}", remoteURI);
-        }
-        @Override
-        public void onInboundMessage(JmsInboundMessageDispatch envelope) {}
-        @Override
-        public void onSessionClosed(Session session, Throwable cause) {}
-        @Override
-        public void onConsumerClosed(MessageConsumer consumer, Throwable cause) {}
-        @Override
-        public void onProducerClosed(MessageProducer producer, Throwable cause) {}
-    };
-
-    /**
-     * 计算签名,password组装方法,请参见AMQP客户端接入说明文档。
-     */
-    private static String doSign(String toSignString, String secret, String signMethod) throws Exception {
-        SecretKeySpec signingKey = new SecretKeySpec(secret.getBytes(), signMethod);
-        Mac mac = Mac.getInstance(signMethod);
-        mac.init(signingKey);
-        byte[] rawHmac = mac.doFinal(toSignString.getBytes());
-        return Base64.encodeBase64String(rawHmac);
-    }
-
-
-
-}

+ 0 - 33
nb-service/iot-service/src/main/java/com/nb/aliyun/service/PlatformLog.java

@@ -1,33 +0,0 @@
-package com.nb.aliyun.service;
-
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableId;
-import lombok.AllArgsConstructor;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-/**
- * @Author XX
- * @Date 2022-01-10 11:43:57
- * @Version 1.0
- * @Description XXX
- */
-@Data
-@NoArgsConstructor
-@AllArgsConstructor
-public class PlatformLog {
-    @TableId(value = "id",type = IdType.AUTO)
-    private Long id;
-    private String code;
-    private String platformCode;
-    private String platformProductCode;
-    private String deviceCode;
-    private String platformData;
-    private String resultData;
-    private String errorLog;
-    private String isError;
-    private Long addTime;
-    private Long updateTime;
-    private String description;
-    private String isDelete;
-}

+ 0 - 12
nb-service/iot-service/src/main/java/com/nb/aliyun/service/PlatformType.java

@@ -1,12 +0,0 @@
-package com.nb.aliyun.service;
-
-/**
- * @Author XX
- * @Date 2022-02-12 08:08:15
- * @Version 1.0
- * @Description XXX
- */
-public class PlatformType {
-    public static final String ALIYUN = "10";
-    public static final String TUOREN = "30";
-}

+ 0 - 18
nb-service/iot-service/src/main/java/com/nb/aliyun/service/bean/AliIotConfig.java

@@ -1,18 +0,0 @@
-package com.nb.aliyun.service.bean;
-
-import lombok.Data;
-
-/**
- * @author lifang
- * @version 1.0.0
- * @ClassName AliIotConfig.java
- * @Description 阿里云物联网注册设备返回配置结果
- * @createTime 2022年04月01日 15:43:00
- */
-@Data
-public class AliIotConfig {
-    private String deviceName;
-    private String deviceSecret;
-    private String productKey;
-    private String iotId;
-}

+ 25 - 0
nb-service/iot-service/src/main/java/com/nb/aliyun/service/consumer/AbstractAliConsumer.java

@@ -0,0 +1,25 @@
+package com.nb.aliyun.service.consumer;
+
+import com.nb.aliyun.service.pojo.AliIotConsumerPojo;
+import lombok.Getter;
+
+/**
+ * @ClassName : AbstractAliyunConsumer
+ * @Description : 阿里云消费组接口
+ * @Author : LF
+ * @Date: 2024年02月18日
+ */
+
+public abstract class AbstractAliConsumer {
+    @Getter
+    private final AliIotConsumerPojo consumer;
+    @Getter
+    private final AliIotSubscribeClient client;
+
+    public AbstractAliConsumer(AliIotSubscribeClient client,AliIotConsumerPojo consumer) {
+        this.consumer = consumer;
+        this.client=client;
+    }
+
+    public  abstract void doSubscribe();
+}

+ 161 - 0
nb-service/iot-service/src/main/java/com/nb/aliyun/service/consumer/AliIotSubscribeClient.java

@@ -0,0 +1,161 @@
+package com.nb.aliyun.service.consumer;
+
+import cn.hutool.core.lang.UUID;
+import cn.hutool.core.net.NetUtil;
+import cn.hutool.core.util.RuntimeUtil;
+import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
+import com.nb.aliyun.api.bean.PlatformAccount;
+import com.nb.aliyun.service.pojo.AliIotConfigPojo;
+import lombok.Data;
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.qpid.jms.JmsConnection;
+import org.apache.qpid.jms.JmsConnectionListener;
+import org.apache.qpid.jms.message.JmsInboundMessageDispatch;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.Async;
+
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
+import javax.jms.*;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import java.net.InetAddress;
+import java.net.URI;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+
+/**
+ * @Author 龙三郎
+ * @Date 2021-06-17 10:53:30
+ * @Version 1.0
+ * @Description XXX
+ *
+ *
+ *
+ * @Author 李放
+ * @Date 2024-02-18 10:53:30
+ * @Version 1.0
+ * @Description 更新 改为多个阿里云订阅配置
+ */
+@Slf4j
+@Data
+public class AliIotSubscribeClient {
+
+    private final AliIotConfigPojo config;
+    private final String subScribeName;
+    public AliIotSubscribeClient(String subScribeName,AliIotConfigPojo config) {
+        this.config=config;
+        this.subScribeName=subScribeName;
+    }
+
+    @Getter
+    private Connection connection = null;
+
+    @Async
+    public void start(MessageListener messageListener) throws Exception {
+        String host=config.getAliyunUid()+".iot-amqp."+ config.getRegionId() +".aliyuncs.com";
+        String macAddress= NetUtil.getMacAddress(InetAddress.getLocalHost());
+        if(StrUtil.isBlank(macAddress)){
+            macAddress= UUID.fastUUID().toString();
+        }
+        //参数说明,请参见AMQP客户端接入说明文档。
+        long timeStamp = System.currentTimeMillis();
+        //签名方法:支持hmacmd5、hmacsha1和hmacsha256。
+        String signMethod = "hmacsha1";
+
+        //userName组装方法,请参见AMQP客户端接入说明文档。
+        String userName = macAddress + "-1|authMode=aksign"
+                + ",signMethod=" + signMethod
+                + ",timestamp=" + timeStamp
+                + ",authId=" + config.getAccessKey()
+                + ",iotInstanceId=" + config.getIotInstanceId()
+                + ",consumerGroupId=" + config.getConsumerGroupId()
+                + "|";
+        //计算签名,password组装方法,请参见AMQP客户端接入说明文档。
+        String signContent = "authId=" + config.getAccessKey() + "&timestamp=" + timeStamp;
+        String password = doSign(signContent, config.getAccessSecret(), signMethod);
+        String connectionUrl = "failover:(amqps://" + host + ":5671?amqp.idleTimeout=80000)"
+                + "?failover.reconnectDelay=30";
+
+        Hashtable<String, String> hashtable = new Hashtable<>();
+        hashtable.put("connectionfactory.SBCF", connectionUrl);
+        hashtable.put("queue.QUEUE", "default");
+        hashtable.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.qpid.jms.jndi.JmsInitialContextFactory");
+        Context context = new InitialContext(hashtable);
+        ConnectionFactory cf = (ConnectionFactory)context.lookup("SBCF");
+        Destination queue = (Destination)context.lookup("QUEUE");
+        // 创建连接。
+        connection = cf.createConnection(userName, password);
+
+        ((JmsConnection)connection).addConnectionListener(myJmsConnectionListener);
+        // 创建会话。
+        // Session.CLIENT_ACKNOWLEDGE: 收到消息后,需要手动调用message.acknowledge()。
+        // Session.AUTO_ACKNOWLEDGE: SDK自动ACK(推荐)。
+        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+        connection.start();
+        // 创建Receiver连接。
+        MessageConsumer consumer = session.createConsumer(queue);
+        consumer.setMessageListener(messageListener);
+    }
+
+
+    private JmsConnectionListener myJmsConnectionListener = new JmsConnectionListener() {
+        /**
+         * 连接成功建立。
+         */
+        @Override
+        public void onConnectionEstablished(URI remoteURI) {
+            log.info("{},连接成功, remoteUri:{}",subScribeName, remoteURI);
+        }
+        /**
+         * 尝试过最大重试次数之后,最终连接失败。
+         */
+        @Override
+        public void onConnectionFailure(Throwable error) {
+            log.error("{},连接失败, {}", subScribeName,error.getMessage());
+        }
+        /**
+         * 连接中断。
+         */
+        @Override
+        public void onConnectionInterrupted(URI remoteURI) {
+            log.info("{},连接中断, remoteUri:{}",subScribeName, remoteURI);
+        }
+        /**
+         * 连接中断后又自动重连上。
+         */
+        @Override
+        public void onConnectionRestored(URI remoteURI) {
+            log.info("{},自动重连, remoteUri:{}",subScribeName, remoteURI);
+        }
+        @Override
+        public void onInboundMessage(JmsInboundMessageDispatch envelope) {}
+        @Override
+        public void onSessionClosed(Session session, Throwable cause) {}
+        @Override
+        public void onConsumerClosed(MessageConsumer consumer, Throwable cause) {}
+        @Override
+        public void onProducerClosed(MessageProducer producer, Throwable cause) {}
+    };
+
+    /**
+     * 计算签名,password组装方法,请参见AMQP客户端接入说明文档。
+     */
+    private static String doSign(String toSignString, String secret, String signMethod) throws Exception {
+        SecretKeySpec signingKey = new SecretKeySpec(secret.getBytes(), signMethod);
+        Mac mac = Mac.getInstance(signMethod);
+        mac.init(signingKey);
+        byte[] rawHmac = mac.doFinal(toSignString.getBytes());
+        return Base64.encodeBase64String(rawHmac);
+    }
+
+
+
+}

+ 30 - 57
nb-service/iot-service/src/main/java/com/nb/aliyun/service/AliyunConsumerGroupService.java → nb-service/iot-service/src/main/java/com/nb/aliyun/service/consumer/NBAndFourGConsumerGroupService.java

@@ -1,10 +1,12 @@
-package com.nb.aliyun.service;
+package com.nb.aliyun.service.consumer;
 
 import cn.hutool.core.text.CharSequenceUtil;
+import cn.hutool.extra.spring.SpringUtil;
 import cn.hutool.json.JSONUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
+import com.nb.aliyun.service.pojo.AliIotConsumerPojo;
 import com.nb.web.api.bean.AliIotConfig;
 import com.nb.web.api.entity.BusDeviceEntity;
 import com.nb.web.api.entity.BusHospitalLogEntity;
@@ -16,83 +18,59 @@ import com.nb.web.api.utils.EnumUtils;
 import com.nb.core.utils.ExceptionUtil;
 import com.nb.web.api.feign.IDeviceClient;
 import com.nb.web.api.utils.Items;
-import io.netty.util.concurrent.SingleThreadEventExecutor;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Lazy;
-import org.springframework.stereotype.Service;
-
-import javax.annotation.PostConstruct;
 import javax.jms.Message;
 import javax.jms.MessageListener;
-import java.util.*;
 import java.util.concurrent.*;
 import java.util.concurrent.atomic.AtomicInteger;
 
 /**
+ * 4G和Nb型网络泵消费者处理组
+ *
+ *
  * @Author 龙三郎
  * @Date 2022-4-06 16:22:13
  * @Version 1.0
  * @Description 阿里云物联网平台服务端订阅
+ *
+ *
+ * @Author 李放
+ * @Date 2024-02-18 16:22:13
+ * @Version 2.0
+ * @Description 改为多连接配置订阅
  */
-@Service
 @Slf4j
-public class AliyunConsumerGroupService {
-    private static final String IOTID = "iotId";
-    private static final String PRODUCTKEY = "productKey";
+public class NBAndFourGConsumerGroupService extends AbstractAliConsumer {
     private static final String DEVICENAME = "deviceName";
     private static final String TOPIC = "topic";
     private static final String MESSAGEID = "messageId";
-    private static final String ITEMS = "items";
-    private static final String VALUE = "value";
     private static final String STATUS = "status";
-    private static final String CONTENT = "payload";
 
-    @Autowired
-    @Lazy
-    private AliyunIotSubscribeClient client;
-    @Autowired
-    @Lazy
+
+
     private IDeviceClient deviceService;
 
-    @Autowired
     private IIotMsgHandler iotMsgHandler;
 
-    /**
-     * 阿里云订阅延迟启动,给ws重连时间
-     */
-    @Value("${tio.websocket.server.heartbeat-timeout:0}")
-    private Long delayTime;
 
-    @Autowired
-    @Lazy
     private IHospitalLogClient hospitalLogService;
 
-    @Value("${aliyun.server-subscription.enable:false}")
-    private boolean isEnable;
+    public NBAndFourGConsumerGroupService(AliIotSubscribeClient client,AliIotConsumerPojo consumer) {
+        super(client,consumer);
+        this.deviceService= SpringUtil.getBean(IDeviceClient.class);
+        this.iotMsgHandler= SpringUtil.getBean(IIotMsgHandler.class);
+        this.hospitalLogService= SpringUtil.getBean(IHospitalLogClient.class);
+    }
 
-    // 开启服务端订阅
-    @PostConstruct
-    public void subscribe(){
-        if (!isEnable){
-            log.info("订阅禁止");
-            return;
-        }
-        log.info("允许开启订阅");
+
+    @Override
+    public void doSubscribe(){
         try {
-            client.start(messageListener);
+            this.getClient().start(messageListener);
+            log.info("{},阿里云物联网订阅成功。",this.getConsumer().getName());
         } catch (Exception e) {
-            e.printStackTrace();
+            log.error("{},阿里云物联网订阅失败,e:{}",this.getConsumer().getName(),e);
         }
-        log.info("阿里云物联网订阅成功。。。。。。。。。。。");
-//        // 开启订阅
-//        Executors.newSingleThreadScheduledExecutor()
-//                .schedule(()->{
-//
-//                        },
-//                        Optional.ofNullable(delayTime).orElse(0L)*2,TimeUnit.SECONDS ) ;
-
     }
 
 
@@ -106,6 +84,7 @@ public class AliyunConsumerGroupService {
             new LinkedBlockingQueue(50000),
             new AliYunThreadFactory());
 
+
     static class AliYunThreadFactory implements ThreadFactory {
         static final AtomicInteger poolNumber = new AtomicInteger(1);
         final ThreadGroup group;
@@ -144,7 +123,7 @@ public class AliyunConsumerGroupService {
             // 如果业务处理耗时过程过长阻塞住线程,可能会影响SDK收到消息后的正常回调。
             executorService.submit(()-> processMessage(message));
         } catch (Exception e) {
-            log.error("submit task occurs exception ", e);
+            log.error("{},submit task occurs exception ", this.getConsumer().getName(),e);
         }
     };
 
@@ -158,13 +137,11 @@ public class AliyunConsumerGroupService {
             String messageId = message.getStringProperty(MESSAGEID);
             hospitalLog.setMsgId(messageId);
             JSONObject content = JSON.parseObject(new String(message.getBody(byte[].class)));
-            log.info("阿里云物联网发送的数据:"+JSON.toJSONString(content));
+            log.info("{},阿里云物联网发送的数据:{}",this.getConsumer().getName(),JSON.toJSONString(content));
             // 设备名称
             deviceName = content.getString(DEVICENAME);
             hospitalLog.setIdentityCode(deviceName);
             hospitalLog.setInput(content.toJSONString());
-            // 创建设备对象
-            Date now = new Date();
             // 根据topic判断数据类型,设备上下线状态
             if (topic.matches("^/as/mqtt/status/[\\w\\/]*")){
                 BusDeviceEntity device = new BusDeviceEntity();
@@ -236,11 +213,7 @@ public class AliyunConsumerGroupService {
             }
             hospitalLogService.save(hospitalLog);
         }
-
     }
 
 
-
-
-
 }

+ 24 - 0
nb-service/iot-service/src/main/java/com/nb/aliyun/service/pojo/AliIotConfigPojo.java

@@ -0,0 +1,24 @@
+package com.nb.aliyun.service.pojo;
+
+import lombok.Data;
+
+/**
+ * @ClassName : AliIotConfigPojo
+ * @Description :
+ * @Author : LF
+ * @Date: 2024年02月18日
+ */
+@Data
+public class AliIotConfigPojo {
+    private String accessKey;
+    private String accessSecret;
+    private String consumerGroupId;
+    private String aliyunUid;
+    private String regionId;
+    /**
+     *   iotInstanceId:企业版实例请填写实例ID,公共实例请填空字符串""。
+     */
+    private String iotInstanceId;
+
+    private String productKey;
+}

+ 27 - 0
nb-service/iot-service/src/main/java/com/nb/aliyun/service/pojo/AliIotConsumerPojo.java

@@ -0,0 +1,27 @@
+package com.nb.aliyun.service.pojo;
+
+
+import com.nb.aliyun.service.consumer.AbstractAliConsumer;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * @ClassName : AliIotConsumerPojo
+ * @Description :
+ * @Author : LF
+ * @Date: 2024年02月18日
+ */
+@Data
+public class AliIotConsumerPojo {
+    @ApiModelProperty("是否启用")
+    private Boolean enable;
+
+    @ApiModelProperty("阿里云iot配置")
+    private AliIotConfigPojo config;
+
+    @ApiModelProperty("消息消费者处理器")
+    private Class<AbstractAliConsumer> consumer;
+
+    @ApiModelProperty("消费者名称")
+    private String name;
+}

+ 16 - 0
nb-service/iot-service/src/main/java/com/nb/aliyun/service/pojo/AliIotProperties.java

@@ -0,0 +1,16 @@
+package com.nb.aliyun.service.pojo;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import java.util.*;
+/**
+ * @ClassName : AliIotProperties
+ * @Description :
+ * @Author : LF
+ * @Date: 2024年02月18日
+ */
+@Data
+@ConfigurationProperties(prefix = "iot")
+public class AliIotProperties {
+    List<AliIotConsumerPojo> consumers;
+}

+ 0 - 16
nb-service/iot-service/src/main/java/com/nb/aliyun/service/utils/Constants.java

@@ -1,16 +0,0 @@
-package com.nb.aliyun.service.utils;
-
-/**
- * @Author 龙三郎
- * @Date 2022-04-26 13:44:36
- * @Version 1.0
- * @Description XXX
- */
-public class Constants {
-    // 默认医院
-    public static final String DefaultHospital = "1";
-    // 默认创建人
-    public static final String DefaultCreateBy = "1";
-    // 默认更新人
-    public static final String DefaultUpdateBy = "1";
-}

+ 0 - 48
nb-service/iot-service/src/main/java/com/nb/aliyun/service/utils/DeviceAlarmUtils.java

@@ -1,48 +0,0 @@
-package com.nb.aliyun.service.utils;
-
-import com.nb.web.api.enums.DeviceAlarmEnum;
-
-/**
- * @Author 龙三郎
- * @Date 2022-04-29 11:04:04
- * @Version 1.0
- * @Description 根据阿里云发送的报警标识,获取报警枚举对象。阿里云发送的报警是0-9的整数。
- */
-public class DeviceAlarmUtils {
-    public static DeviceAlarmEnum getAlarm(Integer i){
-        if (i == 0){
-            // 无报警
-            return DeviceAlarmEnum.None;
-        }else if (i == 1){
-            // 气泡无液报警
-            return DeviceAlarmEnum.Bubble;
-        }else if (i == 2){
-            // 堵塞
-            return DeviceAlarmEnum.Jam;
-        }else if (i == 3){
-            // 输入总量
-            return DeviceAlarmEnum.InfusionMax;
-        }else if (i == 4){
-            // 极限量
-            return DeviceAlarmEnum.Limit;
-        }else if (i == 5){
-            // 电量耗尽
-            return DeviceAlarmEnum.LowBattery;
-        }else if (i == 6){
-            // 输液结束
-            return DeviceAlarmEnum.Finished;
-//        }else if (i == 7){
-            // 电机失控
-//            return DeviceAlarmEnum.OutOfControl;
-        }else if (i == 8){
-            // 机械故障
-            return DeviceAlarmEnum.Machine;
-        }else if (i == 9){
-            // 未装药盒
-            return DeviceAlarmEnum.NotBox;
-        }else {
-
-            return DeviceAlarmEnum.Finished;
-        }
-    }
-}

+ 0 - 32
nb-service/iot-service/src/main/java/com/nb/aliyun/service/utils/DeviceRunStatusUtils.java

@@ -1,32 +0,0 @@
-package com.nb.aliyun.service.utils;
-
-import com.nb.web.api.enums.DeviceStatusEnum;
-
-/**
- * @Author 龙三郎
- * @Date 2022-04-29 11:36:03
- * @Version 1.0
- * @Description 根据阿里云发送的运行标识,获取运行枚举对象。阿里云发送的运行是0-4的整数。
- */
-public class DeviceRunStatusUtils {
-    public static DeviceStatusEnum getRunStatus(Integer i){
-        if (i == 0){
-            // 关机
-            return DeviceStatusEnum.Shutdown;
-        }else if (i == 1){
-            // 运行
-            return DeviceStatusEnum.StartUp;
-        }else if (i == 2){
-            // 运行
-            return DeviceStatusEnum.Running;
-        }else if (i == 3){
-            // 暂停
-            return DeviceStatusEnum.Pause;
-        }else if (i == 4){
-            // 待机
-            return DeviceStatusEnum.Waiting;
-        }else {
-            return DeviceStatusEnum.Shutdown;
-        }
-    }
-}

+ 0 - 25
nb-service/iot-service/src/main/java/com/nb/aliyun/service/utils/DeviceTypeUtils.java

@@ -1,25 +0,0 @@
-package com.nb.aliyun.service.utils;
-
-import com.nb.web.api.enums.DeviceTypeEnum;
-
-/**
- * @Author 龙三郎
- * @Date 2022-04-29 11:52:36
- * @Version 1.0
- * @Description XXX
- */
-public class DeviceTypeUtils {
-    public static DeviceTypeEnum getDeviceType(Integer i){
-        if (i == 0){
-            return DeviceTypeEnum.no;
-        }else if (i == 1){
-            return DeviceTypeEnum.continuous;
-        }else if (i == 2){
-            return DeviceTypeEnum.pulse;
-        }else if (i == 3){
-            return DeviceTypeEnum.intelligent;
-        }else {
-            return DeviceTypeEnum.other;
-        }
-    }
-}

+ 0 - 67
nb-service/iot-service/src/main/java/com/nb/aliyun/service/utils/PumpParams.java

@@ -1,67 +0,0 @@
-package com.nb.aliyun.service.utils;
-
-import lombok.AllArgsConstructor;
-import lombok.Getter;
-
-/**
- * @Author 龙三郎
- * @Date 2022-04-26 10:37:47
- * @Version 1.0
- * @Description 设备上传的数据参数
- */
-@AllArgsConstructor
-public enum PumpParams {
-    protocolHeader("protocolHeader","协议头"),
-    dataLength("dataLength","数据长度"),
-    pumpType("pumpType","泵类型"),
-    classification("classification","分类标识"),
-    dataNumber("dataNumber","数据编号"),
-    patientCodeLength("patientCodeLength","住院号长度"),
-    patientCode("patientCode","住院号"),
-    ward("ward","病区"),
-    bedNo("bedNo","床号"),
-    totalDose("totalDose","总量"),
-    maxDose("maxDose","极限量"),
-    singleDosis("singleDose","追加量"),
-    lockTime("lockTime","锁时时间"),
-    flow("flow","持续量"),
-    finishedDose("finishedDose","已输入量"),
-    firstDosis("firstDose","首次量"),
-    pcaValid("pcaValid","PCA有效次数"),
-    pcaInvalid("pcaInvalid","PCA无效次数"),
-    electricQuantity("electricQuantity","电池电量"),
-    runStatus("runStatus","运行状态"),
-    alarmStatus("alarmStatus","报警"),
-    warnWillFinished("warnWillFinished","输液将结束预报"),
-    warnAnalgesicPoor("warnAnalgesicPoor","镇痛不足预报"),
-    warnLowBattery("warnLowBattery","电量偏低预报"),
-
-    // 脉冲泵属性
-    pulseLockTime("pulseLockTime","脉冲量锁时"),
-    firstLockTime("firstLockTime","首次锁时"),
-    pulseDose("pulseDose","脉冲量"),
-
-    // 智能泵属性
-    resetParams("resetParams","重设参数标志"),
-    warnFlow("warnFlow","加减档预报"),
-    flowDownTime("flowDownTime","减档时间"),
-    flowUpTime("flowUpTime","加档时间"),
-    flowUpPcaValid("flowUpPcaValid","触发加档pca有效次数"),
-    flowAdjuseRate("flowAdjuseRate","加减档百分比"),
-    minFlow("minFlow","减档下限"),
-    maxFlow("maxFlow","加档上限"),
-
-
-
-
-
-    CRC("CRC","CRC");
-
-
-
-    @Getter
-    private String param;
-    @Getter
-    private String info;
-
-}

+ 0 - 36
nb-service/iot-service/src/main/java/com/nb/aliyun/service/utils/WarnFlowUtils.java

@@ -1,36 +0,0 @@
-package com.nb.aliyun.service.utils;
-
-import com.nb.web.api.enums.FlowStatusEnum;
-
-/**
- * @Author 龙三郎
- * @Date 2022-04-29 11:04:04
- * @Version 1.0
- * @Description 根据阿里云发送的加减档预报。阿里云发送的报警是0-5的整数。
- */
-public class WarnFlowUtils {
-    public static FlowStatusEnum getAlarm(Integer i){
-        if (i == 0){
-            // 正常
-            return FlowStatusEnum.None;
-        }else if (i == 1){
-            // 加档受限
-            return FlowStatusEnum.Limited;
-        }else if (i == 2){
-            // 流速已达上限
-            return FlowStatusEnum.MaxFlow;
-        }else if (i == 3){
-            // 加档
-            return FlowStatusEnum.Up;
-        }else if (i == 4){
-            // 减档
-            return FlowStatusEnum.Down;
-        }else if (i == 5){
-            // 低输注状态
-            return FlowStatusEnum.Lowest;
-        }else {
-
-            return FlowStatusEnum.None;
-        }
-    }
-}

+ 0 - 134
nb-service/iot-service/src/main/java/com/nb/mq/entity/PcAnalgesicScoreEntity.java

@@ -1,134 +0,0 @@
-package com.nb.mq.entity;
-
-
-import com.baomidou.mybatisplus.annotation.TableField;
-import com.baomidou.mybatisplus.annotation.TableName;
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableId;
-import java.time.LocalDateTime;
-import java.io.Serializable;
-import io.swagger.annotations.ApiModel;
-import io.swagger.annotations.ApiModelProperty;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-import lombok.experimental.Accessors;
-
-/**
- *
- * 
- * </p>
- *
- * @author fanfan
- * @since 2020-07-03
- */
-@Data
-@EqualsAndHashCode(callSuper = false)
-@Accessors(chain = true)
-@TableName("bus_analgesic_score")
-@ApiModel(value="BusAnalgesicScoreEntity对象", description="")
-public class PcAnalgesicScoreEntity implements Serializable {
-
-    private static final long serialVersionUID = 1L;
-
-    @ApiModelProperty(value = "主键",hidden = true)
-    @TableId(value = "id", type = IdType.AUTO)
-    private Long id;
-
-    @ApiModelProperty(value = "病人ID")
-    public String patientId;
-
-    @ApiModelProperty(value = "泵号")
-    private String pumpCode;
-
-    @ApiModelProperty(value = "医院编码")
-    private String hospitalCode;
-
-    @ApiModelProperty(value = "住院号")
-    private String patientCode;
-
-    @ApiModelProperty(value = "疼痛评分静止")
-    private Integer statics;
-
-    @ApiModelProperty(value = "疼痛评分活动")
-    private Integer activity;
-
-    @ApiModelProperty(value = "镇静评分")
-    private Integer calm;
-
-    @ApiModelProperty(value = "左上肢")
-    private Integer leftArm;
-
-    @ApiModelProperty(value = "左下肢")
-    private Integer leftLeg;
-
-    @ApiModelProperty(value = "右上肢")
-    private Integer rightArm;
-
-    @ApiModelProperty(value = "右下肢")
-    private Integer rightLeg;
-
-    @ApiModelProperty(value = "恶心呕吐")
-    private Integer nauseaVomit;
-
-    @ApiModelProperty(value = "瘙痒")
-    private Integer itch;
-
-    @ApiModelProperty(value = "眩晕")
-    private Integer vertigo;
-
-    @ApiModelProperty(value = "咽喉疼痛")
-    private Integer soreThroat;
-
-    @ApiModelProperty(value = "尿潴留")
-    private Integer uroschesis;
-
-    @ApiModelProperty(value = "呼吸抑制")
-    private Integer breathDepression;
-
-    @ApiModelProperty(value = "声音嘶哑")
-    private Integer hoarseness;
-
-    @ApiModelProperty(value = "认知障碍")
-    private Integer cognitionObstacle;
-
-    @ApiModelProperty(value = "其他")
-    private String other;
-
-    @ApiModelProperty(value = "满意度")
-    private Integer satisfaction;
-
-    @ApiModelProperty(value = "创建时间",hidden = true)
-    private LocalDateTime gmtCreate;
-
-    @ApiModelProperty(value = "更新时间",hidden = true)
-    private LocalDateTime gmtModified;
-
-    @ApiModelProperty(value = "评价时间",hidden = true)
-    private LocalDateTime followDate;
-
-    @ApiModelProperty(value = "评价人")
-    private String creator;
-
-    @ApiModelProperty(value = "产品编码")
-    private String productCode;
-
-    @ApiModelProperty(value = "评价传输ID",hidden = true)
-    @TableField(exist = false)
-    private String analgesicScoreId;
-
-    @ApiModelProperty(value = "收缩压")
-    private String  SBP;
-
-
-    @ApiModelProperty(value = "舒张压")
-    private String  DBP;
-
-    @ApiModelProperty(value = "心率")
-    private String HR;
-
-    @ApiModelProperty(value = "呼吸频率")
-    private String RR;
-
-    @ApiModelProperty(value = "血氧饱和度")
-    private String SpO2;
-}

+ 0 - 107
nb-service/iot-service/src/main/java/com/nb/mq/entity/PcPatientEntity.java

@@ -1,107 +0,0 @@
-package com.nb.mq.entity;
-import java.time.LocalDateTime;
-import java.io.Serializable;
-import io.swagger.annotations.ApiModelProperty;
-import lombok.Data;
-/**
- * <p>
- * 
- * </p>
- *
- * @author fanfan
- * @since 2020-07-03
- */
-@Data
-public class PcPatientEntity implements Serializable {
-
-    private static final long serialVersionUID = 1L;
-
-    @ApiModelProperty(value = "主键/病人id")
-    private String patientId;
-
-    @ApiModelProperty(value = "医院Id")
-    private String hospitalCode;
-
-    @ApiModelProperty(value = "产品编号")
-    private String productCode;
-
-    @ApiModelProperty(value = "住院号")
-    private String patientCode;
-
-    @ApiModelProperty(value = "泵号")
-    private String pumpCode;
-
-    @ApiModelProperty(value = "姓名")
-    private String name;
-
-    @ApiModelProperty(value = "性别")
-    private String sex;
-
-    @ApiModelProperty(value = "体重")
-    private String weight;
-
-    @ApiModelProperty(value = "身高")
-    private String height;
-
-    @ApiModelProperty(value = "年龄")
-    private Integer age;
-
-    @ApiModelProperty(value = "病区")
-    private String wardCode;
-
-    @ApiModelProperty(value = "床号")
-    private String bedCode;
-
-    @ApiModelProperty(value = "手术名称")
-    private String operationName;
-
-    @ApiModelProperty(value = "手术医生")
-    private String operationDoctor;
-
-    @ApiModelProperty(value = "ASA")
-    private String asa;
-
-    @ApiModelProperty(value = "镇痛方式")
-    private String easyMode;
-
-    @ApiModelProperty(value = "麻醉医生")
-    private String anesthesiaDoctor1;
-
-    @ApiModelProperty(value = "麻醉医生2")
-    private String anesthesiaDoctor2;
-
-    @ApiModelProperty(value = "麻醉方式")
-    private String anesthesiaMode;
-
-    @ApiModelProperty(value = "配置人员")
-    private String configPerson;
-
-    @ApiModelProperty(value = "配方")
-    private String formula;
-
-    @ApiModelProperty(value = "撤泵人")
-    private String undoPerson;
-
-    @ApiModelProperty(value = "销毁人")
-    private String destoryPerson;
-
-    @ApiModelProperty(value = "见证人")
-    private String witnessPerson;
-
-    @ApiModelProperty(value = "撤泵时间")
-    private LocalDateTime undoTime;
-
-    @ApiModelProperty(value = "盐值")
-    private String salt;
-
-    @ApiModelProperty(value = "剩余量处置")
-    private String remain;
-
-    @ApiModelProperty(value = "备注")
-    private String remark;
-
-    @ApiModelProperty(value = "是否删除")
-    private Boolean isDelete;
-
-    private String bmi;
-}

+ 0 - 173
nb-service/iot-service/src/main/java/com/nb/mq/entity/PcPumpEntity.java

@@ -1,173 +0,0 @@
-package com.nb.mq.entity;
-import java.math.BigDecimal;
-
-import java.time.LocalDateTime;
-import java.io.Serializable;
-import java.util.Date;
-import com.fasterxml.jackson.annotation.JsonSetter;
-import io.swagger.annotations.ApiModelProperty;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-import lombok.experimental.Accessors;
-/**
- * <p>
- * 
- * </p>
- *
- * @author fanfan
- * @since 2020-07-03
- */
-@Data
-@EqualsAndHashCode(callSuper = false)
-@Accessors(chain = true)
-public class PcPumpEntity implements Serializable {
-
-    private static final long serialVersionUID = 1L;
-
-    @ApiModelProperty(value = "主键")
-    private Long id;
-
-    @ApiModelProperty(value = "注液泵编码")
-    private String PumpCode;
-
-    @ApiModelProperty(value = "产品编码")
-    private String SysProduct_ID;
-
-    @ApiModelProperty(value = "医院编码")
-    private String SysHospital_ID;
-
-    @ApiModelProperty(value = "住院号")
-    private String PatientCode;
-
-    @ApiModelProperty(value = "剩余量")
-    private BigDecimal BalanceQuantity;
-
-    @ApiModelProperty(value = "持续量(智能泵当前流速)(脉冲泵KVO)")
-    private BigDecimal ContinueQuantity;
-
-    @ApiModelProperty(value = "自控量")
-    private BigDecimal SelfQuantity;
-
-    @ApiModelProperty(value = "锁定时间")
-    private Integer LockTime;
-
-    @ApiModelProperty(value = "已输入量")
-    private BigDecimal InputQuantity;
-
-    @ApiModelProperty(value = "有效次数")
-    private Integer TrueNum;
-
-    @ApiModelProperty(value = "无效次数")
-    private Integer FalseNum;
-
-    @ApiModelProperty(value = "极限量")
-    private BigDecimal MaxQuantity;
-
-    @ApiModelProperty(value = "首次量")
-    private Integer FirstQuantity;
-
-    @ApiModelProperty(value = "追加量")
-    private BigDecimal SingleQuantity;
-
-    @ApiModelProperty(value = "总量")
-    private Integer AllQuantity;
-
-    @ApiModelProperty(value = "总按次数")
-    private Integer AllCount;
-
-    @ApiModelProperty(value = "脉冲量")
-    private BigDecimal PulseQuantity;
-
-    @ApiModelProperty(value = "脉冲锁时")
-    private Integer PulseLockTime;
-
-    @ApiModelProperty(value = "首次量锁时")
-    private Integer FirstLockTime;
-
-    @ApiModelProperty(value = "上限")
-    private BigDecimal UpperLimit;
-
-    @ApiModelProperty(value = "下限")
-    private BigDecimal LowerLimit;
-
-    @ApiModelProperty(value = "自调比例")
-    private Integer CustomScate;
-
-    @ApiModelProperty(value = "加档有效次数")
-    private Integer AddTrueFrequency;
-
-    @ApiModelProperty(value = "镇痛泵运行状态")
-    private Integer RunState;
-
-    @ApiModelProperty(value = "镇痛泵状态BUF")
-    private Integer BUFState1;
-
-    @ApiModelProperty(value = "镇痛泵状态BUF")
-    private Integer BUFState2;
-
-    @ApiModelProperty(value = "镇痛泵状态BUF")
-    private Integer BUFState3;
-
-    @ApiModelProperty(value = "镇痛泵状态BUF")
-    @JsonSetter(value = "BUFState4")
-    private Integer BUFState4;
-
-    @ApiModelProperty(value = "镇痛泵状态BUF")
-    private Integer BUFState5;
-
-    @ApiModelProperty(value = "镇痛泵状态BUF")
-    private Integer BUFState6;
-
-    @ApiModelProperty(value = "镇痛泵状态BUF")
-    private Integer BUFState7;
-
-    @ApiModelProperty(value = "镇痛泵状态BUF")
-    private Integer BUFState8;
-
-    @ApiModelProperty(value = "镇痛泵状态BUF")
-    private Integer BUFState9;
-
-    @ApiModelProperty(value = "镇痛评分")
-    private Integer Score;
-
-    @ApiModelProperty(value = "加档周期")
-    private BigDecimal FilingCycle;
-
-    @ApiModelProperty(value = "减档周期")
-    private BigDecimal ReductionPeriod;
-
-    @ApiModelProperty(value = "呼叫标记")
-    private Integer CallFlag;
-
-    @ApiModelProperty(value = "开始时间")
-    private Date StartTime;
-
-    @ApiModelProperty(value = "是否可见")
-    private Boolean Visible;
-
-    @ApiModelProperty(value = "状态标记")
-    private Integer StateFlag;
-
-    @ApiModelProperty(value = "是否在服务区")
-    private Integer NoSignal;
-
-    @ApiModelProperty(value = "显示状态")
-    private String ViewState;
-
-    @ApiModelProperty(value = "备注")
-    private String Remark;
-
-    @ApiModelProperty(value = "最后上传时间")
-    private LocalDateTime LastUploadTime;
-
-    @ApiModelProperty(value = "创建时间",hidden = true)
-    private LocalDateTime gmtCreate;
-
-    @ApiModelProperty(value = "更新时间",hidden = true)
-    private LocalDateTime gmtModified;
-
-    @ApiModelProperty(value = "是否是家用")
-    private Boolean isFamily;
-
-
-}

+ 1 - 1
nb-service/web-service/src/main/java/com/nb/web/service/bus/listener/DeviceInfoListener.java

@@ -93,7 +93,6 @@ public class DeviceInfoListener implements IIotMsgHandler {
     public BusDeviceRunningEntity sync(BusDeviceRunningEntity device, String deviceId) {
         //保证统一设备数据顺序处理,若数据发送过快,为防止冲突,请在此加锁处理
         synchronized (deviceId){
-            log.info("接收到设备消息:{}",JSONUtil.toJsonStr(device));
             String classification = device.getClassification();
             if(StrUtil.isBlank(classification)){
                 log.error("消息【{}】,设备号:【{}】分包标识号为空,无法更新开始时间",device.getMsgId(),device.getDeviceId());
@@ -102,6 +101,7 @@ public class DeviceInfoListener implements IIotMsgHandler {
             long startTime = System.currentTimeMillis();
             DeviceOperator deviceOperator = deviceRegistry.getOperator(deviceId);
             //对设备数据的一些参数进行初始化设置
+            deviceOperator.refreshHospitalCode(device.getHospitalCode());
             init(device);
 
             //缓存操作

+ 2 - 0
nb-service/web-service/src/main/java/com/nb/web/service/bus/registry/constant/DeviceKeyConstant.java

@@ -43,4 +43,6 @@ public class DeviceKeyConstant {
      * 当设备切换医院时,将设备的缓存输注标识更换
      */
     public static final String DEFAULT_CLASSIFY="-1";
+
+    public static final String HOSPITAL_CODE="hospital_code";
 }

+ 31 - 0
nb-service/web-service/src/main/java/com/nb/web/service/bus/registry/device/ClusterDeviceOperator.java

@@ -2,20 +2,26 @@ package com.nb.web.service.bus.registry.device;
 
 
 import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
 import cn.hutool.extra.spring.SpringUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.nb.web.api.entity.BusDeviceEntity;
 import com.nb.web.api.entity.BusInfusionHistoryEntity;
+import com.nb.web.service.bus.entity.BusHospitalEntity;
 import com.nb.web.service.bus.entity.BusInfusionModifyEntity;
 import com.nb.web.api.enums.DeviceTypeEnum;
 import com.nb.web.api.enums.FlowStatusEnum;
 import com.nb.web.service.bus.registry.constant.DeviceKeyConstant;
 import com.nb.web.service.bus.service.LocalBusDeviceService;
+import com.nb.web.service.bus.service.LocalBusHospitalService;
 import com.nb.web.service.bus.service.LocalBusInfusionHistoryService;
 import com.nb.core.Value;
 import com.nb.common.config.utils.RedissonUtil;
+import org.apache.batik.svggen.font.table.Device;
 import org.redisson.api.RMapCache;
 
 import java.math.BigDecimal;
+import java.util.Arrays;
 import java.util.Date;
 
 /**
@@ -31,6 +37,7 @@ public class ClusterDeviceOperator implements DeviceOperator {
     private final RMapCache<String, Value> mapCache;
     private final LocalBusDeviceService deviceService;
     private final LocalBusInfusionHistoryService infusionHistoryService;
+    private final LocalBusHospitalService hospitalService;
 
     public ClusterDeviceOperator(String deviceId) {
         String key="device:"+deviceId;
@@ -38,6 +45,7 @@ public class ClusterDeviceOperator implements DeviceOperator {
         infusionHistoryService=SpringUtil.getBean(LocalBusInfusionHistoryService.class);
         this.deviceId=deviceId;
         mapCache = SpringUtil.getBean(RedissonUtil.class).getRedissonClient().getMapCache(key);
+        this.hospitalService=SpringUtil.getBean(LocalBusHospitalService.class);
     }
 
     @Override
@@ -99,6 +107,26 @@ public class ClusterDeviceOperator implements DeviceOperator {
         return value.asString();
     }
 
+    @Override
+    public void refreshHospitalCode(String hospitalCode) {
+        if(StrUtil.isBlank(hospitalCode)){
+            return;
+        }
+        Value value = getValue(DeviceKeyConstant.HOSPITAL_CODE);
+        boolean change=false;
+        //医院编码发生了改变
+        if(value==null ||!StrUtil.equals(hospitalCode,value.asString()) ){
+            change=true;
+            put(DeviceKeyConstant.HOSPITAL_CODE,wrapperValue(hospitalCode));
+        }
+
+        if(change){
+            BusDeviceEntity device = getDevice();
+            BusHospitalEntity hospital = getHospital(hospitalCode);
+            deviceService.shift(Arrays.asList(this.getDeviceId()),device.getTenantId(),hospital.getId());
+        }
+    }
+
     @Override
     public void setInfusionTenantId(String tenantId) {
         put(DeviceKeyConstant.INFUSION_TENANT_ID,wrapperValue(tenantId) );
@@ -367,4 +395,7 @@ public class ClusterDeviceOperator implements DeviceOperator {
         return infusionHistoryService.lastInfusion(deviceId);
     }
 
+    private BusHospitalEntity getHospital(String hospitalCode){
+        return hospitalService.getOne(new LambdaQueryWrapper<BusHospitalEntity>().eq(BusHospitalEntity::getCode,hospitalCode));
+    }
 }

+ 5 - 0
nb-service/web-service/src/main/java/com/nb/web/service/bus/registry/device/DeviceOperator.java

@@ -63,6 +63,11 @@ public interface DeviceOperator extends Operator {
      */
     String getTenantId();
 
+    /**
+     * 根据医院编码刷新医院id
+     * @param hospitalCode
+     */
+    void refreshHospitalCode(String hospitalCode);
 
 
     /**