Search in sources :

Example 21 with SysDept

use of com.ruoyi.system.api.domain.SysDept in project RuoYi-Cloud-Plus by JavaLionLi.

the class SysDeptController method excludeChild.

/**
 * 查询部门列表(排除节点)
 */
@ApiOperation("查询部门列表(排除节点)")
@SaCheckPermission("system:dept:list")
@GetMapping("/list/exclude/{deptId}")
public R<List<SysDept>> excludeChild(@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.system.api.domain.SysDept) ApiOperation(io.swagger.annotations.ApiOperation) SaCheckPermission(cn.dev33.satoken.annotation.SaCheckPermission)

Example 22 with SysDept

use of com.ruoyi.system.api.domain.SysDept in project RuoYi-Cloud-Plus by JavaLionLi.

the class SysUserController method export.

@ApiOperation("导出用户列表")
@Log(title = "用户管理", businessType = BusinessType.EXPORT)
@SaCheckPermission("system:user:export")
@PostMapping("/export")
public void export(HttpServletResponse response, SysUser user) {
    List<SysUser> list = userService.selectUserList(user);
    List<SysUserExportVo> listVo = BeanUtil.copyToList(list, SysUserExportVo.class);
    for (int i = 0; i < list.size(); i++) {
        SysDept dept = list.get(i).getDept();
        SysUserExportVo vo = listVo.get(i);
        if (ObjectUtil.isNotEmpty(dept)) {
            vo.setDeptName(dept.getDeptName());
            vo.setLeader(dept.getLeader());
        }
    }
    ExcelUtil.exportExcel(listVo, "用户数据", SysUserExportVo.class, response);
}
Also used : SysUser(com.ruoyi.system.api.domain.SysUser) SysDept(com.ruoyi.system.api.domain.SysDept) SysUserExportVo(com.ruoyi.system.domain.vo.SysUserExportVo) Log(com.ruoyi.common.log.annotation.Log) ApiOperation(io.swagger.annotations.ApiOperation) SaCheckPermission(cn.dev33.satoken.annotation.SaCheckPermission)

Example 23 with SysDept

use of com.ruoyi.system.api.domain.SysDept in project RuoYi-Cloud-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.core.exception.ServiceException) SysDept(com.ruoyi.system.api.domain.SysDept)

Example 24 with SysDept

use of com.ruoyi.system.api.domain.SysDept in project RuoYi-Cloud-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.core.exception.ServiceException) SysDept(com.ruoyi.system.api.domain.SysDept)

Example 25 with SysDept

use of com.ruoyi.system.api.domain.SysDept in project RuoYi-Cloud-Plus by JavaLionLi.

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.system.api.domain.SysDept)

Aggregations

SysDept (com.ruoyi.system.api.domain.SysDept)25 ServiceException (com.ruoyi.common.core.exception.ServiceException)6 ArrayList (java.util.ArrayList)5 GetMapping (org.springframework.web.bind.annotation.GetMapping)4 ApiOperation (io.swagger.annotations.ApiOperation)3 SaCheckPermission (cn.dev33.satoken.annotation.SaCheckPermission)2 AjaxResult (com.ruoyi.common.core.web.domain.AjaxResult)2 RequiresPermissions (com.ruoyi.common.security.annotation.RequiresPermissions)2 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)1 Log (com.ruoyi.common.log.annotation.Log)1 SysUser (com.ruoyi.system.api.domain.SysUser)1 SysUserExportVo (com.ruoyi.system.domain.vo.SysUserExportVo)1 HashMap (java.util.HashMap)1