唐耀东
2021-12-09 eeeddf0836a5a5aa03a3342d34318c7202313e93
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java
@@ -2,7 +2,9 @@
import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.http.HttpStatus;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.constant.UserConstants;
@@ -175,7 +177,11 @@
        SysDept info = getById(dept.getParentId());
        // 如果父节点不为正常状态,则不允许新增子节点
        if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) {
            throw new ServiceException("部门停用,不允许新增");
            throw new ServiceException("机构停用,不允许新增");
        }
        List<SysDept> list = baseMapper.selectList(new QueryWrapper<SysDept>().lambda().eq(SysDept::getCode, dept.getCode()));
        if (list.size() > 0) {
            throw new ServiceException("机构编号重复", HttpStatus.HTTP_PARTIAL);
        }
        dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
        return baseMapper.insert(dept);
@@ -189,6 +195,12 @@
     */
    @Override
    public int updateDept(SysDept dept) {
        List<SysDept> list = baseMapper.selectList(new QueryWrapper<SysDept>().lambda()
            .eq(SysDept::getCode, dept.getCode())
            .ne(SysDept::getDeptId, dept.getDeptId()));
        if (list.size() > 0) {
            throw new ServiceException("机构编号重复", HttpStatus.HTTP_PARTIAL);
        }
        SysDept newParentDept = getById(dept.getParentId());
        SysDept oldDept = getById(dept.getDeptId());
        if (StringUtils.isNotNull(newParentDept) && StringUtils.isNotNull(oldDept)) {