CancelNotPay.java 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package com.yihu.jw.util;
  2. import com.yihu.jw.service.channel.TimeoutOverDueService;
  3. import org.apache.commons.lang3.StringUtils;
  4. import org.slf4j.Logger;
  5. import org.slf4j.LoggerFactory;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.context.annotation.Lazy;
  8. import org.springframework.scheduling.Trigger;
  9. import org.springframework.scheduling.TriggerContext;
  10. import org.springframework.scheduling.annotation.EnableScheduling;
  11. import org.springframework.scheduling.annotation.SchedulingConfigurer;
  12. import org.springframework.scheduling.config.ScheduledTaskRegistrar;
  13. import org.springframework.scheduling.support.CronTrigger;
  14. import org.springframework.stereotype.Component;
  15. import java.util.Date;
  16. @Lazy(false)
  17. @Component
  18. @EnableScheduling
  19. public class CancelNotPay implements SchedulingConfigurer {
  20. private static final Logger logger = LoggerFactory.getLogger(CancelNotPay.class);
  21. private static String cron = "0 */1 * * * ?";//"0 0 0 * * ?";0 */5 * * * ?
  22. @Autowired
  23. private TimeoutOverDueService timeoutOverDueService;
  24. public String change(String corIn) {
  25. if (StringUtils.isNotBlank(corIn)) {
  26. cron = corIn;
  27. }
  28. return cron;
  29. }
  30. @Override
  31. public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
  32. taskRegistrar.addTriggerTask(new Runnable() {
  33. @Override
  34. public void run() {
  35. logger.info("START========CancelNotPay========");
  36. try {
  37. timeoutOverDueService.CancelNotPay();
  38. logger.info("END========CancelNotPay========");
  39. } catch (Exception e) {
  40. e.printStackTrace();
  41. logger.error("END===ERROE===CancelNotPay,message:"+e.getMessage());
  42. }
  43. }
  44. }, new Trigger() {
  45. @Override
  46. public Date nextExecutionTime(TriggerContext triggerContext) {
  47. // 任务触发,可修改任务的执行周期
  48. CronTrigger trigger = new CronTrigger(cron);
  49. System.out.println("CancelNotPay,可修改任务的执行周期"+cron);
  50. Date nextExec = trigger.nextExecutionTime(triggerContext);
  51. return nextExec;
  52. }
  53. });
  54. }
  55. }