Przeglądaj źródła

fix(pdf): 修复Illustration字段数据类型处理问题

- 添加对JSONArray和String类型Illustration数据的支持
- 实现类型安全的数据解析避免ClassCastException
- 添加对无效格式数据的日志记录和异常处理
- 确保只有有效的JSONArray数据才会被处理
- 提高代码的健壮性和错误处理能力
xuzhancheng 1 tydzień temu
rodzic
commit
f86f0a0fe7

+ 14 - 3
src/main/java/com/grapecity/controller/GrapeCityController.java

@@ -159,9 +159,20 @@ public class GrapeCityController {
         // 这里可以添加收集浮动图片的逻辑,如果需要的话
         // 目前 pdf 方法中有处理 Illustration 字段,但 filePath 可能不需要
         if (data.get("Illustration") != null) {
-            String illustration = (String) data.get("Illustration");
-            if (illustration.startsWith("[") && illustration.endsWith("]")) {
-                JSONArray jsonArray = JSON.parseArray(illustration);
+            Object illustrationObj = data.get("Illustration");
+            JSONArray jsonArray;
+
+            // 处理不同类型的 Illustration 数据
+            if (illustrationObj instanceof JSONArray arr) {
+                jsonArray = arr;
+            } else if (illustrationObj instanceof String str && str.trim().startsWith("[")) {
+                jsonArray = JSON.parseArray(str);
+            } else {
+                logger.warn("Illustration 字段格式不正确:{}", illustrationObj.getClass().getName());
+                return;
+            }
+
+            if (jsonArray != null) {
                 List<JSONObject> list = new ArrayList<>();
                 for (int k = 0; k < jsonArray.size(); k++) {
                     JSONObject jsonObject = jsonArray.getJSONObject(k);