| | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.StringPool; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.xcong.farmer.cms.common.response.Result; |
| | | import com.xcong.farmer.cms.modules.system.dto.AdminAddMenuDto; |
| | | import com.xcong.farmer.cms.modules.system.dto.AdminDeleteDto; |
| | | import com.xcong.farmer.cms.modules.system.dto.AdminMenuDto; |
| | | import com.xcong.farmer.cms.modules.system.dto.AdminUpdateMenuDto; |
| | | import com.xcong.farmer.cms.modules.system.entity.MenuEntity; |
| | | import com.xcong.farmer.cms.modules.system.entity.RoleMenuEntity; |
| | | import com.xcong.farmer.cms.modules.system.entity.UserEntity; |
| | | import com.xcong.farmer.cms.modules.system.entity.UserRoleEntity; |
| | | import com.xcong.farmer.cms.modules.system.mapper.MenuMapper; |
| | | import com.xcong.farmer.cms.modules.system.mapper.RoleMenuMapper; |
| | | import com.xcong.farmer.cms.modules.system.service.IMenuService; |
| | | import com.xcong.farmer.cms.modules.system.util.LoginUserUtil; |
| | | import com.xcong.farmer.cms.modules.system.vo.AdminMenuVo; |
| | | import com.xcong.farmer.cms.modules.system.vo.AdminSeeMenuInfoVo; |
| | | import com.xcong.farmer.cms.modules.system.vo.AdminUserMenuVo; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | @Override |
| | | public Result getMenuInPage(AdminMenuDto adminMenuDto) { |
| | | Page<AdminMenuVo> page = new Page<>(adminMenuDto.getPageNum(), adminMenuDto.getPageSize()); |
| | | UserEntity userlogin = LoginUserUtil.getLoginUser(); |
| | | MenuEntity menuEntity = new MenuEntity(); |
| | | menuEntity.setParentId(MenuEntity.PARENTID_DEFAULT); |
| | | // menuEntity.setBelongId(userlogin.getBelongId()==null?UserEntity.USER_BELONG_TOP:userlogin.getBelongId()); |
| | | IPage<AdminMenuVo> list = this.baseMapper.selectAdminMenuVoInPage(page,menuEntity); |
| | | List<AdminMenuVo> records = list.getRecords(); |
| | | if(CollUtil.isNotEmpty(records)){ |
| | |
| | | @Override |
| | | @Transactional |
| | | public Result addMenu(AdminAddMenuDto adminAddMenuDto) { |
| | | UserEntity userlogin = LoginUserUtil.getLoginUser(); |
| | | String menuName = adminAddMenuDto.getMenuName(); |
| | | if(StrUtil.isEmpty(menuName)){ |
| | | return Result.fail("请输入菜单名称"); |
| | | } |
| | | Integer menuType = adminAddMenuDto.getMenuType(); |
| | | if(ObjectUtil.isEmpty(menuType)){ |
| | | return Result.fail("请输入菜单类型"); |
| | | } |
| | | MenuEntity menuEntity = new MenuEntity(); |
| | | menuEntity.setMenuName(menuName); |
| | | menuEntity.setMenuType(menuType); |
| | |
| | | return Result.fail("菜单不存在"); |
| | | } |
| | | String menuName = adminUpdateMenuDto.getMenuName(); |
| | | if(StrUtil.isEmpty(menuName)){ |
| | | return Result.fail("请输入菜单名称"); |
| | | } |
| | | menuEntity.setMenuName(menuName); |
| | | Integer menuType = adminUpdateMenuDto.getMenuType(); |
| | | if(ObjectUtil.isEmpty(menuType)){ |
| | | return Result.fail("请输入菜单类型"); |
| | | } |
| | | menuEntity.setMenuType(menuType); |
| | | String routeUrl = adminUpdateMenuDto.getRouteUrl(); |
| | | if(StrUtil.isNotEmpty(routeUrl)){ |
| | |
| | | this.baseMapper.updateById(menuEntity); |
| | | return Result.ok("更新成功"); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public Result delObjs(AdminDeleteDto adminDeleteDto) { |
| | | String ids = adminDeleteDto.getIds(); |
| | | if(StrUtil.isNotEmpty(ids)){ |
| | | String[] menuIds = ids.split(StringPool.COMMA); |
| | | for(String menuIdStr : menuIds){ |
| | | Long menuId = Long.valueOf(menuIdStr); |
| | | QueryWrapper<MenuEntity> objectQueryWrapper = new QueryWrapper<>(); |
| | | objectQueryWrapper.eq("parent_id",menuId); |
| | | this.baseMapper.delete(objectQueryWrapper); |
| | | |
| | | this.baseMapper.deleteById(menuId); |
| | | |
| | | roleMenuMapper.deleteByMenuId(menuId); |
| | | } |
| | | } |
| | | return Result.ok("删除成功"); |
| | | } |
| | | |
| | | @Override |
| | | public Result getMenuInList() { |
| | | UserEntity userlogin = LoginUserUtil.getLoginUser(); |
| | | List<AdminMenuVo> records = this.baseMapper.selectAdminMenuVoInListByParentId(MenuEntity.PARENTID_DEFAULT); |
| | | if(CollUtil.isNotEmpty(records)){ |
| | | for(AdminMenuVo adminMenuVo : records){ |
| | | Long id = adminMenuVo.getId(); |
| | | QueryWrapper<MenuEntity> objectQueryWrapper = new QueryWrapper<>(); |
| | | objectQueryWrapper.eq("parent_id",id); |
| | | List<MenuEntity> menuEntities = this.baseMapper.selectList(objectQueryWrapper); |
| | | List<AdminMenuVo> adminMenuVoChilds = new ArrayList<>(); |
| | | if(CollUtil.isNotEmpty(menuEntities)){ |
| | | for(MenuEntity menuEntityChild : menuEntities){ |
| | | AdminMenuVo child = new AdminMenuVo(); |
| | | child.setId(menuEntityChild.getId()); |
| | | child.setMenuName(menuEntityChild.getMenuName()); |
| | | child.setMenuType(menuEntityChild.getMenuType()); |
| | | child.setRouteUrl(menuEntityChild.getRouteUrl()); |
| | | child.setOrderNum(menuEntityChild.getOrderNum()); |
| | | child.setCreateTime(menuEntityChild.getCreateTime()); |
| | | adminMenuVoChilds.add(child); |
| | | } |
| | | } |
| | | adminMenuVo.setChild(adminMenuVoChilds); |
| | | } |
| | | } |
| | | |
| | | if(CollUtil.isNotEmpty(records)){ |
| | | for(AdminMenuVo adminMenuVo : records){ |
| | | List<AdminMenuVo> child = adminMenuVo.getChild(); |
| | | if(CollUtil.isNotEmpty(child)){ |
| | | List<Long> menuIds = new ArrayList<>(); |
| | | for(AdminMenuVo adminMenuVoChild : child){ |
| | | Long id = adminMenuVoChild.getId(); |
| | | menuIds.add(id); |
| | | } |
| | | List<AdminMenuVo> adminMenuVoByOrderNum = this.baseMapper.selectAdminMenuVoOrderByOrderNum(menuIds); |
| | | adminMenuVo.setChild(adminMenuVoByOrderNum); |
| | | } |
| | | } |
| | | } |
| | | return Result.ok(records); |
| | | } |
| | | } |