TRX 1 rok temu
rodzic
commit
b221ab1149

+ 8 - 0
src/main/java/com/zswl/dataservice/domain/mqtt/GateWayInfo.java

@@ -6,6 +6,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.NoArgsConstructor;
+import org.springframework.data.mongodb.core.mapping.DBRef;
 import org.springframework.data.mongodb.core.mapping.Document;
 
 /**
@@ -31,4 +32,11 @@ public class GateWayInfo extends SuperEntity {
 
     @Schema(description = "网关在线状态")
     OnLineState state;
+
+    @Schema(description = "所属项目")
+    @DBRef(lazy = true)
+    private ProjectInfo projectInfo;
+
+    @Schema(description = "项目code")
+    private String projectInfoCode;
 }

+ 3 - 4
src/main/java/com/zswl/dataservice/model/mqtt/GateWayBindDeviceParam.java

@@ -18,6 +18,9 @@ public class GateWayBindDeviceParam {
     @Schema(description = "网关名称")
     private String gateWayName;
 
+    @Schema(description = "项目code")
+    private String projectInfoCode;
+
     @Schema(description = "ip地址")
     private String ip;
 
@@ -26,8 +29,4 @@ public class GateWayBindDeviceParam {
 
     @Schema(description = "网关连接账号", hidden = true)
     private String userName;
-
-    @Schema(description = "所属项目")
-    @DBRef(lazy = true)
-    private String projectInfoCode;
 }

+ 3 - 0
src/main/java/com/zswl/dataservice/model/mqtt/GateWayInfoAddParam.java

@@ -21,6 +21,9 @@ public class GateWayInfoAddParam extends SuperParam {
     @Schema(description = "网关名称")
     private String gateWayName;
 
+    @Schema(description = "项目code")
+    private String projectInfoCode;
+
     @Schema(description = "ip")
     private String ip;
 

+ 11 - 0
src/main/java/com/zswl/dataservice/model/mqtt/GateWayInfoModel.java

@@ -1,9 +1,11 @@
 package com.zswl.dataservice.model.mqtt;
 
+import com.zswl.dataservice.domain.mqtt.ProjectInfo;
 import com.zswl.dataservice.model.baseParam.SuperModel;
 import com.zswl.dataservice.utils.mqtt.type.OnLineState;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
+import org.springframework.data.mongodb.core.mapping.DBRef;
 
 /**
  * @author TRX
@@ -17,6 +19,15 @@ public class GateWayInfoModel extends SuperModel {
     @Schema(description = "网关名称")
     private String gateWayName;
 
+    @Schema(description = "ip地址")
+    private String ip;
+
+    @Schema(description = "所属项目")
+    private ProjectInfoModel projectInfo;
+
+    @Schema(description = "项目code")
+    private String projectInfoCode;
+
     @Schema(description = "设备在线状态")
     OnLineState state;
 

+ 11 - 0
src/main/java/com/zswl/dataservice/service/mqtt/GateWayInfoService.java

@@ -70,6 +70,11 @@ public class GateWayInfoService extends SuperService {
     @Autowired
     DeviceSyncFullCardService deviceSyncFullCardService;
 
+    @Autowired
+    private ProjectInfoDao projectInfoDao;
+
+    @Autowired
+    ProjectInfoService projectInfoService;
 
     /**
      * 添加网关
@@ -88,6 +93,11 @@ public class GateWayInfoService extends SuperService {
             gateWayInfo.setState(OnLineState.OffLine);
         }
         gateWayInfoDao.save(gateWayInfo);
+        if (StringUtils.isNotEmpty(param.getProjectInfoCode())) {
+            ProjectInfo projectInfo = projectInfoDao.findTopByCode(param.getProjectInfoCode());
+            gateWayInfo.setProjectInfo(projectInfo);
+        }
+        // 通知同步
         deviceSyncFullCardService.noticeSyncGateWay(gateWayInfo);
         return ResultContent.buildSuccess();
     }
@@ -236,6 +246,7 @@ public class GateWayInfoService extends SuperService {
         GateWayInfoModel model = new GateWayInfoModel();
         if (ObjectUtils.isNotEmpty(entity)) {
             BeanUtils.copyProperties(entity, model);
+            model.setProjectInfo(projectInfoService.toModel(entity.getProjectInfo()));
         }
         return model;
     }