From 389faa711067feec3eb1cf42f945b8623f81d01f Mon Sep 17 00:00:00 2001 From: mh Date: Thu, 29 Aug 2024 17:37:25 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E6=B7=BB=E5=8A=A0=E4=B8=BB=E6=9C=BA?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E5=9F=BA=E6=9C=AC=E5=8F=82=E6=95=B0=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mh/user/constants/ChillerParamsEnum.java | 12 + .../user/controller/ChillersController.java | 112 +-- .../service/chillers/ChillersService.java | 4 + .../chillers/impl/ChillersServiceImpl.java | 637 +++++++++++------- .../user/utils/AnalysisReceiveOrder485.java | 14 +- .../main/java/com/mh/user/vo/HostListVO.java | 136 ++++ .../test/java/com/mh/user/SysUserTest.java | 72 +- 7 files changed, 604 insertions(+), 383 deletions(-) create mode 100644 user-service/src/main/java/com/mh/user/constants/ChillerParamsEnum.java create mode 100644 user-service/src/main/java/com/mh/user/vo/HostListVO.java diff --git a/user-service/src/main/java/com/mh/user/constants/ChillerParamsEnum.java b/user-service/src/main/java/com/mh/user/constants/ChillerParamsEnum.java new file mode 100644 index 0000000..38ad851 --- /dev/null +++ b/user-service/src/main/java/com/mh/user/constants/ChillerParamsEnum.java @@ -0,0 +1,12 @@ +package com.mh.user.constants; + +/** + * @author LJF + * @version 1.0 + * @project mh_esi + * @description 主机枚举类 + * @date 2024-08-28 17:21:39 + */ +public enum ChillerParamsEnum { + +} diff --git a/user-service/src/main/java/com/mh/user/controller/ChillersController.java b/user-service/src/main/java/com/mh/user/controller/ChillersController.java index a0be28a..23d4218 100644 --- a/user-service/src/main/java/com/mh/user/controller/ChillersController.java +++ b/user-service/src/main/java/com/mh/user/controller/ChillersController.java @@ -1,18 +1,18 @@ package com.mh.user.controller; +import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; import com.mh.common.http.HttpResult; import com.mh.user.dto.DisplayBoxDataDTO; import com.mh.user.dto.TableInfoDTO; -import com.mh.user.entity.GaugeEntity; -import com.mh.user.entity.HostValue; -import com.mh.user.entity.TableDataEntity; -import com.mh.user.entity.TableInfoEntity; +import com.mh.user.entity.*; import com.mh.user.service.chillers.ChillersService; import com.mh.user.service.chillers.DeviceDisplayService; import com.mh.user.service.chillers.GaugeService; +import com.mh.user.vo.HostListVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @@ -26,6 +26,7 @@ import java.util.List; * @throws : */ @RestController +@RequestMapping("/chillers") public class ChillersController { private final ChillersService chillersService; @@ -36,105 +37,12 @@ public class ChillersController { this.deviceDisplayService = deviceDisplayService; } - // 查询冷水机组各个部位的状态值 -// @GetMapping("/chillers") - - /** - * 查询冷水机组进出水温度值等设备数据详情 - * @param deviceType - * @param type - * @return - */ - @GetMapping("/charts/getDisplayBoxData") - public HttpResult getDisplayBoxData(@RequestParam(value = "deviceType") String deviceType, - @RequestParam(value = "type") Integer type) { - List displayBoxDataDTOS = deviceDisplayService.deviceDisplayBoxData(deviceType, String.valueOf(type)); - return HttpResult.ok("success", displayBoxDataDTOS); - } - - /** - * 主机监测详情左侧表格数据 - * @param deviceName - * @return - */ - @GetMapping("/charts/getHostTableOneData") - public HttpResult queryChillersOneTable(@RequestParam(value = "deviceName") String deviceName) { - TableInfoDTO tableInfoDTO = new TableInfoDTO<>(); - tableInfoDTO.setTableInfo(chillersService.queryLeftAndRightData(deviceName, 1)); - return HttpResult.ok("success", tableInfoDTO); - } - - /** - * 主机监测详情顶部表格数据 - * @param deviceName - * @return - */ - @GetMapping("/charts/getHostTopData") - public HttpResult queryChillersTopTable(@RequestParam(value = "deviceName", required = true) String deviceName) { - TableInfoDTO tableInfoDTO = new TableInfoDTO<>(); - tableInfoDTO.setTableInfo(chillersService.queryTopData(deviceName, 1)); - return HttpResult.ok("success", tableInfoDTO); - } - - /** - * 主机监测详情右侧一表格数据 - * @param deviceName - * @return - */ - @GetMapping("/charts/getHostTableTwoData") - public HttpResult queryChillersRightTable(@RequestParam(value = "deviceName", required = true) String deviceName) { - TableInfoDTO tableInfoDTO = new TableInfoDTO<>(); - tableInfoDTO.setTableInfo(chillersService.queryLeftAndRightData(deviceName, 2)); - return HttpResult.ok("success", tableInfoDTO); - } - - /** - * 主机监测详情右侧二表格数据 - * @param deviceName - * @return - */ - @GetMapping("/charts/getHostTableThreeData") - public HttpResult queryChillersRightTable1(@RequestParam(value = "deviceName", required = true) String deviceName) { - TableInfoDTO tableInfoDTO = new TableInfoDTO<>(); - tableInfoDTO.setTableInfo(chillersService.queryLeftAndRightData(deviceName, 3)); - return HttpResult.ok("success", tableInfoDTO); + @GetMapping("/queryListByProId") + public HttpResult queryChillersByProId(@RequestParam(value = "proId", required = false) String proId, + @RequestParam("systemId") String systemId) { + JSONArray resultJson = chillersService.queryChillersByProId(systemId, proId); + return HttpResult.ok(resultJson); } - // 冷却泵、冷冻泵、冷却塔详情页顶部表格数据 - @GetMapping("/charts/getPumpOrTowerTopTableData") - public HttpResult getPumpOrTowerTopData(@RequestParam(value = "deviceName", required = true) String deviceName) { - TableInfoDTO tableInfoDTO = new TableInfoDTO<>(); - tableInfoDTO.setTableInfo(chillersService.queryLeftAndRightData(deviceName, 1)); - return HttpResult.ok("success", tableInfoDTO); - } - - // 冷却泵、冷冻泵、冷却塔详情页顶部数据 -// @GetMapping("/charts/getPumpOrTowerTopTableData") - @GetMapping("/charts/getPumpOrTowerTopData") - public HttpResult getPumpOrTowerTopTableData(@RequestParam(value = "deviceName", required = true) String deviceName) { - TableInfoDTO tableInfoDTO = new TableInfoDTO<>(); - tableInfoDTO.setTableInfo(chillersService.queryTopData(deviceName, 1)); - return HttpResult.ok("success", tableInfoDTO); - } - - - // 获取冷却/冷冻水进出水温度、主机/冷却塔温度 - @GetMapping("/operation/getTempValue") - public HttpResult getTempValue(@RequestParam(value = "deviceType", required = true) String deviceType) { - List hostValueList = chillersService.queryTempValue(deviceType); - JSONObject jsonObject = new JSONObject(); - jsonObject.put("values", hostValueList); - return HttpResult.ok("success",jsonObject); - } - - @Autowired - private GaugeService gaugeService; - - // 设备监控页表盘分析图 - @GetMapping("/charts/getGaugeData") - public HttpResult getGaugeData(@RequestParam(value = "type") String type, @RequestParam(value = "deviceName") String deviceName) { - GaugeEntity gaugeEntity = gaugeService.getGaugeData(type,deviceName); - return HttpResult.ok("success",gaugeEntity); - } } diff --git a/user-service/src/main/java/com/mh/user/service/chillers/ChillersService.java b/user-service/src/main/java/com/mh/user/service/chillers/ChillersService.java index 1eca903..85e68fe 100644 --- a/user-service/src/main/java/com/mh/user/service/chillers/ChillersService.java +++ b/user-service/src/main/java/com/mh/user/service/chillers/ChillersService.java @@ -1,9 +1,12 @@ package com.mh.user.service.chillers; +import com.alibaba.fastjson2.JSONArray; +import com.alibaba.fastjson2.JSONObject; import com.mh.user.entity.ChillersEntity; import com.mh.user.entity.HostValue; import com.mh.user.entity.TableDataEntity; import com.mh.user.entity.TableInfoEntity; +import com.mh.user.vo.HostListVO; import org.apache.ibatis.annotations.Param; import java.util.List; @@ -57,4 +60,5 @@ public interface ChillersService { // 通过DDC地址查询对应的采集参数设备 List queryDDCAddr(String ddcAddr); + JSONArray queryChillersByProId(String systemId, String proId); } diff --git a/user-service/src/main/java/com/mh/user/service/chillers/impl/ChillersServiceImpl.java b/user-service/src/main/java/com/mh/user/service/chillers/impl/ChillersServiceImpl.java index f2163ab..786b021 100644 --- a/user-service/src/main/java/com/mh/user/service/chillers/impl/ChillersServiceImpl.java +++ b/user-service/src/main/java/com/mh/user/service/chillers/impl/ChillersServiceImpl.java @@ -1,17 +1,24 @@ package com.mh.user.service.chillers.impl; -import com.mh.user.entity.ChillersEntity; -import com.mh.user.entity.HostValue; -import com.mh.user.entity.TableDataEntity; -import com.mh.user.entity.TableInfoEntity; +import com.alibaba.fastjson2.JSONArray; +import com.alibaba.fastjson2.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.mh.user.entity.*; +import com.mh.user.mapper.DevicesManageMapper; +import com.mh.user.mapper.MeterManageMapper; +import com.mh.user.mapper.ProjectInfoMapper; import com.mh.user.mapper.chillers.ChillersMapper; import com.mh.user.service.chillers.ChillersService; import com.mh.user.utils.DateUtil; import com.mh.user.utils.TimeDifferenceUtil; +import com.mh.user.vo.HostListVO; import org.springframework.stereotype.Service; import java.math.BigDecimal; +import java.util.Collections; import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; /** * @author ljf @@ -23,267 +30,411 @@ import java.util.List; @Service public class ChillersServiceImpl implements ChillersService { - // 构造方法注入 - private final ChillersMapper chillersMapper; - private List hostValueList; - double chillerWaterInt = 0.00; // 冷冻水回水温度 0A - double chillerWaterOut = 0.00; // 冷冻水出水温度 0B - double coldWaterInt = 0.00; // 冷却水回水温度 0E - double coldWaterOut = 0.00; // 冷却水出水温度 0F + // 构造方法注入 + private final ChillersMapper chillersMapper; + private List hostValueList; + double chillerWaterInt = 0.00; // 冷冻水回水温度 0A + double chillerWaterOut = 0.00; // 冷冻水出水温度 0B + double coldWaterInt = 0.00; // 冷却水回水温度 0E + double coldWaterOut = 0.00; // 冷却水出水温度 0F - public ChillersServiceImpl(ChillersMapper chillersMapper, List hostValueList) { - this.chillersMapper = chillersMapper; - this.hostValueList = hostValueList; - } + private final DevicesManageMapper devicesManageMapper; - @Override - public List queryTempValue(String deviceType) { - hostValueList.clear(); - if (deviceType.equalsIgnoreCase("other")) { - List chillersEntityList = getRunningChillers(); - if (chillersEntityList.size() == 2) { - // 获取对应的冷冻水、冷却水温度 - List chillersEntityList1 = chillersMapper.getChillersTemp(chillersEntityList.get(0).getDeviceCode()); - List chillersEntityList2 = chillersMapper.getChillersTemp(chillersEntityList.get(1).getDeviceCode()); - for (int i = 0; i < chillersEntityList1.size(); i++) { - String registerAddr = chillersEntityList1.get(i).getRegisterAddress(); - if (registerAddr.equalsIgnoreCase("0A")) { - BigDecimal bigDecimal = new BigDecimal(chillersEntityList1.get(i).getLastValue()); - chillerWaterInt = Double.parseDouble(String.valueOf(bigDecimal)); - } else if (registerAddr.equalsIgnoreCase("0B")) { - BigDecimal bigDecimal = new BigDecimal(chillersEntityList1.get(i).getLastValue()); - chillerWaterOut = Double.parseDouble(String.valueOf(bigDecimal)); - } else if (registerAddr.equalsIgnoreCase("0E")) { - BigDecimal bigDecimal = new BigDecimal(chillersEntityList1.get(i).getLastValue()); - coldWaterInt = Double.parseDouble(String.valueOf(bigDecimal)); - } else if (registerAddr.equalsIgnoreCase("0F")) { - BigDecimal bigDecimal = new BigDecimal(chillersEntityList1.get(i).getLastValue()); - coldWaterOut = Double.parseDouble(String.valueOf(bigDecimal)); - } - } - for (int i = 0; i < chillersEntityList2.size(); i++) { - String registerAddr = chillersEntityList2.get(i).getRegisterAddress(); - if (registerAddr.equalsIgnoreCase("0A")) { - BigDecimal bigDecimal = new BigDecimal(chillersEntityList2.get(i).getLastValue()); - chillerWaterInt = Double.parseDouble(String.valueOf(bigDecimal)) + chillerWaterInt; - } else if (registerAddr.equalsIgnoreCase("0B")) { - BigDecimal bigDecimal = new BigDecimal(chillersEntityList2.get(i).getLastValue()); - chillerWaterOut = Double.parseDouble(String.valueOf(bigDecimal)) + chillerWaterOut; - } else if (registerAddr.equalsIgnoreCase("0E")) { - BigDecimal bigDecimal = new BigDecimal(chillersEntityList2.get(i).getLastValue()); - coldWaterInt = Double.parseDouble(String.valueOf(bigDecimal)) + coldWaterInt; - } else if (registerAddr.equalsIgnoreCase("0F")) { - BigDecimal bigDecimal = new BigDecimal(chillersEntityList2.get(i).getLastValue()); - coldWaterOut = Double.parseDouble(String.valueOf(bigDecimal)) + coldWaterOut; - } - } - // 四舍五入,保留两位小数 - BigDecimal b2 = BigDecimal.valueOf(chillerWaterOut / 2); - chillerWaterOut = b2.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - BigDecimal b1 = BigDecimal.valueOf(chillerWaterInt / 2); - chillerWaterInt = b1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - BigDecimal b4 = BigDecimal.valueOf(coldWaterOut / 2); - coldWaterOut = b4.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - BigDecimal b3 = BigDecimal.valueOf(coldWaterInt / 2); - coldWaterInt = b3.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + private final MeterManageMapper meterManageMapper; - } else if (chillersEntityList.size() == 1) { - // 获取对应的冷冻水、冷却水温度 - List chillersEntityList1 = chillersMapper.getChillersTemp(chillersEntityList.get(0).getDeviceCode()); - for (int i = 0; i < chillersEntityList1.size(); i++) { - String registerAddr = chillersEntityList1.get(i).getRegisterAddress(); - if (registerAddr.equalsIgnoreCase("0A")) { - BigDecimal bigDecimal = new BigDecimal(chillersEntityList1.get(i).getLastValue()); - chillerWaterInt = Double.parseDouble(String.valueOf(bigDecimal)); - } else if (registerAddr.equalsIgnoreCase("0B")) { - BigDecimal bigDecimal = new BigDecimal(chillersEntityList1.get(i).getLastValue()); - chillerWaterOut = Double.parseDouble(String.valueOf(bigDecimal)); - } else if (registerAddr.equalsIgnoreCase("0E")) { - BigDecimal bigDecimal = new BigDecimal(chillersEntityList1.get(i).getLastValue()); - coldWaterInt = Double.parseDouble(String.valueOf(bigDecimal)); - } else if (registerAddr.equalsIgnoreCase("0F")) { - BigDecimal bigDecimal = new BigDecimal(chillersEntityList1.get(i).getLastValue()); - coldWaterOut = Double.parseDouble(String.valueOf(bigDecimal)); - } - } - } else if (chillersEntityList.size() == 0) { // update by ljf on 2021-01-11 - // 获取对应的冷水机组 - List chillersEntityList3 = getStopChillers(); - // 获取对应的冷冻水、冷却水温度 - List chillersEntityList1 = chillersMapper.getChillersTemp(chillersEntityList3.get(0).getDeviceCode()); - List chillersEntityList2 = chillersMapper.getChillersTemp(chillersEntityList3.get(1).getDeviceCode()); - for (int i = 0; i < chillersEntityList1.size(); i++) { - String registerAddr = chillersEntityList1.get(i).getRegisterAddress(); - if (registerAddr.equalsIgnoreCase("0A")) { - BigDecimal bigDecimal = new BigDecimal(chillersEntityList1.get(i).getLastValue()); - chillerWaterInt = Double.parseDouble(String.valueOf(bigDecimal)); - } else if (registerAddr.equalsIgnoreCase("0B")) { - BigDecimal bigDecimal = new BigDecimal(chillersEntityList1.get(i).getLastValue()); - chillerWaterOut = Double.parseDouble(String.valueOf(bigDecimal)); - } else if (registerAddr.equalsIgnoreCase("0E")) { - BigDecimal bigDecimal = new BigDecimal(chillersEntityList1.get(i).getLastValue()); - coldWaterInt = Double.parseDouble(String.valueOf(bigDecimal)); - } else if (registerAddr.equalsIgnoreCase("0F")) { - BigDecimal bigDecimal = new BigDecimal(chillersEntityList1.get(i).getLastValue()); - coldWaterOut = Double.parseDouble(String.valueOf(bigDecimal)); - } - } - for (int i = 0; i < chillersEntityList2.size(); i++) { - String registerAddr = chillersEntityList2.get(i).getRegisterAddress(); - if (registerAddr.equalsIgnoreCase("0A")) { - BigDecimal bigDecimal = new BigDecimal(chillersEntityList2.get(i).getLastValue()); - chillerWaterInt = Double.parseDouble(String.valueOf(bigDecimal)) + chillerWaterInt; - } else if (registerAddr.equalsIgnoreCase("0B")) { - BigDecimal bigDecimal = new BigDecimal(chillersEntityList2.get(i).getLastValue()); - chillerWaterOut = Double.parseDouble(String.valueOf(bigDecimal)) + chillerWaterOut; - } else if (registerAddr.equalsIgnoreCase("0E")) { - BigDecimal bigDecimal = new BigDecimal(chillersEntityList2.get(i).getLastValue()); - coldWaterInt = Double.parseDouble(String.valueOf(bigDecimal)) + coldWaterInt; - } else if (registerAddr.equalsIgnoreCase("0F")) { - BigDecimal bigDecimal = new BigDecimal(chillersEntityList2.get(i).getLastValue()); - coldWaterOut = Double.parseDouble(String.valueOf(bigDecimal)) + coldWaterOut; - } - } - // 四舍五入,保留两位小数 - BigDecimal b2 = BigDecimal.valueOf(chillerWaterOut / 2); - chillerWaterOut = b2.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - BigDecimal b1 = BigDecimal.valueOf(chillerWaterInt / 2); - chillerWaterInt = b1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - BigDecimal b4 = BigDecimal.valueOf(coldWaterOut / 2); - coldWaterOut = b4.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - BigDecimal b3 = BigDecimal.valueOf(coldWaterInt / 2); - coldWaterInt = b3.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - } - HostValue hostValue = new HostValue(); - hostValue.setId(1); - hostValue.setType("chilledOutWater"); - hostValue.setValue(chillerWaterOut); - hostValueList.add(hostValue); - HostValue hostValue1 = new HostValue(); - hostValue1.setId(2); - hostValue1.setType("chilledInWater"); - hostValue1.setValue(chillerWaterInt); - hostValueList.add(hostValue1); - HostValue hostValue2 = new HostValue(); - hostValue2.setId(3); - hostValue2.setType("coolingOutWater"); - hostValue2.setValue(coldWaterOut); - hostValueList.add(hostValue2); - HostValue hostValue3 = new HostValue(); - hostValue3.setId(4); - hostValue3.setType("coolingInWater"); - hostValue3.setValue(coldWaterInt); - hostValueList.add(hostValue3); - } else if (deviceType.equalsIgnoreCase("hostOne")) { + private final ProjectInfoMapper projectInfoMapper; + + public ChillersServiceImpl(ChillersMapper chillersMapper, + List hostValueList, + DevicesManageMapper devicesManageMapper, + MeterManageMapper meterManageMapper, ProjectInfoMapper projectInfoMapper) { + this.chillersMapper = chillersMapper; + this.hostValueList = hostValueList; + this.devicesManageMapper = devicesManageMapper; + this.meterManageMapper = meterManageMapper; + this.projectInfoMapper = projectInfoMapper; + } + + @Override + public List queryTempValue(String deviceType) { + hostValueList.clear(); + if (deviceType.equalsIgnoreCase("other")) { + List chillersEntityList = getRunningChillers(); + if (chillersEntityList.size() == 2) { + // 获取对应的冷冻水、冷却水温度 + List chillersEntityList1 = chillersMapper.getChillersTemp(chillersEntityList.get(0).getDeviceCode()); + List chillersEntityList2 = chillersMapper.getChillersTemp(chillersEntityList.get(1).getDeviceCode()); + for (int i = 0; i < chillersEntityList1.size(); i++) { + String registerAddr = chillersEntityList1.get(i).getRegisterAddress(); + if (registerAddr.equalsIgnoreCase("0A")) { + BigDecimal bigDecimal = new BigDecimal(chillersEntityList1.get(i).getLastValue()); + chillerWaterInt = Double.parseDouble(String.valueOf(bigDecimal)); + } else if (registerAddr.equalsIgnoreCase("0B")) { + BigDecimal bigDecimal = new BigDecimal(chillersEntityList1.get(i).getLastValue()); + chillerWaterOut = Double.parseDouble(String.valueOf(bigDecimal)); + } else if (registerAddr.equalsIgnoreCase("0E")) { + BigDecimal bigDecimal = new BigDecimal(chillersEntityList1.get(i).getLastValue()); + coldWaterInt = Double.parseDouble(String.valueOf(bigDecimal)); + } else if (registerAddr.equalsIgnoreCase("0F")) { + BigDecimal bigDecimal = new BigDecimal(chillersEntityList1.get(i).getLastValue()); + coldWaterOut = Double.parseDouble(String.valueOf(bigDecimal)); + } + } + for (int i = 0; i < chillersEntityList2.size(); i++) { + String registerAddr = chillersEntityList2.get(i).getRegisterAddress(); + if (registerAddr.equalsIgnoreCase("0A")) { + BigDecimal bigDecimal = new BigDecimal(chillersEntityList2.get(i).getLastValue()); + chillerWaterInt = Double.parseDouble(String.valueOf(bigDecimal)) + chillerWaterInt; + } else if (registerAddr.equalsIgnoreCase("0B")) { + BigDecimal bigDecimal = new BigDecimal(chillersEntityList2.get(i).getLastValue()); + chillerWaterOut = Double.parseDouble(String.valueOf(bigDecimal)) + chillerWaterOut; + } else if (registerAddr.equalsIgnoreCase("0E")) { + BigDecimal bigDecimal = new BigDecimal(chillersEntityList2.get(i).getLastValue()); + coldWaterInt = Double.parseDouble(String.valueOf(bigDecimal)) + coldWaterInt; + } else if (registerAddr.equalsIgnoreCase("0F")) { + BigDecimal bigDecimal = new BigDecimal(chillersEntityList2.get(i).getLastValue()); + coldWaterOut = Double.parseDouble(String.valueOf(bigDecimal)) + coldWaterOut; + } + } + // 四舍五入,保留两位小数 + BigDecimal b2 = BigDecimal.valueOf(chillerWaterOut / 2); + chillerWaterOut = b2.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + BigDecimal b1 = BigDecimal.valueOf(chillerWaterInt / 2); + chillerWaterInt = b1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + BigDecimal b4 = BigDecimal.valueOf(coldWaterOut / 2); + coldWaterOut = b4.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + BigDecimal b3 = BigDecimal.valueOf(coldWaterInt / 2); + coldWaterInt = b3.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - } else if (deviceType.equalsIgnoreCase("hostTwo")) { + } else if (chillersEntityList.size() == 1) { + // 获取对应的冷冻水、冷却水温度 + List chillersEntityList1 = chillersMapper.getChillersTemp(chillersEntityList.get(0).getDeviceCode()); + for (int i = 0; i < chillersEntityList1.size(); i++) { + String registerAddr = chillersEntityList1.get(i).getRegisterAddress(); + if (registerAddr.equalsIgnoreCase("0A")) { + BigDecimal bigDecimal = new BigDecimal(chillersEntityList1.get(i).getLastValue()); + chillerWaterInt = Double.parseDouble(String.valueOf(bigDecimal)); + } else if (registerAddr.equalsIgnoreCase("0B")) { + BigDecimal bigDecimal = new BigDecimal(chillersEntityList1.get(i).getLastValue()); + chillerWaterOut = Double.parseDouble(String.valueOf(bigDecimal)); + } else if (registerAddr.equalsIgnoreCase("0E")) { + BigDecimal bigDecimal = new BigDecimal(chillersEntityList1.get(i).getLastValue()); + coldWaterInt = Double.parseDouble(String.valueOf(bigDecimal)); + } else if (registerAddr.equalsIgnoreCase("0F")) { + BigDecimal bigDecimal = new BigDecimal(chillersEntityList1.get(i).getLastValue()); + coldWaterOut = Double.parseDouble(String.valueOf(bigDecimal)); + } + } + } else if (chillersEntityList.size() == 0) { // update by ljf on 2021-01-11 + // 获取对应的冷水机组 + List chillersEntityList3 = getStopChillers(); + // 获取对应的冷冻水、冷却水温度 + List chillersEntityList1 = chillersMapper.getChillersTemp(chillersEntityList3.get(0).getDeviceCode()); + List chillersEntityList2 = chillersMapper.getChillersTemp(chillersEntityList3.get(1).getDeviceCode()); + for (int i = 0; i < chillersEntityList1.size(); i++) { + String registerAddr = chillersEntityList1.get(i).getRegisterAddress(); + if (registerAddr.equalsIgnoreCase("0A")) { + BigDecimal bigDecimal = new BigDecimal(chillersEntityList1.get(i).getLastValue()); + chillerWaterInt = Double.parseDouble(String.valueOf(bigDecimal)); + } else if (registerAddr.equalsIgnoreCase("0B")) { + BigDecimal bigDecimal = new BigDecimal(chillersEntityList1.get(i).getLastValue()); + chillerWaterOut = Double.parseDouble(String.valueOf(bigDecimal)); + } else if (registerAddr.equalsIgnoreCase("0E")) { + BigDecimal bigDecimal = new BigDecimal(chillersEntityList1.get(i).getLastValue()); + coldWaterInt = Double.parseDouble(String.valueOf(bigDecimal)); + } else if (registerAddr.equalsIgnoreCase("0F")) { + BigDecimal bigDecimal = new BigDecimal(chillersEntityList1.get(i).getLastValue()); + coldWaterOut = Double.parseDouble(String.valueOf(bigDecimal)); + } + } + for (int i = 0; i < chillersEntityList2.size(); i++) { + String registerAddr = chillersEntityList2.get(i).getRegisterAddress(); + if (registerAddr.equalsIgnoreCase("0A")) { + BigDecimal bigDecimal = new BigDecimal(chillersEntityList2.get(i).getLastValue()); + chillerWaterInt = Double.parseDouble(String.valueOf(bigDecimal)) + chillerWaterInt; + } else if (registerAddr.equalsIgnoreCase("0B")) { + BigDecimal bigDecimal = new BigDecimal(chillersEntityList2.get(i).getLastValue()); + chillerWaterOut = Double.parseDouble(String.valueOf(bigDecimal)) + chillerWaterOut; + } else if (registerAddr.equalsIgnoreCase("0E")) { + BigDecimal bigDecimal = new BigDecimal(chillersEntityList2.get(i).getLastValue()); + coldWaterInt = Double.parseDouble(String.valueOf(bigDecimal)) + coldWaterInt; + } else if (registerAddr.equalsIgnoreCase("0F")) { + BigDecimal bigDecimal = new BigDecimal(chillersEntityList2.get(i).getLastValue()); + coldWaterOut = Double.parseDouble(String.valueOf(bigDecimal)) + coldWaterOut; + } + } + // 四舍五入,保留两位小数 + BigDecimal b2 = BigDecimal.valueOf(chillerWaterOut / 2); + chillerWaterOut = b2.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + BigDecimal b1 = BigDecimal.valueOf(chillerWaterInt / 2); + chillerWaterInt = b1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + BigDecimal b4 = BigDecimal.valueOf(coldWaterOut / 2); + coldWaterOut = b4.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + BigDecimal b3 = BigDecimal.valueOf(coldWaterInt / 2); + coldWaterInt = b3.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); + } + HostValue hostValue = new HostValue(); + hostValue.setId(1); + hostValue.setType("chilledOutWater"); + hostValue.setValue(chillerWaterOut); + hostValueList.add(hostValue); + HostValue hostValue1 = new HostValue(); + hostValue1.setId(2); + hostValue1.setType("chilledInWater"); + hostValue1.setValue(chillerWaterInt); + hostValueList.add(hostValue1); + HostValue hostValue2 = new HostValue(); + hostValue2.setId(3); + hostValue2.setType("coolingOutWater"); + hostValue2.setValue(coldWaterOut); + hostValueList.add(hostValue2); + HostValue hostValue3 = new HostValue(); + hostValue3.setId(4); + hostValue3.setType("coolingInWater"); + hostValue3.setValue(coldWaterInt); + hostValueList.add(hostValue3); + } else if (deviceType.equalsIgnoreCase("hostOne")) { - } else if (deviceType.equalsIgnoreCase("town")) { + } else if (deviceType.equalsIgnoreCase("hostTwo")) { + } else if (deviceType.equalsIgnoreCase("town")) { + + } + return hostValueList; + } + + // 查询冷水机组进出水温度两者的平均值 + + @Override + public List getRunningChillers() { + return chillersMapper.getRunningChillers(); } - return hostValueList; - } - // 查询冷水机组进出水温度两者的平均值 + @Override + public List getStopChillers() { + return chillersMapper.getStopChillers(); + } - @Override - public List getRunningChillers() { - return chillersMapper.getRunningChillers(); - } + @Override + public List queryChillersByOther(int grade, String ddcAddr) { + return chillersMapper.queryChillersByOther(grade, ddcAddr); + } - @Override - public List getStopChillers() { - return chillersMapper.getStopChillers(); - } + @Override + public int insertChillersHistory(ChillersEntity chillersEntity) { + try { + System.out.println(chillersEntity.toString()); + // 判断是否大于等于最近插入时间的30分钟, + String lastTimeStr = queryLastChillersHistory(chillersEntity); + if (lastTimeStr == null || lastTimeStr.equalsIgnoreCase("")) { + // 格式化时间分钟为15,30,45,00 + chillersEntity.setLastTime(DateUtil.formatDateStr(chillersEntity.getLastTime())); + // 大于就插入数据库,否则就更新基表安装信息的表 + return chillersMapper.insertChillersHistory(chillersEntity); + } else { + int dValue = TimeDifferenceUtil.dValue(lastTimeStr); + if (dValue >= 30) { + // 格式化时间分钟为15,30,45,00 + chillersEntity.setLastTime(DateUtil.formatDateStr(chillersEntity.getLastTime())); + // 大于就插入数据库,否则就更新基表安装信息的表 + return chillersMapper.insertChillersHistory(chillersEntity); + } + } + // 不管时间差如何都进行更新基表安装信息 + chillersMapper.updateChillerRegisterAddr(chillersEntity); + } catch (Exception e) { + e.printStackTrace(); + return 0; + } + return 0; + } - @Override - public List queryChillersByOther(int grade, String ddcAddr) { - return chillersMapper.queryChillersByOther(grade, ddcAddr); - } + @Override + public void updateChillerRegisterAddr(ChillersEntity chillersEntity) { + chillersMapper.updateChillerRegisterAddr(chillersEntity); + } - @Override - public int insertChillersHistory(ChillersEntity chillersEntity) { - try { - System.out.println(chillersEntity.toString()); - // 判断是否大于等于最近插入时间的30分钟, - String lastTimeStr = queryLastChillersHistory(chillersEntity); - if (lastTimeStr == null || lastTimeStr.equalsIgnoreCase("")) { - // 格式化时间分钟为15,30,45,00 - chillersEntity.setLastTime(DateUtil.formatDateStr(chillersEntity.getLastTime())); - // 大于就插入数据库,否则就更新基表安装信息的表 - return chillersMapper.insertChillersHistory(chillersEntity); - } else { - int dValue = TimeDifferenceUtil.dValue(lastTimeStr); - if (dValue >= 30) { - // 格式化时间分钟为15,30,45,00 - chillersEntity.setLastTime(DateUtil.formatDateStr(chillersEntity.getLastTime())); - // 大于就插入数据库,否则就更新基表安装信息的表 - return chillersMapper.insertChillersHistory(chillersEntity); + @Override + public void updateDataNow(ChillersEntity chillersEntity) { + try { + // 判断是否存在实时记录表 + int a = chillersMapper.queryDataNowByOthers(chillersEntity); + if (a == 0) { + // 不存在则进行插入处理 + chillersMapper.insertChillerDataNow(chillersEntity); + } else { + // 存在则进行更新处理 + chillersMapper.updateDataNow(chillersEntity); + } + } catch (Exception e) { + e.printStackTrace(); } - } - // 不管时间差如何都进行更新基表安装信息 - chillersMapper.updateChillerRegisterAddr(chillersEntity); - } catch (Exception e) { - e.printStackTrace(); - return 0; } - return 0; - } - @Override - public void updateChillerRegisterAddr(ChillersEntity chillersEntity) { - chillersMapper.updateChillerRegisterAddr(chillersEntity); - } + @Override + public int batchUpdateRegisterAddr(List chillersEntityLists) { + return chillersMapper.updateRegisterAddr(chillersEntityLists); + } + + @Override + public List queryTopData(String deviceName, int grade) { + return chillersMapper.queryTopData(deviceName, grade); + } + + @Override + public List queryLeftAndRightData(String deviceName, int grade) { + return chillersMapper.queryLeftAndRightData(deviceName, grade); + } - @Override - public void updateDataNow(ChillersEntity chillersEntity) { - try { - // 判断是否存在实时记录表 - int a = chillersMapper.queryDataNowByOthers(chillersEntity); - if (a == 0) { - // 不存在则进行插入处理 - chillersMapper.insertChillerDataNow(chillersEntity); - } else { - // 存在则进行更新处理 - chillersMapper.updateDataNow(chillersEntity); - } - } catch (Exception e) { - e.printStackTrace(); + @Override + public List queryChillersDDC(int grade) { + return chillersMapper.queryChillersDDC(grade); } - } - @Override - public int batchUpdateRegisterAddr(List chillersEntityLists) { - return chillersMapper.updateRegisterAddr(chillersEntityLists); - } + @Override + public void batchInsertChillersHistory(List chillersEntityLists) { + chillersMapper.batchInsertChillersHistory(chillersEntityLists); + } - @Override - public List queryTopData(String deviceName, int grade) { - return chillersMapper.queryTopData(deviceName, grade); - } + @Override + public String queryLastChillersHistory(ChillersEntity chillersEntity) { + return chillersMapper.queryLastChillersHistory(chillersEntity); + } - @Override - public List queryLeftAndRightData(String deviceName, int grade) { - return chillersMapper.queryLeftAndRightData(deviceName, grade); - } + @Override + public List queryDDCAddr(String ddcAddr) { + return chillersMapper.queryDDCAddr(ddcAddr); + } - @Override - public List queryChillersDDC(int grade) { - return chillersMapper.queryChillersDDC(grade); - } + @Override + public JSONArray queryChillersByProId(String systemId, String proId) { + JSONArray resultJson = new JSONArray(); + QueryWrapper deviceQueryWrapper = new QueryWrapper<>(); + if (systemId != null && !systemId.equalsIgnoreCase("")) { + deviceQueryWrapper.eq("system_id", systemId); + } + if (proId != null && !proId.equalsIgnoreCase("")) { + deviceQueryWrapper.eq("project_id", proId); + } + List devicesManageEntityList = devicesManageMapper.selectList(deviceQueryWrapper.orderByAsc("id")); + if (devicesManageEntityList != null && !devicesManageEntityList.isEmpty()) { + HostListVO hostListVO = new HostListVO(); + // 根据projectId进行分组 + Map> proDevicesMap = + devicesManageEntityList.stream().collect(Collectors.groupingBy(DevicesManageEntity::getProjectId)); + // 遍历分组后的数据 + for (Map.Entry> entry : proDevicesMap.entrySet()) { + if (entry.getValue() != null && !entry.getValue().isEmpty()) { + // 根据key(projectId)获取对应的项目名称 + String projectName = projectInfoMapper.selectById(entry.getKey()).getProjectName(); + JSONObject proJson = new JSONObject(); + proJson.put("name", projectName); + proJson.put("value", entry.getKey()); - @Override - public void batchInsertChillersHistory(List chillersEntityLists) { - chillersMapper.batchInsertChillersHistory(chillersEntityLists); - } + JSONArray children = new JSONArray(); + List devicesManageEntities = entry.getValue(); + for (DevicesManageEntity devicesManageEntity : devicesManageEntities) { + JSONObject deviceJson = new JSONObject(); + deviceJson.put("name", devicesManageEntity.getDeviceName()); + deviceJson.put("value", devicesManageEntity.getId()); + JSONArray mtArray = new JSONArray(); + List meterManageEntities = meterManageMapper.selectList( + new QueryWrapper() + .eq("device_id", devicesManageEntity.getId()) + .orderByAsc("sort")); + if (meterManageEntities != null && !meterManageEntities.isEmpty()) { + matchingChillersData(meterManageEntities, hostListVO); + // 额定制冷量 + hostListVO.setRatedRef(String.valueOf(devicesManageEntity.getRatedRefrigerationCapacity())); + // 额定功率 + hostListVO.setRatedPower(String.valueOf(devicesManageEntity.getRatedInputPower())); + // 额定COP + hostListVO.setRatedCop(String.valueOf(devicesManageEntity.getRatedCop())); + } + mtArray.add(hostListVO); + deviceJson.put("children", mtArray); + children.add(deviceJson); + } + proJson.put("children", children); + resultJson.add(proJson); + } + } + } + return resultJson; + } - @Override - public String queryLastChillersHistory(ChillersEntity chillersEntity) { - return chillersMapper.queryLastChillersHistory(chillersEntity); - } + private void matchingChillersData(List meterManageEntities, HostListVO hostListVO) { + hostListVO.reset(); + for (MeterManageEntity meterManageEntity : meterManageEntities) { + // 匹配HostListVO展示给前端 + String funCode = meterManageEntity.getFuncCode(); + String curValue = String.valueOf(meterManageEntity.getCurValue()); + switch (meterManageEntity.getMtCode()) { + case "0001": + if (funCode.equals("1")) { + hostListVO.setRunningStatus(curValue); + } + break; + case "0003": + if (funCode.equals("3")) { + hostListVO.setEnteringTempSet(curValue); + } + break; + case "0005": + if (funCode.equals("3")) { + hostListVO.setEvapLeavingChWTemp(curValue); + } + break; + case "0006": + if (funCode.equals("3")) { + hostListVO.setEvapEnteringChWTemp(curValue); + } + break; + case "0015": + if (funCode.equals("3")) { + hostListVO.setEvapApproach(curValue); + } + break; + case "0009": + if (funCode.equals("3")) { + hostListVO.setCondLeavingChWTemp(curValue); + } + break; + case "0010": + if (funCode.equals("3")) { + hostListVO.setCondEnteringChWTemp(curValue); + } + break; + case "0023": + if (funCode.equals("3")) { + hostListVO.setCondApproach(curValue); + } + break; + case "0139": + if (funCode.equals("3")) { + hostListVO.setRealTimeChillerAmps(curValue); + } + break; + case "0013": + if (funCode.equals("3")) { + hostListVO.setRealTimePower(curValue); + } + break; + case "0014": + if (funCode.equals("3")) { + hostListVO.setRealTimeCop(curValue); + } + break; + case "0122": + if (funCode.equals("3")) { + hostListVO.setRealTimeWarning(curValue); + hostListVO.setRealTimeFault(curValue); + } + break; + default: + break; + } + } + } - @Override - public List queryDDCAddr(String ddcAddr) { - return chillersMapper.queryDDCAddr(ddcAddr); - } } diff --git a/user-service/src/main/java/com/mh/user/utils/AnalysisReceiveOrder485.java b/user-service/src/main/java/com/mh/user/utils/AnalysisReceiveOrder485.java index 32be208..76b2e46 100644 --- a/user-service/src/main/java/com/mh/user/utils/AnalysisReceiveOrder485.java +++ b/user-service/src/main/java/com/mh/user/utils/AnalysisReceiveOrder485.java @@ -46,7 +46,7 @@ public class AnalysisReceiveOrder485 { //解析冷量表 public void analysisCloudOrder485(final String dataStr1, final DeviceCodeParamEntity deviceCodeParam) { - threadPoolService.execute(() -> { +// threadPoolService.execute(() -> { // 去掉空格 String dataStr = dataStr1.replace(" ", "").toUpperCase(); // 检验报文 @@ -59,7 +59,7 @@ public class AnalysisReceiveOrder485 { if (checkWord.equalsIgnoreCase(dataStr.substring(dataStr.length() - 4))) { //创建SimpleDateFormat对象,指定样式 2019-05-13 22:39:30 Date date = new Date(); - String dateStr = ""; + String dateStr = sdf1.format(date);; //保留两位小数处理 DecimalFormat decimalFormat = new DecimalFormat("0.00"); // 表号 @@ -75,14 +75,10 @@ public class AnalysisReceiveOrder485 { DataResultClEntity dataResultCl = new DataResultClEntity(); String registerAddr = deviceCodeParam.getRegisterAddr(); if (ExchangeStringUtil.isInDate(date, "00:00:00", "00:00:30")) { - dateStr = sdf1.format(date); dateStr = dateStr.substring(0, 17) + "00"; - System.out.println("插入时间00" + dateStr); } else if (ExchangeStringUtil.isInDate(date, "00:00:30", "00:00:59")) { - dateStr = sdf1.format(date); dateStr = dateStr.substring(0, 17) + "30"; - System.out.println("插入时间30" + dateStr); } try { @@ -128,7 +124,7 @@ public class AnalysisReceiveOrder485 { } else { log.info("冷量计校验失败===>" + dataStr); } - }); +// }); } public String analysisCloudQueue(QueueParam queueParam) { @@ -354,7 +350,7 @@ public class AnalysisReceiveOrder485 { log.info("meterID==>" + meterId + ",meter curValue==>" + data + ",projectName==>" + projectName); log.info("meter save data success!projectName:" + projectName); } catch (Exception e) { - log.error("保存电表数据失败!", e); + log.error("保存电表数据失败!", e); } rec = "success"; } else { @@ -436,7 +432,7 @@ public class AnalysisReceiveOrder485 { dataResultService.saveDataResult(dataResultEntity); log.info("wtMeter save data success!projectId:" + projectId); } catch (Exception e) { - log.error("保存水表数据失败!", e); + log.error("保存水表数据失败!", e); } }); } diff --git a/user-service/src/main/java/com/mh/user/vo/HostListVO.java b/user-service/src/main/java/com/mh/user/vo/HostListVO.java new file mode 100644 index 0000000..872d60d --- /dev/null +++ b/user-service/src/main/java/com/mh/user/vo/HostListVO.java @@ -0,0 +1,136 @@ +package com.mh.user.vo; + +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; + +/** + * @author LJF + * @version 1.0 + * @project mh_esi + * @description 对前端展示的--主机列表 + * @date 2024-08-28 11:21:19 + */ +@Setter +@Getter +public class HostListVO implements Serializable { + + private static final long serialVersionUID = 1L; + + private String runningStatus; + /** + * 出水温度设定值 + */ + private String enteringTempSet; + + /** + * 蒸发器侧进水温度 + */ + private String evapLeavingChWTemp; + + /** + * 蒸发器侧出水温度 + */ + private String evapEnteringChWTemp; + + /** + * 蒸发器侧趋近温度 + */ + private String evapApproach; + + /** + * 冷凝器侧进水温度 + */ + private String condLeavingChWTemp; + + /** + * 冷凝器侧出水温度 + */ + private String condEnteringChWTemp; + + /** + * 冷凝器侧趋近温度 + */ + private String condApproach; + + /** + * 额定制冷量 + */ + private String ratedRef; + + /** + * 额定功率 + */ + private String ratedPower; + + /** + * 额定COP + */ + private String ratedCop; + + /** + * 实时制冷量 + */ + private String realTimeChillerAmps; + + /** + * 实时功率 + */ + private String realTimePower; + + /** + * 实时COP + */ + private String realTimeCop; + + /** + * 实时告警 + */ + private String realTimeWarning; + + /** + * 实时故障 + */ + private String realTimeFault; + + public void reset() { + this.runningStatus = null; + this.enteringTempSet = null; + this.evapLeavingChWTemp = null; + this.evapEnteringChWTemp = null; + this.evapApproach = null; + this.condLeavingChWTemp = null; + this.condEnteringChWTemp = null; + this.condApproach = null; + this.ratedRef = null; + this.ratedPower = null; + this.ratedCop = null; + this.realTimeChillerAmps = null; + this.realTimePower = null; + this.realTimeCop = null; + this.realTimeWarning = null; + this.realTimeFault = null; + } + + @Override + public String toString() { + return "HostListVO{" + + "enteringTempSet='" + enteringTempSet + '\'' + + ", evapLeavingChWTemp='" + evapLeavingChWTemp + '\'' + + ", evapEnteringChWTemp='" + evapEnteringChWTemp + '\'' + + ", evapApproach='" + evapApproach + '\'' + + ", condLeavingChWTemp='" + condLeavingChWTemp + '\'' + + ", condEnteringChWTemp='" + condEnteringChWTemp + '\'' + + ", condApproach='" + condApproach + '\'' + + ", ratedRef='" + ratedRef + '\'' + + ", ratedPower='" + ratedPower + '\'' + + ", ratedCop='" + ratedCop + '\'' + + ", realTimeChillerAmps='" + realTimeChillerAmps + '\'' + + ", realTimePower='" + realTimePower + '\'' + + ", realTimeCop='" + realTimeCop + '\'' + + ", realTimeWarning='" + realTimeWarning + '\'' + + ", realTimeFault='" + realTimeFault + '\'' + + '}'; + } +} diff --git a/user-service/src/test/java/com/mh/user/SysUserTest.java b/user-service/src/test/java/com/mh/user/SysUserTest.java index 106d5b3..c742479 100644 --- a/user-service/src/test/java/com/mh/user/SysUserTest.java +++ b/user-service/src/test/java/com/mh/user/SysUserTest.java @@ -1,5 +1,6 @@ package com.mh.user; +import com.mh.user.utils.ExchangeStringUtil; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; @@ -29,37 +30,50 @@ import java.util.List; */ public class SysUserTest { - + private static final SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); public static void main(String[] args) throws ParseException, IOException { - // 读取TXT文件中的HTML内容 - String htmlContent = readFile("C:/Users/MH/Desktop/getAir.txt"); - - // 使用Jsoup解析HTML - Document doc = Jsoup.parse(htmlContent); - - // 提取所有的img标签 - Elements imgElements = doc.select("img"); - - // 存储img标签的src属性 - List imgSrcs = new ArrayList<>(); - for (Element img : imgElements) { - if (img.attr("src").startsWith("//")) { - imgSrcs.add("http:" + img.attr("src")); - } else { - imgSrcs.add(img.attr("src")); - } - } - for (int i = 0; i < imgSrcs.size(); i++) { - // 指定要保存的本地文件路径 - Path localFilePath = Paths.get("D:/ljf/images/"+i+".jpg"); - - // 下载图片 - try { - downloadImageToFile(imgSrcs.get(i), localFilePath); - } catch (IOException e) { - continue; - } + String dateStr = ""; + Date date = new Date(); + if (ExchangeStringUtil.isInDate(date, "00:00:00", "00:00:30")) { + dateStr = sdf1.format(date); + dateStr = dateStr.substring(0, 17) + "00"; + + System.out.println("插入时间00" + dateStr); + } else if (ExchangeStringUtil.isInDate(date, "00:00:30", "00:00:59")) { + dateStr = sdf1.format(date); + dateStr = dateStr.substring(0, 17) + "30"; + + System.out.println("插入时间30" + dateStr); } +// // 读取TXT文件中的HTML内容 +// String htmlContent = readFile("C:/Users/MH/Desktop/getAir.txt"); +// +// // 使用Jsoup解析HTML +// Document doc = Jsoup.parse(htmlContent); +// +// // 提取所有的img标签 +// Elements imgElements = doc.select("img"); +// +// // 存储img标签的src属性 +// List imgSrcs = new ArrayList<>(); +// for (Element img : imgElements) { +// if (img.attr("src").startsWith("//")) { +// imgSrcs.add("http:" + img.attr("src")); +// } else { +// imgSrcs.add(img.attr("src")); +// } +// } +// for (int i = 0; i < imgSrcs.size(); i++) { +// // 指定要保存的本地文件路径 +// Path localFilePath = Paths.get("D:/ljf/images/"+i+".jpg"); +// +// // 下载图片 +// try { +// downloadImageToFile(imgSrcs.get(i), localFilePath); +// } catch (IOException e) { +// continue; +// } +// } } private static String readFile(String filePath) throws IOException {