From 17b90f8381d715ba45fbce080d80c88250c172e0 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子li <15040126243@163.com>
Date: 星期五, 17 九月 2021 16:20:26 +0800
Subject: [PATCH] add 增加 限流演示案例
---
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java | 29 ++++++++++++++++++++++++-----
1 files changed, 24 insertions(+), 5 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 93d0129..cbafcf4 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
@@ -10,8 +10,10 @@
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl;
-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.system.mapper.SysDeptMapper;
import com.ruoyi.system.mapper.SysRoleMapper;
import com.ruoyi.system.mapper.SysUserMapper;
@@ -118,7 +120,7 @@
* @return 瀛愰儴闂ㄦ暟
*/
@Override
- public int selectNormalChildrenDeptById(Long deptId) {
+ public long selectNormalChildrenDeptById(Long deptId) {
return count(new LambdaQueryWrapper<SysDept>()
.eq(SysDept::getStatus, 0)
.apply("find_in_set({0}, ancestors)", deptId));
@@ -132,7 +134,7 @@
*/
@Override
public boolean hasChildByDeptId(Long deptId) {
- int result = count(new LambdaQueryWrapper<SysDept>()
+ long result = count(new LambdaQueryWrapper<SysDept>()
.eq(SysDept::getParentId, deptId)
.last("limit 1"));
return result > 0;
@@ -146,7 +148,7 @@
*/
@Override
public boolean checkDeptExistUser(Long deptId) {
- int result = userMapper.selectCount(new LambdaQueryWrapper<SysUser>()
+ long result = userMapper.selectCount(new LambdaQueryWrapper<SysUser>()
.eq(SysUser::getDeptId, deptId));
return result > 0;
}
@@ -171,6 +173,23 @@
}
/**
+ * 鏍¢獙閮ㄩ棬鏄惁鏈夋暟鎹潈闄�
+ *
+ * @param deptId 閮ㄩ棬id
+ */
+ @Override
+ public void checkDeptDataScope(Long deptId) {
+ if (!SysUser.isAdmin(SecurityUtils.getUserId())) {
+ SysDept dept = new SysDept();
+ dept.setDeptId(deptId);
+ List<SysDept> depts = SpringUtils.getAopProxy(this).selectDeptList(dept);
+ if (StringUtils.isEmpty(depts)) {
+ throw new ServiceException("娌℃湁鏉冮檺璁块棶閮ㄩ棬鏁版嵁锛�");
+ }
+ }
+ }
+
+ /**
* 鏂板淇濆瓨閮ㄩ棬淇℃伅
*
* @param dept 閮ㄩ棬淇℃伅
@@ -181,7 +200,7 @@
SysDept info = getById(dept.getParentId());
// 濡傛灉鐖惰妭鐐逛笉涓烘甯哥姸鎬�,鍒欎笉鍏佽鏂板瀛愯妭鐐�
if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) {
- throw new CustomException("閮ㄩ棬鍋滅敤锛屼笉鍏佽鏂板");
+ throw new ServiceException("閮ㄩ棬鍋滅敤锛屼笉鍏佽鏂板");
}
dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
return baseMapper.insert(dept);
--
Gitblit v1.9.3