对比新文件 |
| | |
| | | package com.iailab.module.ansteel.job.task; |
| | | |
| | | 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.data.api.ind.IndItemApi; |
| | | import com.iailab.module.data.api.ind.dto.ApiIndItemValueDTO; |
| | | import com.iailab.module.data.api.point.DataPointApi; |
| | | 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.math.BigDecimal; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @description: 主图主工序指标 |
| | | * @author: dzd |
| | | * @date: 2025/4/27 13:56 |
| | | **/ |
| | | @Slf4j |
| | | @Component("runCokingMainTask") |
| | | public class RunCokingMainTask implements ITask{ |
| | | private Logger logger = LoggerFactory.getLogger(getClass()); |
| | | |
| | | @Resource |
| | | private CokingProcessConfService cokingProcessConfService; |
| | | @Resource |
| | | private DataPointApi dataPointApi; |
| | | @Resource |
| | | private IndItemApi indItemApi; |
| | | @Resource |
| | | private CokingProcessMainService cokingProcessMainService; |
| | | |
| | | @Override |
| | | public void run(String processTypes) { |
| | | logger.info("runCokingMainTask,参数为:{}", 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("ConfList is Empty"); |
| | | continue; |
| | | } |
| | | |
| | | 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); |
| | | |
| | | // 清理旧数据 |
| | | cokingProcessMainService.deleteByClock(clock); |
| | | |
| | | // 主工序指标 筛选info_type = 0 |
| | | List<CokingProcessConfEntity> indList = list.stream().filter(e -> e.getInfoType().equals("0")).collect(Collectors.toList()); |
| | | if (CollectionUtils.isEmpty(indList)) { |
| | | continue; |
| | | } |
| | | List<CokingProcessMainEntity> processMainEntities = new ArrayList<>(indList.size()); |
| | | for (CokingProcessConfEntity conf : indList) { |
| | | if (StringUtils.isBlank(conf.getDataType())) { |
| | | logger.info("DataType is Empty"); |
| | | continue; |
| | | } |
| | | if (StringUtils.isBlank(conf.getPointNo())) { |
| | | logger.info("PointNo is Empty"); |
| | | continue; |
| | | } |
| | | CokingProcessMainEntity processMainEntity = new CokingProcessMainEntity(); |
| | | processMainEntity.setId(UUID.randomUUID().toString()); |
| | | processMainEntity.setCategory("day"); |
| | | processMainEntity.setClock(clock); |
| | | processMainEntity.setInfoType(conf.getInfoType()); |
| | | processMainEntity.setIndCode(conf.getIndCode()); |
| | | processMainEntity.setIndName(conf.getIndName()); |
| | | processMainEntity.setSort(conf.getSort()); |
| | | // 日实际值 |
| | | Double value = getConfValue(conf.getDataType(),conf.getPointNo()); |
| | | processMainEntity.setRealValue(value == null ? BigDecimal.ZERO : BigDecimal.valueOf(value)); |
| | | |
| | | // 基准值、理论值 来源模型下发结果 |
| | | Double standValue = getConfValue("DATAPOINT",conf.getExt1()); |
| | | processMainEntity.setStandValue(standValue == null ? BigDecimal.ZERO : BigDecimal.valueOf(standValue)); |
| | | Double theoryValue = getConfValue("DATAPOINT",conf.getExt2()); |
| | | processMainEntity.setTheoryValue(theoryValue == null ? BigDecimal.ZERO : BigDecimal.valueOf(theoryValue)); |
| | | |
| | | // 计算 月累计 |
| | | calendar.add(Calendar.DAY_OF_YEAR, -29); |
| | | String clock_30 = DateUtils.format(calendar.getTime(), DateUtils.FORMAT_YEAR_MONTH_DAY); |
| | | List<CokingProcessMainEntity> historyList_30 = cokingProcessMainService.historyList(clock_30, clock, "day",conf.getIndCode()); |
| | | historyList_30.add(processMainEntity); |
| | | double monthValue = historyList_30.stream().mapToDouble(e -> e.getRealValue().doubleValue()).sum(); |
| | | processMainEntity.setMonthValue(BigDecimal.valueOf(monthValue)); |
| | | |
| | | // 计算 历史平均 |
| | | calendar.add(Calendar.DAY_OF_YEAR, -60); |
| | | String clock_90 = DateUtils.format(calendar.getTime(), DateUtils.FORMAT_YEAR_MONTH_DAY); |
| | | List<CokingProcessMainEntity> historyList_90 = cokingProcessMainService.historyList(clock_90, clock, "day",conf.getIndCode()); |
| | | historyList_90.add(processMainEntity); |
| | | double avgValue = historyList_90.stream().mapToDouble(e -> e.getRealValue().doubleValue()).average().orElse(0.0); |
| | | processMainEntity.setAvgValue(BigDecimal.valueOf(avgValue)); |
| | | // 历史最优 |
| | | double baseValue = 0.0; |
| | | if (Double.valueOf(conf.getExt3()) > 0.0) { |
| | | baseValue = historyList_90.stream().mapToDouble(e -> e.getRealValue().doubleValue()).max().orElse(0.0); |
| | | }else { |
| | | baseValue = historyList_90.stream().mapToDouble(e -> e.getRealValue().doubleValue()).min().orElse(0.0); |
| | | } |
| | | processMainEntity.setBaseValue(BigDecimal.valueOf(baseValue)); |
| | | |
| | | |
| | | processMainEntities.add(processMainEntity); |
| | | } |
| | | cokingProcessMainService.save(processMainEntities); |
| | | } |
| | | } catch (Exception ex) { |
| | | logger.error("runCokingMainTask运行异常",ex); |
| | | } |
| | | logger.info("runCokingMainTask运行完成"); |
| | | } |
| | | |
| | | private Double getConfValue(String dataType, String pointNo) { |
| | | Double value = null; |
| | | switch (ProcessConfDataTypeEnum.getEumByCode(dataType)) { |
| | | case DATAPOINT: |
| | | List<String> points = new ArrayList<>(); |
| | | points.add(pointNo); |
| | | Map<String, Object> pointsRealValue = dataPointApi.queryPointsRealValue(points); |
| | | if (pointsRealValue.containsKey(pointNo)) { |
| | | value = Double.valueOf(pointsRealValue.get(pointNo).toString()); |
| | | } |
| | | break; |
| | | case IND: |
| | | List<ApiIndItemValueDTO> indValues = indItemApi.queryIndItemDefaultValue(pointNo); |
| | | if (!CollectionUtils.isEmpty(indValues)) { |
| | | value = Double.valueOf(indValues.get(0).getDataValue().toString()); |
| | | } |
| | | break; |
| | | case MODEL: |
| | | break; |
| | | default: |
| | | break; |
| | | |
| | | } |
| | | return value; |
| | | } |
| | | } |