|
@@ -127,8 +127,18 @@ public class UnifiedKnowledgeBaseService {
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
try {
|
|
try {
|
|
|
- Map<String, Object> content = objectMapper.readValue(row.getContent(),
|
|
|
|
|
- new TypeReference<Map<String, Object>>() {});
|
|
|
|
|
|
|
+ Object parsed = objectMapper.readValue(row.getContent(), Object.class);
|
|
|
|
|
+ Map<String, Object> content;
|
|
|
|
|
+ if (parsed instanceof Map) {
|
|
|
|
|
+ content = (Map<String, Object>) parsed;
|
|
|
|
|
+ } else if (parsed instanceof List) {
|
|
|
|
|
+ // 兼容菌属-食材映射等顶层为数组的模块(包装为 {"_list": list})
|
|
|
|
|
+ content = new java.util.LinkedHashMap<>();
|
|
|
|
|
+ content.put("_list", parsed);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ content = new java.util.LinkedHashMap<>();
|
|
|
|
|
+ content.put("_value", parsed);
|
|
|
|
|
+ }
|
|
|
sectionMap.put(row.getModuleKey(), content);
|
|
sectionMap.put(row.getModuleKey(), content);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
log.warn("解析模块[{}]内容失败: {}", row.getModuleKey(), e.getMessage());
|
|
log.warn("解析模块[{}]内容失败: {}", row.getModuleKey(), e.getMessage());
|
|
@@ -345,9 +355,19 @@ public class UnifiedKnowledgeBaseService {
|
|
|
|
|
|
|
|
// --- 菌属-食材映射: [{拉丁名, 中文名, 分组, 功能分类, 功能说明, ...}] ---
|
|
// --- 菌属-食材映射: [{拉丁名, 中文名, 分组, 功能分类, 功能说明, ...}] ---
|
|
|
Object mapping = sectionMap.get("菌属-食材映射");
|
|
Object mapping = sectionMap.get("菌属-食材映射");
|
|
|
|
|
+ List<Object> mappingList = null;
|
|
|
if (mapping instanceof List) {
|
|
if (mapping instanceof List) {
|
|
|
|
|
+ mappingList = (List<Object>) mapping;
|
|
|
|
|
+ } else if (mapping instanceof Map) {
|
|
|
|
|
+ // 兼容 DB 顶层为 Map 但实际数据在 _list 键下的情况
|
|
|
|
|
+ Object inner = ((Map<String, Object>) mapping).get("_list");
|
|
|
|
|
+ if (inner instanceof List) {
|
|
|
|
|
+ mappingList = (List<Object>) inner;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (mappingList != null) {
|
|
|
List<Map<String, Object>> list = new ArrayList<>();
|
|
List<Map<String, Object>> list = new ArrayList<>();
|
|
|
- for (Object item : (List<Object>) mapping) {
|
|
|
|
|
|
|
+ for (Object item : mappingList) {
|
|
|
if (item instanceof Map) {
|
|
if (item instanceof Map) {
|
|
|
list.add((Map<String, Object>) item);
|
|
list.add((Map<String, Object>) item);
|
|
|
}
|
|
}
|