package com.fjhx.task.controller;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.fjhx.stock.service.StockBackPlanService;
import com.fjhx.stock.service.StockCheckrecordService;
import com.fjhx.task.service.ScheduleTaskService;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.launch.BladeApplication;
import org.springblade.core.tool.utils.ThreadUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

@Configuration
@EnableScheduling
@Slf4j
public class ScheduleTaskController {

    @Autowired
    private ScheduleTaskService scheduleTaskService;

    @Autowired
    private StockBackPlanService stockBackPlanService;

    @Autowired
    private StockCheckrecordService stockCheckrecordService;

    /**
     * 定时推送id与工号不一致的信息
     */
    @Scheduled(cron = "0 0/10 * * * ?")
    private void stockAcceptActionTask() {
        if (BladeApplication.isLocalDev()) {
            return;
        }
        scheduleTaskService.stockAcceptActionTask();
    }

    /**
     * 同步领料信息
     */
    @Scheduled(cron = "30 0/19 * * * ?")
    private void schedulingTask() {
        if (BladeApplication.isLocalDev()) {
            return;
        }
        scheduleTaskService.schedulingTask();
    }

    /**
     * 统计排班数据
     */
    @Scheduled(cron = "0 0/5 * * * ?")
    // @PostConstruct
    private void synchronousScheduling() {
        if (BladeApplication.isLocalDev()) {
            return;
        }
        stockBackPlanService.synchronousScheduling();
    }

    /**
     * 盘点
     */
    @Scheduled(cron = "0 0 1 * * ?")
    // @PostConstruct
    private void checkStart() {
        if (BladeApplication.isLocalDev()) {
            return;
        }
        log.error("开始扫描");
        Long check1ForwardSessionId = IdWorker.getId();
        Long check4ForwardSessionId = IdWorker.getId();

        stockCheckrecordService.checkStart("check1", check1ForwardSessionId, "c185883dba22478cb593d33f6b66cc53");
        stockCheckrecordService.checkStart("check4", check4ForwardSessionId, "0b8f584250bb4b40b72d641ce4849d15");

        ThreadUtil.sleep(1000 * 60 * 10);

        stockCheckrecordService.checkEnd("check1", check1ForwardSessionId, "c185883dba22478cb593d33f6b66cc53");
        stockCheckrecordService.checkEnd("check4", check4ForwardSessionId, "0b8f584250bb4b40b72d641ce4849d15");
    }

}
