Search in sources :

Example 11 with SysDept

use of com.ruoyi.project.system.domain.SysDept in project RuoYi-Vue-Oracle by yangzongzhuan.

the class SysDeptController method roleDeptTreeselect.

/**
 * 加载对应角色部门列表树
 */
@GetMapping(value = "/roleDeptTreeselect/{roleId}")
public AjaxResult roleDeptTreeselect(@PathVariable("roleId") Long roleId) {
    List<SysDept> depts = deptService.selectDeptList(new SysDept());
    AjaxResult ajax = AjaxResult.success();
    ajax.put("checkedKeys", deptService.selectDeptListByRoleId(roleId));
    ajax.put("depts", deptService.buildDeptTreeSelect(depts));
    return ajax;
}
Also used : AjaxResult(com.ruoyi.framework.web.domain.AjaxResult) SysDept(com.ruoyi.project.system.domain.SysDept) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 12 with SysDept

use of com.ruoyi.project.system.domain.SysDept in project RuoYi-Vue-fast by yangzongzhuan.

the class SysDeptServiceImpl method buildDeptTree.

/**
 * 构建前端所需要树结构
 *
 * @param depts 部门列表
 * @return 树结构列表
 */
@Override
public List<SysDept> buildDeptTree(List<SysDept> depts) {
    List<SysDept> returnList = new ArrayList<SysDept>();
    List<Long> tempList = new ArrayList<Long>();
    for (SysDept dept : depts) {
        tempList.add(dept.getDeptId());
    }
    for (SysDept dept : depts) {
        // 如果是顶级节点, 遍历该父节点的所有子节点
        if (!tempList.contains(dept.getParentId())) {
            recursionFn(depts, dept);
            returnList.add(dept);
        }
    }
    if (returnList.isEmpty()) {
        returnList = depts;
    }
    return returnList;
}
Also used : SysDept(com.ruoyi.project.system.domain.SysDept) ArrayList(java.util.ArrayList)

Example 13 with SysDept

use of com.ruoyi.project.system.domain.SysDept in project RuoYi-Vue-fast by yangzongzhuan.

the class SysDeptServiceImpl method recursionFn.

/**
 * 递归列表
 */
private void recursionFn(List<SysDept> list, SysDept t) {
    // 得到子节点列表
    List<SysDept> childList = getChildList(list, t);
    t.setChildren(childList);
    for (SysDept tChild : childList) {
        if (hasChild(list, tChild)) {
            recursionFn(list, tChild);
        }
    }
}
Also used : SysDept(com.ruoyi.project.system.domain.SysDept)

Example 14 with SysDept

use of com.ruoyi.project.system.domain.SysDept in project RuoYi-Vue-fast by yangzongzhuan.

the class SysDeptServiceImpl method getChildList.

/**
 * 得到子节点列表
 */
private List<SysDept> getChildList(List<SysDept> list, SysDept t) {
    List<SysDept> tlist = new ArrayList<SysDept>();
    Iterator<SysDept> it = list.iterator();
    while (it.hasNext()) {
        SysDept n = (SysDept) it.next();
        if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getDeptId().longValue()) {
            tlist.add(n);
        }
    }
    return tlist;
}
Also used : SysDept(com.ruoyi.project.system.domain.SysDept) ArrayList(java.util.ArrayList)

Example 15 with SysDept

use of com.ruoyi.project.system.domain.SysDept in project RuoYi-Vue-fast by yangzongzhuan.

the class SysDeptServiceImpl method updateDept.

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

Aggregations

SysDept (com.ruoyi.project.system.domain.SysDept)18 ServiceException (com.ruoyi.common.exception.ServiceException)4 ArrayList (java.util.ArrayList)4 GetMapping (org.springframework.web.bind.annotation.GetMapping)4 AjaxResult (com.ruoyi.framework.web.domain.AjaxResult)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2