This commit is contained in:
PQZ 2024-08-28 16:56:56 +08:00
parent 59e049c2ef
commit 247250713e
6 changed files with 103 additions and 11 deletions

View File

@ -0,0 +1,86 @@
package cn.iocoder.yudao.module.jx.controller.api;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.security.config.SecurityProperties;
import cn.iocoder.yudao.framework.security.core.LoginUser;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.jx.domain.DriveSchoolCoach;
import cn.iocoder.yudao.module.jx.domain.DriveSchoolInfo;
import cn.iocoder.yudao.module.jx.mapper.DriveSchoolCoachMapper;
import cn.iocoder.yudao.module.jx.service.IDriveSchoolInfoService;
import cn.iocoder.yudao.module.system.api.permission.PermissionApi;
import cn.iocoder.yudao.module.system.api.permission.RoleApi;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import cn.iocoder.yudao.module.system.service.auth.AdminAuthService;
import cn.iocoder.yudao.module.system.service.permission.MenuService;
import cn.iocoder.yudao.module.system.service.permission.PermissionService;
import cn.iocoder.yudao.module.system.service.permission.RoleService;
import cn.iocoder.yudao.module.system.service.social.SocialClientService;
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
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.HashMap;
import java.util.Map;
import java.util.Set;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "管理后台 - 认证")
@RestController
@RequestMapping("/jx/auth")
@Validated
@Slf4j
public class JxAuthController {
@Resource
private AdminUserService userService;
@Resource
private PermissionService permissionService;
@Resource
private DriveSchoolCoachMapper driveSchoolCoachMapper;
@Resource
private IDriveSchoolInfoService driveSchoolInfoService;
/**
* 获取
*
* @return 用户信息
*/
@GetMapping("/getJxInfo")
public CommonResult getJxInfo()
{
LoginUser user = SecurityFrameworkUtils.getLoginUser();
// 获取当前登录用户code
Set<String> roles = permissionService.getRolePermission(user.getId());
//获取驾校的
Long userId = user.getId();
AdminUserDO sysUser = userService.getUser(userId);
String phonenumber = sysUser.getMobile();
DriveSchoolCoach driveSchoolCoach = driveSchoolCoachMapper.selectByPhonenumber(phonenumber);
if (ObjectUtils.isNotEmpty(driveSchoolCoach)){
sysUser.setAvatar(driveSchoolCoach.getImage());
}
DriveSchoolInfo driveSchoolInfo = driveSchoolInfoService.getSchoolInfoByDeptId();
Map<String,Object> result = new HashMap<>();
result.put("user", sysUser);
result.put("roles", roles);
result.put("schoolInfo", driveSchoolInfo);
return CommonResult.success(result);
}
}

View File

@ -26,9 +26,11 @@ import cn.iocoder.yudao.module.system.service.auth.AdminAuthService;
import cn.iocoder.yudao.module.system.service.permission.MenuService;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.thoughtworks.xstream.core.SecurityUtils;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
@ -38,10 +40,7 @@ import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.security.spec.AlgorithmParameterSpec;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
@ -63,9 +62,7 @@ public class SysLoginController {
@Resource
private MenuService menuService;
//
// @Autowired
// private SysPermissionService permissionService;
@Resource
private AdminUserApi userService;
@ -268,12 +265,12 @@ public class SysLoginController {
// @GetMapping("getJxInfo")
// public CommonResult getJxInfo()
// {
// AdminUserRespDTO user = SecurityFrameworkUtils.getLoginUser()
// LoginUser user = SecurityFrameworkUtils.getLoginUser();
// // 角色集合
// Set<String> roles = permissionService.getRolePermission(user);
// //获取驾校的
//
// Long userId = SecurityUtils.getUserId();
// LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
// Long userId = loginUser.getId();
// SysUser sysUser = sysUserMapper.selectUserById(userId);
// String phonenumber = sysUser.getPhonenumber();
// DriveSchoolCoach driveSchoolCoach = driveSchoolCoachMapper.selectByPhonenumber(phonenumber);

View File

@ -129,7 +129,8 @@ public class YudaoWebSecurityConfigurerAdapter {
.authorizeRequests()
// 1.1 静态资源可匿名访问
.antMatchers(HttpMethod.GET, "/*.html", "/**/*.html", "/**/*.css", "/**/*.js").permitAll()
.antMatchers(HttpMethod.POST, "/admin-api/rescue/login", "/admin-api/rescue/loginApp","/admin-api/system/auth/loginApp", "/admin-api/rescue/driverLogin").anonymous()
.antMatchers(HttpMethod.POST, "/admin-api/rescue/login","/admin-api/jx/auth/getJxInfo", "/admin-api/rescue/loginApp","/admin-api/system/auth/loginApp", "/admin-api/rescue/driverLogin").anonymous()
// 1.2 设置 @PermitAll 无需认证
.antMatchers(HttpMethod.GET, permitAllUrls.get(HttpMethod.GET).toArray(new String[0])).permitAll()
.antMatchers(HttpMethod.POST, permitAllUrls.get(HttpMethod.POST).toArray(new String[0])).permitAll()

View File

@ -8,6 +8,7 @@ import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
import cn.iocoder.yudao.framework.common.exception.ErrorCode;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.security.config.SecurityProperties;
import cn.iocoder.yudao.framework.security.core.LoginUser;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.system.api.permission.PermissionApi;
import cn.iocoder.yudao.module.system.api.permission.RoleApi;

View File

@ -143,6 +143,8 @@ public interface PermissionService {
*/
Set<Long> getUserRoleIdListByUserIdFromCache(Long userId);
Set<String> getRolePermission(Long userId);
// ========== 用户-部门的相关方法 ==========
/**

View File

@ -267,6 +267,11 @@ public class PermissionServiceImpl implements PermissionService {
return getUserRoleIdListByUserId(userId);
}
@Override
public Set<String> getRolePermission(Long userId) {
return null;
}
@Override
public Set<Long> getUserRoleIdListByRoleId(Collection<Long> roleIds) {
return convertSet(userRoleMapper.selectListByRoleIds(roleIds), UserRoleDO::getUserId);