Commit 87bc3f510c27374714398e9cfafc2c698b518e21
1 parent
e9317bf2
优化:社交登录、用户的管理
Showing
17 changed files
with
77 additions
and
148 deletions
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java
| @@ -116,11 +116,11 @@ public interface ErrorCodeConstants { | @@ -116,11 +116,11 @@ public interface ErrorCodeConstants { | ||
| 116 | 116 | ||
| 117 | // ========== 社交用户 1-002-018-000 ========== | 117 | // ========== 社交用户 1-002-018-000 ========== |
| 118 | ErrorCode SOCIAL_USER_AUTH_FAILURE = new ErrorCode(1_002_018_000, "社交授权失败,原因是:{}"); | 118 | ErrorCode SOCIAL_USER_AUTH_FAILURE = new ErrorCode(1_002_018_000, "社交授权失败,原因是:{}"); |
| 119 | - ErrorCode SOCIAL_USER_UNBIND_NOT_SELF = new ErrorCode(1_002_018_001, "社交解绑失败,非当前用户绑定"); | ||
| 120 | - ErrorCode SOCIAL_USER_NOT_FOUND = new ErrorCode(1_002_018_002, "社交授权失败,找不到对应的用户"); | ||
| 121 | - ErrorCode SOCIAL_APP_WEIXIN_MINI_APP_PHONE_CODE_ERROR = new ErrorCode(1_002_018_103, "获得手机号失败"); | ||
| 122 | - ErrorCode SOCIAL_CLIENT_NOT_EXISTS = new ErrorCode(1_002_018_104, "社交客户端不存在"); | ||
| 123 | - ErrorCode SOCIAL_USER_NOT_EXISTS = new ErrorCode(1_002_018_105, "社交用户不存在"); | 119 | + ErrorCode SOCIAL_USER_NOT_FOUND = new ErrorCode(1_002_018_001, "社交授权失败,找不到对应的用户"); |
| 120 | + | ||
| 121 | + ErrorCode SOCIAL_CLIENT_WEIXIN_MINI_APP_PHONE_CODE_ERROR = new ErrorCode(1_002_018_200, "获得手机号失败"); | ||
| 122 | + ErrorCode SOCIAL_CLIENT_NOT_EXISTS = new ErrorCode(1_002_018_201, "社交客户端不存在"); | ||
| 123 | + ErrorCode SOCIAL_CLIENT_UNIQUE = new ErrorCode(1_002_018_201, "社交客户端已存在配置"); | ||
| 124 | 124 | ||
| 125 | // ========== 系统敏感词 1-002-019-000 ========= | 125 | // ========== 系统敏感词 1-002-019-000 ========= |
| 126 | ErrorCode SENSITIVE_WORD_NOT_EXISTS = new ErrorCode(1_002_019_000, "系统敏感词在所有标签中都不存在"); | 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
| @@ -7,7 +7,6 @@ import cn.iocoder.yudao.module.system.controller.admin.socail.vo.SocialUserBindR | @@ -7,7 +7,6 @@ import cn.iocoder.yudao.module.system.controller.admin.socail.vo.SocialUserBindR | ||
| 7 | import cn.iocoder.yudao.module.system.controller.admin.socail.vo.SocialUserUnbindReqVO; | 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; | 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; | 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; | ||
| 11 | import cn.iocoder.yudao.module.system.convert.social.SocialUserConvert; | 10 | import cn.iocoder.yudao.module.system.convert.social.SocialUserConvert; |
| 12 | import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO; | 11 | import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO; |
| 13 | import cn.iocoder.yudao.module.system.service.social.SocialUserService; | 12 | import cn.iocoder.yudao.module.system.service.social.SocialUserService; |
| @@ -49,23 +48,6 @@ public class SocialUserController { | @@ -49,23 +48,6 @@ public class SocialUserController { | ||
| 49 | 48 | ||
| 50 | // ==================== 社交用户 CRUD ==================== | 49 | // ==================== 社交用户 CRUD ==================== |
| 51 | 50 | ||
| 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") | 51 | @GetMapping("/get") |
| 70 | @Operation(summary = "获得社交用户") | 52 | @Operation(summary = "获得社交用户") |
| 71 | @Parameter(name = "id", description = "编号", required = true, example = "1024") | 53 | @Parameter(name = "id", description = "编号", required = true, example = "1024") |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/client/SocialClientBaseVO.java
| 1 | package cn.iocoder.yudao.module.system.controller.admin.socail.vo.client; | 1 | package cn.iocoder.yudao.module.system.controller.admin.socail.vo.client; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.util.StrUtil; | ||
| 4 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 5 | +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | ||
| 6 | +import cn.iocoder.yudao.framework.common.validation.InEnum; | ||
| 7 | +import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; | ||
| 8 | +import com.fasterxml.jackson.annotation.JsonIgnore; | ||
| 3 | import io.swagger.v3.oas.annotations.media.Schema; | 9 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | import lombok.Data; | 10 | import lombok.Data; |
| 5 | 11 | ||
| 12 | +import javax.validation.constraints.AssertTrue; | ||
| 6 | import javax.validation.constraints.NotNull; | 13 | import javax.validation.constraints.NotNull; |
| 14 | +import java.util.Objects; | ||
| 7 | 15 | ||
| 8 | /** | 16 | /** |
| 9 | * 社交客户端 Base VO,提供给添加、修改、详细的子 VO 使用 | 17 | * 社交客户端 Base VO,提供给添加、修改、详细的子 VO 使用 |
| @@ -18,10 +26,12 @@ public class SocialClientBaseVO { | @@ -18,10 +26,12 @@ public class SocialClientBaseVO { | ||
| 18 | 26 | ||
| 19 | @Schema(description = "社交平台的类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "31") | 27 | @Schema(description = "社交平台的类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "31") |
| 20 | @NotNull(message = "社交平台的类型不能为空") | 28 | @NotNull(message = "社交平台的类型不能为空") |
| 29 | + @InEnum(SocialTypeEnum.class) | ||
| 21 | private Integer socialType; | 30 | private Integer socialType; |
| 22 | 31 | ||
| 23 | @Schema(description = "用户类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") | 32 | @Schema(description = "用户类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") |
| 24 | @NotNull(message = "用户类型不能为空") | 33 | @NotNull(message = "用户类型不能为空") |
| 34 | + @InEnum(UserTypeEnum.class) | ||
| 25 | private Integer userType; | 35 | private Integer userType; |
| 26 | 36 | ||
| 27 | @Schema(description = "客户端编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "wwd411c69a39ad2e54") | 37 | @Schema(description = "客户端编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "wwd411c69a39ad2e54") |
| @@ -37,6 +47,19 @@ public class SocialClientBaseVO { | @@ -37,6 +47,19 @@ public class SocialClientBaseVO { | ||
| 37 | 47 | ||
| 38 | @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | 48 | @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 39 | @NotNull(message = "状态不能为空") | 49 | @NotNull(message = "状态不能为空") |
| 50 | + @InEnum(CommonStatusEnum.class) | ||
| 40 | private Integer status; | 51 | private Integer status; |
| 41 | 52 | ||
| 53 | + @SuppressWarnings("RedundantIfStatement") | ||
| 54 | + @AssertTrue(message = "agentId 不能为空") | ||
| 55 | + @JsonIgnore | ||
| 56 | + public boolean isAgentIdValid() { | ||
| 57 | + // 如果是企业微信,必须填写 agentId 属性 | ||
| 58 | + if (Objects.equals(socialType, SocialTypeEnum.WECHAT_ENTERPRISE.getType()) | ||
| 59 | + && StrUtil.isEmpty(agentId)) { | ||
| 60 | + return false; | ||
| 61 | + } | ||
| 62 | + return true; | ||
| 63 | + } | ||
| 64 | + | ||
| 42 | } | 65 | } |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/client/SocialClientPageReqVO.java
| @@ -5,11 +5,6 @@ import io.swagger.v3.oas.annotations.media.Schema; | @@ -5,11 +5,6 @@ import io.swagger.v3.oas.annotations.media.Schema; | ||
| 5 | import lombok.Data; | 5 | import lombok.Data; |
| 6 | import lombok.EqualsAndHashCode; | 6 | import lombok.EqualsAndHashCode; |
| 7 | import lombok.ToString; | 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 | 8 | ||
| 14 | @Schema(description = "管理后台 - 社交客户端分页 Request VO") | 9 | @Schema(description = "管理后台 - 社交客户端分页 Request VO") |
| 15 | @Data | 10 | @Data |
| @@ -29,14 +24,7 @@ public class SocialClientPageReqVO extends PageParam { | @@ -29,14 +24,7 @@ public class SocialClientPageReqVO extends PageParam { | ||
| 29 | @Schema(description = "客户端编号", example = "145442115") | 24 | @Schema(description = "客户端编号", example = "145442115") |
| 30 | private String clientId; | 25 | private String clientId; |
| 31 | 26 | ||
| 32 | - @Schema(description = "客户端密钥", example = "215151515154446") | ||
| 33 | - private String clientSecret; | ||
| 34 | - | ||
| 35 | @Schema(description = "状态", example = "1") | 27 | @Schema(description = "状态", example = "1") |
| 36 | private Integer status; | 28 | private Integer status; |
| 37 | 29 | ||
| 38 | - @Schema(description = "创建时间") | ||
| 39 | - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | ||
| 40 | - private LocalDateTime[] createTime; | ||
| 41 | - | ||
| 42 | } | 30 | } |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/user/SocialUserBaseVO.java
| @@ -20,10 +20,10 @@ public class SocialUserBaseVO { | @@ -20,10 +20,10 @@ public class SocialUserBaseVO { | ||
| 20 | @NotNull(message = "社交 openid不能为空") | 20 | @NotNull(message = "社交 openid不能为空") |
| 21 | private String openid; | 21 | private String openid; |
| 22 | 22 | ||
| 23 | - @Schema(description = "社交 token", example = "666") | 23 | + @Schema(description = "社交 token", requiredMode = Schema.RequiredMode.REQUIRED, example = "666") |
| 24 | private String token; | 24 | private String token; |
| 25 | 25 | ||
| 26 | - @Schema(description = "原始 Token 数据,一般是 JSON 格式", example = "{}") | 26 | + @Schema(description = "原始 Token 数据,一般是 JSON 格式", requiredMode = Schema.RequiredMode.REQUIRED, example = "{}") |
| 27 | private String rawTokenInfo; | 27 | private String rawTokenInfo; |
| 28 | 28 | ||
| 29 | @Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") | 29 | @Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") |
| @@ -33,13 +33,13 @@ public class SocialUserBaseVO { | @@ -33,13 +33,13 @@ public class SocialUserBaseVO { | ||
| 33 | @Schema(description = "用户头像", example = "https://www.iocoder.cn/xxx.png") | 33 | @Schema(description = "用户头像", example = "https://www.iocoder.cn/xxx.png") |
| 34 | private String avatar; | 34 | private String avatar; |
| 35 | 35 | ||
| 36 | - @Schema(description = "原始用户数据,一般是 JSON 格式", example = "{}") | 36 | + @Schema(description = "原始用户数据,一般是 JSON 格式", requiredMode = Schema.RequiredMode.REQUIRED, example = "{}") |
| 37 | private String rawUserInfo; | 37 | private String rawUserInfo; |
| 38 | 38 | ||
| 39 | - @Schema(description = "最后一次的认证 code", example = "666666") | 39 | + @Schema(description = "最后一次的认证 code", requiredMode = Schema.RequiredMode.REQUIRED, example = "666666") |
| 40 | private String code; | 40 | private String code; |
| 41 | 41 | ||
| 42 | - @Schema(description = "最后一次的认证 state", example = "123456") | 42 | + @Schema(description = "最后一次的认证 state", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456") |
| 43 | private String state; | 43 | private String state; |
| 44 | 44 | ||
| 45 | } | 45 | } |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/user/SocialUserPageReqVO.java
| @@ -23,6 +23,9 @@ public class SocialUserPageReqVO extends PageParam { | @@ -23,6 +23,9 @@ public class SocialUserPageReqVO extends PageParam { | ||
| 23 | @Schema(description = "用户昵称", example = "李四") | 23 | @Schema(description = "用户昵称", example = "李四") |
| 24 | private String nickname; | 24 | private String nickname; |
| 25 | 25 | ||
| 26 | + @Schema(description = "社交 openid", example = "oz-Jdt0kd_jdhUxJHQdBJMlOFN7w\n") | ||
| 27 | + private String openid; | ||
| 28 | + | ||
| 26 | @Schema(description = "创建时间") | 29 | @Schema(description = "创建时间") |
| 27 | @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | 30 | @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) |
| 28 | private LocalDateTime[] createTime; | 31 | private LocalDateTime[] createTime; |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/user/SocialUserRespVO.java
| @@ -19,4 +19,7 @@ public class SocialUserRespVO extends SocialUserBaseVO { | @@ -19,4 +19,7 @@ public class SocialUserRespVO extends SocialUserBaseVO { | ||
| 19 | @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) | 19 | @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) |
| 20 | private LocalDateTime createTime; | 20 | private LocalDateTime createTime; |
| 21 | 21 | ||
| 22 | + @Schema(description = "更新时间", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 23 | + private LocalDateTime updateTime; | ||
| 24 | + | ||
| 22 | } | 25 | } |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/user/SocialUserUpdateReqVO.java deleted
| 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
| @@ -6,7 +6,6 @@ import cn.iocoder.yudao.module.system.api.social.dto.SocialUserUnbindReqDTO; | @@ -6,7 +6,6 @@ import cn.iocoder.yudao.module.system.api.social.dto.SocialUserUnbindReqDTO; | ||
| 6 | import cn.iocoder.yudao.module.system.controller.admin.socail.vo.SocialUserBindReqVO; | 6 | import cn.iocoder.yudao.module.system.controller.admin.socail.vo.SocialUserBindReqVO; |
| 7 | import cn.iocoder.yudao.module.system.controller.admin.socail.vo.SocialUserUnbindReqVO; | 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; | 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; | 9 | import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO; |
| 11 | import org.mapstruct.Mapper; | 10 | import org.mapstruct.Mapper; |
| 12 | import org.mapstruct.Mapping; | 11 | import org.mapstruct.Mapping; |
| @@ -24,8 +23,6 @@ public interface SocialUserConvert { | @@ -24,8 +23,6 @@ public interface SocialUserConvert { | ||
| 24 | 23 | ||
| 25 | SocialUserUnbindReqDTO convert(Long userId, Integer userType, SocialUserUnbindReqVO reqVO); | 24 | SocialUserUnbindReqDTO convert(Long userId, Integer userType, SocialUserUnbindReqVO reqVO); |
| 26 | 25 | ||
| 27 | - SocialUserDO convert(SocialUserUpdateReqVO bean); | ||
| 28 | - | ||
| 29 | SocialUserRespVO convert(SocialUserDO bean); | 26 | SocialUserRespVO convert(SocialUserDO bean); |
| 30 | 27 | ||
| 31 | List<SocialUserRespVO> convertList(List<SocialUserDO> list); | 28 | List<SocialUserRespVO> convertList(List<SocialUserDO> list); |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/social/SocialClientDO.java
| @@ -64,8 +64,12 @@ public class SocialClientDO extends TenantBaseDO { | @@ -64,8 +64,12 @@ public class SocialClientDO extends TenantBaseDO { | ||
| 64 | * 客户端 Secret | 64 | * 客户端 Secret |
| 65 | */ | 65 | */ |
| 66 | private String clientSecret; | 66 | private String clientSecret; |
| 67 | + | ||
| 67 | /** | 68 | /** |
| 68 | - * 授权方的网页应用 ID | 69 | + * 代理编号 |
| 70 | + * | ||
| 71 | + * 目前只有部分“社交类型”在使用: | ||
| 72 | + * 1. 企业微信:对应授权方的网页应用 ID | ||
| 69 | */ | 73 | */ |
| 70 | private String agentId; | 74 | private String agentId; |
| 71 | 75 |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/social/SocialClientMapper.java
| @@ -21,9 +21,7 @@ public interface SocialClientMapper extends BaseMapperX<SocialClientDO> { | @@ -21,9 +21,7 @@ public interface SocialClientMapper extends BaseMapperX<SocialClientDO> { | ||
| 21 | .eqIfPresent(SocialClientDO::getSocialType, reqVO.getSocialType()) | 21 | .eqIfPresent(SocialClientDO::getSocialType, reqVO.getSocialType()) |
| 22 | .eqIfPresent(SocialClientDO::getUserType, reqVO.getUserType()) | 22 | .eqIfPresent(SocialClientDO::getUserType, reqVO.getUserType()) |
| 23 | .eqIfPresent(SocialClientDO::getClientId, reqVO.getClientId()) | 23 | .eqIfPresent(SocialClientDO::getClientId, reqVO.getClientId()) |
| 24 | - .eqIfPresent(SocialClientDO::getClientSecret, reqVO.getClientSecret()) | ||
| 25 | .eqIfPresent(SocialClientDO::getStatus, reqVO.getStatus()) | 24 | .eqIfPresent(SocialClientDO::getStatus, reqVO.getStatus()) |
| 26 | - .betweenIfPresent(SocialClientDO::getCreateTime, reqVO.getCreateTime()) | ||
| 27 | .orderByDesc(SocialClientDO::getId)); | 25 | .orderByDesc(SocialClientDO::getId)); |
| 28 | } | 26 | } |
| 29 | 27 |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/social/SocialUserMapper.java
| @@ -28,6 +28,7 @@ public interface SocialUserMapper extends BaseMapperX<SocialUserDO> { | @@ -28,6 +28,7 @@ public interface SocialUserMapper extends BaseMapperX<SocialUserDO> { | ||
| 28 | return selectPage(reqVO, new LambdaQueryWrapperX<SocialUserDO>() | 28 | return selectPage(reqVO, new LambdaQueryWrapperX<SocialUserDO>() |
| 29 | .eqIfPresent(SocialUserDO::getType, reqVO.getType()) | 29 | .eqIfPresent(SocialUserDO::getType, reqVO.getType()) |
| 30 | .likeIfPresent(SocialUserDO::getNickname, reqVO.getNickname()) | 30 | .likeIfPresent(SocialUserDO::getNickname, reqVO.getNickname()) |
| 31 | + .likeIfPresent(SocialUserDO::getOpenid, reqVO.getOpenid()) | ||
| 31 | .betweenIfPresent(SocialUserDO::getCreateTime, reqVO.getCreateTime()) | 32 | .betweenIfPresent(SocialUserDO::getCreateTime, reqVO.getCreateTime()) |
| 32 | .orderByDesc(SocialUserDO::getId)); | 33 | .orderByDesc(SocialUserDO::getId)); |
| 33 | } | 34 | } |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientService.java
| @@ -11,8 +11,6 @@ import com.xingyuv.jushauth.model.AuthUser; | @@ -11,8 +11,6 @@ import com.xingyuv.jushauth.model.AuthUser; | ||
| 11 | import me.chanjar.weixin.common.bean.WxJsapiSignature; | 11 | import me.chanjar.weixin.common.bean.WxJsapiSignature; |
| 12 | 12 | ||
| 13 | import javax.validation.Valid; | 13 | import javax.validation.Valid; |
| 14 | -import java.util.Collection; | ||
| 15 | -import java.util.List; | ||
| 16 | 14 | ||
| 17 | /** | 15 | /** |
| 18 | * 社交应用 Service 接口 | 16 | * 社交应用 Service 接口 |
| @@ -97,14 +95,6 @@ public interface SocialClientService { | @@ -97,14 +95,6 @@ public interface SocialClientService { | ||
| 97 | SocialClientDO getSocialClient(Long id); | 95 | SocialClientDO getSocialClient(Long id); |
| 98 | 96 | ||
| 99 | /** | 97 | /** |
| 100 | - * 获得社交客户端列表 | ||
| 101 | - * | ||
| 102 | - * @param ids 编号 | ||
| 103 | - * @return 社交客户端列表 | ||
| 104 | - */ | ||
| 105 | - List<SocialClientDO> getSocialClientList(Collection<Long> ids); | ||
| 106 | - | ||
| 107 | - /** | ||
| 108 | * 获得社交客户端分页 | 98 | * 获得社交客户端分页 |
| 109 | * | 99 | * |
| 110 | * @param pageReqVO 分页查询 | 100 | * @param pageReqVO 分页查询 |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImpl.java
| @@ -5,9 +5,8 @@ import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; | @@ -5,9 +5,8 @@ import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; | ||
| 5 | import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; | 5 | import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; |
| 6 | import cn.binarywang.wx.miniapp.config.impl.WxMaRedisBetterConfigImpl; | 6 | import cn.binarywang.wx.miniapp.config.impl.WxMaRedisBetterConfigImpl; |
| 7 | import cn.hutool.core.bean.BeanUtil; | 7 | import cn.hutool.core.bean.BeanUtil; |
| 8 | -import cn.hutool.core.collection.CollUtil; | ||
| 9 | -import cn.hutool.core.collection.ListUtil; | ||
| 10 | import cn.hutool.core.lang.Assert; | 8 | import cn.hutool.core.lang.Assert; |
| 9 | +import cn.hutool.core.util.ObjUtil; | ||
| 11 | import cn.hutool.core.util.ReflectUtil; | 10 | import cn.hutool.core.util.ReflectUtil; |
| 12 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 11 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 13 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 12 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| @@ -23,6 +22,7 @@ import cn.iocoder.yudao.module.system.dal.mysql.social.SocialClientMapper; | @@ -23,6 +22,7 @@ import cn.iocoder.yudao.module.system.dal.mysql.social.SocialClientMapper; | ||
| 23 | import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; | 22 | import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; |
| 24 | import com.binarywang.spring.starter.wxjava.miniapp.properties.WxMaProperties; | 23 | import com.binarywang.spring.starter.wxjava.miniapp.properties.WxMaProperties; |
| 25 | import com.binarywang.spring.starter.wxjava.mp.properties.WxMpProperties; | 24 | import com.binarywang.spring.starter.wxjava.mp.properties.WxMpProperties; |
| 25 | +import com.google.common.annotations.VisibleForTesting; | ||
| 26 | import com.google.common.cache.CacheLoader; | 26 | import com.google.common.cache.CacheLoader; |
| 27 | import com.google.common.cache.LoadingCache; | 27 | import com.google.common.cache.LoadingCache; |
| 28 | import com.xingyuv.jushauth.config.AuthConfig; | 28 | import com.xingyuv.jushauth.config.AuthConfig; |
| @@ -44,8 +44,6 @@ import org.springframework.stereotype.Service; | @@ -44,8 +44,6 @@ import org.springframework.stereotype.Service; | ||
| 44 | 44 | ||
| 45 | import javax.annotation.Resource; | 45 | import javax.annotation.Resource; |
| 46 | import java.time.Duration; | 46 | import java.time.Duration; |
| 47 | -import java.util.Collection; | ||
| 48 | -import java.util.List; | ||
| 49 | import java.util.Objects; | 47 | import java.util.Objects; |
| 50 | 48 | ||
| 51 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 49 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| @@ -224,7 +222,7 @@ public class SocialClientServiceImpl implements SocialClientService { | @@ -224,7 +222,7 @@ public class SocialClientServiceImpl implements SocialClientService { | ||
| 224 | return service.getUserService().getPhoneNoInfo(phoneCode); | 222 | return service.getUserService().getPhoneNoInfo(phoneCode); |
| 225 | } catch (WxErrorException e) { | 223 | } catch (WxErrorException e) { |
| 226 | log.error("[getPhoneNoInfo][userType({}) phoneCode({}) 获得手机号失败]", userType, phoneCode, e); | 224 | log.error("[getPhoneNoInfo][userType({}) phoneCode({}) 获得手机号失败]", userType, phoneCode, e); |
| 227 | - throw exception(SOCIAL_APP_WEIXIN_MINI_APP_PHONE_CODE_ERROR); | 225 | + throw exception(SOCIAL_CLIENT_WEIXIN_MINI_APP_PHONE_CODE_ERROR); |
| 228 | } | 226 | } |
| 229 | } | 227 | } |
| 230 | 228 | ||
| @@ -270,6 +268,9 @@ public class SocialClientServiceImpl implements SocialClientService { | @@ -270,6 +268,9 @@ public class SocialClientServiceImpl implements SocialClientService { | ||
| 270 | 268 | ||
| 271 | @Override | 269 | @Override |
| 272 | public Long createSocialClient(SocialClientCreateReqVO createReqVO) { | 270 | public Long createSocialClient(SocialClientCreateReqVO createReqVO) { |
| 271 | + // 校验重复 | ||
| 272 | + validateSocialClientUnique(null, createReqVO.getUserType(), createReqVO.getSocialType()); | ||
| 273 | + | ||
| 273 | // 插入 | 274 | // 插入 |
| 274 | SocialClientDO socialClient = SocialClientConvert.INSTANCE.convert(createReqVO); | 275 | SocialClientDO socialClient = SocialClientConvert.INSTANCE.convert(createReqVO); |
| 275 | socialClientMapper.insert(socialClient); | 276 | socialClientMapper.insert(socialClient); |
| @@ -281,6 +282,9 @@ public class SocialClientServiceImpl implements SocialClientService { | @@ -281,6 +282,9 @@ public class SocialClientServiceImpl implements SocialClientService { | ||
| 281 | public void updateSocialClient(SocialClientUpdateReqVO updateReqVO) { | 282 | public void updateSocialClient(SocialClientUpdateReqVO updateReqVO) { |
| 282 | // 校验存在 | 283 | // 校验存在 |
| 283 | validateSocialClientExists(updateReqVO.getId()); | 284 | validateSocialClientExists(updateReqVO.getId()); |
| 285 | + // 校验重复 | ||
| 286 | + validateSocialClientUnique(updateReqVO.getId(), updateReqVO.getUserType(), updateReqVO.getSocialType()); | ||
| 287 | + | ||
| 284 | // 更新 | 288 | // 更新 |
| 285 | SocialClientDO updateObj = SocialClientConvert.INSTANCE.convert(updateReqVO); | 289 | SocialClientDO updateObj = SocialClientConvert.INSTANCE.convert(updateReqVO); |
| 286 | socialClientMapper.updateById(updateObj); | 290 | socialClientMapper.updateById(updateObj); |
| @@ -300,17 +304,31 @@ public class SocialClientServiceImpl implements SocialClientService { | @@ -300,17 +304,31 @@ public class SocialClientServiceImpl implements SocialClientService { | ||
| 300 | } | 304 | } |
| 301 | } | 305 | } |
| 302 | 306 | ||
| 303 | - @Override | ||
| 304 | - public SocialClientDO getSocialClient(Long id) { | ||
| 305 | - return socialClientMapper.selectById(id); | 307 | + /** |
| 308 | + * 校验社交应用是否重复,需要保证 userType + socialType 唯一 | ||
| 309 | + * | ||
| 310 | + * 原因是,不同端(userType)选择某个社交登录(socialType)时,需要通过 {@link #buildAuthRequest(Integer, Integer)} 构建对应的请求 | ||
| 311 | + * | ||
| 312 | + * @param id 编号 | ||
| 313 | + * @param userType 用户类型 | ||
| 314 | + * @param socialType 社交类型 | ||
| 315 | + */ | ||
| 316 | + @VisibleForTesting | ||
| 317 | + private void validateSocialClientUnique(Long id, Integer userType, Integer socialType) { | ||
| 318 | + SocialClientDO client = socialClientMapper.selectBySocialTypeAndUserType( | ||
| 319 | + socialType, userType); | ||
| 320 | + if (client == null) { | ||
| 321 | + return; | ||
| 322 | + } | ||
| 323 | + if (id == null // 新增时,说明重复 | ||
| 324 | + || ObjUtil.notEqual(id, client.getId())) { // 更新时,如果 id 不一致,说明重复 | ||
| 325 | + throw exception(SOCIAL_CLIENT_UNIQUE); | ||
| 326 | + } | ||
| 306 | } | 327 | } |
| 307 | 328 | ||
| 308 | @Override | 329 | @Override |
| 309 | - public List<SocialClientDO> getSocialClientList(Collection<Long> ids) { | ||
| 310 | - if (CollUtil.isEmpty(ids)) { | ||
| 311 | - return ListUtil.empty(); | ||
| 312 | - } | ||
| 313 | - return socialClientMapper.selectBatchIds(ids); | 330 | + public SocialClientDO getSocialClient(Long id) { |
| 331 | + return socialClientMapper.selectById(id); | ||
| 314 | } | 332 | } |
| 315 | 333 | ||
| 316 | @Override | 334 | @Override |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserService.java
| @@ -5,12 +5,10 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; | @@ -5,12 +5,10 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 5 | import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO; | 5 | import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO; |
| 6 | import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO; | 6 | import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO; |
| 7 | import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserPageReqVO; | 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; | ||
| 9 | import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO; | 8 | import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO; |
| 10 | import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; | 9 | import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; |
| 11 | 10 | ||
| 12 | import javax.validation.Valid; | 11 | import javax.validation.Valid; |
| 13 | -import java.util.Collection; | ||
| 14 | import java.util.List; | 12 | import java.util.List; |
| 15 | 13 | ||
| 16 | /** | 14 | /** |
| @@ -63,20 +61,6 @@ public interface SocialUserService { | @@ -63,20 +61,6 @@ public interface SocialUserService { | ||
| 63 | // ==================== 社交用户 CRUD ==================== | 61 | // ==================== 社交用户 CRUD ==================== |
| 64 | 62 | ||
| 65 | /** | 63 | /** |
| 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 | * 获得社交用户 | 64 | * 获得社交用户 |
| 81 | * | 65 | * |
| 82 | * @param id 编号 | 66 | * @param id 编号 |
| @@ -85,14 +69,6 @@ public interface SocialUserService { | @@ -85,14 +69,6 @@ public interface SocialUserService { | ||
| 85 | SocialUserDO getSocialUser(Long id); | 69 | SocialUserDO getSocialUser(Long id); |
| 86 | 70 | ||
| 87 | /** | 71 | /** |
| 88 | - * 获得社交用户列表 | ||
| 89 | - * | ||
| 90 | - * @param ids 编号 | ||
| 91 | - * @return 社交用户列表 | ||
| 92 | - */ | ||
| 93 | - List<SocialUserDO> getSocialUserList(Collection<Long> ids); | ||
| 94 | - | ||
| 95 | - /** | ||
| 96 | * 获得社交用户分页 | 72 | * 获得社交用户分页 |
| 97 | * | 73 | * |
| 98 | * @param pageReqVO 分页查询 | 74 | * @param pageReqVO 分页查询 |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImpl.java
| @@ -8,7 +8,6 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; | @@ -8,7 +8,6 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 8 | import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO; | 8 | import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO; |
| 9 | import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO; | 9 | import cn.iocoder.yudao.module.system.api.social.dto.SocialUserRespDTO; |
| 10 | import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserPageReqVO; | 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; | 11 | import cn.iocoder.yudao.module.system.convert.social.SocialUserConvert; |
| 13 | import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserBindDO; | 12 | import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserBindDO; |
| 14 | import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO; | 13 | import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO; |
| @@ -154,42 +153,11 @@ public class SocialUserServiceImpl implements SocialUserService { | @@ -154,42 +153,11 @@ public class SocialUserServiceImpl implements SocialUserService { | ||
| 154 | // ==================== 社交用户 CRUD ==================== | 153 | // ==================== 社交用户 CRUD ==================== |
| 155 | 154 | ||
| 156 | @Override | 155 | @Override |
| 157 | - public void updateSocialUser(SocialUserUpdateReqVO updateReqVO) { | ||
| 158 | - // 校验存在 | ||
| 159 | - validateSocialUserExists(updateReqVO.getId()); | ||
| 160 | - // 更新 | ||
| 161 | - SocialUserDO updateObj = SocialUserConvert.INSTANCE.convert(updateReqVO); | ||
| 162 | - socialUserMapper.updateById(updateObj); | ||
| 163 | - } | ||
| 164 | - | ||
| 165 | - @Override | ||
| 166 | - public void deleteSocialUser(Long id) { | ||
| 167 | - // 校验存在 | ||
| 168 | - validateSocialUserExists(id); | ||
| 169 | - // 删除 | ||
| 170 | - socialUserMapper.deleteById(id); | ||
| 171 | - } | ||
| 172 | - | ||
| 173 | - private void validateSocialUserExists(Long id) { | ||
| 174 | - if (socialUserMapper.selectById(id) == null) { | ||
| 175 | - throw exception(SOCIAL_USER_NOT_EXISTS); | ||
| 176 | - } | ||
| 177 | - } | ||
| 178 | - | ||
| 179 | - @Override | ||
| 180 | public SocialUserDO getSocialUser(Long id) { | 156 | public SocialUserDO getSocialUser(Long id) { |
| 181 | return socialUserMapper.selectById(id); | 157 | return socialUserMapper.selectById(id); |
| 182 | } | 158 | } |
| 183 | 159 | ||
| 184 | @Override | 160 | @Override |
| 185 | - public List<SocialUserDO> getSocialUserList(Collection<Long> ids) { | ||
| 186 | - if (CollUtil.isEmpty(ids)) { | ||
| 187 | - return ListUtil.empty(); | ||
| 188 | - } | ||
| 189 | - return socialUserMapper.selectBatchIds(ids); | ||
| 190 | - } | ||
| 191 | - | ||
| 192 | - @Override | ||
| 193 | public PageResult<SocialUserDO> getSocialUserPage(SocialUserPageReqVO pageReqVO) { | 161 | public PageResult<SocialUserDO> getSocialUserPage(SocialUserPageReqVO pageReqVO) { |
| 194 | return socialUserMapper.selectPage(pageReqVO); | 162 | return socialUserMapper.selectPage(pageReqVO); |
| 195 | } | 163 | } |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImplTest.java
| @@ -13,7 +13,6 @@ import org.springframework.context.annotation.Import; | @@ -13,7 +13,6 @@ import org.springframework.context.annotation.Import; | ||
| 13 | 13 | ||
| 14 | import javax.annotation.Resource; | 14 | import javax.annotation.Resource; |
| 15 | 15 | ||
| 16 | -import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; | ||
| 17 | import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; | 16 | import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; |
| 18 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; | 17 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; |
| 19 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; | 18 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; |
| @@ -22,6 +21,7 @@ import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; | @@ -22,6 +21,7 @@ import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; | ||
| 22 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.SOCIAL_CLIENT_NOT_EXISTS; | 21 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.SOCIAL_CLIENT_NOT_EXISTS; |
| 23 | import static org.junit.jupiter.api.Assertions.*; | 22 | import static org.junit.jupiter.api.Assertions.*; |
| 24 | 23 | ||
| 24 | +// TODO 芋艿:单测后续补充下; | ||
| 25 | /** | 25 | /** |
| 26 | * {@link SocialClientServiceImpl} 的单元测试类 | 26 | * {@link SocialClientServiceImpl} 的单元测试类 |
| 27 | * | 27 | * |
| @@ -133,9 +133,7 @@ public class SocialClientServiceImplTest extends BaseDbUnitTest { | @@ -133,9 +133,7 @@ public class SocialClientServiceImplTest extends BaseDbUnitTest { | ||
| 133 | reqVO.setSocialType(null); | 133 | reqVO.setSocialType(null); |
| 134 | reqVO.setUserType(null); | 134 | reqVO.setUserType(null); |
| 135 | reqVO.setClientId(null); | 135 | reqVO.setClientId(null); |
| 136 | - reqVO.setClientSecret(null); | ||
| 137 | reqVO.setStatus(null); | 136 | reqVO.setStatus(null); |
| 138 | - reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); | ||
| 139 | 137 | ||
| 140 | // 调用 | 138 | // 调用 |
| 141 | PageResult<SocialClientDO> pageResult = socialClientService.getSocialClientPage(reqVO); | 139 | PageResult<SocialClientDO> pageResult = socialClientService.getSocialClientPage(reqVO); |