Commit 12ae5bf128d0c405c7e907d613a8c682f90b063f

Authored by puhui999
1 parent 738fcef4

新增社交用户 RUD

yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java
... ... @@ -120,6 +120,7 @@ public interface ErrorCodeConstants {
120 120 ErrorCode SOCIAL_USER_NOT_FOUND = new ErrorCode(1_002_018_002, "社交授权失败,找不到对应的用户");
121 121 ErrorCode SOCIAL_APP_WEIXIN_MINI_APP_PHONE_CODE_ERROR = new ErrorCode(1_002_018_103, "获得手机号失败");
122 122 ErrorCode SOCIAL_CLIENT_NOT_EXISTS = new ErrorCode(1_002_018_104, "社交客户端不存在");
  123 + ErrorCode SOCIAL_USER_NOT_EXISTS = new ErrorCode(1_002_018_105, "社交用户不存在");
123 124  
124 125 // ========== 系统敏感词 1-002-019-000 =========
125 126 ErrorCode SENSITIVE_WORD_NOT_EXISTS = new ErrorCode(1_002_019_000, "系统敏感词在所有标签中都不存在");
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/SocialUserController.java
... ... @@ -2,18 +2,26 @@ package cn.iocoder.yudao.module.system.controller.admin.socail;
2 2  
3 3 import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
4 4 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
  5 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 6 import cn.iocoder.yudao.module.system.controller.admin.socail.vo.SocialUserBindReqVO;
6 7 import cn.iocoder.yudao.module.system.controller.admin.socail.vo.SocialUserUnbindReqVO;
  8 +import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserPageReqVO;
  9 +import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserRespVO;
  10 +import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserUpdateReqVO;
7 11 import cn.iocoder.yudao.module.system.convert.social.SocialUserConvert;
  12 +import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO;
8 13 import cn.iocoder.yudao.module.system.service.social.SocialUserService;
9   -import io.swagger.v3.oas.annotations.tags.Tag;
10 14 import io.swagger.v3.oas.annotations.Operation;
  15 +import io.swagger.v3.oas.annotations.Parameter;
  16 +import io.swagger.v3.oas.annotations.tags.Tag;
  17 +import org.springframework.security.access.prepost.PreAuthorize;
11 18 import org.springframework.validation.annotation.Validated;
12 19 import org.springframework.web.bind.annotation.*;
13 20  
14 21 import javax.annotation.Resource;
15 22 import javax.validation.Valid;
16 23  
  24 +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
17 25 import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
18 26  
19 27 @Tag(name = "管理后台 - 社交用户")
... ... @@ -39,4 +47,40 @@ public class SocialUserController {
39 47 return CommonResult.success(true);
40 48 }
41 49  
  50 + // ==================== 社交用户 CRUD ====================
  51 +
  52 + @PutMapping("/update")
  53 + @Operation(summary = "更新社交用户")
  54 + @PreAuthorize("@ss.hasPermission('system:social-user:update')")
  55 + public CommonResult<Boolean> updateSocialUser(@Valid @RequestBody SocialUserUpdateReqVO updateReqVO) {
  56 + socialUserService.updateSocialUser(updateReqVO);
  57 + return success(true);
  58 + }
  59 +
  60 + @DeleteMapping("/delete")
  61 + @Operation(summary = "删除社交用户")
  62 + @Parameter(name = "id", description = "编号", required = true)
  63 + @PreAuthorize("@ss.hasPermission('system:social-user:delete')")
  64 + public CommonResult<Boolean> deleteSocialUser(@RequestParam("id") Long id) {
  65 + socialUserService.deleteSocialUser(id);
  66 + return success(true);
  67 + }
  68 +
  69 + @GetMapping("/get")
  70 + @Operation(summary = "获得社交用户")
  71 + @Parameter(name = "id", description = "编号", required = true, example = "1024")
  72 + @PreAuthorize("@ss.hasPermission('system:social-user:query')")
  73 + public CommonResult<SocialUserRespVO> getSocialUser(@RequestParam("id") Long id) {
  74 + SocialUserDO socialUser = socialUserService.getSocialUser(id);
  75 + return success(SocialUserConvert.INSTANCE.convert(socialUser));
  76 + }
  77 +
  78 + @GetMapping("/page")
  79 + @Operation(summary = "获得社交用户分页")
  80 + @PreAuthorize("@ss.hasPermission('system:social-user:query')")
  81 + public CommonResult<PageResult<SocialUserRespVO>> getSocialUserPage(@Valid SocialUserPageReqVO pageVO) {
  82 + PageResult<SocialUserDO> pageResult = socialUserService.getSocialUserPage(pageVO);
  83 + return success(SocialUserConvert.INSTANCE.convertPage(pageResult));
  84 + }
  85 +
42 86 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/user/SocialUserBaseVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.system.controller.admin.socail.vo.user;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import lombok.Data;
  5 +
  6 +import javax.validation.constraints.NotNull;
  7 +
  8 +/**
  9 + * 社交用户 Base VO,提供给添加、修改、详细的子 VO 使用
  10 + * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
  11 + */
  12 +@Data
  13 +public class SocialUserBaseVO {
  14 +
  15 + @Schema(description = "社交平台的类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "30")
  16 + @NotNull(message = "社交平台的类型不能为空")
  17 + private Integer type;
  18 +
  19 + @Schema(description = "社交 openid", requiredMode = Schema.RequiredMode.REQUIRED, example = "666")
  20 + @NotNull(message = "社交 openid不能为空")
  21 + private String openid;
  22 +
  23 + @Schema(description = "社交 token", example = "666")
  24 + private String token;
  25 +
  26 + @Schema(description = "原始 Token 数据,一般是 JSON 格式", example = "{}")
  27 + private String rawTokenInfo;
  28 +
  29 + @Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
  30 + @NotNull(message = "用户昵称不能为空")
  31 + private String nickname;
  32 +
  33 + @Schema(description = "用户头像", example = "https://www.iocoder.cn/xxx.png")
  34 + private String avatar;
  35 +
  36 + @Schema(description = "原始用户数据,一般是 JSON 格式", example = "{}")
  37 + private String rawUserInfo;
  38 +
  39 + @Schema(description = "最后一次的认证 code", example = "666666")
  40 + private String code;
  41 +
  42 + @Schema(description = "最后一次的认证 state", example = "123456")
  43 + private String state;
  44 +
  45 +}
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/user/SocialUserPageReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.system.controller.admin.socail.vo.user;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
  4 +import io.swagger.v3.oas.annotations.media.Schema;
  5 +import lombok.Data;
  6 +import lombok.EqualsAndHashCode;
  7 +import lombok.ToString;
  8 +import org.springframework.format.annotation.DateTimeFormat;
  9 +
  10 +import java.time.LocalDateTime;
  11 +
  12 +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
  13 +
  14 +@Schema(description = "管理后台 - 社交用户分页 Request VO")
  15 +@Data
  16 +@EqualsAndHashCode(callSuper = true)
  17 +@ToString(callSuper = true)
  18 +public class SocialUserPageReqVO extends PageParam {
  19 +
  20 + @Schema(description = "社交平台的类型", example = "30")
  21 + private Integer type;
  22 +
  23 + @Schema(description = "用户昵称", example = "李四")
  24 + private String nickname;
  25 +
  26 + @Schema(description = "创建时间")
  27 + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
  28 + private LocalDateTime[] createTime;
  29 +
  30 +}
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/user/SocialUserRespVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.system.controller.admin.socail.vo.user;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import lombok.Data;
  5 +import lombok.EqualsAndHashCode;
  6 +import lombok.ToString;
  7 +
  8 +import java.time.LocalDateTime;
  9 +
  10 +@Schema(description = "管理后台 - 社交用户 Response VO")
  11 +@Data
  12 +@EqualsAndHashCode(callSuper = true)
  13 +@ToString(callSuper = true)
  14 +public class SocialUserRespVO extends SocialUserBaseVO {
  15 +
  16 + @Schema(description = "主键(自增策略)", requiredMode = Schema.RequiredMode.REQUIRED, example = "14569")
  17 + private Long id;
  18 +
  19 + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
  20 + private LocalDateTime createTime;
  21 +
  22 +}
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/user/SocialUserUpdateReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.system.controller.admin.socail.vo.user;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import lombok.Data;
  5 +import lombok.EqualsAndHashCode;
  6 +import lombok.ToString;
  7 +
  8 +import javax.validation.constraints.NotNull;
  9 +
  10 +@Schema(description = "管理后台 - 社交用户更新 Request VO")
  11 +@Data
  12 +@EqualsAndHashCode(callSuper = true)
  13 +@ToString(callSuper = true)
  14 +public class SocialUserUpdateReqVO extends SocialUserBaseVO {
  15 +
  16 + @Schema(description = "主键(自增策略)", requiredMode = Schema.RequiredMode.REQUIRED, example = "14569")
  17 + @NotNull(message = "主键(自增策略)不能为空")
  18 + private Long id;
  19 +
  20 +}
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/social/SocialUserConvert.java
1 1 package cn.iocoder.yudao.module.system.convert.social;
2 2  
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
3 4 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO;
4 5 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserUnbindReqDTO;
5 6 import cn.iocoder.yudao.module.system.controller.admin.socail.vo.SocialUserBindReqVO;
6 7 import cn.iocoder.yudao.module.system.controller.admin.socail.vo.SocialUserUnbindReqVO;
  8 +import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserRespVO;
  9 +import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserUpdateReqVO;
  10 +import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO;
7 11 import org.mapstruct.Mapper;
8 12 import org.mapstruct.factory.Mappers;
9 13  
  14 +import java.util.List;
  15 +
10 16 @Mapper
11 17 public interface SocialUserConvert {
12 18  
... ... @@ -16,4 +22,12 @@ public interface SocialUserConvert {
16 22  
17 23 SocialUserUnbindReqDTO convert(Long userId, Integer userType, SocialUserUnbindReqVO reqVO);
18 24  
  25 + SocialUserDO convert(SocialUserUpdateReqVO bean);
  26 +
  27 + SocialUserRespVO convert(SocialUserDO bean);
  28 +
  29 + List<SocialUserRespVO> convertList(List<SocialUserDO> list);
  30 +
  31 + PageResult<SocialUserRespVO> convertPage(PageResult<SocialUserDO> page);
  32 +
19 33 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/social/SocialUserMapper.java
1 1 package cn.iocoder.yudao.module.system.dal.mysql.social;
2 2  
3   -import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO;
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 4 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
  5 +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
  6 +import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserPageReqVO;
  7 +import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO;
5 8 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
6   -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
7 9 import org.apache.ibatis.annotations.Mapper;
8 10  
9   -import java.util.Collection;
10   -import java.util.List;
11   -
12 11 @Mapper
13 12 public interface SocialUserMapper extends BaseMapperX<SocialUserDO> {
14 13  
... ... @@ -25,4 +24,12 @@ public interface SocialUserMapper extends BaseMapperX&lt;SocialUserDO&gt; {
25 24 .eq(SocialUserDO::getOpenid, openid));
26 25 }
27 26  
  27 + default PageResult<SocialUserDO> selectPage(SocialUserPageReqVO reqVO) {
  28 + return selectPage(reqVO, new LambdaQueryWrapperX<SocialUserDO>()
  29 + .eqIfPresent(SocialUserDO::getType, reqVO.getType())
  30 + .likeIfPresent(SocialUserDO::getNickname, reqVO.getNickname())
  31 + .betweenIfPresent(SocialUserDO::getCreateTime, reqVO.getCreateTime())
  32 + .orderByDesc(SocialUserDO::getId));
  33 + }
  34 +
28 35 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserService.java
1 1 package cn.iocoder.yudao.module.system.service.social;
2 2  
3 3 import cn.iocoder.yudao.framework.common.exception.ServiceException;
  4 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 5 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO;
5 6 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO;
  7 +import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserPageReqVO;
  8 +import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserUpdateReqVO;
6 9 import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO;
7 10 import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
8 11  
9 12 import javax.validation.Valid;
  13 +import java.util.Collection;
10 14 import java.util.List;
11 15  
12 16 /**
... ... @@ -19,7 +23,7 @@ public interface SocialUserService {
19 23 /**
20 24 * 获得指定用户的社交用户列表
21 25 *
22   - * @param userId 用户编号
  26 + * @param userId 用户编号
23 27 * @param userType 用户类型
24 28 * @return 社交用户列表
25 29 */
... ... @@ -36,10 +40,10 @@ public interface SocialUserService {
36 40 /**
37 41 * 取消绑定社交用户
38 42 *
39   - * @param userId 用户编号
  43 + * @param userId 用户编号
40 44 * @param userType 全局用户类型
41   - * @param type 社交平台的类型 {@link SocialTypeEnum}
42   - * @param openid 社交平台的 openid
  45 + * @param type 社交平台的类型 {@link SocialTypeEnum}
  46 + * @param openid 社交平台的 openid
43 47 */
44 48 void unbindSocialUser(Long userId, Integer userType, Integer type, String openid);
45 49  
... ... @@ -49,11 +53,51 @@ public interface SocialUserService {
49 53 * 在认证信息不正确的情况下,也会抛出 {@link ServiceException} 业务异常
50 54 *
51 55 * @param userType 用户类型
52   - * @param type 社交平台的类型
53   - * @param code 授权码
54   - * @param state state
  56 + * @param type 社交平台的类型
  57 + * @param code 授权码
  58 + * @param state state
55 59 * @return 社交用户
56 60 */
57 61 SocialUserRespDTO getSocialUser(Integer userType, Integer type, String code, String state);
58 62  
  63 + // ==================== 社交用户 CRUD ====================
  64 +
  65 + /**
  66 + * 更新社交用户
  67 + *
  68 + * @param updateReqVO 更新信息
  69 + */
  70 + void updateSocialUser(@Valid SocialUserUpdateReqVO updateReqVO);
  71 +
  72 + /**
  73 + * 删除社交用户
  74 + *
  75 + * @param id 编号
  76 + */
  77 + void deleteSocialUser(Long id);
  78 +
  79 + /**
  80 + * 获得社交用户
  81 + *
  82 + * @param id 编号
  83 + * @return 社交用户
  84 + */
  85 + SocialUserDO getSocialUser(Long id);
  86 +
  87 + /**
  88 + * 获得社交用户列表
  89 + *
  90 + * @param ids 编号
  91 + * @return 社交用户列表
  92 + */
  93 + List<SocialUserDO> getSocialUserList(Collection<Long> ids);
  94 +
  95 + /**
  96 + * 获得社交用户分页
  97 + *
  98 + * @param pageReqVO 分页查询
  99 + * @return 社交用户分页
  100 + */
  101 + PageResult<SocialUserDO> getSocialUserPage(SocialUserPageReqVO pageReqVO);
  102 +
59 103 }
... ...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImpl.java
1 1 package cn.iocoder.yudao.module.system.service.social;
2 2  
3 3 import cn.hutool.core.collection.CollUtil;
  4 +import cn.hutool.core.collection.ListUtil;
4 5 import cn.hutool.core.lang.Assert;
5 6 import cn.iocoder.yudao.framework.common.exception.ServiceException;
  7 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
6 8 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO;
7 9 import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO;
  10 +import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserPageReqVO;
  11 +import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserUpdateReqVO;
  12 +import cn.iocoder.yudao.module.system.convert.social.SocialUserConvert;
8 13 import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserBindDO;
9 14 import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO;
10 15 import cn.iocoder.yudao.module.system.dal.mysql.social.SocialUserBindMapper;
... ... @@ -18,14 +23,14 @@ import org.springframework.validation.annotation.Validated;
18 23  
19 24 import javax.annotation.Resource;
20 25 import javax.validation.constraints.NotNull;
  26 +import java.util.Collection;
21 27 import java.util.Collections;
22 28 import java.util.List;
23 29  
24 30 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
25 31 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
26 32 import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString;
27   -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.AUTH_THIRD_LOGIN_NOT_BIND;
28   -import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.SOCIAL_USER_NOT_FOUND;
  33 +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
29 34  
30 35 /**
31 36 * 社交用户 Service 实现类
... ... @@ -107,14 +112,15 @@ public class SocialUserServiceImpl implements SocialUserService {
107 112 }
108 113  
109 114 // TODO 芋艿:调整下单测
  115 +
110 116 /**
111 117 * 授权获得对应的社交用户
112 118 * 如果授权失败,则会抛出 {@link ServiceException} 异常
113 119 *
114   - * @param type 社交平台的类型 {@link SocialTypeEnum}
  120 + * @param type 社交平台的类型 {@link SocialTypeEnum}
115 121 * @param userType 用户类型
116   - * @param code 授权码
117   - * @param state state
  122 + * @param code 授权码
  123 + * @param state state
118 124 * @return 授权用户
119 125 */
120 126 @NotNull
... ... @@ -146,4 +152,47 @@ public class SocialUserServiceImpl implements SocialUserService {
146 152 return socialUser;
147 153 }
148 154  
  155 + // ==================== 社交用户 CRUD ====================
  156 +
  157 + @Override
  158 + public void updateSocialUser(SocialUserUpdateReqVO updateReqVO) {
  159 + // 校验存在
  160 + validateSocialUserExists(updateReqVO.getId());
  161 + // 更新
  162 + SocialUserDO updateObj = SocialUserConvert.INSTANCE.convert(updateReqVO);
  163 + socialUserMapper.updateById(updateObj);
  164 + }
  165 +
  166 + @Override
  167 + public void deleteSocialUser(Long id) {
  168 + // 校验存在
  169 + validateSocialUserExists(id);
  170 + // 删除
  171 + socialUserMapper.deleteById(id);
  172 + }
  173 +
  174 + private void validateSocialUserExists(Long id) {
  175 + if (socialUserMapper.selectById(id) == null) {
  176 + throw exception(SOCIAL_USER_NOT_EXISTS);
  177 + }
  178 + }
  179 +
  180 + @Override
  181 + public SocialUserDO getSocialUser(Long id) {
  182 + return socialUserMapper.selectById(id);
  183 + }
  184 +
  185 + @Override
  186 + public List<SocialUserDO> getSocialUserList(Collection<Long> ids) {
  187 + if (CollUtil.isEmpty(ids)) {
  188 + return ListUtil.empty();
  189 + }
  190 + return socialUserMapper.selectBatchIds(ids);
  191 + }
  192 +
  193 + @Override
  194 + public PageResult<SocialUserDO> getSocialUserPage(SocialUserPageReqVO pageReqVO) {
  195 + return socialUserMapper.selectPage(pageReqVO);
  196 + }
  197 +
149 198 }
... ...