TRX 1 an în urmă
părinte
comite
71841b1d9a

+ 23 - 0
OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/artemis/OperationMessageResultModel.java

@@ -2,6 +2,8 @@ package com.zhongshu.iot.client.model.artemis;
 
 import cn.hutool.json.JSONObject;
 import com.github.microservice.models.baseParam.SuperModel;
+import com.github.microservice.types.FunctionType;
+import com.zhongshu.iot.client.type.EventType;
 import com.zhongshu.iot.client.type.OperationType;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.AllArgsConstructor;
@@ -19,6 +21,27 @@ public class OperationMessageResultModel extends SuperModel {
 
     //---------------------消息相关信息 start------------------
 
+    @Schema(description = "功能类型,属性 事件 服务")
+    private FunctionType functionType;
+
+    @Schema(description = "标识符")
+    private String identifier;
+
+    @Schema(description = "属性,,事件名称")
+    private String iotName;
+
+    @Schema(description = "事件类型")
+    private EventType eventType;
+
+    private String eventTypeStr;
+
+    public String getEventTypeStr() {
+        if (eventType != null) {
+            return eventType.getRemark();
+        }
+        return "";
+    }
+
     @Schema(description = "mqtt消息类型: 发送 接收")
     private OperationType operationType;
 

+ 14 - 0
OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/artemis/OperationMessageResultSearch.java

@@ -1,6 +1,8 @@
 package com.zhongshu.iot.client.model.artemis;
 
 import com.github.microservice.models.baseParam.SuperSearchParam;
+import com.github.microservice.types.FunctionType;
+import com.zhongshu.iot.client.type.EventType;
 import com.zhongshu.iot.client.type.OperationType;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.AllArgsConstructor;
@@ -39,4 +41,16 @@ public class OperationMessageResultSearch extends SuperSearchParam {
 
     @Schema(description = "mqtt消息类型: 发送 接收")
     private OperationType operationType;
+
+    @Schema(description = "功能类型,属性 事件 服务")
+    private FunctionType functionType;
+
+    @Schema(description = "标识符")
+    private String identifier;
+
+    @Schema(description = "事件类型")
+    private EventType eventType;
+
+    @Schema(description = "属性,,事件名称")
+    private String iotName;
 }

+ 23 - 0
OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/iot/IotMainSimpleModel.java

@@ -0,0 +1,23 @@
+package com.zhongshu.iot.client.model.iot;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @author TRX
+ * @date 2024/6/20
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class IotMainSimpleModel {
+
+    @Schema(description = "功能名称")
+    private String name;
+
+    @Schema(description = "标识符")
+    private String identifier;
+
+}

+ 16 - 37
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/iot/IotController.java

@@ -4,7 +4,9 @@ import com.github.microservice.auth.security.annotations.ResourceAuth;
 import com.github.microservice.auth.security.type.AuthType;
 import com.github.microservice.models.baseParam.NameModel;
 import com.github.microservice.net.ResultContent;
+import com.github.microservice.types.FunctionType;
 import com.zhongshu.iot.client.model.iot.*;
+import com.zhongshu.iot.client.openApi.base.DeviceIdParam;
 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;
@@ -142,42 +144,19 @@ public class IotController {
     public ResultContent deviceBindIotTemplate(@RequestBody DeviceBindIotTemplate param) {
         return iotService.deviceBindIotTemplate(param);
     }
-//
-//    //-------------------------- Topic start------------------------------
-//    @ResourceAuth(value = "user", type = AuthType.User)
-//    @Operation(summary = "添加-编辑Topic", hidden = true)
-//    @RequestMapping(value = "addIotTopic", method = {RequestMethod.POST})
-//    public ResultContent addIotTopic(@RequestBody IotTopicParam param) {
-//        Assert.hasText(param.getTopic(), "topic不能为空");
-//        return iotService.addIotTopic(param);
-//    }
-//
-//    @ResourceAuth(value = "user", type = AuthType.User)
-//    @Operation(summary = "Topic列表-分页查询", hidden = true)
-//    @RequestMapping(value = {"pageIotTopic"}, method = {RequestMethod.POST})
-//    public ResultContent<Page<IotTopicModel>> pageIotTopic(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
-//            @Parameter(required = false) IotTopicSearch param) {
-//        return iotService.pageIotTopic(pageable, param);
-//    }
-//
-//    @ResourceAuth(value = "user", type = AuthType.User)
-//    @Operation(summary = "删除Topic", hidden = true)
-//    @RequestMapping(value = "deleteIotTopic", method = {RequestMethod.GET})
-//    public ResultContent deleteIotTopic(
-//            @RequestParam(name = "id")
-//            @Parameter(name = "id", description = "数据id") String id) {
-//        return iotService.deleteIotTopic(id);
-//    }
-//
-//    @ResourceAuth(value = "user", type = AuthType.User)
-//    @Operation(summary = "查询Topic", hidden = true)
-//    @RequestMapping(value = "getIotTopic", method = {RequestMethod.GET})
-//    public ResultContent<IotTopicModel> getIotTopic(
-//            @RequestParam(name = "id")
-//            @Parameter(name = "id", description = "数据id") String id) {
-//        return iotService.getIotTopic(id);
-//    }
-//
-//    //-------------------------- Topic end--------------------------------
+
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "查询设备所有的 事件")
+    @RequestMapping(value = "getDeviceEventIotMain", method = {RequestMethod.POST})
+    public ResultContent getDeviceEventIotMain(@RequestBody DeviceIdParam param) {
+        return iotService.getDeviceIotMain(param.getDeviceId(), FunctionType.Event);
+    }
+
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "查询设备所有的 服务")
+    @RequestMapping(value = "getDeviceServerIotMain", method = {RequestMethod.POST})
+    public ResultContent getDeviceServerIotMain(@RequestBody DeviceIdParam param) {
+        return iotService.getDeviceIotMain(param.getDeviceId(), FunctionType.Server);
+    }
 
 }

+ 2 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/dao/iot/IotMainDao.java

@@ -38,4 +38,6 @@ public interface IotMainDao extends IotMainDaoExtend, org.springframework.data.m
 
     void deleteByIotThingId(String iotThingId);
 
+    List<IotMain> findByDeviceIdAndFunctionTypeAndIotDataType(String deviceId, FunctionType functionType, IotDataType iotDataType);
+
 }

+ 5 - 1
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/dao/iot/impl/IotThing2DeviceDaoImpl.java

@@ -1,7 +1,7 @@
 package com.zhongshu.iot.server.core.dao.iot.impl;
 
-import com.github.microservice.components.data.mongo.mongo.helper.DBHelper;
 import com.github.microservice.busInfoModel.thing.IotThing2DeviceSearch;
+import com.github.microservice.components.data.mongo.mongo.helper.DBHelper;
 import com.zhongshu.iot.server.core.dao.base.BaseImpl;
 import com.zhongshu.iot.server.core.dao.iot.extend.IotThing2DeviceDaoExtend;
 import com.zhongshu.iot.server.core.domain.iot.IotThing2Device;
@@ -60,6 +60,10 @@ public class IotThing2DeviceDaoImpl extends BaseImpl implements IotThing2DeviceD
             criteria.and("onLineState").is(param.getOnLineState());
         }
 
+        if (StringUtils.isNotEmpty(param.getProductCode())) {
+            criteria.and("productCode").is(param.getProductCode());
+        }
+
         // 模糊搜索
         List<Criteria> criterias = new ArrayList<>();
         if (StringUtils.isNotEmpty(param.getDeviceId())) {

+ 2 - 1
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/dao/mqtt/OperationMessageResultDao.java

@@ -2,12 +2,13 @@ package com.zhongshu.iot.server.core.dao.mqtt;
 
 import com.zhongshu.iot.server.core.dao.mqtt.extend.OperationMessageResultDaoExtend;
 import com.zhongshu.iot.server.core.domain.iot.device.OperationMessageResult;
+import org.springframework.data.mongodb.repository.MongoRepository;
 
 /**
  * @author TRX
  * @date 2024/3/21
  */
-public interface OperationMessageResultDao extends OperationMessageResultDaoExtend, org.springframework.data.mongodb.repository.MongoRepository<OperationMessageResult, String> {
+public interface OperationMessageResultDao extends OperationMessageResultDaoExtend, MongoRepository<OperationMessageResult, String> {
 
     OperationMessageResult findTopById(String id);
 

+ 16 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/dao/mqtt/impl/OperationMessageResultDaoImpl.java

@@ -72,12 +72,28 @@ public class OperationMessageResultDaoImpl extends BaseImpl implements Operation
             criteria.and("operationType").is(param.getOperationType());
         }
 
+        if (param.getFunctionType() != null) {
+            criteria.and("functionType").is(param.getFunctionType());
+        }
+
+        if (StringUtils.isNotEmpty(param.getIdentifier())) {
+            criteria.and("identifier").is(param.getIdentifier());
+        }
+
+        if (param.getEventType() != null) {
+            criteria.and("eventType").is(param.getEventType());
+        }
+
         // 模糊搜索
         List<Criteria> criterias = new ArrayList<>();
         if (StringUtils.isNotEmpty(param.getRealIotTopic())) {
             Pattern pattern = Pattern.compile("^.*" + param.getRealIotTopic() + ".*$");
             criterias.add(Criteria.where("realIotTopic").is(pattern));
         }
+        if (StringUtils.isNotEmpty(param.getIotName())) {
+            Pattern pattern = Pattern.compile("^.*" + param.getIotName() + ".*$");
+            criterias.add(Criteria.where("iotName").is(pattern));
+        }
         if (!CollectionUtils.isEmpty(criterias)) {
             criteria.andOperator(criterias.toArray(new Criteria[]{}));
         }

+ 3 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/domain/iot/IotThing2Device.java

@@ -53,6 +53,9 @@ public class IotThing2Device extends SuperEntity {
     @Schema(description = "项目code")
     private String projectCode;
 
+    @Schema(description = "产品code")
+    private String productCode;
+
     @Schema(description = "在线状态")
     private OnLineState onLineState;
 

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

@@ -3,6 +3,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.EventType;
 import com.zhongshu.iot.client.type.OperationBusType;
 import com.zhongshu.iot.client.type.OperationType;
 import com.zhongshu.iot.server.core.domain.base.SuperEntity;
@@ -36,9 +37,19 @@ public class OperationMessageResult extends SuperEntity {
     @Schema(description = "所属产品code")
     private String productCode;
 
+    //--------------------属性相关的冗余信息 start-------------------
     @Schema(description = "功能类型,属性 事件 服务")
     private FunctionType functionType;
 
+    @Schema(description = "标识符")
+    private String identifier;
+
+    @Schema(description = "属性,,事件名称")
+    private String iotName;
+
+    @Schema(description = "事件类型")
+    private EventType eventType;
+
     @Schema(description = "消息内容")
     @DBRef(lazy = true)
     private OperationMessage operationMessage;
@@ -75,7 +86,7 @@ public class OperationMessageResult extends SuperEntity {
     @Schema(description = "topic")
     private String realIotTopic;
 
-    @Schema(description = "发送数据")
+    @Schema(description = "入参,发送数据")
     private Object data;
 
     //-------------------业务处理结果 start----------------
@@ -103,7 +114,7 @@ public class OperationMessageResult extends SuperEntity {
     @Schema(description = "是否需要返回")
     private Boolean isNeedReplay = Boolean.TRUE;
 
-    @Schema(description = "响应/处理replay数据")
+    @Schema(description = "响应/处理replay数据,出参")
     private JSONObject replayData;
 
     //--------------------发送相关 start --------------

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

@@ -473,21 +473,12 @@ 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
-            messageResult.setProjectCode(iotMain.getProjectCode());
-            messageResult.setGateWayId(entity.getGateWayId());
-            messageResult.setRealIotTopic(iotMain.getRealIotTopic());
+            messageResult.setData(data);
+
+            // OperationMessageResult 组装 IotMain 的信息
+            buildOperationMessageResultIotInfo(messageResult, iotMain);
 
+            messageResult.setGateWayId(entity.getGateWayId());
             boolean isHandleSuccess = true;
             String handleMsg = "处理成功";
 
@@ -638,7 +629,7 @@ public class OperationMessageService {
     }
 
     /**
-     * 设备消息列表日志
+     * 设备消息列表日志 (具体的处理)
      *
      * @param pageable
      * @param param
@@ -695,6 +686,30 @@ public class OperationMessageService {
         return ResultContent.buildSuccess();
     }
 
+    /**
+     * OperationMessageResult 组装 IotMain 的信息
+     * @param messageResult
+     * @param iotMain
+     */
+    public void buildOperationMessageResultIotInfo(OperationMessageResult messageResult, IotMain iotMain) {
+        if (ObjectUtils.isEmpty(messageResult) || ObjectUtils.isEmpty(iotMain)) {
+            return;
+        }
+        // 所属物模型事件 产品信息
+        messageResult.setIotMain(iotMain);
+        messageResult.setIotThingId(iotMain.getIotThingId());
+        messageResult.setProductCode(iotMain.getProductCode());
+        messageResult.setFunctionType(iotMain.getFunctionType());
+        messageResult.setIdentifier(iotMain.getIdentifier());
+        messageResult.setIotName(iotMain.getName());
+        messageResult.setEventType(iotMain.getEventType());
+        // 设备ID
+        messageResult.setDeviceId(iotMain.getDeviceId());
+        // 分组code
+        messageResult.setProjectCode(iotMain.getProjectCode());
+        messageResult.setRealIotTopic(iotMain.getRealIotTopic());
+    }
+
     public OperationMessageModel toModel(OperationMessage entity) {
         OperationMessageModel model = new OperationMessageModel();
         if (ObjectUtils.isNotEmpty(entity)) {

+ 24 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iot/IotServiceImpl.java

@@ -577,6 +577,21 @@ public class IotServiceImpl extends SuperService {
         return ResultContent.buildSuccess(toAttributeModel(entity));
     }
 
+    /**
+     *
+     * @param deviceId
+     * @param functionType
+     * @return
+     */
+    public ResultContent<IotMainSimpleModel> getDeviceIotMain(String deviceId, FunctionType functionType) {
+        List<IotMain> list = iotMainDao.findByDeviceIdAndFunctionTypeAndIotDataType(deviceId, functionType, IotDataType.Device);
+        List<IotMainSimpleModel> models = new ArrayList<>();
+        if (ObjectUtils.isNotEmpty(list)) {
+            models = list.stream().map(this::toSimpleModel).distinct().collect(Collectors.toList());
+        }
+        return ResultContent.buildSuccess(models);
+    }
+
     /**
      * 物模型 结构查询
      *
@@ -672,5 +687,14 @@ public class IotServiceImpl extends SuperService {
         return model;
     }
 
+    public IotMainSimpleModel toSimpleModel(IotMain entity) {
+        IotMainSimpleModel model = null;
+        if (ObjectUtils.isNotEmpty(entity)) {
+            model = new IotMainSimpleModel();
+            BeanUtils.copyProperties(entity, model);
+        }
+        return model;
+    }
+
 
 }

+ 6 - 3
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iot/IotThing2DeviceService.java

@@ -1,11 +1,11 @@
 package com.zhongshu.iot.server.core.service.iot;
 
-import com.github.microservice.net.ResultContent;
-import com.github.microservice.net.ResultMessage;
-import com.github.microservice.types.deviceUse.ThingType;
 import com.github.microservice.busInfoModel.thing.IotThing2DeviceBind;
 import com.github.microservice.busInfoModel.thing.IotThing2DeviceModel;
 import com.github.microservice.busInfoModel.thing.IotThing2DeviceSearch;
+import com.github.microservice.net.ResultContent;
+import com.github.microservice.net.ResultMessage;
+import com.github.microservice.types.deviceUse.ThingType;
 import com.zhongshu.iot.server.core.dao.iot.IotThing2DeviceDao;
 import com.zhongshu.iot.server.core.dao.mqtt.DeviceInfoDao;
 import com.zhongshu.iot.server.core.domain.iot.IotThing;
@@ -73,9 +73,12 @@ public class IotThing2DeviceService extends SuperService {
             entity.setDeviceName(deviceInfo.getDeviceName());
             entity.setDeviceType(deviceInfo.getDeviceType());
             entity.setDeviceInfo(deviceInfo);
+
             entity.setProjectInfo(deviceInfo.getProjectInfo());
             entity.setProjectCode(deviceInfo.getProjectInfoCode());
             entity.setOnLineState(deviceInfo.getOnLineState());
+            // 所属产品信息
+            entity.setProductCode(deviceInfo.getProductCode());
             iotThing2DeviceDao.save(entity);
         }
         return ResultContent.buildSuccess();