初始化仓库
This commit is contained in:
24
xtools-boot-task/pom.xml
Normal file
24
xtools-boot-task/pom.xml
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.xujun</groupId>
|
||||
<artifactId>xtools-boot</artifactId>
|
||||
<version>5.0.0</version>
|
||||
</parent>
|
||||
<artifactId>xtools-boot-task</artifactId>
|
||||
|
||||
<!-- 依赖 -->
|
||||
<dependencies>
|
||||
<!-- xtools-boot begin -->
|
||||
<!-- xtools-boot-core -->
|
||||
<dependency>
|
||||
<groupId>org.xujun</groupId>
|
||||
<artifactId>xtools-boot-core</artifactId>
|
||||
</dependency>
|
||||
<!-- xtools-boot end -->
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,28 @@
|
||||
package xtools.boot.task;
|
||||
|
||||
import org.springframework.context.annotation.Import;
|
||||
import xtools.boot.core.utils.ModuleLoadUtils;
|
||||
import xtools.boot.task.selector.BootTaskImportSelector;
|
||||
|
||||
/**
|
||||
* <p>Title : BootTaskConfiguration</p>
|
||||
* <p>Description : BootTaskConfiguration</p>
|
||||
* <p>DevelopTools : Idea_x64_v2026.1</p>
|
||||
* <p>DevelopSystem : macOS Sequoia 15.7.5</p>
|
||||
* <p>Company : org.xujun</p>
|
||||
*
|
||||
* @author : XuJun
|
||||
* @version : 5.0.0
|
||||
* @date : 2026/01/01 09:30
|
||||
*/
|
||||
@Import(BootTaskImportSelector.class)
|
||||
public class BootTaskConfiguration {
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
*/
|
||||
public BootTaskConfiguration() {
|
||||
ModuleLoadUtils.loadSuccess(BootTaskConfiguration.class);
|
||||
}
|
||||
|
||||
}
|
||||
111
xtools-boot-task/src/main/java/xtools/boot/task/TaskBus.java
Normal file
111
xtools-boot-task/src/main/java/xtools/boot/task/TaskBus.java
Normal file
@@ -0,0 +1,111 @@
|
||||
package xtools.boot.task;
|
||||
|
||||
import xtools.boot.api.exection.BizError;
|
||||
import xtools.boot.core.utils.SpringContextUtils;
|
||||
import xtools.boot.task.enums.TaskStatus;
|
||||
import xtools.boot.task.interfaces.BaseTaskType;
|
||||
import xtools.boot.task.interfaces.TaskBusInterface;
|
||||
import xtools.boot.task.model.dto.TaskInfo;
|
||||
import xtools.core.CollectionUtils;
|
||||
import xtools.core.StringUtils;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* <p>Title : TaskBus</p>
|
||||
* <p>Description : TaskBus</p>
|
||||
* <p>DevelopTools : Idea_x64_v2026.1</p>
|
||||
* <p>DevelopSystem : macOS Sequoia 15.7.5</p>
|
||||
* <p>Company : org.xujun</p>
|
||||
*
|
||||
* @author : XuJun
|
||||
* @version : 5.0.0
|
||||
* @date : 2026/2/15 10:07
|
||||
*/
|
||||
public class TaskBus {
|
||||
|
||||
/**
|
||||
* 任务数据
|
||||
**/
|
||||
private final TaskInfo taskInfo;
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
*
|
||||
* @param code 任务编码
|
||||
* @param type 任务类型
|
||||
* @param status 任务状态
|
||||
*/
|
||||
private TaskBus(String code, BaseTaskType type, TaskStatus status) {
|
||||
// 参数处理
|
||||
if (StringUtils.isBlank(code)) {
|
||||
throw new BizError("任务Code不能为空");
|
||||
}
|
||||
if (type == null) {
|
||||
throw new BizError("任务类型不能为空");
|
||||
}
|
||||
if (status == null) {
|
||||
throw new BizError("任务状态不能为空");
|
||||
}
|
||||
taskInfo = new TaskInfo();
|
||||
// 参数赋值
|
||||
taskInfo.setCode(code);
|
||||
taskInfo.setType(type.desc());
|
||||
taskInfo.setStatus(status);
|
||||
taskInfo.setInfo(type.desc() + "-" + status.desc());
|
||||
taskInfo.setTime(Instant.now());
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化任务
|
||||
*
|
||||
* @param code 任务编码
|
||||
* @param type 任务类型
|
||||
* @param status 任务状态
|
||||
* @return 当前对象
|
||||
*/
|
||||
public static TaskBus init(String code, BaseTaskType type, TaskStatus status) {
|
||||
return new TaskBus(code, type, status);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置任务信息
|
||||
*
|
||||
* @param info 任务信息
|
||||
* @return 当前对象
|
||||
*/
|
||||
public TaskBus info(String info) {
|
||||
if (StringUtils.isBlank(info)) {
|
||||
throw new BizError("任务信息不能为空");
|
||||
}
|
||||
taskInfo.setInfo(info);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置任务时间
|
||||
*
|
||||
* @param time 任务时间
|
||||
* @return 当前对象
|
||||
*/
|
||||
public TaskBus time(Instant time) {
|
||||
if (Objects.isNull(time)) {
|
||||
throw new BizError("任务时间不能为空");
|
||||
}
|
||||
taskInfo.setTime(time);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存任务
|
||||
*/
|
||||
public void save() {
|
||||
Collection<TaskBusInterface> beanList = SpringContextUtils.getBeanList(TaskBusInterface.class);
|
||||
if (CollectionUtils.isNotEmpty(beanList)) {
|
||||
beanList.forEach(item -> item.save(taskInfo));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package xtools.boot.task.enums;
|
||||
|
||||
import xtools.boot.api.enums.BaseEnum;
|
||||
|
||||
/**
|
||||
* <p>Title : TaskStatus</p>
|
||||
* <p>Description : TaskStatus</p>
|
||||
* <p>DevelopTools : Idea_x64_v2026.1</p>
|
||||
* <p>DevelopSystem : macOS Sequoia 15.7.5</p>
|
||||
* <p>Company : org.xujun</p>
|
||||
*
|
||||
* @author : XuJun
|
||||
* @version : 5.0.0
|
||||
* @date : 2026/2/3 10:31
|
||||
*/
|
||||
public enum TaskStatus implements BaseEnum {
|
||||
|
||||
// 任务进行中
|
||||
ING(0, "进行中"),
|
||||
// 任务成功
|
||||
SUCCESS(1, "任务成功"),
|
||||
// 任务失败
|
||||
ERROR(2, "任务失败");
|
||||
|
||||
/**
|
||||
* 编码
|
||||
*/
|
||||
private final int code;
|
||||
|
||||
/**
|
||||
* 说明
|
||||
*/
|
||||
private final String desc;
|
||||
|
||||
/**
|
||||
* 初始化方法
|
||||
*
|
||||
* @param code Code
|
||||
* @param desc 说明
|
||||
*/
|
||||
TaskStatus(int code, String desc) {
|
||||
this.code = code;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断枚举值类型
|
||||
*
|
||||
* @param code 枚举值
|
||||
* @return 枚举值类型
|
||||
*/
|
||||
public static TaskStatus valueOf(int code) {
|
||||
for (TaskStatus type : values()) {
|
||||
if (type.code == code) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("unknown code, code=" + code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有枚举
|
||||
*
|
||||
* @return 所有枚举
|
||||
*/
|
||||
@Override
|
||||
public BaseEnum[] all() {
|
||||
return values();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取枚举编码
|
||||
*
|
||||
* @return 枚举编码
|
||||
*/
|
||||
@Override
|
||||
public int code() {
|
||||
return code;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取枚举说明
|
||||
*
|
||||
* @return 枚举说明
|
||||
*/
|
||||
@Override
|
||||
public String desc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package xtools.boot.task.interfaces;
|
||||
|
||||
import xtools.boot.api.enums.BaseEnum;
|
||||
|
||||
/**
|
||||
* <p>Title : BaseTaskType</p>
|
||||
* <p>Description : BaseTaskType</p>
|
||||
* <p>DevelopTools : Idea_x64_v2026.1</p>
|
||||
* <p>DevelopSystem : macOS Sequoia 15.7.5</p>
|
||||
* <p>Company : org.xujun</p>
|
||||
*
|
||||
* @author : XuJun
|
||||
* @version : 5.0.0
|
||||
* @date : 2026/2/15 09:52
|
||||
*/
|
||||
public interface BaseTaskType extends BaseEnum {
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package xtools.boot.task.interfaces;
|
||||
|
||||
import xtools.boot.task.model.dto.TaskInfo;
|
||||
|
||||
/**
|
||||
* <p>Title : TaskBusInterface</p>
|
||||
* <p>Description : TaskBusInterface</p>
|
||||
* <p>DevelopTools : Idea_x64_v2026.1</p>
|
||||
* <p>DevelopSystem : macOS Sequoia 15.7.5</p>
|
||||
* <p>Company : org.xujun</p>
|
||||
*
|
||||
* @author : XuJun
|
||||
* @version : 5.0.0
|
||||
* @date : 2026/2/15 10:16
|
||||
*/
|
||||
public interface TaskBusInterface {
|
||||
|
||||
/**
|
||||
* 保存任务
|
||||
*
|
||||
* @param taskInfo 任务
|
||||
*/
|
||||
void save(TaskInfo taskInfo);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package xtools.boot.task.model.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import xtools.boot.task.enums.TaskStatus;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.Instant;
|
||||
|
||||
/**
|
||||
* <p>Title : TaskInfo</p>
|
||||
* <p>Description : TaskInfo</p>
|
||||
* <p>DevelopTools : Idea_x64_v2026.1</p>
|
||||
* <p>DevelopSystem : macOS Sequoia 15.7.5</p>
|
||||
* <p>Company : org.xujun</p>
|
||||
*
|
||||
* @author : XuJun
|
||||
* @version : 5.0.0
|
||||
* @date : 2026/2/15 10:07
|
||||
*/
|
||||
@Data
|
||||
public class TaskInfo implements Serializable {
|
||||
|
||||
/**
|
||||
* 任务编码
|
||||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 任务类型
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 任务状态
|
||||
*/
|
||||
private TaskStatus status;
|
||||
|
||||
/**
|
||||
* 任务信息
|
||||
*/
|
||||
private String info;
|
||||
|
||||
/**
|
||||
* 任务时间
|
||||
*/
|
||||
private Instant time;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package xtools.boot.task.selector;
|
||||
|
||||
import org.jspecify.annotations.NonNull;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
|
||||
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
|
||||
/**
|
||||
* <p>Title : BootTaskImportSelector</p>
|
||||
* <p>Description : BootTaskImportSelector</p>
|
||||
* <p>DevelopTools : Idea_x64_v2026.1</p>
|
||||
* <p>DevelopSystem : macOS Sequoia 15.7.5</p>
|
||||
* <p>Company : org.xujun</p>
|
||||
*
|
||||
* @author : XuJun
|
||||
* @version : 5.0.0
|
||||
* @date : 2026/01/01 09:30
|
||||
*/
|
||||
public class BootTaskImportSelector implements ImportBeanDefinitionRegistrar {
|
||||
|
||||
/**
|
||||
* 根据给定的注释元数据,根据需要注册bean
|
||||
*
|
||||
* @param importingClassMetadata AnnotationMetadata
|
||||
* @param registry BeanDefinitionRegistry
|
||||
*/
|
||||
@Override
|
||||
public void registerBeanDefinitions(@NonNull AnnotationMetadata importingClassMetadata, @NonNull BeanDefinitionRegistry registry) {
|
||||
// 构建扫描对象
|
||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(registry, true);
|
||||
// 扫描包下路径
|
||||
scanner.scan("xtools.boot.task");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
xtools.boot.task.BootTaskConfiguration
|
||||
Reference in New Issue
Block a user