OrderReportTask.java 1.46 KB
package com.glsx.task.schedule;

import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import com.glsx.common.feign.client.OrderClient;
import com.glsx.common.pojo.OrderReportReq;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * <p>Description:
 * <p>Project: car-service
 *
 * @author wbh
 * @date 2021-07-14
 */
@Component
@EnableScheduling
@Slf4j
public class OrderReportTask {
    @Autowired
    private OrderClient orderClient;

    /**
     * 每个月 1 号的凌晨三点开始生成订单报表信息
     */
//    @Scheduled(cron = "0 0 0/1 * * ?")
    @Scheduled(cron = "0 0 3 1 * ?")
    private void executeTask() {
        log.info("$$$$ OrderReportTask executeTask...");
        Date now = new Date();
        Date startOfLastMonth = DateUtil.beginOfMonth(now).offset(DateField.MONTH, -1);
        Date endOfLastMonth = DateUtil.endOfMonth(startOfLastMonth);
        OrderReportReq req = new OrderReportReq();
        req.setCreateTimeStart(startOfLastMonth);
        req.setCreateTimeEnd(endOfLastMonth);
        JSONObject respObj = orderClient.generateOrderReport(req);
        log.info("$$$$ OrderReportTask executeTask: {}", respObj.toJSONString());
    }
}