From cb44316d3975af52a3a9af824094b844dd7df874 Mon Sep 17 00:00:00 2001
From: longz <longzhaoz@qq.com>
Date: 星期二, 26 五月 2026 11:34:49 +0800
Subject: [PATCH] fix

---
 backend/src/main/java/com/sinata/appointment/service/ApprovalFlowViewApplicationService.java |   88 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 87 insertions(+), 1 deletions(-)

diff --git a/backend/src/main/java/com/sinata/appointment/service/ApprovalFlowViewApplicationService.java b/backend/src/main/java/com/sinata/appointment/service/ApprovalFlowViewApplicationService.java
index 24e1f0e..d09f696 100644
--- a/backend/src/main/java/com/sinata/appointment/service/ApprovalFlowViewApplicationService.java
+++ b/backend/src/main/java/com/sinata/appointment/service/ApprovalFlowViewApplicationService.java
@@ -13,6 +13,7 @@
 import com.sinata.appointment.entity.ApprovalInstance;
 import com.sinata.appointment.entity.ApprovalTask;
 import com.sinata.appointment.entity.BizApprovalNodeConfig;
+import com.sinata.appointment.entity.MpPassLocalUnit;
 import com.sinata.appointment.entity.MpStaffGroup;
 import com.sinata.appointment.entity.MpUser;
 import com.sinata.appointment.entity.SysDept;
@@ -20,6 +21,7 @@
 import com.sinata.appointment.mapper.ApprovalInstanceMapper;
 import com.sinata.appointment.mapper.ApprovalTaskMapper;
 import com.sinata.appointment.mapper.BizApprovalNodeConfigMapper;
+import com.sinata.appointment.mapper.MpPassLocalUnitMapper;
 import com.sinata.appointment.mapper.MpStaffGroupMapper;
 import com.sinata.appointment.mapper.MpUserMapper;
 import com.sinata.appointment.mapper.SysDeptMapper;
@@ -41,6 +43,7 @@
 public class ApprovalFlowViewApplicationService {
 
     private static final TypeReference<List<String>> STRING_LIST_TYPE = new TypeReference<>() {};
+    private static final TypeReference<List<Long>> LONG_LIST_TYPE = new TypeReference<>() {};
 
     private final ApprovalInstanceMapper approvalInstanceMapper;
     private final ApprovalTaskMapper approvalTaskMapper;
@@ -49,6 +52,7 @@
     private final MpUserMapper mpUserMapper;
     private final SysDeptMapper sysDeptMapper;
     private final MpStaffGroupMapper mpStaffGroupMapper;
+    private final MpPassLocalUnitMapper mpPassLocalUnitMapper;
     private final ObjectMapper objectMapper;
 
     public List<ApprovalFlowNodeVo> treeByOrderId(Long orderId) {
@@ -83,6 +87,7 @@
         Map<Long, String> deptNameMap = loadDeptNameMap(tasks);
         Map<Long, String> staffGroupNameMap = loadStaffGroupNameMap(tasks);
         List<String> localUnitNames = parseStringList(order == null ? null : order.getPassLocalUnitNames());
+        Map<Long, String> localUnitNameMap = loadLocalUnitNameMap(order, tasks);
 
         LinkedHashMap<String, LinkedHashMap<String, List<ApprovalTask>>> byNode = new LinkedHashMap<>();
         for (ApprovalTask t : tasks) {
@@ -104,7 +109,15 @@
                 List<ApprovalTask> groupTasks = groupEntry.getValue();
                 ApprovalFlowGroupVo g = new ApprovalFlowGroupVo();
                 g.setGroupKey(groupKey);
-                GroupMeta meta = resolveGroupMeta(nodeCode, groupKey, deptNameMap, staffGroupNameMap, localUnitNames, tmpIdx);
+                GroupMeta meta =
+                        resolveGroupMeta(
+                                nodeCode,
+                                groupKey,
+                                deptNameMap,
+                                staffGroupNameMap,
+                                localUnitNames,
+                                localUnitNameMap,
+                                tmpIdx);
                 if ("TEMP_GROUP".equals(meta.groupType())) {
                     tmpIdx++;
                 }
@@ -224,15 +237,67 @@
         return out;
     }
 
+    private Map<Long, String> loadLocalUnitNameMap(AppointmentOrder order, List<ApprovalTask> tasks) {
+        Set<Long> unitIds = new LinkedHashSet<>();
+        for (ApprovalTask task : tasks) {
+            Long unitId = parseTailId(task.getGroupKey(), ":UNIT:");
+            if (unitId != null && unitId > 0) {
+                unitIds.add(unitId);
+            }
+        }
+        if (unitIds.isEmpty()) {
+            return Map.of();
+        }
+
+        Map<Long, String> out = new LinkedHashMap<>();
+        if (order != null) {
+            List<Long> orderUnitIds = parseLongList(order.getPassLocalUnitIds());
+            List<String> orderUnitNames = parseStringList(order.getPassLocalUnitNames());
+            int size = Math.min(orderUnitIds.size(), orderUnitNames.size());
+            for (int i = 0; i < size; i++) {
+                Long unitId = orderUnitIds.get(i);
+                String unitName = orderUnitNames.get(i);
+                if (unitId != null && unitId > 0 && StringUtils.hasText(unitName)) {
+                    out.put(unitId, unitName);
+                }
+            }
+        }
+
+        Set<Long> missingIds =
+                unitIds.stream()
+                        .filter(id -> !out.containsKey(id))
+                        .collect(Collectors.toCollection(LinkedHashSet::new));
+        if (missingIds.isEmpty()) {
+            return out;
+        }
+        List<MpPassLocalUnit> rows =
+                mpPassLocalUnitMapper.selectList(
+                        new LambdaQueryWrapper<MpPassLocalUnit>()
+                                .eq(MpPassLocalUnit::getDelFlag, 0)
+                                .in(MpPassLocalUnit::getId, missingIds));
+        for (MpPassLocalUnit row : rows) {
+            if (row.getId() != null && StringUtils.hasText(row.getUnitName())) {
+                out.put(row.getId(), row.getUnitName());
+            }
+        }
+        return out;
+    }
+
     private GroupMeta resolveGroupMeta(
             String nodeCode,
             String groupKey,
             Map<Long, String> deptNameMap,
             Map<Long, String> staffGroupNameMap,
             List<String> localUnitNames,
+            Map<Long, String> localUnitNameMap,
             int tmpIdx) {
         if (!ApprovalNodeCode.LEVEL3_LOCAL_DEPT_LEADER.equals(nodeCode)) {
             return new GroupMeta("DEFAULT", "审批人");
+        }
+        Long localUnitId = parseTailId(groupKey, ":UNIT:");
+        if (localUnitId != null) {
+            String name = localUnitNameMap.getOrDefault(localUnitId, "属地#" + localUnitId);
+            return new GroupMeta("TEMP_GROUP", name);
         }
         Long deptId = parseTailId(groupKey, ":DEPT:");
         if (deptId != null) {
@@ -297,6 +362,27 @@
         }
     }
 
+    private List<Long> parseLongList(String json) {
+        if (!StringUtils.hasText(json)) {
+            return List.of();
+        }
+        try {
+            List<Long> rows = objectMapper.readValue(json, LONG_LIST_TYPE);
+            if (rows == null) {
+                return List.of();
+            }
+            List<Long> out = new ArrayList<>();
+            for (Long row : rows) {
+                if (row != null && row > 0) {
+                    out.add(row);
+                }
+            }
+            return out;
+        } catch (Exception ex) {
+            return List.of();
+        }
+    }
+
     private List<MiniVisitedUserVo> loadNoticeUsers(
             String noticeIds, Map<Long, MpUser> existingUserMap, Map<Long, String> existingDeptNameMap) {
         List<Long> ids = parseCommaSeparatedIds(noticeIds);

--
Gitblit v1.7.1