✨ SYSTEM:同步 jdk21 boot 最新代码
✨ INFRA:同步 jdk21 boot 最新代码
This commit is contained in:
@@ -1,14 +1,26 @@
|
||||
package cn.iocoder.yudao.module.system.api.logger;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogV2CreateReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogV2PageReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogV2RespDTO;
|
||||
import cn.iocoder.yudao.module.system.convert.logger.OperateLogConvert;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogV2DO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import cn.iocoder.yudao.module.system.service.logger.OperateLogService;
|
||||
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
||||
|
||||
@RestController // 提供 RESTful API 接口,给 Feign 调用
|
||||
@Validated
|
||||
@@ -16,6 +28,8 @@ public class OperateLogApiImpl implements OperateLogApi {
|
||||
|
||||
@Resource
|
||||
private OperateLogService operateLogService;
|
||||
@Resource
|
||||
private AdminUserService adminUserService;
|
||||
|
||||
@Override
|
||||
public CommonResult<Boolean> createOperateLog(OperateLogCreateReqDTO createReqDTO) {
|
||||
@@ -23,4 +37,23 @@ public class OperateLogApiImpl implements OperateLogApi {
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<Boolean> createOperateLogV2(OperateLogV2CreateReqDTO createReqDTO) {
|
||||
operateLogService.createOperateLogV2(createReqDTO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<PageResult<OperateLogV2RespDTO>> getOperateLogPage(OperateLogV2PageReqDTO pageReqVO) {
|
||||
PageResult<OperateLogV2DO> operateLogPage = operateLogService.getOperateLogPage(pageReqVO);
|
||||
if (CollUtil.isEmpty(operateLogPage.getList())) {
|
||||
return success(PageResult.empty());
|
||||
}
|
||||
|
||||
// 获取用户
|
||||
List<AdminUserDO> userList = adminUserService.getUserList(
|
||||
convertSet(operateLogPage.getList(), OperateLogV2DO::getUserId));
|
||||
return success(OperateLogConvert.INSTANCE.convertPage(operateLogPage, userList));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,8 +32,13 @@ public class SocialUserApiImpl implements SocialUserApi {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<SocialUserRespDTO> getSocialUser(Integer userType, Integer socialType, String code, String state) {
|
||||
return success(socialUserService.getSocialUser(userType, socialType, code, state));
|
||||
public CommonResult<SocialUserRespDTO> getSocialUserByUserId(Integer userType, Long userId, Integer socialType) {
|
||||
return success(socialUserService.getSocialUserByUserId(userType, userId, socialType));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<SocialUserRespDTO> getSocialUserByCode(Integer userType, Integer socialType, String code, String state) {
|
||||
return success(socialUserService.getSocialUserByCode(userType, socialType, code, state));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@ package cn.iocoder.yudao.module.system.controller.admin.ip;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.framework.ip.core.Area;
|
||||
import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils;
|
||||
import cn.iocoder.yudao.framework.ip.core.utils.IPUtils;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.ip.vo.AreaNodeRespVO;
|
||||
import cn.iocoder.yudao.module.system.convert.ip.AreaConvert;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -31,7 +31,7 @@ public class AreaController {
|
||||
public CommonResult<List<AreaNodeRespVO>> getAreaTree() {
|
||||
Area area = AreaUtils.getArea(Area.ID_CHINA);
|
||||
Assert.notNull(area, "获取不到中国");
|
||||
return success(AreaConvert.INSTANCE.convertList(area.getChildren()));
|
||||
return success(BeanUtils.toBean(area.getChildren(), AreaNodeRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/get-by-ip")
|
||||
|
||||
@@ -2,10 +2,10 @@ package cn.iocoder.yudao.module.system.controller.app.ip;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.framework.ip.core.Area;
|
||||
import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils;
|
||||
import cn.iocoder.yudao.module.system.controller.app.ip.vo.AppAreaNodeRespVO;
|
||||
import cn.iocoder.yudao.module.system.convert.ip.AreaConvert;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -28,7 +28,7 @@ public class AppAreaController {
|
||||
public CommonResult<List<AppAreaNodeRespVO>> getAreaTree() {
|
||||
Area area = AreaUtils.getArea(Area.ID_CHINA);
|
||||
Assert.notNull(area, "获取不到中国");
|
||||
return success(AreaConvert.INSTANCE.convertList3(area.getChildren()));
|
||||
return success(BeanUtils.toBean(area.getChildren(), AppAreaNodeRespVO.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package cn.iocoder.yudao.module.system.convert.logger;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogV2RespDTO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogRespVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogV2DO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
@@ -12,6 +15,9 @@ import org.mapstruct.factory.Mappers;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
|
||||
|
||||
@Mapper
|
||||
public interface OperateLogConvert {
|
||||
|
||||
@@ -25,4 +31,19 @@ public interface OperateLogConvert {
|
||||
});
|
||||
}
|
||||
|
||||
default PageResult<OperateLogV2RespDTO> convertPage(PageResult<OperateLogV2DO> operateLogPage, List<AdminUserDO> userList) {
|
||||
return BeanUtils.toBean(operateLogPage, OperateLogV2RespDTO.class).setList(setUserInfo(operateLogPage.getList(), userList));
|
||||
}
|
||||
|
||||
OperateLogV2RespDTO convert(OperateLogV2DO operateLogV2DO);
|
||||
|
||||
default List<OperateLogV2RespDTO> setUserInfo(List<OperateLogV2DO> logList, List<AdminUserDO> userList) {
|
||||
Map<Long, AdminUserDO> userMap = convertMap(userList, AdminUserDO::getId);
|
||||
return CollectionUtils.convertList(logList, item -> {
|
||||
OperateLogV2RespDTO respDTO = convert(item);
|
||||
findAndThen(userMap, item.getUserId(), user -> respDTO.setUserName(user.getNickname()));
|
||||
return respDTO;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package cn.iocoder.yudao.module.system.dal.dataobject.logger;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 操作日志表 V2
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@TableName(value = "system_operate_log_v2", autoResultMap = true)
|
||||
@KeySequence("system_operate_log_seq_v2") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class OperateLogV2DO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 日志主键
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 链路追踪编号
|
||||
*
|
||||
* 一般来说,通过链路追踪编号,可以将访问日志,错误日志,链路追踪日志,logger 打印日志等,结合在一起,从而进行排错。
|
||||
*/
|
||||
private String traceId;
|
||||
/**
|
||||
* 用户编号
|
||||
*
|
||||
* 关联 MemberUserDO 的 id 属性,或者 AdminUserDO 的 id 属性
|
||||
*/
|
||||
private Long userId;
|
||||
/**
|
||||
* 用户类型
|
||||
*
|
||||
* 关联 {@link UserTypeEnum}
|
||||
*/
|
||||
private Integer userType;
|
||||
/**
|
||||
* 操作模块类型
|
||||
*/
|
||||
private String type;
|
||||
/**
|
||||
* 操作名
|
||||
*/
|
||||
private String subType;
|
||||
/**
|
||||
* 操作模块业务编号
|
||||
*/
|
||||
private Long bizId;
|
||||
/**
|
||||
* 日志内容,记录整个操作的明细
|
||||
*
|
||||
* 例如说,修改编号为 1 的用户信息,将性别从男改成女,将姓名从芋道改成源码。
|
||||
*/
|
||||
private String action;
|
||||
/**
|
||||
* 拓展字段,有些复杂的业务,需要记录一些字段 ( JSON 格式 )
|
||||
*
|
||||
* 例如说,记录订单编号,{ orderId: "1"}
|
||||
*/
|
||||
private String extra;
|
||||
|
||||
/**
|
||||
* 请求方法名
|
||||
*/
|
||||
private String requestMethod;
|
||||
/**
|
||||
* 请求地址
|
||||
*/
|
||||
private String requestUrl;
|
||||
/**
|
||||
* 用户 IP
|
||||
*/
|
||||
private String userIp;
|
||||
/**
|
||||
* 浏览器 UA
|
||||
*/
|
||||
private String userAgent;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package cn.iocoder.yudao.module.system.dal.mysql.logger;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogV2PageReqDTO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogV2DO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface OperateLogV2Mapper extends BaseMapperX<OperateLogV2DO> {
|
||||
|
||||
default PageResult<OperateLogV2DO> selectPage(OperateLogV2PageReqDTO pageReqDTO) {
|
||||
return selectPage(pageReqDTO, new LambdaQueryWrapperX<OperateLogV2DO>()
|
||||
.eqIfPresent(OperateLogV2DO::getType, pageReqDTO.getBizType())
|
||||
.eqIfPresent(OperateLogV2DO::getBizId, pageReqDTO.getBizId())
|
||||
.eqIfPresent(OperateLogV2DO::getUserId, pageReqDTO.getUserId())
|
||||
.orderByDesc(OperateLogV2DO::getId));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -34,4 +34,11 @@ public interface SocialUserBindMapper extends BaseMapperX<SocialUserBindDO> {
|
||||
.eq(SocialUserBindDO::getUserType, userType));
|
||||
}
|
||||
|
||||
default SocialUserBindDO selectByUserIdAndUserTypeAndSocialType(Long userId, Integer userType, Integer socialType) {
|
||||
return selectOne(new LambdaQueryWrapperX<SocialUserBindDO>()
|
||||
.eq(SocialUserBindDO::getUserId, userId)
|
||||
.eq(SocialUserBindDO::getUserType, userType)
|
||||
.eq(SocialUserBindDO::getSocialType, socialType));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -156,9 +156,9 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
||||
@Override
|
||||
public AuthLoginRespVO socialLogin(AuthSocialLoginReqVO reqVO) {
|
||||
// 使用 code 授权码,进行登录。然后,获得到绑定的用户编号
|
||||
SocialUserRespDTO socialUser = socialUserService.getSocialUser(UserTypeEnum.ADMIN.getValue(), reqVO.getType(),
|
||||
SocialUserRespDTO socialUser = socialUserService.getSocialUserByCode(UserTypeEnum.ADMIN.getValue(), reqVO.getType(),
|
||||
reqVO.getCode(), reqVO.getState());
|
||||
if (socialUser == null) {
|
||||
if (socialUser == null || socialUser.getUserId() == null) {
|
||||
throw exception(AUTH_THIRD_LOGIN_NOT_BIND);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,11 @@ package cn.iocoder.yudao.module.system.service.logger;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogV2CreateReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogV2PageReqDTO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogV2DO;
|
||||
|
||||
/**
|
||||
* 操作日志 Service 接口
|
||||
@@ -27,4 +30,21 @@ public interface OperateLogService {
|
||||
*/
|
||||
PageResult<OperateLogDO> getOperateLogPage(OperateLogPageReqVO pageReqVO);
|
||||
|
||||
// ======================= LOG V2 =======================
|
||||
|
||||
/**
|
||||
* 记录操作日志 V2
|
||||
*
|
||||
* @param createReqDTO 创建请求
|
||||
*/
|
||||
void createOperateLogV2(OperateLogV2CreateReqDTO createReqDTO);
|
||||
|
||||
/**
|
||||
* 获得操作日志分页列表
|
||||
*
|
||||
* @param pageReqVO 分页条件
|
||||
* @return 操作日志分页列表
|
||||
*/
|
||||
PageResult<OperateLogV2DO> getOperateLogPage(OperateLogV2PageReqDTO pageReqVO);
|
||||
|
||||
}
|
||||
|
||||
@@ -6,16 +6,20 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.string.StrUtils;
|
||||
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogV2CreateReqDTO;
|
||||
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogV2PageReqDTO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogV2DO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.logger.OperateLogMapper;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.logger.OperateLogV2Mapper;
|
||||
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import java.util.Collection;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
||||
@@ -34,6 +38,8 @@ public class OperateLogServiceImpl implements OperateLogService {
|
||||
|
||||
@Resource
|
||||
private OperateLogMapper operateLogMapper;
|
||||
@Resource
|
||||
private OperateLogV2Mapper operateLogV2Mapper;
|
||||
|
||||
@Resource
|
||||
private AdminUserService userService;
|
||||
@@ -60,4 +66,17 @@ public class OperateLogServiceImpl implements OperateLogService {
|
||||
return operateLogMapper.selectPage(pageReqVO, userIds);
|
||||
}
|
||||
|
||||
// ======================= LOG V2 =======================
|
||||
|
||||
@Override
|
||||
public void createOperateLogV2(OperateLogV2CreateReqDTO createReqDTO) {
|
||||
OperateLogV2DO log = BeanUtils.toBean(createReqDTO, OperateLogV2DO.class);
|
||||
operateLogV2Mapper.insert(log);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<OperateLogV2DO> getOperateLogPage(OperateLogV2PageReqDTO pageReqDTO) {
|
||||
return operateLogV2Mapper.selectPage(pageReqDTO);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserPageReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO;
|
||||
import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -45,6 +45,16 @@ public interface SocialUserService {
|
||||
*/
|
||||
void unbindSocialUser(Long userId, Integer userType, Integer socialType, String openid);
|
||||
|
||||
/**
|
||||
* 获得社交用户,基于 userId
|
||||
*
|
||||
* @param userType 用户类型
|
||||
* @param userId 用户编号
|
||||
* @param socialType 社交平台的类型
|
||||
* @return 社交用户
|
||||
*/
|
||||
SocialUserRespDTO getSocialUserByUserId(Integer userType, Long userId, Integer socialType);
|
||||
|
||||
/**
|
||||
* 获得社交用户
|
||||
*
|
||||
@@ -56,7 +66,7 @@ public interface SocialUserService {
|
||||
* @param state state
|
||||
* @return 社交用户
|
||||
*/
|
||||
SocialUserRespDTO getSocialUser(Integer userType, Integer socialType, String code, String state);
|
||||
SocialUserRespDTO getSocialUserByCode(Integer userType, Integer socialType, String code, String state);
|
||||
|
||||
// ==================== 社交用户 CRUD ====================
|
||||
|
||||
|
||||
@@ -13,20 +13,19 @@ import cn.iocoder.yudao.module.system.dal.mysql.social.SocialUserBindMapper;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.social.SocialUserMapper;
|
||||
import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
|
||||
import com.xingyuv.jushauth.model.AuthUser;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
||||
import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString;
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.AUTH_THIRD_LOGIN_NOT_BIND;
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.SOCIAL_USER_NOT_FOUND;
|
||||
|
||||
/**
|
||||
@@ -94,18 +93,30 @@ public class SocialUserServiceImpl implements SocialUserService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public SocialUserRespDTO getSocialUser(Integer userType, Integer socialType, String code, String state) {
|
||||
public SocialUserRespDTO getSocialUserByUserId(Integer userType, Long userId, Integer socialType) {
|
||||
// 获得绑定用户
|
||||
SocialUserBindDO socialUserBind = socialUserBindMapper.selectByUserIdAndUserTypeAndSocialType(userId, userType, socialType);
|
||||
if (socialUserBind == null) {
|
||||
return null;
|
||||
}
|
||||
// 获得社交用户
|
||||
SocialUserDO socialUser = socialUserMapper.selectById(socialUserBind.getSocialUserId());
|
||||
Assert.notNull(socialUser, "社交用户不能为空");
|
||||
return new SocialUserRespDTO(socialUser.getOpenid(), socialUser.getNickname(), socialUser.getAvatar(),
|
||||
socialUserBind.getUserId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SocialUserRespDTO getSocialUserByCode(Integer userType, Integer socialType, String code, String state) {
|
||||
// 获得社交用户
|
||||
SocialUserDO socialUser = authSocialUser(socialType, userType, code, state);
|
||||
Assert.notNull(socialUser, "社交用户不能为空");
|
||||
|
||||
// 如果未绑定的社交用户,则无法自动登录,进行报错
|
||||
// 获得绑定用户
|
||||
SocialUserBindDO socialUserBind = socialUserBindMapper.selectByUserTypeAndSocialUserId(userType,
|
||||
socialUser.getId());
|
||||
if (socialUserBind == null) {
|
||||
throw exception(AUTH_THIRD_LOGIN_NOT_BIND);
|
||||
}
|
||||
return new SocialUserRespDTO(socialUser.getOpenid(), socialUserBind.getUserId());
|
||||
return new SocialUserRespDTO(socialUser.getOpenid(), socialUser.getNickname(), socialUser.getAvatar(),
|
||||
socialUserBind != null ? socialUserBind.getUserId() : null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -236,8 +236,8 @@ public class AdminAuthServiceImplTest extends BaseDbUnitTest {
|
||||
AuthSocialLoginReqVO reqVO = randomPojo(AuthSocialLoginReqVO.class);
|
||||
// mock 方法(绑定的用户编号)
|
||||
Long userId = 1L;
|
||||
when(socialUserService.getSocialUser(eq(UserTypeEnum.ADMIN.getValue()), eq(reqVO.getType()),
|
||||
eq(reqVO.getCode()), eq(reqVO.getState()))).thenReturn(new SocialUserRespDTO(randomString(), userId));
|
||||
when(socialUserService.getSocialUserByCode(eq(UserTypeEnum.ADMIN.getValue()), eq(reqVO.getType()),
|
||||
eq(reqVO.getCode()), eq(reqVO.getState()))).thenReturn(new SocialUserRespDTO(randomString(), randomString(), randomString(), userId));
|
||||
// mock(用户)
|
||||
AdminUserDO user = randomPojo(AdminUserDO.class, o -> o.setId(userId));
|
||||
when(userService.getUser(eq(userId))).thenReturn(user);
|
||||
|
||||
@@ -147,7 +147,7 @@ public class SocialUserServiceImplTest extends BaseDbUnitTest {
|
||||
socialUserBindMapper.insert(socialUserBind);
|
||||
|
||||
// 调用
|
||||
SocialUserRespDTO socialUser = socialUserService.getSocialUser(userType, type, code, state);
|
||||
SocialUserRespDTO socialUser = socialUserService.getSocialUserByCode(userType, type, code, state);
|
||||
// 断言
|
||||
assertEquals(userId, socialUser.getUserId());
|
||||
assertEquals(socialUserDO.getOpenid(), socialUser.getOpenid());
|
||||
|
||||
Reference in New Issue
Block a user