package com.wms_main.service.quartz_job.job_executor;

import com.wms_main.repository.utils.StringUtils;
import com.wms_main.service.quartz_job.IOutsExecutorService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.PersistJobDataAfterExecution;

/**
 * 定时任务定义类---出库单解析类
 */
@Slf4j
@PersistJobDataAfterExecution
// 以下注解用于实现fixed_delay
@DisallowConcurrentExecution
@RequiredArgsConstructor
public class OutsExecutor implements Job {
    private final IOutsExecutorService outsExecutorService;// 出库单解析服务

    /**
     * 运行定时任务
     *
     * @param jobExecutionContext 定时任务执行的环境（上下文）
     */
    @Override
    public void execute(JobExecutionContext jobExecutionContext) {
        // 解析工作（配料）
        try {
            outsExecutorService.executeKateWorks();
        } catch (Exception e) {
            log.error("解析工作（配料）失败{}", StringUtils.objectToString(e));
        }
        // 处理出库单
        try {
            outsExecutorService.executeOuts();
        } catch (Exception e) {
            log.error("处理出库单失败{}", StringUtils.objectToString(e));
        }
        // 处理盘点单
        try {
            outsExecutorService.executeInventory();
        } catch (Exception e) {
            log.error("处理盘点单失败{}", StringUtils.objectToString(e));
        }
    }
}
