| | |
| | | package com.gs.xky.task; |
| | | |
| | | |
| | | import cn.hutool.core.collection.ListUtil; |
| | | import com.gs.xky.config.DingTalkParam; |
| | | import com.gs.xky.config.DingTalkResponse; |
| | | import com.gs.xky.dto.EmployeeInfo; |
| | | import com.gs.xky.entity.MesInvItemArn; |
| | | import com.gs.xky.service.*; |
| | | import com.gs.xky.service.VwCjScSjTsBbService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | import java.util.concurrent.atomic.AtomicBoolean; |
| | | |
| | | @Component |
| | | @RequiredArgsConstructor |
| | | public class ScheduledTasks { |
| | | private static final Logger log = LoggerFactory.getLogger(ScheduledTasks.class); |
| | | |
| | | private final XkyService xkyService; |
| | | private final VwCjScSjTsBbService vwCjScSjTsBbService; |
| | | |
| | | private final ApiService apiService; |
| | | |
| | | private final MesStaffService staffService; |
| | | |
| | | private final DeliveryNoticeService deliveryNoticeService; |
| | | |
| | | private final MesInvItemArnService invItemArnService; |
| | | private final AtomicBoolean exportTaskRunning = new AtomicBoolean(false); |
| | | |
| | | /** |
| | | * 每五分钟执行一次 |
| | | * 获取设备最近的一条记录 |
| | | * |
| | | * @return void |
| | | * @author tjx |
| | | * @description TODO |
| | | * @date 2024/9/27 21:48 |
| | | */ |
| | | @Scheduled(cron = "0 0/5 * * * ?") |
| | | public void getDeviceRealTimeData() throws IOException { |
| | | xkyService.GetSaveDetail(); |
| | | public void getDeviceRealTimeData() { |
| | | |
| | | } |
| | | |
| | | @Scheduled(cron = "10 3,8,13,18,23,28,33,38,43,48,53,58 * * * ?") |
| | | public void compensateMethod() throws IOException { |
| | | // 补偿逻辑 |
| | | List<MesInvItemArn> itemArnMinus = invItemArnService.getItemArnMinus(); |
| | | deliveryNoticeService.processMesInvItemArnStatusAsync(itemArnMinus); |
| | | /** |
| | | * 每天上午9点执行 |
| | | * 导出生产数据并发送钉钉消息 |
| | | */ |
| | | @Async("taskExecutor") |
| | | @Scheduled(cron = "0 0 9 * * ?") |
| | | public void exportAndSendProductionDataTask() { |
| | | if (!exportTaskRunning.compareAndSet(false, true)) { |
| | | log.warn("生产数据导出任务正在执行中,跳过本次执行"); |
| | | return; |
| | | } |
| | | |
| | | try { |
| | | log.info("开始执行生产数据导出并发送钉钉任务"); |
| | | boolean result = vwCjScSjTsBbService.exportAndSendToDingtalk(); |
| | | |
| | | if (result) { |
| | | log.info("生产数据导出并发送钉钉任务执行成功"); |
| | | } else { |
| | | log.error("生产数据导出并发送钉钉任务执行失败"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("生产数据导出并发送钉钉任务执行异常", e); |
| | | } finally { |
| | | exportTaskRunning.set(false); |
| | | } |
| | | } |
| | | |
| | | @Scheduled(cron = "0 0/53 * * * ?") |
| | | public void getDinTalkData() throws IOException { |
| | | DingTalkParam dingTalkParam = new DingTalkParam(1); |
| | | |
| | | DingTalkResponse<EmployeeInfo> employeeInfoDingTalkResponse = apiService.sendListRequest(dingTalkParam, EmployeeInfo.class, "http://192.168.1.64/eHR/eHRExternalService/Service.ashx"); |
| | | |
| | | |
| | | List<EmployeeInfo> collect = employeeInfoDingTalkResponse.getData().stream().filter(s -> "造梦者(浙江)科技有限公司".equals(s.getCUnitName())).collect(Collectors.toList()); |
| | | System.out.println(collect.size()); |
| | | |
| | | List<List<EmployeeInfo>> partition = ListUtil.partition(collect, 100); |
| | | |
| | | partition.forEach(staffService::UpdateStaff); |
| | | } |
| | | } |