TASK:AiDA design like sort、moodboardPosition

This commit is contained in:
shahaibo
2025-01-07 17:16:45 +08:00
parent 49b8585522
commit 0b245f62af

View File

@@ -175,11 +175,31 @@ public class CollectionServiceImpl extends ServiceImpl<CollectionMapper, Collect
String styleData = position.getStyleData(); String styleData = position.getStyleData();
int sequence = position.getSequence(); // 获取 sequence 值 int sequence = position.getSequence(); // 获取 sequence 值
// 如果 type 字段为 "class",直接将其作为字符串处理
if ("class".equals(type)) {
// 如果 type 字段还没有对应的 JSONArray则初始化它 // 如果 type 字段还没有对应的 JSONArray则初始化它
if (!resultJson.containsKey(type)) { if (!resultJson.containsKey(type)) {
resultJson.put(type, new ArrayList<>()); resultJson.put(type, new ArrayList<>());
} }
// 获取对应类型的列表
List<String> classList = (List<String>) 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<JSONObject> styleList = (List<JSONObject>) resultJson.get(type); List<JSONObject> styleList = (List<JSONObject>) resultJson.get(type);
@@ -192,9 +212,9 @@ public class CollectionServiceImpl extends ServiceImpl<CollectionMapper, Collect
JSONObject styleObject = JSON.parseObject(styleData); JSONObject styleObject = JSON.parseObject(styleData);
styleList.set(sequence, styleObject); // 根据 sequence 设置数据 styleList.set(sequence, styleObject); // 根据 sequence 设置数据
// 更新回 resultJson
resultJson.put(type, styleList); resultJson.put(type, styleList);
} }
}
// 将最终结果转换为字符串 // 将最终结果转换为字符串
return resultJson.toJSONString(); return resultJson.toJSONString();