orders = Arrays.asList(order1, order2, order3);
+ logTestService.testSPELList(orders);
+ }
+
+
+}
diff --git a/spring-boot/spring-boot-drools/pom.xml b/spring-boot/spring-boot-drools/pom.xml
new file mode 100644
index 0000000..39a98e5
--- /dev/null
+++ b/spring-boot/spring-boot-drools/pom.xml
@@ -0,0 +1,22 @@
+
+
+
+
+ spring-boot
+ com.wyl.example
+ 1.0-SNAPSHOT
+ ../pom.xml
+
+ 4.0.0
+ spring-boot-drools
+ spring-boot-drools
+
+ UTF-8
+ 1.8
+ 1.8
+
+
+
+
+
diff --git a/spring-boot/spring-boot-drools/src/test/java/com/wyl/example/service/Service.java b/spring-boot/spring-boot-drools/src/test/java/com/wyl/example/service/Service.java
new file mode 100644
index 0000000..c38dcf7
--- /dev/null
+++ b/spring-boot/spring-boot-drools/src/test/java/com/wyl/example/service/Service.java
@@ -0,0 +1,5 @@
+package com.wyl.example.service;
+
+public interface Service {
+ void test();
+}
diff --git a/spring-boot/spring-boot-drools/src/test/java/com/wyl/example/service/ServiceTest.java b/spring-boot/spring-boot-drools/src/test/java/com/wyl/example/service/ServiceTest.java
new file mode 100644
index 0000000..ad08bba
--- /dev/null
+++ b/spring-boot/spring-boot-drools/src/test/java/com/wyl/example/service/ServiceTest.java
@@ -0,0 +1,8 @@
+package com.wyl.example.service;
+
+public class ServiceTest implements Service{
+ @Override
+ public void test() {
+
+ }
+}
diff --git a/spring-boot/spring-boot-xxjob/pom.xml b/spring-boot/spring-boot-xxjob/pom.xml
new file mode 100644
index 0000000..ab73768
--- /dev/null
+++ b/spring-boot/spring-boot-xxjob/pom.xml
@@ -0,0 +1,68 @@
+
+
+ 4.0.0
+
+ com.wyl.example
+ spring-boot
+ 1.0-SNAPSHOT
+ ../pom.xml
+
+ com.wyl
+ spring-boot-xxjob
+ 0.0.1-SNAPSHOT
+ spring-boot-xxjob
+ Demo project for Spring Boot
+
+ 1.8
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+ com.xuxueli
+ xxl-job-core
+
+
+ org.projectlombok
+ lombok
+ true
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+
+
+
+
+
+
+ com.squareup.okhttp3
+ okhttp
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+ org.projectlombok
+ lombok
+
+
+
+
+
+
+
+
diff --git a/spring-boot/spring-boot-xxjob/src/main/java/com/wyl/springbootxxjob/EnableXxljobRest.java b/spring-boot/spring-boot-xxjob/src/main/java/com/wyl/springbootxxjob/EnableXxljobRest.java
new file mode 100644
index 0000000..61fec7b
--- /dev/null
+++ b/spring-boot/spring-boot-xxjob/src/main/java/com/wyl/springbootxxjob/EnableXxljobRest.java
@@ -0,0 +1,13 @@
+package com.wyl.springbootxxjob;
+
+import com.wyl.springbootxxjob.config.JobServerConfig;
+import org.springframework.context.annotation.Import;
+
+import java.lang.annotation.*;
+
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+@Import(JobServerConfig.class)
+public @interface EnableXxljobRest {
+}
diff --git a/spring-boot/spring-boot-xxjob/src/main/java/com/wyl/springbootxxjob/SpringBootXxjobApplication.java b/spring-boot/spring-boot-xxjob/src/main/java/com/wyl/springbootxxjob/SpringBootXxjobApplication.java
new file mode 100644
index 0000000..dd65bc3
--- /dev/null
+++ b/spring-boot/spring-boot-xxjob/src/main/java/com/wyl/springbootxxjob/SpringBootXxjobApplication.java
@@ -0,0 +1,13 @@
+package com.wyl.springbootxxjob;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class SpringBootXxjobApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(SpringBootXxjobApplication.class, args);
+ }
+
+}
diff --git a/spring-boot/spring-boot-xxjob/src/main/java/com/wyl/springbootxxjob/config/JobServerConfig.java b/spring-boot/spring-boot-xxjob/src/main/java/com/wyl/springbootxxjob/config/JobServerConfig.java
new file mode 100644
index 0000000..9d5fa8d
--- /dev/null
+++ b/spring-boot/spring-boot-xxjob/src/main/java/com/wyl/springbootxxjob/config/JobServerConfig.java
@@ -0,0 +1,54 @@
+package com.wyl.springbootxxjob.config;
+
+import com.wyl.springbootxxjob.service.DynamicXxlJobService;
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+import okhttp3.OkHttpClient;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.http.client.ClientHttpRequestFactory;
+import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;
+import org.springframework.web.client.RestTemplate;
+
+import java.util.concurrent.TimeUnit;
+
+
+@Configuration
+@Getter
+@Slf4j
+public class JobServerConfig {
+
+ @Value("${xxl-job.http.serve.admin.addresses}")
+ private String adminAddresses;
+
+ @Value("${xxl-job.http.job.server.userName}")
+ private String userName;
+
+ @Value("${xxl-job.http.job.server.password}")
+ private String password;
+
+ @Bean("xxJobRestTemplate")
+ public RestTemplate restTemplate() {
+ RestTemplate restTemplate = new RestTemplate(getClientHttpRequestFactory());
+ return restTemplate;
+ }
+
+ @Bean
+ DynamicXxlJobService dynamicXxlJobService() {
+ return new DynamicXxlJobService();
+ }
+
+ /**
+ * 使用OkHttpClient作为底层客户端
+ *
+ * @return
+ */
+ private ClientHttpRequestFactory getClientHttpRequestFactory() {
+ OkHttpClient okHttpClient = new OkHttpClient.Builder().connectTimeout(5, TimeUnit.SECONDS)
+ .writeTimeout(5, TimeUnit.SECONDS)
+ .readTimeout(5, TimeUnit.SECONDS)
+ .build();
+ return new OkHttp3ClientHttpRequestFactory(okHttpClient);
+ }
+}
diff --git a/spring-boot/spring-boot-xxjob/src/main/java/com/wyl/springbootxxjob/job/SampleXxlJob.java b/spring-boot/spring-boot-xxjob/src/main/java/com/wyl/springbootxxjob/job/SampleXxlJob.java
new file mode 100644
index 0000000..585a4fe
--- /dev/null
+++ b/spring-boot/spring-boot-xxjob/src/main/java/com/wyl/springbootxxjob/job/SampleXxlJob.java
@@ -0,0 +1,50 @@
+package com.wyl.springbootxxjob.job;
+
+import com.xxl.job.core.context.XxlJobHelper;
+import com.xxl.job.core.handler.annotation.XxlJob;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+import javax.sound.midi.Soundbank;
+import java.io.BufferedInputStream;
+import java.io.BufferedReader;
+import java.io.DataOutputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * XxlJob开发示例(Bean模式)
+ *
+ * 开发步骤:
+ * 1、任务开发:在Spring Bean实例中,开发Job方法;
+ * 2、注解配置:为Job方法添加注解 "@XxlJob(value="自定义jobhandler名称", init = "JobHandler初始化方法", destroy = "JobHandler销毁方法")",注解value值对应的是调度中心新建任务的JobHandler属性的值。
+ * 3、执行日志:需要通过 "XxlJobHelper.log" 打印执行日志;
+ * 4、任务结果:默认任务结果为 "成功" 状态,不需要主动设置;如有诉求,比如设置任务结果为失败,可以通过 "XxlJobHelper.handleFail/handleSuccess" 自主设置任务结果;
+ *
+ * @author xuxueli 2019-12-11 21:52:51
+ */
+@Component
+public class SampleXxlJob {
+ private static Logger logger = LoggerFactory.getLogger(SampleXxlJob.class);
+
+
+ /**
+ * 1、简单任务示例(Bean模式)
+ */
+ @XxlJob("wylDemoHandler")
+ public void demoJobHandler() throws Exception {
+ XxlJobHelper.log("XXL-JOB, Hello World.");
+ System.out.println(XxlJobHelper.getJobParam());
+ System.out.println(XxlJobHelper.getJobId());
+ for (int i = 0; i < 5; i++) {
+ XxlJobHelper.log("beat at:" + i);
+ TimeUnit.SECONDS.sleep(2);
+ }
+ // default success
+ }
+
+}
diff --git a/spring-boot/spring-boot-xxjob/src/main/java/com/wyl/springbootxxjob/job/XxlJobConfig.java b/spring-boot/spring-boot-xxjob/src/main/java/com/wyl/springbootxxjob/job/XxlJobConfig.java
new file mode 100644
index 0000000..9214baa
--- /dev/null
+++ b/spring-boot/spring-boot-xxjob/src/main/java/com/wyl/springbootxxjob/job/XxlJobConfig.java
@@ -0,0 +1,77 @@
+package com.wyl.springbootxxjob.job;
+
+import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * xxl-job config
+ *
+ * @author xuxueli 2017-04-28
+ */
+@Configuration
+public class XxlJobConfig {
+ private Logger logger = LoggerFactory.getLogger(XxlJobConfig.class);
+
+ @Value("${xxl.job.admin.addresses}")
+ private String adminAddresses;
+
+ @Value("${xxl.job.accessToken}")
+ private String accessToken;
+
+ @Value("${xxl.job.executor.appname}")
+ private String appname;
+
+ @Value("${xxl.job.executor.address}")
+ private String address;
+
+ @Value("${xxl.job.executor.ip}")
+ private String ip;
+
+ @Value("${xxl.job.executor.port}")
+ private int port;
+
+ @Value("${xxl.job.executor.logpath}")
+ private String logPath;
+
+ @Value("${xxl.job.executor.logretentiondays}")
+ private int logRetentionDays;
+
+
+ @Bean
+ public XxlJobSpringExecutor xxlJobExecutor() {
+ logger.info(">>>>>>>>>>> xxl-job config init.");
+ XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
+ xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
+ xxlJobSpringExecutor.setAppname(appname);
+ xxlJobSpringExecutor.setAddress(address);
+ xxlJobSpringExecutor.setIp(ip);
+ xxlJobSpringExecutor.setPort(port);
+ xxlJobSpringExecutor.setAccessToken(accessToken);
+ xxlJobSpringExecutor.setLogPath(logPath);
+ xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);
+ return xxlJobSpringExecutor;
+ }
+
+ /**
+ * 针对多网卡、容器内部署等情况,可借助 "spring-cloud-commons" 提供的 "InetUtils" 组件灵活定制注册IP;
+ *
+ * 1、引入依赖:
+ *
+ * org.springframework.cloud
+ * spring-cloud-commons
+ * ${version}
+ *
+ *
+ * 2、配置文件,或者容器启动变量
+ * spring.cloud.inetutils.preferred-networks: 'xxx.xxx.xxx.'
+ *
+ * 3、获取IP
+ * String ip_ = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress();
+ */
+
+
+}
\ No newline at end of file
diff --git a/spring-boot/spring-boot-xxjob/src/main/java/com/wyl/springbootxxjob/obj/JobEntity.java b/spring-boot/spring-boot-xxjob/src/main/java/com/wyl/springbootxxjob/obj/JobEntity.java
new file mode 100644
index 0000000..c52f7f8
--- /dev/null
+++ b/spring-boot/spring-boot-xxjob/src/main/java/com/wyl/springbootxxjob/obj/JobEntity.java
@@ -0,0 +1,107 @@
+package com.wyl.springbootxxjob.obj;
+
+import lombok.Data;
+import org.springframework.util.LinkedMultiValueMap;
+import org.springframework.util.MultiValueMap;
+
+/**
+ * @author: wangyl
+ * @date: 2022/4/27
+ * @description: 创建任务对象
+ */
+@Data
+public class JobEntity {
+ /**
+ * 任务id 修改是需要填写
+ */
+ Integer id;
+ /**
+ * 执行器主键ID
+ */
+ String jobGroup = "";
+ /**
+ * job描述
+ */
+ String jobDesc = "";
+ /**
+ * 作者
+ */
+ String author = "xxl-job-rest";
+ /**
+ * 调度类型
+ */
+ String scheduleType = "CRON";
+ /**
+ * 调度配置,值含义取决于调度类型
+ */
+ String scheduleConf = "";
+ /**
+ * 调度过期策略
+ */
+ String cronGenDisplay = "";
+ /**
+ *
+ */
+ String scheduleConfCRON = "";
+ /**
+ * GLUE类型 #com.xxl.job.core.glue.GlueTypeEnum
+ */
+ String glueType = "BEAN";
+ /**
+ * 执行器,任务Handler名称
+ */
+ String executorHandler = "";
+ /**
+ * 执行器,任务参数
+ */
+ String executorParam = "";
+ /**
+ * 执行器路由策略
+ */
+ String executorRouteStrategy = "FIRST";
+ /**
+ * 调度过期策略
+ */
+ String misfireStrategy = "DO_NOTHING";
+ /**
+ * 阻塞处理策略
+ */
+ String executorBlockStrategy = "SERIAL_EXECUTION";
+ /**
+ * 任务执行超时时间,单位秒
+ */
+ String executorTimeout = "0";
+ /**
+ * 失败重试次数
+ */
+ String executorFailRetryCount = "0";
+ /**
+ * GLUE备注
+ */
+ String glueRemark = "";
+
+ public MultiValueMap makeParam() {
+ MultiValueMap paramMap = new LinkedMultiValueMap<>();
+ paramMap.add("jobGroup", jobGroup);
+ paramMap.add("jobDesc", jobDesc);
+ paramMap.add("author", author);
+ paramMap.add("scheduleType", scheduleType);
+ paramMap.add("scheduleConf", scheduleConf);
+ paramMap.add("cronGen_display", cronGenDisplay);
+ paramMap.add("glueType", glueType);
+ paramMap.add("executorHandler", executorHandler);
+ paramMap.add("executorParam", executorParam);
+ paramMap.add("executorRouteStrategy", executorRouteStrategy);
+ paramMap.add("misfireStrategy", misfireStrategy);
+ paramMap.add("executorBlockStrategy", executorBlockStrategy);
+ paramMap.add("executorTimeout", executorTimeout);
+ paramMap.add("executorFailRetryCount", executorFailRetryCount);
+ paramMap.add("glueRemark", glueRemark);
+ paramMap.add("schedule_conf_CRON", scheduleConfCRON);
+ if (id != null) {
+ paramMap.add("id", id.toString());
+ }
+ return paramMap;
+ }
+
+}
diff --git a/spring-boot/spring-boot-xxjob/src/main/java/com/wyl/springbootxxjob/obj/JobTriggerEntity.java b/spring-boot/spring-boot-xxjob/src/main/java/com/wyl/springbootxxjob/obj/JobTriggerEntity.java
new file mode 100644
index 0000000..8d76ec6
--- /dev/null
+++ b/spring-boot/spring-boot-xxjob/src/main/java/com/wyl/springbootxxjob/obj/JobTriggerEntity.java
@@ -0,0 +1,34 @@
+package com.wyl.springbootxxjob.obj;
+
+import lombok.Data;
+import org.springframework.util.LinkedMultiValueMap;
+import org.springframework.util.MultiValueMap;
+
+/**
+ * @author: wangyl
+ * @date: 2022/4/27
+ * @description: 立即执行任务参数
+ */
+@Data
+public class JobTriggerEntity {
+ /**
+ * 任务id
+ */
+ Integer id;
+ /**
+ * 执行参数
+ */
+ String executorParam;
+ /**
+ * 执行任务机器ip列表
+ */
+ String addressList;
+
+ public MultiValueMap makeParam() {
+ MultiValueMap hashMap = new LinkedMultiValueMap<>();
+ hashMap.add("id", id.toString());
+ hashMap.add("executorParam", executorParam);
+ hashMap.add("addressList", addressList);
+ return hashMap;
+ }
+}
diff --git a/spring-boot/spring-boot-xxjob/src/main/java/com/wyl/springbootxxjob/obj/LoginEntity.java b/spring-boot/spring-boot-xxjob/src/main/java/com/wyl/springbootxxjob/obj/LoginEntity.java
new file mode 100644
index 0000000..163fc9a
--- /dev/null
+++ b/spring-boot/spring-boot-xxjob/src/main/java/com/wyl/springbootxxjob/obj/LoginEntity.java
@@ -0,0 +1,29 @@
+package com.wyl.springbootxxjob.obj;
+
+import lombok.Data;
+import org.springframework.util.LinkedMultiValueMap;
+import org.springframework.util.MultiValueMap;
+
+/**
+ * @author: wangyl
+ * @date: 2022/4/27
+ * @description: xx-job 登录对象
+ */
+@Data
+public class LoginEntity {
+ /**
+ * 用户名
+ */
+ String userName = "";
+ /**
+ * 密码
+ */
+ String password = "";
+
+ public MultiValueMap makeParam() {
+ MultiValueMap hashMap = new LinkedMultiValueMap<>();
+ hashMap.add("userName", userName);
+ hashMap.add("password", password);
+ return hashMap;
+ }
+}
diff --git a/spring-boot/spring-boot-xxjob/src/main/java/com/wyl/springbootxxjob/obj/Result.java b/spring-boot/spring-boot-xxjob/src/main/java/com/wyl/springbootxxjob/obj/Result.java
new file mode 100644
index 0000000..f767e87
--- /dev/null
+++ b/spring-boot/spring-boot-xxjob/src/main/java/com/wyl/springbootxxjob/obj/Result.java
@@ -0,0 +1,31 @@
+package com.wyl.springbootxxjob.obj;
+
+import lombok.Data;
+
+/**
+ * @author: wangyl
+ * @date: 2022/4/27
+ * @description: xx-job请求返回对象
+ */
+@Data
+public class Result {
+ /**
+ * 操作吗
+ */
+ private Integer code;
+ /**
+ * 错误信息
+ */
+ private String msg;
+ /**
+ * 结果信息
+ */
+ private T content;
+
+ /**
+ * 操作成功
+ */
+ public Boolean succeed() {
+ return 200 == code;
+ }
+}
diff --git a/spring-boot/spring-boot-xxjob/src/main/java/com/wyl/springbootxxjob/service/DynamicXxlJobService.java b/spring-boot/spring-boot-xxjob/src/main/java/com/wyl/springbootxxjob/service/DynamicXxlJobService.java
new file mode 100644
index 0000000..1eb7de2
--- /dev/null
+++ b/spring-boot/spring-boot-xxjob/src/main/java/com/wyl/springbootxxjob/service/DynamicXxlJobService.java
@@ -0,0 +1,232 @@
+package com.wyl.springbootxxjob.service;
+
+import com.wyl.springbootxxjob.config.JobServerConfig;
+import com.wyl.springbootxxjob.obj.JobEntity;
+import com.wyl.springbootxxjob.obj.JobTriggerEntity;
+import com.wyl.springbootxxjob.obj.LoginEntity;
+import com.wyl.springbootxxjob.obj.Result;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.http.*;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+import org.springframework.util.LinkedMultiValueMap;
+import org.springframework.util.MultiValueMap;
+import org.springframework.web.client.RestTemplate;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.List;
+
+@Service
+@Slf4j
+public class DynamicXxlJobService {
+
+ /**
+ * 登录url
+ */
+ static private String LOGIN_URL;
+ /**
+ * 创建任务的url
+ */
+ static private String CREATE_JOB;
+
+ /**
+ * 创建任务的url
+ */
+ static private String UPDATE_JOB;
+ /**
+ * 删除任务的url
+ */
+ static private String REMOVE_JOB;
+ /**
+ * 启动任务的url
+ */
+ static private String START_JOB;
+ /**
+ * 停止任务的url
+ */
+ static private String STOP_JOB;
+ /**
+ * 立即执行任务url
+ */
+ static private String TRIGGER_JOB;
+
+ @PostConstruct
+ public void init() {
+ LOGIN_URL = jobServerConfig.getAdminAddresses() + "/login";
+ CREATE_JOB = jobServerConfig.getAdminAddresses() + "/jobinfo/add";
+ UPDATE_JOB = jobServerConfig.getAdminAddresses() + "/jobinfo/update";
+ REMOVE_JOB = jobServerConfig.getAdminAddresses() + "/jobinfo/remove";
+ START_JOB = jobServerConfig.getAdminAddresses() + "/jobinfo/start";
+ STOP_JOB = jobServerConfig.getAdminAddresses() + "/jobinfo/stop";
+ TRIGGER_JOB = jobServerConfig.getAdminAddresses() + "/jobinfo/trigger";
+ }
+
+ @Resource
+ private JobServerConfig jobServerConfig;
+
+ @Resource(name = "xxJobRestTemplate")
+ RestTemplate restTemplate;
+
+ /**
+ * 创建定时任务
+ *
+ * @param jobEntity
+ * @return java.lang.Integer
+ * @Date 2022/4/27
+ * @Author wangyl
+ */
+ public Integer createJob(JobEntity jobEntity) {
+ MultiValueMap creatJonParam = jobEntity.makeParam();
+ ResponseEntity responseEntity = this.postFrom(CREATE_JOB, creatJonParam, true);
+ Result body = responseEntity.getBody();
+ if (!body.succeed()) {
+ log.error("创建任务失败,参数为;" + creatJonParam + "错误为:" + body.getMsg());
+ throw new RuntimeException();
+ }
+ Object jobId = body.getContent();
+ return Integer.valueOf(jobId.toString());
+ }
+
+ /**
+ * 更新定时任务信息
+ * @param jobEntity
+ * @return boolean
+ * @Date 2022/4/28
+ * @Author wangyl
+ */
+ public boolean updateJob(JobEntity jobEntity) {
+ MultiValueMap creatJonParam = jobEntity.makeParam();
+ ResponseEntity responseEntity = this.postFrom(UPDATE_JOB, creatJonParam, true);
+ Result body = responseEntity.getBody();
+ if (!body.succeed()) {
+ log.error("更新任务失败,参数为;" + creatJonParam + "错误为:" + body.getMsg());
+ throw new RuntimeException(body.getMsg());
+ }
+ return true;
+ }
+ public boolean triggerJob(JobTriggerEntity jobTriggerEntity) {
+ MultiValueMap jobTriggerParam = jobTriggerEntity.makeParam();
+ ResponseEntity responseEntity = this.postFrom(TRIGGER_JOB, jobTriggerParam, true);
+ Result body = responseEntity.getBody();
+ if (!body.succeed()) {
+ log.error("立即执行任务失败,参数为;" + jobTriggerEntity + "错误为:" + body.getMsg());
+ throw new RuntimeException();
+ }
+ return true;
+ }
+
+ /**
+ * 启动固定任务
+ *
+ * @param jobId jobId
+ * @return 启动固定任务
+ */
+ public boolean startJob(Integer jobId) {
+ MultiValueMap paramMap = new LinkedMultiValueMap<>();
+ paramMap.add("id", String.valueOf(jobId));
+ ResponseEntity responseEntity = postFrom(START_JOB, paramMap, true);
+ Result body = responseEntity.getBody();
+ if (!body.succeed()) {
+ log.error("job:" + jobId + "启动失败,失败理由:" + body.getMsg());
+ throw new RuntimeException(body.getMsg());//todo 替换异常对象
+ }
+
+ return true;
+ }
+
+ /**
+ * 停止任务
+ *
+ * @param jobId
+ * @return boolean
+ * @Date 2022/4/27
+ * @Author wangyl
+ */
+ public boolean stopJob(Integer jobId) {
+ MultiValueMap paramMap = new LinkedMultiValueMap<>();
+ paramMap.add("id", String.valueOf(jobId));
+ ResponseEntity responseEntity = postFrom(STOP_JOB, paramMap, true);
+ Result body = responseEntity.getBody();
+ if (!body.succeed()) {
+ log.error("job:" + jobId + "停止失败,失败理由:" + body.getMsg());
+ throw new RuntimeException(body.getMsg());//todo 替换异常对象
+ }
+
+ return true;
+ }
+
+
+ /**
+ * 删除指定任务
+ *
+ * @param jobId 任务id
+ * @return boolean
+ * @Date 2022/4/27
+ * @Author wangyl
+ */
+ public boolean removeJob(Integer jobId) {
+ MultiValueMap paramMap = new LinkedMultiValueMap<>();
+ paramMap.add("id", String.valueOf(jobId));
+ ResponseEntity responseEntity = postFrom(REMOVE_JOB, paramMap, true);
+ Result body = responseEntity.getBody();
+ if (!body.succeed()) {
+ log.error("job:" + jobId + "删除失败,失败理由:" + body.getMsg());
+ throw new RuntimeException(body.getMsg());//todo 替换异常对象
+ }
+ return true;
+ }
+
+ /**
+ * 登录xx-job获取cookies
+ *
+ * @param
+ * @return java.util.List
+ * @Date 2022/4/27
+ * @Author wangyl
+ */
+ public List getCookie() {
+ LoginEntity loginEntity = new LoginEntity();
+ loginEntity.setUserName(jobServerConfig.getUserName());
+ loginEntity.setPassword(jobServerConfig.getPassword());
+ MultiValueMap loginParam = loginEntity.makeParam();
+ ResponseEntity responseEntity = this.postFrom(LOGIN_URL, loginParam, false);
+ Result result = responseEntity.getBody();
+ if (!result.succeed()) {
+ log.error("登录xx-job失败", result.getMsg());
+ throw new RuntimeException(result.getMsg());//todo 替换异常对象
+ }
+ List cookies = responseEntity.getHeaders().get("Set-Cookie");
+ return cookies;
+ }
+
+ /**
+ * 发送post的 form 请求
+ *
+ * @param url 请求url
+ * @param hashMap 请求参数
+ * @return java.lang.String
+ * @Date 2022/4/27
+ * @Author wangyl
+ */
+ public ResponseEntity postFrom(String url, MultiValueMap hashMap, Boolean needCookies) {
+ HttpHeaders headers = new HttpHeaders();
+ List cookies = new ArrayList<>();
+ if (needCookies && CollectionUtils.isEmpty(cookies)) {
+ cookies = getCookie();
+ headers.put(HttpHeaders.COOKIE, cookies);
+ }
+ // 请求头设置,x-www-form-urlencoded格式的数据
+ headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
+ HttpEntity> request = new HttpEntity<>(hashMap, headers);
+ ResponseEntity responseEntity = restTemplate.postForEntity(url, request, Result.class);
+ if (!(responseEntity.getStatusCode() == HttpStatus.OK)) {
+ log.error("请求url:" + url + ",param:" + hashMap + " result:" + responseEntity);
+ throw new RuntimeException("");//TODO 修改为异常
+ }
+ return responseEntity;
+ }
+
+}
+
diff --git a/spring-boot/spring-boot-xxjob/src/main/resources/application.properties b/spring-boot/spring-boot-xxjob/src/main/resources/application.properties
new file mode 100644
index 0000000..900cff9
--- /dev/null
+++ b/spring-boot/spring-boot-xxjob/src/main/resources/application.properties
@@ -0,0 +1,16 @@
+xxl-job.http.serve.admin.addresses=http://192.168.3.10:8080/xxl-job-admin/
+xxl-job.http.job.server.userName = admin
+xxl-job.http.job.server.password = 123456
+
+
+
+
+### xxl-job admin address list, such as "http://address" or "http://address01,http://address02"
+xxl.job.admin.addresses=http://192.168.3.10:8080/xxl-job-admin
+xxl.job.accessToken=
+xxl.job.executor.appname=wyl-first-test
+xxl.job.executor.address=
+xxl.job.executor.ip=
+xxl.job.executor.port=9999
+xxl.job.executor.logpath=./logs
+xxl.job.executor.logretentiondays=30
diff --git a/spring-boot/spring-boot-xxjob/src/test/java/com/wyl/springbootxxjob/BaseTest.java b/spring-boot/spring-boot-xxjob/src/test/java/com/wyl/springbootxxjob/BaseTest.java
new file mode 100644
index 0000000..40dc8b9
--- /dev/null
+++ b/spring-boot/spring-boot-xxjob/src/test/java/com/wyl/springbootxxjob/BaseTest.java
@@ -0,0 +1,15 @@
+package com.wyl.springbootxxjob;
+
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = BaseTest.Application.class)
+public class BaseTest {
+ @ComponentScan(value = "com.wyl.springbootxxjob")
+ public static class Application {
+
+ }
+}
\ No newline at end of file
diff --git a/spring-boot/spring-boot-xxjob/src/test/java/com/wyl/springbootxxjob/SpringBootXxjobApplicationTests.java b/spring-boot/spring-boot-xxjob/src/test/java/com/wyl/springbootxxjob/SpringBootXxjobApplicationTests.java
new file mode 100644
index 0000000..f0376ac
--- /dev/null
+++ b/spring-boot/spring-boot-xxjob/src/test/java/com/wyl/springbootxxjob/SpringBootXxjobApplicationTests.java
@@ -0,0 +1,83 @@
+package com.wyl.springbootxxjob;
+
+import com.wyl.springbootxxjob.obj.JobEntity;
+import com.wyl.springbootxxjob.obj.JobTriggerEntity;
+import com.wyl.springbootxxjob.service.DynamicXxlJobService;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.time.LocalDateTime;
+import java.util.List;
+
+class SpringBootXxjobApplicationTests extends BaseTest {
+
+ @Autowired
+ DynamicXxlJobService dynamicXxlJobService;
+
+ @Test
+ void getCookiesTest() {
+ List cookie = dynamicXxlJobService.getCookie();
+ System.out.println(cookie);
+ }
+
+ @Test
+ void createJobTest() {
+ JobEntity jobEntity = new JobEntity();
+ jobEntity.setJobGroup("2");
+ jobEntity.setJobDesc("测试项目"+ LocalDateTime.now());
+ jobEntity.setAuthor("wyl");
+ jobEntity.setScheduleConf("* * * * * ?");
+ jobEntity.setCronGenDisplay("* * * * * ?");
+ jobEntity.setGlueType("BEAN");
+ jobEntity.setExecutorHandler("wylDemoHandler");
+ jobEntity.setExecutorRouteStrategy("FIRST");
+ jobEntity.setMisfireStrategy("DO_NOTHING");
+ jobEntity.setExecutorTimeout("0");
+ jobEntity.setExecutorFailRetryCount("0");
+ jobEntity.setGlueRemark("wyl测试新建项目");
+ Integer job = dynamicXxlJobService.createJob(jobEntity);
+ }
+
+ @Test
+ void updateJobTest() {
+ JobEntity jobEntity = new JobEntity();
+ jobEntity.setId(7);
+ jobEntity.setJobGroup("2");
+ jobEntity.setJobDesc("测试项目"+ LocalDateTime.now()+"更新");
+ jobEntity.setAuthor("wyl");
+ jobEntity.setScheduleConf("* * * * * ?");
+ jobEntity.setCronGenDisplay("* * * * * ?");
+ jobEntity.setGlueType("BEAN");
+ jobEntity.setExecutorHandler("wylDemoHandler");
+ jobEntity.setExecutorRouteStrategy("FIRST");
+ jobEntity.setMisfireStrategy("DO_NOTHING");
+ jobEntity.setExecutorTimeout("0");
+ jobEntity.setExecutorFailRetryCount("0");
+ jobEntity.setGlueRemark("wyl测试新建项目");
+ dynamicXxlJobService.updateJob(jobEntity);
+ }
+
+ @Test
+ void triggerJobTest() {
+ JobTriggerEntity jobTriggerEntity = new JobTriggerEntity();
+ jobTriggerEntity.setId(5);
+ jobTriggerEntity.setExecutorParam("123");
+ dynamicXxlJobService.triggerJob(jobTriggerEntity);
+ }
+
+ @Test
+ void startJobTest() {
+ boolean b = dynamicXxlJobService.startJob(3);
+ }
+
+ @Test
+ void stopJobJobTest() {
+ boolean b = dynamicXxlJobService.stopJob(3);
+ }
+
+ @Test
+ void removeJobTest() {
+ boolean b = dynamicXxlJobService.removeJob(1);
+ }
+
+}