13 changed files with 1282 additions and 0 deletions
-
219modules/qingyuan/src/main/java/com/thing/qingyuan/board/controller/BoardNewController.java
-
14modules/qingyuan/src/main/java/com/thing/qingyuan/board/dto/BuildDetailRequestDTO.java
-
16modules/qingyuan/src/main/java/com/thing/qingyuan/board/dto/BuildRequestDTO.java
-
21modules/qingyuan/src/main/java/com/thing/qingyuan/board/dto/CarbonAndConsumptionDataDTO.java
-
19modules/qingyuan/src/main/java/com/thing/qingyuan/board/dto/EnergyBuildDataDTO.java
-
17modules/qingyuan/src/main/java/com/thing/qingyuan/board/dto/EnergyConsumptionDataDTO.java
-
20modules/qingyuan/src/main/java/com/thing/qingyuan/board/dto/EnergyCostProportionDataDTO.java
-
16modules/qingyuan/src/main/java/com/thing/qingyuan/board/dto/EnergyDataAnalyseDTO.java
-
16modules/qingyuan/src/main/java/com/thing/qingyuan/board/dto/EnergyDataAnalyseDetailDTO.java
-
17modules/qingyuan/src/main/java/com/thing/qingyuan/board/dto/EnergyDataDTO.java
-
21modules/qingyuan/src/main/java/com/thing/qingyuan/board/dto/EnergyDayDataDTO.java
-
33modules/qingyuan/src/main/java/com/thing/qingyuan/board/service/BoardNewService.java
-
853modules/qingyuan/src/main/java/com/thing/qingyuan/board/service/impl/BoardNewServiceImpl.java
@ -0,0 +1,219 @@ |
|||
package com.thing.qingyuan.board.controller; |
|||
|
|||
|
|||
import com.thing.common.core.web.response.Result; |
|||
import com.thing.qingyuan.board.dto.*; |
|||
import com.thing.qingyuan.board.service.BoardNewService; |
|||
import io.swagger.v3.oas.annotations.Operation; |
|||
import io.swagger.v3.oas.annotations.Parameter; |
|||
import io.swagger.v3.oas.annotations.Parameters; |
|||
import io.swagger.v3.oas.annotations.tags.Tag; |
|||
import lombok.RequiredArgsConstructor; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import java.time.LocalDate; |
|||
import java.time.format.DateTimeFormatter; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 看板 |
|||
* |
|||
* @author wzf 56583086@qq.com |
|||
* @since 1.0.0 2020-09-06 |
|||
*/ |
|||
|
|||
@RestController |
|||
@RequestMapping("/board") |
|||
@Tag(name = "看板") |
|||
@RequiredArgsConstructor |
|||
public class BoardNewController { |
|||
|
|||
private final BoardNewService boardService; |
|||
|
|||
@GetMapping("eachEnergy") |
|||
@Operation(summary = "月用能统计") |
|||
@Parameters({ |
|||
@Parameter(name = "day", description = "日期:例如2023-06-01", required = true) |
|||
}) |
|||
public Result<EnergyDayDataDTO> getEachEnergy(@Parameter(hidden = true) @RequestParam Map<String, Object> params){ |
|||
String day; |
|||
if (params.get("day") != null){ |
|||
day = params.get("day").toString(); |
|||
}else{ |
|||
LocalDate currentDate = LocalDate.now(); |
|||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
|||
day = currentDate.format(formatter); |
|||
} |
|||
EnergyDayDataDTO result = boardService.getEachEnergy(day); |
|||
return new Result<EnergyDayDataDTO>().ok(result); |
|||
} |
|||
|
|||
@GetMapping("eachEnergyYear") |
|||
@Operation(summary ="年用能统计") |
|||
@Parameters({ |
|||
@Parameter(name = "day", description = "日期:例如2023-06-01", required = true) |
|||
}) |
|||
public Result<EnergyDayDataDTO> getYearEachEnergy(@Parameter(hidden = true) @RequestParam Map<String, Object> params){ |
|||
String day; |
|||
if (params.get("day") != null){ |
|||
day = params.get("day").toString(); |
|||
}else{ |
|||
LocalDate currentDate = LocalDate.now(); |
|||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
|||
day = currentDate.format(formatter); |
|||
} |
|||
EnergyDayDataDTO result = boardService.getEachYearEnergy(day); |
|||
return new Result<EnergyDayDataDTO>().ok(result); |
|||
} |
|||
|
|||
@GetMapping("energyConsumption") |
|||
@Operation(summary ="能耗统计") |
|||
@Parameters({ |
|||
@Parameter(name = "day", description = "日期:例如2023-06-01", required = true) |
|||
}) |
|||
public Result<EnergyConsumptionDataDTO> getEnergyConsumption(@Parameter(hidden = true) @RequestParam Map<String, Object> params){ |
|||
String day; |
|||
if (params.get("day") != null){ |
|||
day = params.get("day").toString(); |
|||
}else{ |
|||
LocalDate currentDate = LocalDate.now(); |
|||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
|||
day = currentDate.format(formatter); |
|||
} |
|||
EnergyConsumptionDataDTO result = boardService.getEnergyConsumption(day); |
|||
return new Result<EnergyConsumptionDataDTO>().ok(result); |
|||
} |
|||
|
|||
@GetMapping("carbonAndConsumption") |
|||
@Operation(summary ="碳排和综合能耗数据") |
|||
@Parameters({ |
|||
@Parameter(name = "day", description = "日期:例如2023-06-01", required = true) |
|||
}) |
|||
public Result<CarbonAndConsumptionDataDTO> getCarbonAndConsumption(@Parameter(hidden = true) @RequestParam Map<String, Object> params){ |
|||
String day; |
|||
if (params.get("day") != null){ |
|||
day = params.get("day").toString(); |
|||
}else{ |
|||
LocalDate currentDate = LocalDate.now(); |
|||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
|||
day = currentDate.format(formatter); |
|||
} |
|||
CarbonAndConsumptionDataDTO result = boardService.getCarbonAndConsumption(day); |
|||
return new Result<CarbonAndConsumptionDataDTO>().ok(result); |
|||
} |
|||
|
|||
@GetMapping("energyCost") |
|||
@Operation(summary ="能耗费用统计") |
|||
@Parameters({ |
|||
@Parameter(name = "day", description = "日期:例如2023-06-01", required = true) |
|||
}) |
|||
public Result<List<EnergyCostProportionDataDTO>> getEnergyCost(@Parameter(hidden = true) @RequestParam Map<String, Object> params){ |
|||
String day; |
|||
if (params.get("day") != null){ |
|||
day = params.get("day").toString(); |
|||
}else{ |
|||
LocalDate currentDate = LocalDate.now(); |
|||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
|||
day = currentDate.format(formatter); |
|||
} |
|||
List<EnergyCostProportionDataDTO> result = boardService.getEnergyCost(day); |
|||
return new Result<List<EnergyCostProportionDataDTO>>().ok(result); |
|||
} |
|||
|
|||
@GetMapping("monthEnergy/ranking") |
|||
@Operation(summary ="月用能排行") |
|||
@Parameters({ |
|||
@Parameter(name = "month", description = "日期:例如2023-06", required = true), |
|||
@Parameter(name = "type", description = "类型:传参:电/水/蒸汽/压缩空气", required = true) |
|||
}) |
|||
public Result<List<EnergyDataDTO>> getMonthEnergyRanking(@Parameter(hidden = true) @RequestParam Map<String, Object> params){ |
|||
String key = "A29mm"; |
|||
String type = params.get("type").toString(); |
|||
if ("电".equals(type)){ |
|||
key = "A29mm"; |
|||
}else if("水".equals(type)){ |
|||
key = "B2mm"; |
|||
}else if("蒸汽".equals(type)){ |
|||
key = "E3mm"; |
|||
}else if("压缩空气".equals(type)){ |
|||
key = "D2mm"; |
|||
} |
|||
String month; |
|||
if (params.get("month") != null){ |
|||
month = params.get("month").toString(); |
|||
}else{ |
|||
LocalDate currentDate = LocalDate.now(); |
|||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM"); |
|||
month = currentDate.format(formatter); |
|||
} |
|||
List<EnergyDataDTO> result = boardService.getMonthEnergyRanking(month,key,type); |
|||
return new Result<List<EnergyDataDTO>>().ok(result); |
|||
} |
|||
|
|||
@GetMapping("monthEnergy/analyse") |
|||
@Operation(summary ="月用能趋势") |
|||
@Parameters({ |
|||
@Parameter(name = "month", description = "日期:例如2023-06", required = true), |
|||
@Parameter(name = "type", description = "类型:传参:电/水/蒸汽/压缩空气", required = true) |
|||
}) |
|||
public Result<EnergyDataAnalyseDTO> qcMonthEnergyAnalyse(@Parameter(hidden = true) @RequestParam Map<String, Object> params){ |
|||
String key = "A29dd"; |
|||
String type = params.get("type").toString(); |
|||
if ("电".equals(type)){ |
|||
key = "A29dd"; |
|||
}else if("水".equals(type)){ |
|||
key = "B2dd"; |
|||
}else if("蒸汽".equals(type)){ |
|||
key = "E3dd"; |
|||
}else if("压缩空气".equals(type)){ |
|||
key = "D2dd"; |
|||
} |
|||
String month; |
|||
if (params.get("month") != null){ |
|||
month = params.get("month").toString(); |
|||
}else{ |
|||
LocalDate currentDate = LocalDate.now(); |
|||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM"); |
|||
month = currentDate.format(formatter); |
|||
} |
|||
EnergyDataAnalyseDTO result = boardService.qcMonthEnergyAnalyse(month,key,type); |
|||
return new Result<EnergyDataAnalyseDTO>().ok(result); |
|||
} |
|||
|
|||
@GetMapping("qcDayLoad/analyse") |
|||
@Operation(summary ="日用电负荷") |
|||
@Parameters({ |
|||
@Parameter(name = "day", description = "日期:例如2023-06-01", required = true) |
|||
}) |
|||
public Result<EnergyDataAnalyseDTO> qcDayLoadAnalyse(@Parameter(hidden = true) @RequestParam Map<String, Object> params){ |
|||
String day; |
|||
if (params.get("day") != null){ |
|||
day = params.get("day").toString(); |
|||
}else{ |
|||
LocalDate currentDate = LocalDate.now(); |
|||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
|||
day = currentDate.format(formatter); |
|||
} |
|||
EnergyDataAnalyseDTO result = boardService.qcDayLoadAnalyse(day); |
|||
return new Result<EnergyDataAnalyseDTO>().ok(result); |
|||
} |
|||
|
|||
@PostMapping("build/data") |
|||
@Operation(summary ="建筑对应用能") |
|||
public Result<EnergyBuildDataDTO> getBuildEnergy(@RequestBody BuildRequestDTO dto){ |
|||
if (StringUtils.isBlank(dto.getMonth())){ |
|||
LocalDate currentDate = LocalDate.now(); |
|||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM"); |
|||
String month = currentDate.format(formatter); |
|||
dto.setMonth(month); |
|||
} |
|||
EnergyBuildDataDTO result = boardService.getBuildEnergy(dto); |
|||
return new Result<EnergyBuildDataDTO>().ok(result); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
package com.thing.qingyuan.board.dto; |
|||
|
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Data; |
|||
|
|||
@Data |
|||
public class BuildDetailRequestDTO { |
|||
|
|||
@Schema(description = "物编号") |
|||
private String code; |
|||
@Schema(description = "属性:电A29,水B2,蒸汽E3,压缩空气D2") |
|||
private String key; |
|||
|
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
package com.thing.qingyuan.board.dto; |
|||
|
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Data; |
|||
|
|||
import java.util.List; |
|||
|
|||
@Data |
|||
public class BuildRequestDTO { |
|||
|
|||
@Schema(description = "月份") |
|||
private String month; |
|||
|
|||
@Schema(description = "物编号及属性") |
|||
private List<BuildDetailRequestDTO> datas; |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
package com.thing.qingyuan.board.dto; |
|||
|
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Data; |
|||
|
|||
import java.math.BigDecimal; |
|||
|
|||
@Data |
|||
public class CarbonAndConsumptionDataDTO { |
|||
|
|||
@Schema(description = "日碳排") |
|||
private BigDecimal dayCarbon; |
|||
@Schema(description = "日能耗") |
|||
private BigDecimal dayConsumptionValue; |
|||
@Schema(description = "月能耗") |
|||
private BigDecimal monthConsumptionValue; |
|||
@Schema(description = "年碳排") |
|||
private BigDecimal yearCarbon; |
|||
@Schema(description = "年能耗") |
|||
private BigDecimal yearConsumptionValue; |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
package com.thing.qingyuan.board.dto; |
|||
|
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Data; |
|||
|
|||
import java.math.BigDecimal; |
|||
|
|||
@Data |
|||
public class EnergyBuildDataDTO { |
|||
|
|||
@Schema(description = "用电量") |
|||
private BigDecimal electricValue; |
|||
@Schema(description = "用水量") |
|||
private BigDecimal waterValue; |
|||
@Schema(description = "蒸汽量") |
|||
private BigDecimal steamValue; |
|||
@Schema(description = "压缩空气量") |
|||
private BigDecimal airValue; |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
package com.thing.qingyuan.board.dto; |
|||
|
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Data; |
|||
|
|||
import java.math.BigDecimal; |
|||
|
|||
@Data |
|||
public class EnergyConsumptionDataDTO { |
|||
|
|||
@Schema(description = "日能耗") |
|||
private BigDecimal dayValue; |
|||
@Schema(description = "月能耗") |
|||
private BigDecimal monthValue; |
|||
@Schema(description = "年能耗") |
|||
private BigDecimal yearValue; |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
package com.thing.qingyuan.board.dto; |
|||
|
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Data; |
|||
|
|||
import java.math.BigDecimal; |
|||
|
|||
@Data |
|||
public class EnergyCostProportionDataDTO { |
|||
|
|||
@Schema(description = "能源名称") |
|||
private String name; |
|||
|
|||
@Schema(description = "值") |
|||
private BigDecimal value; |
|||
|
|||
@Schema(description = "占比") |
|||
private String proportion; |
|||
|
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
package com.thing.qingyuan.board.dto; |
|||
|
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Data; |
|||
|
|||
import java.util.List; |
|||
|
|||
@Data |
|||
public class EnergyDataAnalyseDTO { |
|||
|
|||
@Schema(description = "当前月数据") |
|||
private List<EnergyDataAnalyseDetailDTO> currentMonthData; |
|||
// @ApiModelProperty(value = "上月数据") |
|||
// private List<EnergyDataAnalyseDetailDTO> lastMonthData; |
|||
|
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
package com.thing.qingyuan.board.dto; |
|||
|
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Data; |
|||
|
|||
import java.math.BigDecimal; |
|||
|
|||
@Data |
|||
public class EnergyDataAnalyseDetailDTO { |
|||
|
|||
@Schema(description = "日期") |
|||
private String date; |
|||
@Schema(description = "用量") |
|||
private BigDecimal value; |
|||
|
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
package com.thing.qingyuan.board.dto; |
|||
|
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Data; |
|||
|
|||
import java.math.BigDecimal; |
|||
|
|||
@Data |
|||
public class EnergyDataDTO { |
|||
|
|||
@Schema(description = "物名称") |
|||
private String thingName; |
|||
|
|||
@Schema(description = "值") |
|||
private BigDecimal value; |
|||
|
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
package com.thing.qingyuan.board.dto; |
|||
|
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Data; |
|||
|
|||
import java.math.BigDecimal; |
|||
|
|||
@Data |
|||
public class EnergyDayDataDTO { |
|||
|
|||
@Schema(description = "日用电量") |
|||
private BigDecimal electricDayValue; |
|||
@Schema(description = "日水电量") |
|||
private BigDecimal waterDayValue; |
|||
@Schema(description = "日蒸汽电量") |
|||
private BigDecimal steamDayValue; |
|||
@Schema(description = "日压缩空气量") |
|||
private BigDecimal airDayValue; |
|||
@Schema(description = "天然气量") |
|||
private BigDecimal gasValue; |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
package com.thing.qingyuan.board.service; |
|||
|
|||
|
|||
import com.thing.qingyuan.board.dto.*; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 看板 |
|||
* |
|||
* @author wzf 56583086@qq.com |
|||
* @since 1.0.0 2020-09-27 |
|||
*/ |
|||
public interface BoardNewService { |
|||
|
|||
EnergyDayDataDTO getEachEnergy(String day); |
|||
|
|||
EnergyDataAnalyseDTO qcDayLoadAnalyse(String day); |
|||
|
|||
EnergyConsumptionDataDTO getEnergyConsumption(String day); |
|||
|
|||
CarbonAndConsumptionDataDTO getCarbonAndConsumption(String day); |
|||
|
|||
List<EnergyCostProportionDataDTO> getEnergyCost(String day); |
|||
|
|||
List<EnergyDataDTO> getMonthEnergyRanking(String month, String key, String type); |
|||
|
|||
EnergyDataAnalyseDTO qcMonthEnergyAnalyse(String month, String key, String type); |
|||
|
|||
EnergyDayDataDTO getEachYearEnergy(String day); |
|||
|
|||
EnergyBuildDataDTO getBuildEnergy(BuildRequestDTO dto); |
|||
} |
|||
@ -0,0 +1,853 @@ |
|||
package com.thing.qingyuan.board.service.impl; |
|||
|
|||
import cn.hutool.core.collection.CollectionUtil; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.thing.common.core.utils.DateTimeUtils; |
|||
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 lombok.RequiredArgsConstructor; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.math.BigDecimal; |
|||
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; |
|||
|
|||
/** |
|||
* 看板 |
|||
* |
|||
* @author WangJunLong 56583086@qq.com |
|||
* @since 1.0.0 2020-09-27 |
|||
*/ |
|||
@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; |
|||
|
|||
@Override |
|||
public EnergyDataAnalyseDTO qcDayLoadAnalyse(String day) { |
|||
EnergyDataAnalyseDTO result = new EnergyDataAnalyseDTO(); |
|||
List<EnergyDataAnalyseDetailDTO> currentMonthData = new ArrayList<>(); |
|||
//当日开始结束时间 |
|||
String dayStartTime = day + " 00:00:00"; |
|||
String dayEndTime = day + " 23:59:59"; |
|||
//将当月时间转换为时间戳 |
|||
Long dayStartTimeStamp = DateTimeUtils.dateToStamp(dayStartTime); |
|||
//当月结束时间 |
|||
Long dayEndTimeStamp = DateTimeUtils.dateToStamp(dayEndTime); |
|||
|
|||
/** |
|||
* 参数格式:{"总用电": "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); |
|||
// } |
|||
// } |
|||
result.setCurrentMonthData(currentMonthData); |
|||
return result; |
|||
} |
|||
|
|||
|
|||
@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); |
|||
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) { |
|||
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; |
|||
} |
|||
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"); |
|||
} |
|||
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)+"%"); |
|||
} |
|||
} |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
@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) { |
|||
EnergyDataAnalyseDTO result = new EnergyDataAnalyseDTO(); |
|||
List<EnergyDataAnalyseDetailDTO> currentMonthData = new ArrayList<>(); |
|||
//当日开始结束时间 |
|||
String dayStartTime = month + "-01 00:00:00"; |
|||
String dayEndTime = getLastDayOfMonth(month); |
|||
//将当月时间转换为时间戳 |
|||
Long dayStartTimeStamp = DateTimeUtils.dateToStamp(dayStartTime); |
|||
//当月结束时间 |
|||
Long dayEndTimeStamp = DateTimeUtils.dateToStamp(dayEndTime); |
|||
/** |
|||
* 总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); |
|||
// } |
|||
// } |
|||
result.setCurrentMonthData(currentMonthData); |
|||
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"); |
|||
|
|||
/** |
|||
* 总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)); |
|||
// } |
|||
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; |
|||
|
|||
if (CollectionUtil.isEmpty(dto.getDatas())){ |
|||
return result; |
|||
} |
|||
List<BuildDetailRequestDTO> datas = dto.getDatas(); |
|||
for (BuildDetailRequestDTO requestDTO:datas){ |
|||
/** |
|||
* todo ,获取各用能数据 |
|||
*/ |
|||
// ThingsDTO thingsDTO = thingsService.getThingsByCode(requestDTO.getCode()); |
|||
// if (thingsDTO!=null && StringUtils.isNotBlank(thingsDTO.getEntityId())){ |
|||
// DeviceId deviceId = new DeviceId(UUID.fromString(thingsDTO.getEntityId())); |
|||
// //当日 |
|||
// List<String> keys = new ArrayList<>(); |
|||
// String key = requestDTO.getKey(); |
|||
// keys.add(key+"mm"); |
|||
// List<TsKvEntry> dayTsKvEntries = newRestClientUtils.getTimeseries(deviceId,keys,dayStartTimeStamp-5*60000L,dayEndTimeStamp,true); |
|||
// if (CollectionUtil.isNotEmpty(dayTsKvEntries)){ |
|||
// TsKvEntry tsKvEntry = dayTsKvEntries.get(0); |
|||
// if (tsKvEntry.getValue()!=null){ |
|||
// if ("A29".equals(key)){ |
|||
// result.setElectricValue(new BigDecimal(tsKvEntry.getValue().toString()).setScale(2,BigDecimal.ROUND_HALF_UP)); |
|||
// }else if("B2".equals(key)){ |
|||
// result.setWaterValue(new BigDecimal(tsKvEntry.getValue().toString()).setScale(2,BigDecimal.ROUND_HALF_UP)); |
|||
// }else if("E3".equals(key)){ |
|||
// result.setSteamValue(new BigDecimal(tsKvEntry.getValue().toString()).setScale(2,BigDecimal.ROUND_HALF_UP)); |
|||
// }else if("D2".equals(key)){ |
|||
// result.setAirValue(new BigDecimal(tsKvEntry.getValue().toString()).setScale(2,BigDecimal.ROUND_HALF_UP)); |
|||
// } |
|||
// } |
|||
// } |
|||
// } |
|||
} |
|||
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"); |
|||
|
|||
/** |
|||
* 总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<>(); |
|||
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)); |
|||
// } |
|||
|
|||
|
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue