TRX 1 سال پیش
والد
کامیت
dd1bcc72c0

+ 0 - 22
src/main/java/com/zswl/dataservice/domain/iot/DeviceIotMain.java

@@ -1,22 +0,0 @@
-package com.zswl.dataservice.domain.iot;
-
-import com.zswl.dataservice.domain.base.SuperEntity;
-import com.zswl.dataservice.domain.mqtt.DeviceInfo;
-import io.swagger.v3.oas.annotations.media.Schema;
-import org.springframework.data.mongodb.core.mapping.DBRef;
-
-/**
- * 设备对应的
- *
- * @author TRX
- * @date 2024/7/9
- */
-public class DeviceIotMain extends SuperEntity {
-
-    @Schema(description = "设备ID")
-    private String deviceId;
-
-    @Schema(description = "设备信息")
-    @DBRef(lazy = true)
-    private DeviceInfo deviceInfo;
-}

+ 0 - 25
src/main/java/com/zswl/dataservice/domain/iot/DeviceIotTemplate.java

@@ -1,25 +0,0 @@
-package com.zswl.dataservice.domain.iot;
-
-import com.zswl.dataservice.domain.base.SuperEntity;
-import com.zswl.dataservice.domain.mqtt.DeviceInfo;
-import io.swagger.v3.oas.annotations.media.Schema;
-import lombok.Data;
-import org.springframework.data.mongodb.core.mapping.DBRef;
-
-/**
- * @author TRX
- * @date 2024/7/9
- */
-@Data
-public class DeviceIotTemplate extends SuperEntity {
-    @Schema(description = "设备ID")
-    private String deviceId;
-
-    @Schema(description = "设备信息")
-    @DBRef(lazy = true)
-    private DeviceInfo deviceInfo;
-
-    @Schema(description = "模版信息")
-    @DBRef(lazy = true)
-    private IotTemplate iotTemplate;
-}

+ 43 - 17
src/main/java/com/zswl/dataservice/domain/iot/IotMain.java

@@ -1,10 +1,9 @@
 package com.zswl.dataservice.domain.iot;
 
 import com.zswl.dataservice.domain.base.SuperEntity;
-import com.zswl.dataservice.type.DataType;
-import com.zswl.dataservice.type.FunctionType;
-import com.zswl.dataservice.type.MainUnitType;
-import com.zswl.dataservice.type.OperationType;
+import com.zswl.dataservice.model.iot.IotAttribute;
+import com.zswl.dataservice.model.iot.IotDict;
+import com.zswl.dataservice.type.*;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.AllArgsConstructor;
 import lombok.Data;
@@ -13,7 +12,7 @@ import org.springframework.data.mongodb.core.mapping.DBRef;
 import org.springframework.data.mongodb.core.mapping.Document;
 
 import java.util.LinkedHashMap;
-import java.util.Map;
+import java.util.List;
 
 /**
  * 物模型
@@ -27,31 +26,58 @@ import java.util.Map;
 @AllArgsConstructor
 public class IotMain extends SuperEntity {
 
+    // ------------------------iotMain 基础字段 start-----------------------
     @Schema(description = "功能名称")
     private String name;
 
-    @Schema(description = "功能类型")
-    FunctionType functionType;
-
     @Schema(description = "标识符")
     private String identifier;
 
-    @Schema(description = "数据类型")
-    private DataType dataType;
-
-    @Schema(description = "数据定义")
-    private LinkedHashMap<String, Object> data;
+    @Schema(description = "功能类型,属性 事件 服务")
+    FunctionType functionType;
 
     @Schema(description = "物模型Topic")
     private String iotTopic;
 
-    @Schema(description = "设备操作权限")
-    private OperationType operationType;
+    @Schema(description = "真实的topic")
+    private String realIotTopic;
 
     @Schema(description = "所属模版")
     @DBRef(lazy = true)
     IotTemplate iotTemplate;
 
-    @Schema(description = "单位")
-    private MainUnitType mainUnitType;
+    //---------------------------------属性类型的  字段  start ------------------
+    @Schema(description = "数据类型,number、Boolean、String 等")
+    private DataType dataType;
+
+    @Schema(description = "单位名称,如:千克、流明、立方米等...")
+    private String unitName;
+
+    @Schema(description = "步长")
+    private Integer stepNumber;
+
+    @Schema(description = "最大的长度,如:类型为字符串时使用")
+    private String maxLength;
+
+    @Schema(description = "属性,参数列表,输入参数")
+    private List<IotAttribute> attributes;
+
+    @Schema(description = "值的对应,如:0-开")
+    private List<IotDict> values;
+
+    //--------------------------------关联设备时特有的属性 start------------------
+    @Schema(description = "区分是模版还是设备关联的物模型")
+    private IotDataType iotDataType;
+
+    @Schema(description = "关联的设备")
+    private String deviceId;
+
+    @Schema(description = "所属分支code")
+    private String projectCode;
+
+    @Schema(description = "关联时间")
+    private Long addTime;
+
+    @Schema(description = "业务处理地址")
+    private String remoteUrl;
 }

+ 14 - 0
src/main/java/com/zswl/dataservice/domain/iot/IotTemplate.java

@@ -2,6 +2,7 @@ package com.zswl.dataservice.domain.iot;
 
 import com.zswl.dataservice.domain.base.SuperEntity;
 import com.zswl.dataservice.type.DataState;
+import com.zswl.dataservice.type.IotDataType;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.AllArgsConstructor;
 import lombok.Data;
@@ -26,6 +27,19 @@ public class IotTemplate extends SuperEntity {
     @Schema(description = "数据状态")
     private DataState state = DataState.Enable;
 
+    //--------------------------------关联设备时特有的属性 start------------------
+    @Schema(description = "区分是模版还是设备关联的物模型")
+    private IotDataType iotDataType;
+
+    @Schema(description = "关联的设备")
+    private String deviceId;
+
+    @Schema(description = "所属分支code")
+    private String projectCode;
+
+    @Schema(description = "物模型所属模版ID,就是管理设备时绑定的那个模版")
+    private String iotTemplateId;
+
     public static IotTemplate build(String id) {
         IotTemplate entity = new IotTemplate();
         entity.setId(id);

+ 31 - 0
src/main/java/com/zswl/dataservice/model/iot/IotAttribute.java

@@ -0,0 +1,31 @@
+package com.zswl.dataservice.model.iot;
+
+import com.zswl.dataservice.type.DataType;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.List;
+
+/**
+ * @author TRX
+ * @date 2024/7/12
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class IotAttribute {
+
+    @Schema(description = "属性类型,如:数字,字符串 ...")
+    private DataType dataType;
+
+    @Schema(description = "参数名称,如:name")
+    private String key;
+
+    @Schema(description = "参数描述,如:姓名")
+    private String name;
+
+    @Schema(description = "相关值的描述")
+    private List<IotDict> value;
+}

+ 22 - 0
src/main/java/com/zswl/dataservice/model/iot/IotDict.java

@@ -0,0 +1,22 @@
+package com.zswl.dataservice.model.iot;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @author TRX
+ * @date 2024/7/12
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class IotDict {
+
+    @Schema(description = "参数值,如:0")
+    private String value;
+
+    @Schema(description = "描述,如:开")
+    private String desc;
+}

+ 27 - 12
src/main/java/com/zswl/dataservice/model/iot/IotMainParam.java

@@ -10,6 +10,7 @@ import lombok.Data;
 import lombok.NoArgsConstructor;
 
 import java.util.LinkedHashMap;
+import java.util.List;
 
 /**
  * @author TRX
@@ -19,27 +20,41 @@ import java.util.LinkedHashMap;
 @AllArgsConstructor
 @NoArgsConstructor
 public class IotMainParam extends SuperParam {
+
+    @Schema(description = "模版或无模型ID")
+    private String iotTemplateId;
+
     @Schema(description = "功能名称")
     private String name;
 
-    @Schema(description = "功能类型")
-    FunctionType functionType;
-
     @Schema(description = "标识符")
     private String identifier;
 
-    @Schema(description = "数据类型")
-    private DataType dataType;
-
-    @Schema(description = "数据定义")
-    private LinkedHashMap<String, Object> data;
+    @Schema(description = "功能类型,属性 事件 服务")
+    FunctionType functionType;
 
     @Schema(description = "物模型Topic")
     private String iotTopic;
 
-    @Schema(description = "模版ID")
-    private String iotTemplateId;
+    @Schema(description = "数据类型,number、Boolean、String 等")
+    private DataType dataType;
+
+    @Schema(description = "单位名称,如:千克、流明、立方米等...")
+    private String unitName;
+
+    @Schema(description = "步长")
+    private Integer stepNumber;
+
+    @Schema(description = "最大的长度,如:类型为字符串时使用")
+    private String maxLength;
+
+    @Schema(description = "属性,参数列表,输入参数")
+    private List<IotAttribute> attributes;
+
+    @Schema(description = "值的对应,如:0-开")
+    private List<IotDict> values;
+
+    @Schema(description = "业务处理地址")
+    private String remoteUrl;
 
-    @Schema(description = "单位")
-    private MainUnitType mainUnitType;
 }

+ 32 - 0
src/main/java/com/zswl/dataservice/model/iot/IotMainSuper.java

@@ -0,0 +1,32 @@
+package com.zswl.dataservice.model.iot;
+
+import com.zswl.dataservice.model.baseParam.SuperParam;
+import com.zswl.dataservice.type.FunctionType;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @author TRX
+ * @date 2024/7/12
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class IotMainSuper extends SuperParam {
+    @Schema(description = "功能名称")
+    private String name;
+
+    @Schema(description = "标识符")
+    private String identifier;
+
+    @Schema(description = "功能类型,属性 事件 服务")
+    FunctionType functionType;
+
+    @Schema(description = "物模型Topic")
+    private String iotTopic;
+
+    @Schema(description = "所属模版或物模型ID")
+    private String iotTemplateId;
+}

+ 6 - 3
src/main/java/com/zswl/dataservice/service/artemis/ArtemisListenerService.java

@@ -9,6 +9,7 @@ import jakarta.jms.Message;
 import jakarta.jms.Session;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
+import org.apache.activemq.artemis.api.core.RoutingType;
 import org.apache.activemq.artemis.jms.client.ActiveMQBytesMessage;
 import org.apache.activemq.artemis.jms.client.ActiveMQMessage;
 import org.apache.activemq.artemis.jms.client.ActiveMQTopic;
@@ -16,6 +17,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.jms.annotation.JmsListener;
 import org.springframework.stereotype.Service;
 
+import java.util.Enumeration;
+
 /**
  * @author TRX
  * @date 2024/6/27
@@ -41,12 +44,12 @@ public class ArtemisListenerService {
     }
 
     // 网关来的消息
-    @JmsListener(destination = "#", containerFactory = MQConstant.TopicListenerContainerFactory)
+    @JmsListener(destination = "$sys.mqtt.sessions", containerFactory = MQConstant.TopicListenerContainerFactory)
     public void receiveOnLineChangeMessage(Message message, Session session) {
         try {
             ActiveMQTopic activeMQTopic = (ActiveMQTopic) message.getJMSDestination();
             String topicName = activeMQTopic.getTopicName();
-                if (!topicName.equals("$sys.mqtt.sessions")) {
+            if (!topicName.equals("$sys.mqtt.sessions")) {
                 return;
             }
             log.info("==sezz {}", session.getTransacted());
@@ -54,7 +57,7 @@ public class ArtemisListenerService {
             String clientId = message.getStringProperty("_AMQ_LVQ_NAME");
             log.info("receiveMessage {} 消息监听clientId: {}", messageId, clientId);
             log.info("Topic: {}", topicName);
-
+            Enumeration enumeration =message.getPropertyNames();
             if (message instanceof ActiveMQBuffer) {
                 log.info("---------------------");
             }

+ 26 - 4
src/main/java/com/zswl/dataservice/service/iot/IotServiceImpl.java

@@ -14,6 +14,8 @@ import com.zswl.dataservice.model.mqtt.DeviceInfoModel;
 import com.zswl.dataservice.model.mqtt.DeviceInfoSearchParam;
 import com.zswl.dataservice.service.base.SuperService;
 import com.zswl.dataservice.type.FunctionType;
+import com.zswl.dataservice.type.IotDataType;
+import com.zswl.dataservice.type.ResultState;
 import com.zswl.dataservice.utils.bean.BeanUtil;
 import com.zswl.dataservice.utils.bean.BeanUtils;
 import com.zswl.dataservice.utils.page.PageEntityUtil;
@@ -150,6 +152,7 @@ public class IotServiceImpl extends SuperService {
 
     /**
      * 分页查询 模版的Topic管理数据
+     *
      * @param pageable
      * @param param
      * @return
@@ -162,8 +165,16 @@ public class IotServiceImpl extends SuperService {
     //----------------------------- Topic end------------------------------
 
     //----------------------------- 物模型 start----------------------------
+
+    /**
+     * 添加属性  事件
+     *
+     * @param param
+     * @return
+     */
     public ResultContent addIotMain(IotMainParam param) {
         initDefaultUser(param);
+
         String iotTemplateId = param.getIotTemplateId();
         IotTemplate iotTemplate = iotTemplateDao.findTopById(iotTemplateId);
         if (ObjectUtils.isEmpty(iotTemplate)) {
@@ -171,24 +182,35 @@ public class IotServiceImpl extends SuperService {
         }
 
         IotMain entity = null;
+        // 判断名称是否重复
+        IotTopic nameTemp = iotTopicDao.findTopByTopicAndIotTemplate(param.getName(), iotTemplate);
         if (StringUtils.isNotEmpty(param.getId())) {
             entity = iotMainDao.findTopById(param.getId());
             if (ObjectUtils.isEmpty(entity)) {
                 return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, param.getId()));
             }
-            IotTopic temp = iotTopicDao.findTopByTopicAndIotTemplate(param.getName(), iotTemplate);
-            if (ObjectUtils.isNotEmpty(temp) && !temp.getId().equals(param.getId())) {
+            if (ObjectUtils.isNotEmpty(nameTemp) && !nameTemp.getId().equals(param.getId())) {
                 return ResultContent.buildFail(String.format(ResultMessage.NAME_EXIT, param.getName()));
             }
         } else {
             entity = new IotMain();
-            IotTopic temp = iotTopicDao.findTopByTopicAndIotTemplate(param.getName(), iotTemplate);
-            if (ObjectUtils.isNotEmpty(temp)) {
+            if (ObjectUtils.isNotEmpty(nameTemp)) {
                 return ResultContent.buildFail(String.format(ResultMessage.NAME_EXIT, param.getName()));
             }
         }
+
         BeanUtils.copyProperties(param, entity);
         entity.setIotTemplate(iotTemplate);
+        if (iotTemplate.getIotDataType() == IotDataType.Device) {
+            // 把 topic有占位符的换为具体的值
+            String deviceId = iotTemplate.getDeviceId();
+            String iotTopic = entity.getIotTopic();
+            String realIotTopic = "";
+            if (StringUtils.isNotEmpty(iotTopic)) {
+                realIotTopic = iotTopic.replaceAll("$\\{deviceId\\}", deviceId);
+            }
+            entity.setRealIotTopic(realIotTopic);
+        }
         iotMainDao.save(entity);
         return ResultContent.buildSuccess();
     }

+ 4 - 5
src/main/java/com/zswl/dataservice/type/DataType.java

@@ -7,11 +7,10 @@ import lombok.Getter;
  */
 public enum DataType {
     Number("数字"),
-    Bool("布尔值"),
-    Text("字符串"),
-    Date("日期"),
-    Time("时间"),
-    DateTime("日期时间"),
+    String("字符串"),
+    Array("数组"),
+    Object("对象"),
+    Boolean("布尔"),
     ;
 
     @Getter

+ 19 - 0
src/main/java/com/zswl/dataservice/type/IotDataType.java

@@ -0,0 +1,19 @@
+package com.zswl.dataservice.type;
+
+import lombok.Getter;
+
+/**
+ * 数据类型
+ */
+public enum IotDataType {
+    IotTemplate("模版"),
+    Device("设备物模型"),
+    ;
+
+    @Getter
+    private String remark;
+
+    IotDataType(String remark) {
+        this.remark = remark;
+    }
+}