feat 同步当前用户的登录信息的返回接口
This commit is contained in:
parent
54d5dbd5b8
commit
cc3df48ed8
|
|
@ -35,6 +35,7 @@ const axiosHooks: AxiosHooks = {
|
|||
config.params = {}
|
||||
}
|
||||
config.headers = headers
|
||||
config.url = config.url?.replace(".", "/")
|
||||
return config
|
||||
},
|
||||
requestInterceptorsCatchHook(err) {
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ public class LikeAdminInterceptor implements HandlerInterceptor {
|
|||
|
||||
// 请求方法类型
|
||||
String reqUri = request.getRequestURI();
|
||||
if (!(handler instanceof HandlerMethod) || !reqUri.startsWith("/api")) {
|
||||
if (!(handler instanceof HandlerMethod) || ( !reqUri.startsWith("/api") && !reqUri.startsWith("/adminapi"))) {
|
||||
return HandlerInterceptor.super.preHandle(request, response, handler);
|
||||
}
|
||||
|
||||
|
|
@ -67,7 +67,7 @@ public class LikeAdminInterceptor implements HandlerInterceptor {
|
|||
// 演示环境拦截
|
||||
String env = YmlUtils.get("like.production");
|
||||
if (StringUtils.isNotNull(env) && env.equals("true")) {
|
||||
String prefix = "/api/";
|
||||
String prefix = "/adminapi/";
|
||||
String route = request.getRequestURI().replaceFirst(prefix, "");
|
||||
String auths = route.replace("/", ":");
|
||||
List<String> ignoreUrl = Arrays.asList("system:login", "system:logout");
|
||||
|
|
@ -155,9 +155,9 @@ public class LikeAdminInterceptor implements HandlerInterceptor {
|
|||
// 用户校验
|
||||
Admin adminUser = systemAuthAdminMapper.selectOne(
|
||||
new QueryWrapper<Admin>()
|
||||
.select("id,username,role_ids,dept_ids,post_ids,is_disable")
|
||||
.select("id,name,disable")
|
||||
.eq("id", Integer.parseInt(id.toString()))
|
||||
.eq("is_delete", 0)
|
||||
.isNull("delete_time")
|
||||
.last("limit 1"));
|
||||
|
||||
// 删除校验
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
package com.mdd.admin.controller.adminapi.auth;
|
||||
|
||||
import com.mdd.admin.LikeAdminThreadLocal;
|
||||
import com.mdd.admin.service.IIndexService;
|
||||
import com.mdd.admin.service.admin.IAdminService;
|
||||
import com.mdd.admin.vo.auth.AdminMySelfVo;
|
||||
import com.mdd.common.aop.NotLogin;
|
||||
import com.mdd.common.core.AjaxResult;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("adminapi/auth/admin")
|
||||
@Api(tags = "管理员详情管理")
|
||||
public class AdminController {
|
||||
|
||||
@Resource
|
||||
IAdminService iAdminService;
|
||||
|
||||
@GetMapping("/mySelf")
|
||||
@ApiOperation(value="获取当前管理员信息")
|
||||
public AjaxResult<AdminMySelfVo> mySelf() {
|
||||
AdminMySelfVo mySelf = iAdminService.mySelf(LikeAdminThreadLocal.getAdminId());
|
||||
return AjaxResult.success(mySelf);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -14,7 +14,4 @@ public interface IAdminRoleService {
|
|||
*/
|
||||
List<Integer> getRoleIdAttr(Integer adminId);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import com.mdd.admin.validate.system.SystemAdminCreateValidate;
|
|||
import com.mdd.admin.validate.system.SystemAdminSearchValidate;
|
||||
import com.mdd.admin.validate.system.SystemAdminUpInfoValidate;
|
||||
import com.mdd.admin.validate.system.SystemAdminUpdateValidate;
|
||||
import com.mdd.admin.vo.auth.AdminMySelfVo;
|
||||
import com.mdd.admin.vo.system.SystemAuthAdminDetailVo;
|
||||
import com.mdd.admin.vo.system.SystemAuthAdminListedVo;
|
||||
import com.mdd.admin.vo.system.SystemAuthAdminSelvesVo;
|
||||
|
|
@ -85,4 +86,10 @@ public interface IAdminService {
|
|||
*/
|
||||
void disable(Integer id, Integer adminId);
|
||||
|
||||
/**
|
||||
* 查看管理员详情
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
AdminMySelfVo mySelf(Integer id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.mdd.admin.service.impl.admin;
|
|||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.mdd.admin.service.admin.IAdminRoleService;
|
||||
import com.mdd.common.entity.admin.Admin;
|
||||
import com.mdd.common.entity.admin.AdminRole;
|
||||
import com.mdd.common.mapper.admin.AdminRoleMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
@ -21,7 +22,11 @@ public class AdminRoleServiceImpl implements IAdminRoleService {
|
|||
public List<Integer> getRoleIdAttr(Integer adminId) {
|
||||
List<Integer> ret = new ArrayList<Integer>();
|
||||
List<AdminRole> rolesList = adminRoleMapper.selectList(new QueryWrapper<AdminRole>().eq("admin_id", adminId).select("role_id"));
|
||||
System.out.println(rolesList);
|
||||
if (rolesList.size() > 0) {
|
||||
for (AdminRole adminRole : rolesList) {
|
||||
ret.add(adminRole.getRoleId());
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.mdd.admin.service.impl.admin;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
||||
|
|
@ -13,6 +14,7 @@ import com.mdd.admin.validate.system.SystemAdminCreateValidate;
|
|||
import com.mdd.admin.validate.system.SystemAdminSearchValidate;
|
||||
import com.mdd.admin.validate.system.SystemAdminUpInfoValidate;
|
||||
import com.mdd.admin.validate.system.SystemAdminUpdateValidate;
|
||||
import com.mdd.admin.vo.auth.AdminMySelfVo;
|
||||
import com.mdd.admin.vo.system.*;
|
||||
import com.mdd.common.core.PageResult;
|
||||
import com.mdd.common.entity.admin.Admin;
|
||||
|
|
@ -414,4 +416,15 @@ public class AdminServiceImpl implements IAdminService {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AdminMySelfVo mySelf(Integer id) {
|
||||
AdminMySelfVo ret = new AdminMySelfVo();
|
||||
ret.setMenu(new JSONArray());
|
||||
ret.setPermissions(new ArrayList<String>(){{
|
||||
add("*");
|
||||
}});
|
||||
ret.setUser();
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import cn.dev33.satoken.stp.StpUtil;
|
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.mdd.admin.cache.CaptchaCache;
|
||||
import com.mdd.admin.service.system.ISystemLoginService;
|
||||
import com.mdd.admin.service.system.ISystemRoleService;
|
||||
import com.mdd.admin.validate.system.SystemAdminLoginsValidate;
|
||||
import com.mdd.admin.vo.system.SystemCaptchaVo;
|
||||
import com.mdd.admin.vo.system.SystemLoginVo;
|
||||
|
|
@ -35,6 +36,8 @@ import java.util.*;
|
|||
@Service
|
||||
public class SystemLoginServiceImpl implements ISystemLoginService {
|
||||
|
||||
@Resource
|
||||
ISystemRoleService iSystemRoleService;
|
||||
@Resource
|
||||
Producer captchaProducer;
|
||||
|
||||
|
|
@ -136,6 +139,7 @@ public class SystemLoginServiceImpl implements ISystemLoginService {
|
|||
vo.setName(sysAdmin.getName());
|
||||
vo.setAvatar(UrlUtils.toAbsoluteUrl(avatar));
|
||||
vo.setToken(StpUtil.getTokenValue());
|
||||
vo.setRoleName(ListUtils.listToStringByStr(iSystemRoleService.getRoleNameByAdminId(sysAdmin.getId()), "/"));
|
||||
return vo;
|
||||
} catch (Exception e) {
|
||||
Integer adminId = StringUtils.isNotNull(sysAdmin.getId()) ? sysAdmin.getId() : 0;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.mdd.admin.service.admin.IAdminRoleService;
|
||||
import com.mdd.admin.service.system.ISystemAuthPermService;
|
||||
import com.mdd.admin.service.system.ISystemRoleService;
|
||||
import com.mdd.admin.validate.commons.PageValidate;
|
||||
|
|
@ -12,9 +13,11 @@ import com.mdd.admin.validate.system.SystemRoleUpdateValidate;
|
|||
import com.mdd.admin.vo.system.SystemAuthRoleVo;
|
||||
import com.mdd.common.core.PageResult;
|
||||
import com.mdd.common.entity.admin.Admin;
|
||||
import com.mdd.common.entity.admin.AdminRole;
|
||||
import com.mdd.common.entity.system.SystemRole;
|
||||
import com.mdd.common.mapper.admin.AdminMapper;
|
||||
import com.mdd.common.mapper.system.SystemRoleMapper;
|
||||
import com.mdd.common.util.StringUtils;
|
||||
import com.mdd.common.util.TimeUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
@ -31,13 +34,15 @@ import java.util.*;
|
|||
public class SystemRoleServiceImpl implements ISystemRoleService {
|
||||
|
||||
@Resource
|
||||
AdminMapper systemAuthAdminMapper;
|
||||
AdminMapper adminMapper;
|
||||
|
||||
@Resource
|
||||
SystemRoleMapper systemRoleMapper;
|
||||
|
||||
@Resource
|
||||
ISystemAuthPermService iSystemAuthPermService;
|
||||
@Resource
|
||||
IAdminRoleService iAdminRoleService;
|
||||
|
||||
/**
|
||||
* 角色所有
|
||||
|
|
@ -201,7 +206,7 @@ public class SystemRoleServiceImpl implements ISystemRoleService {
|
|||
.last("limit 1")),
|
||||
"角色已不存在!");
|
||||
|
||||
Assert.isNull(systemAuthAdminMapper.selectOne(new QueryWrapper<Admin>()
|
||||
Assert.isNull(adminMapper.selectOne(new QueryWrapper<Admin>()
|
||||
.select("id", "role_ids", "nickname")
|
||||
.apply("find_in_set({0}, role_ids)", id)
|
||||
.eq("is_delete", 0)),
|
||||
|
|
@ -211,4 +216,40 @@ public class SystemRoleServiceImpl implements ISystemRoleService {
|
|||
iSystemAuthPermService.batchDeleteByRoleId(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getRoleNameByAdminId(Integer adminId) {
|
||||
List<String> ret = new ArrayList<String>();
|
||||
Admin admin = adminMapper.selectOne(new QueryWrapper<Admin>().eq("id", adminId).isNull("delete_time"));
|
||||
if (StringUtils.isNull(admin)) {
|
||||
return ret;
|
||||
} else {
|
||||
if (admin.getRoot().equals(1)) {
|
||||
ret.add("系统管理员");
|
||||
} else {
|
||||
List<Integer> roleIds = iAdminRoleService.getRoleIdAttr(adminId);
|
||||
if (roleIds.size() > 0) {
|
||||
ret = getNamesByIds(roleIds);
|
||||
} else {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ids 返回
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
private List<String> getNamesByIds(List<Integer> ids) {
|
||||
List<String> ret = new ArrayList<String>();
|
||||
List<SystemRole> adminRoleList = systemRoleMapper.selectList(new QueryWrapper<SystemRole>().in("id", ids).isNull("delete_time"));
|
||||
if (adminRoleList.size() > 0) {
|
||||
for (SystemRole item : adminRoleList) {
|
||||
ret.add(item.getName());
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,4 +64,10 @@ public interface ISystemRoleService {
|
|||
*/
|
||||
void del(Integer id);
|
||||
|
||||
/**
|
||||
* 根据adminID 返回角色名称
|
||||
* @param adminId
|
||||
*/
|
||||
List<String> getRoleNameByAdminId(Integer adminId);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
package com.mdd.admin.vo.auth;
|
||||
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@ApiModel("相册分类Vo")
|
||||
public class AdminMySelfVo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "当前管理员角色拥有的菜单")
|
||||
private JSONArray menu;
|
||||
|
||||
@ApiModelProperty(value = "当前管理员橘色拥有的按钮权限")
|
||||
private List<String> permissions;
|
||||
|
||||
@ApiModelProperty(value = "user")
|
||||
private JSONObject user;
|
||||
}
|
||||
|
|
@ -80,7 +80,7 @@ mybatis-plus:
|
|||
|
||||
# Sa-token配置
|
||||
sa-token:
|
||||
token-name: like-admin # token的名称
|
||||
token-name: token # token的名称
|
||||
timeout: 2592000 # token有效期单位s(默认30天,-1代表永不过期)
|
||||
activity-timeout: -1 # token临时有效期(指定时间无操作掉线)
|
||||
is-concurrent: true # 是否允许同一账号并发登录
|
||||
|
|
|
|||
Loading…
Reference in New Issue