提交 | 用户 | 时间
|
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 |
/** |
|
23 |
* 压空,计算机组比功率,计算结果写入测点 |
|
24 |
* 定时出发,5 0/1 * * * ? |
|
25 |
* |
|
26 |
* @author PanZhibao |
|
27 |
* @Description |
|
28 |
* @createTime 2024年12月31日 |
|
29 |
*/ |
|
30 |
@Component("runScheduleAirClassMonthTask") |
|
31 |
public class RunScheduleAirClassMonthTask implements ITask { |
|
32 |
private Logger logger = LoggerFactory.getLogger(getClass()); |
|
33 |
|
|
34 |
@Resource |
|
35 |
private McsApi mcsApi; |
|
36 |
|
|
37 |
@Autowired |
|
38 |
private MdkApi mdkApi; |
|
39 |
|
|
40 |
@Override |
|
41 |
public void run(String params) { |
|
42 |
logger.info("RunScheduleAirTask,参数为:{}", params); |
|
43 |
try { |
|
44 |
|
|
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 |
// 根据条件查找方案 |
|
55 |
List<StScheduleSchemeDTO> schemeList = mcsApi.listScheduleScheme(ScheduleTriggerMethodEnum.JOB.getCode(), params); |
|
56 |
if (CollectionUtils.isEmpty(schemeList)) { |
|
57 |
logger.info("方案为空"); |
|
58 |
return; |
|
59 |
} |
|
60 |
|
|
61 |
for (StScheduleSchemeDTO scheme : schemeList) { |
|
62 |
MdkScheduleReqDTO dto = new MdkScheduleReqDTO(); |
|
63 |
dto.setScheduleTime(scheduleTime); |
|
64 |
dto.setScheduleCode(scheme.getCode()); |
|
65 |
LocalDateTime now = LocalDateTime.now(); |
|
66 |
LocalDate startOfMonth = LocalDate.now().withDayOfMonth(1); |
|
67 |
LocalDateTime startOfMonthAtMidnight = startOfMonth.atStartOfDay(); |
|
68 |
long timeDifference = ChronoUnit.MINUTES.between(startOfMonthAtMidnight, now); |
|
69 |
Map<Integer, Integer> dynamicDataLength = new HashMap<>(); |
|
70 |
dynamicDataLength.put(1, (int) timeDifference); |
|
71 |
dynamicDataLength.put(2, (int) timeDifference); |
|
72 |
dynamicDataLength.put(3, (int) timeDifference); |
|
73 |
dto.setDynamicDataLength( dynamicDataLength); |
|
74 |
Map<String, String> dynamicSettings = new HashMap<>(); |
|
75 |
dynamicSettings.put("embedDim", String.valueOf(timeDifference)); |
|
76 |
dto.setDynamicSettings(dynamicSettings); |
d8b11e
|
77 |
MdkScheduleRespDTO mdkScheduleRespDTO = mdkApi.doSchedule(dto); |
b50a43
|
78 |
// 结果写入测点 |
J |
79 |
mdkApi.scheduleModelOut(mdkScheduleRespDTO); |
|
80 |
} |
|
81 |
logger.info(params + "调度方案执行完成"); |
|
82 |
} catch (Exception ex) { |
|
83 |
logger.error("RunScheduleAirTask运行异常"); |
|
84 |
ex.printStackTrace(); |
|
85 |
} |
|
86 |
logger.info("RunScheduleAirTask运行完成"); |
|
87 |
} |
|
88 |
} |