mirror of https://gitee.com/stylefeng/guns
【7.0.2】删除初始化admin过程,修改组织机构树获取的接口,修改登录接口名字
parent
1bccac5d5d
commit
21ffd0c9e8
|
@ -1,36 +0,0 @@
|
|||
package cn.stylefeng.guns.core.listener;
|
||||
|
||||
import cn.stylefeng.guns.core.consts.ProjectConstants;
|
||||
import cn.stylefeng.guns.modular.system.index.service.InitAdminService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 项目启动后初始化超级管理员
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2020/12/17 21:44
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class SuperAdminInitListener implements ApplicationListener<ApplicationReadyEvent>, Ordered {
|
||||
|
||||
@Resource
|
||||
private InitAdminService initAdminService;
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
|
||||
initAdminService.initSuperAdmin();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return ProjectConstants.SUPER_ADMIN_INIT_LISTENER_SORT;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
package cn.stylefeng.guns.modular.system.index.service;
|
||||
|
||||
import cn.stylefeng.guns.core.consts.ProjectConstants;
|
||||
import cn.stylefeng.roses.kernel.system.modular.resource.entity.SysResource;
|
||||
import cn.stylefeng.roses.kernel.system.modular.resource.service.SysResourceService;
|
||||
import cn.stylefeng.roses.kernel.system.modular.role.entity.SysRole;
|
||||
import cn.stylefeng.roses.kernel.system.modular.role.entity.SysRoleResource;
|
||||
import cn.stylefeng.roses.kernel.system.modular.role.service.SysRoleResourceService;
|
||||
import cn.stylefeng.roses.kernel.system.modular.role.service.SysRoleService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 初始化admin管理员的服务
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2020/12/17 21:56
|
||||
*/
|
||||
@Service
|
||||
public class InitAdminService {
|
||||
|
||||
@Resource
|
||||
private SysRoleService sysRoleService;
|
||||
|
||||
@Resource
|
||||
private SysResourceService sysResourceService;
|
||||
|
||||
@Resource
|
||||
private SysRoleResourceService sysRoleResourceService;
|
||||
|
||||
/**
|
||||
* 初始化超级管理员,超级管理员拥有最高权限
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2020/12/17 21:57
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void initSuperAdmin() {
|
||||
|
||||
// 找到超级管理员的角色id
|
||||
LambdaQueryWrapper<SysRole> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(SysRole::getRoleCode, ProjectConstants.SUPER_ADMIN_ROLE_CODE);
|
||||
SysRole superAdminRole = sysRoleService.getOne(queryWrapper);
|
||||
|
||||
// 删除这个角色绑定的所有资源
|
||||
LambdaUpdateWrapper<SysRoleResource> sysRoleResourceLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||
sysRoleResourceLambdaUpdateWrapper.eq(SysRoleResource::getRoleId, superAdminRole.getRoleId());
|
||||
sysRoleResourceService.remove(sysRoleResourceLambdaUpdateWrapper);
|
||||
|
||||
// 找到所有Resource,将所有资源赋给这个角色
|
||||
LambdaQueryWrapper<SysResource> sysResourceLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
sysResourceLambdaQueryWrapper.select(SysResource::getResourceCode);
|
||||
List<SysResource> resources = sysResourceService.list(sysResourceLambdaQueryWrapper);
|
||||
|
||||
ArrayList<SysRoleResource> sysRoleResources = new ArrayList<>();
|
||||
for (SysResource resource : resources) {
|
||||
SysRoleResource sysRoleResource = new SysRoleResource();
|
||||
sysRoleResource.setResourceCode(resource.getResourceCode());
|
||||
sysRoleResource.setRoleId(superAdminRole.getRoleId());
|
||||
sysRoleResources.add(sysRoleResource);
|
||||
}
|
||||
sysRoleResourceService.saveBatch(sysRoleResources, sysRoleResources.size());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,20 +1,9 @@
|
|||
package cn.stylefeng.guns.modular.system.login;
|
||||
|
||||
import cn.stylefeng.roses.kernel.auth.api.AuthServiceApi;
|
||||
import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
|
||||
import cn.stylefeng.roses.kernel.auth.api.pojo.auth.LoginRequest;
|
||||
import cn.stylefeng.roses.kernel.auth.api.pojo.auth.LoginResponse;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 登录相关的界面渲染
|
||||
|
@ -26,9 +15,6 @@ import javax.annotation.Resource;
|
|||
@ApiResource(name = "登录相关的接口")
|
||||
public class LoginViewController {
|
||||
|
||||
@Resource
|
||||
private AuthServiceApi authServiceApi;
|
||||
|
||||
/**
|
||||
* 登录界面
|
||||
*
|
||||
|
@ -44,31 +30,4 @@ public class LoginViewController {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录接口
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2020/12/27 17:10
|
||||
*/
|
||||
@PostResource(name = "登录接口", path = "/loginAction", requiredPermission = false, requiredLogin = false)
|
||||
@ResponseBody
|
||||
public ResponseData loginAction(@RequestBody @Validated LoginRequest loginRequest) {
|
||||
LoginResponse loginResponse = authServiceApi.login(loginRequest);
|
||||
return new SuccessResponseData(loginResponse.getToken());
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户登出
|
||||
*
|
||||
* @return 登出成功
|
||||
* @author majianguo
|
||||
* @date 2020/12/4 上午9:05
|
||||
*/
|
||||
@PostResource(name = "登出接口", path = "/logout", requiredPermission = false)
|
||||
@ResponseBody
|
||||
public ResponseData logoutPage() {
|
||||
authServiceApi.logout();
|
||||
return new SuccessResponseData();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ layui.use(['layer', 'form', 'table', 'util', 'admin', 'tree', 'dropdown', 'xmSel
|
|||
|
||||
/* 渲染树形 */
|
||||
function renderTree() {
|
||||
$.get(Feng.ctxPath + '/hrOrganization/treeLayui', function (res) {
|
||||
$.get(Feng.ctxPath + '/hrOrganization/tree', function (res) {
|
||||
tree.render({
|
||||
elem: '#organizationTree',
|
||||
onlyIconControl: true,
|
||||
|
@ -136,4 +136,4 @@ layui.use(['layer', 'form', 'table', 'util', 'admin', 'tree', 'dropdown', 'xmSel
|
|||
return false;
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
|
|
@ -7,7 +7,7 @@ layui.use(['form', 'admin', 'HttpRequest', 'xmSelect'], function () {
|
|||
var organizationXmSel;
|
||||
|
||||
// 初始化组织树
|
||||
new HttpRequest(Feng.ctxPath + "/hrOrganization/treeLayui", 'get', function (data) {
|
||||
new HttpRequest(Feng.ctxPath + "/hrOrganization/tree", 'get', function (data) {
|
||||
organizationXmSel = xmSelect.render({
|
||||
el: '#organization',
|
||||
data: data.data,
|
||||
|
@ -40,4 +40,4 @@ layui.use(['form', 'admin', 'HttpRequest', 'xmSelect'], function () {
|
|||
request.set(data.field);
|
||||
request.start(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -13,7 +13,7 @@ layui.use(['form', 'admin', 'HttpRequest', 'xmSelect'], function () {
|
|||
form.val('organizationForm', result.data);
|
||||
|
||||
// 初始化组织树
|
||||
new HttpRequest(Feng.ctxPath + "/hrOrganization/treeLayui", 'get', function (data) {
|
||||
new HttpRequest(Feng.ctxPath + "/hrOrganization/tree", 'get', function (data) {
|
||||
console.log(result.data);
|
||||
organizationXmSel = xmSelect.render({
|
||||
el: '#organization',
|
||||
|
@ -49,4 +49,4 @@ layui.use(['form', 'admin', 'HttpRequest', 'xmSelect'], function () {
|
|||
request.set(data.field);
|
||||
request.start(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -132,7 +132,7 @@ layui.use(['layer', 'form', 'table', 'util', 'admin', 'tree', 'dropdown', 'xmSel
|
|||
|
||||
/* 渲染树形 */
|
||||
function renderTree() {
|
||||
$.get(Feng.ctxPath + '/hrOrganization/treeLayui', function (res) {
|
||||
$.get(Feng.ctxPath + '/hrOrganization/tree', function (res) {
|
||||
tree.render({
|
||||
elem: '#organizationTree',
|
||||
onlyIconControl: true,
|
||||
|
|
|
@ -9,7 +9,7 @@ layui.use(['layer', 'form', 'admin', 'laydate', 'HttpRequest', 'xmSelect'], func
|
|||
var positionXmSel;
|
||||
|
||||
// 初始化组织树
|
||||
new HttpRequest(Feng.ctxPath + "/hrOrganization/treeLayui", 'get', function (data) {
|
||||
new HttpRequest(Feng.ctxPath + "/hrOrganization/tree", 'get', function (data) {
|
||||
organizationXmSel = xmSelect.render({
|
||||
el: '#organization',
|
||||
data: data.data,
|
||||
|
|
|
@ -26,7 +26,7 @@ layui.use(['layer', 'form', 'admin', 'laydate', 'HttpRequest', 'xmSelect'], func
|
|||
}).start();
|
||||
|
||||
// 初始化组织树
|
||||
new HttpRequest(Feng.ctxPath + "/hrOrganization/treeLayui", 'get', function (data) {
|
||||
new HttpRequest(Feng.ctxPath + "/hrOrganization/tree", 'get', function (data) {
|
||||
organizationXmSel = xmSelect.render({
|
||||
el: '#organization',
|
||||
data: data.data,
|
||||
|
|
|
@ -257,7 +257,7 @@
|
|||
// 登录操作
|
||||
form.on('submit(loginSubmit)', function (data){
|
||||
admin.btnLoading('#loginSubmit',"登录中");
|
||||
var request = new HttpRequest(Feng.ctxPath + "/loginAction", 'post', function (data) {
|
||||
var request = new HttpRequest(Feng.ctxPath + "/login", 'post', function (data) {
|
||||
// 清除顶部选择应用的缓存
|
||||
index.clearTabCache();
|
||||
// 重定向到首页
|
||||
|
|
Loading…
Reference in New Issue