|
@@ -1,6 +1,7 @@
|
|
|
package org.dromara.system.service.impl;
|
|
package org.dromara.system.service.impl;
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.convert.Convert;
|
|
import cn.hutool.core.convert.Convert;
|
|
|
import cn.hutool.core.lang.tree.Tree;
|
|
import cn.hutool.core.lang.tree.Tree;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
@@ -18,6 +19,7 @@ import org.dromara.common.core.utils.StringUtils;
|
|
|
import org.dromara.common.core.utils.TreeBuildUtils;
|
|
import org.dromara.common.core.utils.TreeBuildUtils;
|
|
|
import org.dromara.common.mybatis.helper.DataBaseHelper;
|
|
import org.dromara.common.mybatis.helper.DataBaseHelper;
|
|
|
import org.dromara.common.redis.utils.CacheUtils;
|
|
import org.dromara.common.redis.utils.CacheUtils;
|
|
|
|
|
+import org.dromara.common.redis.utils.RedisUtils;
|
|
|
import org.dromara.common.satoken.utils.LoginHelper;
|
|
import org.dromara.common.satoken.utils.LoginHelper;
|
|
|
import org.dromara.system.domain.SysDept;
|
|
import org.dromara.system.domain.SysDept;
|
|
|
import org.dromara.system.domain.SysRole;
|
|
import org.dromara.system.domain.SysRole;
|
|
@@ -104,10 +106,10 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|
|
return CollUtil.newArrayList();
|
|
return CollUtil.newArrayList();
|
|
|
}
|
|
}
|
|
|
return TreeBuildUtils.build(depts, (dept, tree) ->
|
|
return TreeBuildUtils.build(depts, (dept, tree) ->
|
|
|
- tree.setId(dept.getDeptId())
|
|
|
|
|
- .setParentId(dept.getParentId())
|
|
|
|
|
- .setName(dept.getDeptName())
|
|
|
|
|
- .setWeight(dept.getOrderNum()));
|
|
|
|
|
|
|
+ tree.setId(dept.getDeptId())
|
|
|
|
|
+ .setParentId(dept.getParentId())
|
|
|
|
|
+ .setName(dept.getDeptName())
|
|
|
|
|
+ .setWeight(dept.getOrderNum()));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -136,7 +138,7 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
SysDeptVo parentDept = baseMapper.selectVoOne(new LambdaQueryWrapper<SysDept>()
|
|
SysDeptVo parentDept = baseMapper.selectVoOne(new LambdaQueryWrapper<SysDept>()
|
|
|
- .select(SysDept::getDeptName).eq(SysDept::getDeptId, dept.getParentId()));
|
|
|
|
|
|
|
+ .select(SysDept::getDeptName).eq(SysDept::getDeptId, dept.getParentId()));
|
|
|
dept.setParentName(ObjectUtil.isNotNull(parentDept) ? parentDept.getDeptName() : null);
|
|
dept.setParentName(ObjectUtil.isNotNull(parentDept) ? parentDept.getDeptName() : null);
|
|
|
return dept;
|
|
return dept;
|
|
|
}
|
|
}
|
|
@@ -150,9 +152,9 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|
|
@Override
|
|
@Override
|
|
|
public List<SysDeptVo> selectDeptByIds(List<Long> deptIds) {
|
|
public List<SysDeptVo> selectDeptByIds(List<Long> deptIds) {
|
|
|
return baseMapper.selectDeptList(new LambdaQueryWrapper<SysDept>()
|
|
return baseMapper.selectDeptList(new LambdaQueryWrapper<SysDept>()
|
|
|
- .select(SysDept::getDeptId, SysDept::getDeptName)
|
|
|
|
|
- .eq(SysDept::getStatus, UserConstants.DEPT_NORMAL)
|
|
|
|
|
- .in(CollUtil.isNotEmpty(deptIds), SysDept::getDeptId, deptIds));
|
|
|
|
|
|
|
+ .select(SysDept::getDeptId, SysDept::getDeptName)
|
|
|
|
|
+ .eq(SysDept::getStatus, UserConstants.DEPT_NORMAL)
|
|
|
|
|
+ .in(CollUtil.isNotEmpty(deptIds), SysDept::getDeptId, deptIds));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -182,8 +184,8 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|
|
@Override
|
|
@Override
|
|
|
public long selectNormalChildrenDeptById(Long deptId) {
|
|
public long selectNormalChildrenDeptById(Long deptId) {
|
|
|
return baseMapper.selectCount(new LambdaQueryWrapper<SysDept>()
|
|
return baseMapper.selectCount(new LambdaQueryWrapper<SysDept>()
|
|
|
- .eq(SysDept::getStatus, UserConstants.DEPT_NORMAL)
|
|
|
|
|
- .apply(DataBaseHelper.findInSet(deptId, "ancestors")));
|
|
|
|
|
|
|
+ .eq(SysDept::getStatus, UserConstants.DEPT_NORMAL)
|
|
|
|
|
+ .apply(DataBaseHelper.findInSet(deptId, "ancestors")));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -195,7 +197,7 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|
|
@Override
|
|
@Override
|
|
|
public boolean hasChildByDeptId(Long deptId) {
|
|
public boolean hasChildByDeptId(Long deptId) {
|
|
|
return baseMapper.exists(new LambdaQueryWrapper<SysDept>()
|
|
return baseMapper.exists(new LambdaQueryWrapper<SysDept>()
|
|
|
- .eq(SysDept::getParentId, deptId));
|
|
|
|
|
|
|
+ .eq(SysDept::getParentId, deptId));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -207,7 +209,7 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|
|
@Override
|
|
@Override
|
|
|
public boolean checkDeptExistUser(Long deptId) {
|
|
public boolean checkDeptExistUser(Long deptId) {
|
|
|
return userMapper.exists(new LambdaQueryWrapper<SysUser>()
|
|
return userMapper.exists(new LambdaQueryWrapper<SysUser>()
|
|
|
- .eq(SysUser::getDeptId, deptId));
|
|
|
|
|
|
|
+ .eq(SysUser::getDeptId, deptId));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -219,9 +221,9 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|
|
@Override
|
|
@Override
|
|
|
public boolean checkDeptNameUnique(SysDeptBo dept) {
|
|
public boolean checkDeptNameUnique(SysDeptBo dept) {
|
|
|
boolean exist = baseMapper.exists(new LambdaQueryWrapper<SysDept>()
|
|
boolean exist = baseMapper.exists(new LambdaQueryWrapper<SysDept>()
|
|
|
- .eq(SysDept::getDeptName, dept.getDeptName())
|
|
|
|
|
- .eq(SysDept::getParentId, dept.getParentId())
|
|
|
|
|
- .ne(ObjectUtil.isNotNull(dept.getDeptId()), SysDept::getDeptId, dept.getDeptId()));
|
|
|
|
|
|
|
+ .eq(SysDept::getDeptName, dept.getDeptName())
|
|
|
|
|
+ .eq(SysDept::getParentId, dept.getParentId())
|
|
|
|
|
+ .ne(ObjectUtil.isNotNull(dept.getDeptId()), SysDept::getDeptId, dept.getDeptId()));
|
|
|
return !exist;
|
|
return !exist;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -299,7 +301,7 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|
|
SysDept oldDept = baseMapper.selectById(dept.getDeptId());
|
|
SysDept oldDept = baseMapper.selectById(dept.getDeptId());
|
|
|
if (!oldDept.getParentId().equals(dept.getParentId())) {
|
|
if (!oldDept.getParentId().equals(dept.getParentId())) {
|
|
|
// 如果是新父部门 则校验是否具有新父部门权限 避免越权
|
|
// 如果是新父部门 则校验是否具有新父部门权限 避免越权
|
|
|
- //this.checkDeptDataScope(dept.getParentId());
|
|
|
|
|
|
|
+ // this.checkDeptDataScope(dept.getParentId());
|
|
|
SysDept newParentDept = baseMapper.selectById(dept.getParentId());
|
|
SysDept newParentDept = baseMapper.selectById(dept.getParentId());
|
|
|
if (ObjectUtil.isNotNull(newParentDept) && ObjectUtil.isNotNull(oldDept)) {
|
|
if (ObjectUtil.isNotNull(newParentDept) && ObjectUtil.isNotNull(oldDept)) {
|
|
|
String newAncestors = newParentDept.getAncestors() + StringUtils.SEPARATOR + newParentDept.getDeptId();
|
|
String newAncestors = newParentDept.getAncestors() + StringUtils.SEPARATOR + newParentDept.getDeptId();
|
|
@@ -310,7 +312,7 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|
|
}
|
|
}
|
|
|
int result = baseMapper.updateById(dept);
|
|
int result = baseMapper.updateById(dept);
|
|
|
if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors())
|
|
if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors())
|
|
|
- && !StringUtils.equals(UserConstants.DEPT_NORMAL, dept.getAncestors())) {
|
|
|
|
|
|
|
+ && !StringUtils.equals(UserConstants.DEPT_NORMAL, dept.getAncestors())) {
|
|
|
// 如果该部门是启用状态,则启用该部门的所有上级部门
|
|
// 如果该部门是启用状态,则启用该部门的所有上级部门
|
|
|
updateParentDeptStatusNormal(dept);
|
|
updateParentDeptStatusNormal(dept);
|
|
|
}
|
|
}
|
|
@@ -326,8 +328,8 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|
|
String ancestors = dept.getAncestors();
|
|
String ancestors = dept.getAncestors();
|
|
|
Long[] deptIds = Convert.toLongArray(ancestors);
|
|
Long[] deptIds = Convert.toLongArray(ancestors);
|
|
|
baseMapper.update(null, new LambdaUpdateWrapper<SysDept>()
|
|
baseMapper.update(null, new LambdaUpdateWrapper<SysDept>()
|
|
|
- .set(SysDept::getStatus, UserConstants.DEPT_NORMAL)
|
|
|
|
|
- .in(SysDept::getDeptId, Arrays.asList(deptIds)));
|
|
|
|
|
|
|
+ .set(SysDept::getStatus, UserConstants.DEPT_NORMAL)
|
|
|
|
|
+ .in(SysDept::getDeptId, Arrays.asList(deptIds)));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -339,7 +341,7 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|
|
*/
|
|
*/
|
|
|
private void updateDeptChildren(Long deptId, String newAncestors, String oldAncestors) {
|
|
private void updateDeptChildren(Long deptId, String newAncestors, String oldAncestors) {
|
|
|
List<SysDept> children = baseMapper.selectList(new LambdaQueryWrapper<SysDept>()
|
|
List<SysDept> children = baseMapper.selectList(new LambdaQueryWrapper<SysDept>()
|
|
|
- .apply(DataBaseHelper.findInSet(deptId, "ancestors")));
|
|
|
|
|
|
|
+ .apply(DataBaseHelper.findInSet(deptId, "ancestors")));
|
|
|
List<SysDept> list = new ArrayList<>();
|
|
List<SysDept> list = new ArrayList<>();
|
|
|
for (SysDept child : children) {
|
|
for (SysDept child : children) {
|
|
|
SysDept dept = new SysDept();
|
|
SysDept dept = new SysDept();
|
|
@@ -373,8 +375,9 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|
|
return CollUtil.newArrayList(deptId);
|
|
return CollUtil.newArrayList(deptId);
|
|
|
}
|
|
}
|
|
|
return baseMapper.selectList(Wrappers.lambdaQuery(SysDept.class)
|
|
return baseMapper.selectList(Wrappers.lambdaQuery(SysDept.class)
|
|
|
- .select(SysDept::getDeptId)
|
|
|
|
|
- .eq(SysDept::getParentId, deptId).or().eq(SysDept::getDeptId, deptId).or().likeRight(SysDept::getAncestors, sysDeptVo.getAncestors() + "," + deptId)
|
|
|
|
|
|
|
+ .select(SysDept::getDeptId)
|
|
|
|
|
+ .eq(SysDept::getParentId, deptId).or().eq(SysDept::getDeptId, deptId).or().likeRight(SysDept::getAncestors,
|
|
|
|
|
+ sysDeptVo.getAncestors() + "," + deptId)
|
|
|
).stream().map(SysDept::getDeptId).toList();
|
|
).stream().map(SysDept::getDeptId).toList();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -391,8 +394,8 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|
|
@Override
|
|
@Override
|
|
|
public SysDeptVo selectDeptByParentIdAndName(Long parentId, String deptName) {
|
|
public SysDeptVo selectDeptByParentIdAndName(Long parentId, String deptName) {
|
|
|
return baseMapper.selectVoOne(new LambdaQueryWrapper<SysDept>()
|
|
return baseMapper.selectVoOne(new LambdaQueryWrapper<SysDept>()
|
|
|
- .eq(SysDept::getParentId, parentId)
|
|
|
|
|
- .eq(SysDept::getDeptName, deptName));
|
|
|
|
|
|
|
+ .eq(SysDept::getParentId, parentId)
|
|
|
|
|
+ .eq(SysDept::getDeptName, deptName));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -410,6 +413,25 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public int deleteDeptByOtherId(String otherId) {
|
|
public int deleteDeptByOtherId(String otherId) {
|
|
|
- return baseMapper.deleteDeptByOtherId(otherId,new Date());
|
|
|
|
|
|
|
+ return baseMapper.deleteDeptByOtherId(otherId, new Date());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 查询指定时间的进行中的班级
|
|
|
|
|
+ * @param doingDate 指定时间
|
|
|
|
|
+ * @return 班级列表
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<SysDeptVo> selectDoingClass(Date doingDate) {
|
|
|
|
|
+ List<SysDeptVo> redisList = RedisUtils.getCacheList(CacheNames.DOING_CLASS);
|
|
|
|
|
+ if(CollectionUtil.isNotEmpty(redisList)){
|
|
|
|
|
+ return redisList;
|
|
|
|
|
+ }
|
|
|
|
|
+ List<SysDeptVo> list = baseMapper.selectVoList(new LambdaQueryWrapper<SysDept>().ge(SysDept::getCheckDate, doingDate).le(SysDept::getEndDate, doingDate));
|
|
|
|
|
+ if(CollectionUtil.isNotEmpty(redisList)){
|
|
|
|
|
+ RedisUtils.setCacheList(CacheNames.DOING_CLASS, list);
|
|
|
|
|
+ return list;
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|