Browse Source

1、添加主机列表基本参数;

dev
mh 3 weeks ago
parent
commit
389faa7110
  1. 12
      user-service/src/main/java/com/mh/user/constants/ChillerParamsEnum.java
  2. 112
      user-service/src/main/java/com/mh/user/controller/ChillersController.java
  3. 4
      user-service/src/main/java/com/mh/user/service/chillers/ChillersService.java
  4. 637
      user-service/src/main/java/com/mh/user/service/chillers/impl/ChillersServiceImpl.java
  5. 14
      user-service/src/main/java/com/mh/user/utils/AnalysisReceiveOrder485.java
  6. 136
      user-service/src/main/java/com/mh/user/vo/HostListVO.java
  7. 72
      user-service/src/test/java/com/mh/user/SysUserTest.java

12
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 {
}

112
user-service/src/main/java/com/mh/user/controller/ChillersController.java

@ -1,18 +1,18 @@
package com.mh.user.controller; package com.mh.user.controller;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.mh.common.http.HttpResult; import com.mh.common.http.HttpResult;
import com.mh.user.dto.DisplayBoxDataDTO; import com.mh.user.dto.DisplayBoxDataDTO;
import com.mh.user.dto.TableInfoDTO; import com.mh.user.dto.TableInfoDTO;
import com.mh.user.entity.GaugeEntity; import com.mh.user.entity.*;
import com.mh.user.entity.HostValue;
import com.mh.user.entity.TableDataEntity;
import com.mh.user.entity.TableInfoEntity;
import com.mh.user.service.chillers.ChillersService; import com.mh.user.service.chillers.ChillersService;
import com.mh.user.service.chillers.DeviceDisplayService; import com.mh.user.service.chillers.DeviceDisplayService;
import com.mh.user.service.chillers.GaugeService; import com.mh.user.service.chillers.GaugeService;
import com.mh.user.vo.HostListVO;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; 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.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -26,6 +26,7 @@ import java.util.List;
* @throws * @throws
*/ */
@RestController @RestController
@RequestMapping("/chillers")
public class ChillersController { public class ChillersController {
private final ChillersService chillersService; private final ChillersService chillersService;
@ -36,105 +37,12 @@ public class ChillersController {
this.deviceDisplayService = deviceDisplayService; this.deviceDisplayService = deviceDisplayService;
} }
// 查询冷水机组各个部位的状态值 @GetMapping("/queryListByProId")
// @GetMapping("/chillers") public HttpResult queryChillersByProId(@RequestParam(value = "proId", required = false) String proId,
@RequestParam("systemId") String systemId) {
/** JSONArray resultJson = chillersService.queryChillersByProId(systemId, proId);
* 查询冷水机组进出水温度值等设备数据详情 return HttpResult.ok(resultJson);
* @param deviceType
* @param type
* @return
*/
@GetMapping("/charts/getDisplayBoxData")
public HttpResult getDisplayBoxData(@RequestParam(value = "deviceType") String deviceType,
@RequestParam(value = "type") Integer type) {
List<DisplayBoxDataDTO> 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<TableInfoEntity> 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<TableDataEntity> 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<TableInfoEntity> 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<TableInfoEntity> tableInfoDTO = new TableInfoDTO<>();
tableInfoDTO.setTableInfo(chillersService.queryLeftAndRightData(deviceName, 3));
return HttpResult.ok("success", tableInfoDTO);
} }
// 冷却泵、冷冻泵、冷却塔详情页顶部表格数据
@GetMapping("/charts/getPumpOrTowerTopTableData")
public HttpResult getPumpOrTowerTopData(@RequestParam(value = "deviceName", required = true) String deviceName) {
TableInfoDTO<TableInfoEntity> 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<TableDataEntity> 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<HostValue> 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);
}
} }

4
user-service/src/main/java/com/mh/user/service/chillers/ChillersService.java

@ -1,9 +1,12 @@
package com.mh.user.service.chillers; 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.ChillersEntity;
import com.mh.user.entity.HostValue; import com.mh.user.entity.HostValue;
import com.mh.user.entity.TableDataEntity; import com.mh.user.entity.TableDataEntity;
import com.mh.user.entity.TableInfoEntity; import com.mh.user.entity.TableInfoEntity;
import com.mh.user.vo.HostListVO;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
@ -57,4 +60,5 @@ public interface ChillersService {
// 通过DDC地址查询对应的采集参数设备 // 通过DDC地址查询对应的采集参数设备
List<String> queryDDCAddr(String ddcAddr); List<String> queryDDCAddr(String ddcAddr);
JSONArray queryChillersByProId(String systemId, String proId);
} }

637
user-service/src/main/java/com/mh/user/service/chillers/impl/ChillersServiceImpl.java

@ -1,17 +1,24 @@
package com.mh.user.service.chillers.impl; package com.mh.user.service.chillers.impl;
import com.mh.user.entity.ChillersEntity; import com.alibaba.fastjson2.JSONArray;
import com.mh.user.entity.HostValue; import com.alibaba.fastjson2.JSONObject;
import com.mh.user.entity.TableDataEntity; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mh.user.entity.TableInfoEntity; 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.mapper.chillers.ChillersMapper;
import com.mh.user.service.chillers.ChillersService; import com.mh.user.service.chillers.ChillersService;
import com.mh.user.utils.DateUtil; import com.mh.user.utils.DateUtil;
import com.mh.user.utils.TimeDifferenceUtil; import com.mh.user.utils.TimeDifferenceUtil;
import com.mh.user.vo.HostListVO;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/** /**
* @author ljf * @author ljf
@ -23,267 +30,411 @@ import java.util.List;
@Service @Service
public class ChillersServiceImpl implements ChillersService { public class ChillersServiceImpl implements ChillersService {
// 构造方法注入 // 构造方法注入
private final ChillersMapper chillersMapper; private final ChillersMapper chillersMapper;
private List<HostValue> hostValueList; private List<HostValue> hostValueList;
double chillerWaterInt = 0.00; // 冷冻水回水温度 0A double chillerWaterInt = 0.00; // 冷冻水回水温度 0A
double chillerWaterOut = 0.00; // 冷冻水出水温度 0B double chillerWaterOut = 0.00; // 冷冻水出水温度 0B
double coldWaterInt = 0.00; // 冷却水回水温度 0E double coldWaterInt = 0.00; // 冷却水回水温度 0E
double coldWaterOut = 0.00; // 冷却水出水温度 0F double coldWaterOut = 0.00; // 冷却水出水温度 0F
public ChillersServiceImpl(ChillersMapper chillersMapper, List<HostValue> hostValueList) { private final DevicesManageMapper devicesManageMapper;
this.chillersMapper = chillersMapper;
this.hostValueList = hostValueList;
}
@Override private final MeterManageMapper meterManageMapper;
public List<HostValue> queryTempValue(String deviceType) {
hostValueList.clear();
if (deviceType.equalsIgnoreCase("other")) {
List<ChillersEntity> chillersEntityList = getRunningChillers();
if (chillersEntityList.size() == 2) {
// 获取对应的冷冻水、冷却水温度
List<ChillersEntity> chillersEntityList1 = chillersMapper.getChillersTemp(chillersEntityList.get(0).getDeviceCode());
List<ChillersEntity> 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 (chillersEntityList.size() == 1) { private final ProjectInfoMapper projectInfoMapper;
// 获取对应的冷冻水、冷却水温度
List<ChillersEntity> chillersEntityList1 = chillersMapper.getChillersTemp(chillersEntityList.get(0).getDeviceCode()); public ChillersServiceImpl(ChillersMapper chillersMapper,
for (int i = 0; i < chillersEntityList1.size(); i++) { List<HostValue> hostValueList,
String registerAddr = chillersEntityList1.get(i).getRegisterAddress(); DevicesManageMapper devicesManageMapper,
if (registerAddr.equalsIgnoreCase("0A")) { MeterManageMapper meterManageMapper, ProjectInfoMapper projectInfoMapper) {
BigDecimal bigDecimal = new BigDecimal(chillersEntityList1.get(i).getLastValue()); this.chillersMapper = chillersMapper;
chillerWaterInt = Double.parseDouble(String.valueOf(bigDecimal)); this.hostValueList = hostValueList;
} else if (registerAddr.equalsIgnoreCase("0B")) { this.devicesManageMapper = devicesManageMapper;
BigDecimal bigDecimal = new BigDecimal(chillersEntityList1.get(i).getLastValue()); this.meterManageMapper = meterManageMapper;
chillerWaterOut = Double.parseDouble(String.valueOf(bigDecimal)); this.projectInfoMapper = projectInfoMapper;
} else if (registerAddr.equalsIgnoreCase("0E")) { }
BigDecimal bigDecimal = new BigDecimal(chillersEntityList1.get(i).getLastValue());
coldWaterInt = Double.parseDouble(String.valueOf(bigDecimal)); @Override
} else if (registerAddr.equalsIgnoreCase("0F")) { public List<HostValue> queryTempValue(String deviceType) {
BigDecimal bigDecimal = new BigDecimal(chillersEntityList1.get(i).getLastValue()); hostValueList.clear();
coldWaterOut = Double.parseDouble(String.valueOf(bigDecimal)); if (deviceType.equalsIgnoreCase("other")) {
} List<ChillersEntity> chillersEntityList = getRunningChillers();
} if (chillersEntityList.size() == 2) {
} else if (chillersEntityList.size() == 0) { // update by ljf on 2021-01-11 // 获取对应的冷冻水、冷却水温度
// 获取对应的冷水机组 List<ChillersEntity> chillersEntityList1 = chillersMapper.getChillersTemp(chillersEntityList.get(0).getDeviceCode());
List<ChillersEntity> chillersEntityList3 = getStopChillers(); List<ChillersEntity> chillersEntityList2 = chillersMapper.getChillersTemp(chillersEntityList.get(1).getDeviceCode());
// 获取对应的冷冻水、冷却水温度 for (int i = 0; i < chillersEntityList1.size(); i++) {
List<ChillersEntity> chillersEntityList1 = chillersMapper.getChillersTemp(chillersEntityList3.get(0).getDeviceCode()); String registerAddr = chillersEntityList1.get(i).getRegisterAddress();
List<ChillersEntity> chillersEntityList2 = chillersMapper.getChillersTemp(chillersEntityList3.get(1).getDeviceCode()); if (registerAddr.equalsIgnoreCase("0A")) {
for (int i = 0; i < chillersEntityList1.size(); i++) { BigDecimal bigDecimal = new BigDecimal(chillersEntityList1.get(i).getLastValue());
String registerAddr = chillersEntityList1.get(i).getRegisterAddress(); chillerWaterInt = Double.parseDouble(String.valueOf(bigDecimal));
if (registerAddr.equalsIgnoreCase("0A")) { } else if (registerAddr.equalsIgnoreCase("0B")) {
BigDecimal bigDecimal = new BigDecimal(chillersEntityList1.get(i).getLastValue()); BigDecimal bigDecimal = new BigDecimal(chillersEntityList1.get(i).getLastValue());
chillerWaterInt = Double.parseDouble(String.valueOf(bigDecimal)); chillerWaterOut = Double.parseDouble(String.valueOf(bigDecimal));
} else if (registerAddr.equalsIgnoreCase("0B")) { } else if (registerAddr.equalsIgnoreCase("0E")) {
BigDecimal bigDecimal = new BigDecimal(chillersEntityList1.get(i).getLastValue()); BigDecimal bigDecimal = new BigDecimal(chillersEntityList1.get(i).getLastValue());
chillerWaterOut = Double.parseDouble(String.valueOf(bigDecimal)); coldWaterInt = Double.parseDouble(String.valueOf(bigDecimal));
} else if (registerAddr.equalsIgnoreCase("0E")) { } else if (registerAddr.equalsIgnoreCase("0F")) {
BigDecimal bigDecimal = new BigDecimal(chillersEntityList1.get(i).getLastValue()); BigDecimal bigDecimal = new BigDecimal(chillersEntityList1.get(i).getLastValue());
coldWaterInt = Double.parseDouble(String.valueOf(bigDecimal)); coldWaterOut = 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")) {
for (int i = 0; i < chillersEntityList2.size(); i++) { BigDecimal bigDecimal = new BigDecimal(chillersEntityList2.get(i).getLastValue());
String registerAddr = chillersEntityList2.get(i).getRegisterAddress(); chillerWaterInt = Double.parseDouble(String.valueOf(bigDecimal)) + chillerWaterInt;
if (registerAddr.equalsIgnoreCase("0A")) { } else if (registerAddr.equalsIgnoreCase("0B")) {
BigDecimal bigDecimal = new BigDecimal(chillersEntityList2.get(i).getLastValue()); BigDecimal bigDecimal = new BigDecimal(chillersEntityList2.get(i).getLastValue());
chillerWaterInt = Double.parseDouble(String.valueOf(bigDecimal)) + chillerWaterInt; chillerWaterOut = Double.parseDouble(String.valueOf(bigDecimal)) + chillerWaterOut;
} else if (registerAddr.equalsIgnoreCase("0B")) { } else if (registerAddr.equalsIgnoreCase("0E")) {
BigDecimal bigDecimal = new BigDecimal(chillersEntityList2.get(i).getLastValue()); BigDecimal bigDecimal = new BigDecimal(chillersEntityList2.get(i).getLastValue());
chillerWaterOut = Double.parseDouble(String.valueOf(bigDecimal)) + chillerWaterOut; coldWaterInt = Double.parseDouble(String.valueOf(bigDecimal)) + coldWaterInt;
} else if (registerAddr.equalsIgnoreCase("0E")) { } else if (registerAddr.equalsIgnoreCase("0F")) {
BigDecimal bigDecimal = new BigDecimal(chillersEntityList2.get(i).getLastValue()); BigDecimal bigDecimal = new BigDecimal(chillersEntityList2.get(i).getLastValue());
coldWaterInt = Double.parseDouble(String.valueOf(bigDecimal)) + coldWaterInt; coldWaterOut = Double.parseDouble(String.valueOf(bigDecimal)) + coldWaterOut;
} 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);
BigDecimal b2 = BigDecimal.valueOf(chillerWaterOut / 2); chillerWaterInt = b1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
chillerWaterOut = b2.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); BigDecimal b4 = BigDecimal.valueOf(coldWaterOut / 2);
BigDecimal b1 = BigDecimal.valueOf(chillerWaterInt / 2); coldWaterOut = b4.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
chillerWaterInt = b1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); BigDecimal b3 = BigDecimal.valueOf(coldWaterInt / 2);
BigDecimal b4 = BigDecimal.valueOf(coldWaterOut / 2); coldWaterInt = b3.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
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("hostTwo")) { } else if (chillersEntityList.size() == 1) {
// 获取对应的冷冻水、冷却水温度
List<ChillersEntity> 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<ChillersEntity> chillersEntityList3 = getStopChillers();
// 获取对应的冷冻水、冷却水温度
List<ChillersEntity> chillersEntityList1 = chillersMapper.getChillersTemp(chillersEntityList3.get(0).getDeviceCode());
List<ChillersEntity> 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<ChillersEntity> getRunningChillers() {
return chillersMapper.getRunningChillers();
} }
return hostValueList;
}
// 查询冷水机组进出水温度两者的平均值 @Override
public List<ChillersEntity> getStopChillers() {
return chillersMapper.getStopChillers();
}
@Override @Override
public List<ChillersEntity> getRunningChillers() { public List<ChillersEntity> queryChillersByOther(int grade, String ddcAddr) {
return chillersMapper.getRunningChillers(); return chillersMapper.queryChillersByOther(grade, ddcAddr);
} }
@Override @Override
public List<ChillersEntity> getStopChillers() { public int insertChillersHistory(ChillersEntity chillersEntity) {
return chillersMapper.getStopChillers(); 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 @Override
public List<ChillersEntity> queryChillersByOther(int grade, String ddcAddr) { public void updateChillerRegisterAddr(ChillersEntity chillersEntity) {
return chillersMapper.queryChillersByOther(grade, ddcAddr); chillersMapper.updateChillerRegisterAddr(chillersEntity);
} }
@Override @Override
public int insertChillersHistory(ChillersEntity chillersEntity) { public void updateDataNow(ChillersEntity chillersEntity) {
try { try {
System.out.println(chillersEntity.toString()); // 判断是否存在实时记录表
// 判断是否大于等于最近插入时间的30分钟, int a = chillersMapper.queryDataNowByOthers(chillersEntity);
String lastTimeStr = queryLastChillersHistory(chillersEntity); if (a == 0) {
if (lastTimeStr == null || lastTimeStr.equalsIgnoreCase("")) { // 不存在则进行插入处理
// 格式化时间分钟为15,30,45,00 chillersMapper.insertChillerDataNow(chillersEntity);
chillersEntity.setLastTime(DateUtil.formatDateStr(chillersEntity.getLastTime())); } else {
// 大于就插入数据库,否则就更新基表安装信息的表 // 存在则进行更新处理
return chillersMapper.insertChillersHistory(chillersEntity); chillersMapper.updateDataNow(chillersEntity);
} else { }
int dValue = TimeDifferenceUtil.dValue(lastTimeStr); } catch (Exception e) {
if (dValue >= 30) { e.printStackTrace();
// 格式化时间分钟为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 @Override
public void updateChillerRegisterAddr(ChillersEntity chillersEntity) { public int batchUpdateRegisterAddr(List<ChillersEntity> chillersEntityLists) {
chillersMapper.updateChillerRegisterAddr(chillersEntity); return chillersMapper.updateRegisterAddr(chillersEntityLists);
} }
@Override
public List<TableDataEntity> queryTopData(String deviceName, int grade) {
return chillersMapper.queryTopData(deviceName, grade);
}
@Override
public List<TableInfoEntity> queryLeftAndRightData(String deviceName, int grade) {
return chillersMapper.queryLeftAndRightData(deviceName, grade);
}
@Override @Override
public void updateDataNow(ChillersEntity chillersEntity) { public List<ChillersEntity> queryChillersDDC(int grade) {
try { return chillersMapper.queryChillersDDC(grade);
// 判断是否存在实时记录表
int a = chillersMapper.queryDataNowByOthers(chillersEntity);
if (a == 0) {
// 不存在则进行插入处理
chillersMapper.insertChillerDataNow(chillersEntity);
} else {
// 存在则进行更新处理
chillersMapper.updateDataNow(chillersEntity);
}
} catch (Exception e) {
e.printStackTrace();
} }
}
@Override @Override
public int batchUpdateRegisterAddr(List<ChillersEntity> chillersEntityLists) { public void batchInsertChillersHistory(List<ChillersEntity> chillersEntityLists) {
return chillersMapper.updateRegisterAddr(chillersEntityLists); chillersMapper.batchInsertChillersHistory(chillersEntityLists);
} }
@Override @Override
public List<TableDataEntity> queryTopData(String deviceName, int grade) { public String queryLastChillersHistory(ChillersEntity chillersEntity) {
return chillersMapper.queryTopData(deviceName, grade); return chillersMapper.queryLastChillersHistory(chillersEntity);
} }
@Override @Override
public List<TableInfoEntity> queryLeftAndRightData(String deviceName, int grade) { public List<String> queryDDCAddr(String ddcAddr) {
return chillersMapper.queryLeftAndRightData(deviceName, grade); return chillersMapper.queryDDCAddr(ddcAddr);
} }
@Override @Override
public List<ChillersEntity> queryChillersDDC(int grade) { public JSONArray queryChillersByProId(String systemId, String proId) {
return chillersMapper.queryChillersDDC(grade); JSONArray resultJson = new JSONArray();
} QueryWrapper<DevicesManageEntity> deviceQueryWrapper = new QueryWrapper<>();
if (systemId != null && !systemId.equalsIgnoreCase("")) {
deviceQueryWrapper.eq("system_id", systemId);
}
if (proId != null && !proId.equalsIgnoreCase("")) {
deviceQueryWrapper.eq("project_id", proId);
}
List<DevicesManageEntity> devicesManageEntityList = devicesManageMapper.selectList(deviceQueryWrapper.orderByAsc("id"));
if (devicesManageEntityList != null && !devicesManageEntityList.isEmpty()) {
HostListVO hostListVO = new HostListVO();
// 根据projectId进行分组
Map<Long, List<DevicesManageEntity>> proDevicesMap =
devicesManageEntityList.stream().collect(Collectors.groupingBy(DevicesManageEntity::getProjectId));
// 遍历分组后的数据
for (Map.Entry<Long, List<DevicesManageEntity>> 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 JSONArray children = new JSONArray();
public void batchInsertChillersHistory(List<ChillersEntity> chillersEntityLists) { List<DevicesManageEntity> devicesManageEntities = entry.getValue();
chillersMapper.batchInsertChillersHistory(chillersEntityLists); for (DevicesManageEntity devicesManageEntity : devicesManageEntities) {
} JSONObject deviceJson = new JSONObject();
deviceJson.put("name", devicesManageEntity.getDeviceName());
deviceJson.put("value", devicesManageEntity.getId());
JSONArray mtArray = new JSONArray();
List<MeterManageEntity> meterManageEntities = meterManageMapper.selectList(
new QueryWrapper<MeterManageEntity>()
.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 private void matchingChillersData(List<MeterManageEntity> meterManageEntities, HostListVO hostListVO) {
public String queryLastChillersHistory(ChillersEntity chillersEntity) { hostListVO.reset();
return chillersMapper.queryLastChillersHistory(chillersEntity); 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<String> queryDDCAddr(String ddcAddr) {
return chillersMapper.queryDDCAddr(ddcAddr);
}
} }

14
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) { public void analysisCloudOrder485(final String dataStr1, final DeviceCodeParamEntity deviceCodeParam) {
threadPoolService.execute(() -> { // threadPoolService.execute(() -> {
// 去掉空格 // 去掉空格
String dataStr = dataStr1.replace(" ", "").toUpperCase(); String dataStr = dataStr1.replace(" ", "").toUpperCase();
// 检验报文 // 检验报文
@ -59,7 +59,7 @@ public class AnalysisReceiveOrder485 {
if (checkWord.equalsIgnoreCase(dataStr.substring(dataStr.length() - 4))) { if (checkWord.equalsIgnoreCase(dataStr.substring(dataStr.length() - 4))) {
//创建SimpleDateFormat对象,指定样式 2019-05-13 22:39:30 //创建SimpleDateFormat对象,指定样式 2019-05-13 22:39:30
Date date = new Date(); Date date = new Date();
String dateStr = ""; String dateStr = sdf1.format(date);;
//保留两位小数处理 //保留两位小数处理
DecimalFormat decimalFormat = new DecimalFormat("0.00"); DecimalFormat decimalFormat = new DecimalFormat("0.00");
// 表号 // 表号
@ -75,14 +75,10 @@ public class AnalysisReceiveOrder485 {
DataResultClEntity dataResultCl = new DataResultClEntity(); DataResultClEntity dataResultCl = new DataResultClEntity();
String registerAddr = deviceCodeParam.getRegisterAddr(); String registerAddr = deviceCodeParam.getRegisterAddr();
if (ExchangeStringUtil.isInDate(date, "00:00:00", "00:00:30")) { if (ExchangeStringUtil.isInDate(date, "00:00:00", "00:00:30")) {
dateStr = sdf1.format(date);
dateStr = dateStr.substring(0, 17) + "00"; dateStr = dateStr.substring(0, 17) + "00";
System.out.println("插入时间00" + dateStr); System.out.println("插入时间00" + dateStr);
} else if (ExchangeStringUtil.isInDate(date, "00:00:30", "00:00:59")) { } else if (ExchangeStringUtil.isInDate(date, "00:00:30", "00:00:59")) {
dateStr = sdf1.format(date);
dateStr = dateStr.substring(0, 17) + "30"; dateStr = dateStr.substring(0, 17) + "30";
System.out.println("插入时间30" + dateStr); System.out.println("插入时间30" + dateStr);
} }
try { try {
@ -128,7 +124,7 @@ public class AnalysisReceiveOrder485 {
} else { } else {
log.info("冷量计校验失败===>" + dataStr); log.info("冷量计校验失败===>" + dataStr);
} }
}); // });
} }
public String analysisCloudQueue(QueueParam queueParam) { public String analysisCloudQueue(QueueParam queueParam) {
@ -354,7 +350,7 @@ public class AnalysisReceiveOrder485 {
log.info("meterID==>" + meterId + ",meter curValue==>" + data + ",projectName==>" + projectName); log.info("meterID==>" + meterId + ",meter curValue==>" + data + ",projectName==>" + projectName);
log.info("meter save data success!projectName:" + projectName); log.info("meter save data success!projectName:" + projectName);
} catch (Exception e) { } catch (Exception e) {
log.error("保存电表数据失败!", e); log.error("保存电表数据失败!", e);
} }
rec = "success"; rec = "success";
} else { } else {
@ -436,7 +432,7 @@ public class AnalysisReceiveOrder485 {
dataResultService.saveDataResult(dataResultEntity); dataResultService.saveDataResult(dataResultEntity);
log.info("wtMeter save data success!projectId:" + projectId); log.info("wtMeter save data success!projectId:" + projectId);
} catch (Exception e) { } catch (Exception e) {
log.error("保存水表数据失败!", e); log.error("保存水表数据失败!", e);
} }
}); });
} }

136
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 + '\'' +
'}';
}
}

72
user-service/src/test/java/com/mh/user/SysUserTest.java

@ -1,5 +1,6 @@
package com.mh.user; package com.mh.user;
import com.mh.user.utils.ExchangeStringUtil;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
@ -29,37 +30,50 @@ import java.util.List;
*/ */
public class SysUserTest { 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 { public static void main(String[] args) throws ParseException, IOException {
// 读取TXT文件中的HTML内容 String dateStr = "";
String htmlContent = readFile("C:/Users/MH/Desktop/getAir.txt"); Date date = new Date();
if (ExchangeStringUtil.isInDate(date, "00:00:00", "00:00:30")) {
// 使用Jsoup解析HTML dateStr = sdf1.format(date);
Document doc = Jsoup.parse(htmlContent); dateStr = dateStr.substring(0, 17) + "00";
// 提取所有的img标签 System.out.println("插入时间00" + dateStr);
Elements imgElements = doc.select("img"); } else if (ExchangeStringUtil.isInDate(date, "00:00:30", "00:00:59")) {
dateStr = sdf1.format(date);
// 存储img标签的src属性 dateStr = dateStr.substring(0, 17) + "30";
List<String> imgSrcs = new ArrayList<>();
for (Element img : imgElements) { System.out.println("插入时间30" + dateStr);
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;
}
} }
// // 读取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<String> 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 { private static String readFile(String filePath) throws IOException {

Loading…
Cancel
Save