处理依赖问题

This commit is contained in:
wanggeng 2021-09-22 16:57:00 +08:00
parent e085001fd6
commit 70dd48564b
4 changed files with 34 additions and 28 deletions

View File

@ -25,13 +25,13 @@ import java.util.Map;
public class CommonStartup implements ApplicationRunner { public class CommonStartup implements ApplicationRunner {
private ApplicationContext applicationContext; private ApplicationContext applicationContext;
@Autowired(required = false)
private IInitBaseMenu initBaseMenu; private IInitBaseMenu initBaseMenu;
@Autowired(required = false)
private IInitBaseUser initBaseUser; private IInitBaseUser initBaseUser;
public CommonStartup(ApplicationContext applicationContext, IInitBaseMenu initBaseMenu, IInitBaseUser initBaseUser) { public CommonStartup(ApplicationContext applicationContext) {
this.applicationContext = applicationContext; this.applicationContext = applicationContext;
this.initBaseMenu = initBaseMenu;
this.initBaseUser = initBaseUser;
} }
@Override @Override

View File

@ -2,10 +2,13 @@ package ink.wgink.login.oauth2.server.service.impl;
import ink.wgink.common.base.DefaultBaseService; import ink.wgink.common.base.DefaultBaseService;
import ink.wgink.exceptions.DependencyException; import ink.wgink.exceptions.DependencyException;
import ink.wgink.exceptions.ParamsException;
import ink.wgink.interfaces.consts.ISystemConstant; import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.interfaces.menu.IMenuBaseService; import ink.wgink.interfaces.menu.IMenuBaseService;
import ink.wgink.interfaces.role.IRoleMenuBaseService; import ink.wgink.interfaces.role.IRoleMenuBaseService;
import ink.wgink.login.oauth2.server.pojo.pos.OAuth2ClientPO;
import ink.wgink.login.oauth2.server.service.IOAuth2ClientMenuService; import ink.wgink.login.oauth2.server.service.IOAuth2ClientMenuService;
import ink.wgink.login.oauth2.server.service.IOAuth2ClientService;
import ink.wgink.pojo.dtos.menu.MenuDTO; import ink.wgink.pojo.dtos.menu.MenuDTO;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -27,6 +30,8 @@ public class OAuth2ClientMenuServiceImpl extends DefaultBaseService implements I
private IRoleMenuBaseService roleMenuBaseService; private IRoleMenuBaseService roleMenuBaseService;
@Autowired(required = false) @Autowired(required = false)
private IMenuBaseService menuBaseService; private IMenuBaseService menuBaseService;
@Autowired
private IOAuth2ClientService oAuth2ClientService;
@Override @Override
public List<MenuDTO> list(String clientId, List<String> roleIds) { public List<MenuDTO> list(String clientId, List<String> roleIds) {
@ -36,15 +41,23 @@ public class OAuth2ClientMenuServiceImpl extends DefaultBaseService implements I
if (menuBaseService == null) { if (menuBaseService == null) {
throw new DependencyException("菜单依赖为引入"); throw new DependencyException("菜单依赖为引入");
} }
OAuth2ClientPO oAuth2ClientPO = oAuth2ClientService.getPO(clientId);
if (StringUtils.isBlank(oAuth2ClientPO.getMenuId())) {
throw new ParamsException("客户端未绑定菜单");
}
List<String> menuIds; List<String> menuIds;
if (StringUtils.equals(roleIds.get(0), ISystemConstant.ADMIN)) { if (StringUtils.equals(roleIds.get(0), ISystemConstant.ADMIN)) {
// 管理员菜单 // 管理员菜单
menuIds = roleMenuBaseService.listMenuId(ISystemConstant.ADMIN); menuIds = roleMenuBaseService.listMenuId(ISystemConstant.ADMIN);
// 管理员菜单为空加载全部
if (menuIds.isEmpty()) {
return menuBaseService.listAllByParentId(oAuth2ClientPO.getMenuId());
}
} else { } else {
// 其他角色菜单 // 其他角色菜单
menuIds = roleMenuBaseService.listMenuId(roleIds); menuIds = roleMenuBaseService.listMenuId(roleIds);
} }
return menuBaseService.listByIds(menuIds); return menuBaseService.listAllByParentIdAndIds(oAuth2ClientPO.getMenuId(), menuIds);
} }
} }

View File

@ -29,6 +29,7 @@
<result property="expireTime" column="expire_time"/> <result property="expireTime" column="expire_time"/>
<result property="systemSummary" column="system_summary"/> <result property="systemSummary" column="system_summary"/>
<result property="systemIcon" column="system_icon"/> <result property="systemIcon" column="system_icon"/>
<result property="menuId" column="menu_id"/>
</resultMap> </resultMap>
<resultMap id="oAuth2ClientPO" type="ink.wgink.login.oauth2.server.pojo.pos.OAuth2ClientPO"> <resultMap id="oAuth2ClientPO" type="ink.wgink.login.oauth2.server.pojo.pos.OAuth2ClientPO">
@ -229,7 +230,6 @@
t1.client_id, t1.client_id,
t1.client_name, t1.client_name,
t1.resource_ids, t1.resource_ids,
t1.client_secret,
t1.scope, t1.scope,
t1.authorized_grant_types, t1.authorized_grant_types,
t1.web_server_redirect_uri, t1.web_server_redirect_uri,
@ -244,6 +244,7 @@
t1.expire_time, t1.expire_time,
t1.system_summary, t1.system_summary,
t1.system_icon, t1.system_icon,
t1.menu_id,
LEFT(t1.gmt_create, 10) gmt_create LEFT(t1.gmt_create, 10) gmt_create
FROM FROM
oauth_client_details t1 oauth_client_details t1
@ -305,7 +306,6 @@
t1.client_id, t1.client_id,
t1.client_name, t1.client_name,
t1.resource_ids, t1.resource_ids,
t1.client_secret,
t1.scope, t1.scope,
t1.authorized_grant_types, t1.authorized_grant_types,
t1.web_server_redirect_uri, t1.web_server_redirect_uri,
@ -369,6 +369,7 @@
t1.expire_time, t1.expire_time,
t1.system_summary, t1.system_summary,
t1.system_icon, t1.system_icon,
t1.menu_id,
t1.gmt_create, t1.gmt_create,
t1.creator, t1.creator,
t1.gmt_modified, t1.gmt_modified,

View File

@ -240,17 +240,16 @@
} }
// 绑定菜单 // 绑定菜单
function bindMenu(clientId, menuId) { function bindMenu(clientId, menuId) {
var params = {};
var message = null; var message = null;
var successMessage = null; var successMessage = null;
if(typeof(menuId) != 'undefined' && menuId != null && menuId != '') { if(menuId) {
params.menuId = menuId;
message = '确定关联?'; message = '确定关联?';
successMessage = '关联成功'; successMessage = '关联成功';
} else { } else {
message = top.dataMessage.bind + '绑定后,根节点菜单将自动生成'; message = top.dataMessage.bind + '绑定后,根节点菜单将自动生成';
successMessage = top.dataMessage.bindSuccess; successMessage = top.dataMessage.bindSuccess;
} }
top.dialog.msg(message, { top.dialog.msg(message, {
time: 0, time: 0,
btn: [top.dataMessage.button.yes, top.dataMessage.button.no], btn: [top.dataMessage.button.yes, top.dataMessage.button.no],
@ -258,7 +257,7 @@
yes: function (index) { yes: function (index) {
top.dialog.close(index); top.dialog.close(index);
var layIndex; var layIndex;
top.restAjax.put(top.restAjax.path('api/oauth2client/update-menu-init/{clientId}', [clientId]), params, null, function (code, data) { top.restAjax.put(top.restAjax.path('api/oauth2client/update-menu-init/{clientId}?menuId={menuId}', [clientId, menuId]), {}, null, function (code, data) {
top.dialog.msg(successMessage, {time: 1000}); top.dialog.msg(successMessage, {time: 1000});
reloadTable(); reloadTable();
}, function (code, data) { }, function (code, data) {
@ -272,27 +271,20 @@
}); });
} }
// 关联菜单 // 关联菜单
function contactMenu(clientId) { function contactMenu(clientId, menuId) {
var self = this; top.dialog.open({
top.dialog.tree({ title: '选择菜单',
title: '绑定菜单', width: '300px',
apiUri: top.restAjax.path('api/menu/listztreemenus', []),
width: '250px',
height: '400px', height: '400px',
dataFilter: function(treeId, parentNode, childNodes) { url: top.restAjax.path('route/menu/list-tree-root?menuId={menuId}', [menuId]),
return childNodes;
},
onClose: function() { onClose: function() {
var selectNodes = top.dialog.dialogTreeData.selectedNodes; var menuId = top.dialog.dialogData.menuId;
if(typeof(selectNodes) != 'undefined' && selectNodes != null) { if(!menuId) {
if(selectNodes.length > 0) { return;
var selectedNode = selectNodes[0];
var menuId = selectedNode.id;
bindMenu(clientId, menuId);
}
} }
bindMenu(clientId, menuId);
} }
}); })
} }
// 解绑菜单 // 解绑菜单
function unBindMenu(clientId) { function unBindMenu(clientId) {
@ -389,7 +381,7 @@
if(layEvent === 'bindMenu') { if(layEvent === 'bindMenu') {
bindMenu(data.clientId); bindMenu(data.clientId);
} else if(layEvent === 'contactMenu') { } else if(layEvent === 'contactMenu') {
contactMenu(data.clientId); contactMenu(data.clientId, data.menuId);
} else if(layEvent === 'unBindMenu') { } else if(layEvent === 'unBindMenu') {
unBindMenu(data.clientId); unBindMenu(data.clientId);
} }