From 781c5f73033ad1ae8c350210c46b4e24925d427b Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期四, 17 九月 2026 17:29:16 +0800
Subject: [PATCH] fix:委托编号更改

---
 basic-server/src/main/java/com/ruoyi/basic/utils/StandardTemplateInspectionItemParser.java |   81 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 81 insertions(+), 0 deletions(-)

diff --git a/basic-server/src/main/java/com/ruoyi/basic/utils/StandardTemplateInspectionItemParser.java b/basic-server/src/main/java/com/ruoyi/basic/utils/StandardTemplateInspectionItemParser.java
new file mode 100644
index 0000000..d2fd833
--- /dev/null
+++ b/basic-server/src/main/java/com/ruoyi/basic/utils/StandardTemplateInspectionItemParser.java
@@ -0,0 +1,81 @@
+package com.ruoyi.basic.utils;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.ruoyi.basic.dto.TemplateInspectionItemDto;
+import com.ruoyi.common.exception.base.BaseException;
+import org.springframework.util.StringUtils;
+
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/** 瑙f瀽 Luckysheet 鍘熷璁板綍妯℃澘涓殑鈥滄楠岄」鈥濇爣璁般�� */
+public final class StandardTemplateInspectionItemParser {
+    private static final String INSPECTION_ITEM_MARK = "妫�楠岄」";
+
+    private StandardTemplateInspectionItemParser() {
+    }
+
+    public static List<TemplateInspectionItemDto> parse(Integer templateId, Integer templateSort, String thing) {
+        if (!StringUtils.hasText(thing)) {
+            throw new BaseException("鍘熷璁板綍妯℃澘鍐呭涓嶈兘涓虹┖");
+        }
+        JSONArray sheets;
+        try {
+            JSONObject root = JSON.parseObject(thing);
+            sheets = root == null ? null : root.getJSONArray("data");
+            if (sheets == null) {
+                sheets = JSON.parseArray(thing);
+            }
+        } catch (Exception e) {
+            throw new BaseException("鍘熷璁板綍妯℃澘鏍煎紡閿欒");
+        }
+        List<TemplateInspectionItemDto> result = new ArrayList<>();
+        Set<Integer> rows = new HashSet<>();
+        if (sheets == null) {
+            throw new BaseException("鍘熷璁板綍妯℃澘鏍煎紡閿欒");
+        }
+        for (Object sheetObject : sheets) {
+            JSONObject sheet = (JSONObject) sheetObject;
+            JSONArray cells = sheet.getJSONArray("celldata");
+            if (cells == null) {
+                continue;
+            }
+            for (Object cellObject : cells) {
+                JSONObject cell = (JSONObject) cellObject;
+                JSONObject value = cell.getJSONObject("v");
+                if (value == null || !isInspectionItem(value)) {
+                    continue;
+                }
+                Integer row = cell.getInteger("r");
+                String item = value.getString("v");
+                if (!StringUtils.hasText(item)) {
+                    item = value.getString("m");
+                }
+                if (row == null || !StringUtils.hasText(item)) {
+                    throw new BaseException("鈥滄楠岄」鈥濇爣璁版墍鍦ㄥ崟鍏冩牸蹇呴』濉啓妫�楠岄」鍚嶇О");
+                }
+                if (!rows.add(row)) {
+                    throw new BaseException("鍚屼竴妯℃澘琛屽彧鑳介厤缃竴涓�滄楠岄」鈥濇爣璁�");
+                }
+                TemplateInspectionItemDto dto = new TemplateInspectionItemDto();
+                dto.setTemplateId(templateId);
+                dto.setTemplateSort(templateSort);
+                dto.setTemplateRowIndex(row);
+                dto.setInspectionItem(item.trim());
+                result.add(dto);
+            }
+        }
+        result.sort(Comparator.comparing(TemplateInspectionItemDto::getTemplateRowIndex));
+        return result;
+    }
+
+    private static boolean isInspectionItem(JSONObject value) {
+        JSONObject ps = value.getJSONObject("ps");
+        return ps != null && INSPECTION_ITEM_MARK.equals(ps.getString("value"));
+    }
+}

--
Gitblit v1.9.3