diff --git a/SQL/202511/20251121/z_exec_last.sql b/SQL/202511/20251121/z_exec_last.sql new file mode 100644 index 0000000..9635398 --- /dev/null +++ b/SQL/202511/20251121/z_exec_last.sql @@ -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' + ); \ No newline at end of file diff --git a/jeelowcode-admin/src/test/java/com/jeelowcode/test/sql/GenerateLastExecuteSQLTest.java b/jeelowcode-admin/src/test/java/com/jeelowcode/test/sql/GenerateLastExecuteSQLTest.java new file mode 100644 index 0000000..07f1e62 --- /dev/null +++ b/jeelowcode-admin/src/test/java/com/jeelowcode/test/sql/GenerateLastExecuteSQLTest.java @@ -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 sqlFileList = FileUtil.loopFiles(dateSqlPath); + if (CollUtil.isNotEmpty(sqlFileList)) { + // 将sqlFileList转换成字符串列表,字符串使用文件名,不带后缀 + List 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"); + } + } + } + } + + } + +}