package com.reptileclient.jlifeapp.schedule;

import cn.hutool.core.date.DateUtil;
import com.reptileclient.jlifeapp.entity.hm.HmBookTradeOrder;
import com.reptileclient.jlifeapp.service.HmBookTradeOrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author fuxubing
 */
@Async
@Component
public class HmBookTradeOrderTask {
    private static final Logger logger = LoggerFactory.getLogger(HmBookTradeOrderTask.class);
    @Resource
    private HmBookTradeOrderService hmBookTradeOrderService;

    /**
     * 每天1点执行一次
     */
    @Scheduled(cron = "0 0 1 * * ?")
    public void runTask() {
        logger.info("开始执行同步盒马技师作业单数据");
        try {
        	HmBookTradeOrder hmBookTradeOrder = hmBookTradeOrderService.selectNewOne();
            int row = hmBookTradeOrderService.addHmBookTradeList();
            logger.info("执行完成总条数：{}", row);
            //数据去重
            hmBookTradeOrderService.deleteDistinctData(null != hmBookTradeOrder ? DateUtil.lastMonth() : null);
        } catch (Exception e) {
            e.printStackTrace();
        }
        
        
        logger.info("开始执行更新盒马技师作业单数据");
        try {
        	HmBookTradeOrder hmBookTradeOrder2 = hmBookTradeOrderService.selectNewOne();
            int row = hmBookTradeOrderService.updateHmBookTradeList();
            logger.info("执行完成总条数：{}", row);
            //数据去重
            hmBookTradeOrderService.deleteDistinctData(null != hmBookTradeOrder2 ? DateUtil.lastMonth() : null);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

//    /**
//     * 每天8点执行一次
//     */
//    @Scheduled(cron = "0 0 8 * * ?")
//    public void runUpdateTask() {
//        logger.info("开始执行更新盒马技师作业单数据");
//        HmBookTradeOrder hmBookTradeOrder = hmBookTradeOrderService.selectNewOne();
//        try {
//            int row = hmBookTradeOrderService.updateHmBookTradeList();
//            logger.info("执行完成总条数：{}", row);
//            //数据去重
//            hmBookTradeOrderService.deleteDistinctData(null != hmBookTradeOrder ? DateUtil.lastMonth() : null);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
}
