TRX il y a 1 an
Parent
commit
dd1e5234c7

+ 1 - 1
OneCardIotClient/src/main/java/com/zhongshu/iot/client/type/IotDataType.java

@@ -6,7 +6,7 @@ import lombok.Getter;
  * 数据类型
  */
 public enum IotDataType {
-    IotTemplate("模"),
+    IotTemplate("模"),
     Device("设备物模型"),
     ;
 

+ 6 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/domain/iot/IotMain.java

@@ -33,6 +33,12 @@ public class IotMain extends SuperEntity {
     @Schema(description = "模版id")
     private String iotMainTemplateId;
 
+    @Schema(description = "所属物模型id")
+    private String iotThingId;
+
+    @Schema(description = "绑定的设备id")
+    private String bindDeviceId;
+
     // ------------------------iotMain 基础字段 start-----------------------
 
     @Schema(description = "功能类型,属性 事件 服务")

+ 4 - 4
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/domain/iot/IotTemplate.java

@@ -9,11 +9,8 @@ import lombok.Data;
 import lombok.NoArgsConstructor;
 import org.springframework.data.mongodb.core.mapping.Document;
 
-import java.util.ArrayList;
-import java.util.List;
-
 /**
- * 物模型 模版 或  物模型 数据
+ * 物模型 模版 或  物模型 数据 (模块引用)
  *
  * @author TRX
  * @date 2024/6/20
@@ -30,6 +27,9 @@ public class IotTemplate extends SuperEntity {
     @Schema(description = "数据状态")
     private DataState state = DataState.Enable;
 
+    @Schema(description = "所属物模型id")
+    private String iotThingId;
+
     //--------------------------------关联设备时特有的属性 start------------------
     @Schema(description = "区分是模版还是设备关联的物模型")
     private IotDataType iotDataType;

+ 30 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/domain/iot/IotThing.java

@@ -0,0 +1,30 @@
+package com.zhongshu.iot.server.core.domain.iot;
+
+import com.zhongshu.iot.server.core.domain.base.SuperEntity;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.springframework.data.mongodb.core.mapping.Document;
+
+/**
+ * 真正的物模型
+ *
+ * @author TRX
+ * @date 2025/2/20
+ */
+@Data
+@Document
+@NoArgsConstructor
+@AllArgsConstructor
+public class IotThing extends SuperEntity {
+
+    @Schema(description = "名称")
+    private String name;
+
+    @Schema(description = "设备数量")
+    private Long deviceCount = 0L;
+
+    @Schema(description = "所属分组")
+    private String projectCode;
+}

+ 11 - 14
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/domain/iot/IotTemplateDeviceBind.java → OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/domain/iot/IotThing2Device.java

@@ -1,6 +1,6 @@
 package com.zhongshu.iot.server.core.domain.iot;
 
-import com.zhongshu.iot.client.type.DataState;
+import com.github.microservice.auth.client.type.DeviceType;
 import com.zhongshu.iot.server.core.domain.base.SuperEntity;
 import com.zhongshu.iot.server.core.domain.iot.mqtt.DeviceInfo;
 import io.swagger.v3.oas.annotations.media.Schema;
@@ -12,29 +12,26 @@ import org.springframework.data.mongodb.core.mapping.Document;
 
 /**
  * @author TRX
- * @date 2025/2/10
+ * @date 2025/2/20
  */
 @Data
 @Document
 @NoArgsConstructor
 @AllArgsConstructor
-public class IotTemplateDeviceBind extends SuperEntity {
+public class IotThing2Device extends SuperEntity {
+
+    @Schema(description = "关联物模型")
+    @DBRef(lazy = true)
+    private IotThing iotThing;
 
     @Schema(description = "设备id")
     private String deviceId;
 
-    @Schema(description = "设备信息")
-    @DBRef(lazy = true)
-    private DeviceInfo deviceInfo;
+    @Schema(description = "设备类型")
+    private DeviceType deviceType;
 
-    @Schema(description = "物模型id")
-    private String templateId;
-
-    @Schema(description = "物模型")
+    @Schema(description = "关联设备信息")
     @DBRef(lazy = true)
-    private IotTemplate template;
-
-    @Schema(description = "设备状态")
-    private DataState state = DataState.Enable;
+    private DeviceInfo deviceInfo;
 
 }

+ 22 - 3
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iotPlatform/impl/OnLineTopic.java

@@ -1,11 +1,16 @@
 package com.zhongshu.iot.server.core.service.iotPlatform.impl;
 
+import cn.hutool.json.JSONUtil;
+import com.github.microservice.models.onLine.DeviceOnLineParam;
+import com.github.microservice.models.onLine.DeviceOnLineResult;
 import com.github.microservice.net.ResultContent;
 import com.zhongshu.iot.server.core.domain.ExecuteAnnotationService;
 import com.zhongshu.iot.server.core.domain.ExecuteAnnotationServiceMethod;
-import com.zhongshu.iot.server.core.service.base.SuperService;
 import com.zhongshu.iot.server.core.service.iotPlatform.PlatformTopic;
+import com.zhongshu.iot.server.core.util.DateUtils;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Component;
 
 /**
@@ -25,7 +30,21 @@ public class OnLineTopic implements PlatformTopic {
     @ExecuteAnnotationServiceMethod(value = "online", remark = "上线")
     @Override
     public ResultContent<Object> action(String topic, String message) {
-
-        return ResultContent.buildSuccess();
+        log.info("online");
+        DeviceOnLineParam param = null;
+        if (StringUtils.isNotEmpty(message)) {
+            param = JSONUtil.toBean(message, DeviceOnLineParam.class);
+        }
+        DeviceOnLineResult result = new DeviceOnLineResult();
+        if (ObjectUtils.isNotEmpty(param)) {
+            result.setOperator(param.getOperator());
+            result.setSuccess();
+            result.setDeviceId(param.getDeviceId());
+            result.setMqttDataId(param.getMqttDataId());
+            result.setGateWayId(param.getGateWayId());
+            result.setTime(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.FORMAT_LONG));
+            result.setInfo(param.getInfo());
+        }
+        return ResultContent.buildSuccess(result);
     }
 }