扫描、导入任务优化
This commit is contained in:
parent
d14f381b3a
commit
8d5c60a5d1
@ -25,7 +25,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
@RestController
|
||||
@RequestMapping("/api/common-items")
|
||||
public class CommonItemController {
|
||||
@Value("${app.data-dir}")
|
||||
@Value("${app.common-dir}")
|
||||
private String appDataDir;
|
||||
private static final String FILE_NAME = "common_items.json";
|
||||
//private static final String DATA_DIR = "data";
|
||||
|
||||
@ -8,6 +8,7 @@ import com.yfd.platform.modules.experimentalData.config.OutputConfig;
|
||||
import com.yfd.platform.modules.experimentalData.config.RuleConfig;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -19,6 +20,8 @@ import java.io.InputStreamReader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
@ -32,9 +35,15 @@ import java.util.*;
|
||||
@Service
|
||||
@Slf4j
|
||||
public class InsFileConvertNewService {
|
||||
@Value("${app.config-dir}")
|
||||
private String configDir;
|
||||
@Value("${app.templates-dir}")
|
||||
private String templatesDir;
|
||||
|
||||
private static final String CONVERT_FILE_NAME = "ins-convert-default.json";
|
||||
private static final Charset UTF8 = StandardCharsets.UTF_8;
|
||||
|
||||
|
||||
/**
|
||||
* 转换 INS 文件
|
||||
* @param insFile INS 源文件
|
||||
@ -153,11 +162,14 @@ public class InsFileConvertNewService {
|
||||
return mapper.readValue(jsonConfigFile, InsConvertConfig.class);
|
||||
}
|
||||
|
||||
// 2. 尝试 jar 同级 config 目录
|
||||
File external = new File("config/ins-convert-default.json");
|
||||
if (external.exists()) {
|
||||
log.info("加载 jar 同级 JSON 配置:{}", external.getAbsolutePath());
|
||||
return mapper.readValue(external, InsConvertConfig.class);
|
||||
// 2. 尝试 配置文件获取 该方法兼容war部署
|
||||
// 获取项目根目录下的data文件夹路径
|
||||
Path dataDir = Paths.get(configDir);
|
||||
Path filePath = dataDir.resolve(CONVERT_FILE_NAME);
|
||||
if (Files.exists(filePath) && Files.isRegularFile(filePath)) {
|
||||
log.info("加载 JSON 配置文件:{}", filePath.toAbsolutePath());
|
||||
// 直接用 Jackson 从 Path 读取
|
||||
return mapper.readValue(filePath.toFile(), InsConvertConfig.class);
|
||||
}
|
||||
|
||||
// 3. 回退到 jar 内 classpath
|
||||
@ -276,12 +288,21 @@ public class InsFileConvertNewService {
|
||||
|
||||
private BufferedReader openTemplateReader(String templatePath) throws IOException {
|
||||
|
||||
// 1. jar 同级文件(相对当前工作目录)
|
||||
File external = new File(templatePath);
|
||||
if (external.exists()) {
|
||||
log.info("加载 jar 同级模板文件:{}", external.getAbsolutePath());
|
||||
return Files.newBufferedReader(external.toPath(), UTF8);
|
||||
// 1. jar 、war外部加载
|
||||
// 01. 仅截取文件名(兼容 templates/xxx.txt、/templates/xxx.txt)
|
||||
String fileName = Paths.get(templatePath).getFileName().toString();
|
||||
// 02. 拼接外部 templatesDir
|
||||
Path externalPath = Paths.get(templatesDir).resolve(fileName);
|
||||
// 03. 校验并读取
|
||||
if (Files.exists(externalPath) && Files.isRegularFile(externalPath)) {
|
||||
log.info("加载外部模板文件:{}", externalPath.toAbsolutePath());
|
||||
return Files.newBufferedReader(externalPath, UTF8);
|
||||
}
|
||||
// File external = new File(templatePath);
|
||||
// if (external.exists()) {
|
||||
// log.info("加载 jar 同级模板文件:{}", external.getAbsolutePath());
|
||||
// return Files.newBufferedReader(external.toPath(), UTF8);
|
||||
// }
|
||||
|
||||
// 2. classpath 内模板
|
||||
log.info("加载内置模板文件:classpath:{}", templatePath);
|
||||
|
||||
@ -1135,9 +1135,9 @@ public class TsNodesServiceImpl extends ServiceImpl<TsNodesMapper, TsNodes> impl
|
||||
}
|
||||
// 记录开始时间
|
||||
long startTimeFiles = System.currentTimeMillis();
|
||||
// 执行更新操作 taskId, String nodeId
|
||||
// 执行更新操作 taskId, String nodeId(这个方法是瓶颈,SQL自连接+字符串拼接,数据大的时候就是瓶颈)
|
||||
// int affectedLevelFilesRows = tsFilesMapper.updateParentIdByPathHierarchy(taskId, nodeId);
|
||||
//在Java内存中计算父子关系——避免上面方法中SQL自连接+字符串拼接
|
||||
//在Java内存中计算父子关系——避免上面方法中SQL自连接+字符串拼接,分批更新。实测有效。
|
||||
int affectedLevelFilesRows = tsFilesService.updateParentId(taskId, nodeId);
|
||||
// 记录结束时间
|
||||
long endTimeFiles = System.currentTimeMillis();
|
||||
|
||||
@ -1366,7 +1366,7 @@ public class TsTaskServiceImpl extends ServiceImpl<TsTaskMapper, TsTask> impleme
|
||||
// 8. 流式分批插入 TS_FILES
|
||||
if (!fileInsertSqls.isEmpty()) {
|
||||
LOGGER.info("开始分批插入 TS_FILES,共 {} 条", fileInsertSqls.size());
|
||||
int batchSize = 2000; // 可调
|
||||
int batchSize = 5000; // 可调
|
||||
List<String> batch = new ArrayList<>(batchSize);
|
||||
int batchCount = 0;
|
||||
for (String fileSql : fileInsertSqls) {
|
||||
|
||||
@ -97,7 +97,9 @@ ip:
|
||||
file-space: #项目文档空间
|
||||
system: D:\file\system\ #单独上传的文件
|
||||
app:
|
||||
data-dir: E:\projectJava\FileManage\data
|
||||
common-dir: E:\projectJava\FileManage\common
|
||||
templates-dir: E:\projectJava\FileManage\templates
|
||||
config-dir: E:\projectJava\FileManage\config
|
||||
# 文件预览大小
|
||||
file-system:
|
||||
preview:
|
||||
|
||||
@ -84,8 +84,10 @@ ip:
|
||||
file-space: #项目文档空间
|
||||
system: /data/local-data/ #单独上传的文件
|
||||
|
||||
app:
|
||||
data-dir: E:\projectJava\FileManage\data
|
||||
app: #common-dir 加载通用标签文件,可读写,templates-dir 加载文件转换模板文件 ;config-dir 加载文件转换配置文件
|
||||
common-dir: /opt/filemgr/common
|
||||
templates-dir: /opt/filemgr/templates
|
||||
config-dir: /opt/filemgr/config
|
||||
|
||||
file-system:
|
||||
preview:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user