处理依赖问题

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 {
private ApplicationContext applicationContext;
@Autowired(required = false)
private IInitBaseMenu initBaseMenu;
@Autowired(required = false)
private IInitBaseUser initBaseUser;
public CommonStartup(ApplicationContext applicationContext, IInitBaseMenu initBaseMenu, IInitBaseUser initBaseUser) {
public CommonStartup(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
this.initBaseMenu = initBaseMenu;
this.initBaseUser = initBaseUser;
}
@Override

View File

@ -2,10 +2,13 @@ package ink.wgink.login.oauth2.server.service.impl;
import ink.wgink.common.base.DefaultBaseService;
import ink.wgink.exceptions.DependencyException;
import ink.wgink.exceptions.ParamsException;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.interfaces.menu.IMenuBaseService;
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.IOAuth2ClientService;
import ink.wgink.pojo.dtos.menu.MenuDTO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -27,6 +30,8 @@ public class OAuth2ClientMenuServiceImpl extends DefaultBaseService implements I
private IRoleMenuBaseService roleMenuBaseService;
@Autowired(required = false)
private IMenuBaseService menuBaseService;
@Autowired
private IOAuth2ClientService oAuth2ClientService;
@Override
public List<MenuDTO> list(String clientId, List<String> roleIds) {
@ -36,15 +41,23 @@ public class OAuth2ClientMenuServiceImpl extends DefaultBaseService implements I
if (menuBaseService == null) {
throw new DependencyException("菜单依赖为引入");
}
OAuth2ClientPO oAuth2ClientPO = oAuth2ClientService.getPO(clientId);
if (StringUtils.isBlank(oAuth2ClientPO.getMenuId())) {
throw new ParamsException("客户端未绑定菜单");
}
List<String> menuIds;
if (StringUtils.equals(roleIds.get(0), ISystemConstant.ADMIN)) {
// 管理员菜单
menuIds = roleMenuBaseService.listMenuId(ISystemConstant.ADMIN);
// 管理员菜单为空加载全部
if (menuIds.isEmpty()) {
return menuBaseService.listAllByParentId(oAuth2ClientPO.getMenuId());
}
} else {
// 其他角色菜单
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="systemSummary" column="system_summary"/>
<result property="systemIcon" column="system_icon"/>
<result property="menuId" column="menu_id"/>
</resultMap>
<resultMap id="oAuth2ClientPO" type="ink.wgink.login.oauth2.server.pojo.pos.OAuth2ClientPO">
@ -229,7 +230,6 @@
t1.client_id,
t1.client_name,
t1.resource_ids,
t1.client_secret,
t1.scope,
t1.authorized_grant_types,
t1.web_server_redirect_uri,
@ -244,6 +244,7 @@
t1.expire_time,
t1.system_summary,
t1.system_icon,
t1.menu_id,
LEFT(t1.gmt_create, 10) gmt_create
FROM
oauth_client_details t1
@ -305,7 +306,6 @@
t1.client_id,
t1.client_name,
t1.resource_ids,
t1.client_secret,
t1.scope,
t1.authorized_grant_types,
t1.web_server_redirect_uri,
@ -369,6 +369,7 @@
t1.expire_time,
t1.system_summary,
t1.system_icon,
t1.menu_id,
t1.gmt_create,
t1.creator,
t1.gmt_modified,

View File

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