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 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 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; } } }