Browse Source

1、能耗管理:机房能耗

dev
mh 3 months ago
parent
commit
76980d5819
  1. 5
      mh-common/pom.xml
  2. 41
      mh-common/src/main/java/com/mh/common/constant/Constants.java
  3. 32
      mh-common/src/main/java/com/mh/common/core/domain/ColumnFilter.java
  4. 15
      mh-common/src/main/java/com/mh/common/core/domain/entity/CollectionParamsManage.java
  5. 106
      mh-common/src/main/java/com/mh/common/core/domain/entity/DeviceTypeEnergyEntity.java
  6. 92
      mh-common/src/main/java/com/mh/common/core/domain/vo/EnergyConsumptionVO.java
  7. 94
      mh-common/src/main/java/com/mh/common/core/domain/vo/EnergyQueryVO.java
  8. 154
      mh-common/src/main/java/com/mh/common/utils/DateUtils.java
  9. 35
      mh-system/src/main/java/com/mh/system/mapper/device/CollectionParamsManageMapper.java
  10. 26
      mh-system/src/main/java/com/mh/system/service/energy/EnergyAnalyzeService.java
  11. 183
      mh-system/src/main/java/com/mh/system/service/energy/impl/EnergyAnalyzeServiceImpl.java
  12. 8
      pom.xml

5
mh-common/pom.xml

@ -150,6 +150,11 @@
<!-- <artifactId>spring-messaging</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>

41
mh-common/src/main/java/com/mh/common/constant/Constants.java

@ -1,6 +1,7 @@
package com.mh.common.constant;
import java.util.Locale;
import io.jsonwebtoken.Claims;
/**
@ -8,8 +9,7 @@ import io.jsonwebtoken.Claims;
*
* @author mh
*/
public class Constants
{
public class Constants {
/**
* UTF-8 字符集
*/
@ -170,4 +170,41 @@ public class Constants
*/
public static final String[] JOB_ERROR_STR = {"java.net.URL", "javax.naming.InitialContext", "org.yaml.snakeyaml",
"org.springframework", "org.apache", "com.mh.common.utils.file", "com.mh.common.config", "com.mh.generator"};
public static final String DAY = "day";
public static final String MONTH = "month";
public static final String CLOSE_ORDER = "close_oder"; // 关闭指令
public static final String HOST_TYPE = "host"; // 主机设备类型
public static final String VALVE_TYPE = "Valve"; // 蝶阀类型
public static final String COOL_PUMP_TYPE = "coolPump"; // 冷却泵
public static final String COOL_PUMP_TYPE_STRING = "冷却泵"; // 冷却泵
public static final String CHILLER_PUMP_TYPE = "chillPump"; // 冷冻泵
public static final String COOL_TOWER_TYPE = "tower"; // 冷却塔
public static final String CLOSE_HOST = "close_host_device_id"; // 关闭主机的设备id
public static final String OPEN_VALVE = "open_valve_device_id"; // 开启蝶阀的设备id
public static boolean CONTROL_WEB_FLAG = false;
public static boolean SEND_STATUS = false; // 指令发送状态
public static boolean FLAG = false;
public static boolean WEB_FLAG = false; // 判断是否有前端指令下发
public static final String TYPE_DDC = "ddc"; // 查询ddc指令
public static final String TYPE_REGISTER = "registers"; // 查询ddc指令
public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss"; // 格式化时间
public static final String METER_TYPE = "meter";
public static final String CLOUD_TYPE = "cloud";
public static final String[] DEVICE_TYPE = {"冷水机组(kwh)", "冷冻泵(kwh)", "冷却泵(kwh)", "冷却塔(kwh)", "其他"}; // 设备类型
public static final String ADD_TIME = "add_time_";
public static final String DELETE_TIME = "delete_time_";
public static final String CP_PID_Type = "CPPIDType"; // 冷却泵PID值
public static final String OPEN_DEVICES = "open_devices"; // 一键启动设备
public static final String ADD_CHILLER = "add_chiller"; // 添加主机
public static final String DELETE_CHILLER = "delete_chiller"; // 减少主机
}

32
mh-common/src/main/java/com/mh/common/core/domain/ColumnFilter.java

@ -0,0 +1,32 @@
package com.mh.common.core.domain;
/**
* 分页查询列过滤器
* @author Louis
* @date Aug 19, 2018
*/
public class ColumnFilter {
/**
* 过滤列名
*/
private String name;
/**
* 查询的值
*/
private String value;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}

15
mh-common/src/main/java/com/mh/common/core/domain/entity/CollectionParamsManage.java

@ -148,6 +148,19 @@ public class CollectionParamsManage extends BaseEntity {
*/
private String otherName;
/**
* 累计/瞬时 状态标识
*/
private Integer grade;
public Integer getGrade() {
return grade;
}
public void setGrade(Integer grade) {
this.grade = grade;
}
public String getOtherName() {
return otherName;
}
@ -385,6 +398,8 @@ public class CollectionParamsManage extends BaseEntity {
.append("registerSize", registerSize)
.append("isUse", isUse)
.append("otherName", otherName)
.append("grade", grade)
.toString();
}
}

106
mh-common/src/main/java/com/mh/common/core/domain/entity/DeviceTypeEnergyEntity.java

@ -0,0 +1,106 @@
package com.mh.common.core.domain.entity;
import java.io.Serializable;
/**
* @author LJF
* @version 1.0
* @project NewZhujiang_Server
* @description 各个设备类型组装成的DTO
* @date 2023-12-14 15:12:30
*/
public class DeviceTypeEnergyEntity implements Serializable {
private static final long serialVersionUID = 10L;
private String calcValue;
private String deviceNum;
private String remark;
private String deviceType;
private String grade;
private String timeStr;
public String getTimeStr() {
return timeStr;
}
public void setTimeStr(String timeStr) {
this.timeStr = timeStr;
}
public String getGrade() {
return grade;
}
public void setGrade(String grade) {
this.grade = grade;
}
public String getCalcValue() {
return calcValue;
}
public void setCalcValue(String calcValue) {
this.calcValue = calcValue;
}
public String getDeviceNum() {
return deviceNum;
}
public void setDeviceNum(String deviceNum) {
this.deviceNum = deviceNum;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
public String getDeviceType() {
return deviceType;
}
public void setDeviceType(String deviceType) {
this.deviceType = deviceType;
}
public String getDeviceTypeRange() {
if (Integer.parseInt(this.grade) < 10) {
return "冷水机组(kwh)";
} else if (Integer.parseInt(this.grade) >= 10 && Integer.parseInt(this.grade) < 20) {
return "冷冻泵(kwh)";
} else if (Integer.parseInt(this.grade) >= 20 && Integer.parseInt(this.grade) < 30) {
return "冷却泵(kwh)";
} else if (Integer.parseInt(this.grade) >= 30 && Integer.parseInt(this.grade) < 40) {
return "冷却塔(kwh)";
} else {
return "其他";
}
}
public Double getDoubleCalcValue() {
return Double.parseDouble(this.calcValue);
}
@Override
public String toString() {
return "DeviceTypeEnergyEntity{" +
"calcValue='" + calcValue + '\'' +
", deviceNum='" + deviceNum + '\'' +
", remark='" + remark + '\'' +
", deviceType='" + deviceType + '\'' +
", grade='" + grade + '\'' +
", timeStr='" + timeStr + '\'' +
'}';
}
}

92
mh-common/src/main/java/com/mh/common/core/domain/vo/EnergyConsumptionVO.java

@ -0,0 +1,92 @@
package com.mh.common.core.domain.vo;
import java.io.Serializable;
/**
* @author LJF
* @version 1.0
* @project NewZhujiang_Server
* @description 能耗分析接收参数
* @date 2023/7/18 15:27:17
*/
public class EnergyConsumptionVO implements Serializable {
private static final long serialVersionUID = 10L;
/**
* 查询类型hourdaymonthyear
*/
private String timeType;
/**
* 开始时间yyyy-MM-dd
*/
private String startTime;
/**
* 结束时间yyyy-MM-dd
*/
private String endTime;
/**
* 设备类型chiller主机chilledWaterPump冷冻泵coolingPump冷却泵coolingTower冷却塔
*/
private String deviceType;
/**
* 参数类型coolelectriccop
*/
private String paramType;
public String getTimeType() {
return timeType;
}
public void setTimeType(String timeType) {
this.timeType = timeType;
}
public String getStartTime() {
return startTime;
}
public void setStartTime(String startTime) {
this.startTime = startTime;
}
public String getEndTime() {
return endTime;
}
public void setEndTime(String endTime) {
this.endTime = endTime;
}
public String getDeviceType() {
return deviceType;
}
public void setDeviceType(String deviceType) {
this.deviceType = deviceType;
}
public String getParamType() {
return paramType;
}
public void setParamType(String paramType) {
this.paramType = paramType;
}
@Override
public String toString() {
return "EnergyConsumptionVO{" +
"timeType='" + timeType + '\'' +
", startTime='" + startTime + '\'' +
", endTime='" + endTime + '\'' +
", deviceType='" + deviceType + '\'' +
", paramType='" + paramType + '\'' +
'}';
}
}

94
mh-common/src/main/java/com/mh/common/core/domain/vo/EnergyQueryVO.java

@ -0,0 +1,94 @@
package com.mh.common.core.domain.vo;
import com.mh.common.core.domain.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import java.io.Serializable;
/**
* @author LJF
* @version 1.0
* @project NewZhujiang_Server
* @description 能耗查询公共参数
* @date 2023-12-13 16:11:24
*/
public class EnergyQueryVO extends BaseEntity implements Serializable {
private static final long serialVersionUID = 10L;
/**
* 查询类型hourdaymonthyear
*/
private String timeType;
/**
* 开始时间yyyy-MM-dd
*/
private String startTime;
/**
* 结束时间yyyy-MM-dd
*/
private String endTime;
/**
* 设备类型chiller主机chilledWaterPump冷冻泵coolingPump冷却泵coolingTower冷却塔
*/
private String deviceType;
/**
* 参数类型coolelectriccop
*/
private String paramType;
public String getTimeType() {
return timeType;
}
public void setTimeType(String timeType) {
this.timeType = timeType;
}
public String getStartTime() {
return startTime;
}
public void setStartTime(String startTime) {
this.startTime = startTime;
}
public String getEndTime() {
return endTime;
}
public void setEndTime(String endTime) {
this.endTime = endTime;
}
public String getDeviceType() {
return deviceType;
}
public void setDeviceType(String deviceType) {
this.deviceType = deviceType;
}
public String getParamType() {
return paramType;
}
public void setParamType(String paramType) {
this.paramType = paramType;
}
@Override
public String toString() {
return new ToStringBuilder(this)
.append("timeType", timeType)
.append("startTime", startTime)
.append("endTime", endTime)
.append("deviceType", deviceType)
.append("paramType", paramType)
.toString();
}
}

154
mh-common/src/main/java/com/mh/common/utils/DateUtils.java

@ -1,14 +1,17 @@
package com.mh.common.utils;
import java.lang.management.ManagementFactory;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.Date;
import com.mh.common.core.domain.vo.EnergyConsumptionVO;
import com.mh.common.core.domain.vo.EnergyQueryVO;
import org.apache.commons.lang3.time.DateFormatUtils;
/**
@ -188,4 +191,145 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
ZonedDateTime zdt = localDateTime.atZone(ZoneId.systemDefault());
return Date.from(zdt.toInstant());
}
/*
* 获取同一个时间的上一个时间
* @param timerStr
* @return
*/
public static String yoyDate(String timerStr) {
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
DateTimeFormatter timeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate localDate = LocalDate.parse(timerStr, timeFormatter);
LocalDate localDate1 = localDate.minusYears(1);
return localDate1.format(timeFormatter1).concat(timerStr.substring(10));
}
/**
* 获取同一个时间的上一个时间
* @param timerStr
* @return
*/
public static String momDate(String timerStr, String timeType, String timeRange) {
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime localDate = LocalDateTime.parse(timerStr, timeFormatter);
LocalDateTime localDate1 = null;
switch (timeType) {
case "hour":
localDate1 = localDate.minusHours(1);
break;
case "day":
localDate1 = localDate.minusDays(1);
break;
case "month":
if ("end".equals(timeRange)) {
localDate1 = localDate.minusMonths(1).with(TemporalAdjusters.lastDayOfMonth());
} else if ("start".equals(timeRange)) {
localDate1 = localDate.minusMonths(1).with(TemporalAdjusters.firstDayOfMonth());
}
break;
case "year":
localDate1 = localDate.minusYears(1);
break;
}
assert localDate1 != null;
return localDate1.format(timeFormatter);
}
public static void energyDateChange(EnergyConsumptionVO vo) {
switch (vo.getTimeType()) {
case "day":
vo.setStartTime(vo.getStartTime().concat(" 00:00:00"));
vo.setEndTime(vo.getEndTime().concat(" 23:59:59"));
break;
case "month":
YearMonth yearMonth = YearMonth.parse(vo.getStartTime(), DateTimeFormatter.ofPattern("yyyy-MM"));
LocalDate firstDayOfMonth = yearMonth.atDay(1);
String firstDayOutput = firstDayOfMonth.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
vo.setStartTime(firstDayOutput.concat(" 00:00:00"));
YearMonth yearMonth1 = YearMonth.parse(vo.getEndTime(), DateTimeFormatter.ofPattern("yyyy-MM"));
LocalDate firstDayOfMonth1 = yearMonth1.atEndOfMonth();
String firstDayOutput1 = firstDayOfMonth1.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
vo.setEndTime(firstDayOutput1.concat(" 23:59:59"));
break;
case "year":
vo.setStartTime(vo.getStartTime().concat("-01-01 00:00:00"));
vo.setEndTime(vo.getEndTime().concat("-12-31 23:59:59"));
break;
default:
break;
}
}
public static void sysEnergyDateChange(EnergyQueryVO vo) {
switch (vo.getTimeType()) {
case "day":
vo.setStartTime(vo.getStartTime().concat(" 00:00:00"));
vo.setEndTime(vo.getEndTime().concat(" 23:59:59"));
break;
case "month":
YearMonth yearMonth = YearMonth.parse(vo.getStartTime(), DateTimeFormatter.ofPattern("yyyy-MM"));
LocalDate firstDayOfMonth = yearMonth.atDay(1);
String firstDayOutput = firstDayOfMonth.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
vo.setStartTime(firstDayOutput.concat(" 00:00:00"));
YearMonth yearMonth1 = YearMonth.parse(vo.getEndTime(), DateTimeFormatter.ofPattern("yyyy-MM"));
LocalDate firstDayOfMonth1 = yearMonth1.atEndOfMonth();
String firstDayOutput1 = firstDayOfMonth1.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
vo.setEndTime(firstDayOutput1.concat(" 23:59:59"));
break;
case "year":
vo.setStartTime(vo.getStartTime().concat("-01-01 00:00:00"));
vo.setEndTime(vo.getEndTime().concat("-12-31 23:59:59"));
break;
default:
break;
}
}
/**
* 计算时间差
* @param curTime
* @param lastTime
* @param type
* @return
*/
public static BigDecimal calcDate(Object curTime, Object lastTime, String type) {
String momDate = momDate((String) curTime, type, "");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
long curDateMillis = 0;
long lastTimeMillis = 0;
try {
LocalDateTime dateTime = LocalDateTime.parse(momDate, formatter);
curDateMillis = dateTime.atZone(ZoneId.systemDefault()).toInstant().getEpochSecond();
LocalDateTime lastDateTime = LocalDateTime.parse((CharSequence) lastTime, formatter);
lastTimeMillis = lastDateTime.atZone(ZoneId.systemDefault()).toInstant().getEpochSecond();
} catch (Exception e) {
System.err.println("无法解析时间字符串: " + e.getMessage());
}
return (new BigDecimal(curDateMillis - lastTimeMillis)).divide(new BigDecimal(60),2, RoundingMode.HALF_UP);
}
public static String getTimeLen(String timeType) {
String timeLen = "";
switch (timeType) {
case "hour":
timeLen = "13";
break;
case "day":
timeLen = "10";
break;
case "month":
timeLen = "7";
break;
case "year":
timeLen = "4";
break;
}
return timeLen;
}
}

35
mh-system/src/main/java/com/mh/system/mapper/device/CollectionParamsManageMapper.java

@ -2,7 +2,9 @@ package com.mh.system.mapper.device;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mh.common.core.domain.entity.CollectionParamsManage;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.*;
import java.util.List;
/**
* @author LJF
@ -13,4 +15,35 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public interface CollectionParamsManageMapper extends BaseMapper<CollectionParamsManage> {
@Results({
@Result(column = "id", property = "id"),
@Result(column = "device_code", property = "deviceCode"),
@Result(column = "device_num", property = "deviceNum"),
@Result(column = "collection_num", property = "collectionNum"),
@Result(column = "data_com", property = "dataCom"),
@Result(column = "initial_value", property = "initialValue"),
@Result(column = "device_rate", property = "deviceRate"),
@Result(column = "device_caliber", property = "deviceCaliber"),
@Result(column = "price", property = "price"),
@Result(column = "param_id", property = "paramId"),
@Result(column = "param_name", property = "paramName"),
@Result(column = "last_value", property = "lastValue"),
@Result(column = "last_date", property = "lastDates"),
@Result(column = "communication_type", property = "communicationType"),
@Result(column = "device_type", property = "deviceType"),
@Result(column = "create_time", property = "createTimes"),
@Result(column = "update_time", property = "updateTimes"),
@Result(column = "remark", property = "remark"),
@Result(column = "grade", property = "grade")
})
@Select("<script>" +
"select * from collection_params_manage" +
"<where>" +
"<if test='deviceNum != null'>" +
"and mt_num = #{deviceNum}" +
"</if>" +
"</where>" +
"</script>")
List<CollectionParamsManage> getDeviceByOther(@Param("deviceNum") String deviceNum);
}

26
mh-system/src/main/java/com/mh/system/service/energy/EnergyAnalyzeService.java

@ -0,0 +1,26 @@
package com.mh.system.service.energy;
import com.alibaba.fastjson2.JSONObject;
import com.mh.common.core.domain.AjaxResult;
import com.mh.common.core.domain.ColumnFilter;
import com.mh.common.core.domain.vo.EnergyQueryVO;
import java.util.List;
/**
* @author LJF
* @version 1.0
* @project NewZhujiang_Server
* @description 能源分析服务
* @date 2023-12-13 15:50:36
*/
public interface EnergyAnalyzeService {
/**
* 通过时间查询各个设备类型的用电量
* @param vo
* @return
*/
JSONObject sysAnalyze(EnergyQueryVO vo);
}

183
mh-system/src/main/java/com/mh/system/service/energy/impl/EnergyAnalyzeServiceImpl.java

@ -0,0 +1,183 @@
package com.mh.system.service.energy.impl;
import com.alibaba.fastjson2.JSONObject;
import com.mh.common.constant.Constants;
import com.mh.common.core.domain.ColumnFilter;
import com.mh.common.core.domain.entity.CollectionParamsManage;
import com.mh.common.core.domain.entity.DeviceTypeEnergyEntity;
import com.mh.common.core.domain.vo.EnergyQueryVO;
import com.mh.common.utils.DateUtils;
import com.mh.system.mapper.device.CollectionParamsManageMapper;
import com.mh.system.mapper.energy.EnergyAnalyzeMapper;
import com.mh.system.service.energy.EnergyAnalyzeService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
/**
* @author LJF
* @version 1.0
* @project NewZhujiang_Server
* @description 能源分析实现类
* @date 2023-12-14 11:50:47
*/
@Service
public class EnergyAnalyzeServiceImpl implements EnergyAnalyzeService {
@Resource
private EnergyAnalyzeMapper energyAnalyzeMapper;
@Resource
private CollectionParamsManageMapper collectionParamsManageMapper;
@Override
public JSONObject sysAnalyze(EnergyQueryVO vo) {
DateUtils.sysEnergyDateChange(vo);
// 获取参数
AtomicReference<String> lastTableName = new AtomicReference<>("data_" + vo.getTimeType());
AtomicReference<String> curTableName = new AtomicReference<>("data_" + vo.getTimeType());
String timeType = vo.getTimeType();
List<DeviceTypeEnergyEntity> deviceTypeEnergyEntities = null;
// 表格数据
if ("month".equalsIgnoreCase(timeType) || "year".equalsIgnoreCase(timeType)) {
// 单表
deviceTypeEnergyEntities = energyAnalyzeMapper.queryOneTable(vo.getStartTime(), vo.getEndTime(), lastTableName.get(), curTableName.get(), DateUtils.getTimeLen(vo.getTimeType()), Constants.METER_TYPE);
} else {
lastTableName.set(lastTableName + vo.getStartTime().substring(0, 4));
curTableName.set(curTableName + vo.getEndTime().substring(0, 4));
if (lastTableName.get().equalsIgnoreCase(curTableName.get())) {
// 单表
deviceTypeEnergyEntities = energyAnalyzeMapper.queryOneTable(vo.getStartTime(), vo.getEndTime(), lastTableName.get(), curTableName.get(), DateUtils.getTimeLen(vo.getTimeType()), Constants.METER_TYPE);
} else {
// 多表
deviceTypeEnergyEntities = energyAnalyzeMapper.queryManyTable(vo.getStartTime(), vo.getEndTime(), lastTableName.get(), curTableName.get(), DateUtils.getTimeLen(vo.getTimeType()), Constants.METER_TYPE);
}
}
if (null == deviceTypeEnergyEntities || deviceTypeEnergyEntities.size() == 0) {
return new JSONObject();
}
// 开始进行分组
// 通过device_manage的grade进行分组,分为四类:0-9:冷水机,10-19:冷冻泵,20-29:冷却泵,30-39:冷却塔
HashMap<String, BigDecimal> result = deviceTypeEnergyEntities.stream()
.collect(Collectors.groupingBy(DeviceTypeEnergyEntity::getDeviceTypeRange))
.entrySet().stream().collect(Collectors.toMap(
Map.Entry<String, List<DeviceTypeEnergyEntity>>::getKey,
entry -> {
List<DeviceTypeEnergyEntity> value = entry.getValue();
BigDecimal sum = new BigDecimal("0");
for (DeviceTypeEnergyEntity deviceTypeEnergyEntity : value) {
sum = sum.add(new BigDecimal(deviceTypeEnergyEntity.getCalcValue()));
}
return sum;
},
BigDecimal::add,
HashMap::new
));
List<ColumnFilter> results = new ArrayList<>();
for (String value : Constants.DEVICE_TYPE) {
ColumnFilter columnFilter = new ColumnFilter();
columnFilter.setName(value);
if (result.containsKey(value)) {
columnFilter.setValue(String.valueOf(result.get(value).setScale(2, RoundingMode.HALF_UP)));
results.add(columnFilter);
} else {
columnFilter.setValue("0.00");
results.add(columnFilter);
}
}
// 查询各个冷水机组的 0-9
List<DeviceTypeEnergyEntity> chiller = createDeviceTypeData(deviceTypeEnergyEntities, 10, 0);
// 查询各个冷冻泵的 10-19
List<DeviceTypeEnergyEntity> chillerPump = createDeviceTypeData(deviceTypeEnergyEntities, 20, 10);
// 查询各个冷却泵的 20-29
List<DeviceTypeEnergyEntity> coolPump = createDeviceTypeData(deviceTypeEnergyEntities, 30, 20);
// 查询各个冷却塔的 30-39
List<DeviceTypeEnergyEntity> coolTower = createDeviceTypeData(deviceTypeEnergyEntities, 40, 30);
// 从device_manage查询不是总表的
List<CollectionParamsManage> deviceByOther = collectionParamsManageMapper.getDeviceByOther(null);
if (deviceByOther != null && deviceByOther.size() > 0) {
// 通过stream进行分组,然后进行重新赋值,封装新对象,重新返回
for (CollectionParamsManage deviceManageEntity : deviceByOther) {
// 重新赋值冷水机
reassignData(chiller, deviceManageEntity);
// 重新赋值冷冻泵
reassignData(chillerPump, deviceManageEntity);
// 重新赋值冷却泵
reassignData(coolPump, deviceManageEntity);
// 重新赋值冷却塔
reassignData(coolTower, deviceManageEntity);
}
}
List<ColumnFilter> chillerData = getResultData(chiller);
List<ColumnFilter> chillerPumpData = getResultData(chillerPump);
List<ColumnFilter> coolPumpData = getResultData(coolPump);
List<ColumnFilter> coolTowerData = getResultData(coolTower);
JSONObject resultJson = new JSONObject();
resultJson.put("all", results);
resultJson.put("chiller", chillerData);
resultJson.put("chillerPump", chillerPumpData);
resultJson.put("coolPump", coolPumpData);
resultJson.put("coolTower", coolTowerData);
return resultJson;
}
private static List<ColumnFilter> getResultData(List<DeviceTypeEnergyEntity> coolTower) {
return coolTower.stream()
.sorted(Comparator.comparing(DeviceTypeEnergyEntity::getGrade))
.map(val -> {
ColumnFilter data = new ColumnFilter();
data.setName(val.getRemark());
BigDecimal calcValue = new BigDecimal(val.getCalcValue()).setScale(2, RoundingMode.HALF_UP);
data.setValue(String.valueOf(calcValue));
return data;
}).collect(Collectors.toList());
}
private static void reassignData(List<DeviceTypeEnergyEntity> chiller, CollectionParamsManage deviceManageEntity) {
chiller.stream()
.filter(val -> val.getDeviceNum().equals(deviceManageEntity.getMtNum()))
.peek(val -> {
val.setDeviceType(deviceManageEntity.getMtType());
val.setRemark(deviceManageEntity.getRemark());
val.setGrade(String.valueOf(deviceManageEntity.getGrade()));
})
.sorted(Comparator.comparing(DeviceTypeEnergyEntity::getGrade))
.collect(Collectors.toList());
}
private static List<DeviceTypeEnergyEntity> createDeviceTypeData(List<DeviceTypeEnergyEntity> deviceTypeEnergyEntities, int x, int x1) {
return deviceTypeEnergyEntities.stream()
.filter(val -> Integer.parseInt(val.getGrade()) < x && Integer.parseInt(val.getGrade()) >= x1)
.collect(Collectors.groupingBy(DeviceTypeEnergyEntity::getDeviceNum, Collectors.summarizingDouble(DeviceTypeEnergyEntity::getDoubleCalcValue)))
.entrySet().stream()
.map(entry -> {
DeviceTypeEnergyEntity deviceTypeEnergyEntity = new DeviceTypeEnergyEntity();
deviceTypeEnergyEntity.setCalcValue(String.valueOf(entry.getValue().getSum()));
deviceTypeEnergyEntity.setDeviceNum(entry.getKey());
return deviceTypeEnergyEntity;
})
.collect(Collectors.toList());
}
}

8
pom.xml

@ -39,6 +39,7 @@
<mqtt.version>6.4.1</mqtt.version>
<lombok.version>1.18.36</lombok.version>
<message.version>6.2.1</message.version>
<easyexcel.version>3.2.1</easyexcel.version>
</properties>
<!-- 依赖声明 -->
@ -260,6 +261,13 @@
<version>${message.version}</version>
</dependency>
<!-- excel包 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>${easyexcel.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

Loading…
Cancel
Save