package com.zm.order.tool.server.listener;

import com.zm.order.tool.server.service.*;
import com.zm.util.dto.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 *
 * @className: DelOrderOperationsDataTask
 * @author zhuxiaofeng
 * @date 2022/8/6 14:33
 */
@Component
@EnableScheduling
public class OrderConvertTask {
    private static final Logger logger = LoggerFactory.getLogger(OrderConvertTask.class);

    @Autowired
    private OrderRoutingService service;

    @Autowired
    private OrderRouting2Service service2;

    @Autowired
    private OrderRouting3Service service3;

    @Autowired
    private OrderRouting4Service service4;

    @Autowired
    private OrderRouting5Service service5;

    @Autowired
    private OrderRouting6Service service6;

    @Autowired
    private OrderRouting7Service service7;

    @Autowired
    private OrderRouting8Service service8;

    @Autowired
    private OrderRoutingRefundService refundService;
//
//    @Async
//    @Scheduled(cron = "0 0 21 * * ?")
//    public Result execute1() {
//        Result result = new Result();
//        try {
//            logger.info("OrderConvertTask1[start]!");
//            service.orderConvert();
//            logger.info("OrderConvertTask1[end]!");
//            result.setStatus(true);
//        } catch (Throwable e) {
//            logger.error("OrderConvertTask[execute] failed!, cause by:{}", e);
//            result.setException(ExceptionConstants.SYSTEM_ERROR);
//        }
//        return result;
//    }
//
//    @Async
//    @Scheduled(cron = "0 5 21 * * ?")
//    public Result execute2() {
//        Result result = new Result();
//        try {
//            logger.info("OrderConvertTask2[start]!");
//            service2.orderConvert();
//            logger.info("OrderConvertTask2[end]!");
//            result.setStatus(true);
//        } catch (Throwable e) {
//            logger.error("OrderConvertTask[execute] failed!, cause by:{}", e);
//            result.setException(ExceptionConstants.SYSTEM_ERROR);
//        }
//        return result;
//    }
//
//    @Async
//    @Scheduled(cron = "0 7 21 * * ?")
//    public Result execute3() {
//        Result result = new Result();
//        try {
//            logger.info("OrderConvertTask3[start]!");
//            service3.orderConvert();
//
//            logger.info("OrderConvertTask3[end]!");
//            result.setStatus(true);
//        } catch (Throwable e) {
//            logger.error("OrderConvertTask[execute] failed!, cause by:{}", e);
//            result.setException(ExceptionConstants.SYSTEM_ERROR);
//        }
//        return result;
//    }
//
//    @Async
//    @Scheduled(cron = "0 9 21 * * ?")
//    public Result execute4() {
//        Result result = new Result();
//        try {
//            logger.info("OrderConvertTask4[start]!");
//            service4.orderConvert();
//            logger.info("OrderConvertTask4[end]!");
//            result.setStatus(true);
//        } catch (Throwable e) {
//            logger.error("OrderConvertTask[execute] failed!, cause by:{}", e);
//            result.setException(ExceptionConstants.SYSTEM_ERROR);
//        }
//        return result;
//    }
//
//    @Async
//    @Scheduled(cron = "0 35 21 * * ?")
//    public Result execute5() {
//        Result result = new Result();
//        try {
//            logger.info("OrderConvertTask5[start]!");
//            service5.orderConvert();
//            logger.info("OrderConvertTask5[end]!");
//            result.setStatus(true);
//        } catch (Throwable e) {
//            logger.error("OrderConvertTask[execute] failed!, cause by:{}", e);
//            result.setException(ExceptionConstants.SYSTEM_ERROR);
//        }
//        return result;
//    }
//
//    @Async
//    @Scheduled(cron = "0 40 21 * * ?")
//    public Result execute6() {
//        Result result = new Result();
//        try {
//            logger.info("OrderConvertTask6[start]!");
//            service6.orderConvert();
//            logger.info("OrderConvertTask6[end]!");
//            result.setStatus(true);
//        } catch (Throwable e) {
//            logger.error("OrderConvertTask[execute] failed!, cause by:{}", e);
//            result.setException(ExceptionConstants.SYSTEM_ERROR);
//        }
//        return result;
//    }
//
//
//    @Async
//    @Scheduled(cron = "0 45 21 * * ?")
//    public Result execute7() {
//        Result result = new Result();
//        try {
//            logger.info("OrderConvertTask7[start]!");
//            service7.orderConvert();
//            logger.info("OrderConvertTask7[end]!");
//            result.setStatus(true);
//        } catch (Throwable e) {
//            logger.error("OrderConvertTask[execute] failed!, cause by:{}", e);
//            result.setException(ExceptionConstants.SYSTEM_ERROR);
//        }
//        return result;
//    }
//
//
//    @Async
//    @Scheduled(cron = "0 55 21 * * ?")
//    public Result execute8() {
//        Result result = new Result();
//        try {
//            logger.info("OrderConvertTask8[start]!");
//            service8.orderConvert();
//            logger.info("OrderConvertTask8[end]!");
//            result.setStatus(true);
//        } catch (Throwable e) {
//            logger.error("OrderConvertTask[execute] failed!, cause by:{}", e);
//            result.setException(ExceptionConstants.SYSTEM_ERROR);
//        }
//        return result;
//    }
//
//
//    @Async
//    @Scheduled(cron = "0 0 22 * * ?")
//    public Result executeRefund() {
//        Result result = new Result();
//        try {
//            logger.info("executeRefund[start]!");
//            refundService.refundConvertNew();
//            refundService.commentConvert();
//            refundService.itemCommentConvert();
//            logger.info("executeRefund[end]!");
//            result.setStatus(true);
//        } catch (Throwable e) {
//            logger.error("OrderConvertTask[execute] failed!, cause by:{}", e);
//            result.setException(ExceptionConstants.SYSTEM_ERROR);
//        }
//        return result;
//    }



    @Autowired
    private TempOrderRoutingServiceImpl tp1;

    @Autowired
    private TempOrderRouting2ServiceImpl tp2;

    @Autowired
    private TempOrderRouting3ServiceImpl tp3;

    @Autowired
    private TempOrderRouting4ServiceImpl tp4;

    @Autowired
    private TempOrderRouting5ServiceImpl tp5;

    @Autowired
    private TempOrderRouting6ServiceImpl tp6;

    @Autowired
    private TempOrderRouting7ServiceImpl tp7;

    @Autowired
    private TempOrderRouting8ServiceImpl tp8;


    @Async
    @Scheduled(cron = "0 40 22 * * ?")
    public Result executeT1() {
        Result result = new Result();
        try {
            logger.info("OrderConvertTask8[start]!");
            tp1.orderConvert();
            logger.info("OrderConvertTask8[end]!");
            result.setStatus(true);
        } catch (Throwable e) {
            logger.error("OrderConvertTask[execute] failed!, cause by:{}", e);
            result.setException(ExceptionConstants.SYSTEM_ERROR);
        }
        return result;
    }

    @Async
    @Scheduled(cron = "0 40 22 * * ?")
    public Result executeT2() {
        Result result = new Result();
        try {
            logger.info("OrderConvertTask8[start]!");
            tp2.orderConvert();
            logger.info("OrderConvertTask8[end]!");
            result.setStatus(true);
        } catch (Throwable e) {
            logger.error("OrderConvertTask[execute] failed!, cause by:{}", e);
            result.setException(ExceptionConstants.SYSTEM_ERROR);
        }
        return result;
    }

    @Async
    @Scheduled(cron = "0 40 22 * * ?")
    public Result executeT3() {
        Result result = new Result();
        try {
            logger.info("OrderConvertTask8[start]!");
            tp3.orderConvert();
            logger.info("OrderConvertTask8[end]!");
            result.setStatus(true);
        } catch (Throwable e) {
            logger.error("OrderConvertTask[execute] failed!, cause by:{}", e);
            result.setException(ExceptionConstants.SYSTEM_ERROR);
        }
        return result;
    }
    @Async
    @Scheduled(cron = "0 40 22 * * ?")
    public Result executeT4() {
        Result result = new Result();
        try {
            logger.info("OrderConvertTask8[start]!");
            tp4.orderConvert();
            logger.info("OrderConvertTask8[end]!");
            result.setStatus(true);
        } catch (Throwable e) {
            logger.error("OrderConvertTask[execute] failed!, cause by:{}", e);
            result.setException(ExceptionConstants.SYSTEM_ERROR);
        }
        return result;
    }
    @Async
    @Scheduled(cron = "0 40 22 * * ?")
    public Result executeT5() {
        Result result = new Result();
        try {
            logger.info("OrderConvertTask8[start]!");
            tp5.orderConvert();
            logger.info("OrderConvertTask8[end]!");
            result.setStatus(true);
        } catch (Throwable e) {
            logger.error("OrderConvertTask[execute] failed!, cause by:{}", e);
            result.setException(ExceptionConstants.SYSTEM_ERROR);
        }
        return result;
    }
    @Async
    @Scheduled(cron = "0 40 22 * * ?")
    public Result executeT6() {
        Result result = new Result();
        try {
            logger.info("OrderConvertTask8[start]!");
            tp6.orderConvert();
            logger.info("OrderConvertTask8[end]!");
            result.setStatus(true);
        } catch (Throwable e) {
            logger.error("OrderConvertTask[execute] failed!, cause by:{}", e);
            result.setException(ExceptionConstants.SYSTEM_ERROR);
        }
        return result;
    }
    @Async
    @Scheduled(cron = "0 40 22 * * ?")
    public Result executeT7() {
        Result result = new Result();
        try {
            logger.info("OrderConvertTask8[start]!");
            tp7.orderConvert();
            logger.info("OrderConvertTask8[end]!");
            result.setStatus(true);
        } catch (Throwable e) {
            logger.error("OrderConvertTask[execute] failed!, cause by:{}", e);
            result.setException(ExceptionConstants.SYSTEM_ERROR);
        }
        return result;
    }
    @Async
    @Scheduled(cron = "0 40 22 * * ?")
    public Result executeT8() {
        Result result = new Result();
        try {
            logger.info("OrderConvertTask8[start]!");
            tp8.orderConvert();
            logger.info("OrderConvertTask8[end]!");
            result.setStatus(true);
        } catch (Throwable e) {
            logger.error("OrderConvertTask[execute] failed!, cause by:{}", e);
            result.setException(ExceptionConstants.SYSTEM_ERROR);
        }
        return result;
    }
}

