XxlJobInfo.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. package com.cyksj.xxljob;
  2. import cn.hutool.core.net.URLEncoder;
  3. import com.cyksj.common.exception.BusinessRuntimeException;
  4. import lombok.Data;
  5. import lombok.Getter;
  6. import org.apache.commons.lang3.StringUtils;
  7. import java.nio.charset.Charset;
  8. /**
  9. * @ClassName XxlJobInfo
  10. * @Description TODO
  11. * @Author Huang yuanzhi
  12. * @Date 2023/6/12 16:11
  13. * @Version 1.0.0
  14. **/
  15. @Data
  16. public class XxlJobInfo {
  17. public XxlJobInfo() {
  18. }
  19. public XxlJobInfo(int id, String jobDesc, String jobCron, int jobGroup, String author, String alarmEmail, String executorHandler, String executorParam) {
  20. this.id = id;
  21. this.jobGroup = jobGroup;
  22. this.jobDesc = jobDesc;
  23. this.jobCron = jobCron;
  24. this.author = author;
  25. this.alarmEmail = alarmEmail;
  26. this.executorHandler = executorHandler;
  27. this.executorParam = executorParam;
  28. this.triggerStatus = 1;
  29. }
  30. private int id;
  31. /**
  32. * 执行器主键ID
  33. */
  34. private int jobGroup = 5;
  35. /**
  36. * 备注
  37. */
  38. private String jobDesc;
  39. /**
  40. * 表达式
  41. */
  42. private String jobCron;
  43. private String glueType = "BEAN";
  44. /**
  45. * 负责人
  46. */
  47. private String author;
  48. /**
  49. * 报警邮件
  50. */
  51. private String alarmEmail;
  52. /**
  53. * 执行器路由策略
  54. */
  55. private String executorRouteStrategy = "FIRST";
  56. /**
  57. * 执行器,任务Handler名称
  58. */
  59. private String executorHandler;
  60. /**
  61. * 执行器,任务参数
  62. */
  63. private String executorParam;
  64. /**
  65. * 阻塞处理策略
  66. */
  67. private String executorBlockStrategy = "SERIAL_EXECUTION";
  68. /**
  69. * 任务执行超时时间,单位秒
  70. */
  71. private int executorTimeout;
  72. private String glueRemark = "GLUE代码初始化";
  73. /**
  74. * 失败重试次数
  75. */
  76. private int executorFailRetryCount;
  77. /**
  78. * 子任务ID,多个逗号分隔
  79. */
  80. private String childJobId;
  81. /**
  82. * 调度状态:0-停止,1-运行
  83. */
  84. private int triggerStatus;
  85. /**
  86. * 上次调度时间
  87. */
  88. private long triggerLastTime;
  89. /**
  90. * 下次调度时间
  91. */
  92. private long triggerNextTime;
  93. //银河执行器 id
  94. private static int jobGroups = 10;
  95. /**
  96. * 创建执行器
  97. *
  98. * @param author
  99. * @param jobDesc 任务秒速
  100. * @param corn 表达式
  101. * @param executorHandler executorHandler
  102. * @param executorParam 参数
  103. * @return
  104. */
  105. public static XxlJobInfo getInstance(AUTHOR author, String jobDesc, String corn, int jopGroup, String executorHandler, String executorParam) {
  106. return new XxlJobInfo(0, jobDesc, URLEncoder.createQuery().encode(corn, Charset.defaultCharset()), jopGroup, author.getName(), author.email, executorHandler, executorParam);
  107. }
  108. public static XxlJobInfo getUpdateInstance(int id, AUTHOR author, String jobDesc, String corn, int jopGroup, String executorHandler, String executorParam) {
  109. return new XxlJobInfo(id, jobDesc, URLEncoder.createQuery().encode(corn, Charset.defaultCharset()), jopGroup, author.getName(), author.email, executorHandler, executorParam);
  110. }
  111. public static XxlJobInfo getTaskInstance(int id, String corn, String executorParam) {
  112. AUTHOR author = AUTHOR.Zou;
  113. if (StringUtils.isBlank(corn)) {
  114. throw BusinessRuntimeException.getInstance("任务运行周期不能为空");
  115. }
  116. return new XxlJobInfo(id, "周期群发任务", URLEncoder.createQuery().encode(corn, Charset.defaultCharset()), jobGroups, author.getName(), author.email, "yh_corp_msg_bulk_task_cycle_job", executorParam);
  117. }
  118. @Getter
  119. public enum AUTHOR {
  120. Zou("zou", "1091496505@qq.com");
  121. AUTHOR(String name, String email) {
  122. this.name = name;
  123. this.email = email;
  124. }
  125. private String name;
  126. private String email;
  127. }
  128. @Override
  129. public String toString() {
  130. return
  131. "?id=" + id +
  132. "&jobDesc=" + jobDesc +
  133. "&jobCron=" + jobCron +
  134. "&jobGroup=" + jobGroup +
  135. "&glueType=" + glueType +
  136. "&author=" + author +
  137. "&alarmEmail=" + alarmEmail +
  138. "&executorRouteStrategy=" + executorRouteStrategy +
  139. "&executorHandler=" + executorHandler +
  140. "&executorParam=" + executorParam +
  141. "&executorBlockStrategy=" + executorBlockStrategy +
  142. "&executorTimeout=" + executorTimeout +
  143. "&glueRemark=" + glueRemark +
  144. "&executorFailRetryCount=" + executorFailRetryCount +
  145. "&triggerStatus=" + triggerStatus +
  146. "&triggerLastTime=" + triggerLastTime +
  147. "&triggerNextTime=" + triggerNextTime;
  148. }
  149. }