BillsScheduler.java 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package com.sqx.scheduler.reconciliation;
  2. import com.sqx.modules.coupon.service.TbCouponUserService;
  3. import com.sqx.modules.reconciliation.service.PlatformBillService;
  4. import com.sqx.scheduler.config.SchedulerLock;
  5. import lombok.RequiredArgsConstructor;
  6. import lombok.extern.slf4j.Slf4j;
  7. import org.redisson.api.RLock;
  8. import org.redisson.api.RedissonClient;
  9. import org.springframework.scheduling.annotation.Async;
  10. import org.springframework.scheduling.annotation.Scheduled;
  11. import org.springframework.stereotype.Component;
  12. /**
  13. * 对账定时任务
  14. *
  15. * @author : codingliang
  16. * @date : 2024-09-09 12:22
  17. */
  18. @Slf4j
  19. @Component
  20. @RequiredArgsConstructor
  21. public class BillsScheduler {
  22. private final PlatformBillService platformBillService;
  23. /**
  24. * 将所有超过失效时间的优惠券改为失效状态
  25. * 每填0点2分30秒执行一次
  26. */
  27. @Async
  28. @Scheduled(cron = "30 2 0 * * ?", zone = "Asia/Shanghai")
  29. public void insertPlatformBill(){
  30. int errorCount = 0 ;
  31. log.info("开始统计对账数据");
  32. while (errorCount<3){
  33. try {
  34. int count =platformBillService.insertPlatformBill();
  35. if(count!=0){
  36. break;
  37. }
  38. } catch (Exception e) {
  39. log.error("统计对账数据异常:{}", e.getMessage());
  40. errorCount++;
  41. try {
  42. Thread.sleep(10000);
  43. } catch (InterruptedException ex) {
  44. throw new RuntimeException(ex);
  45. }
  46. }
  47. }
  48. log.info("统计对账数据结束");
  49. }
  50. }