12 changed files with 788 additions and 13 deletions
@ -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; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -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 + '\'' + |
||||||
|
'}'; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -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; |
||||||
|
|
||||||
|
/** |
||||||
|
* 查询类型:hour,day,month,year |
||||||
|
*/ |
||||||
|
private String timeType; |
||||||
|
|
||||||
|
/** |
||||||
|
* 开始时间yyyy-MM-dd |
||||||
|
*/ |
||||||
|
private String startTime; |
||||||
|
|
||||||
|
/** |
||||||
|
* 结束时间:yyyy-MM-dd |
||||||
|
*/ |
||||||
|
private String endTime; |
||||||
|
|
||||||
|
/** |
||||||
|
* 设备类型:chiller:主机,chilledWaterPump:冷冻泵,coolingPump:冷却泵,coolingTower:冷却塔 |
||||||
|
*/ |
||||||
|
private String deviceType; |
||||||
|
|
||||||
|
/** |
||||||
|
* 参数类型:cool,electric,cop |
||||||
|
*/ |
||||||
|
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 + '\'' + |
||||||
|
'}'; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -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; |
||||||
|
|
||||||
|
/** |
||||||
|
* 查询类型:hour,day,month,year |
||||||
|
*/ |
||||||
|
private String timeType; |
||||||
|
|
||||||
|
/** |
||||||
|
* 开始时间yyyy-MM-dd |
||||||
|
*/ |
||||||
|
private String startTime; |
||||||
|
|
||||||
|
/** |
||||||
|
* 结束时间:yyyy-MM-dd |
||||||
|
*/ |
||||||
|
private String endTime; |
||||||
|
|
||||||
|
/** |
||||||
|
* 设备类型:chiller:主机,chilledWaterPump:冷冻泵,coolingPump:冷却泵,coolingTower:冷却塔 |
||||||
|
*/ |
||||||
|
private String deviceType; |
||||||
|
|
||||||
|
/** |
||||||
|
* 参数类型:cool,electric,cop |
||||||
|
*/ |
||||||
|
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(); |
||||||
|
} |
||||||
|
} |
@ -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); |
||||||
|
|
||||||
|
} |
@ -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()); |
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue