Java Code Examples for com.ruoyi.system.domain.SysDept#setAncestors()

The following examples show how to use com.ruoyi.system.domain.SysDept#setAncestors() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SysDeptServiceImpl.java    From supplierShop with MIT License 6 votes vote down vote up
/**
 * 修改保存部门信息
 * 
 * @param dept 部门信息
 * @return 结果
 */
@Override
@Transactional
public int updateDept(SysDept dept)
{
    SysDept newParentDept = deptMapper.selectDeptById(dept.getParentId());
    SysDept oldDept = 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()))
    {
        // 如果该部门是启用状态,则启用该部门的所有上级部门
        updateParentDeptStatus(dept);
    }
    return result;
}
 
Example 2
Source File: SysDeptServiceImpl.java    From ruoyiplus with MIT License 6 votes vote down vote up
/**
 * 新增保存部门信息
 * 
 * @param dept 部门信息
 * @return 结果
 */
@Override
public int insertDept(SysDept dept)
{
    if(dept.getParentId()==0){
        dept.setAncestors("0");
        return deptMapper.insertDept(dept);
    }else {
        SysDept info = deptMapper.selectDeptById(dept.getParentId());
        // 如果父节点不为"正常"状态,则不允许新增子节点
        if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) {
            throw new BusinessException("部门停用,不允许新增");
        }
        dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
        return deptMapper.insertDept(dept);
    }
}
 
Example 3
Source File: SysDeptServiceImpl.java    From ruoyiplus with MIT License 6 votes vote down vote up
/**
 * 修改保存部门信息
 * 
 * @param dept 部门信息
 * @return 结果
 */
@Override
public int updateDept(SysDept dept)
{
    SysDept info = deptMapper.selectDeptById(dept.getParentId());
    if (StringUtils.isNotNull(info))
    {
        String ancestors = info.getAncestors() + "," + info.getDeptId();
        dept.setAncestors(ancestors);
        updateDeptChildren(dept.getDeptId(), ancestors);
    }
    int result = deptMapper.updateDept(dept);
    if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()))
    {
        // 如果该部门是启用状态,则启用该部门的所有上级部门
        updateParentDeptStatus(dept);
    }
    return result;
}
 
Example 4
Source File: SysDeptServiceImpl.java    From RuoYi with Apache License 2.0 6 votes vote down vote up
/**
 * 修改保存部门信息
 *
 * @param dept 部门信息
 * @return 结果
 */
@Override
public int updateDept(SysDept dept) {
    SysDept newParentDept = deptMapper.selectDeptById(dept.getParentId());
    SysDept oldDept = selectDeptById(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 = deptMapper.updateDept(dept);
    if(UserConstants.DEPT_NORMAL.equals(dept.getStatus())){
        //如果该部门是启用状态,这启用该部门的所有上级部门
        updateParentDeptStatus(dept);
    }
    return result;
}
 
Example 5
Source File: SysDeptServiceImpl.java    From supplierShop with MIT License 5 votes vote down vote up
/**
 * 新增保存部门信息
 * 
 * @param dept 部门信息
 * @return 结果
 */
@Override
public int insertDept(SysDept dept)
{
    SysDept info = deptMapper.selectDeptById(dept.getParentId());
    // 如果父节点不为"正常"状态,则不允许新增子节点
    if (!UserConstants.DEPT_NORMAL.equals(info.getStatus()))
    {
        throw new BusinessException("部门停用,不允许新增");
    }
    dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
    return deptMapper.insertDept(dept);
}
 
Example 6
Source File: SysDeptServiceImpl.java    From supplierShop with MIT License 5 votes vote down vote up
/**
 * 修改子元素关系
 * 
 * @param deptId 被修改的部门ID
 * @param newAncestors 新的父ID集合
 * @param oldAncestors 旧的父ID集合
 */
public void updateDeptChildren(Long deptId, String newAncestors, String oldAncestors)
{
    List<SysDept> children = deptMapper.selectChildrenDeptById(deptId);
    for (SysDept child : children)
    {
        child.setAncestors(child.getAncestors().replace(oldAncestors, newAncestors));
    }
    if (children.size() > 0)
    {
        deptMapper.updateDeptChildren(children);
    }
}
 
Example 7
Source File: SysDeptServiceImpl.java    From ruoyiplus with MIT License 5 votes vote down vote up
/**
 * 修改子元素关系
 * 
 * @param deptId 部门ID
 * @param ancestors 元素列表
 */
public void updateDeptChildren(Long deptId, String ancestors)
{
    SysDept dept = new SysDept();
    dept.setParentId(deptId);
    List<SysDept> childrens = deptMapper.selectDeptList(dept);
    for (SysDept children : childrens)
    {
        children.setAncestors(ancestors + "," + dept.getParentId());
    }
    if (childrens.size() > 0)
    {
        deptMapper.updateDeptChildren(childrens);
    }
}
 
Example 8
Source File: SysDeptServiceImpl.java    From RuoYi with Apache License 2.0 5 votes vote down vote up
/**
 * 新增保存部门信息
 *
 * @param dept 部门信息
 * @return 结果
 */
@Override
public int insertDept(SysDept dept) {
    SysDept info = deptMapper.selectDeptById(dept.getParentId());
    //如果父节点不为"正常"状态,则不允许新增子节点
    if(!UserConstants.DEPT_NORMAL.equals(info.getStatus())){
        throw new BusinessException("上级部门不为正常状态,新增失败!");
    }
    dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
    return deptMapper.insertDept(dept);
}
 
Example 9
Source File: SysDeptServiceImpl.java    From RuoYi with Apache License 2.0 5 votes vote down vote up
/**
 * 修改子元素关系
 *
 * @param deptId   部门
 * @param newAncestors 新的父ID集合
 * @param oldAncestors 旧的父ID集合
 */
private void updateDeptChildren(Long deptId, String newAncestors, String oldAncestors) {
    List<SysDept> children = deptMapper.selectChildrenDeptById(deptId);
    for (SysDept child : children){
        child.setAncestors(child.getAncestors().replace(oldAncestors,newAncestors));
    }
    if (CollectionUtil.isNotEmpty(children)){
        deptMapper.updateDeptChildren(children);
    }
}