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 3 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 8 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 15 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 20 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 13 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 17 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 23 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 33 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 23 * * ?")
//    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;
//    }
}

