权限修改
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
package com.czg.service.account.mapper;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.czg.account.entity.CashMenu;
|
||||
|
||||
/**
|
||||
* 映射层。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-05-26
|
||||
*/
|
||||
public interface CashMenuMapper extends BaseMapper<CashMenu> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.czg.service.account.service.impl;
|
||||
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.account.entity.CashMenu;
|
||||
import com.czg.account.service.CashMenuService;
|
||||
import com.czg.service.account.mapper.CashMenuMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 服务层实现。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-05-26
|
||||
*/
|
||||
@Service
|
||||
public class CashMenuServiceImpl extends ServiceImpl<CashMenuMapper, CashMenu> implements CashMenuService{
|
||||
|
||||
}
|
||||
@@ -6,8 +6,10 @@ import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.czg.account.dto.menu.MenuAddDTO;
|
||||
import com.czg.account.dto.menu.MenuEditDTO;
|
||||
import com.czg.account.entity.CashMenu;
|
||||
import com.czg.account.entity.SysMenu;
|
||||
import com.czg.account.entity.SysUsersRoles;
|
||||
import com.czg.account.service.CashMenuService;
|
||||
import com.czg.account.service.SysMenuService;
|
||||
import com.czg.account.vo.MenuVO;
|
||||
import com.czg.exception.ApiNotPrintException;
|
||||
@@ -35,6 +37,8 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
||||
private SysMenuMapper sysMenuMapper;
|
||||
@Resource
|
||||
private SysUsersRolesMapper sysUsersRolesMapper;
|
||||
@Resource
|
||||
private CashMenuService cashMenuService;
|
||||
|
||||
@Override
|
||||
public List<MenuVO> getMenu() {
|
||||
@@ -177,4 +181,9 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
||||
}
|
||||
return permissions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CashMenu> getCashAll() {
|
||||
return cashMenuService.list();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,11 @@ import com.czg.account.dto.menu.MenuApiInfoItemDTO;
|
||||
import com.czg.account.dto.role.RoleAddDTO;
|
||||
import com.czg.account.dto.role.RoleEditDTO;
|
||||
import com.czg.account.dto.role.RolePermissionDTO;
|
||||
import com.czg.account.entity.CashMenu;
|
||||
import com.czg.account.entity.SysMenu;
|
||||
import com.czg.account.entity.SysRole;
|
||||
import com.czg.account.entity.SysRolesMenus;
|
||||
import com.czg.account.service.CashMenuService;
|
||||
import com.czg.account.service.SysMenuService;
|
||||
import com.czg.account.service.SysRoleService;
|
||||
import com.czg.account.service.SysRolesMenusService;
|
||||
@@ -43,6 +45,8 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> imp
|
||||
private SysMenuService sysMenuService;
|
||||
@Resource
|
||||
private SysRolesMenusService sysRolesMenusService;
|
||||
@Resource
|
||||
private CashMenuService cashMenuService;
|
||||
|
||||
@Override
|
||||
public List<SysRole> getByUserId(Long id) {
|
||||
@@ -125,20 +129,57 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> imp
|
||||
}
|
||||
|
||||
public boolean addMenu(Long roleId, List<Long> menuIds, boolean isAdmin) {
|
||||
List<SysMenu> sysMenuList = sysMenuService.queryChain().in(SysMenu::getMenuId, menuIds).list();
|
||||
if (sysMenuList.size() != menuIds.size()) {
|
||||
throw new ApiNotPrintException("菜单id包含错误id");
|
||||
}
|
||||
|
||||
ArrayList<MenuApiInfoItemDTO> apiPathList = new ArrayList<>();
|
||||
sysMenuList.forEach(item -> {
|
||||
if (StrUtil.isNotBlank(item.getApiInfo())) {
|
||||
List<MenuApiInfoItemDTO> itemDTOS = JSONArray.parseArray(item.getApiInfo()).toJavaList(MenuApiInfoItemDTO.class);
|
||||
if (!itemDTOS.isEmpty()) {
|
||||
apiPathList.addAll(itemDTOS);
|
||||
|
||||
ArrayList<SysRolesMenus> rolesMenus = new ArrayList<>();
|
||||
if (isAdmin) {
|
||||
List<SysMenu> sysMenuList = sysMenuService.queryChain().in(SysMenu::getMenuId, menuIds).list();
|
||||
if (sysMenuList.size() != menuIds.size()) {
|
||||
throw new ApiNotPrintException("菜单id包含错误id");
|
||||
}
|
||||
|
||||
sysMenuList.forEach(item -> {
|
||||
if (StrUtil.isNotBlank(item.getApiInfo())) {
|
||||
List<MenuApiInfoItemDTO> itemDTOS = JSONArray.parseArray(item.getApiInfo()).toJavaList(MenuApiInfoItemDTO.class);
|
||||
if (!itemDTOS.isEmpty()) {
|
||||
apiPathList.addAll(itemDTOS);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
for (SysMenu sysMenu : sysMenuList) {
|
||||
long count = sysRolesMenusService.count(new QueryWrapper().eq(SysRolesMenus::getMenuId, sysMenu.getMenuId())
|
||||
.eq(SysRolesMenus::getRoleId, roleId)
|
||||
.eq(SysRolesMenus::getType, isAdmin ? 0 : 1));
|
||||
if (count == 0) {
|
||||
rolesMenus.add(new SysRolesMenus(sysMenu.getMenuId(), roleId, isAdmin ? 0 : 1));
|
||||
}
|
||||
}
|
||||
});
|
||||
}else {
|
||||
List<CashMenu> list = cashMenuService.queryChain().in(CashMenu::getMenuId, menuIds).list();
|
||||
if (list.size() != menuIds.size()) {
|
||||
throw new ApiNotPrintException("菜单id包含错误id");
|
||||
}
|
||||
|
||||
list.forEach(item -> {
|
||||
if (StrUtil.isNotBlank(item.getApiInfo())) {
|
||||
List<MenuApiInfoItemDTO> itemDTOS = JSONArray.parseArray(item.getApiInfo()).toJavaList(MenuApiInfoItemDTO.class);
|
||||
if (!itemDTOS.isEmpty()) {
|
||||
apiPathList.addAll(itemDTOS);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
for (CashMenu sysMenu : list) {
|
||||
long count = sysRolesMenusService.count(new QueryWrapper().eq(SysRolesMenus::getMenuId, sysMenu.getMenuId())
|
||||
.eq(SysRolesMenus::getRoleId, roleId)
|
||||
.eq(SysRolesMenus::getType, isAdmin ? 0 : 1));
|
||||
if (count == 0) {
|
||||
rolesMenus.add(new SysRolesMenus(sysMenu.getMenuId(), roleId, isAdmin ? 0 : 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!apiPathList.isEmpty()) {
|
||||
String string = buildLikeSql(apiPathList, "url");
|
||||
@@ -146,20 +187,19 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> imp
|
||||
wrapper.where(string);
|
||||
List<SysMenu> sysMenus = sysMenuService.list(wrapper);
|
||||
if (!sysMenus.isEmpty()) {
|
||||
sysMenuList.addAll(sysMenus);
|
||||
for (SysMenu sysMenu : sysMenus) {
|
||||
long count = sysRolesMenusService.count(new QueryWrapper().eq(SysRolesMenus::getMenuId, sysMenu.getMenuId())
|
||||
.eq(SysRolesMenus::getRoleId, roleId)
|
||||
.eq(SysRolesMenus::getType, isAdmin ? 0 : 1));
|
||||
if (count == 0) {
|
||||
rolesMenus.add(new SysRolesMenus(sysMenu.getMenuId(), roleId, isAdmin ? 0 : 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ArrayList<SysRolesMenus> rolesMenus = new ArrayList<>();
|
||||
for (SysMenu sysMenu : sysMenuList) {
|
||||
long count = sysRolesMenusService.count(new QueryWrapper().eq(SysRolesMenus::getMenuId, sysMenu.getMenuId())
|
||||
.eq(SysRolesMenus::getRoleId, roleId)
|
||||
.eq(SysRolesMenus::getType, isAdmin ? 0 : 1));
|
||||
if (count == 0) {
|
||||
rolesMenus.add(new SysRolesMenus(sysMenu.getMenuId(), roleId, isAdmin ? 0 : 1));
|
||||
}
|
||||
}
|
||||
return sysRolesMenusService.saveBatch(rolesMenus);
|
||||
|
||||
return rolesMenus.isEmpty() || sysRolesMenusService.saveBatch(rolesMenus);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.czg.service.account.mapper.CashMenuMapper">
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user