TRX 1 an în urmă
părinte
comite
3cf3f80d57

+ 22 - 0
src/main/java/com/zswl/dataservice/dao/iot/IotDeviceDataDao.java

@@ -0,0 +1,22 @@
+package com.zswl.dataservice.dao.iot;
+
+import com.zswl.dataservice.dao.MongoDao;
+import com.zswl.dataservice.dao.iot.extend.IotMainDaoExtend;
+import com.zswl.dataservice.domain.iot.IotDeviceData;
+import com.zswl.dataservice.domain.iot.IotMain;
+import com.zswl.dataservice.domain.iot.IotTemplate;
+import com.zswl.dataservice.type.FunctionType;
+
+import java.util.List;
+
+/**
+ * @author TRX
+ * @date 2024/3/21
+ */
+public interface IotDeviceDataDao extends MongoDao<IotDeviceData> {
+
+    IotDeviceData findTopById(String id);
+
+    IotDeviceData findTopByIotMain(IotMain iotMain);
+
+}

+ 3 - 0
src/main/java/com/zswl/dataservice/domain/iot/IotDeviceData.java

@@ -23,6 +23,9 @@ public class IotDeviceData extends SuperEntity {
     @DBRef(lazy = true)
     private IotMain iotMain;
 
+    @Schema(description = "所属模版ID")
+    private String iotTemplateId;
+
     @Schema(description = "关联的设备")
     private String deviceId;
 

+ 2 - 1
src/main/java/com/zswl/dataservice/domain/iot/IotMain.java

@@ -11,6 +11,7 @@ import lombok.NoArgsConstructor;
 import org.springframework.data.mongodb.core.mapping.DBRef;
 import org.springframework.data.mongodb.core.mapping.Document;
 
+import java.math.BigDecimal;
 import java.util.LinkedHashMap;
 import java.util.List;
 
@@ -57,7 +58,7 @@ public class IotMain extends SuperEntity {
     private String unitName;
 
     @Schema(description = "步长")
-    private Integer stepNumber;
+    private BigDecimal stepNumber;
 
     @Schema(description = "最大的长度,如:类型为字符串时使用")
     private String maxLength;

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

@@ -6,6 +6,7 @@ import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 
+import java.math.BigDecimal;
 import java.util.List;
 
 /**
@@ -26,6 +27,18 @@ public class IotAttribute {
     @Schema(description = "参数描述,如:姓名")
     private String name;
 
+    @Schema(description = "单位名称,如:千克、流明、立方米等...")
+    private String unitName;
+
+    @Schema(description = "步长")
+    private BigDecimal stepNumber;
+
+    @Schema(description = "最大的长度,如:类型为字符串时使用")
+    private String maxLength;
+
     @Schema(description = "相关值的描述")
     private List<IotDict> value;
+
+    @Schema(description = "子属性")
+    private List<IotAttribute> childs;
 }

+ 20 - 0
src/main/java/com/zswl/dataservice/model/iot/IotDeviceDataModel.java

@@ -0,0 +1,20 @@
+package com.zswl.dataservice.model.iot;
+
+import com.zswl.dataservice.model.baseParam.SuperModel;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @author TRX
+ * @date 2024/7/16
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class IotDeviceDataModel extends SuperModel {
+    @Schema(description = "对应的值")
+    private Object data;
+
+}

+ 28 - 0
src/main/java/com/zswl/dataservice/model/iot/IotMainAttributeModel.java

@@ -0,0 +1,28 @@
+package com.zswl.dataservice.model.iot;
+
+import com.zswl.dataservice.model.baseParam.SuperModel;
+import com.zswl.dataservice.type.DataType;
+import com.zswl.dataservice.type.FunctionType;
+import com.zswl.dataservice.type.OperationType;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.math.BigDecimal;
+import java.util.List;
+
+/**
+ * 属性
+ *
+ * @author TRX
+ * @date 2024/6/20
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class IotMainAttributeModel extends IotMainModel {
+
+    @Schema(description = "属性的值")
+    IotDeviceDataModel deviceData;
+}

+ 44 - 28
src/main/java/com/zswl/dataservice/model/iot/IotMainModel.java

@@ -13,7 +13,9 @@ import lombok.Data;
 import lombok.NoArgsConstructor;
 import org.springframework.data.mongodb.core.mapping.DBRef;
 
+import java.math.BigDecimal;
 import java.util.LinkedHashMap;
+import java.util.List;
 
 /**
  * @author TRX
@@ -23,12 +25,25 @@ import java.util.LinkedHashMap;
 @AllArgsConstructor
 @NoArgsConstructor
 public class IotMainModel extends SuperModel {
+
     @Schema(description = "功能名称")
     private String name;
 
-    @Schema(description = "功能类型")
+    @Schema(description = "标识符")
+    private String identifier;
+
+    @Schema(description = "功能类型,属性 事件 服务")
     FunctionType functionType;
 
+    @Schema(description = "物模型Topic")
+    private String iotTopic;
+
+    @Schema(description = "真实的topic")
+    private String realIotTopic;
+
+    @Schema(description = "是否返回数据")
+    private Boolean isReturnData = Boolean.TRUE;
+
     private String functionTypeStr;
 
     public String getFunctionTypeStr() {
@@ -38,27 +53,6 @@ public class IotMainModel extends SuperModel {
         return "";
     }
 
-    @Schema(description = "标识符")
-    private String identifier;
-
-    @Schema(description = "数据类型")
-    private DataType dataType;
-
-    private String dataTypeStr;
-
-    public String getDataTypeStr() {
-        if (dataType != null) {
-            return dataType.getRemark();
-        }
-        return "";
-    }
-
-    @Schema(description = "数据定义")
-    private LinkedHashMap<String, Object> data;
-
-    @Schema(description = "物模型Topic")
-    private String iotTopic;
-
     @Schema(description = "所属模版")
     IotTemplateModel iotTemplate;
 
@@ -74,15 +68,37 @@ public class IotMainModel extends SuperModel {
         return "";
     }
 
-    @Schema(description = "单位")
-    private MainUnitType mainUnitType;
+    //---------------------------------属性类型的  字段  start ------------------
+    @Schema(description = "数据类型,number、Boolean、String 等")
+    private DataType dataType;
 
-    private String mainUnitTypeStr;
+    private String dataTypeStr;
 
-    public String getMainUnitTypeStr() {
-        if (mainUnitType != null) {
-            return mainUnitType.getRemark();
+    public String getDataTypeStr() {
+        if (dataType != null) {
+            return dataType.getRemark();
         }
         return "";
     }
+
+    @Schema(description = "单位名称,如:千克、流明、立方米等...")
+    private String unitName;
+
+    @Schema(description = "步长")
+    private BigDecimal stepNumber;
+
+    @Schema(description = "最大的长度,如:类型为字符串时使用")
+    private String maxLength;
+
+    @Schema(description = "属性,参数列表,输入参数")
+    private List<IotAttribute> attributes;
+
+    @Schema(description = "值的对应,如:0-开")
+    private List<IotDict> values;
+
+    //--------------------------------关联设备时特有的属性 start------------------
+
+    @Schema(description = "业务处理地址")
+    private String remoteUrl;
+
 }

+ 46 - 1
src/main/java/com/zswl/dataservice/service/iot/IotServiceImpl.java

@@ -2,12 +2,14 @@ package com.zswl.dataservice.service.iot;
 
 import ch.qos.logback.core.model.NamedModel;
 import com.zswl.dataservice.dao.UserDao;
+import com.zswl.dataservice.dao.iot.IotDeviceDataDao;
 import com.zswl.dataservice.dao.iot.IotMainDao;
 import com.zswl.dataservice.dao.iot.IotTemplateDao;
 import com.zswl.dataservice.dao.iot.IotTopicDao;
 import com.zswl.dataservice.dao.mqtt.DeviceInfoDao;
 import com.zswl.dataservice.dao.mqtt.GateWay2DeviceDao;
 import com.zswl.dataservice.dataConfig.ResultMessage;
+import com.zswl.dataservice.domain.iot.IotDeviceData;
 import com.zswl.dataservice.domain.iot.IotMain;
 import com.zswl.dataservice.domain.iot.IotTemplate;
 import com.zswl.dataservice.domain.iot.IotTopic;
@@ -62,8 +64,13 @@ public class IotServiceImpl extends SuperService {
 
     @Autowired
     DeviceInfoDao deviceInfoDao;
+
+    @Autowired
     private GateWay2DeviceDao gateWay2DeviceDao;
 
+    @Autowired
+    IotDeviceDataDao iotDeviceDataDao;
+
     //----------------------------- 模版 start----------------------------
 
     /**
@@ -408,13 +415,24 @@ public class IotServiceImpl extends SuperService {
         return ResultContent.buildSuccess(toModel(entity));
     }
 
+    /**
+     * 物模型 结构查询
+     *
+     * @param pageable
+     * @param param
+     * @return
+     */
     public ResultContent<Page<IotMainModel>> pageIotMain(Pageable pageable, IotMainSearch param) {
         initSearchParam(param);
         if (StringUtils.isEmpty(param.getIotTemplateId())) {
             return ResultContent.buildFail("iotTemplateId不能为空");
         }
         Page<IotMain> page = iotMainDao.page(pageable, param);
-        return ResultContent.buildSuccess(PageEntityUtil.toPageModel(page, this::toModel));
+        if (param.getFunctionType() != null && param.getFunctionType() == FunctionType.Attribute) {
+            return ResultContent.buildSuccess(PageEntityUtil.toPageModel(page, this::toAttributeModel));
+        } else {
+            return ResultContent.buildSuccess(PageEntityUtil.toPageModel(page, this::toModel));
+        }
     }
 
     /**
@@ -452,6 +470,12 @@ public class IotServiceImpl extends SuperService {
         return model;
     }
 
+    /**
+     * IOTMain模型
+     *
+     * @param entity
+     * @return
+     */
     public IotMainModel toModel(IotMain entity) {
         IotMainModel model = null;
         if (ObjectUtils.isNotEmpty(entity)) {
@@ -461,5 +485,26 @@ public class IotServiceImpl extends SuperService {
         return model;
     }
 
+    /**
+     * 属性 类型的model,包含值
+     *
+     * @param entity
+     * @return
+     */
+    public IotMainAttributeModel toAttributeModel(IotMain entity) {
+        IotMainAttributeModel model = null;
+        if (ObjectUtils.isNotEmpty(entity)) {
+            model = new IotMainAttributeModel();
+            BeanUtils.copyProperties(entity, model);
+            IotDeviceData iotDeviceData = iotDeviceDataDao.findTopByIotMain(entity);
+            if (ObjectUtils.isNotEmpty(iotDeviceData)) {
+                IotDeviceDataModel deviceData = new IotDeviceDataModel();
+                BeanUtils.copyProperties(iotDeviceData, deviceData);
+                model.setDeviceData(deviceData);
+            }
+        }
+        return model;
+    }
+
 
 }