|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSON; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.moral.api.entity.ManageAccount; | 
|---|
|  |  |  | import com.moral.api.entity.ManageAccountRole; | 
|---|
|  |  |  | import com.moral.api.entity.ManageLog; | 
|---|
|  |  |  | import com.moral.api.entity.ManageRole; | 
|---|
|  |  |  | import com.moral.api.mapper.ManageAccountRoleMapper; | 
|---|
|  |  |  | import com.moral.api.mapper.ManageLogMapper; | 
|---|
|  |  |  | import com.moral.api.mapper.ManageRoleMapper; | 
|---|
|  |  |  | import com.moral.api.mapper.ManageRoleMenuMapper; | 
|---|
|  |  |  | import com.moral.api.entity.*; | 
|---|
|  |  |  | import com.moral.api.mapper.*; | 
|---|
|  |  |  | import com.moral.api.pojo.dto.login.AccountInfoDTO; | 
|---|
|  |  |  | import com.moral.api.service.ManageRoleService; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired(required = false) | 
|---|
|  |  |  | private ManageRoleMapper manageRoleMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired(required = false) | 
|---|
|  |  |  | private ManageMenuMapper manageMenuMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired(required = false) | 
|---|
|  |  |  | private ManageRoleMenuMapper manageRoleMenuMapper; | 
|---|
|  |  |  | 
|---|
|  |  |  | manageRoleMapper.insertOne(manageRole); | 
|---|
|  |  |  | ManageRole manageRoleIns = manageRoleMapper.getManageRoleByName(manageRole.getName()); | 
|---|
|  |  |  | int role_id = manageRoleIns.getId(); | 
|---|
|  |  |  | List insertList = new ArrayList(); | 
|---|
|  |  |  | for (Object temp: list) { | 
|---|
|  |  |  | Map<String,Integer> insertMap = new HashMap<>(); | 
|---|
|  |  |  | insertMap.put("role_id",role_id); | 
|---|
|  |  |  | insertMap.put("menu_id",Integer.parseInt(temp.toString())); | 
|---|
|  |  |  | insertList.add(insertMap); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //判断在新建角色时,是否添加菜单 | 
|---|
|  |  |  | if (insertList.size()>0){ | 
|---|
|  |  |  | if (list.size()>0){ | 
|---|
|  |  |  | //补充父菜单 | 
|---|
|  |  |  | List supplementList = new ArrayList(); | 
|---|
|  |  |  | supplementList.addAll(list); | 
|---|
|  |  |  | for (int i=0;i<supplementList.size();i++) { | 
|---|
|  |  |  | supplementList.addAll(supplementParentMenus(Integer.parseInt(supplementList.get(i).toString()))); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | LinkedHashSet<Object> hashSet = new LinkedHashSet<>(supplementList); | 
|---|
|  |  |  | ArrayList<Object> menuList = new ArrayList<>(hashSet); | 
|---|
|  |  |  | List insertList = new ArrayList(); | 
|---|
|  |  |  | for (Object temp: menuList) { | 
|---|
|  |  |  | Map<String,Integer> insertMap = new HashMap<>(); | 
|---|
|  |  |  | insertMap.put("role_id",role_id); | 
|---|
|  |  |  | insertMap.put("menu_id",Integer.parseInt(temp.toString())); | 
|---|
|  |  |  | insertList.add(insertMap); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | manageRoleMenuMapper.insertBatch(insertList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //操作插入日志 | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @Description: 补充父菜单 | 
|---|
|  |  |  | * @Param: [list, menuId]list:menuId集合 | 
|---|
|  |  |  | * @return: void | 
|---|
|  |  |  | * @Author: 李子杰 | 
|---|
|  |  |  | * @Date: 2021/4/28 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private List supplementParentMenus(int menuId) { | 
|---|
|  |  |  | List list = new ArrayList(); | 
|---|
|  |  |  | ManageMenu manageMenu = manageMenuMapper.getManageMenuById(menuId); | 
|---|
|  |  |  | if (manageMenu.getParentId()!=0){ | 
|---|
|  |  |  | list.add(manageMenu.getParentId()); | 
|---|
|  |  |  | list.addAll(supplementParentMenus(manageMenu.getParentId())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return list; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|