| | |
| | | package com.iailab.module.ansteel.job.task; |
| | | |
| | | import com.iailab.module.ansteel.api.entity.CokingProcessConfEntity; |
| | | import com.iailab.module.ansteel.api.entity.CokingProdDayEntity; |
| | | import com.iailab.module.ansteel.api.service.CokingProcessConfService; |
| | | import com.iailab.module.ansteel.api.service.CokingProdDayService; |
| | | import com.iailab.framework.common.util.date.DateUtils; |
| | | import com.iailab.module.ansteel.coking.entity.CokingAnalyIndEntity; |
| | | import com.iailab.module.ansteel.coking.entity.CokingProcessConfEntity; |
| | | import com.iailab.module.ansteel.coking.entity.CokingProdDayEntity; |
| | | import com.iailab.module.ansteel.coking.entity.CokingTraceIndEntity; |
| | | import com.iailab.module.ansteel.coking.service.CokingProcessConfService; |
| | | import com.iailab.module.ansteel.coking.service.CokingProdDayService; |
| | | import com.iailab.module.ansteel.coking.service.CokingTraceIndService; |
| | | 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 com.iailab.module.model.api.mcs.McsApi; |
| | | import com.iailab.module.model.api.mcs.dto.StScheduleSchemeDTO; |
| | | import com.iailab.module.model.api.mdk.MdkApi; |
| | | import com.iailab.module.model.api.mdk.dto.MdkScheduleReqDTO; |
| | | import com.iailab.module.model.api.mdk.dto.MdkScheduleRespDTO; |
| | | import com.iailab.module.model.enums.ScheduleTriggerMethodEnum; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | 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.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 生成焦化日前生产信息 |
| | | * 0 5 0 * * ? |
| | | * |
| | | * @author HouZhongjian |
| | | * @Description |
| | | * @createTime 2025年04月12日 |
| | |
| | | private CokingProdDayService cokingProdDayService; |
| | | |
| | | @Resource |
| | | private CokingTraceIndService cokingTraceIndService; |
| | | |
| | | @Resource |
| | | private DataPointApi dataPointApi; |
| | | |
| | | @Resource |
| | | private IndItemApi indItemApi; |
| | | |
| | | @Override |
| | | public void run(String params) { |
| | | logger.info("RunCokingProdDayTask,参数为:{}", params); |
| | | try { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.set(Calendar.MILLISECOND, 0); |
| | | calendar.set(Calendar.SECOND, 0); |
| | | CokingProcessConfEntity queryParams = new CokingProcessConfEntity(); |
| | | queryParams.setIndType("prod_day"); |
| | | List<CokingProcessConfEntity> list = cokingProcessConfService.list(queryParams); |
| | | if (ObjectUtils.isNotEmpty(list)) { |
| | | // List<String> points = list.stream().map(CokingProcessConfEntity::getIndCode).collect(Collectors.toList()); |
| | | // Map<String, Object> stringObjectMap = dataPointApi.queryPointsRealValue(points); |
| | | // 获取当前日期时间 |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | // 减去一天得到昨天同一时间 |
| | | LocalDateTime yesterday = now.minusDays(1); |
| | | // 格式化输出 |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
| | | String formattedDateTime = yesterday.format(formatter); |
| | | |
| | | list.stream().forEach(cokingProcessConfEntity -> { |
| | | List<String> points = new ArrayList<>(); |
| | | points.add(cokingProcessConfEntity.getPointNo()); |
| | | Map<String, Object> stringObjectMap = dataPointApi.queryPointsRealValue(points); |
| | | //保存数据 |
| | | if(ObjectUtils.isNotEmpty(stringObjectMap.get(cokingProcessConfEntity.getPointNo()))) { |
| | | CokingProdDayEntity cokingProdDayEntity = new CokingProdDayEntity(); |
| | | cokingProdDayEntity.setInfoType("0"); |
| | | cokingProdDayEntity.setSort(cokingProcessConfEntity.getSort()); |
| | | cokingProdDayEntity.setIndName(cokingProcessConfEntity.getIndName()); |
| | | cokingProdDayEntity.setIndUnit(cokingProcessConfEntity.getIndUnit()); |
| | | cokingProdDayEntity.setIndValue(stringObjectMap.get(cokingProcessConfEntity.getPointNo()).toString()); |
| | | cokingProdDayEntity.setClock(formattedDateTime); |
| | | cokingProdDayService.save(cokingProdDayEntity); |
| | | } |
| | | }); |
| | | 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.add(Calendar.DAY_OF_YEAR, -1); |
| | | String clock = DateUtils.format(calendar.getTime(), DateUtils.FORMAT_YEAR_MONTH_DAY); |
| | | String clock2 = ""; |
| | | int hour = calendar.get(Calendar.HOUR_OF_DAY); |
| | | if (hour == 0) { |
| | | clock2 = clock.concat("-").concat("A"); |
| | | } else if (hour == 8) { |
| | | clock2 = clock.concat("-").concat("B"); |
| | | } else if (hour == 16) { |
| | | clock2 = clock.concat("-").concat("C"); |
| | | } |
| | | logger.info("清理旧数据"); |
| | | cokingProdDayService.deleteByClock(clock); |
| | | for (CokingProcessConfEntity conf : list) { |
| | | if (StringUtils.isBlank(conf.getDataType())) { |
| | | logger.info("DataType is Empty"); |
| | | continue; |
| | | } |
| | | if (StringUtils.isBlank(conf.getPointNo())) { |
| | | logger.info("PointNo is Empty"); |
| | | continue; |
| | | } |
| | | 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; |
| | | case MODEL: |
| | | value = "100"; |
| | | break; |
| | | default: |
| | | break; |
| | | |
| | | } |
| | | saveProdDay(conf, value, clock); |
| | | saveTraceInd(conf, value, clock2); |
| | | } |
| | | } catch (Exception ex) { |
| | | logger.error("RunCokingProdDayTask运行异常"); |
| | | ex.printStackTrace(); |
| | |
| | | logger.info("RunCokingProdDayTask运行完成"); |
| | | |
| | | } |
| | | |
| | | private void saveTraceInd(CokingProcessConfEntity conf, String value, String clock) { |
| | | CokingTraceIndEntity cokingTraceIndEntity = new CokingTraceIndEntity(); |
| | | cokingTraceIndEntity.setTitle(conf.getIndType()); |
| | | cokingTraceIndEntity.setClock(clock); |
| | | cokingTraceIndEntity.setIndName(conf.getIndName()); |
| | | cokingTraceIndEntity.setIndValue(value); |
| | | cokingTraceIndEntity.setIndUnit(conf.getIndUnit()); |
| | | cokingTraceIndService.save(cokingTraceIndEntity); |
| | | } |
| | | |
| | | private void saveProdDay(CokingProcessConfEntity conf, String value, String clock) { |
| | | CokingProdDayEntity cokingProdDayEntity = new CokingProdDayEntity(); |
| | | cokingProdDayEntity.setInfoType(conf.getInfoType()); |
| | | cokingProdDayEntity.setSort(conf.getSort()); |
| | | cokingProdDayEntity.setIndName(conf.getIndName()); |
| | | cokingProdDayEntity.setIndUnit(conf.getIndUnit()); |
| | | cokingProdDayEntity.setIndValue(value); |
| | | cokingProdDayEntity.setClock(clock); |
| | | cokingProdDayService.save(cokingProdDayEntity); |
| | | } |
| | | } |