diff --git a/mh-admin/src/main/resources/logback.xml b/mh-admin/src/main/resources/logback.xml
index 71571bb..5e1890f 100644
--- a/mh-admin/src/main/resources/logback.xml
+++ b/mh-admin/src/main/resources/logback.xml
@@ -20,7 +20,7 @@
${log.path}/sys-info.%d{yyyy-MM-dd}.log
- 60
+ 1
${log.pattern}
@@ -42,7 +42,7 @@
${log.path}/sys-error.%d{yyyy-MM-dd}.log
- 60
+ 3
${log.pattern}
@@ -64,7 +64,7 @@
${log.path}/sys-user.%d{yyyy-MM-dd}.log
- 60
+ 1
${log.pattern}
diff --git a/mh-common/src/main/java/com/mh/common/constant/TopicEnum.java b/mh-common/src/main/java/com/mh/common/constant/TopicEnum.java
index 022de21..0a27143 100644
--- a/mh-common/src/main/java/com/mh/common/constant/TopicEnum.java
+++ b/mh-common/src/main/java/com/mh/common/constant/TopicEnum.java
@@ -1,5 +1,7 @@
package com.mh.common.constant;
+import com.mh.common.config.MHConfig;
+
import java.util.Arrays;
import java.util.regex.Pattern;
@@ -53,7 +55,9 @@ public enum TopicEnum {
return beanName;
}
- public static TopicEnum find(String topic) {
- return Arrays.stream(TopicEnum.values()).filter(topicEnum -> topicEnum.pattern.matcher(topic).matches()).findAny().orElse(UNKNOWN);
+ public static TopicEnum find(String proName, String topic) {
+ // 去掉第一个"/"以及之前数据
+ String finalTopic = topic.replaceFirst("^"+proName, "");;
+ return Arrays.stream(TopicEnum.values()).filter(topicEnum -> topicEnum.pattern.matcher(finalTopic).matches()).findAny().orElse(UNKNOWN);
}
}
diff --git a/mh-framework/src/main/java/com/mh/framework/mqtt/handler/InboundMessageRouter.java b/mh-framework/src/main/java/com/mh/framework/mqtt/handler/InboundMessageRouter.java
index 48b3e37..015746f 100644
--- a/mh-framework/src/main/java/com/mh/framework/mqtt/handler/InboundMessageRouter.java
+++ b/mh-framework/src/main/java/com/mh/framework/mqtt/handler/InboundMessageRouter.java
@@ -1,9 +1,11 @@
package com.mh.framework.mqtt.handler;
+import com.mh.common.config.MHConfig;
import com.mh.common.constant.ChannelName;
import com.mh.common.constant.TopicEnum;
import com.mh.common.utils.spring.SpringUtils;
import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.annotation.Router;
import org.springframework.integration.mqtt.support.MqttHeaders;
import org.springframework.integration.router.AbstractMessageRouter;
@@ -27,6 +29,10 @@ import java.util.Objects;
@Component
public class InboundMessageRouter extends AbstractMessageRouter {
+ /** 系统基础配置 */
+ @Autowired
+ private MHConfig mHConfig;
+
/**
* 目前只需要这个方式,后期在拓展使用IntegrationFlow方式
* @param message
@@ -39,9 +45,18 @@ public class InboundMessageRouter extends AbstractMessageRouter {
String topic = Objects.requireNonNull(headers.get(MqttHeaders.RECEIVED_TOPIC)).toString();
// byte[] payload = (byte[]) message.getPayload();
// log.info("从当前主题 topic: {}, 接收到的消息:{}", topic, new String(payload));
+ // 判断当前主题是否是当前项目的,温湿度目前写死的
+ if (!topic.startsWith(mHConfig.getName()) && !topic.contains("/temp")) {
+ log.info("当前主题 topic: {} 不是当前项目的,直接丢弃", topic);
+ return Collections.singleton(SpringUtils.getBean(ChannelName.DEFAULT_BOUND));
+ }
// 找到对应的主题消息通道
- TopicEnum topicEnum = TopicEnum.find(topic);
- MessageChannel bean = (MessageChannel) SpringUtils.getBean(topicEnum.getBeanName());
- return Collections.singleton(bean);
+ if (topic.contains("/temp")) {
+ return Collections.singleton(SpringUtils.getBean(ChannelName.EVENTS_UPLOAD_INBOUND));
+ } else {
+ TopicEnum topicEnum = TopicEnum.find(mHConfig.getName() + "/", topic);
+ MessageChannel bean = SpringUtils.getBean(topicEnum.getBeanName());
+ return Collections.singleton(bean);
+ }
}
}
diff --git a/mh-quartz/src/main/java/com/mh/quartz/task/DealOnOrOffData.java b/mh-quartz/src/main/java/com/mh/quartz/task/DealOnOrOffData.java
new file mode 100644
index 0000000..389ae67
--- /dev/null
+++ b/mh-quartz/src/main/java/com/mh/quartz/task/DealOnOrOffData.java
@@ -0,0 +1,29 @@
+package com.mh.quartz.task;
+
+import com.mh.system.service.device.IDeviceLedgerService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author LJF
+ * @version 1.0
+ * @project EEMCS
+ * @description 更新在线状态
+ * @date 2025-04-27 09:32:08
+ */
+@Slf4j
+@Component("dealOnOrOffData")
+public class DealOnOrOffData {
+
+ private IDeviceLedgerService deviceLedgerService;
+
+ public DealOnOrOffData(IDeviceLedgerService deviceLedgerService) {
+ this.deviceLedgerService = deviceLedgerService;
+ }
+
+ public void dealDeviceLedger() {
+ log.info("处理设备在线状态数据");
+ deviceLedgerService.updateDeviceLedgerStatus();
+ }
+
+}
diff --git a/mh-system/src/main/java/com/mh/system/mapper/device/CollectionParamsManageMapper.java b/mh-system/src/main/java/com/mh/system/mapper/device/CollectionParamsManageMapper.java
index 9023e5b..4766be8 100644
--- a/mh-system/src/main/java/com/mh/system/mapper/device/CollectionParamsManageMapper.java
+++ b/mh-system/src/main/java/com/mh/system/mapper/device/CollectionParamsManageMapper.java
@@ -139,37 +139,57 @@ public interface CollectionParamsManageMapper extends BaseMapper selectByAreaId(@Param("areaId") String areaId);
- @Select("select " +
- " csr.house_id, " +
- " hi.house_name, " +
- " cpm.other_name, " +
- " cpm.cur_value, " +
- " cpm.cur_time, " +
- " cpm.id as cpm_id, " +
- " dl.status, " +
- " hi.order_num, " +
- " cpm.param_type, " +
- " case " +
- " when ar.create_time >= CURRENT_DATE " +
- " and ar.create_time < CURRENT_DATE + interval '1 day' then 1 " +
- " else 0 " +
- " end as alarm_status " +
- "from " +
- " cpm_space_relation csr " +
- "join collection_params_manage cpm on " +
- " csr.cpm_id = cpm.id " +
- "join house_info hi on " +
- " csr.house_id = hi.id " +
- "join device_ledger dl on " +
- " dl.id = cpm.device_ledger_id " +
- "left join alarm_records ar on " +
- " ar.cpm_id = cpm.id " +
- "where " +
- " csr.floor_id = #{floorId} " +
- " and hi.floor_id = #{floorId} " +
- " and cpm.param_type = #{paramType} " +
- " and cpm.system_type = #{systemType}" +
- " order by hi.order_num ; ")
+ @Select("WITH ranked_data AS ( " +
+ " SELECT " +
+ " csr.house_id, " +
+ " hi.house_name, " +
+ " cpm.other_name, " +
+ " cpm.cur_value, " +
+ " cpm.cur_time, " +
+ " cpm.id as cpm_id, " +
+ " dl.status, " +
+ " hi.order_num, " +
+ " cpm.param_type, " +
+ " CASE " +
+ " WHEN ar.create_time >= CURRENT_DATE AND ar.create_time < CURRENT_DATE + interval '1 day' " +
+ " THEN 1 " +
+ " ELSE 0 " +
+ " END as alarm_status, " +
+ " ROW_NUMBER() OVER ( " +
+ " PARTITION BY csr.house_id " +
+ " ORDER BY " +
+ " CASE WHEN ar.create_time >= CURRENT_DATE AND ar.create_time < CURRENT_DATE + interval '1 day' THEN 0 ELSE 1 END, " +
+ " cpm.cur_time DESC " +
+ " ) as row_num " +
+ " FROM " +
+ " cpm_space_relation csr " +
+ " JOIN collection_params_manage cpm ON csr.cpm_id = cpm.id " +
+ " RIGHT JOIN house_info hi ON csr.house_id = hi.id " +
+ " JOIN device_ledger dl ON dl.id = cpm.device_ledger_id " +
+ " LEFT JOIN alarm_records ar ON ar.cpm_id = cpm.id " +
+ " WHERE " +
+ " csr.floor_id = #{floorId} " +
+ " AND hi.floor_id = #{floorId} " +
+ " AND cpm.param_type = #{paramType} " +
+ " AND cpm.system_type = #{systemType} " +
+ ") " +
+ "SELECT " +
+ " house_id, " +
+ " house_name, " +
+ " other_name, " +
+ " cur_value, " +
+ " cur_time, " +
+ " cpm_id, " +
+ " status, " +
+ " order_num, " +
+ " param_type, " +
+ " alarm_status " +
+ "FROM " +
+ " ranked_data " +
+ "WHERE " +
+ " row_num = 1 " +
+ "ORDER BY " +
+ " order_num; ")
List selectByParamType(@Param("systemType") String systemType,
@Param("floorId") String floorId,
@Param("paramType") String paramType);
@@ -307,4 +327,15 @@ public interface CollectionParamsManageMapper extends BaseMapper OffLine();
}
diff --git a/mh-system/src/main/java/com/mh/system/mapper/device/DeviceLedgerMapper.java b/mh-system/src/main/java/com/mh/system/mapper/device/DeviceLedgerMapper.java
index e226e14..acff726 100644
--- a/mh-system/src/main/java/com/mh/system/mapper/device/DeviceLedgerMapper.java
+++ b/mh-system/src/main/java/com/mh/system/mapper/device/DeviceLedgerMapper.java
@@ -16,6 +16,9 @@ import org.apache.ibatis.annotations.Update;
@Mapper
public interface DeviceLedgerMapper extends BaseMapper {
- @Update("update device_ledger set status = 0 where id = #{id}")
+ @Update("update device_ledger set status = 0, update_time = current_timestamp where id = #{id}")
void updateOnlineStatus(@Param("id") String deviceLedgerId);
+
+ @Update("update device_ledger set status = #{status}, update_time = current_timestamp where id = #{id}")
+ void updateOnlineOrOfflineStatus(@Param("id") String deviceLedgerId, @Param("status") int integer);
}
diff --git a/mh-system/src/main/java/com/mh/system/service/device/IDeviceLedgerService.java b/mh-system/src/main/java/com/mh/system/service/device/IDeviceLedgerService.java
index d79a87b..09c6434 100644
--- a/mh-system/src/main/java/com/mh/system/service/device/IDeviceLedgerService.java
+++ b/mh-system/src/main/java/com/mh/system/service/device/IDeviceLedgerService.java
@@ -21,4 +21,6 @@ public interface IDeviceLedgerService {
int updateDeviceLedger(DeviceLedger gatewayManage);
int deleteDeviceLedgerByIds(String[] ledgerIds);
+
+ void updateDeviceLedgerStatus();
}
diff --git a/mh-system/src/main/java/com/mh/system/service/device/impl/DeviceLedgerServiceImpl.java b/mh-system/src/main/java/com/mh/system/service/device/impl/DeviceLedgerServiceImpl.java
index 00077bb..fc1dc36 100644
--- a/mh-system/src/main/java/com/mh/system/service/device/impl/DeviceLedgerServiceImpl.java
+++ b/mh-system/src/main/java/com/mh/system/service/device/impl/DeviceLedgerServiceImpl.java
@@ -1,8 +1,10 @@
package com.mh.system.service.device.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.mh.common.core.domain.entity.CollectionParamsManage;
import com.mh.common.core.domain.entity.DeviceLedger;
import com.mh.common.utils.StringUtils;
+import com.mh.system.mapper.device.CollectionParamsManageMapper;
import com.mh.system.mapper.device.DeviceLedgerMapper;
import com.mh.system.service.device.IDeviceLedgerService;
import jakarta.annotation.Resource;
@@ -25,6 +27,19 @@ public class DeviceLedgerServiceImpl implements IDeviceLedgerService {
@Resource
private DeviceLedgerMapper deviceLedgerMapper;
+ @Resource
+ private CollectionParamsManageMapper collectionParamsManageMapper;
+
+ @Override
+ public void updateDeviceLedgerStatus() {
+ // 先从采集点为中查询,看看当天是否有数据上来
+ List deviceLedgerList = collectionParamsManageMapper.OffLine();
+ // 开始根据id更新设备台账状态
+ for (String deviceLedgerId : deviceLedgerList) {
+ deviceLedgerMapper.updateOnlineOrOfflineStatus(deviceLedgerId, 1);
+ }
+ }
+
@Override
public List selectDeviceLedgerList(DeviceLedger ledgerInfo) {
if (ledgerInfo == null) {