package com.iailab.module.ansteel.job.task;
|
|
import com.iailab.module.ansteel.common.utils.DecimalUtil;
|
import com.iailab.module.ansteel.power.entity.PowerDemandEntity;
|
import com.iailab.module.ansteel.power.entity.PowerMaxdemandDetEntity;
|
import com.iailab.module.ansteel.power.entity.PowerMaxdemandMainEntity;
|
import com.iailab.module.ansteel.power.entity.PowerNetDropdownEntity;
|
import com.iailab.module.ansteel.power.service.PowerDemandService;
|
import com.iailab.module.ansteel.power.service.PowerMaxdemandDetService;
|
import com.iailab.module.ansteel.power.service.PowerMaxdemandMainService;
|
import com.iailab.module.ansteel.power.service.PowerNetDropdownService;
|
import com.iailab.module.data.api.point.DataPointApi;
|
import com.iailab.module.data.api.point.dto.ApiPointValueDTO;
|
import com.iailab.module.data.api.point.dto.ApiPointValueQueryDTO;
|
import org.apache.commons.lang3.StringUtils;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
import org.springframework.util.CollectionUtils;
|
|
import javax.annotation.Resource;
|
import java.math.BigDecimal;
|
import java.util.*;
|
|
/**
|
* 检查每天的需量与这个月的最大值比较
|
* 如果大于,则保存
|
* 每天23:59执行
|
*
|
* @author PanZhibao
|
* @Description
|
* @createTime 2025年05月08日
|
*/
|
@Component("runPowerMaxdemandTask")
|
public class RunPowerMaxdemandTask implements ITask {
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
|
@Autowired
|
private PowerDemandService powerDemandService;
|
|
@Autowired
|
private PowerMaxdemandMainService powerMaxdemandMainService;
|
|
@Autowired
|
private PowerNetDropdownService powerNetDropdownService;
|
|
@Autowired
|
private PowerMaxdemandDetService powerMaxdemandDetService;
|
|
@Resource
|
private DataPointApi dataPointApi;
|
|
@Override
|
public void run(String params) {
|
logger.info("RunPowerMaxdemandTask start");
|
Calendar calendar = Calendar.getInstance();
|
calendar.set(Calendar.MILLISECOND, 0);
|
calendar.set(Calendar.SECOND, 0);
|
Date nowTime = calendar.getTime();
|
calendar.set(Calendar.MINUTE, 0);
|
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
Date dayStart = calendar.getTime();
|
calendar.set(Calendar.DAY_OF_MONTH, 1);
|
Date monStart = calendar.getTime();
|
try {
|
Map<String, Object> params0 = new HashMap<>();
|
List<PowerDemandEntity> demandList = powerDemandService.list(params0);
|
if (CollectionUtils.isEmpty(demandList)) {
|
logger.info("demandList is empty");
|
return;
|
}
|
for (PowerDemandEntity demand : demandList) {
|
logger.info("查询今天的最大需量");
|
ApiPointValueQueryDTO pointValueQuery0 = new ApiPointValueQueryDTO();
|
pointValueQuery0.setStart(dayStart);
|
pointValueQuery0.setEnd(nowTime);
|
pointValueQuery0.setPointNo(demand.getCurDemand());
|
Map<String, Object> maxValue = dataPointApi.queryPointMaxValue(pointValueQuery0);
|
if (CollectionUtils.isEmpty(maxValue)) {
|
logger.info("maxValue is empty");
|
continue;
|
}
|
BigDecimal todayMax = new BigDecimal(maxValue.get(demand.getCurDemand()).toString());
|
logger.info("todayMax=" + todayMax);
|
List<ApiPointValueDTO> valueList = dataPointApi.queryPointHistoryValue(pointValueQuery0);
|
if (CollectionUtils.isEmpty(valueList)) {
|
logger.info("valueList is empty");
|
continue;
|
}
|
Date occurTime = new Date(nowTime.getTime());
|
for (ApiPointValueDTO apiPointValueDTO : valueList) {
|
if (Math.abs(apiPointValueDTO.getV() - todayMax.doubleValue()) < 0.001) {
|
occurTime = apiPointValueDTO.getT();
|
break;
|
}
|
}
|
|
logger.info("查询本月需量发生记录");
|
BigDecimal monthMax = powerMaxdemandMainService.getMax(demand.getCode(), monStart, nowTime);
|
|
// 保存记录
|
if (todayMax.compareTo(monthMax) <= 0) {
|
continue;
|
}
|
PowerMaxdemandMainEntity mainEntity = new PowerMaxdemandMainEntity();
|
mainEntity.setCode(demand.getCode());
|
mainEntity.setName(demand.getName());
|
mainEntity.setOccurTime(occurTime);
|
mainEntity.setMaxDemand(todayMax);
|
String mainId = powerMaxdemandMainService.add(mainEntity);
|
|
Map<String, Object> params1 = new HashMap<>();
|
params1.put("groupName", demand.getName());
|
List<PowerNetDropdownEntity> dropdownList = powerNetDropdownService.list(params1);
|
if (CollectionUtils.isEmpty(dropdownList)) {
|
logger.info("dropdownList is empty");
|
continue;
|
}
|
Calendar calendar1 = Calendar.getInstance();
|
calendar1.setTime(occurTime);
|
calendar1.add(Calendar.MINUTE, 1);
|
for (PowerNetDropdownEntity dropdown : dropdownList) {
|
if (StringUtils.isBlank(dropdown.getExt1())) {
|
logger.info(dropdown.getNodeCode() + ":dropdown.getExt1() is empty");
|
continue;
|
}
|
logger.info(dropdown.getNodeCode() + ":dropdown.getExt1() = " + dropdown.getExt1());
|
ApiPointValueQueryDTO pointValueQuery1 = new ApiPointValueQueryDTO();
|
pointValueQuery1.setStart(occurTime);
|
pointValueQuery1.setEnd(calendar1.getTime());
|
pointValueQuery1.setPointNo(dropdown.getExt1());
|
List<ApiPointValueDTO> valueList1 = dataPointApi.queryPointHistoryValue(pointValueQuery1);
|
if (CollectionUtils.isEmpty(valueList1)) {
|
logger.info("valueList1 is empty");
|
continue;
|
}
|
PowerMaxdemandDetEntity detEntity = new PowerMaxdemandDetEntity();
|
detEntity.setRelId(mainId);
|
detEntity.setCode(dropdown.getNodeCode());
|
detEntity.setName(dropdown.getNodeName());
|
detEntity.setOccurTime(occurTime);
|
detEntity.setMaxDemand(BigDecimal.valueOf(valueList1.get(0).getV()));
|
powerMaxdemandDetService.add(detEntity);
|
}
|
}
|
logger.info("RunPowerMaxdemandTask end");
|
} catch (Exception e) {
|
logger.error("RunPowerMaxdemandTask error", e);
|
e.printStackTrace();
|
}
|
}
|
}
|