package com.iailab.module.ansteel.job.task;
|
|
import cn.hutool.core.bean.BeanUtil;
|
import com.iailab.framework.common.util.date.DateUtils;
|
import com.iailab.module.ansteel.coking.entity.*;
|
import com.iailab.module.ansteel.coking.service.*;
|
import com.iailab.module.ansteel.common.enums.ProcessConfDataTypeEnum;
|
import com.iailab.module.ansteel.common.enums.ProcessTypeEnum;
|
import com.iailab.module.data.api.ind.IndItemApi;
|
import com.iailab.module.data.api.ind.dto.ApiIndItemQueryDTO;
|
import com.iailab.module.data.api.ind.dto.ApiIndItemValueDTO;
|
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 lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.StringUtils;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.stereotype.Component;
|
import org.springframework.util.CollectionUtils;
|
|
import javax.annotation.Resource;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
/**
|
* 备煤工序-概况
|
*
|
* @author PanZhibao
|
* @Description
|
* @createTime 2025年04月21日
|
*/
|
@Slf4j
|
@Component("runCokingOverviewTask")
|
public class RunCokingOverviewTask implements ITask{
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
|
@Resource
|
private CokingProcessConfService cokingProcessConfService;
|
@Resource
|
private CokingOverviewService cokingOverviewService;
|
@Resource
|
private DataPointApi dataPointApi;
|
@Resource
|
private IndItemApi indItemApi;
|
@Resource
|
private CokingTraceReportService cokingTraceReportService;
|
@Resource
|
private CokingTraceChartService cokingTraceChartService;
|
@Resource
|
private CokingTraceSuggestService cokingTraceSuggestService;
|
@Resource
|
private CokingTraceDataService cokingTraceDataService;
|
|
@Override
|
public void run(String processTypes) {
|
logger.info("runCokingOverviewTask,参数为:{}", processTypes);
|
try {
|
|
String[] split = processTypes.split(",");
|
|
for (String processType : split) {
|
CokingProcessConfEntity queryParams = new CokingProcessConfEntity();
|
queryParams.setIndType(processType);
|
List<CokingProcessConfEntity> list = cokingProcessConfService.list(queryParams);
|
if (CollectionUtils.isEmpty(list)) {
|
logger.info("ConfLis is Empty");
|
return;
|
}
|
|
Calendar calendar = Calendar.getInstance();
|
calendar.set(Calendar.MILLISECOND, 0);
|
calendar.set(Calendar.SECOND, 0);
|
calendar.set(Calendar.MINUTE, 0);
|
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
calendar.add(Calendar.DAY_OF_YEAR, -1);
|
String clock = DateUtils.format(calendar.getTime(), DateUtils.FORMAT_YEAR_MONTH_DAY);
|
// 溯源报告
|
CokingTraceReportEntity reportEntity = new CokingTraceReportEntity();
|
String relId = UUID.randomUUID().toString();
|
reportEntity.setId(relId);
|
reportEntity.setProcess(ProcessTypeEnum.getEumByCode(processType).getProcess());
|
reportEntity.setReportName(ProcessTypeEnum.getEumByCode(processType).getReportName());
|
reportEntity.setAnalyDate(clock);
|
reportEntity.setClock(clock);
|
reportEntity.setCreateDate(new Date());
|
cokingTraceReportService.save(reportEntity);
|
|
// 整体情况
|
// 筛选info_type = 2,按照子工序类型分组
|
Map<String, List<CokingProcessConfEntity>> processTypeMap = list.stream().filter(e -> e.getInfoType().equals("2")).collect(Collectors.groupingBy(CokingProcessConfEntity::getExt2));
|
// 结果 <子工序类型,<数据key,数据value>>
|
List<CokingOverviewEntity> result = new ArrayList<>(processTypeMap.size());
|
|
for (Map.Entry<String, List<CokingProcessConfEntity>> entry : processTypeMap.entrySet()) {
|
Map<String,Double> values = new HashMap<>(entry.getValue().size());
|
for (CokingProcessConfEntity conf : entry.getValue()) {
|
if (StringUtils.isBlank(conf.getDataType())) {
|
logger.info("DataType is Empty");
|
continue;
|
}
|
if (StringUtils.isBlank(conf.getPointNo())) {
|
logger.info("PointNo is Empty");
|
continue;
|
}
|
Double value = 0.0;
|
switch (ProcessConfDataTypeEnum.getEumByCode(conf.getDataType())) {
|
case DATAPOINT:
|
List<String> points = new ArrayList<>();
|
points.add(conf.getPointNo());
|
Map<String, Object> pointsRealValue = dataPointApi.queryPointsRealValue(points);
|
value = Double.valueOf(pointsRealValue.get(conf.getPointNo()).toString());
|
break;
|
case IND:
|
List<ApiIndItemValueDTO> indValues = indItemApi.queryIndItemDefaultValue(conf.getPointNo());
|
if (!CollectionUtils.isEmpty(indValues)) {
|
value = Double.valueOf(indValues.get(indValues.size() - 1).getDataValue().toString());
|
}
|
break;
|
case MODEL:
|
break;
|
default:
|
break;
|
|
}
|
values.put(conf.getExt1(),value);
|
}
|
CokingOverviewEntity overviewEntity = new CokingOverviewEntity();
|
BeanUtil.fillBeanWithMap(values,overviewEntity,true);
|
overviewEntity.setId(UUID.randomUUID().toString());
|
overviewEntity.setRelId(relId);
|
overviewEntity.setProcessType(processType);
|
overviewEntity.setSubProcessType(entry.getKey());
|
overviewEntity.setClock(clock);
|
result.add(overviewEntity);
|
|
// 清理旧数据
|
cokingOverviewService.deleteByProcessType(processType, clock);
|
cokingTraceDataService.deleteByExObj(processType, clock);
|
}
|
cokingOverviewService.insert(result);
|
|
// 指标运行趋势
|
List<CokingProcessConfEntity> indRunTrend = list.stream().filter(e -> e.getInfoType().equals("1")).collect(Collectors.toList());
|
List<CokingTraceChartEntity> cokingTraceChartEntityList = new ArrayList<>(indRunTrend.size());
|
// List<CokingTraceSuggestEntity> suggestEntitieList = new ArrayList<>();
|
List<CokingTraceDataEntity> exDatalist = new ArrayList<>(indRunTrend.size());
|
indRunTrend.forEach(e -> {
|
CokingTraceChartEntity cokingTraceChartEntity = new CokingTraceChartEntity();
|
cokingTraceChartEntity.setRelId(relId);
|
cokingTraceChartEntity.setName(e.getIndName());
|
cokingTraceChartEntity.setClock(clock);
|
cokingTraceChartEntity.setDataNo(e.getPointNo());
|
cokingTraceChartEntity.setDataType(e.getDataType());
|
|
Calendar clone = (Calendar) calendar.clone();
|
cokingTraceChartEntity.setEndTime(clone.getTime());
|
if (e.getExt2().equals("month")) {
|
clone.add(Calendar.MONTH,-1 * Integer.parseInt(e.getExt1()));
|
} else if (e.getExt2().equals("day")) {
|
clone.add(Calendar.DAY_OF_YEAR,-1 * Integer.parseInt(e.getExt1()));
|
}
|
cokingTraceChartEntity.setStartTime(clone.getTime());
|
cokingTraceChartEntity.setCreateDate(new Date());
|
cokingTraceChartEntityList.add(cokingTraceChartEntity);
|
|
// 异常数据处理
|
exDatalist.addAll(handleAbnormalData(e, cokingTraceChartEntity.getStartTime(), cokingTraceChartEntity.getEndTime(),relId,clock));
|
});
|
cokingTraceChartService.insert(cokingTraceChartEntityList);
|
// cokingTraceSuggestService.insert(suggestEntitieList);
|
cokingTraceDataService.insertList(exDatalist);
|
|
}
|
} catch (Exception ex) {
|
logger.error("runCokingOverviewTask运行异常",ex);
|
}
|
logger.info("runCokingOverviewTask运行完成");
|
|
}
|
|
private List<CokingTraceDataEntity> handleAbnormalData(CokingProcessConfEntity e, Date startTime, Date endTime, String relId, String clock) {
|
List<CokingTraceDataEntity> suggestEntities = new ArrayList<>();
|
switch (ProcessConfDataTypeEnum.getEumByCode(e.getDataType())) {
|
case DATAPOINT:
|
ApiPointValueQueryDTO queryDTO = new ApiPointValueQueryDTO();
|
queryDTO.setPointNo(e.getPointNo());
|
queryDTO.setStart(startTime);
|
queryDTO.setEnd(endTime);
|
List<ApiPointValueDTO> pointValues = dataPointApi.queryPointHistoryValue(queryDTO);
|
Map<Date, Double> pointValueMap = pointValues.stream().collect(Collectors.toMap(ApiPointValueDTO::getT, ApiPointValueDTO::getV, (e1, e2) -> e1));
|
Calendar calendar = Calendar.getInstance();
|
calendar.setTime(startTime);
|
while (!calendar.getTime().after(endTime)) {
|
String content = null;
|
if (pointValueMap.containsKey(calendar.getTime())) {
|
Double value = pointValueMap.get(calendar.getTime());
|
if (value.equals(0.0)) {
|
content = DateUtils.format(calendar.getTime()) + " " + e.getIndName() + "数据异常(数据为0)";
|
}else if (value.compareTo(Double.valueOf(e.getExt3())) > 0) {
|
content = DateUtils.format(calendar.getTime()) + " " + e.getIndName() + "数据异常(超上限)";
|
}else if (value.compareTo(Double.valueOf(e.getExt4())) < 0) {
|
content = DateUtils.format(calendar.getTime()) + " " + e.getIndName() + "数据异常(超下限)";
|
}
|
}else {
|
content = DateUtils.format(calendar.getTime()) + " " + e.getIndName() + "数据异常(无数据)";
|
}
|
if (StringUtils.isNotBlank(content)) {
|
CokingTraceDataEntity ctd = new CokingTraceDataEntity();
|
ctd.setId(UUID.randomUUID().toString());
|
ctd.setRelId(relId);
|
ctd.setProcess(ProcessTypeEnum.getEumByCode(e.getIndType()).getReportName());
|
ctd.setClock(clock);
|
ctd.setExObj(e.getIndType()+"_AD");
|
ctd.setExTime(calendar.getTime());
|
ctd.setExType(content);
|
suggestEntities.add(ctd);
|
}
|
calendar.add(Calendar.DAY_OF_YEAR,1);
|
}
|
break;
|
case IND:
|
ApiIndItemQueryDTO query = new ApiIndItemQueryDTO();
|
query.setItemNo(e.getPointNo());
|
query.setStart(startTime);
|
query.setEnd(endTime);
|
List<ApiIndItemValueDTO> indValues = indItemApi.queryIndItemHistoryValue(query);
|
Map<String, Double> indValueMap = indValues.stream().collect(Collectors.toMap(ApiIndItemValueDTO::getDataTime, ind -> Double.valueOf(ind.getDataValue().toString()), (e1, e2) -> e1));
|
Calendar intCalendar = Calendar.getInstance();
|
intCalendar.setTime(startTime);
|
while (!intCalendar.getTime().after(endTime)) {
|
String content = null;
|
String time = DateUtils.format(intCalendar.getTime());
|
if (indValueMap.containsKey(time)) {
|
Double value = indValueMap.get(time);
|
if (value.equals(0.0)) {
|
content = time + " " + e.getIndName() + "数据异常(数据为0)";
|
}else if (value.compareTo(Double.valueOf(e.getExt3())) > 0) {
|
content = time + " " + e.getIndName() + "数据异常(超上限)";
|
}else if (value.compareTo(Double.valueOf(e.getExt4())) < 0) {
|
content = time + " " + e.getIndName() + "数据异常(超下限)";
|
}
|
}else {
|
content = time + " " + e.getIndName() + "数据异常(无数据)";
|
}
|
if (StringUtils.isNotBlank(content)) {
|
CokingTraceDataEntity ctd = new CokingTraceDataEntity();
|
ctd.setId(UUID.randomUUID().toString());
|
ctd.setRelId(relId);
|
ctd.setProcess(ProcessTypeEnum.getEumByCode(e.getIndType()).getReportName());
|
ctd.setClock(clock);
|
ctd.setExObj(e.getIndType()+"_AD");
|
ctd.setExTime(intCalendar.getTime());
|
ctd.setExType(content);
|
suggestEntities.add(ctd);
|
// suggestEntities.add(new CokingTraceSuggestEntity(UUID.randomUUID().toString(),relId,ProcessTypeEnum.getEumByCode(e.getIndType()).getReportName(),e.getIndType()+"_AD",clock,content,new Date()));
|
}
|
intCalendar.add(Calendar.DAY_OF_YEAR,1);
|
}
|
break;
|
default:
|
break;
|
|
}
|
return suggestEntities;
|
}
|
}
|