From 0b245f62afecbb67366202ea94b52ea552f7bdb3 Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Tue, 7 Jan 2025 17:16:45 +0800 Subject: [PATCH] =?UTF-8?q?TASK:AiDA=20design=20like=20sort=E3=80=81moodbo?= =?UTF-8?q?ardPosition?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/CollectionServiceImpl.java | 56 +++++++++++++------ 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/ai/da/service/impl/CollectionServiceImpl.java b/src/main/java/com/ai/da/service/impl/CollectionServiceImpl.java index 90e299e2..9c6fdf93 100644 --- a/src/main/java/com/ai/da/service/impl/CollectionServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/CollectionServiceImpl.java @@ -175,25 +175,45 @@ public class CollectionServiceImpl extends ServiceImpl()); + // 如果 type 字段为 "class",直接将其作为字符串处理 + if ("class".equals(type)) { + // 如果 type 字段还没有对应的 JSONArray,则初始化它 + if (!resultJson.containsKey(type)) { + resultJson.put(type, new ArrayList<>()); + } + + // 获取对应类型的列表 + List classList = (List) resultJson.get(type); + + // 确保列表长度足够,可以容纳 `sequence` 索引 + while (classList.size() <= sequence) { + classList.add(""); // 添加空字符串,直到长度大于 `sequence` + } + + // 将 class 字段直接存入列表 + classList.set(sequence, styleData); // 根据 sequence 设置数据 + + resultJson.put(type, classList); + } else { + // 如果 type 字段为其他类型,按照正常方式处理 + if (!resultJson.containsKey(type)) { + resultJson.put(type, new ArrayList<>()); + } + + // 获取对应类型的列表 + List styleList = (List) resultJson.get(type); + + // 确保列表长度足够,可以容纳 `sequence` 索引 + while (styleList.size() <= sequence) { + styleList.add(new JSONObject()); // 添加空的 JSONObject,直到长度大于 `sequence` + } + + // 将解析的样式数据存入正确的索引位置 + JSONObject styleObject = JSON.parseObject(styleData); + styleList.set(sequence, styleObject); // 根据 sequence 设置数据 + + resultJson.put(type, styleList); } - - // 获取对应类型的列表 - List styleList = (List) resultJson.get(type); - - // 确保列表长度足够,可以容纳 `sequence` 索引 - while (styleList.size() <= sequence) { - styleList.add(new JSONObject()); // 添加空的 JSONObject,直到长度大于 `sequence` - } - - // 将解析的样式数据存入正确的索引位置 - JSONObject styleObject = JSON.parseObject(styleData); - styleList.set(sequence, styleObject); // 根据 sequence 设置数据 - - // 更新回 resultJson - resultJson.put(type, styleList); } // 将最终结果转换为字符串