feat(test): 添加生成最后执行SQL的测试功能
- 新增GenerateLastExecuteSQLTest单元测试类 - 实现自动生成z_exec_last.sql文件的功能 - 根据指定日期读取对应SQL目录下的所有文件 - 过滤并提取SQL文件名用于构建更新语句 - 自动生成针对LOWCODE_DBFORM表的更新脚本 - 支持按月分类存储SQL文件的目录结构处理
This commit is contained in:
7
SQL/202511/20251121/z_exec_last.sql
Normal file
7
SQL/202511/20251121/z_exec_last.sql
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
update
|
||||||
|
"LOWCODE_FRAME"."LOWCODE_DBFORM"
|
||||||
|
set IS_DB_SYNC='N'
|
||||||
|
where TABLE_NAME in (
|
||||||
|
'lc_confined_space_operation', 'lc_fire_operation', 'lc_high_operation', 'lc_item_result',
|
||||||
|
'lc_land_operation', 'lc_lifting_operation', 'lc_outside_person', 'lc_temporary_power_operation'
|
||||||
|
);
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package com.jeelowcode.test.sql;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.io.FileUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.db.sql.SqlUtil;
|
||||||
|
import com.jeelowcode.tool.framework.test.core.ut.BaseMockitoUnitTest;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 描述:生成最后执行SQL
|
||||||
|
*
|
||||||
|
* @author shelly
|
||||||
|
*/
|
||||||
|
public class GenerateLastExecuteSQLTest extends BaseMockitoUnitTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGenerateLastExecuteSQL() throws Exception {
|
||||||
|
String executeDateStr = "20251121";
|
||||||
|
Date executeDate = DateUtil.parse(executeDateStr, "yyyyMMdd");
|
||||||
|
String monthStr = DateUtil.format(executeDate, "yyyyMM");
|
||||||
|
// 获取项目目录下的SQL目录路径
|
||||||
|
String projectPath = System.getProperty("user.dir");
|
||||||
|
File adminPath = new File(projectPath);
|
||||||
|
File baseProjectPath = adminPath.getParentFile();
|
||||||
|
File sqlPath = new File(baseProjectPath, "SQL");
|
||||||
|
File monthSqlPath = new File(sqlPath, monthStr);
|
||||||
|
if (monthSqlPath.exists()) {
|
||||||
|
File dateSqlPath = new File(monthSqlPath, executeDateStr);
|
||||||
|
if (dateSqlPath.exists()) {
|
||||||
|
// 查询目录下所有的文件
|
||||||
|
List<File> sqlFileList = FileUtil.loopFiles(dateSqlPath);
|
||||||
|
if (CollUtil.isNotEmpty(sqlFileList)) {
|
||||||
|
// 将sqlFileList转换成字符串列表,字符串使用文件名,不带后缀
|
||||||
|
List<String> sqlFileNameList = sqlFileList.stream()
|
||||||
|
.map(file -> file.getName().substring(0, file.getName().lastIndexOf(".")))
|
||||||
|
.filter(fileName -> !StrUtil.equals(fileName, "z_exec_last"))
|
||||||
|
.map(fileName -> StrUtil.concat(true, "'", fileName, "'"))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
//将列表sqlFileNameList转换成字符串,使用逗号分隔
|
||||||
|
String template = "update \"LOWCODE_FRAME\".\"LOWCODE_DBFORM\" set IS_DB_SYNC='N' where TABLE_NAME in ({});";
|
||||||
|
String formatSql = SqlUtil.formatSql(StrUtil.format(template, CollUtil.join(sqlFileNameList, ",")));
|
||||||
|
File lastExec = new File(dateSqlPath, "z_exec_last.sql");
|
||||||
|
if (lastExec.exists() || (!lastExec.exists() && lastExec.createNewFile())) {
|
||||||
|
// 将formatSql写到lastExec中
|
||||||
|
FileUtil.writeString(formatSql, lastExec, "utf-8");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user