package com.ruoyi.schedule; import com.ruoyi.business.domain.Business; import com.ruoyi.business.service.IBusinessService; import com.ruoyi.businessDayBill.service.IBusinessDayBillService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Lazy; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.util.Date; import java.util.List; @Component @Configuration @EnableScheduling @Lazy(false) @Slf4j @RequiredArgsConstructor public class BusinessSchedule { private final IBusinessService businessService; private final IBusinessDayBillService businessDayBillService; /** * 每晚0点过1分开始执行一次过期 */ @Scheduled(cron = "${task1h}") public void autoExpires() { List list = businessService.needAutoExpires(); list.forEach(v -> { try { log.info(String.format("商家:%s,开始执行过期", v.getBusinessName())); businessService.autoExpires(v); log.info(String.format("商家:%s,结束执行过期", v.getBusinessName())); } catch (Exception ex) { log.info(String.format("商家:%s,执行过期失败", v.getBusinessName())); } }); } /** * 每晚0点过5分开始执行一次结算 */ @Scheduled(cron = "${task0h10}") public void settlementDayBill() { businessDayBillService.settlementDayBill(new Date()); } }