BusinessSchedule.java 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package com.ruoyi.schedule;
  2. import com.ruoyi.business.domain.Business;
  3. import com.ruoyi.business.service.IBusinessService;
  4. import com.ruoyi.businessDayBill.service.IBusinessDayBillService;
  5. import lombok.RequiredArgsConstructor;
  6. import lombok.extern.slf4j.Slf4j;
  7. import org.springframework.context.annotation.Configuration;
  8. import org.springframework.context.annotation.Lazy;
  9. import org.springframework.scheduling.annotation.EnableScheduling;
  10. import org.springframework.scheduling.annotation.Scheduled;
  11. import org.springframework.stereotype.Component;
  12. import java.util.Date;
  13. import java.util.List;
  14. @Component
  15. @Configuration
  16. @EnableScheduling
  17. @Lazy(false)
  18. @Slf4j
  19. @RequiredArgsConstructor
  20. public class BusinessSchedule {
  21. private final IBusinessService businessService;
  22. private final IBusinessDayBillService businessDayBillService;
  23. /**
  24. * 每晚0点过1分开始执行一次过期
  25. */
  26. @Scheduled(cron = "${task1h}")
  27. public void autoExpires() {
  28. List<Business> list = businessService.needAutoExpires();
  29. list.forEach(v -> {
  30. try {
  31. log.info(String.format("商家:%s,开始执行过期", v.getBusinessName()));
  32. businessService.autoExpires(v);
  33. log.info(String.format("商家:%s,结束执行过期", v.getBusinessName()));
  34. } catch (Exception ex) {
  35. log.info(String.format("商家:%s,执行过期失败", v.getBusinessName()));
  36. }
  37. });
  38. }
  39. /**
  40. * 每晚0点过5分开始执行一次结算
  41. */
  42. @Scheduled(cron = "${task0h10}")
  43. public void settlementDayBill() {
  44. businessDayBillService.settlementDayBill(new Date());
  45. }
  46. }