From 1b035ae5524d279bf960681d84fd8c511c78f921 Mon Sep 17 00:00:00 2001 From: mh Date: Wed, 30 Apr 2025 17:49:36 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=B8=BB=E6=9C=BA=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../device/ChillersParamsController.java | 72 +++++++++++ .../src/main/resources/application-dev.yml | 6 +- .../src/main/resources/application-prod.yml | 4 +- .../src/main/resources/application-test.yml | 4 +- .../java/com/mh/common/utils/DateUtils.java | 3 + .../dealdata/impl/DataProcessServiceImpl.java | 96 +++++++++++--- .../mapper/device/DataProcessMapper.java | 3 +- .../system/service/energy/IEnergyService.java | 3 + .../energy/impl/EnergyServiceImpl.java | 117 ++++++++++++++++++ 9 files changed, 286 insertions(+), 22 deletions(-) create mode 100644 mh-admin/src/main/java/com/mh/web/controller/device/ChillersParamsController.java diff --git a/mh-admin/src/main/java/com/mh/web/controller/device/ChillersParamsController.java b/mh-admin/src/main/java/com/mh/web/controller/device/ChillersParamsController.java new file mode 100644 index 0000000..b2c8679 --- /dev/null +++ b/mh-admin/src/main/java/com/mh/web/controller/device/ChillersParamsController.java @@ -0,0 +1,72 @@ +package com.mh.web.controller.device; + +import com.mh.common.core.controller.BaseController; +import com.mh.common.core.domain.AjaxResult; +import com.mh.common.core.domain.entity.CollectionParamsManage; +import com.mh.common.core.domain.entity.CommunicationParams; +import com.mh.common.core.domain.vo.EnergyConsumptionVO; +import com.mh.common.core.domain.vo.EnergyQueryVO; +import com.mh.common.core.page.TableDataInfo; +import com.mh.common.utils.DateUtils; +import com.mh.system.service.device.ICollectionParamsManageService; +import com.mh.system.service.device.ICommunicationParamsService; +import com.mh.system.service.energy.IEnergyService; +import org.springframework.web.bind.annotation.*; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * @author LJF + * @version 1.0 + * @project EEMCS + * @description 主机参数以及各个设备折线图数据 + * @date 2025-04-29 09:21:17 + */ +@RestController +@RequestMapping("/chillers") +public class ChillersParamsController extends BaseController { + + private final ICollectionParamsManageService iCollectionParamsManageService; + + private final IEnergyService energyService; + + public ChillersParamsController(ICollectionParamsManageService iCollectionParamsManageService, IEnergyService energyService) { + this.iCollectionParamsManageService = iCollectionParamsManageService; + this.energyService = energyService; + } + + /** + * 获取注解全部参数内容数据 + * @param collectionParamsManage + * @return + */ + @GetMapping("/list") + public TableDataInfo list(CollectionParamsManage collectionParamsManage) + { + List list = iCollectionParamsManageService.selectCollectionParamsManageList(collectionParamsManage); + // 再根据mtType进行分组 + Map> collect = list.stream().collect(Collectors.groupingBy(CollectionParamsManage::getMtType)); + // map转list + List> result = collect.entrySet().stream().map(entry -> { + Map map = new HashMap<>(); + map.put("mtType", entry.getKey()); + map.put("list", entry.getValue()); + return map; + }).collect(Collectors.toList()); + return getDataTable(result); + } + + /** + * 获取折线图数据:冷冻水进出水温度和冷却水进出水温度 + * @param vo + * @return + */ + @PostMapping("/lineList") + public AjaxResult lineList(@RequestBody EnergyQueryVO vo) { + return energyService.chillerLine(vo); + } + +} diff --git a/mh-admin/src/main/resources/application-dev.yml b/mh-admin/src/main/resources/application-dev.yml index ef61494..cdd9257 100644 --- a/mh-admin/src/main/resources/application-dev.yml +++ b/mh-admin/src/main/resources/application-dev.yml @@ -1,7 +1,7 @@ # 项目相关配置 mh: # 名称 - name: MH + name: mz # 版本 version: 1.0.0 # 版权年份 @@ -98,8 +98,8 @@ spring: # 主库数据源 master: #添加allowMultiQueries=true 在批量更新时才不会出错 - url: jdbc:postgresql://127.0.0.1:5432/eemcs_hw - # url: jdbc:postgresql://127.0.0.1:5432/eemcs +# url: jdbc:postgresql://127.0.0.1:5432/eemcs_hw_dev + url: jdbc:postgresql://127.0.0.1:5432/eemcs username: postgres password: mh@803 # 从库数据源 diff --git a/mh-admin/src/main/resources/application-prod.yml b/mh-admin/src/main/resources/application-prod.yml index 3390710..ce09e12 100644 --- a/mh-admin/src/main/resources/application-prod.yml +++ b/mh-admin/src/main/resources/application-prod.yml @@ -98,8 +98,8 @@ spring: # 主库数据源 master: #添加allowMultiQueries=true 在批量更新时才不会出错 -# url: jdbc:postgresql://127.0.0.1:5505/eemcs_hw - url: jdbc:postgresql://127.0.0.1:5505/eemcs + url: jdbc:postgresql://127.0.0.1:5505/eemcs_hw +# url: jdbc:postgresql://127.0.0.1:5505/eemcs username: postgres password: mhtech@803 # 从库数据源 diff --git a/mh-admin/src/main/resources/application-test.yml b/mh-admin/src/main/resources/application-test.yml index c0a3054..098d3eb 100644 --- a/mh-admin/src/main/resources/application-test.yml +++ b/mh-admin/src/main/resources/application-test.yml @@ -98,9 +98,9 @@ spring: # 主库数据源 master: #添加allowMultiQueries=true 在批量更新时才不会出错 - url: jdbc:postgresql://127.0.0.1:5432/eemcs + url: jdbc:postgresql://106.55.173.225:5505/eemcs_hw username: postgres - password: mh@803 + password: mhtech@803 # 从库数据源 slave: # 从数据源开关/默认关闭 diff --git a/mh-common/src/main/java/com/mh/common/utils/DateUtils.java b/mh-common/src/main/java/com/mh/common/utils/DateUtils.java index 3b8a9b8..8b5875e 100644 --- a/mh-common/src/main/java/com/mh/common/utils/DateUtils.java +++ b/mh-common/src/main/java/com/mh/common/utils/DateUtils.java @@ -351,6 +351,9 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils public static String getTimeLen(String timeType) { String timeLen = ""; switch (timeType) { + case "min": + timeLen = "16"; + break; case "hour": timeLen = "13"; break; diff --git a/mh-framework/src/main/java/com/mh/framework/dealdata/impl/DataProcessServiceImpl.java b/mh-framework/src/main/java/com/mh/framework/dealdata/impl/DataProcessServiceImpl.java index e821f6e..c53dac5 100644 --- a/mh-framework/src/main/java/com/mh/framework/dealdata/impl/DataProcessServiceImpl.java +++ b/mh-framework/src/main/java/com/mh/framework/dealdata/impl/DataProcessServiceImpl.java @@ -9,7 +9,6 @@ import com.mh.common.core.redis.RedisCache; import com.mh.common.model.request.AdvantechDatas; import com.mh.common.model.request.AdvantechReceiver; import com.mh.common.model.request.OneTwoThreeTempData; -import com.mh.common.model.request.Params; import com.mh.common.utils.DateUtils; import com.mh.common.utils.EnergyThreadPoolService; import com.mh.common.utils.StringUtils; @@ -457,22 +456,91 @@ public class DataProcessServiceImpl implements DataProcessService { @Override public void insertChillerReport(List cacheList) { - // 根据时间排序 - cacheList.sort(Comparator.comparing(CollectionParamsManage::getCurTime)); - // 批量插入到chillers_data_min表 - Calendar calendar = Calendar.getInstance(); - calendar.setTime(new Date()); - int year = calendar.get(Calendar.YEAR); - String tableName = "chillers_data_min" + year; - int batchSize = 10; - // 分页查询并插入数据 - for (int i = 0; i < cacheList.size(); i += batchSize) { - List batchList = cacheList.subList(i, Math.min(i + batchSize, cacheList.size())); - // 执行插入语句 - dataProcessMapper.batchInsertChiller(batchList, tableName); + // 先根据表具类型进行分组 + Map> groupMap = cacheList + .stream() + .collect(Collectors.groupingBy(CollectionParamsManage::getMtType)); + // 开始进行数据遍历 + for (Map.Entry> entry : groupMap.entrySet()) { + String mtType = entry.getKey(); + List dataList = entry.getValue(); + // 再根据mtNum分组 + Map> groupMap1 = dataList + .stream() + .collect(Collectors.groupingBy(CollectionParamsManage::getMtNum)); + // 开始进行数据遍历 + for (Map.Entry> entry1 : groupMap1.entrySet()) { + List dataList1 = entry1.getValue(); + // 进行数据处理入库操作等 + try { + List dealList = new ArrayList<>(); + Map> dateOptionalMap = dealAndInsertChillers(dataList1, mtType); + for (Map.Entry> value : dateOptionalMap.entrySet()) { + boolean present = value.getValue().isPresent(); + if (!present) { + continue; + } + dealList.add(value.getValue().get()); + } + // 根据时间排序 + dealList.sort(Comparator.comparing(CollectionParamsManage::getCurTime)); + // 批量插入到chillers_data_min表 + Calendar calendar = Calendar.getInstance(); + calendar.setTime(new Date()); + int year = calendar.get(Calendar.YEAR); + String tableName = "chillers_data_min" + year; + for (CollectionParamsManage collectionParamsManage : dealList) { + // 判断是否存在,存在的话就不插入 + DeviceReport deviceReport = new DeviceReport(); + deviceReport.setDeviceNum(collectionParamsManage.getMtNum()); + deviceReport.setCurTime(collectionParamsManage.getCurTime()); + if (null == dataProcessMapper.isHaveData(deviceReport, tableName)) { + continue; + } + dataProcessMapper.batchInsertChiller(List.of(collectionParamsManage), tableName); + } +// int batchSize = 10; +// // 分页查询并插入数据 +// for (int i = 0; i < cacheList.size(); i += batchSize) { +// List batchList = cacheList.subList(i, Math.min(i + batchSize, cacheList.size())); +// // 执行插入语句 +// dataProcessMapper.batchInsertChiller(batchList, tableName); +// } + } catch (Exception e) { + log.error("处理主机参数异常:{}", e); + } + } } } + /** + * 排序 + * @param map + * @return + */ + public static Map> sortMapByDate(Map> map) { + return map.entrySet().stream() + .sorted(Map.Entry.comparingByKey()) + .collect(Collectors.toMap( + Map.Entry::getKey, + Map.Entry::getValue, + (oldValue, newValue) -> oldValue, + LinkedHashMap::new + )); + } + + private Map> dealAndInsertChillers(List dataList, String mtType) { + // 格式化时间点,然后取同样时间点的最大值 + Map> collect = dataList.stream() + .peek(val -> val.setCurTime(DateUtils.stringToDate(DateUtils.getTimeMin(val.getCurTime(), 1), "yyyy-MM-dd HH:mm:ss"))) + .collect( + Collectors.groupingBy( + CollectionParamsManage::getCurTime, + Collectors.maxBy(Comparator.comparing(CollectionParamsManage::getCurValue))) + ); + return sortMapByDate(collect); + } + @Override public void batchUpdateRunTime(List> runTimeList) { diff --git a/mh-system/src/main/java/com/mh/system/mapper/device/DataProcessMapper.java b/mh-system/src/main/java/com/mh/system/mapper/device/DataProcessMapper.java index fe856c1..0a2de36 100644 --- a/mh-system/src/main/java/com/mh/system/mapper/device/DataProcessMapper.java +++ b/mh-system/src/main/java/com/mh/system/mapper/device/DataProcessMapper.java @@ -23,7 +23,7 @@ public interface DataProcessMapper { * @param tableName */ @Select("