diff --git a/mh-admin/src/main/java/com/mh/web/controller/monitor/HotWaterMonitorController.java b/mh-admin/src/main/java/com/mh/web/controller/monitor/HotWaterMonitorController.java index 23f55a9..7ecd07d 100644 --- a/mh-admin/src/main/java/com/mh/web/controller/monitor/HotWaterMonitorController.java +++ b/mh-admin/src/main/java/com/mh/web/controller/monitor/HotWaterMonitorController.java @@ -1,14 +1,15 @@ package com.mh.web.controller.monitor; import com.mh.common.core.controller.BaseController; -import com.mh.common.core.domain.ColumnData; import com.mh.common.core.domain.ColumnFilter; +import com.mh.common.core.domain.entity.DeviceState; import com.mh.common.core.domain.dto.HotWaterControlDTO; import com.mh.common.core.domain.dto.HotWaterNowDataDTO; import com.mh.common.core.domain.dto.PumpInfoDTO; import com.mh.common.core.domain.entity.ChillersEntity; import com.mh.common.core.page.TableDataInfo; import com.mh.system.service.device.ICollectionParamsManageService; +import com.mh.system.service.device.IDeviceLedgerService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -30,9 +31,12 @@ public class HotWaterMonitorController extends BaseController { private final ICollectionParamsManageService iCollectionParamsManageService; + private final IDeviceLedgerService deviceLedgerService; + @Autowired - public HotWaterMonitorController(ICollectionParamsManageService iCollectionParamsManageService) { + public HotWaterMonitorController(ICollectionParamsManageService iCollectionParamsManageService, IDeviceLedgerService deviceLedgerService) { this.iCollectionParamsManageService = iCollectionParamsManageService; + this.deviceLedgerService = deviceLedgerService; } /** @@ -89,4 +93,16 @@ public class HotWaterMonitorController extends BaseController { return getDataTable(list); } + /** + * 获取设备状态信息数据 + * @param systemType + * @return + */ + @GetMapping("/deviceState") + public TableDataInfo deviceState(@RequestParam("systemType") String systemType) { + startPage(); + List list = deviceLedgerService.deviceState(systemType); + return getDataTable(list); + } + } diff --git a/mh-common/src/main/java/com/mh/common/core/domain/entity/DeviceState.java b/mh-common/src/main/java/com/mh/common/core/domain/entity/DeviceState.java new file mode 100644 index 0000000..ef77558 --- /dev/null +++ b/mh-common/src/main/java/com/mh/common/core/domain/entity/DeviceState.java @@ -0,0 +1,81 @@ +package com.mh.common.core.domain.entity; + +import lombok.Data; + +import java.util.Date; + +/** + * @author LJF + * @version 1.0 + * @date 2025-02-14 09:30:47 + * @description 设备统计状态表 + */ +@Data +public class DeviceState { + + /** + * 当前时间 + */ + private Date curDate; + + /** + * 设备数目 + */ + private int deviceNum; + + /** + * 电表数目 + */ + private int electNum; + + /** + * 水表数目 + */ + private int waterNum; + + /** + * 泵数目 + */ + private int pumpNum; + + /** + * 压力表数目 + */ + private int pressureNum; + + /** + * 在线设备数目 + */ + private int onlineNum; + + /** + * 离线设备数目 + */ + private int offlineNum; + + /** + * 故障设备数目 + */ + private int faultNum; + + /** + * 上次故障数目 + */ + private int lastFaultNum; + + /** + * 故障环比 + */ + private String faultP; + + /** + * 热泵正在运行的数目 + */ + private int pumpOnline; + + /** + * 其他设备数目 + */ + private int otherNum; + +} diff --git a/mh-quartz/src/main/java/com/mh/quartz/task/HotWaterTask.java b/mh-quartz/src/main/java/com/mh/quartz/task/HotWaterTask.java new file mode 100644 index 0000000..2882c24 --- /dev/null +++ b/mh-quartz/src/main/java/com/mh/quartz/task/HotWaterTask.java @@ -0,0 +1,40 @@ +package com.mh.quartz.task; + +import com.mh.system.service.device.IDeviceLedgerService; +import jakarta.annotation.Resource; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description 生活热水供水系统定时器 + * @date 2025-06-17 16:12:04 + */ +@Slf4j +@Component("hotWaterTask") +public class HotWaterTask { + + @Resource + private IDeviceLedgerService deviceLedgerService; + + private boolean createOrUpdateDeviceState = false; + + /** + * 新增或者更新设备状态表 + */ + public void createOrUpdateDeviceState() { + try { + if (!createOrUpdateDeviceState) { + createOrUpdateDeviceState = true; + deviceLedgerService.createOrUpdateDeviceState(); + } + } catch (Exception e) { + log.error("新增或者更新设备状态表失败", e); + createOrUpdateDeviceState = false; + } finally { + createOrUpdateDeviceState = false; + } + } +} 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 acff726..0db7f5e 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 @@ -2,10 +2,14 @@ package com.mh.system.mapper.device; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.mh.common.core.domain.entity.DeviceLedger; +import com.mh.common.core.domain.entity.DeviceState; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Update; +import java.util.List; + /** * @author LJF * @version 1.0 @@ -21,4 +25,8 @@ public interface DeviceLedgerMapper extends BaseMapper { @Update("update device_ledger set status = #{status}, update_time = current_timestamp where id = #{id}") void updateOnlineOrOfflineStatus(@Param("id") String deviceLedgerId, @Param("status") int integer); + + @Select("SELECT pro_device_state(#{curDate})") + void createOrUpdateDeviceState(@Param("curDate") String curDate); + } diff --git a/mh-system/src/main/java/com/mh/system/mapper/device/DeviceStateMapper.java b/mh-system/src/main/java/com/mh/system/mapper/device/DeviceStateMapper.java new file mode 100644 index 0000000..1fe84fc --- /dev/null +++ b/mh-system/src/main/java/com/mh/system/mapper/device/DeviceStateMapper.java @@ -0,0 +1,22 @@ +package com.mh.system.mapper.device; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.mh.common.core.domain.entity.DeviceState; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Select; + +import java.util.List; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description 设备状态mapper类 + * @date 2025-06-17 17:40:14 + */ +@Mapper +public interface DeviceStateMapper extends BaseMapper { + + @Select("select * from device_state where system_type = #{systemType} and date(cur_date) = date(curdate()) limit 1") + List deviceState(String systemType); +} 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 09c6434..15d61aa 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 @@ -1,5 +1,6 @@ package com.mh.system.service.device; +import com.mh.common.core.domain.entity.DeviceState; import com.mh.common.core.domain.entity.DeviceLedger; import java.util.List; @@ -23,4 +24,8 @@ public interface IDeviceLedgerService { int deleteDeviceLedgerByIds(String[] ledgerIds); void updateDeviceLedgerStatus(); + + List deviceState(String systemType); + + void createOrUpdateDeviceState(); } 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 fc1dc36..d5e0154 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,11 +1,12 @@ 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.DeviceState; 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.mapper.device.DeviceStateMapper; import com.mh.system.service.device.IDeviceLedgerService; import jakarta.annotation.Resource; import org.springframework.stereotype.Service; @@ -27,9 +28,26 @@ public class DeviceLedgerServiceImpl implements IDeviceLedgerService { @Resource private DeviceLedgerMapper deviceLedgerMapper; + @Resource + private DeviceStateMapper deviceStateMapper; + @Resource private CollectionParamsManageMapper collectionParamsManageMapper; + @Override + public List deviceState(String systemType) { + if (StringUtils.isEmpty(systemType)) { + return List.of(); + } + return deviceStateMapper.deviceState(systemType); + } + + @Override + public void createOrUpdateDeviceState() { + String currentDate = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); + deviceLedgerMapper.createOrUpdateDeviceState(currentDate); + } + @Override public void updateDeviceLedgerStatus() { // 先从采集点为中查询,看看当天是否有数据上来