Browse Source

青原看板 2025年4月1日14:33:07

qingyuan_dev_new
jiangc 10 months ago
parent
commit
08b7414bc7
  1. 4
      modules/qingyuan/src/main/java/com/thing/qingyuan/board/dto/EnergyDayDataDTO.java
  2. 269
      modules/qingyuan/src/main/java/com/thing/qingyuan/board/service/impl/BoardNewServiceImpl.java

4
modules/qingyuan/src/main/java/com/thing/qingyuan/board/dto/EnergyDayDataDTO.java

@ -16,6 +16,6 @@ public class EnergyDayDataDTO {
private BigDecimal steamDayValue;
@Schema(description = "日压缩空气量")
private BigDecimal airDayValue;
@Schema(description = "天然气量")
private BigDecimal gasValue;
@Schema(description = "天然气量")
private BigDecimal gasDayValue;
}

269
modules/qingyuan/src/main/java/com/thing/qingyuan/board/service/impl/BoardNewServiceImpl.java

@ -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) {
@ -561,6 +552,47 @@ 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) {
@ -568,86 +600,42 @@ public class BoardNewServiceImpl implements BoardNewService {
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 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();
@ -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<>();

Loading…
Cancel
Save