From 9d8b9fabbea813e980d7f8e67ee633a55d205955 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子Li <15040126243@163.com>
Date: 星期四, 16 一月 2025 11:50:19 +0800
Subject: [PATCH] update 优化 ws模块替换session的时候关闭session连接
---
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java | 72 ++++++++++++++++++++++++++----------
1 files changed, 52 insertions(+), 20 deletions(-)
diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java
index c173916..ca062be 100644
--- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java
+++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java
@@ -1,5 +1,6 @@
package org.dromara.system.service.impl;
+import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.tree.Tree;
@@ -9,14 +10,11 @@
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.constant.CacheNames;
-import org.dromara.common.core.constant.UserConstants;
+import org.dromara.common.core.constant.SystemConstants;
+import org.dromara.common.core.domain.dto.DeptDTO;
import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.core.service.DeptService;
-import org.dromara.common.core.utils.MapstructUtils;
-import org.dromara.common.core.utils.SpringUtils;
-import org.dromara.common.core.utils.StringUtils;
-import org.dromara.common.core.utils.StreamUtils;
-import org.dromara.common.core.utils.TreeBuildUtils;
+import org.dromara.common.core.utils.*;
import org.dromara.common.mybatis.helper.DataBaseHelper;
import org.dromara.common.redis.utils.CacheUtils;
import org.dromara.common.satoken.utils.LoginHelper;
@@ -31,7 +29,9 @@
import org.dromara.system.service.ISysDeptService;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
+import org.springframework.cache.annotation.Caching;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Arrays;
@@ -70,8 +70,6 @@
*/
@Override
public List<Tree<Long>> selectDeptTreeList(SysDeptBo bo) {
- // 鍙煡璇㈡湭绂佺敤閮ㄩ棬
- bo.setStatus(UserConstants.DEPT_NORMAL);
LambdaQueryWrapper<SysDept> lqw = buildQueryWrapper(bo);
List<SysDeptVo> depts = baseMapper.selectDeptList(lqw);
return buildDeptTreeSelect(depts);
@@ -79,7 +77,7 @@
private LambdaQueryWrapper<SysDept> buildQueryWrapper(SysDeptBo bo) {
LambdaQueryWrapper<SysDept> lqw = Wrappers.lambdaQuery();
- lqw.eq(SysDept::getDelFlag, UserConstants.DEL_FLAG_NORMAL);
+ lqw.eq(SysDept::getDelFlag, SystemConstants.NORMAL);
lqw.eq(ObjectUtil.isNotNull(bo.getDeptId()), SysDept::getDeptId, bo.getDeptId());
lqw.eq(ObjectUtil.isNotNull(bo.getParentId()), SysDept::getParentId, bo.getParentId());
lqw.like(StringUtils.isNotBlank(bo.getDeptName()), SysDept::getDeptName, bo.getDeptName());
@@ -113,8 +111,9 @@
tree.setId(dept.getDeptId())
.setParentId(dept.getParentId())
.setName(dept.getDeptName())
- .setWeight(dept.getOrderNum()));
- Tree<Long> tree = trees.stream().filter(it -> it.getId().longValue() == d.getDeptId()).findFirst().get();
+ .setWeight(dept.getOrderNum())
+ .putExtra("disabled", SystemConstants.DISABLE.equals(dept.getStatus())));
+ Tree<Long> tree = StreamUtils.findFirst(trees, it -> it.getId().longValue() == d.getDeptId());
treeList.add(tree);
}
}
@@ -148,7 +147,7 @@
}
SysDeptVo parentDept = baseMapper.selectVoOne(new LambdaQueryWrapper<SysDept>()
.select(SysDept::getDeptName).eq(SysDept::getDeptId, dept.getParentId()));
- dept.setParentName(ObjectUtil.isNotNull(parentDept) ? parentDept.getDeptName() : null);
+ dept.setParentName(ObjectUtils.notNullGetter(parentDept, SysDeptVo::getDeptName));
return dept;
}
@@ -156,7 +155,7 @@
public List<SysDeptVo> selectDeptByIds(List<Long> deptIds) {
return baseMapper.selectDeptList(new LambdaQueryWrapper<SysDept>()
.select(SysDept::getDeptId, SysDept::getDeptName, SysDept::getLeader)
- .eq(SysDept::getStatus, UserConstants.DEPT_NORMAL)
+ .eq(SysDept::getStatus, SystemConstants.NORMAL)
.in(CollUtil.isNotEmpty(deptIds), SysDept::getDeptId, deptIds));
}
@@ -179,6 +178,31 @@
}
/**
+ * 鏍规嵁閮ㄩ棬ID鏌ヨ閮ㄩ棬璐熻矗浜�
+ *
+ * @param deptId 閮ㄩ棬ID锛岀敤浜庢寚瀹氶渶瑕佹煡璇㈢殑閮ㄩ棬
+ * @return 杩斿洖璇ラ儴闂ㄧ殑璐熻矗浜篒D
+ */
+ @Override
+ public Long selectDeptLeaderById(Long deptId) {
+ SysDeptVo vo = SpringUtils.getAopProxy(this).selectDeptById(deptId);
+ return vo.getLeader();
+ }
+
+ /**
+ * 鏌ヨ閮ㄩ棬
+ *
+ * @return 閮ㄩ棬鍒楄〃
+ */
+ @Override
+ public List<DeptDTO> selectDeptsByList() {
+ List<SysDeptVo> list = baseMapper.selectDeptList(new LambdaQueryWrapper<SysDept>()
+ .select(SysDept::getDeptId, SysDept::getDeptName, SysDept::getParentId)
+ .eq(SysDept::getStatus, SystemConstants.NORMAL));
+ return BeanUtil.copyToList(list, DeptDTO.class);
+ }
+
+ /**
* 鏍规嵁ID鏌ヨ鎵�鏈夊瓙閮ㄩ棬鏁帮紙姝e父鐘舵�侊級
*
* @param deptId 閮ㄩ棬ID
@@ -187,7 +211,7 @@
@Override
public long selectNormalChildrenDeptById(Long deptId) {
return baseMapper.selectCount(new LambdaQueryWrapper<SysDept>()
- .eq(SysDept::getStatus, UserConstants.DEPT_NORMAL)
+ .eq(SysDept::getStatus, SystemConstants.NORMAL)
.apply(DataBaseHelper.findInSet(deptId, "ancestors")));
}
@@ -254,11 +278,12 @@
* @param bo 閮ㄩ棬淇℃伅
* @return 缁撴灉
*/
+ @CacheEvict(cacheNames = CacheNames.SYS_DEPT_AND_CHILD, allEntries = true)
@Override
public int insertDept(SysDeptBo bo) {
SysDept info = baseMapper.selectById(bo.getParentId());
// 濡傛灉鐖惰妭鐐逛笉涓烘甯哥姸鎬�,鍒欎笉鍏佽鏂板瀛愯妭鐐�
- if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) {
+ if (!SystemConstants.NORMAL.equals(info.getStatus())) {
throw new ServiceException("閮ㄩ棬鍋滅敤锛屼笉鍏佽鏂板");
}
SysDept dept = MapstructUtils.convert(bo, SysDept.class);
@@ -272,8 +297,12 @@
* @param bo 閮ㄩ棬淇℃伅
* @return 缁撴灉
*/
- @CacheEvict(cacheNames = CacheNames.SYS_DEPT, key = "#bo.deptId")
+ @Caching(evict = {
+ @CacheEvict(cacheNames = CacheNames.SYS_DEPT, key = "#bo.deptId"),
+ @CacheEvict(cacheNames = CacheNames.SYS_DEPT_AND_CHILD, allEntries = true)
+ })
@Override
+ @Transactional(rollbackFor = Exception.class)
public int updateDept(SysDeptBo bo) {
SysDept dept = MapstructUtils.convert(bo, SysDept.class);
SysDept oldDept = baseMapper.selectById(dept.getDeptId());
@@ -294,8 +323,8 @@
dept.setAncestors(oldDept.getAncestors());
}
int result = baseMapper.updateById(dept);
- if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors())
- && !StringUtils.equals(UserConstants.DEPT_NORMAL, dept.getAncestors())) {
+ if (SystemConstants.NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors())
+ && !StringUtils.equals(SystemConstants.NORMAL, dept.getAncestors())) {
// 濡傛灉璇ラ儴闂ㄦ槸鍚敤鐘舵�侊紝鍒欏惎鐢ㄨ閮ㄩ棬鐨勬墍鏈変笂绾ч儴闂�
updateParentDeptStatusNormal(dept);
}
@@ -311,7 +340,7 @@
String ancestors = dept.getAncestors();
Long[] deptIds = Convert.toLongArray(ancestors);
baseMapper.update(null, new LambdaUpdateWrapper<SysDept>()
- .set(SysDept::getStatus, UserConstants.DEPT_NORMAL)
+ .set(SysDept::getStatus, SystemConstants.NORMAL)
.in(SysDept::getDeptId, Arrays.asList(deptIds)));
}
@@ -345,7 +374,10 @@
* @param deptId 閮ㄩ棬ID
* @return 缁撴灉
*/
- @CacheEvict(cacheNames = CacheNames.SYS_DEPT, key = "#deptId")
+ @Caching(evict = {
+ @CacheEvict(cacheNames = CacheNames.SYS_DEPT, key = "#deptId"),
+ @CacheEvict(cacheNames = CacheNames.SYS_DEPT_AND_CHILD, key = "#deptId")
+ })
@Override
public int deleteDeptById(Long deptId) {
return baseMapper.deleteById(deptId);
--
Gitblit v1.9.3