优化代码
This commit is contained in:
parent
0f09fce119
commit
550c1b4861
|
@ -1,7 +1,7 @@
|
|||
package net.maku.system.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.AllArgsConstructor;
|
||||
import net.maku.framework.common.constant.Constant;
|
||||
import net.maku.framework.common.exception.FastException;
|
||||
|
@ -31,87 +31,87 @@ import java.util.Set;
|
|||
@Service
|
||||
@AllArgsConstructor
|
||||
public class SysMenuServiceImpl extends BaseServiceImpl<SysMenuDao, SysMenuEntity> implements SysMenuService {
|
||||
private final SysRoleMenuService sysRoleMenuService;
|
||||
private final SysRoleMenuService sysRoleMenuService;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void save(SysMenuVO vo) {
|
||||
SysMenuEntity entity = SysMenuConvert.INSTANCE.convert(vo);
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void save(SysMenuVO vo) {
|
||||
SysMenuEntity entity = SysMenuConvert.INSTANCE.convert(vo);
|
||||
|
||||
// 保存菜单
|
||||
baseMapper.insert(entity);
|
||||
}
|
||||
// 保存菜单
|
||||
baseMapper.insert(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(SysMenuVO vo) {
|
||||
SysMenuEntity entity = SysMenuConvert.INSTANCE.convert(vo);
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(SysMenuVO vo) {
|
||||
SysMenuEntity entity = SysMenuConvert.INSTANCE.convert(vo);
|
||||
|
||||
// 上级菜单不能为自己
|
||||
if(entity.getId().equals(entity.getPid())){
|
||||
throw new FastException("上级菜单不能为自己");
|
||||
}
|
||||
// 上级菜单不能为自己
|
||||
if (entity.getId().equals(entity.getPid())) {
|
||||
throw new FastException("上级菜单不能为自己");
|
||||
}
|
||||
|
||||
// 更新菜单
|
||||
updateById(entity);
|
||||
}
|
||||
// 更新菜单
|
||||
updateById(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(Long id) {
|
||||
// 删除菜单
|
||||
removeById(id);
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(Long id) {
|
||||
// 删除菜单
|
||||
removeById(id);
|
||||
|
||||
// 删除角色菜单关系
|
||||
sysRoleMenuService.deleteByMenuId(id);
|
||||
}
|
||||
// 删除角色菜单关系
|
||||
sysRoleMenuService.deleteByMenuId(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysMenuVO> getMenuList(Integer type) {
|
||||
List<SysMenuEntity> menuList = baseMapper.getMenuList(type);
|
||||
@Override
|
||||
public List<SysMenuVO> getMenuList(Integer type) {
|
||||
List<SysMenuEntity> menuList = baseMapper.getMenuList(type);
|
||||
|
||||
return TreeUtils.build(SysMenuConvert.INSTANCE.convertList(menuList), Constant.ROOT);
|
||||
}
|
||||
return TreeUtils.build(SysMenuConvert.INSTANCE.convertList(menuList), Constant.ROOT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysMenuVO> getUserMenuList(UserDetail user, Integer type) {
|
||||
List<SysMenuEntity> menuList;
|
||||
@Override
|
||||
public List<SysMenuVO> getUserMenuList(UserDetail user, Integer type) {
|
||||
List<SysMenuEntity> menuList;
|
||||
|
||||
// 系统管理员,拥有最高权限
|
||||
if(user.getSuperAdmin().equals(SuperAdminEnum.YES.getValue())){
|
||||
menuList = baseMapper.getMenuList(type);
|
||||
}else {
|
||||
menuList = baseMapper.getUserMenuList(user.getId(), type);
|
||||
}
|
||||
// 系统管理员,拥有最高权限
|
||||
if (user.getSuperAdmin().equals(SuperAdminEnum.YES.getValue())) {
|
||||
menuList = baseMapper.getMenuList(type);
|
||||
} else {
|
||||
menuList = baseMapper.getUserMenuList(user.getId(), type);
|
||||
}
|
||||
|
||||
return TreeUtils.build(SysMenuConvert.INSTANCE.convertList(menuList));
|
||||
}
|
||||
return TreeUtils.build(SysMenuConvert.INSTANCE.convertList(menuList));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getSubMenuCount(Long pid) {
|
||||
return count(new QueryWrapper<SysMenuEntity>().eq("pid", pid));
|
||||
}
|
||||
@Override
|
||||
public Long getSubMenuCount(Long pid) {
|
||||
return count(new LambdaQueryWrapper<SysMenuEntity>().eq(SysMenuEntity::getPid, pid));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getUserAuthority(UserDetail user) {
|
||||
// 系统管理员,拥有最高权限
|
||||
List<String> authorityList;
|
||||
if(user.getSuperAdmin().equals(SuperAdminEnum.YES.getValue())) {
|
||||
authorityList = baseMapper.getAuthorityList();
|
||||
}else{
|
||||
authorityList = baseMapper.getUserAuthorityList(user.getId());
|
||||
}
|
||||
@Override
|
||||
public Set<String> getUserAuthority(UserDetail user) {
|
||||
// 系统管理员,拥有最高权限
|
||||
List<String> authorityList;
|
||||
if (user.getSuperAdmin().equals(SuperAdminEnum.YES.getValue())) {
|
||||
authorityList = baseMapper.getAuthorityList();
|
||||
} else {
|
||||
authorityList = baseMapper.getUserAuthorityList(user.getId());
|
||||
}
|
||||
|
||||
// 用户权限列表
|
||||
Set<String> permsSet = new HashSet<>();
|
||||
for(String authority : authorityList){
|
||||
if(StrUtil.isBlank(authority)){
|
||||
continue;
|
||||
}
|
||||
permsSet.addAll(Arrays.asList(authority.trim().split(",")));
|
||||
}
|
||||
// 用户权限列表
|
||||
Set<String> permsSet = new HashSet<>();
|
||||
for (String authority : authorityList) {
|
||||
if (StrUtil.isBlank(authority)) {
|
||||
continue;
|
||||
}
|
||||
permsSet.addAll(Arrays.asList(authority.trim().split(",")));
|
||||
}
|
||||
|
||||
return permsSet;
|
||||
}
|
||||
return permsSet;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user