GeneralJob.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package com.txz.mall.task;
  2. import cn.hutool.core.collection.CollUtil;
  3. import com.txz.mall.service.StoreFlashActivityService;
  4. import com.txz.mall.service.StoreOrderService;
  5. import com.xxl.job.core.biz.model.ReturnT;
  6. import com.xxl.job.core.handler.annotation.XxlJob;
  7. import lombok.extern.slf4j.Slf4j;
  8. import org.slf4j.Logger;
  9. import org.slf4j.LoggerFactory;
  10. import org.springframework.stereotype.Component;
  11. import tk.mybatis.mapper.entity.Condition;
  12. import javax.annotation.Resource;
  13. import java.util.List;
  14. /**
  15. * 常规job
  16. *
  17. * 开发步骤:
  18. * 1、在Spring Bean实例中,开发Job方法,方式格式要求为 "public ReturnT<String> execute(String param)"
  19. * 2、为Job方法添加注解 "@XxlJob(value="自定义jobhandler名称", init = "JobHandler初始化方法", destroy = "JobHandler销毁方法")",注解value值对应的是调度中心新建任务的JobHandler属性的值。
  20. * 3、执行日志:需要通过 "XxlJobLogger.log" 打印执行日志;
  21. *
  22. * @author xuxueli 2019-12-11 21:52:51
  23. */
  24. @Component
  25. @Slf4j
  26. public class GeneralJob {
  27. // private static Logger logger = LoggerFactory.getLogger(GeneralJob.class);
  28. @Resource
  29. private StoreOrderService storeOrderService;
  30. @Resource
  31. private StoreFlashActivityService storeFlashActivityService;
  32. /**
  33. * 1、简单任务示例(Bean模式)
  34. */
  35. @XxlJob("newScheduledTaskStorePinkSummaryClose")
  36. public ReturnT<String> newsScheduledTaskStorePinkSummaryClose(String param) throws Exception {
  37. try {
  38. log.info("newScheduledTaskStorePinkSummaryClose start");
  39. storeOrderService.scheduledTaskStorePinkSummaryClose();
  40. log.info("newsScheduledTaskStorePinkSummaryClose end");
  41. } catch (Exception e) {
  42. log.error("newScheduledTaskStorePinkSummaryCloseError:e{}", e);
  43. return ReturnT.FAIL;
  44. }
  45. return ReturnT.SUCCESS;
  46. }
  47. @XxlJob("newScheduledTaskBatchSigning")
  48. public ReturnT<String> newScheduledTaskBatchSigning(String param) throws Exception {
  49. try {
  50. log.info("newScheduledTaskBatchSigning start");
  51. storeOrderService.batchSigning();
  52. log.info("newScheduledTaskBatchSigning end");
  53. } catch (Exception e) {
  54. log.error("newScheduledTaskBatchSigningError:e{}", e);
  55. return ReturnT.FAIL;
  56. }
  57. return ReturnT.SUCCESS;
  58. }
  59. @XxlJob("newOrderTimeoutAutomaticCancel")
  60. public ReturnT<String> newOrderTimeoutAutomaticCancel(String param) throws Exception {
  61. try {
  62. log.info("newOrderTimeoutAutomaticCancel start");
  63. storeOrderService.orderTimeoutAutomaticCancel();
  64. log.info("newOrderTimeoutAutomaticCancel end");
  65. } catch (Exception e) {
  66. log.error("newOrderTimeoutAutomaticCancelError:e{}", e);
  67. return ReturnT.FAIL;
  68. }
  69. return ReturnT.SUCCESS;
  70. }
  71. @XxlJob("newActivityStatusJudgmentTimedTask")
  72. public ReturnT<String> newActivityStatusJudgmentTimedTask(String param) throws Exception {
  73. try {
  74. log.info("newActivityStatusJudgmentTimedTask start");
  75. storeFlashActivityService.activityStatusJudgmentTimedTask();
  76. log.info("newActivityStatusJudgmentTimedTask end");
  77. } catch (Exception e) {
  78. log.error("newActivityStatusJudgmentTimedTaskError:e{}", e);
  79. return ReturnT.FAIL;
  80. }
  81. return ReturnT.SUCCESS;
  82. }
  83. }