| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | 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) { |
| | |
| | | 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) { |
| | |
| | | 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++; |
| | | } |
| | |
| | | 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) { |
| | |
| | | } |
| | | } |
| | | |
| | | 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); |