package com.reptileclient.jlifeapp.schedule;

import cn.hutool.core.date.DateUtil;
import com.reptileclient.jlifeapp.service.HmPaymentOrderService;
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 HmPaymentOrderTask {
    private static final Logger logger = LoggerFactory.getLogger(HmPaymentOrderTask.class);
    @Resource
    private HmPaymentOrderService hmPaymentOrderService;

    /**
     * 每天1点执行一次
     */
    @Scheduled(cron = "0 0/1 * * * ?")
    //@Scheduled(cron = "0 0 1 * * ?")
    public void runTask() {
        logger.info("开始执行同步盒马服务付款单数据");
        try {
            int row = hmPaymentOrderService.addPaymentOrderList();
            logger.info("执行完成总条数：{}", row);
            //数据去重
            hmPaymentOrderService.deleteDistinctData(DateUtil.lastMonth());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
