|
@@ -0,0 +1,105 @@
|
|
|
|
|
+import com.google.gson.JsonArray;
|
|
|
|
|
+import com.google.gson.JsonElement;
|
|
|
|
|
+import com.google.gson.JsonObject;
|
|
|
|
|
+import com.google.gson.JsonParser;
|
|
|
|
|
+
|
|
|
|
|
+import java.sql.Connection;
|
|
|
|
|
+import java.sql.DriverManager;
|
|
|
|
|
+import java.sql.PreparedStatement;
|
|
|
|
|
+import java.sql.ResultSet;
|
|
|
|
|
+import java.util.LinkedHashMap;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 正式发布专用 GW.FWC 增量合并工具。
|
|
|
|
|
+ *
|
|
|
|
|
+ * 仅向 bjpj 数组追加缺失服务,不重写其他模块。
|
|
|
|
|
+ */
|
|
|
|
|
+public class MergeFwc20261029 {
|
|
|
|
|
+ private static final Map<Long, List<String>> SERVICES = new LinkedHashMap<>();
|
|
|
|
|
+
|
|
|
|
|
+ static {
|
|
|
|
|
+ SERVICES.put(1015263L, List.of(
|
|
|
|
|
+ "xxwjjl", "xxwjjl_ck", "xxwjjl_lr",
|
|
|
|
|
+ "ssnwjc_mpList",
|
|
|
|
|
+ "bjStarClass_mpInit", "bjStarClass_mpSummary",
|
|
|
|
|
+ "bjStarClass_mpDay", "bjStarClass_mpDetail"
|
|
|
|
|
+ ));
|
|
|
|
|
+ SERVICES.put(102121L, List.of(
|
|
|
|
|
+ "cswsjc", "cswsjc_ck", "cswsjc_lr",
|
|
|
|
|
+ "sswjjl", "sswjjl_ck", "sswjjl_lr",
|
|
|
|
|
+ "xxwjjl", "xxwjjl_ck", "xxwjjl_lr",
|
|
|
|
|
+ "xxhjjl", "xxhjjl_ck", "xxhjjl_lr"
|
|
|
|
|
+ ));
|
|
|
|
|
+ SERVICES.put(1015484L, List.of(
|
|
|
|
|
+ "cswsjc", "cswsjc_ck", "cswsjc_lr",
|
|
|
|
|
+ "sswjjl", "sswjjl_ck", "sswjjl_lr",
|
|
|
|
|
+ "xxwjjl", "xxwjjl_ck", "xxwjjl_lr",
|
|
|
|
|
+ "xxhjjl", "xxhjjl_ck", "xxhjjl_lr"
|
|
|
|
|
+ ));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static void main(String[] args) throws Exception {
|
|
|
|
|
+ String url = requiredEnv("DB_URL");
|
|
|
|
|
+ String user = requiredEnv("DB_USER");
|
|
|
|
|
+ String password = requiredEnv("DB_PASSWORD");
|
|
|
|
|
+ try (Connection conn = DriverManager.getConnection(url, user, password)) {
|
|
|
|
|
+ conn.setAutoCommit(false);
|
|
|
|
|
+ for (Map.Entry<Long, List<String>> entry : SERVICES.entrySet()) {
|
|
|
|
|
+ merge(conn, entry.getKey(), entry.getValue());
|
|
|
|
|
+ }
|
|
|
|
|
+ conn.commit();
|
|
|
|
|
+ System.out.println("FWC_MERGE_OK");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static void merge(Connection conn, long gwid, List<String> services)
|
|
|
|
|
+ throws Exception {
|
|
|
|
|
+ String fwc;
|
|
|
|
|
+ try (PreparedStatement ps = conn.prepareStatement(
|
|
|
|
|
+ "select FWC from GW where GWID=? for update")) {
|
|
|
|
|
+ ps.setLong(1, gwid);
|
|
|
|
|
+ try (ResultSet rs = ps.executeQuery()) {
|
|
|
|
|
+ if (!rs.next() || rs.getString(1) == null) {
|
|
|
|
|
+ throw new IllegalStateException("GW.FWC 为空:" + gwid);
|
|
|
|
|
+ }
|
|
|
|
|
+ fwc = rs.getString(1);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ JsonObject root = JsonParser.parseString(fwc).getAsJsonObject();
|
|
|
|
|
+ JsonArray bjpj = root.has("bjpj") && root.get("bjpj").isJsonArray()
|
|
|
|
|
+ ? root.getAsJsonArray("bjpj") : new JsonArray();
|
|
|
|
|
+ for (String service : services) {
|
|
|
|
|
+ boolean exists = false;
|
|
|
|
|
+ for (JsonElement item : bjpj) {
|
|
|
|
|
+ if (service.equals(item.getAsString())) {
|
|
|
|
|
+ exists = true;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!exists) {
|
|
|
|
|
+ bjpj.add(service);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ root.add("bjpj", bjpj);
|
|
|
|
|
+
|
|
|
|
|
+ try (PreparedStatement ps = conn.prepareStatement(
|
|
|
|
|
+ "update GW set FWC=? where GWID=?")) {
|
|
|
|
|
+ ps.setString(1, root.toString());
|
|
|
|
|
+ ps.setLong(2, gwid);
|
|
|
|
|
+ if (ps.executeUpdate() != 1) {
|
|
|
|
|
+ throw new IllegalStateException("GW 更新行数异常:" + gwid);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static String requiredEnv(String name) {
|
|
|
|
|
+ String value = System.getenv(name);
|
|
|
|
|
+ if (value == null || value.isBlank()) {
|
|
|
|
|
+ throw new IllegalStateException("缺少环境变量:" + name);
|
|
|
|
|
+ }
|
|
|
|
|
+ return value;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|