Search in sources :

Example 1 with SysDept

use of com.ruoyi.common.core.domain.entity.SysDept in project RuoYi-Flowable-Plus by KonBAI-Q.

the class SysDeptController method excludeChild.

/**
 * 查询部门列表(排除节点)
 */
@ApiOperation("查询部门列表(排除节点)")
@SaCheckPermission("system:dept:list")
@GetMapping("/list/exclude/{deptId}")
public R<List<SysDept>> excludeChild(@ApiParam("部门ID") @PathVariable(value = "deptId", required = false) Long deptId) {
    List<SysDept> depts = deptService.selectDeptList(new SysDept());
    depts.removeIf(d -> d.getDeptId().equals(deptId) || ArrayUtil.contains(StringUtils.split(d.getAncestors(), ","), deptId + ""));
    return R.ok(depts);
}
Also used : SysDept(com.ruoyi.common.core.domain.entity.SysDept) ApiOperation(io.swagger.annotations.ApiOperation) SaCheckPermission(cn.dev33.satoken.annotation.SaCheckPermission)

Example 2 with SysDept

use of com.ruoyi.common.core.domain.entity.SysDept in project RuoYi-Flowable-Plus by KonBAI-Q.

the class SysDeptServiceImpl method updateDeptChildren.

/**
 * 修改子元素关系
 *
 * @param deptId       被修改的部门ID
 * @param newAncestors 新的父ID集合
 * @param oldAncestors 旧的父ID集合
 */
public void updateDeptChildren(Long deptId, String newAncestors, String oldAncestors) {
    List<SysDept> children = baseMapper.selectList(new LambdaQueryWrapper<SysDept>().apply(DataBaseHelper.findInSet(deptId, "ancestors")));
    List<SysDept> list = new ArrayList<>();
    for (SysDept child : children) {
        SysDept dept = new SysDept();
        dept.setDeptId(child.getDeptId());
        dept.setAncestors(child.getAncestors().replaceFirst(oldAncestors, newAncestors));
        list.add(dept);
    }
    if (list.size() > 0) {
        baseMapper.updateBatchById(list);
    }
}
Also used : SysDept(com.ruoyi.common.core.domain.entity.SysDept) ArrayList(java.util.ArrayList) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 3 with SysDept

use of com.ruoyi.common.core.domain.entity.SysDept in project RuoYi-Flowable-Plus by KonBAI-Q.

the class SysDeptServiceImpl method updateDept.

/**
 * 修改保存部门信息
 *
 * @param dept 部门信息
 * @return 结果
 */
@Override
public int updateDept(SysDept dept) {
    SysDept newParentDept = baseMapper.selectById(dept.getParentId());
    SysDept oldDept = baseMapper.selectById(dept.getDeptId());
    if (ObjectUtil.isNotNull(newParentDept) && ObjectUtil.isNotNull(oldDept)) {
        String newAncestors = newParentDept.getAncestors() + "," + newParentDept.getDeptId();
        String oldAncestors = oldDept.getAncestors();
        dept.setAncestors(newAncestors);
        updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors);
    }
    int result = baseMapper.updateById(dept);
    if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors()) && !StringUtils.equals(UserConstants.DEPT_NORMAL, dept.getAncestors())) {
        // 如果该部门是启用状态,则启用该部门的所有上级部门
        updateParentDeptStatusNormal(dept);
    }
    return result;
}
Also used : SysDept(com.ruoyi.common.core.domain.entity.SysDept)

Example 4 with SysDept

use of com.ruoyi.common.core.domain.entity.SysDept in project RuoYi-Vue-Plus by JavaLionLi.

the class SysDeptServiceImpl method checkDeptDataScope.

/**
 * 校验部门是否有数据权限
 *
 * @param deptId 部门id
 */
@Override
public void checkDeptDataScope(Long deptId) {
    if (!LoginHelper.isAdmin()) {
        SysDept dept = new SysDept();
        dept.setDeptId(deptId);
        List<SysDept> depts = this.selectDeptList(dept);
        if (CollUtil.isEmpty(depts)) {
            throw new ServiceException("没有权限访问部门数据!");
        }
    }
}
Also used : ServiceException(com.ruoyi.common.exception.ServiceException) SysDept(com.ruoyi.common.core.domain.entity.SysDept)

Example 5 with SysDept

use of com.ruoyi.common.core.domain.entity.SysDept in project RuoYi-Vue-Plus by JavaLionLi.

the class SysDeptServiceImpl method insertDept.

/**
 * 新增保存部门信息
 *
 * @param dept 部门信息
 * @return 结果
 */
@Override
public int insertDept(SysDept dept) {
    SysDept info = baseMapper.selectById(dept.getParentId());
    // 如果父节点不为正常状态,则不允许新增子节点
    if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) {
        throw new ServiceException("部门停用,不允许新增");
    }
    dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
    return baseMapper.insert(dept);
}
Also used : ServiceException(com.ruoyi.common.exception.ServiceException) SysDept(com.ruoyi.common.core.domain.entity.SysDept)

Aggregations

SysDept (com.ruoyi.common.core.domain.entity.SysDept)39 ServiceException (com.ruoyi.common.exception.ServiceException)8 ArrayList (java.util.ArrayList)7 GetMapping (org.springframework.web.bind.annotation.GetMapping)6 SaCheckPermission (cn.dev33.satoken.annotation.SaCheckPermission)4 ApiOperation (io.swagger.annotations.ApiOperation)4 AjaxResult (com.ruoyi.common.core.domain.AjaxResult)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 Log (com.ruoyi.common.annotation.Log)2 SysUser (com.ruoyi.common.core.domain.entity.SysUser)2 SysUserExportVo (com.ruoyi.system.domain.vo.SysUserExportVo)2 HashMap (java.util.HashMap)2 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)1 CustomException (com.ruoyi.common.exception.CustomException)1