|
|
@ -10,12 +10,9 @@ import com.thing.qingyuan.board.dto.*; |
|
|
import com.thing.qingyuan.board.service.BoardNewService; |
|
|
import com.thing.qingyuan.board.service.BoardNewService; |
|
|
import com.thing.sys.biz.service.SysParamsService; |
|
|
import com.thing.sys.biz.service.SysParamsService; |
|
|
import com.thing.sys.security.context.UserContext; |
|
|
import com.thing.sys.security.context.UserContext; |
|
|
import jakarta.annotation.Resource; |
|
|
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.springframework.stereotype.Service; |
|
|
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.math.BigDecimal; |
|
|
import java.math.RoundingMode; |
|
|
import java.math.RoundingMode; |
|
|
@ -297,150 +294,56 @@ public class BoardNewServiceImpl implements BoardNewService { |
|
|
@Override |
|
|
@Override |
|
|
public List<EnergyCostProportionDataDTO> getEnergyCost(String day) { |
|
|
public List<EnergyCostProportionDataDTO> getEnergyCost(String day) { |
|
|
List<EnergyCostProportionDataDTO> result = new ArrayList<>(); |
|
|
List<EnergyCostProportionDataDTO> result = new ArrayList<>(); |
|
|
|
|
|
|
|
|
//月时间 |
|
|
//月时间 |
|
|
Long dayTime = DateTimeUtils.dateToStamp(day.substring(0, 7) + "-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); |
|
|
|
|
|
|
|
|
|
|
|
List<String> keyList = new ArrayList<>(); |
|
|
|
|
|
keyList.add("A29_rush"); |
|
|
|
|
|
keyList.add("A29_peak"); |
|
|
|
|
|
keyList.add("A29_valley"); |
|
|
|
|
|
keyList.add("A29_normal"); |
|
|
|
|
|
keyList.add("A29"); |
|
|
|
|
|
keyList.add("B2"); |
|
|
|
|
|
keyList.add("D2"); |
|
|
|
|
|
keyList.add("E3"); |
|
|
|
|
|
/** |
|
|
|
|
|
* todo ,获取各用能的价格 |
|
|
|
|
|
*/ |
|
|
|
|
|
Map<String, BigDecimal> finalPriceMap = new HashMap<>(); |
|
|
|
|
|
// SysDeptEntity sysDeptEntity = sysDeptService.getDeptVaildPermission(); |
|
|
|
|
|
// Map<String,List<EnergyPriceDTO>> priceMap = new HashMap<>(); |
|
|
|
|
|
// //获取价格配置 |
|
|
|
|
|
// List<EnergyPriceDTO> energyPriceList = energyPriceService.getUnitPriceList(keyList, sysDeptEntity.getId()); |
|
|
|
|
|
// if (CollectionUtil.isNotEmpty(energyPriceList)){ |
|
|
|
|
|
// priceMap = energyPriceList.stream() |
|
|
|
|
|
// // 按照 attributeKey 进行分组 |
|
|
|
|
|
// .collect(Collectors.groupingBy(EnergyPriceDTO::getAttributeKey, |
|
|
|
|
|
// // 分组后的每个列表根据 startTime 降序排序 |
|
|
|
|
|
// Collectors.collectingAndThen( |
|
|
|
|
|
// Collectors.toList(), |
|
|
|
|
|
// list -> list.stream() |
|
|
|
|
|
// .sorted(Comparator.comparing(EnergyPriceDTO::getStartTime).reversed()) |
|
|
|
|
|
// .collect(Collectors.toList()) |
|
|
|
|
|
// ) |
|
|
|
|
|
// )); |
|
|
|
|
|
// } |
|
|
|
|
|
// |
|
|
|
|
|
// if (priceMap!=null){ |
|
|
|
|
|
// for (Map.Entry<String,List<EnergyPriceDTO>> entry:priceMap.entrySet()){ |
|
|
|
|
|
// EnergyPriceDTO energyPriceDTO = entry.getValue().get(0); |
|
|
|
|
|
// BigDecimal unitCost = BigDecimal.ZERO; |
|
|
|
|
|
// if (energyPriceDTO.getPrice()!=null){ |
|
|
|
|
|
// unitCost = new BigDecimal(energyPriceDTO.getPrice()); |
|
|
|
|
|
// } |
|
|
|
|
|
// finalPriceMap.put(entry.getKey(),unitCost); |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
BigDecimal totalAllValue = BigDecimal.ZERO; |
|
|
|
|
|
for (Map.Entry<String, String> entry : codeMap.entrySet()) { |
|
|
|
|
|
if (entry.getKey().equals("总压缩空气")) { |
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
Long monthDayTime = DateTimeUtils.dateToStamp(day.substring(0, 7) + "-01 00:00:00"); |
|
|
|
|
|
//月结束时间 |
|
|
|
|
|
Long monthEndTime = DateTimeUtils.convertTimeToLong(DateTimeUtils.getMonthEndTime(day)); |
|
|
|
|
|
// //年时间 |
|
|
|
|
|
// Long yearDayStartTime = DateTimeUtils.dateToStamp(day.substring(0, 4) + "-01-01 00:00:00"); |
|
|
|
|
|
// //年结束时间 |
|
|
|
|
|
// Long yearEndTime = DateTimeUtils.convertTimeToLong(DateTimeUtils.getYearEndTime(day)); |
|
|
|
|
|
EnergyCostProportionDataDTO energyA29 = new EnergyCostProportionDataDTO(); |
|
|
|
|
|
energyA29.setName("电"); |
|
|
|
|
|
EnergyCostProportionDataDTO energyB2 = new EnergyCostProportionDataDTO(); |
|
|
|
|
|
energyB2.setName("水"); |
|
|
|
|
|
Long realTenantCode = UserContext.getRealTenantCode(); |
|
|
|
|
|
EnergyCostProportionDataDTO energyE3 = new EnergyCostProportionDataDTO(); |
|
|
|
|
|
energyE3.setName("蒸气"); |
|
|
|
|
|
//月用电 |
|
|
|
|
|
List<TsKvDTO> tsKvMonth = tsKvService.findTsKvByCodeAndAttrs("CO_" + realTenantCode, Lists.newArrayList("A29mm", "B2mm", "G02", "E3mm"), monthDayTime, monthEndTime, true); |
|
|
|
|
|
|
|
|
|
|
|
//年用电 |
|
|
|
|
|
// List<TsKvDTO> tsKvYear = tsKvService.findTsKvByCodeAndAttrs("CO_" + realTenantCode, Lists.newArrayList("G01", "G03", "G02", "D_V0000151_1","C2"), monthDayTime, monthEndTime, true); |
|
|
|
|
|
if(CollectionUtil.isNotEmpty(tsKvMonth)){ |
|
|
|
|
|
BigDecimal totalValueA29 = BigDecimal.ZERO; |
|
|
|
|
|
BigDecimal totalValueB2 = BigDecimal.ZERO; |
|
|
|
|
|
BigDecimal totalValueE3 = BigDecimal.ZERO; |
|
|
|
|
|
List<TsKvDTO> listA29 = tsKvMonth.stream().filter(tsKvDTO -> StringUtils.equals("A29mm", tsKvDTO.getAttrKey())).toList(); |
|
|
|
|
|
List<TsKvDTO> listB2 = tsKvMonth.stream().filter(tsKvDTO -> StringUtils.equals("B2mm", 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); |
|
|
} |
|
|
} |
|
|
EnergyCostProportionDataDTO costProportionDataDTO = new EnergyCostProportionDataDTO(); |
|
|
|
|
|
List<String> keys = new ArrayList<>(); |
|
|
|
|
|
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("总用水")) { |
|
|
|
|
|
costProportionDataDTO.setName("水"); |
|
|
|
|
|
keys.add("B2mm"); |
|
|
|
|
|
} else if (entry.getKey().equals("总蒸汽")) { |
|
|
|
|
|
costProportionDataDTO.setName("蒸汽"); |
|
|
|
|
|
keys.add("E3mm"); |
|
|
|
|
|
|
|
|
if(CollectionUtil.isNotEmpty(listB2)){ |
|
|
|
|
|
BigDecimal reduce = listB2.stream().map(v -> new BigDecimal(v.getVal())).reduce(BigDecimal.ZERO, BigDecimal::add); |
|
|
|
|
|
totalValueB2 = reduce.multiply(new BigDecimal("0.2571")).divide(new BigDecimal("1000"),2,RoundingMode.HALF_UP); |
|
|
} |
|
|
} |
|
|
BigDecimal totalValue = BigDecimal.ZERO; |
|
|
|
|
|
/** |
|
|
|
|
|
* 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)){ |
|
|
|
|
|
// Map<String,List<TsKvEntry>> tsKvMap = new HashMap<>(); |
|
|
|
|
|
// if (CollectionUtil.isNotEmpty(dayTsKvEntries)){ |
|
|
|
|
|
// tsKvMap = dayTsKvEntries.stream() |
|
|
|
|
|
// .collect(Collectors.groupingBy(TsKvEntry::getKey)); |
|
|
|
|
|
// } |
|
|
|
|
|
// if (tsKvMap!=null){ |
|
|
|
|
|
// for (Map.Entry<String,List<TsKvEntry>> keyEntry:tsKvMap.entrySet()){ |
|
|
|
|
|
// BigDecimal value1 = new BigDecimal(keyEntry.getValue().get(0).getValue().toString()); |
|
|
|
|
|
// BigDecimal unitCost =BigDecimal.ZERO; |
|
|
|
|
|
// if (keyEntry.getKey().equals("A29_rushmm")){ |
|
|
|
|
|
// if (finalPriceMap.get("A29_rush")!=null){ |
|
|
|
|
|
// unitCost =finalPriceMap.get("A29_rush"); |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
// if (keyEntry.getKey().equals("A29_peakmm")){ |
|
|
|
|
|
// if (finalPriceMap.get("A29_peak")!=null){ |
|
|
|
|
|
// unitCost =finalPriceMap.get("A29_peak"); |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
// if (entry.getKey().equals("A29_valleymm")){ |
|
|
|
|
|
// if (finalPriceMap.get("A29_valley")!=null){ |
|
|
|
|
|
// unitCost =finalPriceMap.get("A29_valley"); |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
// if (keyEntry.getKey().equals("A29_normalmm")){ |
|
|
|
|
|
// if (finalPriceMap.get("A29_normal")!=null){ |
|
|
|
|
|
// unitCost =finalPriceMap.get("A29_normal"); |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
// if (keyEntry.getKey().equals("B2mm")){ |
|
|
|
|
|
// if (finalPriceMap.get("B2")!=null){ |
|
|
|
|
|
// unitCost =finalPriceMap.get("B2"); |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
// if (keyEntry.getKey().equals("D2mm")){ |
|
|
|
|
|
// if (finalPriceMap.get("D2")!=null){ |
|
|
|
|
|
// unitCost =finalPriceMap.get("D2"); |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
// if (keyEntry.getKey().equals("E3mm")){ |
|
|
|
|
|
// if (finalPriceMap.get("E3")!=null){ |
|
|
|
|
|
// unitCost =finalPriceMap.get("E3"); |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
// if (value1!=null){ |
|
|
|
|
|
// if (unitCost!=null){ |
|
|
|
|
|
// totalValue = totalValue.add(value1.multiply(unitCost)); |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
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(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); |
|
|
} |
|
|
} |
|
|
|
|
|
BigDecimal total = totalValueA29.add(totalValueB2).add(totalValueE3); |
|
|
|
|
|
energyA29.setProportion(totalValueA29.divide(total,4,RoundingMode.HALF_UP).toPlainString()); |
|
|
|
|
|
energyA29.setValue(totalValueA29); |
|
|
|
|
|
energyB2.setProportion(totalValueB2.divide(total,4,RoundingMode.HALF_UP).toPlainString()); |
|
|
|
|
|
energyB2.setValue(totalValueB2); |
|
|
|
|
|
energyE3.setProportion(totalValueE3.divide(total,4,RoundingMode.HALF_UP).toPlainString()); |
|
|
|
|
|
energyE3.setValue(totalValueE3); |
|
|
} |
|
|
} |
|
|
|
|
|
result.add(energyA29); |
|
|
|
|
|
result.add(energyB2); |
|
|
|
|
|
result.add(energyE3); |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|