沙钢智慧能源系统后端代码
潘志宝
5 天以前 17d9680846fdec953c086695ec0040e510998f4c
提交 | 用户 | 时间
b50a43 1 package com.iailab.module.shasteel.job.task;
J 2
3 import com.iailab.module.model.api.mcs.McsApi;
4 import com.iailab.module.model.api.mcs.dto.StScheduleSchemeDTO;
5 import com.iailab.module.model.api.mdk.MdkApi;
6 import com.iailab.module.model.api.mdk.dto.MdkScheduleReqDTO;
7 import com.iailab.module.model.api.mdk.dto.MdkScheduleRespDTO;
8 import com.iailab.module.model.enums.ScheduleTriggerMethodEnum;
9 import org.apache.commons.lang3.StringUtils;
10 import org.slf4j.Logger;
11 import org.slf4j.LoggerFactory;
12 import org.springframework.beans.factory.annotation.Autowired;
13 import org.springframework.stereotype.Component;
14 import org.springframework.util.CollectionUtils;
15
16 import javax.annotation.Resource;
17 import java.time.LocalDate;
18 import java.time.LocalDateTime;
19 import java.time.temporal.ChronoUnit;
20 import java.util.*;
21
22 /**
17d968 23  * 压缩空气运行指标(月)
24  * 动态数据长度,月初到当天
25  * 每天更新,10 0 0 1/1 * ?
b50a43 26  *
J 27  * @author PanZhibao
28  * @Description
29  * @createTime 2024年12月31日
30  */
17d968 31 @Component("runScheduleAirIndexMonthTask")
32 public class RunScheduleAirIndexMonthTask implements ITask {
b50a43 33     private Logger logger = LoggerFactory.getLogger(getClass());
J 34
35     @Resource
36     private McsApi mcsApi;
37
38     @Autowired
39     private MdkApi mdkApi;
40
41     @Override
42     public void run(String params) {
17d968 43         logger.info("RunScheduleAirIndexMonthTask,参数为:{}", params);
b50a43 44         try {
J 45             Calendar calendar = Calendar.getInstance();
46             calendar.set(Calendar.MILLISECOND, 0);
47             calendar.set(Calendar.SECOND, 0);
48             Date scheduleTime = calendar.getTime();
49             if (StringUtils.isEmpty(params)) {
50                 logger.info("参数为空");
51                 return;
52             }
53             // 根据条件查找方案
54             List<StScheduleSchemeDTO> schemeList = mcsApi.listScheduleScheme(ScheduleTriggerMethodEnum.JOB.getCode(), params);
55             if (CollectionUtils.isEmpty(schemeList)) {
56                 logger.info("方案为空");
57                 return;
58             }
59
60             for (StScheduleSchemeDTO scheme : schemeList) {
61                 MdkScheduleReqDTO dto = new MdkScheduleReqDTO();
62                 dto.setScheduleTime(scheduleTime);
63                 dto.setScheduleCode(scheme.getCode());
64                 LocalDateTime now = LocalDateTime.now();
65                 LocalDate startOfMonth = LocalDate.now().withDayOfMonth(1);
66                 LocalDateTime startOfMonthAtMidnight = startOfMonth.atStartOfDay();
67                 long timeDifference = ChronoUnit.MINUTES.between(startOfMonthAtMidnight, now);
68                 Map<Integer, Integer> dynamicDataLength = new HashMap<>();
69                 dynamicDataLength.put(1,  (int) timeDifference);
70                 dynamicDataLength.put(2,  (int) timeDifference);
71                 dynamicDataLength.put(3,  (int) timeDifference);
72                 dto.setDynamicDataLength( dynamicDataLength);
73                 Map<String, String> dynamicSettings = new HashMap<>();
74                 dynamicSettings.put("embedDim", String.valueOf(timeDifference));
75                 dto.setDynamicSettings(dynamicSettings);
d8b11e 76                 MdkScheduleRespDTO mdkScheduleRespDTO = mdkApi.doSchedule(dto);
b50a43 77                 // 结果写入测点
J 78                 mdkApi.scheduleModelOut(mdkScheduleRespDTO);
79             }
80             logger.info(params + "调度方案执行完成");
81         } catch (Exception ex) {
17d968 82             logger.error("RunScheduleAirIndexMonthTask运行异常");
b50a43 83             ex.printStackTrace();
J 84         }
17d968 85         logger.info("RunScheduleAirIndexMonthTask运行完成");
b50a43 86     }
J 87 }