TRX 1 рік тому
батько
коміт
0c1fba628f

+ 2 - 5
src/main/java/com/zswl/dataservice/controller/free/GateWayFreeController.java

@@ -1,9 +1,6 @@
 package com.zswl.dataservice.controller.free;
 
-import com.zswl.dataservice.model.mqtt.DeviceInfoAddParam;
-import com.zswl.dataservice.model.mqtt.DeviceInfoRegisterParam;
-import com.zswl.dataservice.model.mqtt.GateWayBindDeviceParam;
-import com.zswl.dataservice.model.mqtt.GateWayInfoAddParam;
+import com.zswl.dataservice.model.mqtt.*;
 import com.zswl.dataservice.service.mqtt.DeviceInfoService;
 import com.zswl.dataservice.service.mqtt.GateWayInfoService;
 import com.zswl.dataservice.utils.result.ResultContent;
@@ -37,7 +34,7 @@ public class GateWayFreeController {
 
     @Operation(summary = "注册网关")
     @RequestMapping(value = "registerGateWay", method = {RequestMethod.POST})
-    public ResultContent registerGateWay(@RequestBody GateWayInfoAddParam param) {
+    public ResultContent<MqttInfoReturnModel> registerGateWay(@RequestBody GateWayInfoAddParam param) {
         Assert.hasText(param.getGateWayId(), "网关ID不能为空");
         return gateWayInfoService.registerGateWay(param);
     }

+ 1 - 1
src/main/java/com/zswl/dataservice/domain/docker/RestartPolicy.java

@@ -17,7 +17,7 @@ public class RestartPolicy {
 
     @Schema(description = "启动方式,如:always")
     @JsonProperty("name")
-    private String name;
+    private String name = "always";
 
     @Schema(description = "MaximumRetryCount,如: 0")
     @JsonProperty("maximumRetryCount")

+ 6 - 0
src/main/java/com/zswl/dataservice/domain/mqtt/MqttInfo.java

@@ -30,6 +30,12 @@ public class MqttInfo extends SuperEntity {
     @Schema(description = "mqtt端口")
     private String brokerPort;
 
+    @Schema(description = "mqtt用户名")
+    private String userName;
+
+    @Schema(description = "密码")
+    private String password;
+
     @Schema(description = "标记这个服务器的地址的名称,如:重庆、贵阳、成都")
     private AddressType address;
 

+ 1 - 1
src/main/java/com/zswl/dataservice/model/docker/DockerMetaParam.java

@@ -50,7 +50,7 @@ public class DockerMetaParam extends SuperParam {
 
     @Schema(description = "启动配置")
     @JsonProperty("RestartPolicy")
-    private RestartPolicy restartPolicy;
+    private RestartPolicy restartPolicy = new RestartPolicy();
 
     @Schema(description = "目录映射,mounts")
     private List<Mount> mounts = new ArrayList<>();

+ 22 - 0
src/main/java/com/zswl/dataservice/model/mqtt/MqttInfoReturnModel.java

@@ -0,0 +1,22 @@
+package com.zswl.dataservice.model.mqtt;
+
+import com.zswl.dataservice.model.baseParam.SuperModel;
+import com.zswl.dataservice.utils.mqtt.type.AddressType;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+/**
+ * @author TRX
+ * @date 2024/5/21
+ */
+@Data
+public class MqttInfoReturnModel {
+    @Schema(description = "MQTT地址")
+    private String brokerAdress;
+
+    @Schema(description = "用户名")
+    private String brokerUsername;
+
+    @Schema(description = "密码")
+    private String brokerPassword;
+}

+ 6 - 0
src/main/java/com/zswl/dataservice/model/mqtt/MqttInfoSimpleModel.java

@@ -21,6 +21,12 @@ public class MqttInfoSimpleModel extends SuperModel {
     @Schema(description = "mqtt端口")
     private String brokerPort;
 
+    @Schema(description = "mqtt用户名")
+    private String userName;
+
+    @Schema(description = "密码")
+    private String password;
+
     @Schema(description = "标记这个服务器的地址的名称,如:重庆、贵阳、成都")
     private AddressType address;
 

+ 8 - 2
src/main/java/com/zswl/dataservice/service/mqtt/GateWayInfoService.java

@@ -116,13 +116,19 @@ public class GateWayInfoService extends SuperService {
      * @param param
      * @return
      */
-    public ResultContent registerGateWay(GateWayInfoAddParam param) {
+    public ResultContent<MqttInfoReturnModel> registerGateWay(GateWayInfoAddParam param) {
         ProjectInfo projectInfo = projectInfoDao.findTopByCode(param.getProjectInfoCode());
         if (ObjectUtils.isEmpty(projectInfo)) {
             return ResultContent.buildFail(String.format("分组不存在:%s", param.getProjectInfoCode()));
         }
         addGateWayInfo(param);
-        return ResultContent.buildSuccess();
+
+        // 给网关分配个mqtt账号
+        MqttInfoReturnModel mqttInfoSimpleModel = new MqttInfoReturnModel();
+        mqttInfoSimpleModel.setBrokerAdress("tcp://162.14.78.247:61616");
+        mqttInfoSimpleModel.setBrokerUsername("admin");
+        mqttInfoSimpleModel.setBrokerPassword("admin123");
+        return ResultContent.buildSuccess(mqttInfoSimpleModel);
     }
 
     /**