From 08f95b2f159b56fa3bd4f4b348855989de8aa456 Mon Sep 17 00:00:00 2001
From: wlzboy <66905212@qq.com>
Date: 星期四, 18 十二月 2025 21:48:18 +0800
Subject: [PATCH] feat: vehicle
---
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java | 121 ++++++++++++++++++++++++++++++++++++++++
1 files changed, 121 insertions(+), 0 deletions(-)
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java
index 54b605d..3d393c1 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java
@@ -1,9 +1,13 @@
package com.ruoyi.system.service.impl;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Set;
import java.util.stream.Collectors;
+
+import com.ruoyi.common.utils.DeptUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.annotation.DataScope;
@@ -335,4 +339,121 @@
{
return getChildList(list, t).size() > 0;
}
+
+ /**
+ * 璁$畻鎸囧畾鐢ㄦ埛鐨勫垎鍏徃鍒楄〃
+ * 閫昏緫锛�
+ * 1. 鏍规嵁鐢ㄦ埛鐨刼aOrderClass鍖归厤鍒嗗叕鍙革紙鏈嶅姟鍗曠紪鐮�/璋冨害鍗曠紪鐮侊級
+ * 2. 闄勫姞鐢ㄦ埛鎵�灞炵殑鍒嗗叕鍙革紙浠巇eptId/ancestors瑙f瀽锛�
+ * 3. 鍘婚噸鍚庤繑鍥�
+ *
+ * @param user 鐢ㄦ埛淇℃伅
+ * @return 鍒嗗叕鍙稿垪琛�
+ */
+ @Override
+ public List<SysDept> computeBranchCompaniesForUser(SysUser user)
+ {
+ List<SysDept> result = new ArrayList<>();
+ Set<Long> seen = new HashSet<>();
+
+ if (user == null) {
+ return result;
+ }
+
+ // 1. 鏍规嵁oaOrderClass鍖归厤鍒嗗叕鍙革紙浼樺寲锛氫竴娆℃煡璇級
+ String orderClass = user.getOaOrderClass();
+ if (StringUtils.isNotEmpty(orderClass))
+ {
+ // 瑙f瀽orderClass涓虹紪鐮佸垪琛�
+ List<String> orderCodes = new ArrayList<>();
+ for (String raw : orderClass.split(",")) {
+ String code = raw.trim();
+ if (!code.isEmpty()) {
+ orderCodes.add(code);
+ }
+ }
+
+ // 涓�娆℃�ф煡璇㈡墍鏈夊尮閰嶇殑鍒嗗叕鍙�
+ if (!orderCodes.isEmpty()) {
+ List<SysDept> matchedDepts = deptMapper.selectBranchCompaniesByOrderCodes(orderCodes);
+ for (SysDept dept : matchedDepts) {
+ if (seen.add(dept.getDeptId())) {
+ result.add(dept);
+ }
+ }
+ }
+ }
+
+ // 2. 闄勫姞璇ョ敤鎴锋墍灞炲垎鍏徃锛堜粠deptId/ancestors瑙f瀽锛�
+ if (user.getDeptId() != null)
+ {
+ SysDept userDept = selectDeptById(user.getDeptId());
+ Long branchCompanyId = null;
+
+ if (userDept != null)
+ {
+ // 鍒ゆ柇鏄惁鏈韩灏辨槸鍒嗗叕鍙�
+ if (userDept.getParentId() != null && userDept.getParentId() == 100L)
+ {
+ branchCompanyId = userDept.getDeptId();
+ }
+ // 鍚﹀垯浠巃ncestors涓煡鎵�
+ else if (userDept.getAncestors() != null && !userDept.getAncestors().isEmpty())
+ {
+ String[] ancestorIds = userDept.getAncestors().split(",");
+ for (int i = 0; i < ancestorIds.length; i++)
+ {
+ // 鎵惧埌100鐨勪笅涓�涓氨鏄垎鍏徃ID
+ if ("100".equals(ancestorIds[i]) && i + 1 < ancestorIds.length)
+ {
+ try {
+ branchCompanyId = Long.parseLong(ancestorIds[i + 1]);
+ } catch (NumberFormatException e) {
+ branchCompanyId = null;
+ }
+ break;
+ }
+ }
+ }
+ }
+
+ // 濡傛灉鎵惧埌浜嗗垎鍏徃ID锛屾坊鍔犲埌缁撴灉涓�
+ if (branchCompanyId != null)
+ {
+ SysDept branchCompany = selectDeptById(branchCompanyId);
+ if (branchCompany != null && seen.add(branchCompany.getDeptId()))
+ {
+ result.add(branchCompany);
+ }
+ }
+ }
+
+ return result;
+ }
+
+ @Override
+ public Long getBranchCompany(Long deptId) {
+ Long branchId = DeptUtil.getBranchId(deptId);
+ if(branchId!=null)return branchId;
+ branchId = deptMapper.selectBranchCompanyIdByDeptId(deptId);
+ if(branchId!=null){
+ DeptUtil.setDeptIdBranchId(deptId,branchId);
+ return branchId;
+ }
+ else {
+ return null;
+ }
+ }
+
+ /**
+ * 鏍规嵁service_class鏌ヨ閮ㄩ棬淇℃伅
+ *
+ * @param serviceClass 鏈嶅姟绫诲埆缂栫爜
+ * @return 閮ㄩ棬淇℃伅
+ */
+ @Override
+ public SysDept selectDeptByServiceClass(String serviceClass)
+ {
+ return deptMapper.selectDeptByServiceClass(serviceClass);
+ }
}
--
Gitblit v1.9.1