tjx
2025-11-12 eb8196ba93963893dc77f4ae6eae0e742e2ce133
src/main/java/com/gs/xky/task/ScheduledTasks.java
@@ -1,57 +1,60 @@
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.service.ApiService;
import com.gs.xky.service.MesStaffService;
import com.gs.xky.service.XkyService;
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 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 = "0 0/53 * * * ?")
    public void getDinTalkData() throws IOException {
        DingTalkParam dingTalkParam = new DingTalkParam(1);
    /**
     * 每天上午9点执行
     * 导出生产数据并发送钉钉消息
     */
    @Async("taskExecutor")
    @Scheduled(cron = "0 0 9 * * ?")
    public void exportAndSendProductionDataTask() {
        if (!exportTaskRunning.compareAndSet(false, true)) {
            log.warn("生产数据导出任务正在执行中,跳过本次执行");
            return;
        }
        DingTalkResponse<EmployeeInfo> employeeInfoDingTalkResponse = apiService.sendListRequest(dingTalkParam, EmployeeInfo.class, "http://192.168.1.64/eHR/eHRExternalService/Service.ashx");
        try {
            log.info("开始执行生产数据导出并发送钉钉任务");
            boolean result = vwCjScSjTsBbService.exportAndSendToDingtalk();
        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);
            if (result) {
                log.info("生产数据导出并发送钉钉任务执行成功");
            } else {
                log.error("生产数据导出并发送钉钉任务执行失败");
            }
        } catch (Exception e) {
            log.error("生产数据导出并发送钉钉任务执行异常", e);
        } finally {
            exportTaskRunning.set(false);
        }
    }
}