From 8b0c506f7ed8adf6687683a33d1a80b066853d14 Mon Sep 17 00:00:00 2001
From: sxu <602087911@qq.com>
Date: Wed, 23 Jul 2025 10:21:00 +0800
Subject: [PATCH] add job
---
bonus-common-biz/job/pom.xml | 21 ++
.../net/xnzn/framework/job/XxlJobConfig.java | 40 ++
.../xnzn/framework/job/XxlJobProperties.java | 353 ++++++++++++++++++
.../net/xnzn/framework/job/api/XxlJobApi.java | 72 ++++
.../xnzn/framework/job/api/XxlJobInfo.java | 271 ++++++++++++++
.../framework/job/api/XxlJobRemoteHelper.java | 63 ++++
.../xnzn/framework/job/api/XxlJobReturn.java | 66 ++++
.../xnzn/framework/job/api/XxlJobUser.java | 82 ++++
bonus-common-biz/pom.xml | 1 +
9 files changed, 969 insertions(+)
create mode 100644 bonus-common-biz/job/pom.xml
create mode 100644 bonus-common-biz/job/src/main/java/net/xnzn/framework/job/XxlJobConfig.java
create mode 100644 bonus-common-biz/job/src/main/java/net/xnzn/framework/job/XxlJobProperties.java
create mode 100644 bonus-common-biz/job/src/main/java/net/xnzn/framework/job/api/XxlJobApi.java
create mode 100644 bonus-common-biz/job/src/main/java/net/xnzn/framework/job/api/XxlJobInfo.java
create mode 100644 bonus-common-biz/job/src/main/java/net/xnzn/framework/job/api/XxlJobRemoteHelper.java
create mode 100644 bonus-common-biz/job/src/main/java/net/xnzn/framework/job/api/XxlJobReturn.java
create mode 100644 bonus-common-biz/job/src/main/java/net/xnzn/framework/job/api/XxlJobUser.java
diff --git a/bonus-common-biz/job/pom.xml b/bonus-common-biz/job/pom.xml
new file mode 100644
index 00000000..75557d66
--- /dev/null
+++ b/bonus-common-biz/job/pom.xml
@@ -0,0 +1,21 @@
+
+
+ 4.0.0
+
+ com.bonus
+ bonus-common-biz
+ 24.12.0-SNAPSHOT
+
+
+ org.example
+ job
+
+
+ 21
+ 21
+ UTF-8
+
+
+
\ No newline at end of file
diff --git a/bonus-common-biz/job/src/main/java/net/xnzn/framework/job/XxlJobConfig.java b/bonus-common-biz/job/src/main/java/net/xnzn/framework/job/XxlJobConfig.java
new file mode 100644
index 00000000..4c9a1729
--- /dev/null
+++ b/bonus-common-biz/job/src/main/java/net/xnzn/framework/job/XxlJobConfig.java
@@ -0,0 +1,40 @@
+package net.xnzn.framework.job;
+
+import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
+import net.xnzn.framework.job.api.XxlJobApi;
+import org.springframework.boot.autoconfigure.AutoConfiguration;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.cloud.commons.util.InetUtils;
+import org.springframework.cloud.commons.util.UtilAutoConfiguration;
+import org.springframework.context.annotation.Bean;
+
+@AutoConfiguration(
+ after = {UtilAutoConfiguration.class}
+)
+@EnableConfigurationProperties({XxlJobProperties.class})
+@ConditionalOnProperty(
+ name = {"xxl.job.enabled"},
+ havingValue = "true",
+ matchIfMissing = true
+)
+public class XxlJobConfig {
+ @Bean
+ public XxlJobSpringExecutor xxlJobExecutor(XxlJobProperties xxlJobProperties, InetUtils inetUtils) {
+ XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
+ xxlJobSpringExecutor.setAdminAddresses(xxlJobProperties.getAdmin().getAddresses());
+ xxlJobSpringExecutor.setAppname(xxlJobProperties.getExecutor().getAppName());
+ xxlJobSpringExecutor.setAddress(xxlJobProperties.getExecutor().getAddress());
+ xxlJobSpringExecutor.setIp(inetUtils.findFirstNonLoopbackHostInfo().getIpAddress());
+ xxlJobSpringExecutor.setPort(xxlJobProperties.getExecutor().getPort());
+ xxlJobSpringExecutor.setAccessToken(xxlJobProperties.getAdmin().getAccessToken());
+ xxlJobSpringExecutor.setLogPath(xxlJobProperties.getExecutor().getLogPath());
+ xxlJobSpringExecutor.setLogRetentionDays(xxlJobProperties.getExecutor().getLogRetentionDays());
+ return xxlJobSpringExecutor;
+ }
+
+ @Bean
+ public XxlJobApi xxlJobApi(XxlJobProperties xxlJobProperties) {
+ return new XxlJobApi(xxlJobProperties);
+ }
+}
diff --git a/bonus-common-biz/job/src/main/java/net/xnzn/framework/job/XxlJobProperties.java b/bonus-common-biz/job/src/main/java/net/xnzn/framework/job/XxlJobProperties.java
new file mode 100644
index 00000000..43a2f5e9
--- /dev/null
+++ b/bonus-common-biz/job/src/main/java/net/xnzn/framework/job/XxlJobProperties.java
@@ -0,0 +1,353 @@
+package net.xnzn.framework.job;
+
+import lombok.Generated;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+@ConfigurationProperties(
+ prefix = "xxl.job"
+)
+public class XxlJobProperties {
+ public static final String PREFIX = "xxl.job";
+ private boolean enabled = true;
+ private AdminProperties admin = new AdminProperties();
+ private ExecutorProperties executor = new ExecutorProperties();
+
+ @Generated
+ public boolean isEnabled() {
+ return this.enabled;
+ }
+
+ @Generated
+ public AdminProperties getAdmin() {
+ return this.admin;
+ }
+
+ @Generated
+ public ExecutorProperties getExecutor() {
+ return this.executor;
+ }
+
+ @Generated
+ public void setEnabled(final boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ @Generated
+ public void setAdmin(final AdminProperties admin) {
+ this.admin = admin;
+ }
+
+ @Generated
+ public void setExecutor(final ExecutorProperties executor) {
+ this.executor = executor;
+ }
+
+ @Generated
+ public boolean equals(final Object o) {
+ if (o == this) {
+ return true;
+ } else if (!(o instanceof XxlJobProperties)) {
+ return false;
+ } else {
+ XxlJobProperties other = (XxlJobProperties)o;
+ if (!other.canEqual(this)) {
+ return false;
+ } else if (this.isEnabled() != other.isEnabled()) {
+ return false;
+ } else {
+ Object this$admin = this.getAdmin();
+ Object other$admin = other.getAdmin();
+ if (this$admin == null) {
+ if (other$admin != null) {
+ return false;
+ }
+ } else if (!this$admin.equals(other$admin)) {
+ return false;
+ }
+
+ Object this$executor = this.getExecutor();
+ Object other$executor = other.getExecutor();
+ if (this$executor == null) {
+ if (other$executor != null) {
+ return false;
+ }
+ } else if (!this$executor.equals(other$executor)) {
+ return false;
+ }
+
+ return true;
+ }
+ }
+ }
+
+ @Generated
+ protected boolean canEqual(final Object other) {
+ return other instanceof XxlJobProperties;
+ }
+
+ @Generated
+ public int hashCode() {
+ int PRIME = true;
+ int result = 1;
+ result = result * 59 + (this.isEnabled() ? 79 : 97);
+ Object $admin = this.getAdmin();
+ result = result * 59 + ($admin == null ? 43 : $admin.hashCode());
+ Object $executor = this.getExecutor();
+ result = result * 59 + ($executor == null ? 43 : $executor.hashCode());
+ return result;
+ }
+
+ @Generated
+ public String toString() {
+ boolean var10000 = this.isEnabled();
+ return "XxlJobProperties(enabled=" + var10000 + ", admin=" + String.valueOf(this.getAdmin()) + ", executor=" + String.valueOf(this.getExecutor()) + ")";
+ }
+
+ public static class AdminProperties {
+ private String addresses = "http://127.0.0.1:8080/xxl-job-admin";
+ private String accessToken;
+
+ @Generated
+ public String getAddresses() {
+ return this.addresses;
+ }
+
+ @Generated
+ public String getAccessToken() {
+ return this.accessToken;
+ }
+
+ @Generated
+ public void setAddresses(final String addresses) {
+ this.addresses = addresses;
+ }
+
+ @Generated
+ public void setAccessToken(final String accessToken) {
+ this.accessToken = accessToken;
+ }
+
+ @Generated
+ public boolean equals(final Object o) {
+ if (o == this) {
+ return true;
+ } else if (!(o instanceof AdminProperties)) {
+ return false;
+ } else {
+ AdminProperties other = (AdminProperties)o;
+ if (!other.canEqual(this)) {
+ return false;
+ } else {
+ Object this$addresses = this.getAddresses();
+ Object other$addresses = other.getAddresses();
+ if (this$addresses == null) {
+ if (other$addresses != null) {
+ return false;
+ }
+ } else if (!this$addresses.equals(other$addresses)) {
+ return false;
+ }
+
+ Object this$accessToken = this.getAccessToken();
+ Object other$accessToken = other.getAccessToken();
+ if (this$accessToken == null) {
+ if (other$accessToken != null) {
+ return false;
+ }
+ } else if (!this$accessToken.equals(other$accessToken)) {
+ return false;
+ }
+
+ return true;
+ }
+ }
+ }
+
+ @Generated
+ protected boolean canEqual(final Object other) {
+ return other instanceof AdminProperties;
+ }
+
+ @Generated
+ public int hashCode() {
+ int PRIME = true;
+ int result = 1;
+ Object $addresses = this.getAddresses();
+ result = result * 59 + ($addresses == null ? 43 : $addresses.hashCode());
+ Object $accessToken = this.getAccessToken();
+ result = result * 59 + ($accessToken == null ? 43 : $accessToken.hashCode());
+ return result;
+ }
+
+ @Generated
+ public String toString() {
+ String var10000 = this.getAddresses();
+ return "XxlJobProperties.AdminProperties(addresses=" + var10000 + ", accessToken=" + this.getAccessToken() + ")";
+ }
+ }
+
+ public static class ExecutorProperties {
+ private String appName = "xxl-job-executor";
+ private String address;
+ private String ip;
+ private int port = 0;
+ private String logPath = "/var/log/xxl-job";
+ private int logRetentionDays = 7;
+
+ @Generated
+ public String getAppName() {
+ return this.appName;
+ }
+
+ @Generated
+ public String getAddress() {
+ return this.address;
+ }
+
+ @Generated
+ public String getIp() {
+ return this.ip;
+ }
+
+ @Generated
+ public int getPort() {
+ return this.port;
+ }
+
+ @Generated
+ public String getLogPath() {
+ return this.logPath;
+ }
+
+ @Generated
+ public int getLogRetentionDays() {
+ return this.logRetentionDays;
+ }
+
+ @Generated
+ public void setAppName(final String appName) {
+ this.appName = appName;
+ }
+
+ @Generated
+ public void setAddress(final String address) {
+ this.address = address;
+ }
+
+ @Generated
+ public void setIp(final String ip) {
+ this.ip = ip;
+ }
+
+ @Generated
+ public void setPort(final int port) {
+ this.port = port;
+ }
+
+ @Generated
+ public void setLogPath(final String logPath) {
+ this.logPath = logPath;
+ }
+
+ @Generated
+ public void setLogRetentionDays(final int logRetentionDays) {
+ this.logRetentionDays = logRetentionDays;
+ }
+
+ @Generated
+ public boolean equals(final Object o) {
+ if (o == this) {
+ return true;
+ } else if (!(o instanceof ExecutorProperties)) {
+ return false;
+ } else {
+ ExecutorProperties other = (ExecutorProperties)o;
+ if (!other.canEqual(this)) {
+ return false;
+ } else if (this.getPort() != other.getPort()) {
+ return false;
+ } else if (this.getLogRetentionDays() != other.getLogRetentionDays()) {
+ return false;
+ } else {
+ label64: {
+ Object this$appName = this.getAppName();
+ Object other$appName = other.getAppName();
+ if (this$appName == null) {
+ if (other$appName == null) {
+ break label64;
+ }
+ } else if (this$appName.equals(other$appName)) {
+ break label64;
+ }
+
+ return false;
+ }
+
+ label57: {
+ Object this$address = this.getAddress();
+ Object other$address = other.getAddress();
+ if (this$address == null) {
+ if (other$address == null) {
+ break label57;
+ }
+ } else if (this$address.equals(other$address)) {
+ break label57;
+ }
+
+ return false;
+ }
+
+ Object this$ip = this.getIp();
+ Object other$ip = other.getIp();
+ if (this$ip == null) {
+ if (other$ip != null) {
+ return false;
+ }
+ } else if (!this$ip.equals(other$ip)) {
+ return false;
+ }
+
+ Object this$logPath = this.getLogPath();
+ Object other$logPath = other.getLogPath();
+ if (this$logPath == null) {
+ if (other$logPath != null) {
+ return false;
+ }
+ } else if (!this$logPath.equals(other$logPath)) {
+ return false;
+ }
+
+ return true;
+ }
+ }
+ }
+
+ @Generated
+ protected boolean canEqual(final Object other) {
+ return other instanceof ExecutorProperties;
+ }
+
+ @Generated
+ public int hashCode() {
+ int PRIME = true;
+ int result = 1;
+ result = result * 59 + this.getPort();
+ result = result * 59 + this.getLogRetentionDays();
+ Object $appName = this.getAppName();
+ result = result * 59 + ($appName == null ? 43 : $appName.hashCode());
+ Object $address = this.getAddress();
+ result = result * 59 + ($address == null ? 43 : $address.hashCode());
+ Object $ip = this.getIp();
+ result = result * 59 + ($ip == null ? 43 : $ip.hashCode());
+ Object $logPath = this.getLogPath();
+ result = result * 59 + ($logPath == null ? 43 : $logPath.hashCode());
+ return result;
+ }
+
+ @Generated
+ public String toString() {
+ String var10000 = this.getAppName();
+ return "XxlJobProperties.ExecutorProperties(appName=" + var10000 + ", address=" + this.getAddress() + ", ip=" + this.getIp() + ", port=" + this.getPort() + ", logPath=" + this.getLogPath() + ", logRetentionDays=" + this.getLogRetentionDays() + ")";
+ }
+ }
+}
diff --git a/bonus-common-biz/job/src/main/java/net/xnzn/framework/job/api/XxlJobApi.java b/bonus-common-biz/job/src/main/java/net/xnzn/framework/job/api/XxlJobApi.java
new file mode 100644
index 00000000..125de546
--- /dev/null
+++ b/bonus-common-biz/job/src/main/java/net/xnzn/framework/job/api/XxlJobApi.java
@@ -0,0 +1,72 @@
+package net.xnzn.framework.job.api;
+
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.lang.TypeReference;
+import com.google.common.collect.Maps;
+import java.util.List;
+import java.util.Map;
+import net.xnzn.framework.job.XxlJobProperties;
+
+public class XxlJobApi {
+ private final XxlJobRemoteHelper remoteHelper;
+
+ public XxlJobApi(XxlJobProperties properties) {
+ this.remoteHelper = new XxlJobRemoteHelper(properties);
+ }
+
+ public Map pageList(XxlJobInfo xxlJobInfo) {
+ Map params = BeanUtil.beanToMap(xxlJobInfo, false, false);
+ return (Map)this.remoteHelper.sendPost("/jobinfo/pageList", params, new TypeReference