Commit c9c837e7 authored by ZWT's avatar ZWT

feat(能源管理系统): 间开优化定时任务

1.开发间开优化长期间开优化定时任务,完成并网流程绿电消纳优先策略;
2.开发间开优化长期间开优化定时任务,完成并网流程消峰平谷策略;
3.开发间开优化中短期间开优化定时任务,创建定时任务并添加配置;
4.抽取间开优化定时任务逻辑处理父类,对长期间开优化定时任务/中短期间开优化定时任务代码结构进行优化;
5.开发间开优化中短期间开优化定时任务,完成并网流程绿电消纳优先策略;
6.开发间开优化中短期间开优化定时任务,完成并网流程消峰平谷策略;
7.修改间开制度管理设为基础制度接口,增加长期/中短期间开优化业务处理逻辑;

BREAKING CHANGE: 无

Closes 无

[skip ci]
parent a3f743c2
......@@ -293,63 +293,16 @@ public class SpaceInstitutionDetailService extends SpaceOptimizeBaseService {
String ouId = input.getOuId();
String lineId = input.getLineId();
String institutionId = input.getId();
SpaceInstitutionDetailMapper mapper = context.getBean(SpaceInstitutionDetailMapper.class);
SpaceInstitutionDetailEnt detail = this.getInstitutionDetail(mapper, institutionId);
if (Objects.isNull(detail)) {
return XServiceResult.error(context, XError.NotFound);
}
Integer isCurrentBasic = detail.getIsCurrentBasic();
if (isCurrentBasic.equals(BusinessConstant.ZERO)) {
return XServiceResult.error(context, BusinessError.RepeatSetting);
}
//取制度开始时间,判断是否可以执行
Date institutionStartDate = detail.getInstitutionStartDate();
DateTime currentTime = DateUtil.date();
List<SpaceOptimizePeriodDTO> longPeriodDTOList = new ArrayList<>(32);
List<SpaceOptimizeWellheadDTO> longWellheadDTOList = new ArrayList<>(64);
List<SpaceOptimizeDurationDTO> longDurationDTOList = new ArrayList<>(128);
List<SpaceOptimizeDurationDTO> longUnOptimizeDurationList = new ArrayList<>(128);
List<SpaceOptimizePeriodDTO> midPeriodDTOList = new ArrayList<>(32);
List<SpaceOptimizeWellheadDTO> midWellheadDTOList = new ArrayList<>(64);
List<SpaceOptimizeDurationDTO> midDurationDTOList = new ArrayList<>(128);
List<SpaceOptimizeDurationDTO> midUnOptimizeDurationList = new ArrayList<>(128);
DateTime endOfMonth = DateUtil.endOfMonth(currentTime);
DateTime endOfWeek = DateUtil.endOfWeek(currentTime);
boolean checkOptimize = currentTime.compareTo(institutionStartDate) >= 0;
if (checkOptimize) {
//取年份
int year = currentTime.year();
//月份要加一
int monthNum = currentTime.month() + 1;
String month;
if (monthNum < BusinessConstant.TEN) {
month = "0" + monthNum;
} else {
month = String.valueOf(monthNum);
}
SpaceOptimizeWellheadAndPlant wellheadAndPlant = super.getWellheadAndPlant(context, ListUtil.toList(detail));
//长期间开优化
List<DynamicQueryPlantPredictedPowerOutput> longAvgPowerList = super.getAveragePowerGenerationListByPlantIds(context,
DynamicQueryPlantPredictedPowerInput.builder()
.plantIds(wellheadAndPlant.getPlantIdsByLineIdMap().get(lineId))
.yearTime(String.valueOf(year))
.monthTime(month)
.build()
);
this.institutionalOptimization(context, longPeriodDTOList, longWellheadDTOList, longDurationDTOList, longUnOptimizeDurationList, wellheadAndPlant,
longAvgPowerList, detail, BaseUtils.getExecutionCycleForMonth(currentTime), endOfMonth, monthNum);
//中短期间开优化
List<DynamicQueryPlantPredictedPowerOutput> midAvgPowerList = super.getAveragePowerGenerationListByPlantIds(context,
DynamicQueryPlantPredictedPowerInput.builder()
.plantIds(wellheadAndPlant.getPlantIdsByLineIdMap().get(lineId))
.startTime(DateUtil.beginOfWeek(currentTime).toString(BusinessConstant.DATE_FORMAT_DAY))
.endTime(DateUtil.beginOfWeek(DateUtil.nextWeek()).toString(BusinessConstant.DATE_FORMAT_DAY))
.build()
);
this.institutionalOptimization(context, midPeriodDTOList, midWellheadDTOList, midDurationDTOList, midUnOptimizeDurationList, wellheadAndPlant,
midAvgPowerList, detail, BaseUtils.getExecutionCycleForWeek(currentTime), endOfWeek, monthNum);
}
return XTransactionHelper.begin(context, () -> {
SpaceInstitutionDetailMapper mapper = context.getBean(SpaceInstitutionDetailMapper.class);
SpaceInstitutionDetailEnt detail = this.getInstitutionDetail(mapper, institutionId);
if (Objects.isNull(detail)) {
return XServiceResult.error(context, XError.NotFound);
}
Integer isCurrentBasic = detail.getIsCurrentBasic();
if (isCurrentBasic.equals(BusinessConstant.ZERO)) {
return XServiceResult.error(context, BusinessError.RepeatSetting);
}
//关闭当前基础制度
mapper.update(null, new LambdaUpdateWrapper<SpaceInstitutionDetailEnt>()
.eq(SpaceInstitutionDetailEnt::getOuId, ouId)
......@@ -362,143 +315,8 @@ public class SpaceInstitutionDetailService extends SpaceOptimizeBaseService {
.eq(BaseModel::getId, institutionId)
.set(SpaceInstitutionDetailEnt::getIsCurrentBasic, BusinessConstant.ZERO)
);
//长期/中短期间开优化
if (checkOptimize) {
//逻辑删除已创建的长期优化数据
SpaceOptimizeLongPeriodMapper longPeriodMapper = context.getBean(SpaceOptimizeLongPeriodMapper.class);
List<SpaceOptimizeLongPeriodEnt> longPeriodEntList = longPeriodMapper.selectList(new LambdaQueryWrapper<SpaceOptimizeLongPeriodEnt>()
.eq(BaseModel::getIsDeleted, BusinessConstant.ONE)
.eq(SpaceOptimizeLongPeriodEnt::getOptimizeState, BusinessConstant.ZERO)
.eq(SpaceOptimizeLongPeriodEnt::getInstitutionId, institutionId)
.eq(SpaceOptimizeLongPeriodEnt::getLineId, lineId)
.eq(SpaceOptimizeLongPeriodEnt::getOptimizeDeadline, endOfMonth)
);
if (CollUtil.isNotEmpty(longPeriodEntList)) {
List<String> longIds = longPeriodEntList.stream()
.map(BaseModel::getId)
.collect(Collectors.toList());
longPeriodMapper.update(null, new LambdaUpdateWrapper<SpaceOptimizeLongPeriodEnt>()
.set(BaseModel::getIsDeleted, BusinessConstant.ZERO)
.in(BaseModel::getId, longIds)
);
//删除关联数据
SpaceOptimizeLongWellheadMapper longWellheadMapper = context.getBean(SpaceOptimizeLongWellheadMapper.class);
longWellheadMapper.update(null, new LambdaUpdateWrapper<SpaceOptimizeLongWellheadEnt>()
.set(BaseModel::getIsDeleted, BusinessConstant.ZERO)
.in(SpaceOptimizeLongWellheadEnt::getLongPeriodId, longIds)
);
SpaceOptimizeLongDurationMapper longDurationMapper = context.getBean(SpaceOptimizeLongDurationMapper.class);
longDurationMapper.update(null, new LambdaUpdateWrapper<SpaceOptimizeLongDurationEnt>()
.set(BaseModel::getIsDeleted, BusinessConstant.ZERO)
.in(SpaceOptimizeLongDurationEnt::getLongPeriodId, longIds)
);
}
//逻辑删除已创建的中短期优化数据
SpaceOptimizeMidPeriodMapper midPeriodMapper = context.getBean(SpaceOptimizeMidPeriodMapper.class);
List<SpaceOptimizeMidPeriodEnt> midPeriodEntList = midPeriodMapper.selectList(new LambdaQueryWrapper<SpaceOptimizeMidPeriodEnt>()
.eq(BaseModel::getIsDeleted, BusinessConstant.ONE)
.eq(SpaceOptimizeMidPeriodEnt::getOptimizeState, BusinessConstant.ZERO)
.eq(SpaceOptimizeMidPeriodEnt::getInstitutionId, institutionId)
.eq(SpaceOptimizeMidPeriodEnt::getLineId, lineId)
.eq(SpaceOptimizeMidPeriodEnt::getOptimizeDeadline, endOfWeek)
);
if (CollUtil.isNotEmpty(midPeriodEntList)) {
List<String> midIds = midPeriodEntList.stream()
.map(BaseModel::getId)
.collect(Collectors.toList());
midPeriodMapper.update(null, new LambdaUpdateWrapper<SpaceOptimizeMidPeriodEnt>()
.set(BaseModel::getIsDeleted, BusinessConstant.ZERO)
.in(BaseModel::getId, midIds)
);
//删除关联数据
SpaceOptimizeMidWellheadMapper longWellheadMapper = context.getBean(SpaceOptimizeMidWellheadMapper.class);
longWellheadMapper.update(null, new LambdaUpdateWrapper<SpaceOptimizeMidWellheadEnt>()
.set(BaseModel::getIsDeleted, BusinessConstant.ZERO)
.in(SpaceOptimizeMidWellheadEnt::getMidPeriodId, midIds)
);
SpaceOptimizeMidDurationMapper longDurationMapper = context.getBean(SpaceOptimizeMidDurationMapper.class);
longDurationMapper.update(null, new LambdaUpdateWrapper<SpaceOptimizeMidDurationEnt>()
.set(BaseModel::getIsDeleted, BusinessConstant.ZERO)
.in(SpaceOptimizeMidDurationEnt::getMidPeriodId, midIds)
);
}
//创建长期优化数据
int size;
SpaceOptimizeViewMapper optimizeViewMapper = context.getBean(SpaceOptimizeViewMapper.class);
if (CollUtil.isNotEmpty(longPeriodDTOList)) {
size = longPeriodDTOList.size();
if (size > BaseUtils.BATCH_SIZE) {
List<List<SpaceOptimizePeriodDTO>> subList = BaseUtils.getSubList(longPeriodDTOList);
subList.forEach(b -> optimizeViewMapper.longPeriodBatchInsertList(b));
} else {
optimizeViewMapper.longPeriodBatchInsertList(longPeriodDTOList);
}
}
if (CollUtil.isNotEmpty(longWellheadDTOList)) {
size = longWellheadDTOList.size();
if (size > BaseUtils.BATCH_SIZE) {
List<List<SpaceOptimizeWellheadDTO>> subList = BaseUtils.getSubList(longWellheadDTOList);
subList.forEach(b -> optimizeViewMapper.longWellheadBatchInsertList(b));
} else {
optimizeViewMapper.longWellheadBatchInsertList(longWellheadDTOList);
}
}
if (CollUtil.isNotEmpty(longDurationDTOList)) {
size = longDurationDTOList.size();
if (size > BaseUtils.BATCH_SIZE) {
List<List<SpaceOptimizeDurationDTO>> subList = BaseUtils.getSubList(longDurationDTOList);
subList.forEach(b -> optimizeViewMapper.longDurationBatchInsertList(b));
} else {
optimizeViewMapper.longDurationBatchInsertList(longDurationDTOList);
}
}
if (CollUtil.isNotEmpty(longUnOptimizeDurationList)) {
size = longUnOptimizeDurationList.size();
if (size > BaseUtils.BATCH_SIZE) {
List<List<SpaceOptimizeDurationDTO>> subList = BaseUtils.getSubList(longUnOptimizeDurationList);
subList.forEach(b -> optimizeViewMapper.longDurationBatchInsertList(b));
} else {
optimizeViewMapper.longDurationBatchInsertList(longUnOptimizeDurationList);
}
}
//创建中短期优化数据
if (CollUtil.isNotEmpty(midPeriodDTOList)) {
size = midPeriodDTOList.size();
if (size > BaseUtils.BATCH_SIZE) {
List<List<SpaceOptimizePeriodDTO>> subList = BaseUtils.getSubList(midPeriodDTOList);
subList.forEach(b -> optimizeViewMapper.midPeriodBatchInsertList(b));
} else {
optimizeViewMapper.midPeriodBatchInsertList(midPeriodDTOList);
}
}
if (CollUtil.isNotEmpty(midWellheadDTOList)) {
size = midWellheadDTOList.size();
if (size > BaseUtils.BATCH_SIZE) {
List<List<SpaceOptimizeWellheadDTO>> subList = BaseUtils.getSubList(midWellheadDTOList);
subList.forEach(b -> optimizeViewMapper.midWellheadBatchInsertList(b));
} else {
optimizeViewMapper.midWellheadBatchInsertList(midWellheadDTOList);
}
}
if (CollUtil.isNotEmpty(midDurationDTOList)) {
size = midDurationDTOList.size();
if (size > BaseUtils.BATCH_SIZE) {
List<List<SpaceOptimizeDurationDTO>> subList = BaseUtils.getSubList(midDurationDTOList);
subList.forEach(b -> optimizeViewMapper.midDurationBatchInsertList(b));
} else {
optimizeViewMapper.midDurationBatchInsertList(midDurationDTOList);
}
}
if (CollUtil.isNotEmpty(midUnOptimizeDurationList)) {
size = midUnOptimizeDurationList.size();
if (size > BaseUtils.BATCH_SIZE) {
List<List<SpaceOptimizeDurationDTO>> subList = BaseUtils.getSubList(midUnOptimizeDurationList);
subList.forEach(b -> optimizeViewMapper.midDurationBatchInsertList(b));
} else {
optimizeViewMapper.midDurationBatchInsertList(midUnOptimizeDurationList);
}
}
}
//长期/中短期制度优化初始化
this.institutionOptimizeInitialize(context, detail);
return XServiceResult.OK;
});
}
......
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