TRX 1 سال پیش
والد
کامیت
832d55dc59

+ 29 - 14
OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/artemis/OperationMessageResultModel.java

@@ -1,9 +1,8 @@
 package com.zhongshu.iot.client.model.artemis;
 
 import cn.hutool.json.JSONObject;
-import com.zhongshu.iot.client.model.artemis.OperationMessageModel;
 import com.zhongshu.iot.client.model.baseParam.SuperModel;
-import com.zhongshu.iot.client.model.iot.IotMainModel;
+import com.zhongshu.iot.client.type.OperationType;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.AllArgsConstructor;
 import lombok.Data;
@@ -19,6 +18,19 @@ import lombok.NoArgsConstructor;
 public class OperationMessageResultModel extends SuperModel {
 
     //---------------------消息相关信息 start------------------
+
+    @Schema(description = "mqtt消息类型: 发送 接收")
+    private OperationType operationType;
+
+    private String operationTypeStr;
+
+    public String operationTypeStr() {
+        if (operationType != null) {
+            return operationType.getRemark();
+        }
+        return "";
+    }
+
     @Schema(description = "设备ID")
     private String deviceId;
 
@@ -28,15 +40,25 @@ public class OperationMessageResultModel extends SuperModel {
     @Schema(description = "网关ID")
     private String gateWayId;
 
-    @Schema(description = "消息内容")
-    private OperationMessageModel operationMessage;
-
-    @Schema(description = "关联的事件")
-    private IotMainModel iotMain;
+    @Schema(description = "发送数据")
+    private Object data;
 
     @Schema(description = "topic")
     private String realIotTopic;
 
+    //--------------------发送相关 start --------------
+    @Schema(description = "是否发送成功")
+    private Boolean isSendSuccess = Boolean.TRUE;
+
+    @Schema(description = "发送结果")
+    private String sendMsg = "";
+
+    @Schema(description = "是否需要返回")
+    private Boolean isNeedReplay;
+
+    @Schema(description = "replay数据")
+    private JSONObject replayData;
+
     //-------------------业务处理结果 start----------------
 
     @Schema(description = "是否处理成功")
@@ -54,13 +76,6 @@ public class OperationMessageResultModel extends SuperModel {
     @Schema(description = "处理时间")
     private Long handlerTime;
 
-    //--------------------返回数据 start(就是把结果发送给响应网关)-------------
-    @Schema(description = "是否需要返回")
-    private Boolean isNeedReplay = Boolean.TRUE;
-
-    @Schema(description = "replay数据")
-    private JSONObject replayData;
-
     //--------------------返回数据 start(就是把结果发送给响应网关)-------------
     @Schema(description = "是否响应成功")
     private Boolean isResult = Boolean.FALSE;

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

@@ -1,6 +1,7 @@
 package com.zhongshu.iot.client.model.artemis;
 
 import com.zhongshu.iot.client.model.baseParam.SuperSearchParam;
+import com.zhongshu.iot.client.type.OperationType;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.AllArgsConstructor;
 import lombok.Data;
@@ -14,6 +15,7 @@ import lombok.NoArgsConstructor;
 @AllArgsConstructor
 @NoArgsConstructor
 public class OperationMessageResultSearch extends SuperSearchParam {
+
     @Schema(description = "设备ID")
     private String deviceId;
 
@@ -25,4 +27,16 @@ public class OperationMessageResultSearch extends SuperSearchParam {
 
     @Schema(description = "topic")
     private String realIotTopic;
+
+    @Schema(description = "所属物模型topicID")
+    private String iotMainId;
+
+    @Schema(description = "所属物模型id")
+    private String iotTemplateId;
+
+    @Schema(description = "是否发送成功")
+    private Boolean isSendSuccess;
+
+    @Schema(description = "mqtt消息类型: 发送 接收")
+    private OperationType operationType;
 }

+ 5 - 3
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/devices/OperationMessageController.java

@@ -2,13 +2,13 @@ package com.zhongshu.iot.server.core.controller.devices;
 
 import com.github.microservice.auth.security.annotations.ResourceAuth;
 import com.github.microservice.auth.security.type.AuthType;
+import com.github.microservice.net.ResultContent;
 import com.zhongshu.iot.client.model.artemis.OperationMessageModel;
 import com.zhongshu.iot.client.model.artemis.OperationMessageResultModel;
 import com.zhongshu.iot.client.model.artemis.OperationMessageResultSearch;
 import com.zhongshu.iot.client.model.artemis.OperationMessageSearchParam;
 import com.zhongshu.iot.server.core.service.artemis.OperationMessageService;
 import com.zhongshu.iot.server.core.service.device.DeviceInfoService;
-import com.github.microservice.net.ResultContent;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
 import io.swagger.v3.oas.annotations.tags.Tag;
@@ -41,7 +41,7 @@ public class OperationMessageController {
     OperationMessageService operationMessageService;
 
     @ResourceAuth(value = "user", type = AuthType.User)
-    @Operation(summary = "标指令已响应")
+    @Operation(summary = "标指令已响应")
     @RequestMapping(value = "receiveMessage", method = {RequestMethod.GET})
     @Parameter(name = "messageId", description = "指令ID")
     public ResultContent receiveMessage(String messageId) {
@@ -55,6 +55,8 @@ public class OperationMessageController {
         return operationMessageService.page(pageable, param);
     }
 
+    //------------------------------------具体的发送消息 start-------------------
+
     @ResourceAuth(value = "user", type = AuthType.User)
     @Operation(summary = "日志列表-分页查询")
     @RequestMapping(value = {"pageMessage"}, method = {RequestMethod.POST})
@@ -65,7 +67,7 @@ public class OperationMessageController {
     }
 
     @ResourceAuth(value = "user", type = AuthType.User)
-    @Operation(summary = "得到设备日志详情")
+    @Operation(summary = "得到消息详情")
     @RequestMapping(value = "getMessageById", method = {RequestMethod.GET})
     public ResultContent<OperationMessageResultModel> getMessageById(
             @Parameter(name = "id", description = "数据ID", example = "")

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

@@ -11,6 +11,8 @@ import org.springframework.data.domain.Pageable;
  * @Version: 1.0
  */
 public interface OperationMessageResultDaoExtend {
+
     Page<OperationMessageResult> page(Pageable pageable, OperationMessageResultSearch param);
 
+
 }

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

@@ -1,9 +1,11 @@
 package com.zhongshu.iot.server.core.dao.mqtt.impl;
 
-import com.zhongshu.iot.server.core.dao.base.BaseImpl;
-import com.zhongshu.iot.server.core.dao.mqtt.extend.OperationMessageResultDaoExtend;
 import com.github.microservice.components.data.mongo.mongo.helper.DBHelper;
 import com.zhongshu.iot.client.model.artemis.OperationMessageResultSearch;
+import com.zhongshu.iot.server.core.dao.base.BaseImpl;
+import com.zhongshu.iot.server.core.dao.mqtt.extend.OperationMessageResultDaoExtend;
+import com.zhongshu.iot.server.core.domain.iot.IotMain;
+import com.zhongshu.iot.server.core.domain.iot.IotTemplate;
 import com.zhongshu.iot.server.core.domain.iot.mqtt.OperationMessageResult;
 import com.zhongshu.iot.server.core.util.CommonUtil;
 import org.apache.commons.lang3.StringUtils;
@@ -44,14 +46,32 @@ public class OperationMessageResultDaoImpl extends BaseImpl implements Operation
             criteria.and("deviceId").is(param.getDeviceId());
         }
 
-        if (StringUtils.isNotEmpty(param.getEpId())) {
-            criteria.and("epId").is(param.getEpId());
-        }
-
         if (StringUtils.isNotEmpty(param.getGateWayId())) {
             criteria.and("gateWayId").is(param.getGateWayId());
         }
 
+        if (StringUtils.isNotEmpty(param.getProjectCode())) {
+            criteria.and("projectCode").is(param.getProjectCode());
+        }
+
+        if (StringUtils.isNotEmpty(param.getIotMainId())) {
+            criteria.and("iotMain").is(IotMain.build(param.getIotMainId()));
+        }
+
+        if (StringUtils.isNotEmpty(param.getIotTemplateId())) {
+            criteria.and("iotTemplate").is(IotTemplate.build(param.getIotTemplateId()));
+        }
+
+        // 是否成功
+        if (param.getIsSendSuccess() != null) {
+            criteria.and("isSendSuccess").is(param.getIsSendSuccess());
+        }
+
+        // 是接收还是发送
+        if (param.getOperationType() != null) {
+            criteria.and("operationType").is(param.getOperationType());
+        }
+
         // 时间范围
         if (!CommonUtil.longIsEmpty(param.getStartTime()) && !CommonUtil.longIsEmpty(param.getEndTime())) {
             criteria.and("createTime").gte(param.getStartTime()).lte(param.getEndTime());

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

@@ -129,4 +129,10 @@ public class IotMain extends SuperEntity {
 
     @Schema(description = "网关信息")
     private String gateWayId;
+
+    public static IotMain build(String id) {
+        IotMain iotMain = new IotMain();
+        iotMain.setId(id);
+        return iotMain;
+    }
 }

+ 10 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/domain/iot/mqtt/OperationMessage.java

@@ -1,5 +1,6 @@
 package com.zhongshu.iot.server.core.domain.iot.mqtt;
 
+import cn.hutool.json.JSONObject;
 import com.zhongshu.iot.client.type.OperationType;
 import com.zhongshu.iot.server.core.domain.base.SuperEntity;
 import io.swagger.v3.oas.annotations.media.Schema;
@@ -122,7 +123,16 @@ public class OperationMessage extends SuperEntity {
     @Schema(description = "处理时间")
     private Long handlerTime;
 
+    //--------------------返回数据 start(就是把结果发送给响应网关)-------------
+
+    @Schema(description = "是否需要返回")
+    private Boolean isNeedReplay = Boolean.TRUE;
+
+    @Schema(description = "replay数据")
+    private JSONObject replayData;
+
     //--------------------返回数据 start ------------------
+
     @Schema(description = "是否响应成功")
     private Boolean isResult = Boolean.FALSE;
 

+ 12 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/domain/iot/mqtt/OperationMessageResult.java

@@ -4,6 +4,7 @@ import cn.hutool.json.JSONObject;
 import com.zhongshu.iot.client.type.OperationType;
 import com.zhongshu.iot.server.core.domain.base.SuperEntity;
 import com.zhongshu.iot.server.core.domain.iot.IotMain;
+import com.zhongshu.iot.server.core.domain.iot.IotTemplate;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.AllArgsConstructor;
 import lombok.Data;
@@ -36,8 +37,13 @@ public class OperationMessageResult extends SuperEntity {
     private OperationType operationType;
 
     @Schema(description = "关联的事件")
+    @DBRef(lazy = true)
     private IotMain iotMain;
 
+    @Schema(description = "所属物模型")
+    @DBRef(lazy = true)
+    private IotTemplate iotTemplate;
+
     @Schema(description = "设备ID")
     private String deviceId;
 
@@ -81,6 +87,12 @@ public class OperationMessageResult extends SuperEntity {
     @Schema(description = "replay数据")
     private JSONObject replayData;
 
+    //--------------------发送相关 start --------------
+    @Schema(description = "是否发送成功")
+    private Boolean isSendSuccess = Boolean.TRUE;
+
+    @Schema(description = "发送结果")
+    private String sendMsg = "";
 
     //-------------------响应相关信息 start ---------------------------------
     @Schema(description = "是否响应成功")

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

@@ -630,7 +630,7 @@ public class OperationMessageService {
      */
     public ResultContent<Page<OperationMessageResultModel>> pageMessage(Pageable pageable, OperationMessageResultSearch param) {
         Page<OperationMessageResult> page = operationMessageResultDao.page(pageable, param);
-        return ResultContent.buildSuccess(PageEntityUtil.toPageModel(page, this::toModel));
+        return ResultContent.buildSuccess(PageEntityUtil.toPageModel(page, this::toResultModel));
     }
 
     /**
@@ -644,7 +644,7 @@ public class OperationMessageService {
         if (ObjectUtils.isEmpty(messageResult)) {
             return ResultContent.buildFail(String.format("数据ID不存在:%s", id));
         }
-        OperationMessageResultModel model = toModel(messageResult);
+        OperationMessageResultModel model = toResultModel(messageResult);
         return ResultContent.buildSuccess(model);
     }
 
@@ -680,11 +680,10 @@ public class OperationMessageService {
         return model;
     }
 
-    public OperationMessageResultModel toModel(OperationMessageResult entity) {
+    public OperationMessageResultModel toResultModel(OperationMessageResult entity) {
         OperationMessageResultModel model = null;
         if (ObjectUtils.isNotEmpty(entity)) {
             model = new OperationMessageResultModel();
-
         }
         return model;
     }

+ 10 - 1
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iot/IotSendMessageService.java

@@ -162,6 +162,7 @@ public class IotSendMessageService extends SuperService {
             entity.setTtl(new Date(System.currentTimeMillis() + ttlMill));
             entity.setReceiveTime(System.currentTimeMillis());
             entity.setReceiveTimeStr(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.FORMAT_LONG));
+            entity.setIsNeedReplay(param.getIsNeedReplay());
             operationMessageDao.save(entity);
 
             for (IotMain iotMain : list) {
@@ -175,6 +176,8 @@ public class IotSendMessageService extends SuperService {
                 messageResult.setOperationMessage(entity);
                 // 物模型信息
                 messageResult.setIotMain(iotMain);
+                messageResult.setIotTemplate(iotMain.getIotTemplate());
+                jsonObject.set("id", messageId);
 
                 // 设备ID
                 messageResult.setDeviceId(iotMain.getDeviceId());
@@ -185,12 +188,18 @@ public class IotSendMessageService extends SuperService {
                 messageResult.setData(jsonObject);
                 messageResult.setOperationType(entity.getOperationType());
 
-                jsonObject.set("id", messageId);
+                Boolean isSendSuccess = Boolean.TRUE;
+                String sendMsg = "下发成功";
                 try {
                     mqClient.sendObject(topic, JSONUtil.toJsonStr(jsonObject), messageId);
                 } catch (Exception e) {
                     e.printStackTrace();
+                    sendMsg = String.format("下发出错:%s", e.getMessage());
                 }
+                messageResult.setIsSendSuccess(isSendSuccess);
+                messageResult.setSendMsg(sendMsg);
+                messageResult.setOperationType(OperationType.Push);
+                messageResult.setIsNeedReplay(param.getIsNeedReplay());
                 operationMessageResultDao.save(messageResult);
             }
         } else {