TRX 1 an în urmă
părinte
comite
1949b32806

+ 3 - 0
OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/iot/IotTemplateParam.java

@@ -22,6 +22,9 @@ public class IotTemplateParam extends SuperParam {
     @Schema(description = "产品名称")
     private String name;
 
+    @Schema(description = "关联code,产品code")
+    private String productCode;
+
     @Schema(description = "产品品类,直连设备、网关子设备、网关设备")
     private DeviceCategory deviceCategory;
 

+ 2 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/iot/IotController.java

@@ -5,6 +5,7 @@ import com.github.microservice.auth.security.type.AuthType;
 import com.github.microservice.models.baseParam.NameModel;
 import com.github.microservice.net.ResultContent;
 import com.zhongshu.iot.client.model.iot.*;
+import com.zhongshu.iot.client.type.IotDataType;
 import com.zhongshu.iot.server.core.service.iot.IotServiceImpl;
 import com.zhongshu.iot.server.core.service.iot.IotTemplateManagerService;
 import io.swagger.v3.oas.annotations.Operation;
@@ -59,6 +60,7 @@ public class IotController {
     @RequestMapping(value = {"pageTemplate"}, method = {RequestMethod.POST})
     public ResultContent<Page<IotTemplateModel>> pageTemplate(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
             @Parameter(required = false) IotTemplateSearch param) {
+        param.setIotDataType(IotDataType.IotTemplate);
         return iotService.pageTemplate(pageable, param);
     }
 

+ 5 - 1
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/domain/iot/device/OperationMessageResult.java

@@ -1,6 +1,7 @@
 package com.zhongshu.iot.server.core.domain.iot.device;
 
 import cn.hutool.json.JSONObject;
+import com.github.microservice.types.FunctionType;
 import com.zhongshu.card.client.utils.DateUtils;
 import com.zhongshu.iot.client.type.OperationBusType;
 import com.zhongshu.iot.client.type.OperationType;
@@ -35,6 +36,9 @@ public class OperationMessageResult extends SuperEntity {
     @Schema(description = "所属产品code")
     private String productCode;
 
+    @Schema(description = "功能类型,属性 事件 服务")
+    private FunctionType functionType;
+
     @Schema(description = "消息内容")
     @DBRef(lazy = true)
     private OperationMessage operationMessage;
@@ -99,7 +103,7 @@ public class OperationMessageResult extends SuperEntity {
     @Schema(description = "是否需要返回")
     private Boolean isNeedReplay = Boolean.TRUE;
 
-    @Schema(description = "replay数据")
+    @Schema(description = "响应/处理replay数据")
     private JSONObject replayData;
 
     //--------------------发送相关 start --------------

+ 9 - 1
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/artemis/OperationMessageService.java

@@ -364,8 +364,9 @@ public class OperationMessageService {
                 entity.setOperationBusType(OperationBusType.IotThing);
                 // 去重
                 events = events.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(IotMain::getRealIotTopic))), ArrayList::new));
-                // 物模型执行
+                // 物模型执行 记录
                 for (IotMain iotMain : events) {
+                    //todo
                     executeOperationMessage(entity, requestData, iotMain);
                 }
             } else {
@@ -472,7 +473,14 @@ public class OperationMessageService {
             //todo
             OperationMessageResult messageResult = new OperationMessageResult();
             messageResult.setOperationMessage(entity);
+            messageResult.setData(entity.getData());
+
+            // 所属物模型事件 产品信息
             messageResult.setIotMain(iotMain);
+            messageResult.setIotThingId(iotMain.getIotThingId());
+            messageResult.setProductCode(iotMain.getProductCode());
+            messageResult.setFunctionType(iotMain.getFunctionType());
+
             // 设备ID
             messageResult.setDeviceId(iotMain.getDeviceId());
             // 分组code

+ 13 - 2
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/device/DeviceInfoService.java

@@ -10,6 +10,7 @@ import com.zhongshu.iot.client.model.iot.IotMainModel;
 import com.zhongshu.iot.client.model.mqtt.DeviceInfoAddParam;
 import com.zhongshu.iot.client.model.mqtt.DeviceInfoSearchParam;
 import com.zhongshu.iot.client.model.mqtt.DeviceInfoUpdateRemark;
+import com.zhongshu.iot.client.model.mqtt.GateWayUserInfoModel;
 import com.zhongshu.iot.client.type.IotDataType;
 import com.zhongshu.iot.client.type.type.LogsLevel;
 import com.zhongshu.iot.server.core.dao.iot.IotTemplateDao;
@@ -400,9 +401,9 @@ public class DeviceInfoService {
     }
 
     /**
-     * 统计产品关联的设备数量
+     * 统计产品关联的 设备数量
      *
-     * @param productCode
+     * @param productCode 产品code
      * @return
      */
     public Long countByProductCode(String productCode) {
@@ -482,7 +483,17 @@ public class DeviceInfoService {
         if (ObjectUtils.isNotEmpty(deviceInfo)) {
             DeviceInfoModel _model = toModel(deviceInfo);
             BeanUtils.copyProperties(_model, deviceInfoModel);
+            // 所属产品信息
             deviceInfoModel.setIotTemplate(iotService.toSimpleModel(deviceInfo.getProductCode()));
+
+            ResultContent<GateWayUserInfoModel> resultContent = gateWayUserInfoService.updateBindNumber(deviceInfo.getMqttUserName());
+            if (resultContent.isSuccess()) {
+                GateWayUserInfoModel gateWayUserInfoModel = resultContent.getContent();
+                if (ObjectUtils.isNotEmpty(gateWayUserInfoModel)) {
+                    deviceInfoModel.setMqttUserName(gateWayUserInfoModel.getUserName());
+                    deviceInfoModel.setMqttPassword(gateWayUserInfoModel.getPassWord());
+                }
+            }
         }
         return deviceInfoModel;
     }

+ 16 - 6
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iot/IotServiceImpl.java

@@ -97,22 +97,24 @@ public class IotServiceImpl extends SuperService {
         IotTemplate template = null;
         initDefaultUser(param);
 
-        IotTemplate temp = iotTemplateDao.findTopByNameAndIotDataType(param.getName(), IotDataType.IotTemplate);
+        if (StringUtils.isEmpty(param.getName())) {
+            return ResultContent.buildFail("name is empty");
+        }
+
+        IotTemplate nameTemp = iotTemplateDao.findTopByNameAndIotDataType(param.getName(), IotDataType.IotTemplate);
         if (StringUtils.isNotEmpty(param.getId())) {
             // 编辑 (只能编辑名称和备注)
             template = iotTemplateDao.findTopById(param.getId());
             if (ObjectUtils.isEmpty(template)) {
                 return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, param.getId()));
             }
-            if (ObjectUtils.isNotEmpty(temp) && !temp.getId().equals(param.getId())) {
+            if (ObjectUtils.isNotEmpty(nameTemp) && !nameTemp.getId().equals(template.getId())) {
                 return ResultContent.buildFail(String.format(ResultMessage.NAME_EXIT, param.getName()));
             }
             template.setName(param.getName());
             template.setRemark(param.getRemark());
         } else {
-            if (StringUtils.isEmpty(param.getName())) {
-                return ResultContent.buildFail("name is empty");
-            }
+            // 添加
             if (param.getDeviceCategory() == null) {
                 return ResultContent.buildFail("deviceCategory is empty");
             }
@@ -127,9 +129,17 @@ public class IotServiceImpl extends SuperService {
                 param.setSpecType(DeviceSpecType.Common);
             }
 
+            // 验证产品code
+            if (StringUtils.isNotEmpty(param.getProductCode())) {
+                IotTemplate codeTemp = iotTemplateDao.findTopByProductCodeAndIotDataType(param.getProductCode(), IotDataType.IotTemplate);
+                if (ObjectUtils.isNotEmpty(codeTemp)) {
+                    return ResultContent.buildFail(String.format("产品code已存在:%s", param.getProductCode()));
+                }
+            }
+
             // 新增加
             template = new IotTemplate();
-            if (ObjectUtils.isNotEmpty(temp)) {
+            if (ObjectUtils.isNotEmpty(nameTemp)) {
                 return ResultContent.buildFail(String.format(ResultMessage.NAME_EXIT, param.getName()));
             }
             template.setIotDataType(IotDataType.IotTemplate);