|
@@ -29,9 +29,21 @@ public class TeamImportRunner {
|
|
|
private static final long TEACHER_ID = 111148350L;
|
|
private static final long TEACHER_ID = 111148350L;
|
|
|
private static final String EFFECTIVE_DATE = "2026-11-01";
|
|
private static final String EFFECTIVE_DATE = "2026-11-01";
|
|
|
private static final String SCHOOL_YEAR = "2026-2027";
|
|
private static final String SCHOOL_YEAR = "2026-2027";
|
|
|
|
|
+ private static final Set<String> ALLOWED_SCHEMAS =
|
|
|
|
|
+ Set.of("PMS_TEST", "C##DC");
|
|
|
|
|
|
|
|
public static String run(Db db, String groupFile, String memberFile,
|
|
public static String run(Db db, String groupFile, String memberFile,
|
|
|
String batchId, boolean execute) throws Exception {
|
|
String batchId, boolean execute) throws Exception {
|
|
|
|
|
+ return run(db, groupFile, memberFile, batchId, execute, "PMS_TEST");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static String run(Db db, String groupFile, String memberFile,
|
|
|
|
|
+ String batchId, boolean execute,
|
|
|
|
|
+ String expectedSchema) throws Exception {
|
|
|
|
|
+ if (!ALLOWED_SCHEMAS.contains(expectedSchema))
|
|
|
|
|
+ throw new IllegalArgumentException(
|
|
|
|
|
+ "unsupported schema: " + expectedSchema);
|
|
|
|
|
+
|
|
|
List<GroupRow> groups = rdGroups(Path.of(groupFile));
|
|
List<GroupRow> groups = rdGroups(Path.of(groupFile));
|
|
|
List<MemberRow> members = rdMembers(Path.of(memberFile), groups);
|
|
List<MemberRow> members = rdMembers(Path.of(memberFile), groups);
|
|
|
validate(groups, members);
|
|
validate(groups, members);
|
|
@@ -40,23 +52,45 @@ public class TeamImportRunner {
|
|
|
report.append("mode=").append(execute ? "EXECUTE" : "DRY_RUN")
|
|
report.append("mode=").append(execute ? "EXECUTE" : "DRY_RUN")
|
|
|
.append('\n');
|
|
.append('\n');
|
|
|
report.append("batch=").append(batchId).append('\n');
|
|
report.append("batch=").append(batchId).append('\n');
|
|
|
|
|
+ report.append("schema=").append(expectedSchema).append('\n');
|
|
|
report.append("TT=").append(groups.size()).append('\n');
|
|
report.append("TT=").append(groups.size()).append('\n');
|
|
|
report.append("TTCY=").append(members.size()).append('\n');
|
|
report.append("TTCY=").append(members.size()).append('\n');
|
|
|
report.append("TTWCY=").append(members.stream()
|
|
report.append("TTWCY=").append(members.stream()
|
|
|
.filter(row -> row.memberTable.equals("TTWCY")).count())
|
|
.filter(row -> row.memberTable.equals("TTWCY")).count())
|
|
|
.append('\n');
|
|
.append('\n');
|
|
|
|
|
|
|
|
- if (!execute) {
|
|
|
|
|
- report.append("DRY_RUN_OK\n");
|
|
|
|
|
- return report.toString();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
Field connField = Db.class.getDeclaredField("conn");
|
|
Field connField = Db.class.getDeclaredField("conn");
|
|
|
connField.setAccessible(true);
|
|
connField.setAccessible(true);
|
|
|
Connection connection = (Connection) connField.get(db);
|
|
Connection connection = (Connection) connField.get(db);
|
|
|
String user = scalarString(connection, "select user from dual");
|
|
String user = scalarString(connection, "select user from dual");
|
|
|
- if (!"PMS_TEST".equals(user)) {
|
|
|
|
|
- throw new IllegalStateException("refusing import: current user is " + user);
|
|
|
|
|
|
|
+ if (!expectedSchema.equals(user)) {
|
|
|
|
|
+ throw new IllegalStateException("refusing import: expected schema "
|
|
|
|
|
+ + expectedSchema + ", current user is " + user);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!execute) {
|
|
|
|
|
+ report.append("columns=")
|
|
|
|
|
+ .append(importColumnCount(connection)).append('\n');
|
|
|
|
|
+ int existingGroups = 0;
|
|
|
|
|
+ for (GroupRow group : groups) {
|
|
|
|
|
+ if (findGroup(connection, group) > 0)
|
|
|
|
|
+ existingGroups++;
|
|
|
|
|
+ }
|
|
|
|
|
+ report.append("existingGroups=")
|
|
|
|
|
+ .append(existingGroups).append('\n');
|
|
|
|
|
+ if (count(connection,
|
|
|
|
|
+ "select count(*) from user_tables where table_name=?",
|
|
|
|
|
+ "XJB_TT_IMPORT_BATCH") > 0) {
|
|
|
|
|
+ report.append("batchExists=")
|
|
|
|
|
+ .append(count(connection,
|
|
|
|
|
+ "select count(*) from XJB_TT_IMPORT_BATCH "
|
|
|
|
|
+ + "where IMPORT_BATCH_ID=?", batchId))
|
|
|
|
|
+ .append('\n');
|
|
|
|
|
+ } else {
|
|
|
|
|
+ report.append("batchExists=table_missing\n");
|
|
|
|
|
+ }
|
|
|
|
|
+ report.append("DRY_RUN_OK\n");
|
|
|
|
|
+ return report.toString();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ensureImportTables(connection);
|
|
ensureImportTables(connection);
|
|
@@ -209,6 +243,16 @@ public class TeamImportRunner {
|
|
|
"create sequence XJB_TT_IMPORT_MAP_SEQ start with 1 increment by 1");
|
|
"create sequence XJB_TT_IMPORT_MAP_SEQ start with 1 increment by 1");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private static int importColumnCount(Connection connection)
|
|
|
|
|
+ throws Exception {
|
|
|
|
|
+ return (int) scalarLong(connection,
|
|
|
|
|
+ "select count(*) from user_tab_columns "
|
|
|
|
|
+ + "where (table_name in ('TT','TTCY') "
|
|
|
|
|
+ + "and column_name in ('KSRQ','JSRQ','XNDM')) "
|
|
|
|
|
+ + "or (table_name='TTWCY' "
|
|
|
|
|
+ + "and column_name in ('ZWMC','KSRQ','JSRQ','XNDM'))");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private static void backupTables(
|
|
private static void backupTables(
|
|
|
Connection connection, StringBuilder report) throws Exception {
|
|
Connection connection, StringBuilder report) throws Exception {
|
|
|
for (String table : List.of("TT", "TTCY", "TTWCY")) {
|
|
for (String table : List.of("TT", "TTCY", "TTWCY")) {
|