|
|
|
@ -2,14 +2,20 @@ 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.utils.DateTimeUtils; |
|
|
|
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.SysDeptService; |
|
|
|
import com.thing.sys.biz.service.SysParamsService; |
|
|
|
import com.thing.sys.security.context.UserContext; |
|
|
|
import jakarta.annotation.Resource; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.thingsboard.server.common.data.id.DeviceId; |
|
|
|
import org.thingsboard.server.common.data.kv.TsKvEntry; |
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.time.LocalDate; |
|
|
|
@ -28,25 +34,10 @@ import java.util.stream.Collectors; |
|
|
|
@Service |
|
|
|
@RequiredArgsConstructor |
|
|
|
public class BoardNewServiceImpl implements BoardNewService { |
|
|
|
// @Autowired |
|
|
|
// private ThingsDao thingsDao; |
|
|
|
@Autowired |
|
|
|
private SysParamsService sysParamsService; |
|
|
|
// @Autowired |
|
|
|
// private NewRestClientUtils newRestClientUtils; |
|
|
|
@Autowired |
|
|
|
private SysDeptService sysDeptService; |
|
|
|
// @Autowired |
|
|
|
// private PowerCoalRatioDao powerCoalRatioDao; |
|
|
|
// |
|
|
|
// @Autowired |
|
|
|
// private ThingsService thingsService; |
|
|
|
// |
|
|
|
// @Autowired |
|
|
|
// private EnergyPriceService energyPriceService; |
|
|
|
// |
|
|
|
// @Autowired |
|
|
|
// private EnergyMonthDataService energyMonthDataService; |
|
|
|
|
|
|
|
private final SysParamsService sysParamsService; |
|
|
|
private final TsKvService tsKvService; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public EnergyDataAnalyseDTO qcDayLoadAnalyse(String day) { |
|
|
|
@ -58,7 +49,7 @@ public class BoardNewServiceImpl implements BoardNewService { |
|
|
|
//将当月时间转换为时间戳 |
|
|
|
Long dayStartTimeStamp = DateTimeUtils.dateToStamp(dayStartTime); |
|
|
|
//当月结束时间 |
|
|
|
Long dayEndTimeStamp = DateTimeUtils.dateToStamp(dayEndTime); |
|
|
|
Long dayEndTimeStamp = DateTimeUtils.dateToStamp(dayEndTime); |
|
|
|
|
|
|
|
/** |
|
|
|
* 参数格式:{"总用电": "G01","总用水": "G03","总蒸汽": "G02","总压缩空气": "D_V0000151_1"} |
|
|
|
@ -92,14 +83,14 @@ public class BoardNewServiceImpl implements BoardNewService { |
|
|
|
public EnergyConsumptionDataDTO getEnergyConsumption(String day) { |
|
|
|
EnergyConsumptionDataDTO result = new EnergyConsumptionDataDTO(); |
|
|
|
//日时间 |
|
|
|
Long dayTime = DateTimeUtils.dateToStamp(day+" 00:00:00"); |
|
|
|
Long dayTime = DateTimeUtils.dateToStamp(day + " 00:00:00"); |
|
|
|
//月时间 |
|
|
|
Long monthTime = DateTimeUtils.dateToStamp(day.substring(0,7)+"-01 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"); |
|
|
|
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; |
|
|
|
BigDecimal totalMonthValue = BigDecimal.ZERO; |
|
|
|
BigDecimal totalYearValue = BigDecimal.ZERO; |
|
|
|
/** |
|
|
|
* 总code :参数格式:{"总用电": "G01","总用水": "G03","总蒸汽": "G02","总压缩空气": "D_V0000151_1"} |
|
|
|
*/ |
|
|
|
@ -117,25 +108,25 @@ public class BoardNewServiceImpl implements BoardNewService { |
|
|
|
// } |
|
|
|
// } |
|
|
|
|
|
|
|
for(Map.Entry<String, String> entry : codeMap.entrySet()){ |
|
|
|
if (entry.getKey().equals("总用水")){ |
|
|
|
for (Map.Entry<String, String> entry : codeMap.entrySet()) { |
|
|
|
if (entry.getKey().equals("总用水")) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
BigDecimal coalRatioValue =null; |
|
|
|
BigDecimal coalRatioValue = null; |
|
|
|
List<String> keys = new ArrayList<>(); |
|
|
|
List<String> keys1 = new ArrayList<>(); |
|
|
|
List<String> keys2 = new ArrayList<>(); |
|
|
|
if (entry.getKey().equals("总用电")){ |
|
|
|
if (entry.getKey().equals("总用电")) { |
|
|
|
coalRatioValue = coalRatio.get("A"); |
|
|
|
keys.add("A29dd"); |
|
|
|
keys1.add("A29mm"); |
|
|
|
keys2.add("A29yy"); |
|
|
|
}else if (entry.getKey().equals("总蒸汽")){ |
|
|
|
} else if (entry.getKey().equals("总蒸汽")) { |
|
|
|
coalRatioValue = coalRatio.get("E"); |
|
|
|
keys.add("E3dd"); |
|
|
|
keys1.add("E3mm"); |
|
|
|
keys2.add("E3yy"); |
|
|
|
}else if(entry.getKey().equals("总压缩空气")){ |
|
|
|
} else if (entry.getKey().equals("总压缩空气")) { |
|
|
|
coalRatioValue = coalRatio.get("D"); |
|
|
|
keys.add("D2dd"); |
|
|
|
keys1.add("D2mm"); |
|
|
|
@ -194,17 +185,17 @@ public class BoardNewServiceImpl implements BoardNewService { |
|
|
|
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 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 monthTime = DateTimeUtils.dateToStamp(day.substring(0, 7) + "-01 00:00:00"); |
|
|
|
//年时间 |
|
|
|
Long yearTime = DateTimeUtils.dateToStamp(day.substring(0,4)+"-01-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 totalMonthConsumtionValue = BigDecimal.ZERO; |
|
|
|
BigDecimal totalYearConsumtionValue = BigDecimal.ZERO; |
|
|
|
BigDecimal totalYearCarbonValue= BigDecimal.ZERO; |
|
|
|
BigDecimal totalYearCarbonValue = BigDecimal.ZERO; |
|
|
|
/** |
|
|
|
* 总code :参数格式:{"总用电": "G01","总用水": "G03","总蒸汽": "G02","总压缩空气": "D_V0000151_1"} |
|
|
|
*/ |
|
|
|
@ -225,25 +216,25 @@ public class BoardNewServiceImpl implements BoardNewService { |
|
|
|
// } |
|
|
|
// } |
|
|
|
|
|
|
|
for(Map.Entry<String, String> entry : codeMap.entrySet()){ |
|
|
|
if (entry.getKey().equals("总用水")){ |
|
|
|
for (Map.Entry<String, String> entry : codeMap.entrySet()) { |
|
|
|
if (entry.getKey().equals("总用水")) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
BigDecimal coalRatioValue =null; |
|
|
|
BigDecimal coalRatioValue = null; |
|
|
|
List<String> keys = new ArrayList<>(); |
|
|
|
List<String> keys1 = new ArrayList<>(); |
|
|
|
List<String> keys2 = new ArrayList<>(); |
|
|
|
if (entry.getKey().equals("总用电")){ |
|
|
|
if (entry.getKey().equals("总用电")) { |
|
|
|
coalRatioValue = coalRatio.get("A"); |
|
|
|
keys.add("A29dd"); |
|
|
|
keys1.add("A29mm"); |
|
|
|
keys2.add("A29yy"); |
|
|
|
}else if (entry.getKey().equals("总蒸汽")){ |
|
|
|
} else if (entry.getKey().equals("总蒸汽")) { |
|
|
|
coalRatioValue = coalRatio.get("E"); |
|
|
|
keys.add("E3dd"); |
|
|
|
keys1.add("E3mm"); |
|
|
|
keys2.add("E3yy"); |
|
|
|
}else if(entry.getKey().equals("总压缩空气")){ |
|
|
|
} else if (entry.getKey().equals("总压缩空气")) { |
|
|
|
coalRatioValue = coalRatio.get("D"); |
|
|
|
keys.add("D2dd"); |
|
|
|
keys1.add("D2mm"); |
|
|
|
@ -293,11 +284,11 @@ public class BoardNewServiceImpl implements BoardNewService { |
|
|
|
// } |
|
|
|
// } |
|
|
|
} |
|
|
|
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)); |
|
|
|
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; |
|
|
|
} |
|
|
|
@ -307,7 +298,7 @@ public class BoardNewServiceImpl implements BoardNewService { |
|
|
|
List<EnergyCostProportionDataDTO> result = new ArrayList<>(); |
|
|
|
|
|
|
|
//月时间 |
|
|
|
Long dayTime = DateTimeUtils.dateToStamp(day.substring(0,7)+"-01 00:00:00"); |
|
|
|
Long dayTime = DateTimeUtils.dateToStamp(day.substring(0, 7) + "-01 00:00:00"); |
|
|
|
/** |
|
|
|
* 总code :参数格式:{"总用电": "G01","总用水": "G03","总蒸汽": "G02","总压缩空气": "D_V0000151_1"} |
|
|
|
*/ |
|
|
|
@ -327,7 +318,7 @@ public class BoardNewServiceImpl implements BoardNewService { |
|
|
|
/** |
|
|
|
* todo ,获取各用能的价格 |
|
|
|
*/ |
|
|
|
Map<String,BigDecimal> finalPriceMap= new HashMap<>(); |
|
|
|
Map<String, BigDecimal> finalPriceMap = new HashMap<>(); |
|
|
|
// SysDeptEntity sysDeptEntity = sysDeptService.getDeptVaildPermission(); |
|
|
|
// Map<String,List<EnergyPriceDTO>> priceMap = new HashMap<>(); |
|
|
|
// //获取价格配置 |
|
|
|
@ -357,22 +348,22 @@ public class BoardNewServiceImpl implements BoardNewService { |
|
|
|
// } |
|
|
|
// } |
|
|
|
BigDecimal totalAllValue = BigDecimal.ZERO; |
|
|
|
for(Map.Entry<String, String> entry : codeMap.entrySet()){ |
|
|
|
if(entry.getKey().equals("总压缩空气")){ |
|
|
|
for (Map.Entry<String, String> entry : codeMap.entrySet()) { |
|
|
|
if (entry.getKey().equals("总压缩空气")) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
EnergyCostProportionDataDTO costProportionDataDTO = new EnergyCostProportionDataDTO(); |
|
|
|
List<String> keys = new ArrayList<>(); |
|
|
|
if (entry.getKey().equals("总用电")){ |
|
|
|
if (entry.getKey().equals("总用电")) { |
|
|
|
costProportionDataDTO.setName("电"); |
|
|
|
keys.add("A29_rushmm"); |
|
|
|
keys.add("A29_peakmm"); |
|
|
|
keys.add("A29_valleymm"); |
|
|
|
keys.add("A29_normalmm"); |
|
|
|
}else if (entry.getKey().equals("总用水")){ |
|
|
|
} else if (entry.getKey().equals("总用水")) { |
|
|
|
costProportionDataDTO.setName("水"); |
|
|
|
keys.add("B2mm"); |
|
|
|
}else if (entry.getKey().equals("总蒸汽")){ |
|
|
|
} else if (entry.getKey().equals("总蒸汽")) { |
|
|
|
costProportionDataDTO.setName("蒸汽"); |
|
|
|
keys.add("E3mm"); |
|
|
|
} |
|
|
|
@ -438,14 +429,14 @@ public class BoardNewServiceImpl implements BoardNewService { |
|
|
|
// } |
|
|
|
// } |
|
|
|
// } |
|
|
|
costProportionDataDTO.setValue(totalValue.setScale(2,BigDecimal.ROUND_HALF_UP)); |
|
|
|
costProportionDataDTO.setValue(totalValue.setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
|
|
result.add(costProportionDataDTO); |
|
|
|
totalAllValue = totalAllValue.add(totalValue); |
|
|
|
} |
|
|
|
if (CollectionUtil.isNotEmpty(result)){ |
|
|
|
for (EnergyCostProportionDataDTO cost:result){ |
|
|
|
if (totalAllValue!=null && totalAllValue.compareTo(BigDecimal.ZERO)!=0){ |
|
|
|
cost.setProportion(cost.getValue().divide(totalAllValue,2,BigDecimal.ROUND_HALF_UP)+"%"); |
|
|
|
if (CollectionUtil.isNotEmpty(result)) { |
|
|
|
for (EnergyCostProportionDataDTO cost : result) { |
|
|
|
if (totalAllValue != null && totalAllValue.compareTo(BigDecimal.ZERO) != 0) { |
|
|
|
cost.setProportion(cost.getValue().divide(totalAllValue, 2, BigDecimal.ROUND_HALF_UP) + "%"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -458,7 +449,7 @@ public class BoardNewServiceImpl implements BoardNewService { |
|
|
|
//月数据 |
|
|
|
String dayStartTime = month + "-01 00:00:00"; |
|
|
|
Long dayStartTimeStamp = DateTimeUtils.dateToStamp(dayStartTime); |
|
|
|
Long dayEndTimeStamp = dayStartTimeStamp + 5*60*1000; |
|
|
|
Long dayEndTimeStamp = dayStartTimeStamp + 5 * 60 * 1000; |
|
|
|
/** |
|
|
|
* 排行表 :参数格式:["D_V0000151_3","D_V0000151_4","D_V0000151_2","E_V0000151_7"] |
|
|
|
*/ |
|
|
|
@ -487,7 +478,7 @@ public class BoardNewServiceImpl implements BoardNewService { |
|
|
|
// result.add(energyDataDTO); |
|
|
|
// } |
|
|
|
|
|
|
|
result =result.stream() |
|
|
|
result = result.stream() |
|
|
|
.sorted(Comparator.comparing(EnergyDataDTO::getValue, Comparator.nullsLast(Comparator.reverseOrder()))) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
return result; |
|
|
|
@ -519,7 +510,7 @@ public class BoardNewServiceImpl implements BoardNewService { |
|
|
|
//将当月时间转换为时间戳 |
|
|
|
Long dayStartTimeStamp = DateTimeUtils.dateToStamp(dayStartTime); |
|
|
|
//当月结束时间 |
|
|
|
Long dayEndTimeStamp = DateTimeUtils.dateToStamp(dayEndTime); |
|
|
|
Long dayEndTimeStamp = DateTimeUtils.dateToStamp(dayEndTime); |
|
|
|
/** |
|
|
|
* 总code :参数格式:{"总用电": "G01","总用水": "G03","总蒸汽": "G02","总压缩空气": "D_V0000151_1"} |
|
|
|
*/ |
|
|
|
@ -528,14 +519,14 @@ public class BoardNewServiceImpl implements BoardNewService { |
|
|
|
Map<String, String> codeMap = JSONObject.parseObject(cqStr, Map.class); |
|
|
|
List<String> keys = new ArrayList<>(); |
|
|
|
keys.add(key); |
|
|
|
String code =null; |
|
|
|
if ("电".equals(type)){ |
|
|
|
String code = null; |
|
|
|
if ("电".equals(type)) { |
|
|
|
code = codeMap.get("总用电"); |
|
|
|
}else if("水".equals(type)){ |
|
|
|
} else if ("水".equals(type)) { |
|
|
|
code = codeMap.get("总用水"); |
|
|
|
}else if("蒸汽".equals(type)){ |
|
|
|
} else if ("蒸汽".equals(type)) { |
|
|
|
code = codeMap.get("总蒸汽"); |
|
|
|
}else if("压缩空气".equals(type)){ |
|
|
|
} else if ("压缩空气".equals(type)) { |
|
|
|
code = codeMap.get("总压缩空气"); |
|
|
|
} |
|
|
|
/** |
|
|
|
@ -561,105 +552,102 @@ public class BoardNewServiceImpl implements BoardNewService { |
|
|
|
result.setCurrentMonthData(currentMonthData); |
|
|
|
return result; |
|
|
|
} |
|
|
|
@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"); |
|
|
|
//次月第一天时间戳 |
|
|
|
Long nextMonthDayTime = DateTimeUtils.dateToStamp( |
|
|
|
LocalDate.parse(month + "-01").plusMonths(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd 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, nextMonthDayTime, 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, BigDecimal.ROUND_HALF_UP)); |
|
|
|
} else if ("G03".equals(code)) { |
|
|
|
// 月用水量 |
|
|
|
result.setWaterDayValue(new BigDecimal(value).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
|
|
} else if ("G02".equals(code)) { |
|
|
|
// 月蒸汽量 |
|
|
|
result.setSteamDayValue(new BigDecimal(value).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
|
|
} else if ("D_V0000151_1".equals(code)) { |
|
|
|
// 月压缩空气量 |
|
|
|
result.setAirDayValue(new BigDecimal(value).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
|
|
} else if ("C2".equals(code)) { |
|
|
|
// 月天然气用量 |
|
|
|
result.setGasDayValue(new BigDecimal(value).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public EnergyDayDataDTO getEachYearEnergy(String day) { |
|
|
|
EnergyDayDataDTO result = new EnergyDayDataDTO(); |
|
|
|
String year = day.substring(0,4); |
|
|
|
String year = day.substring(0, 4); |
|
|
|
//年时间 |
|
|
|
Long dayTime = DateTimeUtils.dateToStamp(year+"-01-01 00:00:00"); |
|
|
|
|
|
|
|
/** |
|
|
|
* 总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); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* todo 获取各用能数据 |
|
|
|
*/ |
|
|
|
// ThingsDTO thingsDTO = thingsService.getThingsByCode(codeMap.get("总用电")); |
|
|
|
// if (thingsDTO!=null && StringUtils.isNotBlank(thingsDTO.getEntityId())){ |
|
|
|
// DeviceId deviceId = new DeviceId(UUID.fromString(thingsDTO.getEntityId())); |
|
|
|
// //当日 |
|
|
|
// List<String> keys = new ArrayList<>(); |
|
|
|
// keys.add("A29yy"); |
|
|
|
// 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){ |
|
|
|
// result.setElectricDayValue(new BigDecimal(tsKvEntry.getValue().toString()).divide(new BigDecimal(10000)).setScale(2,BigDecimal.ROUND_HALF_UP)); |
|
|
|
// } |
|
|
|
// } |
|
|
|
// } |
|
|
|
// //水 |
|
|
|
// ThingsDTO thingsDTO1 = thingsService.getThingsByCode(codeMap.get("总用水")); |
|
|
|
// if (thingsDTO1!=null && StringUtils.isNotBlank(thingsDTO1.getEntityId())){ |
|
|
|
// DeviceId deviceId = new DeviceId(UUID.fromString(thingsDTO1.getEntityId())); |
|
|
|
// //当月 |
|
|
|
// List<String> keys1 = new ArrayList<>(); |
|
|
|
// keys1.add("B2yy"); |
|
|
|
// List<TsKvEntry> monthTsKvEntries = newRestClientUtils.getTimeseries(deviceId,keys1,dayTime-5*60000L,dayTime+5*60000L,true); |
|
|
|
// if (CollectionUtil.isNotEmpty(monthTsKvEntries)){ |
|
|
|
// TsKvEntry tsKvEntry = monthTsKvEntries.get(0); |
|
|
|
// if (tsKvEntry.getValue()!=null){ |
|
|
|
// result.setWaterDayValue(new BigDecimal(tsKvEntry.getValue().toString()).setScale(2,BigDecimal.ROUND_HALF_UP)); |
|
|
|
// } |
|
|
|
// } |
|
|
|
// } |
|
|
|
// //压缩空气 |
|
|
|
// ThingsDTO thingsDTO2 = thingsService.getThingsByCode(codeMap.get("总压缩空气")); |
|
|
|
// if (thingsDTO2!=null && StringUtils.isNotBlank(thingsDTO2.getEntityId())){ |
|
|
|
// DeviceId deviceId = new DeviceId(UUID.fromString(thingsDTO2.getEntityId())); |
|
|
|
// //当月 |
|
|
|
// List<String> keys1 = new ArrayList<>(); |
|
|
|
// keys1.add("D2yy"); |
|
|
|
// List<TsKvEntry> monthTsKvEntries = newRestClientUtils.getTimeseries(deviceId,keys1,dayTime-5*60000L,dayTime+5*60000L,true); |
|
|
|
// if (CollectionUtil.isNotEmpty(monthTsKvEntries)){ |
|
|
|
// TsKvEntry tsKvEntry = monthTsKvEntries.get(0); |
|
|
|
// if (tsKvEntry.getValue()!=null){ |
|
|
|
// result.setAirDayValue(new BigDecimal(tsKvEntry.getValue().toString()).setScale(2,BigDecimal.ROUND_HALF_UP)); |
|
|
|
// } |
|
|
|
// } |
|
|
|
// } |
|
|
|
// //蒸汽 |
|
|
|
// ThingsDTO thingsDTO3 = thingsService.getThingsByCode(codeMap.get("总蒸汽")); |
|
|
|
// if (thingsDTO3!=null && StringUtils.isNotBlank(thingsDTO3.getEntityId())){ |
|
|
|
// DeviceId deviceId = new DeviceId(UUID.fromString(thingsDTO3.getEntityId())); |
|
|
|
// //当月 |
|
|
|
// List<String> keys1 = new ArrayList<>(); |
|
|
|
// keys1.add("E3yy"); |
|
|
|
// List<TsKvEntry> monthTsKvEntries = newRestClientUtils.getTimeseries(deviceId,keys1,dayTime-5*60000L,dayTime+5*60000L,true); |
|
|
|
// if (CollectionUtil.isNotEmpty(monthTsKvEntries)){ |
|
|
|
// TsKvEntry tsKvEntry = monthTsKvEntries.get(0); |
|
|
|
// if (tsKvEntry.getValue()!=null){ |
|
|
|
// result.setSteamDayValue(new BigDecimal(tsKvEntry.getValue().toString()).setScale(2,BigDecimal.ROUND_HALF_UP)); |
|
|
|
// } |
|
|
|
// } |
|
|
|
// } |
|
|
|
// |
|
|
|
// //天然气 |
|
|
|
// BigDecimal gasValue = energyMonthDataService.getYearDataByBaseInfoIdAndYear(100L,year); |
|
|
|
// if (gasValue!=null){ |
|
|
|
// result.setGasValue(gasValue.setScale(2,BigDecimal.ROUND_HALF_UP)); |
|
|
|
// } |
|
|
|
Long dayTime = DateTimeUtils.dateToStamp(year + "-01-01 00:00:00"); |
|
|
|
//次年第一天的时间戳 |
|
|
|
Long nextYearDayTime = DateTimeUtils.dateToStamp( |
|
|
|
LocalDate.parse(year + "-01-01").plusYears(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd 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, nextYearDayTime, 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, BigDecimal.ROUND_HALF_UP)); |
|
|
|
} else if ("G03".equals(code)) { |
|
|
|
// 年用水量 |
|
|
|
result.setWaterDayValue(new BigDecimal(value).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
|
|
} else if ("G02".equals(code)) { |
|
|
|
// 年蒸汽量 |
|
|
|
result.setSteamDayValue(new BigDecimal(value).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
|
|
} else if ("D_V0000151_1".equals(code)) { |
|
|
|
// 年压缩空气量 |
|
|
|
result.setAirDayValue(new BigDecimal(value).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
|
|
} else if ("C2".equals(code)) { |
|
|
|
// 年天然气用量 |
|
|
|
result.setGasDayValue(new BigDecimal(value).setScale(2, BigDecimal.ROUND_HALF_UP)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public EnergyBuildDataDTO getBuildEnergy(BuildRequestDTO dto) { |
|
|
|
EnergyBuildDataDTO result = new EnergyBuildDataDTO(); |
|
|
|
String dayStartTime = dto.getMonth() + "-01 00:00:00"; |
|
|
|
Long dayStartTimeStamp = DateTimeUtils.dateToStamp(dayStartTime); |
|
|
|
Long dayEndTimeStamp = dayStartTimeStamp + 5*60*1000; |
|
|
|
Long dayEndTimeStamp = dayStartTimeStamp + 5 * 60 * 1000; |
|
|
|
|
|
|
|
if (CollectionUtil.isEmpty(dto.getDatas())){ |
|
|
|
if (CollectionUtil.isEmpty(dto.getDatas())) { |
|
|
|
return result; |
|
|
|
} |
|
|
|
List<BuildDetailRequestDTO> datas = dto.getDatas(); |
|
|
|
for (BuildDetailRequestDTO requestDTO:datas){ |
|
|
|
for (BuildDetailRequestDTO requestDTO : datas) { |
|
|
|
/** |
|
|
|
* todo ,获取各用能数据 |
|
|
|
*/ |
|
|
|
@ -691,91 +679,6 @@ public class BoardNewServiceImpl implements BoardNewService { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@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"); |
|
|
|
|
|
|
|
/** |
|
|
|
* 总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); |
|
|
|
|
|
|
|
/** |
|
|
|
* todo 获取各用能数据 |
|
|
|
*/ |
|
|
|
// ThingsDTO thingsDTO = thingsService.getThingsByCode(codeMap.get("总用电")); |
|
|
|
// if (thingsDTO!=null && StringUtils.isNotBlank(thingsDTO.getEntityId())){ |
|
|
|
// DeviceId deviceId = new DeviceId(UUID.fromString(thingsDTO.getEntityId())); |
|
|
|
// //当日 |
|
|
|
// List<String> keys = new ArrayList<>(); |
|
|
|
// keys.add("A29mm"); |
|
|
|
// 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){ |
|
|
|
// result.setElectricDayValue(new BigDecimal(tsKvEntry.getValue().toString()).divide(new BigDecimal(10000)).setScale(2,BigDecimal.ROUND_HALF_UP)); |
|
|
|
// } |
|
|
|
// } |
|
|
|
// } |
|
|
|
// //水 |
|
|
|
// ThingsDTO thingsDTO1 = thingsService.getThingsByCode(codeMap.get("总用水")); |
|
|
|
// if (thingsDTO1!=null && StringUtils.isNotBlank(thingsDTO1.getEntityId())){ |
|
|
|
// DeviceId deviceId = new DeviceId(UUID.fromString(thingsDTO1.getEntityId())); |
|
|
|
// //当月 |
|
|
|
// List<String> keys1 = new ArrayList<>(); |
|
|
|
// keys1.add("B2mm"); |
|
|
|
// List<TsKvEntry> monthTsKvEntries = newRestClientUtils.getTimeseries(deviceId,keys1,dayTime-5*60000L,dayTime+5*60000L,true); |
|
|
|
// if (CollectionUtil.isNotEmpty(monthTsKvEntries)){ |
|
|
|
// TsKvEntry tsKvEntry = monthTsKvEntries.get(0); |
|
|
|
// if (tsKvEntry.getValue()!=null){ |
|
|
|
// result.setWaterDayValue(new BigDecimal(tsKvEntry.getValue().toString()).setScale(2,BigDecimal.ROUND_HALF_UP)); |
|
|
|
// } |
|
|
|
// } |
|
|
|
// } |
|
|
|
// //压缩空气 |
|
|
|
// ThingsDTO thingsDTO2 = thingsService.getThingsByCode(codeMap.get("总压缩空气")); |
|
|
|
// if (thingsDTO2!=null && StringUtils.isNotBlank(thingsDTO2.getEntityId())){ |
|
|
|
// DeviceId deviceId = new DeviceId(UUID.fromString(thingsDTO2.getEntityId())); |
|
|
|
// //当月 |
|
|
|
// List<String> keys1 = new ArrayList<>(); |
|
|
|
// keys1.add("D2mm"); |
|
|
|
// List<TsKvEntry> monthTsKvEntries = newRestClientUtils.getTimeseries(deviceId,keys1,dayTime-5*60000L,dayTime+5*60000L,true); |
|
|
|
// if (CollectionUtil.isNotEmpty(monthTsKvEntries)){ |
|
|
|
// TsKvEntry tsKvEntry = monthTsKvEntries.get(0); |
|
|
|
// if (tsKvEntry.getValue()!=null){ |
|
|
|
// result.setAirDayValue(new BigDecimal(tsKvEntry.getValue().toString()).setScale(2,BigDecimal.ROUND_HALF_UP)); |
|
|
|
// } |
|
|
|
// } |
|
|
|
// } |
|
|
|
// //蒸汽 |
|
|
|
// ThingsDTO thingsDTO3 = thingsService.getThingsByCode(codeMap.get("总蒸汽")); |
|
|
|
// if (thingsDTO3!=null && StringUtils.isNotBlank(thingsDTO3.getEntityId())){ |
|
|
|
// DeviceId deviceId = new DeviceId(UUID.fromString(thingsDTO3.getEntityId())); |
|
|
|
// //当月 |
|
|
|
// List<String> keys1 = new ArrayList<>(); |
|
|
|
// keys1.add("E3mm"); |
|
|
|
// List<TsKvEntry> monthTsKvEntries = newRestClientUtils.getTimeseries(deviceId,keys1,dayTime-5*60000L,dayTime+5*60000L,true); |
|
|
|
// if (CollectionUtil.isNotEmpty(monthTsKvEntries)){ |
|
|
|
// TsKvEntry tsKvEntry = monthTsKvEntries.get(0); |
|
|
|
// if (tsKvEntry.getValue()!=null){ |
|
|
|
// result.setSteamDayValue(new BigDecimal(tsKvEntry.getValue().toString()).setScale(2,BigDecimal.ROUND_HALF_UP)); |
|
|
|
// } |
|
|
|
// } |
|
|
|
// } |
|
|
|
// |
|
|
|
// //天然气 |
|
|
|
// BigDecimal gasValue = energyMonthDataService.getDataByBaseIdAndMonth(100L,month); |
|
|
|
// if (gasValue!=null){ |
|
|
|
// result.setGasValue(gasValue.setScale(2,BigDecimal.ROUND_HALF_UP)); |
|
|
|
// } |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static List<String> getDaysBetween(String startDate, String endDate) { |
|
|
|
List<String> daysList = new ArrayList<>(); |
|
|
|
|