package com.prolog.eis.schedule;

import com.prolog.eis.common.util.RunTimeHelper;
import com.prolog.eis.service.out.TimeTaskService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RequiredArgsConstructor
public class OutboundSchedule {

    private final TimeTaskService timeTaskService;
    private final RedisTemplate redisTemplate;

    /**
     * 拆零区调度逻辑整体逻辑
     */
    @Scheduled(initialDelay = 3000, fixedDelay = 400)
    public void dispatch() throws Exception {
        RunTimeHelper.RunDispatch("拆零区调度逻辑", () -> {
            try {
                timeTaskService.dispatch();
            } catch (Exception e) {
                log.error("拆零区调度逻辑异常：" + e.getMessage(), e);
            }
        });
    }


    /**
     * 拆零区盘点/养护定位库存
     */
    @Scheduled(initialDelay = 3000, fixedDelay = 3000)
    public void createContainerTask() throws Exception {
        RunTimeHelper.RunDispatch("拆零区盘点/养护定位库存任务", () -> {
            try {
                timeTaskService.createContainerTask();
            } catch (Exception e) {
                log.error("拆零区盘点/养护定位库存异常：" + e.getMessage(), e);
            }
        });
    }

    /**
     * 拆零区托盘库合托搬运到站台
     */
    @Scheduled(initialDelay = 3000, fixedDelay = 3000)
    public void mergeContainerToStation() throws Exception {
        RunTimeHelper.RunDispatch("拆零区托盘库合托搬运到站台任务", () -> {
            try {
                timeTaskService.mergeContainerToStation();
            } catch (Exception e) {
                log.error("拆零区托盘库合托搬运到站台异常：" + e.getMessage(), e);
            }
        });
    }


    /**
     * 拆零区托盘库合托搬运到站台任务
     */
    @Scheduled(initialDelay = 3000, fixedDelay = 3000)
    public void sendMcsCarryTask() throws Exception {
        RunTimeHelper.RunDispatch("拆零区托盘库合托搬运到站台任务", () -> {
            try {
                timeTaskService.mergeContainerToStation();
            } catch (Exception e) {
                log.error("拆零区托盘库合托搬运到站台异常：" + e.getMessage(), e);
            }
        });
    }

}
