Pu Zhibing
16 小时以前 98b09eae533537dc9a5277aa6374bd7d35cfe5c4
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/util/task/TaskUtil.java
@@ -11,6 +11,8 @@
import com.ruoyi.order.service.TChargingOrderService;
import org.apache.logging.log4j.core.util.UuidUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.context.WebServerInitializedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@@ -30,7 +32,7 @@
 * @date 2023/7/11 8:39
 */
@Component
public class TaskUtil {
public class TaskUtil implements ApplicationListener<WebServerInitializedEvent> {
    @Resource
    private TChargingBillService chargingBillService;
@@ -39,10 +41,13 @@
    @Resource
    private TChargingOrderService chargingOrderService;
    private Integer port = null;
    @Scheduled(cron = "0 0 0 2 * ?")
    public void taskMonth() {
        if(null != port && port == 5400){
        try {
            // 获取上个月的开始和结束日期
            LocalDate firstDayOfLastMonth = LocalDate.now().minusMonths(1).
@@ -129,10 +134,12 @@
            e.printStackTrace();
        }
    }
    }
    // 每个月最后一天23点执行的定时任务
    @Scheduled(cron = "0 0 23 * * ?")
    public void taskLastDay() {
        if(null != port && port == 5400){
        try {
            // 获取上个月的开始和结束日期
            LocalDate firstDayOfLastMonth = LocalDate.now().minusMonths(1).
@@ -157,5 +164,11 @@
            e.printStackTrace();
        }
    }
    }
    @Override
    public void onApplicationEvent(WebServerInitializedEvent event) {
        port = event.getWebServer().getPort();
        System.out.println("端口号:" + port);
    }
}