20260914223013

This commit is contained in:
oneao committed 2026-09-14 22:30:13 +08:00
1 parent 549c8bd2eb
commit 63514476d7
60 files changed
+6478 -2004

No files matched your search

@@ -13,6 +13,7 @@ import java.util.*;
* s_columnLib.col_TableName = s_module.b_view_table
* s_columnLib.col_FieldName = s_field.b_field
* 两侧用 Chinese_PRC_CI_AS 比较,兼容 v_b_OtherCompany 这类大小写差异。
* 重命名字段走别名映射(b_vessel_name → b_name、b_name_c → b_name,见 FIELD_ALIAS)。
*
* 列表/表单的成员资格沿用旧库语义:旧库标志为 '1' 的字段才进入对应配置,
* 其余字段(标志为 '0'、空、无记录)**直接不写入 JSON**,不写 visible:false。
@@ -32,6 +33,7 @@ import java.util.*;
* --dry-run 只报告不写库
* --skip-schema 只同步 s_field.b_name,不重建 s_module_schema
* --force 允许覆盖已存在且非空的 s_module_schema 行
* --all-otherdata 批量模式:同步 base_otherdata 下所有数据模块(不需要位置参数,失败跳过继续)
*/
public class FieldNameSync {
@@ -43,6 +45,8 @@ public class FieldNameSync {
boolean dryRun = false;
boolean skipSchema = false;
boolean force = false;
boolean allOtherData = false;
boolean batchMode = false; // 批量子任务:出错抛异常交给批量汇总,而不是 System.exit
String moduleId;
String oldTableOverride;
@@ -70,6 +74,14 @@ public class FieldNameSync {
Integer editPosition; // col_edit_position
}
/**
* 旧库字段名 → 新系统字段名。
* 表设计里做过重命名的字段:b_vessel_name → b_name(船名)、b_name_c → b_name(中文名)。
*/
private static final Map<String, String> FIELD_ALIAS = Map.of(
"b_vessel_name", "b_name",
"b_name_c", "b_name");
// ------------------------------------------------------------------ SQL
static final String QUERY_MODULE = """
SELECT b_id, b_view_table, b_name, b_module_type
@@ -117,7 +129,45 @@ public class FieldNameSync {
public static void main(String[] args) throws Exception {
FieldNameSync tool = new FieldNameSync();
tool.parseArgs(args);
tool.run();
if (tool.allOtherData) {
tool.runBatch();
} else {
tool.run();
}
}
/** 批量:同步 base_otherdata 下所有数据模块;每个模块独立事务,失败跳过并继续 */
void runBatch() throws SQLException {
List<String> ids = new ArrayList<>();
try (Connection c = DriverManager.getConnection(URL, USER, PASSWORD);
PreparedStatement ps = c.prepareStatement(
"SELECT b_id FROM dbo.s_module WHERE b_path LIKE '/base/base_otherdata/%' "
+ "AND b_module_type = 'data' ORDER BY b_xh, b_id");
ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
ids.add(rs.getString(1));
}
}
System.out.println("批量同步 " + ids.size() + " 个模块(base_otherdata)" + (dryRun ? "[dry-run]" : "") + "\n");
int ok = 0;
int failed = 0;
for (String id : ids) {
FieldNameSync one = new FieldNameSync();
one.dryRun = dryRun;
one.skipSchema = skipSchema;
one.force = force;
one.batchMode = true;
one.moduleId = id;
try {
one.run();
ok++;
} catch (Exception e) {
failed++;
System.err.println("[失败] " + id + ": " + e.getMessage());
}
}
System.out.println("\n批量完成:成功 " + ok + " 个,失败 " + failed + " 个");
}
void parseArgs(String[] args) {
@@ -128,6 +178,7 @@ public class FieldNameSync {
case "--dry-run" -> dryRun = true;
case "--skip-schema" -> skipSchema = true;
case "--force" -> force = true;
case "--all-otherdata" -> allOtherData = true;
default -> {
if (arg.startsWith("--")) {
System.err.println("未知选项: " + arg);
@@ -139,8 +190,11 @@ public class FieldNameSync {
}
}
if (positional.isEmpty()) {
usage();
System.exit(1);
if (!allOtherData) {
usage();
System.exit(1);
}
return;
}
moduleId = positional.get(0);
if (positional.size() > 1) oldTableOverride = positional.get(1);
@@ -153,6 +207,7 @@ public class FieldNameSync {
static void usage() {
System.err.println("用法: java FieldNameSync <moduleId> [oldTableName] [--dry-run] [--skip-schema] [--force]");
System.err.println(" java FieldNameSync --all-otherdata [--dry-run] [--force] 批量同步 base_otherdata 下所有数据模块");
}
void run() throws SQLException {
@@ -203,6 +258,9 @@ public class FieldNameSync {
}
} catch (Exception e) {
conn.rollback();
if (batchMode) {
throw new SQLException(e.getMessage(), e);
}
System.err.println("\n[错误] " + e.getMessage());
System.exit(1);
}
@@ -268,7 +326,8 @@ public class FieldNameSync {
col.width = intOrNull(rs, "col_Width");
col.position = intOrNull(rs, "col_Position");
col.editPosition = intOrNull(rs, "col_edit_position");
oldColumns.put(trim(rs.getString("col_FieldName")), col);
String fieldName = trim(rs.getString("col_FieldName"));
oldColumns.put(FIELD_ALIAS.getOrDefault(fieldName.toLowerCase(Locale.ROOT), fieldName), col);
}
}
}
@@ -349,10 +408,27 @@ public class FieldNameSync {
return updated;
}
/** view 配置:{"schemaVersion":1,"columns":[{"field":..,"width":..}]},只含旧库 col_Visible='1' 的字段 */
/** 备注列统一排到最后(其他数据字典表的展示习惯) */
private static void moveBzLast(List<Field> list) {
Field bz = null;
for (Iterator<Field> iterator = list.iterator(); iterator.hasNext(); ) {
Field field = iterator.next();
if ("b_bz".equalsIgnoreCase(field.name)) {
bz = field;
iterator.remove();
break;
}
}
if (bz != null) {
list.add(bz);
}
}
/** view 配置:{"schemaVersion":1,"columns":[{"field":..,"width":..}]},只含旧库 col_Visible='1' 的字段;备注列固定排最后 */
String buildViewJson() {
StringBuilder sb = new StringBuilder("{\"schemaVersion\":1,\"columns\":[");
List<Field> list = includedFields("view");
List<Field> list = new ArrayList<>(includedFields("view"));
moveBzLast(list);
for (int i = 0; i < list.size(); i++) {
Field f = list.get(i);
if (i > 0) sb.append(',');
@@ -364,10 +440,11 @@ public class FieldNameSync {
return sb.append("]}").toString();
}
/** edit 配置:{"schemaVersion":1,"children":[{"field":..,"span":24}]},只含旧库 col_edit='1' 的字段 */
/** edit 配置:{"schemaVersion":1,"children":[{"field":..,"span":24}]},只含旧库 col_edit='1' 的字段;备注列固定排最后 */
String buildEditJson() {
StringBuilder sb = new StringBuilder("{\"schemaVersion\":1,\"children\":[");
List<Field> list = includedFields("edit");
List<Field> list = new ArrayList<>(includedFields("edit"));
moveBzLast(list);
for (int i = 0; i < list.size(); i++) {
Field f = list.get(i);
if (i > 0) sb.append(',');