tjx
昨天 a53e6872c70ba7c6c870627007ece21df9bcedbc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package com.hk.NumericalCollection.task;
 
 
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.hk.NumericalCollection.entity.DevMachine;
import com.hk.NumericalCollection.service.*;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import java.util.List;
 
@Component
@RequiredArgsConstructor
public class ScheduledTasksNoOrder {
 
    private final INumericalNoOrderService numericalNoOrderService;
 
    private final DevMachineService devMachineService;
 
    private final INumericalService numericalService;
 
 
    /**
     *  获取所有机台的基础数据
     *
     * @return void
     * @author tjx
     * @date 2024/9/27 21:48
     */
    @Scheduled(cron = "0 0 7 * * ?")
    public void SoDeviceList() throws Exception {
        numericalService.SoDeviceList();
    }
 
    /**
     * 每五分钟执行一次
     * 获取设备最近的一条记录
     *
     * @return void
     * @author tjx
     * @description TODO
     * @date 2024/9/27 21:48
     */
    @Scheduled(cron = "0 0/2 * * * ?")
    public void getDeviceRealTimeData() {
        List<DevMachine> list = devMachineService.list();
        list.forEach(s -> {
            try {
                numericalNoOrderService.getDeviceRealTimeData(s.getDevNo());
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        });
    }
 
    /**
     * 每天早上7:35执行一次
     * 获取所有设备的故障列表(昨天7:30到今天7:30)
     *
     * @return void
     * @author tjx
     * @date 2024/12/17
     */
    @Scheduled(cron = "0 35 7 * * ?")
    public void GetAllDeviceErrorList() throws Exception {
        DateTime yesterday = DateUtil.yesterday();
        DateTime startDateTime = DateUtil.parse(DateUtil.format(yesterday, "yyyy-MM-dd") + " 07:30:00");
        DateTime endDateTime = DateUtil.parse(DateUtil.format(DateUtil.date(), "yyyy-MM-dd") + " 07:30:00");
 
        String startDate = DateUtil.format(startDateTime, "yyyy-MM-dd HH:mm:ss");
        String endDate = DateUtil.format(endDateTime, "yyyy-MM-dd HH:mm:ss");
 
        try {
            List<DevMachine> list = devMachineService.list();
            for (DevMachine machine : list) {
                numericalNoOrderService.getDeviceErrorList(machine.getDevNo(), startDate, endDate);
                System.out.println("设备 " + machine.getDevNo() + " 故障列表获取成功");
            }
        } catch (Exception e) {
            System.err.println("批量获取设备故障列表失败: " + e.getMessage());
            throw e;
        }
    }
 
}