第81批紧急修复:removeRootLevelDuplicates硬编码bug导致供应商.json被清空+供应商.json特殊处理
Auto Release / build (push) Successful in 2m16s
Auto Release / build (push) Successful in 2m16s
This commit is contained in:
@@ -1558,7 +1558,25 @@ public class ConfigManager {
|
|||||||
String label = "通用模板:" + name;
|
String label = "通用模板:" + name;
|
||||||
String lower = name.toLowerCase(Locale.ROOT);
|
String lower = name.toLowerCase(Locale.ROOT);
|
||||||
boolean ok;
|
boolean ok;
|
||||||
if (lower.endsWith(".md")) {
|
// ★ 第81批:供应商.json 结构特殊(嵌套键名→URL字符串,非同构对象),
|
||||||
|
// upgradeJsonMissing 的递归补键逻辑会把它搞坏(空对象+写回空对象)。
|
||||||
|
// 这里特殊处理:如果原文件解析后键数 < 模板键数,直接用模板覆盖。
|
||||||
|
if (lower.endsWith(".json") && name.contains("供应商")) {
|
||||||
|
com.google.gson.JsonElement tplEl2 = com.google.gson.JsonParser.parseString(
|
||||||
|
new String(tpl, StandardCharsets.UTF_8));
|
||||||
|
com.google.gson.JsonElement curEl2 = com.google.gson.JsonParser.parseString(
|
||||||
|
new String(cur, StandardCharsets.UTF_8));
|
||||||
|
int tplKeyCount = tplEl2.isJsonObject() ? tplEl2.getAsJsonObject().size() : 0;
|
||||||
|
int curKeyCount = curEl2.isJsonObject() ? curEl2.getAsJsonObject().size() : 0;
|
||||||
|
if (curKeyCount < tplKeyCount) {
|
||||||
|
java.nio.file.Files.write(target.toPath(), tpl);
|
||||||
|
logger.info("[" + label + "] 原文件键数(" + curKeyCount + ") < 模板(" + tplKeyCount + "),直接用模板覆盖");
|
||||||
|
upgraded++;
|
||||||
|
ok = true;
|
||||||
|
} else {
|
||||||
|
ok = upgradeJsonMissing(target, tpl, label);
|
||||||
|
}
|
||||||
|
} else if (lower.endsWith(".md")) {
|
||||||
ok = safeUpgradeDoc(target, readUtf8Lines(tpl), label);
|
ok = safeUpgradeDoc(target, readUtf8Lines(tpl), label);
|
||||||
} else if (lower.endsWith(".json")) {
|
} else if (lower.endsWith(".json")) {
|
||||||
ok = upgradeJsonMissing(target, tpl, label);
|
ok = upgradeJsonMissing(target, tpl, label);
|
||||||
@@ -1651,7 +1669,7 @@ public class ConfigManager {
|
|||||||
com.google.gson.JsonObject root = oldEl.getAsJsonObject();
|
com.google.gson.JsonObject root = oldEl.getAsJsonObject();
|
||||||
List<String> added = new ArrayList<>();
|
List<String> added = new ArrayList<>();
|
||||||
boolean merged = mergeJsonMissing(root, tplEl.getAsJsonObject(), "", added);
|
boolean merged = mergeJsonMissing(root, tplEl.getAsJsonObject(), "", added);
|
||||||
boolean cleaned = removeRootLevelDuplicates(root);
|
boolean cleaned = removeRootLevelDuplicates(root, tplEl.getAsJsonObject());
|
||||||
boolean reordered = reorderToTemplateOrder(root, tplEl.getAsJsonObject());
|
boolean reordered = reorderToTemplateOrder(root, tplEl.getAsJsonObject());
|
||||||
if (!merged && !cleaned && !reordered) {
|
if (!merged && !cleaned && !reordered) {
|
||||||
return false; // 无缺失键、无多余键、顺序一致,幂等
|
return false; // 无缺失键、无多余键、顺序一致,幂等
|
||||||
@@ -1701,25 +1719,26 @@ public class ConfigManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ★ 第77批-后续修复:清理根级多余键。
|
* ★ 第77批-后续修复 + 第81批修复bug:清理根级多余键。
|
||||||
* <p>
|
* <p>
|
||||||
* 历史同步 bug 导致某些本应嵌套在 配置部分.2 内的键
|
* 第77批:历史同步 bug 导致某些本应嵌套在 配置部分.2 内的键
|
||||||
* (如 填写规范、配置填写示例)被误加到 JSON 根级,
|
* (如 填写规范、配置填写示例)被误加到 models.json 根级,造成键值重复。
|
||||||
* 造成键值重复(29对括号 vs 模板21对)。
|
|
||||||
* <p>
|
* <p>
|
||||||
* 此方法删除根级中模板不存在的键——模板根级只有
|
* ★ 第81批修复:第77批硬编码了「人设部分/配置部分」两个键名,
|
||||||
* 「人设部分」和「配置部分」,任何其他根级键都是误加的。
|
* 对供应商.json 这种根级键名不同的配置文件,会把所有键都删掉 → 清空成 {}。
|
||||||
|
* 改为通用逻辑:只删除模板里没有的根级键(传入 tpl 做键集合对比)。
|
||||||
*/
|
*/
|
||||||
private boolean removeRootLevelDuplicates(com.google.gson.JsonObject root) {
|
private boolean removeRootLevelDuplicates(com.google.gson.JsonObject root,
|
||||||
|
com.google.gson.JsonObject tpl) {
|
||||||
List<String> toRemove = new ArrayList<>();
|
List<String> toRemove = new ArrayList<>();
|
||||||
for (String key : root.keySet()) {
|
for (String key : root.keySet()) {
|
||||||
if (!key.equals("人设部分") && !key.equals("配置部分")) {
|
if (!tpl.has(key)) {
|
||||||
toRemove.add(key);
|
toRemove.add(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (String key : toRemove) {
|
for (String key : toRemove) {
|
||||||
root.remove(key);
|
root.remove(key);
|
||||||
logger.info("[配置升级] 清理根级多余键: " + key + "(应存在于配置部分.2 内)");
|
logger.info("[配置升级] 清理根级多余键: " + key + "(模板根级无此键)");
|
||||||
}
|
}
|
||||||
return !toRemove.isEmpty();
|
return !toRemove.isEmpty();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user