| | |
| | | package com.ruoyi.system.service.impl.sys; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import com.ruoyi.common.core.constant.UserConstants; |
| | | import com.ruoyi.common.core.exception.ServiceException; |
| | | import com.ruoyi.common.core.text.Convert; |
| | |
| | | import com.ruoyi.system.api.domain.poji.sys.SysDept; |
| | | import com.ruoyi.system.api.domain.poji.sys.SysRole; |
| | | import com.ruoyi.system.api.domain.poji.sys.SysUser; |
| | | import com.ruoyi.system.domain.pojo.sys.SysDeptMenu; |
| | | import com.ruoyi.system.domain.vo.TreeSelect; |
| | | import com.ruoyi.system.mapper.sys.SysDeptMapper; |
| | | import com.ruoyi.system.mapper.sys.SysDeptMenuMapper; |
| | | import com.ruoyi.system.mapper.sys.SysRoleMapper; |
| | | import com.ruoyi.system.service.sys.ISysDeptService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 部门管理 服务实现 |
| | | * |
| | | * @author ruoyi |
| | | * @author jqs |
| | | */ |
| | | @Service |
| | | public class SysDeptServiceImpl implements ISysDeptService |
| | |
| | | |
| | | @Autowired |
| | | private SysRoleMapper roleMapper; |
| | | |
| | | @Autowired |
| | | private SysDeptMenuMapper deptMenuMapper; |
| | | |
| | | /** |
| | | * 查询部门管理数据 |
| | |
| | | throw new ServiceException("部门停用,不允许新增"); |
| | | } |
| | | dept.setAncestors(info.getAncestors() + "," + dept.getParentId()); |
| | | return deptMapper.insertDept(dept); |
| | | //新增部门 |
| | | int i = deptMapper.insertDept(dept); |
| | | if(dept.getMenuIds()!=null||dept.getStaffMenuIds()!=null){ |
| | | return insertDeptMenu(dept); |
| | | }else{ |
| | | return i; |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 新增角色菜单信息 |
| | | * |
| | | * @param dept 部门对象 |
| | | */ |
| | | public int insertDeptMenu(SysDept dept) |
| | | { |
| | | int rows = 1; |
| | | // 新增用户与角色管理 |
| | | List<SysDeptMenu> list = new ArrayList<SysDeptMenu>(); |
| | | for (Long menuId : dept.getMenuIds()) |
| | | { |
| | | SysDeptMenu rm = new SysDeptMenu(); |
| | | rm.setDeptId(dept.getDeptId()); |
| | | rm.setMenuId(menuId); |
| | | rm.setMenuFrom(1); |
| | | list.add(rm); |
| | | } |
| | | for(Long menuId : dept.getStaffMenuIds()){ |
| | | SysDeptMenu rm = new SysDeptMenu(); |
| | | rm.setDeptId(dept.getDeptId()); |
| | | rm.setMenuId(menuId); |
| | | rm.setMenuFrom(2); |
| | | list.add(rm); |
| | | } |
| | | if (list.size() > 0) |
| | | { |
| | | rows = deptMenuMapper.batchDeptMenu(list); |
| | | } |
| | | return rows; |
| | | } |
| | | |
| | | /** |
| | |
| | | // 如果该部门是启用状态,则启用该部门的所有上级部门 |
| | | updateParentDeptStatusNormal(dept); |
| | | } |
| | | // 删除角色与菜单关联 |
| | | deptMenuMapper.deleteDeptMenuByDeptId(dept.getDeptId()); |
| | | insertDeptMenu(dept); |
| | | return result; |
| | | } |
| | | |