TRX hace 1 año
padre
commit
5ee333ee68

+ 4 - 0
OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/iot/IotMainSearch.java

@@ -3,6 +3,7 @@ package com.zhongshu.iot.client.model.iot;
 import com.github.microservice.types.FunctionType;
 import com.github.microservice.models.baseParam.SuperSearchParam;
 import com.zhongshu.iot.client.type.DataType;
+import com.zhongshu.iot.client.type.EventType;
 import com.zhongshu.iot.client.type.IotDataType;
 import com.zhongshu.iot.client.type.RemoteUrlType;
 import io.swagger.v3.oas.annotations.media.Schema;
@@ -55,4 +56,7 @@ public class IotMainSearch extends SuperSearchParam {
     @Schema(description = "业务地址类型")
     private RemoteUrlType remoteUrlType;
 
+    @Schema(description = "事件类型")
+    private EventType eventType;
+
 }

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

@@ -79,6 +79,11 @@ public class IotMainDaoImpl extends BaseImpl implements IotMainDaoExtend {
             criteria.and("remoteUrlType").is(param.getRemoteUrlType());
         }
 
+        // 事件类型,如:消息 警告 故障
+        if (param.getEventType() != null) {
+            criteria.and("eventType").is(param.getEventType());
+        }
+
         // 模糊搜索
         List<Criteria> criterias = new ArrayList<>();
         if (StringUtils.isNotEmpty(param.getName())) {
@@ -101,11 +106,7 @@ public class IotMainDaoImpl extends BaseImpl implements IotMainDaoExtend {
         // 关键字搜索
         if (StringUtils.isNotEmpty(param.getKeyWord())) {
             Pattern pattern = Pattern.compile("^.*" + param.getKeyWord() + ".*$");
-            criteria.orOperator(
-                    Criteria.where("name").regex(pattern),
-                    Criteria.where("identifier").regex(pattern),
-                    Criteria.where("iotTopic").regex(pattern)
-            );
+            criteria.orOperator(Criteria.where("name").regex(pattern), Criteria.where("identifier").regex(pattern), Criteria.where("iotTopic").regex(pattern));
         }
 
         Sort sort = buildSort(param);

+ 4 - 2
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/domain/iot/IotDeviceData.java

@@ -2,7 +2,6 @@ package com.zhongshu.iot.server.core.domain.iot;
 
 import com.github.microservice.types.deviceUse.IotDeviceDataType;
 import com.zhongshu.card.client.utils.DateUtils;
-import com.zhongshu.iot.client.model.iot.IotAttribute;
 import com.zhongshu.iot.server.core.domain.base.SuperEntity;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.AllArgsConstructor;
@@ -44,7 +43,7 @@ public class IotDeviceData extends SuperEntity {
     private Object data;
 
     @Schema(description = "数据类型,如:当前数据,历史数据")
-    private IotDeviceDataType dataType;
+    private IotDeviceDataType dataType = IotDeviceDataType.Current;
 
     //------------------------------时间信息 start--------------------
     @Schema(description = "年份,如:2024")
@@ -65,6 +64,9 @@ public class IotDeviceData extends SuperEntity {
     @Schema(description = "当前的第几小时")
     private Integer hourOfDay;
 
+    @Schema(description = "时间,可阅读的")
+    private String timeStr;
+
     public void setTimes() {
         this.year = DateUtils.getCurrentYear();
         this.month = DateUtils.getCurrentMonthInYear();

+ 5 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iot/IotDeviceDataService.java

@@ -9,6 +9,7 @@ import com.zhongshu.iot.server.core.dao.iot.IotDeviceDataDao;
 import com.zhongshu.iot.server.core.dao.iot.IotMainDao;
 import com.zhongshu.iot.server.core.domain.iot.IotDeviceData;
 import com.zhongshu.iot.server.core.domain.iot.IotMain;
+import com.zhongshu.iot.server.core.util.DateUtils;
 import com.zhongshu.iot.server.core.util.bean.BeanUtils;
 import com.zhongshu.iot.server.core.util.page.PageEntityUtil;
 import lombok.extern.slf4j.Slf4j;
@@ -46,12 +47,15 @@ public class IotDeviceDataService {
     public ResultContent saveProperty(String deviceId, String property, Object value) {
         List<IotMain> iotMains = iotMainDao.findByDeviceIdAndIdentifierAndIotDataType(deviceId, property, IotDataType.Device);
         if (ObjectUtils.isNotEmpty(iotMains)) {
+
+            // 把以前的改为历史数据
             IotDeviceData iotDeviceData = iotDeviceDataDao.findTopByDeviceIdAndPropertyOrderByCreateTimeDesc(deviceId, property);
             if (ObjectUtils.isNotEmpty(iotDeviceData)) {
                 iotDeviceData.setDataType(IotDeviceDataType.History);
                 iotDeviceDataDao.save(iotDeviceData);
             }
 
+            // 保存最新的数据
             IotMain iotMain = iotMains.get(0);
             IotDeviceData temp = new IotDeviceData();
             temp.setIotMain(iotMain);
@@ -63,6 +67,7 @@ public class IotDeviceDataService {
             temp.setData(value);
             temp.setDataType(IotDeviceDataType.Current);
             temp.setTimes();
+            temp.setTimeStr(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.FORMAT_LONG));
             iotDeviceDataDao.save(temp);
 
             return ResultContent.buildSuccess();

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

@@ -114,7 +114,7 @@ public class IotServiceImpl extends SuperService {
 
         IotTemplate temp = 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()));
@@ -463,30 +463,36 @@ public class IotServiceImpl extends SuperService {
             String iotTopic = iotMain.getIotTopic();
             // 响应的topic
             String replyIotTopic = iotMain.getReplyIotTopic();
+            if (StringUtils.isEmpty(iotTopic)) {
+                iotTopic = "";
+            }
+            if (StringUtils.isEmpty(replyIotTopic)) {
+                replyIotTopic = "";
+            }
 
+            // 消息topic
             String realIotTopic = iotTopic;
             String replyRealIotTopic = replyIotTopic;
-            if (StringUtils.isNotEmpty(iotTopic)) {
-                realIotTopic = realIotTopic.replaceAll(Pattern.quote("${deviceId}"), deviceId);
-            }
-            if (StringUtils.isNotEmpty(replyIotTopic)) {
-                replyRealIotTopic = replyRealIotTopic.replaceAll(Pattern.quote("${deviceId}"), deviceId);
-            }
+
+            realIotTopic = realIotTopic.replaceAll(Pattern.quote("${deviceId}"), deviceId);
+            replyRealIotTopic = replyRealIotTopic.replaceAll(Pattern.quote("${deviceId}"), deviceId);
 
             DeviceInfo deviceInfo = deviceInfoDao.findTopByDeviceId(deviceId);
             if (ObjectUtils.isNotEmpty(deviceInfo)) {
                 GateWay2Device gateWay2Device = gateWay2DeviceDao.findTopByDeviceInfoOrderByUpdateTimeDesc(deviceInfo);
                 if (ObjectUtils.isNotEmpty(gateWay2Device)) {
                     String gateWayId = gateWay2Device.getGateWayInfo().getDeviceId();
-                    if (StringUtils.isNotEmpty(iotTopic)) {
-                        realIotTopic = realIotTopic.replaceAll(Pattern.quote("${gateWayId}"), gateWayId);
-                    }
-                    if (StringUtils.isNotEmpty(replyRealIotTopic)) {
-                        replyRealIotTopic = replyRealIotTopic.replaceAll(Pattern.quote("${gateWayId}"), gateWayId);
-                    }
+                    realIotTopic = realIotTopic.replaceAll(Pattern.quote("${gateWayId}"), gateWayId);
+                    replyRealIotTopic = replyRealIotTopic.replaceAll(Pattern.quote("${gateWayId}"), gateWayId);
                     iotMain.setGateWayId(gateWayId);
                 }
             }
+
+            if (deviceInfo.getDeviceCategory() == DeviceCategory.GW) {
+                realIotTopic = realIotTopic.replaceAll(Pattern.quote("${gateWayId}"), deviceInfo.getDeviceId());
+                replyRealIotTopic = replyRealIotTopic.replaceAll(Pattern.quote("${gateWayId}"), deviceInfo.getDeviceId());
+            }
+            
             iotMain.setRealIotTopic(realIotTopic);
             iotMain.setReplyRealIotTopic(replyRealIotTopic);
         }
@@ -547,9 +553,7 @@ public class IotServiceImpl extends SuperService {
     public ResultContent<Page<IotMainModel>> pageIotMain(Pageable pageable, IotMainSearch param) {
         initSearchParam(param);
         // 从物模型查看  或 从产品查看
-        if (StringUtils.isEmpty(param.getIotTemplateId())
-                && StringUtils.isEmpty(param.getIotThingId())
-                && StringUtils.isEmpty(param.getDeviceId())) {
+        if (StringUtils.isEmpty(param.getIotTemplateId()) && StringUtils.isEmpty(param.getIotThingId()) && StringUtils.isEmpty(param.getDeviceId())) {
             return ResultContent.buildFail("iotTemplateId和iotThingId和deviceId不能同时为空");
         }
         Page<IotMain> page = iotMainDao.page(pageable, param);