OrderReportTask.java
1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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());
}
}