Commit 0e140b67 authored by ZWT's avatar ZWT

feat(能源管理系统): 测试问题修复

1.开发统计分析-能耗分析模块,绿电消纳列表接口,修改光伏电站Cloud模块查询电站列表接口,增加组织ID集合查询条件,添加接口文档,并完成接口冒烟测试;

BREAKING CHANGE: 无

Closes 无

[skip ci]
parent dfcbbddf
...@@ -27,4 +27,7 @@ public class GetBasePhotovoltaicPlantCloudInput { ...@@ -27,4 +27,7 @@ public class GetBasePhotovoltaicPlantCloudInput {
@XText("电站ID集合") @XText("电站ID集合")
private List<String> plantIds; private List<String> plantIds;
@XText("组织ID集合")
private List<String> ouIds;
} }
...@@ -33,6 +33,11 @@ ...@@ -33,6 +33,11 @@
<version>1.0.0-pps</version> <version>1.0.0-pps</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>gf</groupId>
<artifactId>pps-cloud-system</artifactId>
<version>1.0.0-pps</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
......
package pps.core.prediction.service; package pps.core.prediction.service;
import cn.hutool.core.collection.CollUtil;
import pps.cloud.base.service.data.base_photovoltaic_plant.GetBasePhotovoltaicPlantCloudInput;
import pps.cloud.base.service.data.base_photovoltaic_plant.GetBasePhotovoltaicPlantCloudOutput;
import pps.core.common.constant.BusinessConstant;
import pps.core.prediction.service.data.energy_consumption_analysis.GetEnergyConsumptionAnalysisInput;
import pps.core.prediction.service.data.energy_consumption_analysis.GetEnergyConsumptionAnalysisOutput;
import pps.core.prediction.service.data.energy_consumption_curve.GetEnergyConsumptionCurveOutput;
import xstartup.annotation.XService; import xstartup.annotation.XService;
import xstartup.annotation.XText; import xstartup.annotation.XText;
import xstartup.base.XContext;
import xstartup.base.util.XCopyUtils;
import xstartup.data.XListResult;
import xstartup.feature.api.annotation.XApiAnonymous;
import xstartup.feature.api.annotation.XApiGet;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/** /**
* 能耗分析模块(测试用) * 能耗分析模块(测试用)
...@@ -12,8 +30,58 @@ import xstartup.annotation.XText; ...@@ -12,8 +30,58 @@ import xstartup.annotation.XText;
*/ */
@XText("能耗分析模块") @XText("能耗分析模块")
@XService @XService
public class EnergyConsumptionAnalysisService { public class EnergyConsumptionAnalysisService extends StatisticAnalysisBaseService {
/**
* 能耗分析--绿电消纳
*
* @param context 上下文
* @param input 输入
* @return {@link XListResult}<{@link GetEnergyConsumptionCurveOutput}>
*/
@XText("能耗分析--绿电消纳")
@XApiAnonymous
@XApiGet
public XListResult<GetEnergyConsumptionAnalysisOutput> queryGreenElectricityAbsorption(XContext context, GetEnergyConsumptionAnalysisInput input) {
//查包含当前组织的所有子组织列表
List<String> orgIdsByPath = super.getOrgIdsByPath(context, input.getOuId());
//查组织下的光伏电站
List<GetBasePhotovoltaicPlantCloudOutput> photovoltaicPlantList = super.getPhotovoltaicPlantByParam(context,
GetBasePhotovoltaicPlantCloudInput.builder()
.ouIds(orgIdsByPath)
.build()
);
List powerGenerationList = null;
if (CollUtil.isNotEmpty(photovoltaicPlantList)) {
powerGenerationList = super.getPhotovoltaicPowerGeneration(context, input.getDateType(),
photovoltaicPlantList.stream()
.map(GetBasePhotovoltaicPlantCloudOutput::getId)
.collect(Collectors.toList())
);
}
List<GetEnergyConsumptionAnalysisOutput> outputList = new ArrayList<>(0);
if (CollUtil.isNotEmpty(powerGenerationList)) {
XCopyUtils.copyList(powerGenerationList, outputList, GetEnergyConsumptionAnalysisOutput.class);
//todo 设置一个值计算用电量
BigDecimal flag = new BigDecimal(0.8);
BigDecimal power;
for (GetEnergyConsumptionAnalysisOutput output : outputList) {
power = output.getPower();
if (Objects.isNull(power) ||
power.compareTo(BigDecimal.ZERO) <= BusinessConstant.ZERO
) {
output.setElectricityConsumption(BigDecimal.ZERO);
continue;
}
//计算负荷
output.setElectricityConsumption(
power.multiply(flag)
.setScale(2, BigDecimal.ROUND_HALF_UP)
);
}
}
return XListResult.success(outputList);
}
/*-----------------------------------private-----------------------------------*/ /*-----------------------------------private-----------------------------------*/
} }
package pps.core.prediction.service; package pps.core.prediction.service;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import pps.cloud.base.service.BasePhotovoltaicPlantCloudService;
import pps.cloud.base.service.IBasePowerLineCloudService; import pps.cloud.base.service.IBasePowerLineCloudService;
import pps.cloud.base.service.data.base_photovoltaic_plant.GetBasePhotovoltaicPlantCloudInput; import pps.cloud.base.service.data.base_photovoltaic_plant.GetBasePhotovoltaicPlantCloudInput;
import pps.cloud.base.service.data.base_photovoltaic_plant.GetBasePhotovoltaicPlantCloudOutput; import pps.cloud.base.service.data.base_photovoltaic_plant.GetBasePhotovoltaicPlantCloudOutput;
import pps.cloud.base.service.data.base_power_line_plant.DynamicQueryBasePowerLinePlantInput; import pps.cloud.base.service.data.base_power_line_plant.DynamicQueryBasePowerLinePlantInput;
import pps.cloud.base.service.data.base_power_line_plant.DynamicQueryBasePowerLinePlantOutput; import pps.cloud.base.service.data.base_power_line_plant.DynamicQueryBasePowerLinePlantOutput;
import pps.core.common.constant.BusinessConstant; import pps.core.common.constant.BusinessConstant;
import pps.core.common.utils.BaseUtils;
import pps.core.prediction.entity.PlantPredictedPowerDataEnt;
import pps.core.prediction.entity.PlantPredictedPowerLongTermDataEnt;
import pps.core.prediction.mapper.PlantPredictedPowerDataMapper;
import pps.core.prediction.mapper.PlantPredictedPowerLongTermDataMapper;
import pps.core.prediction.service.data.energy_consumption_curve.GetEnergyConsumptionCurveInput; import pps.core.prediction.service.data.energy_consumption_curve.GetEnergyConsumptionCurveInput;
import pps.core.prediction.service.data.energy_consumption_curve.GetEnergyConsumptionCurveOutput; import pps.core.prediction.service.data.energy_consumption_curve.GetEnergyConsumptionCurveOutput;
import xstartup.annotation.XService; import xstartup.annotation.XService;
...@@ -42,7 +33,7 @@ import java.util.stream.Collectors; ...@@ -42,7 +33,7 @@ import java.util.stream.Collectors;
*/ */
@XText("用能曲线模块") @XText("用能曲线模块")
@XService @XService
public class EnergyConsumptionCurveService { public class EnergyConsumptionCurveService extends StatisticAnalysisBaseService {
/** /**
* 用能曲线--发电列表 * 用能曲线--发电列表
...@@ -63,60 +54,17 @@ public class EnergyConsumptionCurveService { ...@@ -63,60 +54,17 @@ public class EnergyConsumptionCurveService {
plantIdList = plantListByLineIds.stream() plantIdList = plantListByLineIds.stream()
.map(DynamicQueryBasePowerLinePlantOutput::getPlantId) .map(DynamicQueryBasePowerLinePlantOutput::getPlantId)
.collect(Collectors.toList()); .collect(Collectors.toList());
//取当前时间 powerGenerationList = super.getPhotovoltaicPowerGeneration(context, input.getDateType(), plantIdList);
DateTime date = DateUtil.date();
PlantPredictedPowerDataMapper powerDataMapper;
switch (input.getDateType()) {
case 0:
powerDataMapper = context.getBean(PlantPredictedPowerDataMapper.class);
powerGenerationList = powerDataMapper.selectList(new QueryWrapper<PlantPredictedPowerDataEnt>()
.select("hour_time",
"SUM( power ) AS power")
.lambda()
.eq(PlantPredictedPowerDataEnt::getYearTime, String.valueOf(date.year()))
.eq(PlantPredictedPowerDataEnt::getMonthTime, BaseUtils.getMonthString(date.month() + 1))
.eq(PlantPredictedPowerDataEnt::getDayTime, String.valueOf(date.dayOfMonth()))
.in(PlantPredictedPowerDataEnt::getPlantId, plantIdList)
.groupBy(PlantPredictedPowerDataEnt::getHourTime)
.orderByAsc(PlantPredictedPowerDataEnt::getHourTime)
);
break;
case 1:
powerDataMapper = context.getBean(PlantPredictedPowerDataMapper.class);
powerGenerationList = powerDataMapper.selectList(new QueryWrapper<PlantPredictedPowerDataEnt>()
.select("hour_time",
"SUM( power ) AS power")
.lambda()
.in(PlantPredictedPowerDataEnt::getPlantId, plantIdList)
.between(PlantPredictedPowerDataEnt::getDataDate,
date.toString(BusinessConstant.DATE_FORMAT_DAY),
DateUtil.offsetDay(date, 7).toString(BusinessConstant.DATE_FORMAT_DAY))
.groupBy(PlantPredictedPowerDataEnt::getHourTime)
.orderByAsc(PlantPredictedPowerDataEnt::getHourTime)
);
break;
case 2:
PlantPredictedPowerLongTermDataMapper longTermDataMapper = context.getBean(PlantPredictedPowerLongTermDataMapper.class);
powerGenerationList = longTermDataMapper.selectList(new QueryWrapper<PlantPredictedPowerLongTermDataEnt>()
.select("hour_time",
"SUM( power ) AS power")
.lambda()
.in(PlantPredictedPowerLongTermDataEnt::getPlantId, plantIdList)
.between(PlantPredictedPowerLongTermDataEnt::getDataDate,
date.toString(BusinessConstant.DATE_FORMAT_DAY),
DateUtil.offsetDay(date, 30).toString(BusinessConstant.DATE_FORMAT_DAY))
.groupBy(PlantPredictedPowerLongTermDataEnt::getHourTime)
.orderByAsc(PlantPredictedPowerLongTermDataEnt::getHourTime)
);
break;
default:
}
} }
List<GetEnergyConsumptionCurveOutput> outputList = new ArrayList<>(0); List<GetEnergyConsumptionCurveOutput> outputList = new ArrayList<>(0);
if (CollUtil.isNotEmpty(powerGenerationList)) { if (CollUtil.isNotEmpty(powerGenerationList)) {
XCopyUtils.copyList(powerGenerationList, outputList, GetEnergyConsumptionCurveOutput.class); XCopyUtils.copyList(powerGenerationList, outputList, GetEnergyConsumptionCurveOutput.class);
//有发电量说明有电站ID,查电站详情 //有发电量说明有电站ID,查电站详情
List<GetBasePhotovoltaicPlantCloudOutput> plantList = this.getPhotovoltaicPlantByPlantIds(context, plantIdList); List<GetBasePhotovoltaicPlantCloudOutput> plantList = super.getPhotovoltaicPlantByParam(context,
GetBasePhotovoltaicPlantCloudInput.builder()
.plantIds(plantIdList)
.build()
);
Optional<BigDecimal> reduce = plantList.stream() Optional<BigDecimal> reduce = plantList.stream()
.map(GetBasePhotovoltaicPlantCloudOutput::getTotalPower) .map(GetBasePhotovoltaicPlantCloudOutput::getTotalPower)
.reduce(BigDecimal::add); .reduce(BigDecimal::add);
...@@ -164,21 +112,4 @@ public class EnergyConsumptionCurveService { ...@@ -164,21 +112,4 @@ public class EnergyConsumptionCurveService {
result.throwIfFail(); result.throwIfFail();
return result.getResult(); return result.getResult();
} }
/**
* 获取光伏发电厂
*
* @param context 上下文
* @param plantIds 植物id
* @return {@link List}<{@link GetBasePhotovoltaicPlantCloudOutput}>
*/
private List<GetBasePhotovoltaicPlantCloudOutput> getPhotovoltaicPlantByPlantIds(XContext context, List<String> plantIds) {
BasePhotovoltaicPlantCloudService cloudService = context.getBean(BasePhotovoltaicPlantCloudService.class);
XListResult<GetBasePhotovoltaicPlantCloudOutput> result = cloudService.getBasePhotovoltaicPlantList(context,
GetBasePhotovoltaicPlantCloudInput.builder()
.plantIds(plantIds)
.build());
result.throwIfFail();
return result.getResult();
}
} }
package pps.core.prediction.service;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import pps.cloud.base.service.BasePhotovoltaicPlantCloudService;
import pps.cloud.base.service.data.base_photovoltaic_plant.GetBasePhotovoltaicPlantCloudInput;
import pps.cloud.base.service.data.base_photovoltaic_plant.GetBasePhotovoltaicPlantCloudOutput;
import pps.cloud.system.service.SysOrganizationCloudService;
import pps.cloud.system.service.data.GetAllOuListByOuIdInput;
import pps.cloud.system.service.data.GetSysOrganizationViewOutput;
import pps.core.common.constant.BusinessConstant;
import pps.core.common.utils.BaseUtils;
import pps.core.prediction.entity.PlantPredictedPowerDataEnt;
import pps.core.prediction.entity.PlantPredictedPowerLongTermDataEnt;
import pps.core.prediction.mapper.PlantPredictedPowerDataMapper;
import pps.core.prediction.mapper.PlantPredictedPowerLongTermDataMapper;
import xstartup.base.XContext;
import xstartup.data.XListResult;
import java.util.List;
import java.util.stream.Collectors;
/**
* 统计分析基类
*
* @author ZWT
* @date 2023/09/28 10:21
*/
public class StatisticAnalysisBaseService {
/**
* 获得光伏发电
*
* @param context 上下文
* @param dateType 日期类型
* @param plantIdList 工厂id列表
* @return {@link List}
*/
public List getPhotovoltaicPowerGeneration(XContext context, Integer dateType, List<String> plantIdList) {
List powerGenerationList = null;
//取当前时间
DateTime date = DateUtil.date();
PlantPredictedPowerDataMapper powerDataMapper;
switch (dateType) {
case 0:
powerDataMapper = context.getBean(PlantPredictedPowerDataMapper.class);
powerGenerationList = powerDataMapper.selectList(new QueryWrapper<PlantPredictedPowerDataEnt>()
.select("hour_time",
"SUM( power ) AS power")
.lambda()
.eq(PlantPredictedPowerDataEnt::getYearTime, String.valueOf(date.year()))
.eq(PlantPredictedPowerDataEnt::getMonthTime, BaseUtils.getMonthString(date.month() + 1))
.eq(PlantPredictedPowerDataEnt::getDayTime, String.valueOf(date.dayOfMonth()))
.in(PlantPredictedPowerDataEnt::getPlantId, plantIdList)
.groupBy(PlantPredictedPowerDataEnt::getHourTime)
.orderByAsc(PlantPredictedPowerDataEnt::getHourTime)
);
break;
case 1:
powerDataMapper = context.getBean(PlantPredictedPowerDataMapper.class);
powerGenerationList = powerDataMapper.selectList(new QueryWrapper<PlantPredictedPowerDataEnt>()
.select("hour_time",
"SUM( power ) AS power")
.lambda()
.in(PlantPredictedPowerDataEnt::getPlantId, plantIdList)
.between(PlantPredictedPowerDataEnt::getDataDate,
date.toString(BusinessConstant.DATE_FORMAT_DAY),
DateUtil.offsetDay(date, 7).toString(BusinessConstant.DATE_FORMAT_DAY))
.groupBy(PlantPredictedPowerDataEnt::getHourTime)
.orderByAsc(PlantPredictedPowerDataEnt::getHourTime)
);
break;
case 2:
PlantPredictedPowerLongTermDataMapper longTermDataMapper = context.getBean(PlantPredictedPowerLongTermDataMapper.class);
powerGenerationList = longTermDataMapper.selectList(new QueryWrapper<PlantPredictedPowerLongTermDataEnt>()
.select("hour_time",
"SUM( power ) AS power")
.lambda()
.in(PlantPredictedPowerLongTermDataEnt::getPlantId, plantIdList)
.between(PlantPredictedPowerLongTermDataEnt::getDataDate,
date.toString(BusinessConstant.DATE_FORMAT_DAY),
DateUtil.offsetDay(date, 30).toString(BusinessConstant.DATE_FORMAT_DAY))
.groupBy(PlantPredictedPowerLongTermDataEnt::getHourTime)
.orderByAsc(PlantPredictedPowerLongTermDataEnt::getHourTime)
);
break;
default:
}
return powerGenerationList;
}
/**
* 获取所有path包含组织ID的组织
*
* @param context 上下文
* @param ouId ou id
* @return {@link List}<{@link String}>
*/
public List<String> getOrgIdsByPath(XContext context, String ouId) {
SysOrganizationCloudService organizationCloudService = context.getBean(SysOrganizationCloudService.class);
GetAllOuListByOuIdInput ouIdInput = new GetAllOuListByOuIdInput();
ouIdInput.setOuId(ouId);
XListResult<GetSysOrganizationViewOutput> allListByOuId = organizationCloudService.getAllListByOuId(context, ouIdInput);
allListByOuId.throwIfFail();
return allListByOuId.getResult().stream()
.map(GetSysOrganizationViewOutput::getId)
.collect(Collectors.toList());
}
/**
* 获取光伏发电厂
*
* @param context 上下文
* @param input 输入
* @return {@link List}<{@link GetBasePhotovoltaicPlantCloudOutput}>
*/
public List<GetBasePhotovoltaicPlantCloudOutput> getPhotovoltaicPlantByParam(XContext context, GetBasePhotovoltaicPlantCloudInput input) {
BasePhotovoltaicPlantCloudService cloudService = context.getBean(BasePhotovoltaicPlantCloudService.class);
XListResult<GetBasePhotovoltaicPlantCloudOutput> result = cloudService.getBasePhotovoltaicPlantList(context, input);
result.throwIfFail();
return result.getResult();
}
}
package pps.core.prediction.service.data.energy_consumption_analysis;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import xstartup.annotation.XText;
/**
* 用能曲线(模拟数据测试用)
*
* @author ZWT
* @date 2023/09/20
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class GetEnergyConsumptionAnalysisInput {
@XText("组织机构ID")
@NotBlank(message = "缺少组织机构ID")
private String ouId;
@NotNull(message = "缺少日期类型")
@XText("日期类型(0_今日,1_近7天,2_近30天)")
private Integer dateType;
}
package pps.core.prediction.service.data.energy_consumption_analysis;
import lombok.Data;
import xstartup.annotation.XText;
import java.math.BigDecimal;
/**
* 用能曲线(模拟数据测试用)
*
* @author ZWT
* @date 2023/09/20
*/
@Data
public class GetEnergyConsumptionAnalysisOutput {
@XText("小时")
private String hourTime;
@XText("光伏发电")
private BigDecimal power;
@XText("光伏用电")
private BigDecimal electricityConsumption;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment