| | |
| | | package com.iailab.module.ansteel.job.task; |
| | | |
| | | import com.iailab.framework.common.util.date.DateUtils; |
| | | import com.iailab.module.ansteel.api.entity.CokingProcessConfEntity; |
| | | import com.iailab.module.ansteel.api.entity.CokingProcessMainEntity; |
| | | import com.iailab.module.ansteel.api.service.CokingProcessConfService; |
| | | import com.iailab.module.ansteel.api.service.CokingProcessMainService; |
| | | import com.iailab.module.ansteel.common.enums.ProcessConfDataTypeEnum; |
| | | import com.iailab.module.ansteel.common.enums.ProcessIndDataTypeEnum; |
| | | 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 org.apache.commons.lang3.ObjectUtils; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | import java.util.concurrent.atomic.AtomicReference; |
| | | import java.util.stream.Collectors; |
| | |
| | | @Resource |
| | | private DataPointApi dataPointApi; |
| | | |
| | | @Resource |
| | | private IndItemApi indItemApi; |
| | | |
| | | @Override |
| | | public void run(String params) { |
| | | logger.info("RunCokingMainDayTask,参数为:{}", params); |
| | |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.set(Calendar.MILLISECOND, 0); |
| | | calendar.set(Calendar.SECOND, 0); |
| | | calendar.add(Calendar.DAY_OF_YEAR, -1); |
| | | String clock = DateUtils.format(calendar.getTime(), DateUtils.FORMAT_YEAR_MONTH_DAY); |
| | | CokingProcessConfEntity queryParams = new CokingProcessConfEntity(); |
| | | queryParams.setIndType("main"); |
| | | List<CokingProcessConfEntity> list = cokingProcessConfService.list(queryParams); |
| | | if (ObjectUtils.isNotEmpty(list)) { |
| | | //按照指标大类扩展字段ext1分类 并且按照sort排序 |
| | | // Map<String, List<CokingProcessConfEntity>> groupMap = list.stream().sorted(Comparator.comparing(CokingProcessConfEntity::getSort)) |
| | | // .collect(Collectors.groupingBy(CokingProcessConfEntity::getExt1, TreeMap::new, Collectors.toList())); |
| | | |
| | | // 先建立ext1到sort的映射关系 |
| | | Map<String, Integer> ext1ToSort = list.stream() |
| | | .collect(Collectors.toMap( |
| | | CokingProcessConfEntity::getExt1, |
| | | CokingProcessConfEntity::getSort, |
| | | (oldValue, newValue) -> oldValue)); |
| | | |
| | | // 然后按这个关系排序分组 |
| | | Map<String, List<CokingProcessConfEntity>> groupMap = list.stream() |
| | | .sorted(Comparator.comparing(CokingProcessConfEntity::getSort)) |
| | | .collect(Collectors.collectingAndThen( |
| | | Collectors.groupingBy(CokingProcessConfEntity::getExt1), |
| | | map -> map.entrySet().stream() |
| | | .sorted(Comparator.comparingInt( |
| | | e -> ext1ToSort.get(e.getKey()))) // 按ext1对应的sort值排序 |
| | | .collect(Collectors.toMap( |
| | | Map.Entry::getKey, |
| | | Map.Entry::getValue, |
| | | (a, b) -> a, |
| | | LinkedHashMap::new)))); |
| | | |
| | | // 获取当前日期时间 |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | // 减去一天得到昨天同一时间 |
| | | LocalDateTime yesterday = now.minusDays(1); |
| | | // 格式化输出 |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
| | | String formattedDateTime = yesterday.format(formatter); |
| | | //计数器 |
| | | AtomicReference<Integer> counter = new AtomicReference<>(1); |
| | | groupMap.forEach((group, confList) -> { |
| | | CokingProcessMainEntity cokingProcessMainEntity = new CokingProcessMainEntity(); |
| | | cokingProcessMainEntity.setInfoType("0"); |
| | | cokingProcessMainEntity.setSort(counter.getAndSet(counter.get() + 1)); |
| | | cokingProcessMainEntity.setCategory("day"); |
| | | cokingProcessMainEntity.setIndName(group); |
| | | cokingProcessMainEntity.setClock(formattedDateTime); |
| | | confList.forEach(cokingProcessConfEntity -> { |
| | | List<String> points = new ArrayList<>(); |
| | | points.add(cokingProcessConfEntity.getPointNo()); |
| | | Map<String, Object> stringObjectMap = dataPointApi.queryPointsRealValue(points); |
| | | //保存数据 |
| | | Object value = stringObjectMap.get(cokingProcessConfEntity.getPointNo()); |
| | | if(ObjectUtils.isNotEmpty(value)) { |
| | | if(cokingProcessConfEntity.getIndCode().endsWith("LSPJ")) { |
| | | cokingProcessMainEntity.setAvgValue(value.toString()); |
| | | } else if(cokingProcessConfEntity.getIndCode().endsWith("LLZ")) { |
| | | cokingProcessMainEntity.setTheoryValue(value.toString()); |
| | | } else if(cokingProcessConfEntity.getIndCode().endsWith("SJZ")) { |
| | | cokingProcessMainEntity.setActualValue(value.toString()); |
| | | } else if(cokingProcessConfEntity.getIndCode().endsWith("JZZ")) { |
| | | cokingProcessMainEntity.setStandValue(value.toString()); |
| | | } else if(cokingProcessConfEntity.getIndCode().endsWith("SSSJ")) { |
| | | cokingProcessMainEntity.setRealValue(value.toString()); |
| | | } |
| | | } |
| | | }); |
| | | cokingProcessMainService.save(cokingProcessMainEntity); |
| | | }); |
| | | if (CollectionUtils.isEmpty(list)) { |
| | | logger.info("ConfLis is Empty"); |
| | | return; |
| | | } |
| | | // 先建立ext1到sort的映射关系 |
| | | Map<String, Integer> ext1ToSort = list.stream() |
| | | .collect(Collectors.toMap( |
| | | CokingProcessConfEntity::getExt1, |
| | | CokingProcessConfEntity::getSort, |
| | | (oldValue, newValue) -> oldValue)); |
| | | |
| | | // 然后按这个关系排序分组 |
| | | Map<String, List<CokingProcessConfEntity>> groupMap = list.stream() |
| | | .sorted(Comparator.comparing(CokingProcessConfEntity::getSort)) |
| | | .collect(Collectors.collectingAndThen( |
| | | Collectors.groupingBy(CokingProcessConfEntity::getExt1), |
| | | map -> map.entrySet().stream() |
| | | .sorted(Comparator.comparingInt( |
| | | e -> ext1ToSort.get(e.getKey()))) // 按ext1对应的sort值排序 |
| | | .collect(Collectors.toMap( |
| | | Map.Entry::getKey, |
| | | Map.Entry::getValue, |
| | | (a, b) -> a, |
| | | LinkedHashMap::new)))); |
| | | |
| | | logger.info("清理旧数据"); |
| | | cokingProcessMainService.deleteByClock(clock); |
| | | |
| | | //计数器 |
| | | AtomicReference<Integer> counter = new AtomicReference<>(1); |
| | | groupMap.forEach((group, confList) -> { |
| | | CokingProcessMainEntity cokingProcessMainEntity = new CokingProcessMainEntity(); |
| | | cokingProcessMainEntity.setInfoType("0"); |
| | | cokingProcessMainEntity.setSort(counter.getAndSet(counter.get() + 1)); |
| | | cokingProcessMainEntity.setCategory("day"); |
| | | CokingProcessConfEntity cokingProcessConfEntity = confList.get(0); |
| | | cokingProcessMainEntity.setIndName(cokingProcessConfEntity.getExt3()); |
| | | cokingProcessMainEntity.setClock(clock); |
| | | confList.forEach(conf -> { |
| | | String value = ""; |
| | | switch (ProcessConfDataTypeEnum.getEumByCode(conf.getDataType())) { |
| | | case DATAPOINT: |
| | | List<String> points = new ArrayList<>(); |
| | | points.add(conf.getPointNo()); |
| | | Map<String, Object> pointsRealValue = dataPointApi.queryPointsRealValue(points); |
| | | value = pointsRealValue.get(conf.getPointNo()).toString(); |
| | | break; |
| | | case IND: |
| | | List<ApiIndItemValueDTO> indValues = indItemApi.queryIndItemDefaultValue(conf.getPointNo()); |
| | | if (!CollectionUtils.isEmpty(indValues)) { |
| | | value = indValues.get(indValues.size() - 1).getDataValue().toString(); |
| | | } |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | //保存数据 |
| | | if(ObjectUtils.isNotEmpty(value)) { |
| | | if(conf.getExt2().equals(ProcessIndDataTypeEnum.LSPJ.getCode())) { |
| | | cokingProcessMainEntity.setAvgValue(value.toString()); |
| | | } else if(conf.getExt2().equals(ProcessIndDataTypeEnum.LLZ.getCode())) { |
| | | cokingProcessMainEntity.setTheoryValue(value.toString()); |
| | | } else if(conf.getExt2().equals(ProcessIndDataTypeEnum.SJZ.getCode())) { |
| | | cokingProcessMainEntity.setActualValue(value.toString()); |
| | | } else if(conf.getExt2().equals(ProcessIndDataTypeEnum.JZZ.getCode())) { |
| | | cokingProcessMainEntity.setStandValue(value.toString()); |
| | | } else if(conf.getExt2().equals(ProcessIndDataTypeEnum.SSSJ.getCode())) { |
| | | cokingProcessMainEntity.setRealValue(value.toString()); |
| | | } |
| | | } |
| | | }); |
| | | cokingProcessMainService.save(cokingProcessMainEntity); |
| | | }); |
| | | |
| | | } catch (Exception ex) { |
| | | logger.error("RunCokingMainDayTask运行异常"); |