diff --git a/modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/controller/ManageBoardController.java b/modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/controller/ManageBoardController.java index fc9943c..6b64e92 100644 --- a/modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/controller/ManageBoardController.java +++ b/modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/controller/ManageBoardController.java @@ -56,12 +56,6 @@ public class ManageBoardController { return boardService.totalInfo(); } - @PostMapping ("reduction") - @Operation(summary="管理端主平台-光伏节能减排信息") - private Result reduction(){ - return boardService.reduction(); - } - @GetMapping ("alertList") @Operation(summary="管理端主平台,光伏子平台-光伏项目告警记录列表") private Result> alertList(){ diff --git a/modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/controller/PlantController.java b/modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/controller/PlantController.java index ab38756..2b1b4ac 100644 --- a/modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/controller/PlantController.java +++ b/modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/controller/PlantController.java @@ -1,6 +1,9 @@ package com.thing.qingyuan.manageboard.controller; +import com.thing.qingyuan.manageboard.dto.PhotovoltaicDTO; +import com.thing.qingyuan.manageboard.dto.PhotovoltaicOverviewDTO; import com.thing.qingyuan.manageboard.dto.PlantDTO; +import com.thing.qingyuan.manageboard.dto.ReductionStatistics; import com.thing.qingyuan.manageboard.service.PlantService; import com.thing.common.core.annotation.LogOperation; import com.thing.common.core.constants.Constant; @@ -53,6 +56,27 @@ public class PlantController { return new Result().ok(data); } + @GetMapping("getById") + @Operation(summary="信息") + public Result getById(Long id){ + PhotovoltaicDTO data = plantService.findById(id); + return new Result().ok(data); + } + + @GetMapping("overview") + @Operation(summary="获取光伏概览数据信息") + public Result getOverview(){ + PhotovoltaicOverviewDTO data = plantService.getOverview(); + return new Result().ok(data); + } + + @PostMapping ("reduction") + @Operation(summary="管理端主平台-光伏节能减排信息") + private Result reduction(){ + return plantService.reduction(); + } + + @GetMapping("list") @Operation(summary="电站列表信息") public Result> list(@RequestParam Map params){ diff --git a/modules/qingyuan/src/main/java/com/thing/qingyuan/photovoltaic/dto/PhotovoltaicDTO.java b/modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/dto/PhotovoltaicDTO.java similarity index 96% rename from modules/qingyuan/src/main/java/com/thing/qingyuan/photovoltaic/dto/PhotovoltaicDTO.java rename to modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/dto/PhotovoltaicDTO.java index 2320aac..14adb59 100644 --- a/modules/qingyuan/src/main/java/com/thing/qingyuan/photovoltaic/dto/PhotovoltaicDTO.java +++ b/modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/dto/PhotovoltaicDTO.java @@ -1,4 +1,4 @@ -package com.thing.qingyuan.photovoltaic.dto; +package com.thing.qingyuan.manageboard.dto; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; diff --git a/modules/qingyuan/src/main/java/com/thing/qingyuan/photovoltaic/dto/PhotovoltaicOverviewDTO.java b/modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/dto/PhotovoltaicOverviewDTO.java similarity index 85% rename from modules/qingyuan/src/main/java/com/thing/qingyuan/photovoltaic/dto/PhotovoltaicOverviewDTO.java rename to modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/dto/PhotovoltaicOverviewDTO.java index 59074d8..19129b9 100644 --- a/modules/qingyuan/src/main/java/com/thing/qingyuan/photovoltaic/dto/PhotovoltaicOverviewDTO.java +++ b/modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/dto/PhotovoltaicOverviewDTO.java @@ -1,4 +1,4 @@ -package com.thing.qingyuan.photovoltaic.dto; +package com.thing.qingyuan.manageboard.dto; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -20,7 +20,7 @@ public class PhotovoltaicOverviewDTO implements Serializable { @Serial private static final long serialVersionUID = 1L; - @Schema(description = "光伏数量") + @Schema(description = "光伏电站数量") private BigDecimal num = BigDecimal.ZERO; @Schema(description = "电站装机容量 (单位:kWp)") private BigDecimal capacity = BigDecimal.ZERO; @@ -32,5 +32,7 @@ public class PhotovoltaicOverviewDTO implements Serializable { private BigDecimal energySaveUsage = BigDecimal.ZERO; @Schema(description = "年减排量(单位:tCO2)") private BigDecimal reductionUsage = BigDecimal.ZERO; + @Schema(description = "年收益") + private BigDecimal profit = BigDecimal.ZERO; } \ No newline at end of file diff --git a/modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/dto/PlantDTO.java b/modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/dto/PlantDTO.java index 9557486..9f6a82e 100644 --- a/modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/dto/PlantDTO.java +++ b/modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/dto/PlantDTO.java @@ -52,7 +52,13 @@ public class PlantDTO implements Serializable { @Schema(description = "日照时常") private BigDecimal sunshine; @Schema(description = "电站收益, 每千瓦时发电量减排二氧化碳, 标准化单位") - private String profitco; + private String profitco2; + @Schema(description = "电站收益, 每千瓦时发电量节省标准煤, 标准化单位") + private BigDecimal profitcoal; + @Schema(description = "电站收益, 每千瓦时发电量减排二氧化硫, 标准化单位") + private BigDecimal profitso2; + @Schema(description = "电站收益, 每千瓦时发电量收益") + private BigDecimal unitProfit; @Schema(description = "当年每千瓦时发电量减排二氧化碳量") private String reduction; @Schema(description = "当年发电A29") diff --git a/modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/entity/PlantEntity.java b/modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/entity/PlantEntity.java index b4910db..8b946e8 100644 --- a/modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/entity/PlantEntity.java +++ b/modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/entity/PlantEntity.java @@ -87,4 +87,23 @@ public class PlantEntity implements Serializable { * 日照时常 */ private BigDecimal sunshine; + + /** + * 电站收益, 每千瓦时发电量减排二氧化碳, 标准化单位 + */ + private BigDecimal profitco2; + + /** + * 电站收益, 每千瓦时发电量节省标准煤, 标准化单位 + */ + private BigDecimal profitcoal; + + /** + * 电站收益, 每千瓦时发电量减排二氧化硫, 标准化单位 + */ + private BigDecimal profitso2; + /** + * 电站收益, 每千瓦时发电量收益 + */ + private BigDecimal unitProfit; } \ No newline at end of file diff --git a/modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/service/ManageBoardService.java b/modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/service/ManageBoardService.java index 01fa366..bd895f6 100644 --- a/modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/service/ManageBoardService.java +++ b/modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/service/ManageBoardService.java @@ -17,8 +17,6 @@ public interface ManageBoardService { Result totalInfo(); - Result reduction(); - Result> alertList(); Result findListByAttrCodeAndType(DataParam dataParam); diff --git a/modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/service/PlantService.java b/modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/service/PlantService.java index f18266e..194147c 100644 --- a/modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/service/PlantService.java +++ b/modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/service/PlantService.java @@ -1,9 +1,8 @@ package com.thing.qingyuan.manageboard.service; -import com.thing.qingyuan.manageboard.dto.MapParam; -import com.thing.qingyuan.manageboard.dto.PlantDTO; -import com.thing.qingyuan.manageboard.dto.PlantInfoReq; +import com.thing.common.core.web.response.Result; +import com.thing.qingyuan.manageboard.dto.*; import com.thing.qingyuan.manageboard.entity.PlantEntity; import com.thing.common.orm.service.IBaseService; @@ -18,6 +17,12 @@ import java.util.Map; */ public interface PlantService extends IBaseService { + PhotovoltaicOverviewDTO getOverview(); + + PhotovoltaicDTO findById(Long plantId); + + Result reduction(); + List list(Map params); Map> findByParam(MapParam mapParam); diff --git a/modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/service/impl/ManageBoardServiceImpl.java b/modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/service/impl/ManageBoardServiceImpl.java index 95e9a20..44c4b50 100644 --- a/modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/service/impl/ManageBoardServiceImpl.java +++ b/modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/service/impl/ManageBoardServiceImpl.java @@ -2,6 +2,12 @@ package com.thing.qingyuan.manageboard.service.impl; import cn.hutool.core.util.ObjectUtil; import com.thing.carbon.energyrepory.dto.EnergyTimeLabelData; +import com.thing.common.core.enumeration.AttributeTypeEnum; +import com.thing.common.core.utils.ConvertUtils; +import com.thing.common.core.utils.DateTimeUtils; +import com.thing.common.core.web.response.Result; +import com.thing.common.data.tskv.TsKvDTO; +import com.thing.common.tskv.service.TsKvService; import com.thing.qingyuan.alert.dto.AlertDTO; import com.thing.qingyuan.alert.service.AlertService; import com.thing.qingyuan.manageboard.dto.*; @@ -10,12 +16,6 @@ import com.thing.qingyuan.manageboard.service.ManageBoardService; import com.thing.qingyuan.manageboard.service.PlantService; import com.thing.qingyuan.screen.ScreenData; import com.thing.qingyuan.util.CalculationUtil; -import com.thing.common.core.enumeration.AttributeTypeEnum; -import com.thing.common.core.utils.ConvertUtils; -import com.thing.common.core.utils.DateTimeUtils; -import com.thing.common.core.web.response.Result; -import com.thing.common.data.tskv.TsKvDTO; -import com.thing.common.tskv.service.TsKvService; import com.thing.thing.dict.dto.IotThingDictDTO; import com.thing.thing.dict.service.IotThingDictService; import lombok.RequiredArgsConstructor; @@ -131,27 +131,6 @@ public class ManageBoardServiceImpl implements ManageBoardService { return new Result().ok(result); } - @Override - public Result reduction() { - BigDecimal nowTotalA29yy = this.nowTotalA29yy(); - BigDecimal allTotalA29yy = this.AllTotalA29yy(); - BigDecimal tceRatio = BigDecimal.valueOf(0.0004); - BigDecimal co2Ratio = BigDecimal.valueOf(0.000475); - BigDecimal treeRatio = BigDecimal.valueOf(18.3).divide(BigDecimal.valueOf(40),8,RoundingMode.UP).multiply(BigDecimal.valueOf(1000)); - - ReductionStatistics.ReductionInfo nowYearInfo = new ReductionStatistics.ReductionInfo(); - nowYearInfo.setTce(nowTotalA29yy.multiply(tceRatio).setScale(4,RoundingMode.UP)); - nowYearInfo.setCo2(nowTotalA29yy.multiply(co2Ratio).setScale(4,RoundingMode.UP)); - nowYearInfo.setTree(nowYearInfo.getCo2().multiply(treeRatio).setScale(4,RoundingMode.UP)); - - ReductionStatistics.ReductionInfo allInfo = new ReductionStatistics.ReductionInfo(); - allInfo.setTce(allTotalA29yy.multiply(tceRatio).setScale(4,RoundingMode.UP)); - allInfo.setCo2(allTotalA29yy.multiply(co2Ratio).setScale(4,RoundingMode.UP)); - allInfo.setTree(allInfo.getCo2().multiply(treeRatio).setScale(4,RoundingMode.UP)); - ReductionStatistics result = new ReductionStatistics(nowYearInfo,allInfo); - - return new Result().ok(result); - } @Override public Result> alertList() { @@ -377,18 +356,6 @@ public class ManageBoardServiceImpl implements ManageBoardService { .reduce(BigDecimal.ZERO, BigDecimal::add); } - /** - * 光伏项目所有历史发电量总合 - * @return - */ - private BigDecimal AllTotalA29yy(){ - List list = plantService.list(); - List entityCodes = list.stream().map(PlantEntity::getPlantId).map(String::valueOf).toList(); - List tsKvDTOS = tskvService.findTsKvByCodesAndAttrs(entityCodes,List.of("A29yy"),1701360000000L,System.currentTimeMillis(),false); - return tsKvDTOS.stream() - .map(dto -> new BigDecimal(dto.getVal())) - .reduce(BigDecimal.ZERO, BigDecimal::add); - } /** diff --git a/modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/service/impl/PlantServiceImpl.java b/modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/service/impl/PlantServiceImpl.java index 884d633..0dca8a6 100644 --- a/modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/service/impl/PlantServiceImpl.java +++ b/modules/qingyuan/src/main/java/com/thing/qingyuan/manageboard/service/impl/PlantServiceImpl.java @@ -1,19 +1,23 @@ package com.thing.qingyuan.manageboard.service.impl; import cn.hutool.core.map.MapUtil; +import cn.hutool.core.util.ObjectUtil; import com.google.common.collect.Lists; import com.mybatisflex.core.query.QueryColumn; import com.mybatisflex.core.query.QueryWrapper; +import com.thing.common.core.exception.SysException; import com.thing.common.core.utils.ConvertUtils; +import com.thing.common.core.web.response.Result; import com.thing.common.data.tskv.TsKvDTO; import com.thing.common.orm.service.impl.BaseServiceImpl; import com.thing.common.tskv.service.TsKvService; -import com.thing.qingyuan.manageboard.dto.MapParam; -import com.thing.qingyuan.manageboard.dto.PlantDTO; -import com.thing.qingyuan.manageboard.dto.PlantInfoReq; +import com.thing.qingyuan.basedevice.dto.DeviceDTO; +import com.thing.qingyuan.basedevice.service.IotDeviceService; +import com.thing.qingyuan.manageboard.dto.*; import com.thing.qingyuan.manageboard.entity.PlantEntity; import com.thing.qingyuan.manageboard.mapper.PlantMapper; import com.thing.qingyuan.manageboard.service.PlantService; +import com.thing.qingyuan.util.CalculationUtil; import com.thing.sys.security.context.UserContext; import com.thing.thing.entity.dto.IotThingEntityDTO; import com.thing.thing.entity.service.IotThingEntityService; @@ -28,6 +32,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; +import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; import static com.mybatisflex.core.query.QueryMethods.column; @@ -42,10 +47,23 @@ import static com.mybatisflex.core.query.QueryMethods.column; public class PlantServiceImpl extends BaseServiceImpl implements PlantService { @Resource - IotThingEntityService iotThingEntityService; + private IotThingEntityService thingEntityService; + @Resource + private IotDeviceService iotDeviceService; @Resource private TsKvService tsKvService; + private final static String attrA29dd = "A29dd"; + private final static String attrA29yy = "A29yy"; + private final static String attrA30dd = "A30dd"; + private final static String attrA30yy = "A30yy"; + private final static BigDecimal coefficient = BigDecimal.ONE.divide(BigDecimal.TEN.pow(3)); + //年减排量 + private final static BigDecimal reductionFactor = new BigDecimal("0.475"); + //年节能量 + private final static BigDecimal energySaveFactor = new BigDecimal("0.4"); + + @Override public QueryWrapper getWrapper(Map params){ QueryWrapper wrapper = new QueryWrapper(); @@ -68,6 +86,126 @@ public class PlantServiceImpl extends BaseServiceImpl } + @Override + public PhotovoltaicOverviewDTO getOverview() { + PhotovoltaicOverviewDTO photovoltaicOverviewDTO = new PhotovoltaicOverviewDTO(); + List list = mapper.selectAll(); + if (CollectionUtils.isEmpty(list)) { + return photovoltaicOverviewDTO; + } + //光伏数量 + photovoltaicOverviewDTO.setNum(new BigDecimal(CollectionUtils.size(list))); + //光伏装机容量 + BigDecimal capacity = list.stream().map(PlantEntity::getCapacity).reduce(BigDecimal.ZERO, BigDecimal::add); + photovoltaicOverviewDTO.setCapacity(capacity); + List entityCodes = list.stream().map(PlantEntity::getPlantId).map(Object::toString).toList(); + //获取所有光伏电站的物实体 + Optional> thingEntities = thingEntityService.findByCodes(entityCodes, UserContext.getRealTenantCode(), true); + if (thingEntities.isPresent()) { + List tsKvDTOList = tsKvService.findLatestByCodesAndAttrs(thingEntities.get().stream().map(IotThingEntityDTO::getCode).toList(), Lists.newArrayList(attrA29yy,attrA30yy), false); + if (CollectionUtils.isNotEmpty(tsKvDTOList)) { + //年发电总量 + BigDecimal electricityUsage = tsKvDTOList.stream().filter(s -> StringUtils.equals(s.getAttrKey(), attrA29yy)) + .map(s -> new BigDecimal(s.getVal())).reduce(BigDecimal.ZERO, BigDecimal::add); + BigDecimal performance = CalculationUtil.getPerformance(electricityUsage, new BigDecimal(10000), 2); + photovoltaicOverviewDTO.setElectricityUsage(performance); + //年收益 + AtomicReference incomeTotal = new AtomicReference<>(BigDecimal.ZERO); + for (TsKvDTO tsKvDTO : tsKvDTOList) { + if (!tsKvDTO.getAttrKey().equals(attrA29yy)) { + continue; + } + list.stream() + .filter(s -> StringUtils.equals(s.getPlantId().toString(), tsKvDTO.getThingCode())) + .findFirst() + .ifPresent(s -> { + BigDecimal income = CalculationUtil.income(new BigDecimal(tsKvDTO.getVal()), s.getProfitco2(), 2); + if (income == null) { + income = BigDecimal.ZERO; + } + // 使用 AtomicReference 来修改 incomeTotal + incomeTotal.set(incomeTotal.get().add(income)); + }); + } + // 获取收益 + BigDecimal finalIncomeTotal = incomeTotal.get(); + photovoltaicOverviewDTO.setProfit(finalIncomeTotal); + //上网量 TODO + BigDecimal internetUsage = tsKvDTOList.stream().filter(s -> StringUtils.equals(s.getAttrKey(), attrA30yy)) + .map(s -> new BigDecimal(s.getVal())).reduce(BigDecimal.ZERO, BigDecimal::add); + photovoltaicOverviewDTO.setInternetUsage(internetUsage); + //年节能量 +// BigDecimal energySaveUsage = CalculationUtil.getCarbonUsage(electricityUsage, energySaveFactor, coefficient, 2); +// photovoltaicOverviewDTO.setEnergySaveUsage(energySaveUsage); + //年减排量 +// BigDecimal reductionUsage = CalculationUtil.getCarbonUsage(electricityUsage, reductionFactor, coefficient, 2); +// photovoltaicOverviewDTO.setReductionUsage(reductionUsage); + } + } + return photovoltaicOverviewDTO; + } + + @Override + public PhotovoltaicDTO findById(Long plantId) { + PhotovoltaicDTO photovoltaicDTO = mapper.selectOneByQueryAs(QueryWrapper.create().eq(PlantEntity::getPlantId,plantId),PhotovoltaicDTO.class); + if(ObjectUtil.isNull(photovoltaicDTO)) { + throw new SysException("电站信息不存在,请重新选择"); + } + Optional entityByCode = thingEntityService.findEntityByCode(String.valueOf(photovoltaicDTO.getPlantId()), UserContext.getRealTenantCode(), true); + if (entityByCode.isEmpty()) { + throw new SysException("当前电站实体不存在,请先去物实体管理中添加"); + } + List deviceDTOS = iotDeviceService.findByPlantId(photovoltaicDTO.getPlantId(), 2); + //逆变器数量 + photovoltaicDTO.setInverterNum(CollectionUtils.size(deviceDTOS)); + //调用正常的逆变器状态 + photovoltaicDTO.setPointNormal(BigDecimal.valueOf(deviceDTOS.stream().filter(s-> Objects.equals(s.getStatus(),0)).count())); + //今日发电量(A29dd)和今日上网量(??) + List tsKvDTOList = tsKvService.findLatestByCodeAndAttrs(String.valueOf(photovoltaicDTO.getPlantId()), Lists.newArrayList(attrA29dd, attrA30dd), false); + if (CollectionUtils.isNotEmpty(tsKvDTOList)) { + BigDecimal a29dd = tsKvDTOList.stream() + .filter(s -> StringUtils.equals(attrA29dd, s.getAttrKey())) + .map(s -> new BigDecimal(s.getVal())/*.divide(new BigDecimal("1000"),2, RoundingMode.UP)*/) + .findFirst() + .orElse(BigDecimal.ZERO); + photovoltaicDTO.setElectricityUsage(a29dd); + //今日减碳排量 + BigDecimal carbonUsage = CalculationUtil.getCarbonUsage(a29dd, reductionFactor, BigDecimal.ONE, 2); + photovoltaicDTO.setCarbonUsage(carbonUsage); + //今日上网量 + BigDecimal internetUsage = tsKvDTOList.stream() + .filter(s -> StringUtils.equals(attrA30dd, s.getAttrKey())) + .map(s -> new BigDecimal(s.getVal())) + .findFirst() + .orElse(BigDecimal.ZERO); + photovoltaicDTO.setInternetUsage(internetUsage); + } + return photovoltaicDTO; + } + + @Override + public Result reduction() { + BigDecimal nowTotalA29yy = this.nowTotalA29yy(); + BigDecimal allTotalA29yy = this.AllTotalA29yy(); + BigDecimal tceRatio = BigDecimal.valueOf(0.0004); + BigDecimal co2Ratio = BigDecimal.valueOf(0.000475); + BigDecimal treeRatio = BigDecimal.valueOf(18.3).divide(BigDecimal.valueOf(40),8,RoundingMode.UP).multiply(BigDecimal.valueOf(1000)); + + ReductionStatistics.ReductionInfo nowYearInfo = new ReductionStatistics.ReductionInfo(); + nowYearInfo.setTce(nowTotalA29yy.multiply(tceRatio).setScale(4,RoundingMode.UP)); + nowYearInfo.setCo2(nowTotalA29yy.multiply(co2Ratio).setScale(4,RoundingMode.UP)); + nowYearInfo.setTree(nowYearInfo.getCo2().multiply(treeRatio).setScale(4,RoundingMode.UP)); + + ReductionStatistics.ReductionInfo allInfo = new ReductionStatistics.ReductionInfo(); + allInfo.setTce(allTotalA29yy.multiply(tceRatio).setScale(4,RoundingMode.UP)); + allInfo.setCo2(allTotalA29yy.multiply(co2Ratio).setScale(4,RoundingMode.UP)); + allInfo.setTree(allInfo.getCo2().multiply(treeRatio).setScale(4,RoundingMode.UP)); + ReductionStatistics result = new ReductionStatistics(nowYearInfo,allInfo); + + return new Result().ok(result); + } + + @Override public List list(Map params) { List plantDTOS = listAs(params, PlantDTO.class); @@ -81,14 +219,10 @@ public class PlantServiceImpl extends BaseServiceImpl if(!Objects.isNull(tsKvDTO29)){ plantDTO.setAttrKey29(tsKvDTO29.getAttrKey()); plantDTO.setVal29(tsKvDTO29.getVal()); - //减排量 - if(!Objects.isNull(plantDTO.getProfitco())){ - plantDTO.setReduction( - new BigDecimal(tsKvDTO29.getVal()) - .subtract(new BigDecimal(plantDTO.getProfitco())) - .setScale(4, RoundingMode.HALF_UP) // 保留四位小数,四舍五入 - .toPlainString() - ); + //年减排量 + if(!Objects.isNull(plantDTO.getProfitco2())){ + BigDecimal reductionUsage = CalculationUtil.getCarbonUsage(new BigDecimal(tsKvDTO29.getVal()), reductionFactor, coefficient, 2); + plantDTO.setReduction(reductionUsage.toPlainString()); } } //当前功率 @@ -103,13 +237,9 @@ public class PlantServiceImpl extends BaseServiceImpl plantDTO.setAttrKeyToday29(tsKvDToday29.getAttrKey()); plantDTO.setValToday29(tsKvDToday29.getVal()); //今日减排量 - if(!Objects.isNull(plantDTO.getProfitco())){ - plantDTO.setTodayReduction( - new BigDecimal(tsKvDToday29.getVal()) - .subtract(new BigDecimal(plantDTO.getProfitco())) - .setScale(4, RoundingMode.HALF_UP) // 保留四位小数,四舍五入 - .toPlainString() - ); + if(!Objects.isNull(plantDTO.getProfitco2())){ + BigDecimal reductionUsage = CalculationUtil.getCarbonUsage(new BigDecimal(tsKvDToday29.getVal()), reductionFactor, coefficient, 2); + plantDTO.setTodayReduction(reductionUsage.toPlainString()); } } } @@ -128,7 +258,7 @@ public class PlantServiceImpl extends BaseServiceImpl } List dtos = ConvertUtils.sourceToTarget(this.list(wrapper), PlantDTO.class); dtos.forEach(temp->{ - Optional optional = iotThingEntityService.findEntityByCode(String.valueOf(temp.getPlantId()), UserContext.getRealTenantCode(), true); + Optional optional = thingEntityService.findEntityByCode(String.valueOf(temp.getPlantId()), UserContext.getRealTenantCode(), true); if(optional.isPresent()){ temp.setPlantName(optional.get().getName()); } @@ -148,7 +278,7 @@ public class PlantServiceImpl extends BaseServiceImpl List entities = this.list(wrapper); entities.forEach(temp->{ - Optional optional = iotThingEntityService.findEntityByCode(String.valueOf(temp.getPlantId()), UserContext.getRealTenantCode(), true); + Optional optional = thingEntityService.findEntityByCode(String.valueOf(temp.getPlantId()), UserContext.getRealTenantCode(), true); if(optional.isPresent()){ temp.setPlantName(optional.get().getName()); } @@ -157,4 +287,31 @@ public class PlantServiceImpl extends BaseServiceImpl return ConvertUtils.sourceToTarget(entities,PlantInfoReq.class); } + + /** + * 本年,所有光伏项目总发电量 + * @return + */ + private BigDecimal nowTotalA29yy(){ + List list = this.list(); + List entityCodes = list.stream().map(PlantEntity::getPlantId).map(String::valueOf).toList(); + List tsKvDTOS = tsKvService.findLatestByCodesAndAttrs(entityCodes,List.of("A29yy"),false); + return tsKvDTOS.stream() + .map(dto -> new BigDecimal(dto.getVal())) + .reduce(BigDecimal.ZERO, BigDecimal::add); + } + + /** + * 光伏项目所有历史发电量总合 + * @return + */ + private BigDecimal AllTotalA29yy(){ + List list = this.list(); + List entityCodes = list.stream().map(PlantEntity::getPlantId).map(String::valueOf).toList(); + List tsKvDTOS = tsKvService.findTsKvByCodesAndAttrs(entityCodes,List.of("A29yy"),1701360000000L,System.currentTimeMillis(),false); + return tsKvDTOS.stream() + .map(dto -> new BigDecimal(dto.getVal())) + .reduce(BigDecimal.ZERO, BigDecimal::add); + } + } \ No newline at end of file diff --git a/modules/qingyuan/src/main/java/com/thing/qingyuan/photovoltaic/controller/PhotovoltaicController.java b/modules/qingyuan/src/main/java/com/thing/qingyuan/photovoltaic/controller/PhotovoltaicController.java deleted file mode 100644 index 918729f..0000000 --- a/modules/qingyuan/src/main/java/com/thing/qingyuan/photovoltaic/controller/PhotovoltaicController.java +++ /dev/null @@ -1,129 +0,0 @@ -package com.thing.qingyuan.photovoltaic.controller; - -import com.thing.common.core.annotation.LogOperation; -import com.thing.common.core.web.response.Result; -import com.thing.common.data.tskv.TsKvDTO; -import com.thing.qingyuan.chargeStation.dto.ChargeStatisticRequest; -import com.thing.qingyuan.photovoltaic.dto.PhotovoltaicDTO; -import com.thing.qingyuan.photovoltaic.dto.PhotovoltaicOverviewDTO; -import com.thing.qingyuan.photovoltaic.dto.PhotovoltaicReportDTO; -import com.thing.qingyuan.photovoltaic.service.PhotovoltaicService; -import com.thing.qingyuan.screen.ScreenData; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.servlet.http.HttpServletResponse; -import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.*; - -import java.util.List; -import java.util.Map; - -/** - * 光伏项目点位信息 - * - * @author xc - * @since 3.0 2024-01-29 - */ -@RestController -@RequestMapping("photovoltaic") -@Tag(name="光伏项目点位信息") -@RequiredArgsConstructor -public class PhotovoltaicController { - - private final PhotovoltaicService photovoltaicService; - - - @GetMapping("overview") - @Operation(summary="获取光伏概览数据信息") - public Result getOverview(){ - PhotovoltaicOverviewDTO data = photovoltaicService.getOverview(); - return new Result().ok(data); - } - - @GetMapping("{plantId}") - @Operation(summary="获取电站信息") - public Result get(@PathVariable("plantId") Long plantId){ - PhotovoltaicDTO data = photovoltaicService.findById(plantId); - return new Result().ok(data); - } - - @GetMapping("video/{plantId}") - @Operation(summary="获取视频信息") - public Result getVideo(@PathVariable("plantId") Long plantId){ - PhotovoltaicDTO data = photovoltaicService.findById(plantId); - return new Result().ok(data); - } - - - @GetMapping("heatMap") - @Operation(summary="获取热力图信息") - public Result> getHeatMap(){ - List heatMap = photovoltaicService.getHeatMap(); - return new Result>().ok(heatMap); - } - - @GetMapping("powerAnalysis/{plantId}/{type}") - @Operation(summary="发电分析") - public Result>> powerAnalysis(@PathVariable("plantId") Long plantId,@PathVariable("type") String type){ - Map> resultData = photovoltaicService.getPowerAnalysis(plantId,type); - return new Result>>().ok(resultData); - } - - @GetMapping("electricPowerAnalysis/{plantId}/{type}") - @Operation(summary="发电消纳分析") - public Result>> electricPowerAnalysis(@PathVariable("plantId") Long plantId,@PathVariable("type") String type){ - Map> resultData = photovoltaicService.getElectricPowerAnalysis(plantId,type); - return new Result>>().ok(resultData); - } - - @GetMapping("inverter/{code}") - @Operation(summary="逆变器详情") - public Result>> inverterDetails(@PathVariable String code){ - Map> resultData = photovoltaicService.getInverterDetails(code); - return new Result>>().ok(resultData); - } - - @PostMapping("report/electric") - @Operation(summary="发电报表") - public Result> reportElectric(@RequestBody ChargeStatisticRequest chargeStatisticRequest){ - List reportElectric = photovoltaicService.getReportElectric(chargeStatisticRequest); - return new Result>().ok(reportElectric); - } - - @PostMapping("report/electric/export") - @Operation(summary="发电报表导出") - @LogOperation("发电报表导出") - public void electricExport( @RequestBody ChargeStatisticRequest chargeStatisticRequest, HttpServletResponse response) throws Exception { - photovoltaicService.electricExport(chargeStatisticRequest, response); - } - - @PostMapping("report/consumption") - @Operation(summary="上网消纳量报表") - public Result> reportConsumption(@RequestBody ChargeStatisticRequest chargeStatisticRequest){ - List reportElectric = photovoltaicService.getReportConsumption(chargeStatisticRequest); - return new Result>().ok(reportElectric); - } - - @PostMapping("report/consumption/export") - @Operation(summary="上网消纳量报表导出") - @LogOperation("上网消纳量报表导出") - public void reportElectric(@RequestBody ChargeStatisticRequest chargeStatisticRequest,HttpServletResponse response){ - photovoltaicService.consumptionExport(chargeStatisticRequest, response); - } - -/* @GetMapping("page") - @Operation(summary="分页") - @Parameters({ - @Parameter(name = Constant.PAGE, description = "当前页码,从1开始") , - @Parameter(name = Constant.LIMIT, description = "每页显示记录数") , - @Parameter(name = Constant.ORDER_FIELD, description = "排序字段") , - @Parameter(name = Constant.ORDER, description = "排序方式,可选值(asc、desc)"), - @Parameter(name = Constant.ORDER, description = "排序方式,可选值(asc、desc)") - }) - public Result> page(@RequestParam Map params){ - PageData page = photovoltaicService.getP(params, PlantDTO.class); - return new Result>().ok(page); - }*/ - - -} \ No newline at end of file diff --git a/modules/qingyuan/src/main/java/com/thing/qingyuan/photovoltaic/dto/PhotovoltaicConsumptionDTO.java b/modules/qingyuan/src/main/java/com/thing/qingyuan/photovoltaic/dto/PhotovoltaicConsumptionDTO.java deleted file mode 100644 index cae2d9e..0000000 --- a/modules/qingyuan/src/main/java/com/thing/qingyuan/photovoltaic/dto/PhotovoltaicConsumptionDTO.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.thing.qingyuan.photovoltaic.dto; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import java.io.Serial; -import java.io.Serializable; -import java.math.BigDecimal; - -/** -* 光伏项目概览数据信息 -* -* @author xc -* @since 3.0 2024-01-29 -*/ -@Data -@Schema( description= "消纳报表数据信息") -public class PhotovoltaicConsumptionDTO implements Serializable { - - @Serial - private static final long serialVersionUID = 1L; - - @Schema(description = "发电量") - private BigDecimal electricityUsage = BigDecimal.ZERO; - @Schema(description = "消纳量") - private BigDecimal consumptionUsage = BigDecimal.ZERO; - @Schema(description = "上网量") - private BigDecimal internetUsage = BigDecimal.ZERO; - @Schema(description = "消纳率") - private BigDecimal consumptionRate = BigDecimal.ZERO; - @Schema(description = "时间") - private Long ts ; -} \ No newline at end of file diff --git a/modules/qingyuan/src/main/java/com/thing/qingyuan/photovoltaic/dto/PhotovoltaicReportDTO.java b/modules/qingyuan/src/main/java/com/thing/qingyuan/photovoltaic/dto/PhotovoltaicReportDTO.java deleted file mode 100644 index 072adc0..0000000 --- a/modules/qingyuan/src/main/java/com/thing/qingyuan/photovoltaic/dto/PhotovoltaicReportDTO.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.thing.qingyuan.photovoltaic.dto; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import java.io.Serial; -import java.io.Serializable; -import java.math.BigDecimal; -import java.util.List; -import java.util.Map; - -/** -* 光伏项目概览数据信息 -* -* @author xc -* @since 3.0 2024-01-29 -*/ -@Data -@Schema( description= "光伏和消纳报表数据信息") -public class PhotovoltaicReportDTO implements Serializable { - - @Serial - private static final long serialVersionUID = 1L; - - @Schema(description = "物的id") - private Long thingId; - @Schema(description = "结构编码") - private String code; - @Schema(description = "结构名称") - private String name; - @Schema(description = "发电总量 (单位:kwh)") - private BigDecimal electricityUsage = BigDecimal.ZERO; - @Schema(description = "光伏报表数据,key: ts,val ") - private List> plantDataList; - @Schema(description = "消纳报表总量数据") - private PhotovoltaicConsumptionDTO consumptionTotal; - @Schema(description = "消纳报表数据") - private List consumptionDataList; - @Schema(description = "时间列表:暂时后端使用") - private List timeList; - - -} \ No newline at end of file diff --git a/modules/qingyuan/src/main/java/com/thing/qingyuan/photovoltaic/service/PhotovoltaicService.java b/modules/qingyuan/src/main/java/com/thing/qingyuan/photovoltaic/service/PhotovoltaicService.java deleted file mode 100644 index 94ea616..0000000 --- a/modules/qingyuan/src/main/java/com/thing/qingyuan/photovoltaic/service/PhotovoltaicService.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.thing.qingyuan.photovoltaic.service; - - -import com.thing.common.data.tskv.TsKvDTO; -import com.thing.qingyuan.chargeStation.dto.ChargeStatisticRequest; -import com.thing.qingyuan.photovoltaic.dto.PhotovoltaicDTO; -import com.thing.qingyuan.photovoltaic.dto.PhotovoltaicOverviewDTO; -import com.thing.qingyuan.photovoltaic.dto.PhotovoltaicReportDTO; -import com.thing.qingyuan.screen.ScreenData; -import jakarta.servlet.http.HttpServletResponse; - -import java.util.List; -import java.util.Map; - -/** - * 光伏项目点位信息 - * - * @author xc - * @since 3.0 2024-01-29 - */ -public interface PhotovoltaicService { - - - PhotovoltaicOverviewDTO getOverview(); - - PhotovoltaicDTO findById(Long plantId); - - List findVideoById(Long plantId); - - List getHeatMap(); - - Map> getPowerAnalysis(Long plantId, String type); - - Map> getElectricPowerAnalysis(Long plantId, String type); - - Map> getInverterDetails(String code); - - List getReportElectric(ChargeStatisticRequest chargeStatisticRequest); - - void electricExport(ChargeStatisticRequest chargeStatisticRequest, HttpServletResponse response); - - List getReportConsumption(ChargeStatisticRequest chargeStatisticRequest); - - void consumptionExport(ChargeStatisticRequest chargeStatisticRequest, HttpServletResponse response); -} \ No newline at end of file diff --git a/modules/qingyuan/src/main/java/com/thing/qingyuan/photovoltaic/service/impl/PhotovoltaicServiceImpl.java b/modules/qingyuan/src/main/java/com/thing/qingyuan/photovoltaic/service/impl/PhotovoltaicServiceImpl.java deleted file mode 100644 index 61fa020..0000000 --- a/modules/qingyuan/src/main/java/com/thing/qingyuan/photovoltaic/service/impl/PhotovoltaicServiceImpl.java +++ /dev/null @@ -1,776 +0,0 @@ -package com.thing.qingyuan.photovoltaic.service.impl; - -import cn.afterturn.easypoi.excel.ExcelExportUtil; -import cn.afterturn.easypoi.excel.entity.ExportParams; -import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity; -import cn.hutool.core.collection.CollectionUtil; -import cn.hutool.core.comparator.CompareUtil; -import cn.hutool.core.util.ObjectUtil; -import com.google.common.collect.Lists; -import com.thing.common.core.enumeration.ThingAttrType; -import com.thing.common.core.enumeration.TimeType; -import com.thing.common.core.exception.SysException; -import com.thing.common.core.utils.DateTimeUtils; -import com.thing.common.core.utils.excel.ExcelUtils; -import com.thing.common.data.tskv.TsKvDTO; -import com.thing.common.tskv.service.TsKvService; -import com.thing.qingyuan.basedevice.dto.DeviceDTO; -import com.thing.qingyuan.basedevice.service.IotDeviceService; -import com.thing.qingyuan.chargeStation.dto.ChargeStatisticRequest; -import com.thing.qingyuan.manageboard.entity.PlantEntity; -import com.thing.qingyuan.manageboard.service.PlantService; -import com.thing.qingyuan.photovoltaic.dto.PhotovoltaicConsumptionDTO; -import com.thing.qingyuan.photovoltaic.dto.PhotovoltaicDTO; -import com.thing.qingyuan.photovoltaic.dto.PhotovoltaicOverviewDTO; -import com.thing.qingyuan.photovoltaic.dto.PhotovoltaicReportDTO; -import com.thing.qingyuan.photovoltaic.service.PhotovoltaicService; -import com.thing.qingyuan.screen.ScreenData; -import com.thing.qingyuan.util.CalculationUtil; - -import com.thing.sys.security.context.UserContext; -import com.thing.thing.entity.dto.IotThingEntityDTO; -import com.thing.thing.entity.entity.IotThingEntity; -import com.thing.thing.entity.service.IotThingEntityService; -import jakarta.servlet.http.HttpServletResponse; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.collections4.MapUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.poi.ss.usermodel.Workbook; -import org.springframework.stereotype.Service; - -import java.math.BigDecimal; -import java.math.RoundingMode; -import java.util.*; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -/** - * 光伏项目点位信息 - * - * @author xc - * @since 3.0 2024-01-29 - */ -@Slf4j -@Service -@RequiredArgsConstructor -public class PhotovoltaicServiceImpl implements PhotovoltaicService { - - private final PlantService plantService; - private final IotThingEntityService thingEntityService; - private final TsKvService tsKvService; - private final IotDeviceService iotDeviceService; - - - private final static BigDecimal coefficient = BigDecimal.ONE.divide(BigDecimal.TEN.pow(3)); - private final static BigDecimal reductionFactor = new BigDecimal("0.475"); - private final static BigDecimal energySaveFactor = new BigDecimal("0.4"); - private final static String attrA16 = "A16"; - private final static String attrA29 = "A29"; - private final static String attrA29dd = "A29dd"; - private final static String attrA29mm = "A29mm"; - private final static String attrA30 = "A30"; - private final static String attrA30hh = "A30hh"; - private final static String attrA30dd = "A30dd"; - private final static String attrA30mm = "A30mm"; - private final static String attrA30yy = "A30yy"; - private final static String attrA29yy = "A29yy"; - private final static Long ONE_DAY = 86400000L; - - @Override - public PhotovoltaicOverviewDTO getOverview() { - PhotovoltaicOverviewDTO photovoltaicOverviewDTO = new PhotovoltaicOverviewDTO(); - List list = plantService.list(); - if (CollectionUtils.isNotEmpty(list)) { - photovoltaicOverviewDTO.setNum(new BigDecimal(CollectionUtils.size(list))); - BigDecimal capacity = list.stream().map(PlantEntity::getCapacity).reduce(BigDecimal.ZERO, BigDecimal::add); - photovoltaicOverviewDTO.setCapacity(capacity); - - List entityCodes = list.stream().map(PlantEntity::getPlantId).map(Object::toString).toList(); - Optional> thingEntities = thingEntityService.findByCodes(entityCodes, UserContext.getRealTenantCode(), true); - if (thingEntities.isPresent()) { - List tsKvDTOList = tsKvService.findLatestByCodesAndAttrs(thingEntities.get().stream().map(IotThingEntityDTO::getCode).toList(), Lists.newArrayList(attrA29yy, attrA30yy), false); - if (CollectionUtils.isNotEmpty(tsKvDTOList)) { - //年发电总量 - BigDecimal electricityUsage = tsKvDTOList.stream().filter(s -> StringUtils.equals(s.getAttrKey(), attrA29yy)).map(s -> new BigDecimal(s.getVal())).reduce(BigDecimal.ZERO, BigDecimal::add); - BigDecimal performance = CalculationUtil.getPerformance(electricityUsage, new BigDecimal(10000), 2); - photovoltaicOverviewDTO.setElectricityUsage(performance); - BigDecimal internetUsage = tsKvDTOList.stream().filter(s -> StringUtils.equals(s.getAttrKey(), attrA30yy)).map(s -> new BigDecimal(s.getVal())).reduce(BigDecimal.ZERO, BigDecimal::add); - photovoltaicOverviewDTO.setInternetUsage(internetUsage); - //年节能量 - BigDecimal energySaveUsage = CalculationUtil.getCarbonUsage(electricityUsage, energySaveFactor, coefficient, 2); - photovoltaicOverviewDTO.setEnergySaveUsage(energySaveUsage); - //年减排量 - BigDecimal reductionUsage = CalculationUtil.getCarbonUsage(electricityUsage, reductionFactor, coefficient, 2); - photovoltaicOverviewDTO.setReductionUsage(reductionUsage); - } - } - } - return photovoltaicOverviewDTO; - } - - @Override - public PhotovoltaicDTO findById(Long plantId) { - PhotovoltaicDTO photovoltaicDTO = plantService.getByIdAs(plantId, PhotovoltaicDTO.class); - if (ObjectUtil.isNull(photovoltaicDTO)) { - throw new SysException("电站信息不存在,请重新选择"); - } - Optional entityByCode = thingEntityService.findEntityByCode(String.valueOf(photovoltaicDTO.getPlantId()), UserContext.getRealTenantCode(), true); - if (entityByCode.isEmpty()) { - throw new SysException("当前电站实体不存在,请重新选择"); - } - List deviceDTOS = iotDeviceService.findByPlantId(photovoltaicDTO.getPlantId(), 2); - //逆变器数量 - photovoltaicDTO.setInverterNum(CollectionUtils.size(deviceDTOS)); - //今日发电量(A29dd)和今日上网量(??) - List tsKvDTOList = tsKvService.findLatestByCodeAndAttrs(String.valueOf(photovoltaicDTO.getPlantId()), Lists.newArrayList(attrA29dd, attrA30dd), false); - if (CollectionUtils.isNotEmpty(tsKvDTOList)) { - BigDecimal a29dd = tsKvDTOList.stream() - .filter(s -> StringUtils.equals(attrA29dd, s.getAttrKey())) - .map(s -> new BigDecimal(s.getVal())/*.divide(new BigDecimal("1000"),2, RoundingMode.UP)*/) - .findFirst() - .orElse(BigDecimal.ZERO); - photovoltaicDTO.setElectricityUsage(a29dd); - //今日减碳排量 - // BigDecimal carbonUsage = CalculationUtil.getCarbonUsage(a29dd, reductionFactor, coefficient, 2); - BigDecimal carbonUsage = CalculationUtil.getCarbonUsage(a29dd, reductionFactor, BigDecimal.ONE, 2); - photovoltaicDTO.setCarbonUsage(carbonUsage); - //今日上网量 - BigDecimal internetUsage = tsKvDTOList.stream() - .filter(s -> StringUtils.equals(attrA30dd, s.getAttrKey())) - .map(s -> new BigDecimal(s.getVal())) - .findFirst() - .orElse(BigDecimal.ZERO); - photovoltaicDTO.setInternetUsage(internetUsage); - } - //调用大华视频接口,获取检测点数,获取正常和总数 - return photovoltaicDTO; - } - - @Override - public List findVideoById(Long plantId) { - //调用大华视频接口,获取最新视频数据 - return null; - } - - @Override - public List getHeatMap() { - List list = plantService.list(); - if (CollectionUtils.isEmpty(list)) { - throw new SysException("光伏信息不存在"); - } - List entityCodes = list.stream().map(PlantEntity::getPlantId).map(String::valueOf).toList(); - Optional> entityDTOList = thingEntityService.findByCodes(entityCodes, UserContext.getRealTenantCode(), true); - if (entityDTOList.isEmpty()) { - throw new SysException("光伏信息不存在"); - } - return list.stream().flatMap(s -> { - ScreenData screenData = new ScreenData(); - IotThingEntityDTO iotThingEntity = entityDTOList.get().stream().filter(t -> StringUtils.equals(s.getPlantId().toString(), t.getCode())).findFirst().orElse(null); - if(ObjectUtil.isNotNull(iotThingEntity)){ - screenData.setId(s.getPlantId()); - screenData.setName(iotThingEntity.getName()); - screenData.setLon(s.getLongitude()); - screenData.setLat(s.getLatitude()); - List attrDataList = Lists.newArrayList(); - //装机容量单独处理 - ScreenData.AttrData attrCapacity = getAttr(null, "capacity", "装机容量", "kWp", s.getCapacity()); - attrDataList.add(attrCapacity); - //日发电量,日上网量,实时功率 - List tsKvDTOList = tsKvService.findLatestByCodeAndAttrs(String.valueOf(s.getPlantId()), Lists.newArrayList(attrA29dd, attrA30dd, attrA16), false); - //发电功率 - ScreenData.AttrData attr16 = getAttr(tsKvDTOList, attrA16, "发电功率", "W", BigDecimal.ZERO); - attrDataList.add(attr16); - //日发电量 - ScreenData.AttrData attrA29 = getAttr(tsKvDTOList, attrA29dd, "日发电量", "kWh", BigDecimal.ZERO); - attrDataList.add(attrA29); - BigDecimal dayUsage = filterAttrVal(tsKvDTOList, attrA29dd); - screenData.setMeasure(dayUsage); - //日上网量 - ScreenData.AttrData attrA30 = getAttr(tsKvDTOList, attrA30dd, "日上网量", "kWh", BigDecimal.ZERO); - attrDataList.add(attrA30); - //性能比 - ScreenData.AttrData performance = getAttr(null, "performance", "性能比", "", - CalculationUtil.getPerformance(filterAttrVal(tsKvDTOList, attrA16).divide(new BigDecimal("1000")), s.getCapacity(), 2)); - attrDataList.add(performance); - screenData.setData(attrDataList); - return Stream.of(screenData); - } - return null; - }).collect(Collectors.toList()); - } - - @Override - public Map> getPowerAnalysis(Long plantId, String type) { - Map> result = new HashMap<>(); - Optional entityByCode = thingEntityService.findEntityByCode(plantId.toString(), UserContext.getRealTenantCode(), true); - //获取今天的开始时间和结束时间 - String dayBeginTime = DateTimeUtils.getDayBeginTime(); - Long startTimeT = DateTimeUtils.convertTimeToLong(dayBeginTime); - //获取昨天的开始时间和结束时间 - Long endTimeT = startTimeT + ONE_DAY - 1; - Long startTimeY = startTimeT - ONE_DAY; - Long endTimeY = startTimeT - 1; - String attrCode; - if (StringUtils.equals(type, "2")) { - attrCode = attrA30hh; - } else { - attrCode = attrA16; - } - List tsKvDTOST = tsKvService.findTsKvByCodeAndAttr(entityByCode.get().getCode(), attrCode, startTimeT, endTimeT, true); - tsKvDTOST.forEach(temp->{ - temp.setTs(getStartOfHour(temp.getTs())); - }); - List distinctAndSortedTsKvDTOST = tsKvDTOST.stream() - // 按 ts 字段去重,保留每个 ts 的第一个出现的对象 - .collect(Collectors.collectingAndThen( - Collectors.toMap( - TsKvDTO::getTs, // 假设 TsKvDTO 有 getTs() 方法 - tsKvDTO -> tsKvDTO, - (existing, replacement) -> existing), - map -> map.values().stream().sorted( - (o1, o2) -> o1.getTs().compareTo(o2.getTs()) // 按 ts 字段升序排序 - ).collect(Collectors.toList()) - )); - List tsKvDTOSY = tsKvService.findTsKvByCodeAndAttr(entityByCode.get().getCode(), attrCode, startTimeY, endTimeY, true); - tsKvDTOSY.forEach(temp->{ - temp.setTs(getStartOfHour(temp.getTs())); - }); - List distinctAndSortedTsKvDTOSY = tsKvDTOSY.stream() - // 按 ts 字段去重,保留每个 ts 的第一个出现的对象 - .collect(Collectors.collectingAndThen( - Collectors.toMap( - TsKvDTO::getTs, // 假设 TsKvDTO 有 getTs() 方法 - tsKvDTO -> tsKvDTO, - (existing, replacement) -> existing), - map -> map.values().stream().sorted( - (o1, o2) -> o1.getTs().compareTo(o2.getTs()) // 按 ts 字段升序排序 - ).collect(Collectors.toList()) - )); - List yyTskv = Lists.newArrayList(); - for (int i = 0; i < distinctAndSortedTsKvDTOSY.size(); i++) { - //本期的数据 - TsKvDTO tsKvDTOY = distinctAndSortedTsKvDTOSY.get(i); - Long ts = tsKvDTOY.getTs(); - //同期的数据 - List tsKvDTOT = distinctAndSortedTsKvDTOST.stream().filter(s->s.getTs().compareTo(ts) == 0 ).toList(); - if(CollectionUtil.isEmpty(tsKvDTOT)){ - TsKvDTO yy = new TsKvDTO(tsKvDTOY.getThingCode(), tsKvDTOY.getAttrKey(), ts, "0"); - yyTskv.add(yy); - }else{ - BigDecimal yoy = CalculationUtil.getYOY(new BigDecimal(tsKvDTOT.get(0).getVal()), new BigDecimal(tsKvDTOY.getVal())); - TsKvDTO yy = new TsKvDTO(tsKvDTOY.getThingCode(), tsKvDTOY.getAttrKey(), ts, yoy.toString()); - yyTskv.add(yy); - - } - tsKvDTOY.setVal(new BigDecimal(tsKvDTOY.getVal()).divide(new BigDecimal(1000),2,RoundingMode.HALF_UP).toString()); - } - for (int i = 0; i < distinctAndSortedTsKvDTOST.size(); i++) { - //本期的数据 - TsKvDTO tsKvDTOY = distinctAndSortedTsKvDTOST.get(i); - tsKvDTOY.setVal(new BigDecimal(tsKvDTOY.getVal()).divide(new BigDecimal(1000),2,RoundingMode.HALF_UP).toString()); - } - result.put("today", distinctAndSortedTsKvDTOST); - result.put("yesterday", distinctAndSortedTsKvDTOSY); - result.put("yy", yyTskv); - return result; - } - - - - /** - * 获取指定时间戳所在的整点时间戳 - * - * @param timestamp 时间戳 - * @return 整点时间戳 - */ - public static long getStartOfHour(long timestamp) { - // 将时间戳截断到整点(小时) - return (timestamp / 3600000) * 3600000; - } - - - @Override - public Map> getElectricPowerAnalysis(Long plantId, String type) { - Map> result = new HashMap<>(); - Optional entityByCode = thingEntityService.findEntityByCode(plantId.toString(), UserContext.getRealTenantCode(), true); - if (StringUtils.endsWithIgnoreCase(type, ThingAttrType.YY.getTime().getName())) { - String yearBeginTime = DateTimeUtils.getYearBeginTime(); - Long startTime = DateTimeUtils.convertTimeToLong(yearBeginTime); - String yearEndTime = DateTimeUtils.getYearEndTime(); - Long endTime = DateTimeUtils.convertTimeToLong(yearEndTime); - //时间列表 - List intervalTimeList = DateTimeUtils.getIntervalMonthList(startTime, endTime, 1); - consumption(entityByCode.get(), startTime, endTime, intervalTimeList, attrA29mm, attrA30mm, 1, TimeType.MONTH, result); - } - if (StringUtils.endsWithIgnoreCase(type, ThingAttrType.MM.getTime().getName())) { - String monthBeginTime = DateTimeUtils.getMonthBeginTime(); - Long startTime = DateTimeUtils.convertTimeToLong(monthBeginTime); - String monthEndTime = DateTimeUtils.getMonthEndTime(); - Long endTime = DateTimeUtils.convertTimeToLong(monthEndTime); - List intervalTimeList = DateTimeUtils.getIntervalDayList(startTime, endTime, 1); - consumption(entityByCode.get(), startTime, endTime, intervalTimeList, attrA29dd, attrA30dd, 1, TimeType.DAY, result); - } - return result; - } - - @Override - public Map> getInverterDetails(String code) { - return null; - } - - @Override - public List getReportElectric(ChargeStatisticRequest chargeStatisticRequest) { - List resultList = new ArrayList<>(); - List thingIds = chargeStatisticRequest.getThingIds(); - List entities = thingEntityService.findEntityByIds(thingIds); - if (CollectionUtils.isEmpty(entities)) { - return resultList; - } - List codes = entities.stream().map(IotThingEntityDTO::getCode).toList(); - String attrType = chargeStatisticRequest.getAttrType(); - Long startTime = 0L; - Long endTime = 0L; - List timeList = new ArrayList<>(); - String timeType = chargeStatisticRequest.getTimeType(); - if (StringUtils.equalsIgnoreCase(TimeType.DAY.getName(), timeType)) { - String dayBeginTime = DateTimeUtils.getDayBeginTime(chargeStatisticRequest.getBeginTime()); - startTime = DateTimeUtils.dateToTimestamp(dayBeginTime); - endTime = startTime + ONE_DAY - 1; - timeList = DateTimeUtils.getIntervalList(startTime, endTime, 60 * 60 * 1000); - } - if (StringUtils.equalsIgnoreCase(TimeType.MONTH.getName(), timeType)) { - String monthBeginTime = DateTimeUtils.getMonthBeginTime(chargeStatisticRequest.getBeginTime()); - String monthEndTime = DateTimeUtils.getMonthEndTime(chargeStatisticRequest.getBeginTime()); - startTime = DateTimeUtils.dateToTimestamp(monthBeginTime); - endTime = DateTimeUtils.dateToTimestamp(monthEndTime); - timeList = DateTimeUtils.getIntervalDayList(startTime, endTime, 1); - } - if (StringUtils.equalsIgnoreCase(TimeType.YEAR.getName(), timeType)) { - String monthBeginTime = DateTimeUtils.getYearBeginTime(chargeStatisticRequest.getBeginTime()); - String monthEndTime = DateTimeUtils.getYearEndTime(chargeStatisticRequest.getBeginTime()); - startTime = DateTimeUtils.convertTimeToLong(monthBeginTime); - endTime = DateTimeUtils.convertTimeToLong(monthEndTime); - timeList = DateTimeUtils.getIntervalMonthList(startTime, endTime, 1); - } - if (StringUtils.equalsIgnoreCase(TimeType.ANY.getName(), timeType)) { - startTime = DateTimeUtils.dateToTimestamp(chargeStatisticRequest.getBeginTime()); - endTime = DateTimeUtils.dateToTimestamp(chargeStatisticRequest.getEndTime()); - } - long currentTime = DateTimeUtils.getCurrentTime(); - //去除超过的时间 - timeList.removeIf(s -> CompareUtil.compare(s, currentTime) > 0); - List tsKvList = tsKvService.findTsKvByCodesAndAttrs(codes, Lists.newArrayList(attrA29 + attrType), startTime, endTime, false); - - List finalTimeList = timeList; - if (CollectionUtils.isEmpty(tsKvList)) { - return entities.stream().map(e -> { - PhotovoltaicReportDTO reportDTO = new PhotovoltaicReportDTO(); - reportDTO.setThingId(e.getId()); - reportDTO.setCode(e.getCode()); - reportDTO.setName(e.getName()); - reportDTO.setTimeList(finalTimeList); - return reportDTO; - }).toList(); - } - - return entities.stream().map(e -> { - PhotovoltaicReportDTO reportDTO = new PhotovoltaicReportDTO(); - reportDTO.setThingId(e.getId()); - reportDTO.setCode(e.getCode()); - reportDTO.setName(e.getName()); - reportDTO.setTimeList(finalTimeList); - //过滤数据 - List dataList = tsKvList.stream().filter(tsKvDTO -> StringUtils.equals(tsKvDTO.getThingCode(), e.getCode())).toList(); - - List> collect = Lists.newArrayList(); - for (int i = 0; i < finalTimeList.size(); i++) { - int finalI = i; - List list; - if(i== (finalTimeList.size()-1)){ - list = dataList.stream().filter(s -> CompareUtil.compare(s.getTs(), finalTimeList.get(finalI)) >= 0 ) - .toList(); - }else { - list = dataList.stream().filter(s -> CompareUtil.compare(s.getTs(), finalTimeList.get(finalI)) >= 0 && CompareUtil.compare(s.getTs(), finalTimeList.get(finalI + 1)) < 0).toList(); - } - BigDecimal total = list.stream().map(s -> new BigDecimal(s.getVal())).reduce(BigDecimal.ZERO, BigDecimal::add); - collect.addAll(list.stream().map(data -> Map.of("ts", finalTimeList.get(finalI), "val", total)).toList()); - - } - reportDTO.setPlantDataList(collect); - BigDecimal total = dataList.stream().map(s -> new BigDecimal(s.getVal())).reduce(BigDecimal.ZERO, BigDecimal::add); - reportDTO.setElectricityUsage(total); - return reportDTO; - }).toList(); - } - - @Override - public void electricExport(ChargeStatisticRequest chargeStatisticRequest, HttpServletResponse response) { - List reportDTOList = getReportElectric(chargeStatisticRequest); - //获取动态时间 - List timeList = reportDTOList.get(0).getTimeList(); - //创建表头 - List tableHeaderList = getTableHeader(timeList, chargeStatisticRequest.getTimeType()); - - if (CollectionUtils.isEmpty(reportDTOList)) { - ExportParams exportParams = new ExportParams("发电统计报表", "发电统计"); - Workbook workbook = ExcelExportUtil.exportExcel(exportParams, tableHeaderList, Lists.newArrayList()); - ExcelUtils.downLoadExcel("发电统计报表.xls", response, workbook); - } - List> dataList = new ArrayList<>(); - for (PhotovoltaicReportDTO photovoltaicReportDTO : reportDTOList) { - Map valMap = new HashMap<>(); - valMap.put("name", photovoltaicReportDTO.getName()); - valMap.put("electricityUsage", photovoltaicReportDTO.getElectricityUsage()); - List> plantDataList = photovoltaicReportDTO.getPlantDataList(); - if (CollectionUtils.isNotEmpty(plantDataList)) { - for (Map plantData : plantDataList) { - Long ts = MapUtils.getLong(plantData, "ts"); - String val = MapUtils.getString(plantData, "val"); - valMap.put(String.valueOf(ts), val); - } - } - dataList.add(valMap); - } - ExportParams exportParams = new ExportParams("发电统计报表", "发电统计"); - Workbook workbook = ExcelExportUtil.exportExcel(exportParams, tableHeaderList, dataList); - ExcelUtils.downLoadExcel("发电统计报表.xls", response, workbook); - } - - @Override - public List getReportConsumption(ChargeStatisticRequest chargeStatisticRequest) { - List resultList = new ArrayList<>(); - List thingIds = chargeStatisticRequest.getThingIds(); - List entities = thingEntityService.findEntityByIds(thingIds); - if (CollectionUtils.isEmpty(entities)) { - return resultList; - } - List codes = entities.stream().map(IotThingEntityDTO::getCode).toList(); - String attrType = chargeStatisticRequest.getAttrType(); - Long startTime = 0L; - Long endTime = 0L; - List timeList = new ArrayList<>(); - String timeType = chargeStatisticRequest.getTimeType(); - if (StringUtils.equalsIgnoreCase(TimeType.DAY.getName(), timeType)) { - String dayBeginTime = DateTimeUtils.getDayBeginTime(chargeStatisticRequest.getBeginTime()); - startTime = DateTimeUtils.dateToTimestamp(dayBeginTime); - endTime = startTime + ONE_DAY - 1; - timeList = DateTimeUtils.getIntervalList(startTime, endTime, 60 * 60 * 1000); - } - if (StringUtils.equalsIgnoreCase(TimeType.MONTH.getName(), timeType)) { - String monthBeginTime = DateTimeUtils.getMonthBeginTime(chargeStatisticRequest.getBeginTime()); - String monthEndTime = DateTimeUtils.getMonthEndTime(chargeStatisticRequest.getBeginTime()); - startTime = DateTimeUtils.dateToTimestamp(monthBeginTime); - endTime = DateTimeUtils.dateToTimestamp(monthEndTime); - timeList = DateTimeUtils.getIntervalDayList(startTime, endTime, 1); - } - - if (StringUtils.equalsIgnoreCase(TimeType.YEAR.getName(), timeType)) { - String monthBeginTime = DateTimeUtils.getYearBeginTime(chargeStatisticRequest.getBeginTime()); - String monthEndTime = DateTimeUtils.getYearEndTime(chargeStatisticRequest.getBeginTime()); - startTime = DateTimeUtils.convertTimeToLong(monthBeginTime); - endTime = DateTimeUtils.convertTimeToLong(monthEndTime); - timeList = DateTimeUtils.getIntervalMonthList(startTime, endTime, 1); - } - if (StringUtils.equalsIgnoreCase(TimeType.ANY.getName(), timeType)) { - startTime = DateTimeUtils.dateToTimestamp(chargeStatisticRequest.getBeginTime()); - endTime = DateTimeUtils.dateToTimestamp(chargeStatisticRequest.getEndTime()); - } - - long currentTime = DateTimeUtils.getCurrentTime(); - //去除超过的时间 - timeList.removeIf(s -> CompareUtil.compare(s, currentTime) > 0); - //发电量 - List tsKvList29 = getFillDataList(codes, attrA29 + attrType, startTime, endTime, timeList); - //上网量 - List tsKvList30 = getFillDataList(codes, attrA30 + attrType, startTime, endTime, timeList); - //获取总量 - List finalTimeList = timeList; - entities.forEach(e -> { - PhotovoltaicReportDTO photovoltaicReportDTO = new PhotovoltaicReportDTO(); - photovoltaicReportDTO.setThingId(e.getId()); - photovoltaicReportDTO.setCode(e.getCode()); - photovoltaicReportDTO.setName(e.getName()); - photovoltaicReportDTO.setTimeList(finalTimeList); - List list29 = tsKvList29.stream().filter(tsKvDTO -> StringUtils.equals(tsKvDTO.getThingCode(), e.getCode()) && StringUtils.startsWith(tsKvDTO.getAttrKey(), attrA29)).toList(); - BigDecimal reduce29 = list29.stream().map(s -> new BigDecimal(s.getVal())).reduce(BigDecimal.ZERO, BigDecimal::add); - List list30 = tsKvList30.stream().filter(tsKvDTO -> StringUtils.equals(tsKvDTO.getThingCode(), e.getCode()) && StringUtils.startsWith(tsKvDTO.getAttrKey(), attrA30)).toList(); - BigDecimal reduce30 = list30.stream().map(s -> new BigDecimal(s.getVal())).reduce(BigDecimal.ZERO, BigDecimal::add); - //消纳量 = 发电量 - 上网量 - BigDecimal consumption = reduce29.subtract(reduce30); - //消纳率 - BigDecimal performance = CalculationUtil.getPerformance(consumption, reduce29, 4); - PhotovoltaicConsumptionDTO consumptionTotal = new PhotovoltaicConsumptionDTO(); - consumptionTotal.setElectricityUsage(reduce29); - consumptionTotal.setInternetUsage(reduce30); - consumptionTotal.setConsumptionUsage(consumption); - consumptionTotal.setConsumptionRate(performance); - photovoltaicReportDTO.setConsumptionTotal(consumptionTotal); - //时间段的消纳报表数据 - List consumptionDTOList = Lists.newArrayList(); - - for (int i = 0; i < finalTimeList.size(); i++) { - int finalI = i; - List list2; - List list3; - if(i== (finalTimeList.size()-1)){ - list2 = list29.stream().filter(s -> CompareUtil.compare(s.getTs(), finalTimeList.get(finalI)) >= 0 ) - .toList(); - list3 = list30.stream().filter(s -> CompareUtil.compare(s.getTs(), finalTimeList.get(finalI)) >= 0 ) - .toList(); - }else { - list2 = list29.stream().filter(s -> CompareUtil.compare(s.getTs(), finalTimeList.get(finalI)) >= 0 && CompareUtil.compare(s.getTs(), finalTimeList.get(finalI + 1)) < 0) - .toList(); - list3 = list30.stream().filter(s -> CompareUtil.compare(s.getTs(), finalTimeList.get(finalI)) >= 0 && CompareUtil.compare(s.getTs(), finalTimeList.get(finalI + 1)) < 0) - .toList(); - } - BigDecimal reduce2 = list2.stream().map(s -> new BigDecimal(s.getVal())).reduce(BigDecimal.ZERO, BigDecimal::add); - BigDecimal reduce3 = list3.stream().map(s -> new BigDecimal(s.getVal())).reduce(BigDecimal.ZERO, BigDecimal::add); - PhotovoltaicConsumptionDTO consumptionDTO = new PhotovoltaicConsumptionDTO(); - consumptionDTO.setElectricityUsage(reduce2); - consumptionDTO.setInternetUsage(reduce3); - BigDecimal subtract = reduce2.subtract(reduce3); - consumptionDTO.setConsumptionUsage(subtract); - consumptionDTO.setConsumptionRate(CalculationUtil.getPerformance(subtract, reduce2, 4)); - consumptionDTO.setTs(finalTimeList.get(finalI)); - consumptionDTOList.add(consumptionDTO); - } - photovoltaicReportDTO.setConsumptionDataList(consumptionDTOList); - resultList.add(photovoltaicReportDTO); - }); - return resultList; - } - - @Override - public void consumptionExport(ChargeStatisticRequest chargeStatisticRequest, HttpServletResponse response) { - try { - List reportDTOList = getReportConsumption(chargeStatisticRequest); - //获取动态时间 - List timeList = reportDTOList.get(0).getTimeList(); - //创建表头 - List tableHeaderList = getConsumptionTableHeader(timeList, chargeStatisticRequest.getTimeType()); - if (CollectionUtils.isEmpty(reportDTOList)) { - ExportParams exportParams = new ExportParams("上网消纳报表", "上网消纳"); - Workbook workbook = ExcelExportUtil.exportExcel(exportParams, tableHeaderList, Lists.newArrayList()); - ExcelUtils.downLoadExcel("上网消纳报表.xls", response, workbook); - } - List> dataList = new ArrayList<>(); - for (PhotovoltaicReportDTO photovoltaicReportDTO : reportDTOList) { - Map valMap = new HashMap<>(); - valMap.put("name", photovoltaicReportDTO.getName()); - //发电总量的数据 - PhotovoltaicConsumptionDTO consumptionTotal = photovoltaicReportDTO.getConsumptionTotal(); - List> yhxxList = new ArrayList<>(); - Map yhxxMap = new HashMap<>(); - yhxxMap.put("electricityUsage", consumptionTotal.getElectricityUsage()); - yhxxMap.put("consumptionUsage", consumptionTotal.getConsumptionUsage()); - yhxxMap.put("internetUsage", consumptionTotal.getInternetUsage()); - yhxxMap.put("consumptionRate", consumptionTotal.getConsumptionRate()); - yhxxList.add(yhxxMap); - valMap.put("electricityUsage", yhxxList); - //动态时间量 - List consumptionDataList = photovoltaicReportDTO.getConsumptionDataList(); - consumptionDataList.forEach(c -> { -// int time = 0; -// if (StringUtils.equalsIgnoreCase(TimeType.DAY.getName(), chargeStatisticRequest.getTimeType())){ -// time = DateTimeUtils.parseDateTime(c.getTs()).getHour(); -// } -// if (StringUtils.equalsIgnoreCase(TimeType.MONTH.getName(), chargeStatisticRequest.getTimeType())){ -// time = DateTimeUtils.parseDateTime(c.getTs()).getDayOfMonth(); -// } -// if (StringUtils.equalsIgnoreCase(TimeType.YEAR.getName(), chargeStatisticRequest.getTimeType())){ -// time = DateTimeUtils.parseDateTime(c.getTs()).getMonth().getValue(); -// } - List> yhxxList1 = new ArrayList<>(); - Map yhxxMap1 = new HashMap<>(); - yhxxMap1.put("electricityUsage", c.getElectricityUsage()); - yhxxMap1.put("consumptionUsage", c.getConsumptionUsage()); - yhxxMap1.put("internetUsage", c.getInternetUsage()); - yhxxMap1.put("consumptionRate", c.getConsumptionRate()); - yhxxList1.add(yhxxMap1); - valMap.put(String.valueOf(c.getTs()), yhxxList1); - }); - dataList.add(valMap); - } - ExportParams exportParams = new ExportParams("发电统计报表", "发电统计"); - Workbook workbook = ExcelExportUtil.exportExcel(exportParams, tableHeaderList, dataList); - ExcelUtils.downLoadExcel("发电统计报表.xls", response, workbook); - } catch (Exception e) { - log.error("222222", e); - } - } - - private List getFillDataList(List codes, String attr, Long startTime, Long endTime, List timeList) { - List tsKvList29 = tsKvService.findTsKvByCodesAndAttrs(codes, Lists.newArrayList(attr), startTime, endTime, false); - return codes.stream().flatMap(s -> fillData(timeList, tsKvList29, s, attr).stream()).toList(); - } - - private void consumption(IotThingEntityDTO thingEntityDTO, Long startTime, Long endTime, List intervalTimeList, String attrA29, String attrA30, Integer interval, TimeType timeType, Map> result) { - //月发电量 - List tsKvYYList = tsKvService.findTsKvByCodeAndAttr(thingEntityDTO.getCode(), attrA29, startTime, endTime, true); - //补全数据 - List tsKvDTOS = fillData(intervalTimeList, tsKvYYList, thingEntityDTO.getCode(), attrA29); - //月上网量 - List tsKvYY30List = tsKvService.findTsKvByCodeAndAttr(thingEntityDTO.getCode(), attrA30, startTime, endTime, true); - //List tsKvYY30List = tsKvService.findTsKvIntervalAggByCodeAndAttr(thingEntityDTO.getCode(), attrA30, startTime, endTime, AggType.SUM, interval, timeType, true); - //补全数据 - List tsKv30DTOS = fillData(intervalTimeList, tsKvYY30List, thingEntityDTO.getCode(), attrA30); - //消纳量 - List consumptionTskv = Lists.newArrayList(); - List consumptionTskvRate = Lists.newArrayList(); - for (int i = 0; i < tsKvDTOS.size(); i++) { - TsKvDTO tsKvDTO29 = tsKvDTOS.get(i); - tsKvDTO29.setVal(new BigDecimal(tsKvDTO29.getVal())/*.divide(new BigDecimal(1000), 2, BigDecimal.ROUND_HALF_UP)*/.toPlainString()); - TsKvDTO tsKvDTO30 = tsKv30DTOS.get(i); - //消纳量 - BigDecimal consumption = new BigDecimal(tsKvDTO29.getVal()).subtract(new BigDecimal(tsKvDTO30.getVal())); - TsKvDTO tsKv = new TsKvDTO(thingEntityDTO.getCode(), "consumption", tsKvDTO29.getTs(), consumption.toString()); - consumptionTskv.add(tsKv); - //消纳比 - BigDecimal consumptionPerformance = CalculationUtil.getPerformance(consumption, new BigDecimal(tsKvDTO29.getVal()), 4); - TsKvDTO tsKvDTO = new TsKvDTO(thingEntityDTO.getCode(), "consumptionRate", tsKvDTO29.getTs(), consumptionPerformance.toString()); - consumptionTskvRate.add(tsKvDTO); - } - result.put("A29", tsKvDTOS); - result.put("consumption",consumptionTskv); - result.put("consumptionRate", consumptionTskvRate); - } - - - private ScreenData.AttrData getAttr(List tsKvDTOList, String attrCode, String attrName, String attrUnit, BigDecimal defaultVal) { - ScreenData.AttrData attrData = new ScreenData.AttrData(); - attrData.setAttrCode(attrCode); - attrData.setAttrName(attrName); - attrData.setAttrUnit(attrUnit); - if (CollectionUtils.isNotEmpty(tsKvDTOList)) { - if(attrCode.startsWith(attrA29)){ - //attrData.setAttrValue(filterAttrVal(tsKvDTOList, attrCode).toString()); - attrData.setAttrValue(filterAttrVal(tsKvDTOList, attrCode)/*.divide(new BigDecimal("1000"),2, RoundingMode.UP)*/.toPlainString()); - }else { - attrData.setAttrValue(filterAttrVal(tsKvDTOList, attrCode).divide(new BigDecimal("1000"),2, RoundingMode.UP).toPlainString()); - } - } else { - attrData.setAttrValue(defaultVal.toString()); - } - return attrData; - } - - private static BigDecimal filterAttrVal(List tsKvDTOList, String attrCode) { - return tsKvDTOList.stream() - .filter(d -> StringUtils.equals(attrCode, d.getAttrKey())) - .map(d -> new BigDecimal(d.getVal())) - .findFirst() - .orElse(BigDecimal.ZERO); - } - - private static List fillData(List intervalTimeList, List tsKvList, String code, String attr) { - if (CollectionUtils.isEmpty(tsKvList)) { - return intervalTimeList.stream() - .map(s -> new TsKvDTO(code, attr, s, "0")) - .collect(Collectors.toList()); - } - if(CollectionUtils.isEmpty(intervalTimeList)){ - return tsKvList; - } - List handleList = tsKvList.stream().filter(d -> StringUtils.equals(code, d.getThingCode()) && StringUtils.equals(attr, d.getAttrKey())).toList(); - Map>> groupedMap = handleList.stream() - .collect(Collectors.groupingBy(TsKvDTO::getThingCode, - Collectors.groupingBy(TsKvDTO::getAttrKey))); - List result = new ArrayList<>(); - for (Map.Entry>> stringMapEntry : groupedMap.entrySet()) { - String thingCode = stringMapEntry.getKey(); - for (Map.Entry> stringListEntry : stringMapEntry.getValue().entrySet()) { - String attrKey = stringListEntry.getKey(); - List value = stringListEntry.getValue(); - List existingTimestamps = value.stream().map(TsKvDTO::getTs).toList(); - for (Long timestamp : intervalTimeList) { - if (existingTimestamps.contains(timestamp)) { - TsKvDTO tsKvDTO1 = value.stream() - .filter(tsKvDTO -> tsKvDTO.getTs().equals(timestamp)) - .findAny().orElse(null); - //电力要/1000 - if (ObjectUtil.isNotNull(tsKvDTO1) && tsKvDTO1.getAttrKey().startsWith(attrA16)) { - BigDecimal performance = CalculationUtil.getPerformance(new BigDecimal(tsKvDTO1.getVal()), new BigDecimal(1000), 2); - tsKvDTO1.setVal(performance.toString()); - } - result.add(tsKvDTO1); - } else { - result.add(new TsKvDTO(thingCode, attrKey, timestamp, "0")); - } - } - } - } - return result; - } - - private List getConsumptionTableHeader(List timeList, String timeType) { - List paramCols = new ArrayList<>(); - ExcelExportEntity colEntity1 = new ExcelExportEntity("结构", "name"); - colEntity1.setNeedMerge(true); - paramCols.add(colEntity1); - ExcelExportEntity colEntity2 = new ExcelExportEntity("发电总量(kWh)", "electricityUsage"); - List yyxxList = new ArrayList<>(); - yyxxList.add(new ExcelExportEntity("发电量", "electricityUsage")); - yyxxList.add(new ExcelExportEntity("消纳量", "consumptionUsage")); - yyxxList.add(new ExcelExportEntity("上网量", "internetUsage")); - yyxxList.add(new ExcelExportEntity("消纳率", "consumptionRate")); - colEntity2.setList(yyxxList); - paramCols.add(colEntity2); - //动态表头集合 - paramCols.addAll(new ArrayList<>(timeList.stream() - .flatMap(c -> { - ExcelExportEntity excelExportEntity = null; - if (StringUtils.equalsIgnoreCase(TimeType.DAY.getName(), timeType)) { - int hour = DateTimeUtils.parseDateTime(c).getHour(); - excelExportEntity = new ExcelExportEntity(hour + "时", String.valueOf(c)); - } - if (StringUtils.equalsIgnoreCase(TimeType.MONTH.getName(), timeType)) { - int day = DateTimeUtils.parseDateTime(c).getDayOfMonth(); - excelExportEntity = new ExcelExportEntity(day + "日", String.valueOf(c)); - } - if (StringUtils.equalsIgnoreCase(TimeType.YEAR.getName(), timeType)) { - int month = DateTimeUtils.parseDateTime(c).getMonth().getValue(); - excelExportEntity = new ExcelExportEntity(month + "月", String.valueOf(c)); - } - List yyxxList1 = new ArrayList<>(); - yyxxList1.add(new ExcelExportEntity("发电量", "electricityUsage")); - yyxxList1.add(new ExcelExportEntity("消纳量", "consumptionUsage")); - yyxxList1.add(new ExcelExportEntity("上网量", "internetUsage")); - yyxxList1.add(new ExcelExportEntity("消纳率", "consumptionRate")); - if (ObjectUtil.isNotNull(excelExportEntity)) { - excelExportEntity.setList(yyxxList1); - return Stream.of(excelExportEntity); - } - return Stream.empty(); - }).toList())); - return paramCols; - } - - private List getTableHeader(List timeList, String timeType) { - List paramCols = new ArrayList<>(); - ExcelExportEntity colEntity1 = new ExcelExportEntity("结构", "name"); - paramCols.add(colEntity1); - ExcelExportEntity colEntity2 = new ExcelExportEntity("发电总量(kWh)", "electricityUsage"); - paramCols.add(colEntity2); - //动态表头集合 - paramCols.addAll(new ArrayList<>(timeList.stream() - .flatMap(c -> { - if (StringUtils.equalsIgnoreCase(TimeType.DAY.getName(), timeType)) { - int hour = DateTimeUtils.parseDateTime(c).getHour(); - return Stream.of(new ExcelExportEntity(hour + "时", String.valueOf(c))); - } - if (StringUtils.equalsIgnoreCase(TimeType.MONTH.getName(), timeType)) { - int day = DateTimeUtils.parseDateTime(c).getDayOfMonth(); - return Stream.of(new ExcelExportEntity(day + "日", String.valueOf(c))); - } - if (StringUtils.equalsIgnoreCase(TimeType.YEAR.getName(), timeType)) { - int month = DateTimeUtils.parseDateTime(c).getMonth().getValue(); - return Stream.of(new ExcelExportEntity(month + "月", String.valueOf(c))); - } - return Stream.empty(); - }).toList())); - return paramCols; - } - -} \ No newline at end of file diff --git a/modules/qingyuan/src/main/java/com/thing/qingyuan/util/CalculationUtil.java b/modules/qingyuan/src/main/java/com/thing/qingyuan/util/CalculationUtil.java index aae40fe..a50eb48 100644 --- a/modules/qingyuan/src/main/java/com/thing/qingyuan/util/CalculationUtil.java +++ b/modules/qingyuan/src/main/java/com/thing/qingyuan/util/CalculationUtil.java @@ -74,4 +74,16 @@ public class CalculationUtil { return result.setScale(4,RoundingMode.UP); } + /** + * 收益 + * @param a29 发电量 + * @param income 每千瓦时发电量收益 + * @param scale scale + * @return capacity * hour * attenuation ^ scale + */ + public static BigDecimal income(BigDecimal a29 ,BigDecimal income,Integer scale){ + BigDecimal result = a29.multiply(income).pow(scale); + return result.setScale(scale,RoundingMode.UP); + } + }