ÎļþÃû´Ó laboratory-server/src/main/java/com/yuanchu/limslaboratory/service/impl/RoleManagerServiceImpl.java ÐÞ¸Ä |
| | |
| | | |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.IdUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.yuanchu.limslaboratory.mapper.MenuMapper; |
| | | import com.yuanchu.limslaboratory.mapper.RoleManageMapper; |
| | | import com.yuanchu.limslaboratory.pojo.LimitPage; |
| | | import com.yuanchu.limslaboratory.pojo.Menu; |
| | | import com.yuanchu.limslaboratory.pojo.RoleInfo; |
| | | import com.yuanchu.limslaboratory.pojo.RoleMenu; |
| | | import com.yuanchu.limslaboratory.pojo.dto.GetAllRoleAndMenuByConditionPageDto; |
| | | import com.yuanchu.limslaboratory.pojo.dto.RoleAndMenuDto; |
| | | import com.yuanchu.limslaboratory.pojo.dto.RoleInfoDto; |
| | | import com.yuanchu.limslaboratory.pojo.dto.UpdateRoleMenuDto; |
| | | import com.yuanchu.limslaboratory.service.RoleManagerService; |
| | | import com.yuanchu.limslaboratory.utils.JsonUtil; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | List<RoleAndMenuDto> roleAndMenuDtos = roleManageMapper.selectAllRoleAndMenu(dto); |
| | | roleAndMenuDtos.forEach(r->{ |
| | | List<RoleMenu>roleMenuList=r.getRoleMenuList(); |
| | | System.out.println(roleMenuList); |
| | | //System.out.println(roleMenuList); |
| | | List<RoleMenu> collect = roleMenuList.stream() |
| | | .filter(t -> t.getParentId() == 0) |
| | | .peek((menu) -> menu.setChildren(this.getRoleMenuChildren(menu, roleMenuList))) |
| | |
| | | }); |
| | | Map<String, Object>result=new HashMap<>(3); |
| | | result.put("list",roleAndMenuDtos); |
| | | int size = roleManageMapper.getRoleByName(dto.getName()).size(); |
| | | int size = roleManageMapper.getRoleInfoByName(dto.getName()).size(); |
| | | result.put("total",size); |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public boolean deleteRole(Long id) { |
| | | return roleManageMapper.updateRoleState(id)>0; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean updateRoleMenu(UpdateRoleMenuDto dto) { |
| | | //ä¿®æ¹roleè¡¨ä¿¡æ¯ |
| | | UpdateWrapper<RoleInfo>updateWrapper=new UpdateWrapper<>(); |
| | | updateWrapper.lambda() |
| | | .set(RoleInfo::getName,dto.getRoleName()) |
| | | .set(RoleInfo::getUpdateTime,DateUtil.toLocalDateTime(DateUtil.date())) |
| | | .eq(RoleInfo::getId,dto.getRoleId()); |
| | | int update = roleManageMapper.update(null, updateWrapper); |
| | | //å é¤role_menuä¿¡æ¯ |
| | | int deleteRoleMenuByRoleId = roleManageMapper.deleteRoleMenuByRoleId(dto.getRoleId()); |
| | | //æ·»å ææ°éæ©ã |
| | | dto.getMenuData().forEach(l->{ |
| | | l.setRoleId(dto.getRoleId()); |
| | | l.setCreateTime(DateUtil.toLocalDateTime(DateUtil.date())); |
| | | l.setUpdateTime(DateUtil.toLocalDateTime(DateUtil.date())); |
| | | }); |
| | | int insertBatchRoleMenu = roleManageMapper.insertBatchRoleMenu(dto.getMenuData()); |
| | | return update>0&&deleteRoleMenuByRoleId>0&&insertBatchRoleMenu>0; |
| | | } |
| | | |
| | | @Override |
| | | public RoleAndMenuDto getRoleAndMenuByRole(Long roleId) { |
| | | return roleManageMapper.selectAllRoleAndMenuByRoleId(roleId); |
| | | } |
| | | |
| | | |
| | | private List<Menu> getEnumChildren(Menu root, List<Menu> all) { |
| | | return all.stream() |