From 78b0b58d0c0fa4a50b5767136f3bbee8f364fe61 Mon Sep 17 00:00:00 2001
From: maven <2163098428@qq.com>
Date: 星期五, 26 九月 2025 09:11:08 +0800
Subject: [PATCH] yys 新增配置文件
---
src/main/java/com/ruoyi/project/system/service/impl/SysDeptServiceImpl.java | 65 ++++++++++++++++++++++++++------
1 files changed, 53 insertions(+), 12 deletions(-)
diff --git a/src/main/java/com/ruoyi/project/system/service/impl/SysDeptServiceImpl.java b/src/main/java/com/ruoyi/project/system/service/impl/SysDeptServiceImpl.java
index 30963e2..eae688f 100644
--- a/src/main/java/com/ruoyi/project/system/service/impl/SysDeptServiceImpl.java
+++ b/src/main/java/com/ruoyi/project/system/service/impl/SysDeptServiceImpl.java
@@ -8,12 +8,15 @@
import org.springframework.stereotype.Service;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.text.Convert;
-import com.ruoyi.common.exception.CustomException;
+import com.ruoyi.common.exception.ServiceException;
+import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.framework.aspectj.lang.annotation.DataScope;
import com.ruoyi.framework.web.domain.TreeSelect;
import com.ruoyi.project.system.domain.SysDept;
import com.ruoyi.project.system.domain.SysRole;
+import com.ruoyi.project.system.domain.SysUser;
import com.ruoyi.project.system.mapper.SysDeptMapper;
import com.ruoyi.project.system.mapper.SysRoleMapper;
import com.ruoyi.project.system.service.ISysDeptService;
@@ -44,6 +47,19 @@
{
return deptMapper.selectDeptList(dept);
}
+
+ /**
+ * 鏌ヨ閮ㄩ棬鏍戠粨鏋勪俊鎭�
+ *
+ * @param dept 閮ㄩ棬淇℃伅
+ * @return 閮ㄩ棬鏍戜俊鎭泦鍚�
+ */
+ @Override
+ public List<TreeSelect> selectDeptTreeList(SysDept dept)
+ {
+ List<SysDept> depts = SpringUtils.getAopProxy(this).selectDeptList(dept);
+ return buildDeptTreeSelect(depts);
+ }
/**
* 鏋勫缓鍓嶇鎵�闇�瑕佹爲缁撴瀯
@@ -55,14 +71,9 @@
public List<SysDept> buildDeptTree(List<SysDept> depts)
{
List<SysDept> returnList = new ArrayList<SysDept>();
- List<Long> tempList = new ArrayList<Long>();
+ List<Long> tempList = depts.stream().map(SysDept::getDeptId).collect(Collectors.toList());
for (SysDept dept : depts)
{
- tempList.add(dept.getDeptId());
- }
- for (Iterator<SysDept> iterator = depts.iterator(); iterator.hasNext();)
- {
- SysDept dept = (SysDept) iterator.next();
// 濡傛灉鏄《绾ц妭鐐�, 閬嶅巻璇ョ埗鑺傜偣鐨勬墍鏈夊瓙鑺傜偣
if (!tempList.contains(dept.getParentId()))
{
@@ -97,7 +108,7 @@
* @return 閫変腑閮ㄩ棬鍒楄〃
*/
@Override
- public List<Integer> selectDeptListByRoleId(Long roleId)
+ public List<Long> selectDeptListByRoleId(Long roleId)
{
SysRole role = roleMapper.selectRoleById(roleId);
return deptMapper.selectDeptListByRoleId(roleId, role.isDeptCheckStrictly());
@@ -137,7 +148,7 @@
public boolean hasChildByDeptId(Long deptId)
{
int result = deptMapper.hasChildByDeptId(deptId);
- return result > 0 ? true : false;
+ return result > 0;
}
/**
@@ -150,7 +161,7 @@
public boolean checkDeptExistUser(Long deptId)
{
int result = deptMapper.checkDeptExistUser(deptId);
- return result > 0 ? true : false;
+ return result > 0;
}
/**
@@ -160,7 +171,7 @@
* @return 缁撴灉
*/
@Override
- public String checkDeptNameUnique(SysDept dept)
+ public boolean checkDeptNameUnique(SysDept dept)
{
Long deptId = StringUtils.isNull(dept.getDeptId()) ? -1L : dept.getDeptId();
SysDept info = deptMapper.checkDeptNameUnique(dept.getDeptName(), dept.getParentId());
@@ -169,6 +180,26 @@
return UserConstants.NOT_UNIQUE;
}
return UserConstants.UNIQUE;
+ }
+
+ /**
+ * 鏍¢獙閮ㄩ棬鏄惁鏈夋暟鎹潈闄�
+ *
+ * @param deptId 閮ㄩ棬id
+ */
+ @Override
+ public void checkDeptDataScope(Long deptId)
+ {
+ if (!SysUser.isAdmin(SecurityUtils.getUserId()) && StringUtils.isNotNull(deptId))
+ {
+ SysDept dept = new SysDept();
+ dept.setDeptId(deptId);
+ List<SysDept> depts = SpringUtils.getAopProxy(this).selectDeptList(dept);
+ if (StringUtils.isEmpty(depts))
+ {
+ throw new ServiceException("娌℃湁鏉冮檺璁块棶閮ㄩ棬鏁版嵁锛�");
+ }
+ }
}
/**
@@ -184,7 +215,7 @@
// 濡傛灉鐖惰妭鐐逛笉涓烘甯哥姸鎬�,鍒欎笉鍏佽鏂板瀛愯妭鐐�
if (!UserConstants.DEPT_NORMAL.equals(info.getStatus()))
{
- throw new CustomException("閮ㄩ棬鍋滅敤锛屼笉鍏佽鏂板");
+ throw new ServiceException("閮ㄩ棬鍋滅敤锛屼笉鍏佽鏂板");
}
dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
return deptMapper.insertDept(dept);
@@ -263,6 +294,16 @@
}
/**
+ * 鏌ヨ椤跺眰閮ㄩ棬id
+ * @param deptId
+ * @return
+ */
+ @Override
+ public Long maxLevelDeptId(Long deptId) {
+ return deptMapper.maxLevelDeptId(deptId);
+ }
+
+ /**
* 閫掑綊鍒楄〃
*/
private void recursionFn(List<SysDept> list, SysDept t)
--
Gitblit v1.9.3