初始化项目
This commit is contained in:
31
xtools-app-common/xtools-app-common-jar/pom.xml
Normal file
31
xtools-app-common/xtools-app-common-jar/pom.xml
Normal file
@@ -0,0 +1,31 @@
|
||||
<?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-app-common</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<artifactId>xtools-app-common-jar</artifactId>
|
||||
|
||||
<!-- 依赖 -->
|
||||
<dependencies>
|
||||
<!-- xtools begin -->
|
||||
<!-- xtools-boot-log -->
|
||||
<dependency>
|
||||
<groupId>org.xujun</groupId>
|
||||
<artifactId>xtools-boot-log</artifactId>
|
||||
</dependency>
|
||||
<!-- xtools end -->
|
||||
|
||||
<!-- 项目模块 begin -->
|
||||
<dependency>
|
||||
<groupId>org.xujun</groupId>
|
||||
<artifactId>xtools-app-common-cache</artifactId>
|
||||
</dependency>
|
||||
<!-- 项目模块 end -->
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,71 @@
|
||||
package xtools.app.common.jar.init;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import org.jspecify.annotations.NonNull;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
import xtools.app.common.cache.enums.AppCache;
|
||||
import xtools.base.config.BaseParams;
|
||||
import xtools.boot.cache.redis.base.RedisService;
|
||||
import xtools.boot.core.utils.JarUtils;
|
||||
import xtools.boot.log.LogBus;
|
||||
import xtools.boot.log.enums.LogBusBaseType;
|
||||
import xtools.boot.log.holder.LogTrackHolder;
|
||||
import xtools.core.CollectionUtils;
|
||||
import xtools.core.enums.LogLevel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* <p>Title : InitJar</p>
|
||||
* <p>Description : InitJar</p>
|
||||
* <p>DevelopTools : Idea_x64_v2026.1</p>
|
||||
* <p>DevelopSystem : macOS Sequoia 15.7.5</p>
|
||||
* <p>Company : org.xujun</p>
|
||||
*
|
||||
* @author : XuJun
|
||||
* @version : 1.0.0
|
||||
* @date : 2026/2/2 14:13
|
||||
*/
|
||||
@Component
|
||||
@Order(BaseParams.CP_NUM200)
|
||||
public class InitJar implements ApplicationRunner {
|
||||
|
||||
/**
|
||||
* 应用名称
|
||||
*/
|
||||
@Value("${spring.application.name:xtools-app}")
|
||||
private String name;
|
||||
|
||||
@Resource
|
||||
private RedisService redisService;
|
||||
|
||||
|
||||
@Override
|
||||
public void run(@NonNull ApplicationArguments args) {
|
||||
ScopedValue.where(LogTrackHolder.getScoped(), LogTrackHolder.newMain()).run(() -> {
|
||||
try {
|
||||
init();
|
||||
} catch (Exception e) {
|
||||
LogBus.init(LogLevel.ERROR, LogBusBaseType.OTHER).title("初始化Jar异常").error(e).save();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
*/
|
||||
private void init() {
|
||||
List<String> jarNameList = JarUtils.getJarName();
|
||||
if (CollectionUtils.isEmpty(jarNameList)) {
|
||||
return;
|
||||
}
|
||||
String key = AppCache.SYS_CACHE_JAR.key() + name;
|
||||
redisService.set(key, jarNameList);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package xtools.app.common.jar.utils;
|
||||
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import xtools.app.common.cache.enums.AppCache;
|
||||
import xtools.base.config.BaseParams;
|
||||
import xtools.boot.cache.redis.utils.RedisUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* <p>Title : RunJarUtils</p>
|
||||
* <p>Description : RunJarUtils</p>
|
||||
* <p>DevelopTools : Idea_x64_v2026.1</p>
|
||||
* <p>DevelopSystem : macOS Sequoia 15.7.5</p>
|
||||
* <p>Company : org.xujun</p>
|
||||
*
|
||||
* @author : XuJun
|
||||
* @version : 1.0.0
|
||||
* @date : 2026/2/18 21:11
|
||||
*/
|
||||
public class RunJarUtils implements BaseParams {
|
||||
|
||||
/**
|
||||
* 缓存参数
|
||||
*/
|
||||
private static final AppCache CACHE_PARAM = AppCache.SYS_CACHE_JAR;
|
||||
|
||||
/**
|
||||
* 获取运行中的Jar
|
||||
*/
|
||||
public static List<JSONObject> get() {
|
||||
String cacheKey = AppCache.SYS_CACHE_JAR.key();
|
||||
Set<String> keys = RedisUtils.get().getByPattern(cacheKey + CP_ASTERISK);
|
||||
List<JSONObject> dataList = new ArrayList<>();
|
||||
for (String key : keys) {
|
||||
JSONArray cacheData = RedisUtils.get().get(key, JSONArray.class);
|
||||
if (Objects.isNull(cacheData) || cacheData.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("name", key.replace(cacheKey, CP_EMPTY));
|
||||
data.put("jars", cacheData);
|
||||
dataList.add(data);
|
||||
}
|
||||
return dataList;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user