41 lines
2.2 KiB
Java
41 lines
2.2 KiB
Java
|
|||
|
|
import java.io.File;
|
||
|
|
import java.nio.file.Files;
|
||
|
|
import java.sql.*;
|
||
|
|
|
||
|
|
public class VerifyDbIntegrity {
|
||
|
|
public static void main(String[] args) throws Exception {
|
||
|
|
Class.forName("com.kingbase8.Driver");
|
||
|
|
File yml = new File("RuoYi-Vue/ruoyi-admin/src/main/resources/application-druid.yml");
|
||
|
|
String pass = "";
|
||
|
|
for (String line : Files.readAllLines(yml.toPath())) {
|
||
|
|
if (line.trim().startsWith("password:")) pass = line.trim().substring("password:".length()).trim();
|
||
|
|
}
|
||
|
|
try (Connection conn = DriverManager.getConnection("jdbc:kingbase8://127.0.0.1:4321/railwaysystem_integrated_qa_20260916?useUnicode=true&characterEncoding=utf8", "kingbase", pass)) {
|
||
|
|
// 1. Check orphan enrollments
|
||
|
|
int orphanEnrollments = 0;
|
||
|
|
try (Statement st = conn.createStatement();
|
||
|
|
ResultSet rs = st.executeQuery("SELECT count(*) FROM public.train_enrollment e WHERE NOT EXISTS (SELECT 1 FROM public.train_class_plan p WHERE p.plan_id = e.plan_id)")) {
|
||
|
|
if (rs.next()) orphanEnrollments = rs.getInt(1);
|
||
|
|
}
|
||
|
|
|
||
|
|
// 2. Check active accommodation duplicate count
|
||
|
|
int activeDup = 0;
|
||
|
|
try (Statement st = conn.createStatement();
|
||
|
|
ResultSet rs = st.executeQuery("SELECT enrollment_id, count(*) FROM public.train_accommodation WHERE accommodation_status = 1 GROUP BY enrollment_id HAVING count(*) > 1")) {
|
||
|
|
while (rs.next()) activeDup++;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 3. Check operation idempotency violation
|
||
|
|
int idempDup = 0;
|
||
|
|
try (Statement st = conn.createStatement();
|
||
|
|
ResultSet rs = st.executeQuery("SELECT door_auth_id, operation_type, count(*) FROM public.train_external_operation GROUP BY door_auth_id, operation_type HAVING count(*) > 1")) {
|
||
|
|
while (rs.next()) idempDup++;
|
||
|
|
}
|
||
|
|
|
||
|
|
System.out.println("ORPHAN_COUNT=" + orphanEnrollments);
|
||
|
|
System.out.println("ACTIVE_ACCOMMODATION_DUPLICATE_COUNT=" + activeDup);
|
||
|
|
System.out.println("DMS_OPERATION_IDEMPOTENCY_VIOLATION=" + idempDup);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|