|
|
|
@ -1,7 +1,6 @@ |
|
|
|
package com.thing.qingyuan.board.service.impl; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.google.common.collect.Lists; |
|
|
|
import com.thing.common.core.exception.SysException; |
|
|
|
import com.thing.common.core.utils.DateTimeUtils; |
|
|
|
@ -9,8 +8,9 @@ import com.thing.common.data.tskv.TsKvDTO; |
|
|
|
import com.thing.common.tskv.service.TsKvService; |
|
|
|
import com.thing.qingyuan.board.dto.*; |
|
|
|
import com.thing.qingyuan.board.service.BoardNewService; |
|
|
|
import com.thing.sys.biz.service.SysParamsService; |
|
|
|
import com.thing.sys.security.context.UserContext; |
|
|
|
import com.thing.thing.entity.dto.IotThingEntityDTO; |
|
|
|
import com.thing.thing.entity.service.IotThingEntityService; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
@ -20,7 +20,6 @@ import java.math.RoundingMode; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.time.LocalDate; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.time.YearMonth; |
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
@ -35,290 +34,134 @@ import java.util.stream.Collectors; |
|
|
|
@RequiredArgsConstructor |
|
|
|
public class BoardNewServiceImpl implements BoardNewService { |
|
|
|
|
|
|
|
private final SysParamsService sysParamsService; |
|
|
|
private final TsKvService tsKvService; |
|
|
|
private final IotThingEntityService thingEntityService; |
|
|
|
|
|
|
|
@Override |
|
|
|
public EnergyDayDataDTO getEachEnergy(String day) { |
|
|
|
EnergyDayDataDTO result = new EnergyDayDataDTO(); |
|
|
|
String month = day.substring(0, 7); |
|
|
|
//月时间 |
|
|
|
Long dayTime = DateTimeUtils.dateToStamp(month + "-01 00:00:00"); |
|
|
|
//当月结束时间戳 |
|
|
|
String monthEndTime = DateTimeUtils.getMonthEndTime(day); |
|
|
|
Long endTime = DateTimeUtils.convertTimeToLong(monthEndTime); |
|
|
|
//获取此租户编码 |
|
|
|
Long realTenantCode = UserContext.getRealTenantCode(); |
|
|
|
//查询这个月的 "总用电": "G01","总用水": "G03","总蒸汽": "G02","总压缩空气": "D_V0000151_1","天然气":"C2"用能情况 |
|
|
|
List<TsKvDTO> tsKvByCodeAndAttrs = tsKvService.findTsKvByCodeAndAttrs("CO_" + realTenantCode, Lists.newArrayList("A29mm", "B2mm", "E3mm", "D2mm","C2mm"), dayTime, endTime, true); |
|
|
|
if(CollectionUtil.isNotEmpty(tsKvByCodeAndAttrs)){ |
|
|
|
for (TsKvDTO tsKvDTO : tsKvByCodeAndAttrs) { |
|
|
|
String code = tsKvDTO.getThingCode(); |
|
|
|
String value = tsKvDTO.getVal(); |
|
|
|
if ("A29mm".equals(code)) { |
|
|
|
// 月用电量 |
|
|
|
result.setElectricDayValue(new BigDecimal(value).setScale(2, RoundingMode.HALF_UP)); |
|
|
|
} else if ("B2mm".equals(code)) { |
|
|
|
// 月用水量 |
|
|
|
result.setWaterDayValue(new BigDecimal(value).setScale(2, RoundingMode.HALF_UP)); |
|
|
|
} else if ("E3mm".equals(code)) { |
|
|
|
// 月蒸汽量 |
|
|
|
result.setSteamDayValue(new BigDecimal(value).setScale(2, RoundingMode.HALF_UP)); |
|
|
|
} else if ("D2mm".equals(code)) { |
|
|
|
// 月压缩空气量 |
|
|
|
result.setAirDayValue(new BigDecimal(value).setScale(2, RoundingMode.HALF_UP)); |
|
|
|
} else if ("C2mm".equals(code)) { |
|
|
|
// 月天然气用量 |
|
|
|
result.setGasDayValue(new BigDecimal(value).setScale(2, RoundingMode.HALF_UP)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public EnergyDataAnalyseDTO qcDayLoadAnalyse(String day) { |
|
|
|
public EnergyDayDataDTO getEachYearEnergy(String day) { |
|
|
|
EnergyDayDataDTO result = new EnergyDayDataDTO(); |
|
|
|
String year = day.substring(0, 4); |
|
|
|
//年时间 |
|
|
|
Long dayTime = DateTimeUtils.dateToStamp(year + "-01-01 00:00:00"); |
|
|
|
//当年结束时间戳 |
|
|
|
String yearEndTime = DateTimeUtils.getYearEndTime(day); |
|
|
|
Long endTime = DateTimeUtils.convertTimeToLong(yearEndTime); |
|
|
|
//获取此租户编码 |
|
|
|
Long realTenantCode = UserContext.getRealTenantCode(); |
|
|
|
|
|
|
|
//查询这一年的 "总用电": "G01","总用水": "G03","总蒸汽": "G02","总压缩空气": "D_V0000151_1","天然气":"C2"用能情况 |
|
|
|
List<TsKvDTO> tsKvByCodeAndAttrs = tsKvService.findTsKvByCodeAndAttrs("CO_" + realTenantCode, Lists.newArrayList("A29yy", "B2yy", "E3yy", "D2yy","C2yy"), dayTime, endTime, true); |
|
|
|
if(CollectionUtil.isNotEmpty(tsKvByCodeAndAttrs)){ |
|
|
|
for (TsKvDTO tsKvDTO : tsKvByCodeAndAttrs) { |
|
|
|
String code = tsKvDTO.getThingCode(); |
|
|
|
String value = tsKvDTO.getVal(); |
|
|
|
if ("A29yy".equals(code)) { |
|
|
|
// 年用电量 |
|
|
|
result.setElectricDayValue(new BigDecimal(value).setScale(2, RoundingMode.HALF_UP)); |
|
|
|
} else if ("B2yy".equals(code)) { |
|
|
|
// 年用水量 |
|
|
|
result.setWaterDayValue(new BigDecimal(value).setScale(2, RoundingMode.HALF_UP)); |
|
|
|
} else if ("E3yy".equals(code)) { |
|
|
|
// 年蒸汽量 |
|
|
|
result.setSteamDayValue(new BigDecimal(value).setScale(2, RoundingMode.HALF_UP)); |
|
|
|
} else if ("D2yy".equals(code)) { |
|
|
|
// 年压缩空气量 |
|
|
|
result.setAirDayValue(new BigDecimal(value).setScale(2, RoundingMode.HALF_UP)); |
|
|
|
} else if ("C2yy".equals(code)) { |
|
|
|
// 年天然气用量 |
|
|
|
result.setGasDayValue(new BigDecimal(value).setScale(2, RoundingMode.HALF_UP)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public EnergyDataAnalyseDTO qcMonthEnergyAnalyse(String month, String key, String type) { |
|
|
|
EnergyDataAnalyseDTO result = new EnergyDataAnalyseDTO(); |
|
|
|
List<EnergyDataAnalyseDetailDTO> currentMonthData = new ArrayList<>(); |
|
|
|
//当日开始结束时间 |
|
|
|
String dayStartTime = day + " 00:00:00"; |
|
|
|
String dayEndTime = day + " 23:59:59"; |
|
|
|
//将当月时间转换为时间戳 |
|
|
|
String dayStartTime = month + "-01 00:00:00"; |
|
|
|
String dayEndTime = getLastDayOfMonth(month); |
|
|
|
//将当月第一天时间转换为时间戳 |
|
|
|
Long dayStartTimeStamp = DateTimeUtils.dateToStamp(dayStartTime); |
|
|
|
//当月结束时间 |
|
|
|
Long dayEndTimeStamp = DateTimeUtils.dateToStamp(dayEndTime); |
|
|
|
|
|
|
|
List<String> attrs = new ArrayList<>(); |
|
|
|
if ("电".equals(type)) { |
|
|
|
attrs.add("A29dd"); |
|
|
|
} else if ("水".equals(type)) { |
|
|
|
attrs.add("B2dd"); |
|
|
|
} else if ("蒸汽".equals(type)) { |
|
|
|
attrs.add("E3dd"); |
|
|
|
} else if ("压缩空气".equals(type)) { |
|
|
|
attrs.add("D2dd"); |
|
|
|
} else if ("天然气".equals(type)) { |
|
|
|
attrs.add("C2dd"); |
|
|
|
} |
|
|
|
|
|
|
|
//获取租户编码 |
|
|
|
Long realTenantCode = UserContext.getRealTenantCode(); |
|
|
|
List<TsKvDTO> attr = tsKvService.findTsKvByCodeAndAttr("CO_" + realTenantCode, "A16", dayStartTimeStamp, dayEndTimeStamp, true); |
|
|
|
// 检查数据是否为空 |
|
|
|
if (CollectionUtil.isEmpty(attr)) { |
|
|
|
// 如果没有数据,返回错误 |
|
|
|
throw new SysException("没有找到电力负荷数据"); |
|
|
|
} |
|
|
|
for (TsKvDTO kv : attr) { |
|
|
|
List<TsKvDTO> tsKvByCodeAndAttrs = tsKvService.findTsKvByCodeAndAttrs("CO_" + realTenantCode, attrs, dayStartTimeStamp, dayEndTimeStamp, true); |
|
|
|
if (CollectionUtil.isNotEmpty(tsKvByCodeAndAttrs)) { |
|
|
|
for (TsKvDTO kv : tsKvByCodeAndAttrs) { |
|
|
|
// 获取时间戳 |
|
|
|
Long timestamp = kv.getTs(); |
|
|
|
// 电力负荷值 |
|
|
|
//获取值 |
|
|
|
String value = kv.getVal(); |
|
|
|
// 将时间戳转换为日期格式 |
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
|
String timestampStr = sdf.format(new Date(timestamp)); |
|
|
|
// 填充电力负荷数据 |
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
String date = sdf.format(new Date(timestamp)); |
|
|
|
EnergyDataAnalyseDetailDTO detailDTO = new EnergyDataAnalyseDetailDTO(); |
|
|
|
// 设置时间 |
|
|
|
detailDTO.setDate(timestampStr); |
|
|
|
// 设置电力负荷值 |
|
|
|
detailDTO.setDate(date); |
|
|
|
detailDTO.setValue(new BigDecimal(value)); |
|
|
|
currentMonthData.add(detailDTO); |
|
|
|
} |
|
|
|
result.setCurrentMonthData(currentMonthData); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// /** |
|
|
|
// * 参数格式:{"总用电": "G01","总用水": "G03","总蒸汽": "G02","总压缩空气": "D_V0000151_1"} |
|
|
|
// */ |
|
|
|
// String cqStr = sysParamsService.getValue("BOARD_TOTAL_ENERGY"); |
|
|
|
// Map<String, String> codeMap = JSONObject.parseObject(cqStr, Map.class); |
|
|
|
// List<String> keys = new ArrayList<>(); |
|
|
|
// keys.add("A16"); |
|
|
|
//注释说明:获取电表在所传时间内A16属性的数据,该接口传的是天的时间,A16表示电负荷, todo |
|
|
|
// ThingsDTO thingsDTO = thingsService.getThingsByCode(codeMap.get("总用电")); |
|
|
|
// if(thingsDTO==null && StringUtils.isBlank(thingsDTO.getEntityId())){ |
|
|
|
// return result; |
|
|
|
// } |
|
|
|
// //当天 |
|
|
|
// DeviceId deviceId = new DeviceId(UUID.fromString(thingsDTO.getEntityId())); |
|
|
|
// List<TsKvEntry> currentTsKvEntries = newRestClientUtils.getTimeseries(deviceId,keys,dayStartTimeStamp-1000L,dayEndTimeStamp,true); |
|
|
|
// if (CollectionUtil.isNotEmpty(currentTsKvEntries)) { |
|
|
|
// for (TsKvEntry tsKvEntry:currentTsKvEntries){ |
|
|
|
// EnergyDataAnalyseDetailDTO energyDataAnalyseDetailDTO = new EnergyDataAnalyseDetailDTO(); |
|
|
|
// energyDataAnalyseDetailDTO.setDate(DateTimeUtils.timestampToDate(tsKvEntry.getTs(),DateTimeUtils.DATE_TIME_PATTERN_STR)); |
|
|
|
// energyDataAnalyseDetailDTO.setValue(new BigDecimal(tsKvEntry.getValue().toString())); |
|
|
|
// currentMonthData.add(energyDataAnalyseDetailDTO); |
|
|
|
// } |
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public EnergyConsumptionDataDTO getEnergyConsumption(String day) { |
|
|
|
EnergyConsumptionDataDTO result = new EnergyConsumptionDataDTO(); |
|
|
|
//日时间 |
|
|
|
Long dayTime = DateTimeUtils.dateToStamp(day + " 00:00:00"); |
|
|
|
//月时间 |
|
|
|
Long monthTime = DateTimeUtils.dateToStamp(day.substring(0, 7) + "-01 00:00:00"); |
|
|
|
//年时间 |
|
|
|
Long yearTime = DateTimeUtils.dateToStamp(day.substring(0, 4) + "-01-01 00:00:00"); |
|
|
|
BigDecimal totalDayValue = BigDecimal.ZERO; |
|
|
|
BigDecimal totalMonthValue = BigDecimal.ZERO; |
|
|
|
BigDecimal totalYearValue = BigDecimal.ZERO; |
|
|
|
/** |
|
|
|
* 总code :参数格式:{"总用电": "G01","总用水": "G03","总蒸汽": "G02","总压缩空气": "D_V0000151_1"} |
|
|
|
*/ |
|
|
|
String cqStr = sysParamsService.getValue("BOARD_TOTAL_ENERGY"); |
|
|
|
Map<String, String> codeMap = new HashMap<>(); |
|
|
|
codeMap = JSONObject.parseObject(cqStr, Map.class); |
|
|
|
|
|
|
|
// SysDeptEntity dept = sysDeptService.getDeptVaildPermission((Long) null); |
|
|
|
//获取折标煤系数,这边需要调整,物管理获取折标煤系数的地方 todo |
|
|
|
Map<String, BigDecimal> coalRatio = new HashMap<>(); |
|
|
|
// List<PowerCoalRatioEntity> powerCoalRatioList = getPowerCoalRatioList(dept.getTenantCode(), dept.getId()); |
|
|
|
// if (CollectionUtils.isNotEmpty(powerCoalRatioList)){ |
|
|
|
// for (PowerCoalRatioEntity powerCoalRatioEntity:powerCoalRatioList){ |
|
|
|
// coalRatio.put(powerCoalRatioEntity.getPowerTypeCode(),powerCoalRatioEntity.getCoalRatio()); |
|
|
|
// } |
|
|
|
// } |
|
|
|
|
|
|
|
for (Map.Entry<String, String> entry : codeMap.entrySet()) { |
|
|
|
if (entry.getKey().equals("总用水")) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
BigDecimal coalRatioValue = null; |
|
|
|
List<String> keys = new ArrayList<>(); |
|
|
|
List<String> keys1 = new ArrayList<>(); |
|
|
|
List<String> keys2 = new ArrayList<>(); |
|
|
|
if (entry.getKey().equals("总用电")) { |
|
|
|
coalRatioValue = coalRatio.get("A"); |
|
|
|
keys.add("A29dd"); |
|
|
|
keys1.add("A29mm"); |
|
|
|
keys2.add("A29yy"); |
|
|
|
} else if (entry.getKey().equals("总蒸汽")) { |
|
|
|
coalRatioValue = coalRatio.get("E"); |
|
|
|
keys.add("E3dd"); |
|
|
|
keys1.add("E3mm"); |
|
|
|
keys2.add("E3yy"); |
|
|
|
} else if (entry.getKey().equals("总压缩空气")) { |
|
|
|
coalRatioValue = coalRatio.get("D"); |
|
|
|
keys.add("D2dd"); |
|
|
|
keys1.add("D2mm"); |
|
|
|
keys2.add("D2yy"); |
|
|
|
} |
|
|
|
/** |
|
|
|
* todo 获取各用能数据 |
|
|
|
*/ |
|
|
|
// ThingsDTO thingsDTO = thingsService.getThingsByCode(entry.getValue()); |
|
|
|
// if (thingsDTO!=null && StringUtils.isNotBlank(thingsDTO.getEntityId())){ |
|
|
|
// DeviceId deviceId = new DeviceId(UUID.fromString(thingsDTO.getEntityId())); |
|
|
|
// List<TsKvEntry> dayTsKvEntries = newRestClientUtils.getTimeseries(deviceId,keys,dayTime-5*60000L,dayTime+5*60000L,true); |
|
|
|
// if (CollectionUtil.isNotEmpty(dayTsKvEntries)){ |
|
|
|
// TsKvEntry tsKvEntry = dayTsKvEntries.get(0); |
|
|
|
// if (tsKvEntry.getValue()!=null && coalRatioValue!=null){ |
|
|
|
// BigDecimal value = new BigDecimal(tsKvEntry.getValue().toString()); |
|
|
|
// if (value!=null){ |
|
|
|
// BigDecimal dayConsumptionValue = value.multiply(coalRatioValue).setScale(2,BigDecimal.ROUND_HALF_UP); |
|
|
|
// totalDayValue = totalDayValue.add(dayConsumptionValue); |
|
|
|
// } |
|
|
|
// } |
|
|
|
// } |
|
|
|
// //当月 |
|
|
|
// List<TsKvEntry> monthTsKvEntries = newRestClientUtils.getTimeseries(deviceId,keys1,monthTime-5*60000L,monthTime+5*60000L,true); |
|
|
|
// if (CollectionUtil.isNotEmpty(monthTsKvEntries)){ |
|
|
|
// TsKvEntry tsKvEntry = monthTsKvEntries.get(0); |
|
|
|
// if (tsKvEntry.getValue()!=null && coalRatioValue!=null){ |
|
|
|
// BigDecimal value = new BigDecimal(tsKvEntry.getValue().toString()); |
|
|
|
// if (value!=null){ |
|
|
|
// BigDecimal monthConsumptionValue = value.multiply(coalRatioValue).setScale(2,BigDecimal.ROUND_HALF_UP); |
|
|
|
// totalMonthValue = totalMonthValue.add(monthConsumptionValue); |
|
|
|
// } |
|
|
|
// } |
|
|
|
// } |
|
|
|
// //当年 |
|
|
|
// List<TsKvEntry> yearTsKvEntries = newRestClientUtils.getTimeseries(deviceId,keys2,yearTime-5*60000L,yearTime+5*60000L,true); |
|
|
|
// if (CollectionUtil.isNotEmpty(yearTsKvEntries)){ |
|
|
|
// TsKvEntry tsKvEntry = yearTsKvEntries.get(0); |
|
|
|
// if (tsKvEntry.getValue()!=null && coalRatioValue!=null){ |
|
|
|
// BigDecimal value = new BigDecimal(tsKvEntry.getValue().toString()); |
|
|
|
// if (value!=null){ |
|
|
|
// BigDecimal yearConsumptionValue = value.multiply(coalRatioValue).setScale(2,BigDecimal.ROUND_HALF_UP); |
|
|
|
// totalYearValue = totalYearValue.add(yearConsumptionValue); |
|
|
|
// } |
|
|
|
// } |
|
|
|
// } |
|
|
|
// } |
|
|
|
} |
|
|
|
result.setDayValue(totalDayValue); |
|
|
|
result.setMonthValue(totalMonthValue); |
|
|
|
result.setYearValue(totalYearValue); |
|
|
|
// 将当前月的数据填充到result中 |
|
|
|
result.setCurrentMonthData(currentMonthData); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public CarbonAndConsumptionDataDTO getCarbonAndConsumption(String day) { |
|
|
|
CarbonAndConsumptionDataDTO result = new CarbonAndConsumptionDataDTO(); |
|
|
|
//日时间 |
|
|
|
Long dayTime = DateTimeUtils.dateToStamp(day + " 00:00:00"); |
|
|
|
Long lastDayTime = dayTime - 24 * 60 * 60 * 1000L; |
|
|
|
//月时间 |
|
|
|
Long monthTime = DateTimeUtils.dateToStamp(day.substring(0, 7) + "-01 00:00:00"); |
|
|
|
//年时间 |
|
|
|
Long yearTime = DateTimeUtils.dateToStamp(day.substring(0, 4) + "-01-01 00:00:00"); |
|
|
|
BigDecimal totalDayCarbonValue = BigDecimal.ZERO; |
|
|
|
BigDecimal totalDayConsumtionValue = BigDecimal.ZERO; |
|
|
|
BigDecimal totalMonthConsumtionValue = BigDecimal.ZERO; |
|
|
|
BigDecimal totalYearConsumtionValue = BigDecimal.ZERO; |
|
|
|
BigDecimal totalYearCarbonValue = BigDecimal.ZERO; |
|
|
|
/** |
|
|
|
* 总code :参数格式:{"总用电": "G01","总用水": "G03","总蒸汽": "G02","总压缩空气": "D_V0000151_1"} |
|
|
|
*/ |
|
|
|
String cqStr = sysParamsService.getValue("BOARD_TOTAL_ENERGY"); |
|
|
|
Map<String, String> codeMap = new HashMap<>(); |
|
|
|
codeMap = JSONObject.parseObject(cqStr, Map.class); |
|
|
|
|
|
|
|
Map<String, BigDecimal> coalRatio = new HashMap<>(); |
|
|
|
/** |
|
|
|
* 获取折标煤系数,这边需要调整,物管理获取折标煤系数的地方 todo |
|
|
|
*/ |
|
|
|
// SysDeptEntity dept = sysDeptService.getDeptVaildPermission((Long) null); |
|
|
|
// //获取折标煤系数 |
|
|
|
// List<PowerCoalRatioEntity> powerCoalRatioList = getPowerCoalRatioList(dept.getTenantCode(), dept.getId()); |
|
|
|
// if (CollectionUtils.isNotEmpty(powerCoalRatioList)){ |
|
|
|
// for (PowerCoalRatioEntity powerCoalRatioEntity:powerCoalRatioList){ |
|
|
|
// coalRatio.put(powerCoalRatioEntity.getPowerTypeCode(),powerCoalRatioEntity.getCoalRatio()); |
|
|
|
// } |
|
|
|
// } |
|
|
|
|
|
|
|
for (Map.Entry<String, String> entry : codeMap.entrySet()) { |
|
|
|
if (entry.getKey().equals("总用水")) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
BigDecimal coalRatioValue = null; |
|
|
|
List<String> keys = new ArrayList<>(); |
|
|
|
List<String> keys1 = new ArrayList<>(); |
|
|
|
List<String> keys2 = new ArrayList<>(); |
|
|
|
if (entry.getKey().equals("总用电")) { |
|
|
|
coalRatioValue = coalRatio.get("A"); |
|
|
|
keys.add("A29dd"); |
|
|
|
keys1.add("A29mm"); |
|
|
|
keys2.add("A29yy"); |
|
|
|
} else if (entry.getKey().equals("总蒸汽")) { |
|
|
|
coalRatioValue = coalRatio.get("E"); |
|
|
|
keys.add("E3dd"); |
|
|
|
keys1.add("E3mm"); |
|
|
|
keys2.add("E3yy"); |
|
|
|
} else if (entry.getKey().equals("总压缩空气")) { |
|
|
|
coalRatioValue = coalRatio.get("D"); |
|
|
|
keys.add("D2dd"); |
|
|
|
keys1.add("D2mm"); |
|
|
|
keys2.add("D2yy"); |
|
|
|
} |
|
|
|
//获取各用能数据 |
|
|
|
// ThingsDTO thingsDTO = thingsService.getThingsByCode(entry.getValue()); |
|
|
|
// if (thingsDTO!=null && StringUtils.isNotBlank(thingsDTO.getEntityId())){ |
|
|
|
// DeviceId deviceId = new DeviceId(UUID.fromString(thingsDTO.getEntityId())); |
|
|
|
// List<TsKvEntry> dayTsKvEntries = newRestClientUtils.getTimeseries(deviceId,keys,lastDayTime-5*60000L,lastDayTime+5*60000L,true); |
|
|
|
// if (CollectionUtil.isNotEmpty(dayTsKvEntries)){ |
|
|
|
// TsKvEntry tsKvEntry = dayTsKvEntries.get(0); |
|
|
|
// if (tsKvEntry.getValue()!=null && coalRatioValue!=null){ |
|
|
|
// BigDecimal value = new BigDecimal(tsKvEntry.getValue().toString()); |
|
|
|
// if (value!=null){ |
|
|
|
// BigDecimal dayConsumptionValue = value.multiply(coalRatioValue).setScale(2,BigDecimal.ROUND_HALF_UP); |
|
|
|
// totalDayConsumtionValue = totalDayConsumtionValue.add(dayConsumptionValue); |
|
|
|
// BigDecimal dayCarbonValue = dayConsumptionValue.multiply(new BigDecimal("2.493")); |
|
|
|
// totalDayCarbonValue = totalDayCarbonValue.add(dayCarbonValue); |
|
|
|
// } |
|
|
|
// } |
|
|
|
// } |
|
|
|
// //当月 |
|
|
|
// List<TsKvEntry> monthTsKvEntries = newRestClientUtils.getTimeseries(deviceId,keys1,monthTime-5*60000L,monthTime+5*60000L,true); |
|
|
|
// if (CollectionUtil.isNotEmpty(monthTsKvEntries)){ |
|
|
|
// TsKvEntry tsKvEntry = monthTsKvEntries.get(0); |
|
|
|
// if (tsKvEntry.getValue()!=null && coalRatioValue!=null){ |
|
|
|
// BigDecimal value = new BigDecimal(tsKvEntry.getValue().toString()); |
|
|
|
// if (value!=null){ |
|
|
|
// BigDecimal monthConsumptionValue = value.multiply(coalRatioValue).setScale(2,BigDecimal.ROUND_HALF_UP); |
|
|
|
// totalMonthConsumtionValue = totalMonthConsumtionValue.add(monthConsumptionValue); |
|
|
|
// } |
|
|
|
// } |
|
|
|
// } |
|
|
|
// List<TsKvEntry> yearTsKvEntries = newRestClientUtils.getTimeseries(deviceId,keys2,yearTime-5*60000L,yearTime+5*60000L,true); |
|
|
|
// if (CollectionUtil.isNotEmpty(yearTsKvEntries)){ |
|
|
|
// TsKvEntry tsKvEntry = yearTsKvEntries.get(0); |
|
|
|
// if (tsKvEntry.getValue()!=null && coalRatioValue!=null){ |
|
|
|
// BigDecimal value = new BigDecimal(tsKvEntry.getValue().toString()); |
|
|
|
// if (value!=null){ |
|
|
|
// BigDecimal yearConsumptionValue = value.multiply(coalRatioValue).setScale(2,BigDecimal.ROUND_HALF_UP); |
|
|
|
// totalYearConsumtionValue = totalYearConsumtionValue.add(yearConsumptionValue); |
|
|
|
// BigDecimal yearCarbonValue = yearConsumptionValue.multiply(new BigDecimal("2.493")); |
|
|
|
// totalYearCarbonValue = totalYearCarbonValue.add(yearCarbonValue); |
|
|
|
// } |
|
|
|
// } |
|
|
|
// } |
|
|
|
// } |
|
|
|
} |
|
|
|
result.setDayCarbon(totalDayCarbonValue.setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
|
|
result.setDayConsumptionValue(totalDayConsumtionValue.setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
|
|
result.setMonthConsumptionValue(totalMonthConsumtionValue.setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
|
|
result.setYearCarbon(totalYearCarbonValue.setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
|
|
result.setYearConsumptionValue(totalYearConsumtionValue.setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<EnergyCostProportionDataDTO> getEnergyCost(String day) { |
|
|
|
@ -377,231 +220,168 @@ public class BoardNewServiceImpl implements BoardNewService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<EnergyDataDTO> getMonthEnergyRanking(String month, String key, String type) { |
|
|
|
List<EnergyDataDTO> result = new ArrayList<>(); |
|
|
|
//月数据 |
|
|
|
String dayStartTime = month + "-01 00:00:00"; |
|
|
|
Long dayStartTimeStamp = DateTimeUtils.dateToStamp(dayStartTime); |
|
|
|
Long dayEndTimeStamp = dayStartTimeStamp + 5 * 60 * 1000; |
|
|
|
/** |
|
|
|
* 排行表 :参数格式:["D_V0000151_3","D_V0000151_4","D_V0000151_2","E_V0000151_7"] |
|
|
|
*/ |
|
|
|
String codeStr = sysParamsService.getValue("BOARD_ENERGY_RANKING"); |
|
|
|
List<String> codeList = JSONObject.parseArray(codeStr, String.class); |
|
|
|
List<String> keys = new ArrayList<>(); |
|
|
|
keys.add(key); |
|
|
|
/** |
|
|
|
* todo 获取各表的数据 |
|
|
|
*/ |
|
|
|
// List<ThingsDTO> things = thingsDao.getByCodes(codeList); |
|
|
|
// if(CollectionUtil.isEmpty(things)){ |
|
|
|
// return result; |
|
|
|
// } |
|
|
|
// for (ThingsDTO thingsDTO : things){ |
|
|
|
// EnergyDataDTO energyDataDTO = new EnergyDataDTO(); |
|
|
|
// energyDataDTO.setThingName(thingsDTO.getName()); |
|
|
|
// List<TsKvEntry> tsKvEntries = newRestClientUtils.getTimeseries(thingsDTO.getEntityId(),keys,dayStartTimeStamp-1000L,dayEndTimeStamp); |
|
|
|
// if (CollectionUtil.isEmpty(tsKvEntries)) { |
|
|
|
// continue; |
|
|
|
// } |
|
|
|
// BigDecimal value = new BigDecimal(tsKvEntries.get(0).getValue().toString()); |
|
|
|
// if (value !=null){ |
|
|
|
// energyDataDTO.setValue(value.setScale(2,BigDecimal.ROUND_HALF_UP)); |
|
|
|
// } |
|
|
|
// result.add(energyDataDTO); |
|
|
|
// } |
|
|
|
|
|
|
|
result = result.stream() |
|
|
|
.sorted(Comparator.comparing(EnergyDataDTO::getValue, Comparator.nullsLast(Comparator.reverseOrder()))) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static String getLastDayOfMonth(String month) { |
|
|
|
String fullDateString = month + "-01"; |
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
|
|
|
LocalDate date = LocalDate.parse(fullDateString, formatter); |
|
|
|
|
|
|
|
// 获取该月的最后一天 |
|
|
|
LocalDate lastDayOfMonth = date.withDayOfMonth(date.lengthOfMonth()); |
|
|
|
|
|
|
|
// 设置最后一天的时间为 23:59:59 |
|
|
|
LocalDateTime lastMomentOfMonth = lastDayOfMonth.atTime(23, 59, 59); |
|
|
|
|
|
|
|
// 返回结果的字符串,格式为 "yyyy-MM-dd HH:mm:ss" |
|
|
|
return lastMomentOfMonth.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public EnergyDataAnalyseDTO qcMonthEnergyAnalyse(String month, String key, String type) { |
|
|
|
public EnergyDataAnalyseDTO qcDayLoadAnalyse(String day) { |
|
|
|
EnergyDataAnalyseDTO result = new EnergyDataAnalyseDTO(); |
|
|
|
List<EnergyDataAnalyseDetailDTO> currentMonthData = new ArrayList<>(); |
|
|
|
//当日开始结束时间 |
|
|
|
String dayStartTime = month + "-01 00:00:00"; |
|
|
|
String dayEndTime = getLastDayOfMonth(month); |
|
|
|
//将当月第一天时间转换为时间戳 |
|
|
|
String dayStartTime = day + " 00:00:00"; |
|
|
|
String dayEndTime = day + " 23:59:59"; |
|
|
|
//将当月时间转换为时间戳 |
|
|
|
Long dayStartTimeStamp = DateTimeUtils.dateToStamp(dayStartTime); |
|
|
|
//当月结束时间 |
|
|
|
Long dayEndTimeStamp = DateTimeUtils.dateToStamp(dayEndTime); |
|
|
|
|
|
|
|
List<String> attrs = new ArrayList<>(); |
|
|
|
if ("电".equals(type)) { |
|
|
|
attrs.add("A29dd"); |
|
|
|
} else if ("水".equals(type)) { |
|
|
|
attrs.add("B2dd"); |
|
|
|
} else if ("蒸汽".equals(type)) { |
|
|
|
attrs.add("E3dd"); |
|
|
|
} else if ("压缩空气".equals(type)) { |
|
|
|
attrs.add("D2dd"); |
|
|
|
} else if ("天然气".equals(type)) { |
|
|
|
attrs.add("C2dd"); |
|
|
|
} |
|
|
|
|
|
|
|
//获取租户编码 |
|
|
|
Long realTenantCode = UserContext.getRealTenantCode(); |
|
|
|
List<TsKvDTO> tsKvByCodeAndAttrs = tsKvService.findTsKvByCodeAndAttrs("CO_" + realTenantCode, attrs, dayStartTimeStamp, dayEndTimeStamp, true); |
|
|
|
if (CollectionUtil.isNotEmpty(tsKvByCodeAndAttrs)) { |
|
|
|
for (TsKvDTO kv : tsKvByCodeAndAttrs) { |
|
|
|
List<TsKvDTO> attr = tsKvService.findTsKvByCodeAndAttr("CO_" + realTenantCode, "A16", dayStartTimeStamp, dayEndTimeStamp, true); |
|
|
|
// 检查数据是否为空 |
|
|
|
if (CollectionUtil.isEmpty(attr)) { |
|
|
|
// 如果没有数据,返回错误 |
|
|
|
throw new SysException("没有找到电力负荷数据"); |
|
|
|
} |
|
|
|
for (TsKvDTO kv : attr) { |
|
|
|
// 获取时间戳 |
|
|
|
Long timestamp = kv.getTs(); |
|
|
|
//获取值 |
|
|
|
// 电力负荷值 |
|
|
|
String value = kv.getVal(); |
|
|
|
|
|
|
|
// 将时间戳转换为日期格式 |
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
String date = sdf.format(new Date(timestamp)); |
|
|
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
|
String timestampStr = sdf.format(new Date(timestamp)); |
|
|
|
// 填充电力负荷数据 |
|
|
|
EnergyDataAnalyseDetailDTO detailDTO = new EnergyDataAnalyseDetailDTO(); |
|
|
|
detailDTO.setDate(date); |
|
|
|
// 设置时间 |
|
|
|
detailDTO.setDate(timestampStr); |
|
|
|
// 设置电力负荷值 |
|
|
|
detailDTO.setValue(new BigDecimal(value)); |
|
|
|
currentMonthData.add(detailDTO); |
|
|
|
} |
|
|
|
} |
|
|
|
// 将当前月的数据填充到result中 |
|
|
|
result.setCurrentMonthData(currentMonthData); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public CarbonAndConsumptionDataDTO getCarbonAndConsumption(String day) { |
|
|
|
CarbonAndConsumptionDataDTO result = new CarbonAndConsumptionDataDTO(); |
|
|
|
//日时间 |
|
|
|
//Long dayTime = DateTimeUtils.dateToStamp(day + " 00:00:00"); |
|
|
|
//月时间 |
|
|
|
Long monthDayTime = DateTimeUtils.dateToStamp(day.substring(0, 7) + "-01 00:00:00"); |
|
|
|
//月结束时间 |
|
|
|
Long monthEndTime = DateTimeUtils.convertTimeToLong(DateTimeUtils.getMonthEndTime(day)); |
|
|
|
//年时间 |
|
|
|
Long yearStartTime = DateTimeUtils.dateToStamp(day.substring(0, 4) + "-01-01 00:00:00"); |
|
|
|
//年结束时间 |
|
|
|
Long yearEndTime = DateTimeUtils.convertTimeToLong(DateTimeUtils.getYearEndTime(day)); |
|
|
|
|
|
|
|
//查询电,蒸汽,总压缩空气的用量 |
|
|
|
//月能耗 |
|
|
|
List<TsKvDTO> tsKvMonth = tsKvService.findTsKvByCodeAndAttrs("CO_" + UserContext.getRealTenantCode(), Lists.newArrayList("A29dd", "E3mm", "D2mm"), monthDayTime, monthEndTime, true); |
|
|
|
List<TsKvDTO> tsKvYear = tsKvService.findTsKvByCodeAndAttrs("CO_" + UserContext.getRealTenantCode(), Lists.newArrayList("A29yy", "E3yy", "D2yy"), yearStartTime, yearEndTime, true); |
|
|
|
|
|
|
|
// /** |
|
|
|
// * 总code :参数格式:{"总用电": "G01","总用水": "G03","总蒸汽": "G02","总压缩空气": "D_V0000151_1"} |
|
|
|
// */ |
|
|
|
// String cqStr = sysParamsService.getValue("BOARD_TOTAL_ENERGY"); |
|
|
|
// |
|
|
|
// Map<String, String> codeMap = JSONObject.parseObject(cqStr, Map.class); |
|
|
|
// List<String> keys = new ArrayList<>(); |
|
|
|
// keys.add(key); |
|
|
|
// String code = null; |
|
|
|
// if ("电".equals(type)) { |
|
|
|
// code = codeMap.get("总用电"); |
|
|
|
// } else if ("水".equals(type)) { |
|
|
|
// code = codeMap.get("总用水"); |
|
|
|
// } else if ("蒸汽".equals(type)) { |
|
|
|
// code = codeMap.get("总蒸汽"); |
|
|
|
// } else if ("压缩空气".equals(type)) { |
|
|
|
// code = codeMap.get("总压缩空气"); |
|
|
|
// } |
|
|
|
// /** |
|
|
|
// * todo 获取各用能数据 |
|
|
|
// */ |
|
|
|
// ThingsDTO thingsDTO = thingsService.getThingsByCode(code); |
|
|
|
// if(thingsDTO==null && StringUtils.isBlank(thingsDTO.getEntityId())){ |
|
|
|
// return result; |
|
|
|
// } |
|
|
|
// //当月 |
|
|
|
// DeviceId deviceId = new DeviceId(UUID.fromString(thingsDTO.getEntityId())); |
|
|
|
// List<TsKvEntry> currentTsKvEntries = newRestClientUtils.getTimeseries(deviceId,keys,dayStartTimeStamp-1000L,dayEndTimeStamp,true); |
|
|
|
// if (CollectionUtil.isNotEmpty(currentTsKvEntries)) { |
|
|
|
// for (TsKvEntry tsKvEntry:currentTsKvEntries){ |
|
|
|
// EnergyDataAnalyseDetailDTO energyDataAnalyseDetailDTO = new EnergyDataAnalyseDetailDTO(); |
|
|
|
// energyDataAnalyseDetailDTO.setDate(DateUtils.timeStamp2Date(String.valueOf(tsKvEntry.getTs()),DateUtils.DATE_TIME_PATTERN)); |
|
|
|
// if (tsKvEntry.getValue()!=null){ |
|
|
|
// energyDataAnalyseDetailDTO.setValue(new BigDecimal(tsKvEntry.getValue().toString()).setScale(2,BigDecimal.ROUND_HALF_UP)); |
|
|
|
// } |
|
|
|
// currentMonthData.add(energyDataAnalyseDetailDTO); |
|
|
|
// } |
|
|
|
// } |
|
|
|
if(CollectionUtil.isNotEmpty(tsKvMonth)){ |
|
|
|
BigDecimal totalValueA29 = BigDecimal.ZERO; |
|
|
|
BigDecimal totalValueE3 = BigDecimal.ZERO; |
|
|
|
BigDecimal totalValueD2 = BigDecimal.ZERO; |
|
|
|
|
|
|
|
@Override |
|
|
|
public EnergyDayDataDTO getEachEnergy(String day) { |
|
|
|
EnergyDayDataDTO result = new EnergyDayDataDTO(); |
|
|
|
String month = day.substring(0, 7); |
|
|
|
//月时间 |
|
|
|
Long dayTime = DateTimeUtils.dateToStamp(month + "-01 00:00:00"); |
|
|
|
//当月结束时间戳 |
|
|
|
String monthEndTime = DateTimeUtils.getMonthEndTime(day); |
|
|
|
Long endTime = DateTimeUtils.convertTimeToLong(monthEndTime); |
|
|
|
//获取此租户编码 |
|
|
|
Long realTenantCode = UserContext.getRealTenantCode(); |
|
|
|
//查询这个月的 "总用电": "G01","总用水": "G03","总蒸汽": "G02","总压缩空气": "D_V0000151_1","天然气":"C2"用能情况 |
|
|
|
List<TsKvDTO> tsKvByCodeAndAttrs = tsKvService.findTsKvByCodeAndAttrs("CO_" + realTenantCode, Lists.newArrayList("G01", "G03", "G02", "D_V0000151_1","C2"), dayTime, endTime, true); |
|
|
|
if(CollectionUtil.isNotEmpty(tsKvByCodeAndAttrs)){ |
|
|
|
for (TsKvDTO tsKvDTO : tsKvByCodeAndAttrs) { |
|
|
|
String code = tsKvDTO.getThingCode(); |
|
|
|
String value = tsKvDTO.getVal(); |
|
|
|
if ("G01".equals(code)) { |
|
|
|
// 月用电量 |
|
|
|
result.setElectricDayValue(new BigDecimal(value).setScale(2, RoundingMode.HALF_UP)); |
|
|
|
} else if ("G03".equals(code)) { |
|
|
|
// 月用水量 |
|
|
|
result.setWaterDayValue(new BigDecimal(value).setScale(2, RoundingMode.HALF_UP)); |
|
|
|
} else if ("G02".equals(code)) { |
|
|
|
// 月蒸汽量 |
|
|
|
result.setSteamDayValue(new BigDecimal(value).setScale(2, RoundingMode.HALF_UP)); |
|
|
|
} else if ("D_V0000151_1".equals(code)) { |
|
|
|
// 月压缩空气量 |
|
|
|
result.setAirDayValue(new BigDecimal(value).setScale(2, RoundingMode.HALF_UP)); |
|
|
|
} else if ("C2".equals(code)) { |
|
|
|
// 月天然气用量 |
|
|
|
result.setGasDayValue(new BigDecimal(value).setScale(2, RoundingMode.HALF_UP)); |
|
|
|
List<TsKvDTO> listA29 = tsKvMonth.stream().filter(tsKvDTO -> StringUtils.equals("A29mm", tsKvDTO.getAttrKey())).toList(); |
|
|
|
List<TsKvDTO> listD2 = tsKvMonth.stream().filter(tsKvDTO -> StringUtils.equals("D2mm", tsKvDTO.getAttrKey())).toList(); |
|
|
|
List<TsKvDTO> listE3 = tsKvMonth.stream().filter(tsKvDTO -> StringUtils.equals("E3mm", tsKvDTO.getAttrKey())).toList(); |
|
|
|
if(CollectionUtil.isNotEmpty(listA29)){ |
|
|
|
BigDecimal reduce = listA29.stream().map(v -> new BigDecimal(v.getVal())).reduce(BigDecimal.ZERO, BigDecimal::add); |
|
|
|
totalValueA29 = reduce.multiply(new BigDecimal("0.1229")).divide(new BigDecimal("1000"),2,RoundingMode.HALF_UP); |
|
|
|
} |
|
|
|
if(CollectionUtil.isNotEmpty(listD2)){ |
|
|
|
BigDecimal reduce = listD2.stream().map(v -> new BigDecimal(v.getVal())).reduce(BigDecimal.ZERO, BigDecimal::add); |
|
|
|
totalValueD2 = reduce.multiply(new BigDecimal("0.2571")).divide(new BigDecimal("1000"),2,RoundingMode.HALF_UP); |
|
|
|
} |
|
|
|
if(CollectionUtil.isNotEmpty(listE3)){ |
|
|
|
BigDecimal reduce = listE3.stream().map(v -> new BigDecimal(v.getVal())).reduce(BigDecimal.ZERO, BigDecimal::add); |
|
|
|
totalValueE3 = reduce.multiply(new BigDecimal("1.2143")).divide(new BigDecimal("1000"),2,RoundingMode.HALF_UP); |
|
|
|
} |
|
|
|
//月综合能耗 |
|
|
|
result.setMonthConsumptionValue(totalValueA29.add(totalValueD2).add(totalValueE3)); |
|
|
|
} |
|
|
|
|
|
|
|
if(CollectionUtil.isNotEmpty(tsKvYear)){ |
|
|
|
BigDecimal totalValueA29 = BigDecimal.ZERO; |
|
|
|
BigDecimal totalValueE3 = BigDecimal.ZERO; |
|
|
|
BigDecimal totalValueD2 = BigDecimal.ZERO; |
|
|
|
BigDecimal total = BigDecimal.ZERO; |
|
|
|
|
|
|
|
List<TsKvDTO> listA29 = tsKvYear.stream().filter(tsKvDTO -> StringUtils.equals("A29yy", tsKvDTO.getAttrKey())).toList(); |
|
|
|
List<TsKvDTO> listD2 = tsKvYear.stream().filter(tsKvDTO -> StringUtils.equals("D2yy", tsKvDTO.getAttrKey())).toList(); |
|
|
|
List<TsKvDTO> listE3 = tsKvYear.stream().filter(tsKvDTO -> StringUtils.equals("E3yy", tsKvDTO.getAttrKey())).toList(); |
|
|
|
if(CollectionUtil.isNotEmpty(listA29)){ |
|
|
|
BigDecimal reduce = listA29.stream().map(v -> new BigDecimal(v.getVal())).reduce(BigDecimal.ZERO, BigDecimal::add); |
|
|
|
totalValueA29 = reduce.multiply(new BigDecimal("0.1229")).divide(new BigDecimal("1000"),2,RoundingMode.HALF_UP); |
|
|
|
total = total.add(reduce); |
|
|
|
} |
|
|
|
if(CollectionUtil.isNotEmpty(listD2)){ |
|
|
|
BigDecimal reduce = listD2.stream().map(v -> new BigDecimal(v.getVal())).reduce(BigDecimal.ZERO, BigDecimal::add); |
|
|
|
totalValueD2 = reduce.multiply(new BigDecimal("0.2571")).divide(new BigDecimal("1000"),2,RoundingMode.HALF_UP); |
|
|
|
total = total.add(reduce); |
|
|
|
} |
|
|
|
if(CollectionUtil.isNotEmpty(listE3)){ |
|
|
|
BigDecimal reduce = listE3.stream().map(v -> new BigDecimal(v.getVal())).reduce(BigDecimal.ZERO, BigDecimal::add); |
|
|
|
totalValueE3 = reduce.multiply(new BigDecimal("1.2143")).divide(new BigDecimal("1000"),2,RoundingMode.HALF_UP); |
|
|
|
total = total.add(reduce); |
|
|
|
} |
|
|
|
//年综合能耗 |
|
|
|
result.setYearConsumptionValue(totalValueA29.add(totalValueD2).add(totalValueE3)); |
|
|
|
result.setYearCarbon(total.multiply(new BigDecimal("2.493")).setScale(4, RoundingMode.HALF_UP)); |
|
|
|
} |
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public EnergyDayDataDTO getEachYearEnergy(String day) { |
|
|
|
EnergyDayDataDTO result = new EnergyDayDataDTO(); |
|
|
|
String year = day.substring(0, 4); |
|
|
|
//年时间 |
|
|
|
Long dayTime = DateTimeUtils.dateToStamp(year + "-01-01 00:00:00"); |
|
|
|
//当年结束时间戳 |
|
|
|
String yearEndTime = DateTimeUtils.getYearEndTime(day); |
|
|
|
Long endTime = DateTimeUtils.convertTimeToLong(yearEndTime); |
|
|
|
//获取此租户编码 |
|
|
|
public List<EnergyDataDTO> getMonthEnergyRanking(String month, String key, String type) { |
|
|
|
List<EnergyDataDTO> result = new ArrayList<>(); |
|
|
|
//月时间 |
|
|
|
Long monthDayTime = DateTimeUtils.dateToStamp(month.substring(0, 7) + "-01 00:00:00"); |
|
|
|
//月结束时间 |
|
|
|
Long monthEndTime = DateTimeUtils.convertTimeToLong(DateTimeUtils.getMonthEndTime(month.substring(0, 7) + "-01 00:00:00")); |
|
|
|
Long realTenantCode = UserContext.getRealTenantCode(); |
|
|
|
|
|
|
|
//查询这一年的 "总用电": "G01","总用水": "G03","总蒸汽": "G02","总压缩空气": "D_V0000151_1","天然气":"C2"用能情况 |
|
|
|
List<TsKvDTO> tsKvByCodeAndAttrs = tsKvService.findTsKvByCodeAndAttrs("CO_" + realTenantCode, Lists.newArrayList("G01", "G03", "G02", "D_V0000151_1","C2"), dayTime, endTime, true); |
|
|
|
if(CollectionUtil.isNotEmpty(tsKvByCodeAndAttrs)){ |
|
|
|
for (TsKvDTO tsKvDTO : tsKvByCodeAndAttrs) { |
|
|
|
String code = tsKvDTO.getThingCode(); |
|
|
|
String value = tsKvDTO.getVal(); |
|
|
|
if ("G01".equals(code)) { |
|
|
|
// 年用电量 |
|
|
|
result.setElectricDayValue(new BigDecimal(value).setScale(2, RoundingMode.HALF_UP)); |
|
|
|
} else if ("G03".equals(code)) { |
|
|
|
// 年用水量 |
|
|
|
result.setWaterDayValue(new BigDecimal(value).setScale(2, RoundingMode.HALF_UP)); |
|
|
|
} else if ("G02".equals(code)) { |
|
|
|
// 年蒸汽量 |
|
|
|
result.setSteamDayValue(new BigDecimal(value).setScale(2, RoundingMode.HALF_UP)); |
|
|
|
} else if ("D_V0000151_1".equals(code)) { |
|
|
|
// 年压缩空气量 |
|
|
|
result.setAirDayValue(new BigDecimal(value).setScale(2, RoundingMode.HALF_UP)); |
|
|
|
} else if ("C2".equals(code)) { |
|
|
|
// 年天然气用量 |
|
|
|
result.setGasDayValue(new BigDecimal(value).setScale(2, RoundingMode.HALF_UP)); |
|
|
|
} |
|
|
|
//查询所有物实体 |
|
|
|
List<IotThingEntityDTO> entityList = thingEntityService.findEntityAllByCode(null, realTenantCode, true); |
|
|
|
if(CollectionUtil.isEmpty(entityList)){ |
|
|
|
return result; |
|
|
|
} |
|
|
|
List<String> codes = entityList.stream().map(IotThingEntityDTO::getCode).collect(Collectors.toList()); |
|
|
|
List<TsKvDTO> tsKvByCodesAndAttrs = tsKvService.findTsKvByCodesAndAttrs(codes, Lists.newArrayList(key), monthDayTime, monthEndTime, true); |
|
|
|
if(CollectionUtil.isNotEmpty(tsKvByCodesAndAttrs)){ |
|
|
|
//先排序,然后再取前五的排名,最后转换对象EnergyDataDTO |
|
|
|
List<EnergyDataDTO> list = tsKvByCodesAndAttrs.stream().sorted(Comparator.comparing(TsKvDTO::getVal, Comparator.nullsLast(Comparator.reverseOrder()))).limit(5) |
|
|
|
.map(tsKvDTO -> { |
|
|
|
EnergyDataDTO energyDataDTO = new EnergyDataDTO(); |
|
|
|
Optional<IotThingEntityDTO> first = entityList.stream().filter(iotThingEntityDTO -> |
|
|
|
StringUtils.equals(tsKvDTO.getThingCode(), iotThingEntityDTO.getCode())) |
|
|
|
.findFirst(); |
|
|
|
energyDataDTO.setThingName(first.get().getName()); |
|
|
|
energyDataDTO.setValue(new BigDecimal(tsKvDTO.getVal())); |
|
|
|
return energyDataDTO; |
|
|
|
}).toList(); |
|
|
|
return list; |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
public static String getLastDayOfMonth(String month) { |
|
|
|
String fullDateString = month + "-01"; |
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
|
|
|
LocalDate date = LocalDate.parse(fullDateString, formatter); |
|
|
|
|
|
|
|
// 获取该月的最后一天 |
|
|
|
LocalDate lastDayOfMonth = date.withDayOfMonth(date.lengthOfMonth()); |
|
|
|
|
|
|
|
// 设置最后一天的时间为 23:59:59 |
|
|
|
LocalDateTime lastMomentOfMonth = lastDayOfMonth.atTime(23, 59, 59); |
|
|
|
|
|
|
|
// 返回结果的字符串,格式为 "yyyy-MM-dd HH:mm:ss" |
|
|
|
return lastMomentOfMonth.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public EnergyBuildDataDTO getBuildEnergy(BuildRequestDTO dto) { |
|
|
|
@ -645,79 +425,4 @@ public class BoardNewServiceImpl implements BoardNewService { |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static List<String> getDaysBetween(String startDate, String endDate) { |
|
|
|
List<String> daysList = new ArrayList<>(); |
|
|
|
LocalDate start = LocalDate.parse(startDate); |
|
|
|
LocalDate end = LocalDate.parse(endDate); |
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
|
|
|
|
|
|
|
while (!start.isAfter(end)) { |
|
|
|
String day = start.format(formatter); |
|
|
|
daysList.add(day); |
|
|
|
start = start.plusDays(1); |
|
|
|
} |
|
|
|
Collections.reverse(daysList); |
|
|
|
return daysList; |
|
|
|
} |
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
String month = "2024-12"; |
|
|
|
String dayEndTime = getLastDayOfMonth(month); |
|
|
|
System.out.println(dayEndTime); |
|
|
|
// List<String> daysList = getDaysBetween(month, LocalDate.now().toString()); |
|
|
|
// Collections.reverse(daysList); |
|
|
|
// System.out.println(daysList); |
|
|
|
// |
|
|
|
// String year = "2023"; |
|
|
|
// List<String> monthsList = getMonthsBetween(year + "-01", YearMonth.now().toString()); |
|
|
|
// System.out.println(monthsList); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static List<String> getMonthsBetween(String startMonth, String endMonth) { |
|
|
|
List<String> monthsList = new ArrayList<>(); |
|
|
|
YearMonth start = YearMonth.parse(startMonth); |
|
|
|
YearMonth end = YearMonth.parse(endMonth); |
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM"); |
|
|
|
|
|
|
|
while (!start.isAfter(end)) { |
|
|
|
String month = start.format(formatter); |
|
|
|
monthsList.add(month); |
|
|
|
start = start.plusMonths(1); |
|
|
|
} |
|
|
|
Collections.reverse(monthsList); |
|
|
|
return monthsList; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static String getWeekdayName(int dayOfWeek) { |
|
|
|
switch (dayOfWeek) { |
|
|
|
case 1: |
|
|
|
return "周一"; |
|
|
|
case 2: |
|
|
|
return "周二"; |
|
|
|
case 3: |
|
|
|
return "周三"; |
|
|
|
case 4: |
|
|
|
return "周四"; |
|
|
|
case 5: |
|
|
|
return "周五"; |
|
|
|
case 6: |
|
|
|
return "周六"; |
|
|
|
case 7: |
|
|
|
return "周日"; |
|
|
|
default: |
|
|
|
return ""; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// private List<PowerCoalRatioEntity> getPowerCoalRatioList(Long tenantCode, Long deptId) { |
|
|
|
// return powerCoalRatioDao.selectList(Wrappers.<PowerCoalRatioEntity>lambdaQuery() |
|
|
|
// .eq(PowerCoalRatioEntity::getDeptId, deptId).eq(PowerCoalRatioEntity::getTenantCode, tenantCode)); |
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
} |