diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java index 348edbedbd..7b9632e54e 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java +++ b/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 { // ========== 社交用户 1-002-018-000 ========== ErrorCode SOCIAL_USER_AUTH_FAILURE = new ErrorCode(1_002_018_000, "社交授权失败,原因是:{}"); - ErrorCode SOCIAL_USER_UNBIND_NOT_SELF = new ErrorCode(1_002_018_001, "社交解绑失败,非当前用户绑定"); - ErrorCode SOCIAL_USER_NOT_FOUND = new ErrorCode(1_002_018_002, "社交授权失败,找不到对应的用户"); - ErrorCode SOCIAL_APP_WEIXIN_MINI_APP_PHONE_CODE_ERROR = new ErrorCode(1_002_018_103, "获得手机号失败"); - ErrorCode SOCIAL_CLIENT_NOT_EXISTS = new ErrorCode(1_002_018_104, "社交客户端不存在"); - ErrorCode SOCIAL_USER_NOT_EXISTS = new ErrorCode(1_002_018_105, "社交用户不存在"); + ErrorCode SOCIAL_USER_NOT_FOUND = new ErrorCode(1_002_018_001, "社交授权失败,找不到对应的用户"); + + ErrorCode SOCIAL_CLIENT_WEIXIN_MINI_APP_PHONE_CODE_ERROR = new ErrorCode(1_002_018_200, "获得手机号失败"); + ErrorCode SOCIAL_CLIENT_NOT_EXISTS = new ErrorCode(1_002_018_201, "社交客户端不存在"); + ErrorCode SOCIAL_CLIENT_UNIQUE = new ErrorCode(1_002_018_201, "社交客户端已存在配置"); // ========== 系统敏感词 1-002-019-000 ========= ErrorCode SENSITIVE_WORD_NOT_EXISTS = new ErrorCode(1_002_019_000, "系统敏感词在所有标签中都不存在"); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/SocialUserController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/SocialUserController.java index 502d65817f..08b45147e5 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/SocialUserController.java +++ b/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 import cn.iocoder.yudao.module.system.controller.admin.socail.vo.SocialUserUnbindReqVO; import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserPageReqVO; import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserRespVO; -import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserUpdateReqVO; import cn.iocoder.yudao.module.system.convert.social.SocialUserConvert; import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO; import cn.iocoder.yudao.module.system.service.social.SocialUserService; @@ -49,23 +48,6 @@ public class SocialUserController { // ==================== 社交用户 CRUD ==================== - @PutMapping("/update") - @Operation(summary = "更新社交用户") - @PreAuthorize("@ss.hasPermission('system:social-user:update')") - public CommonResult updateSocialUser(@Valid @RequestBody SocialUserUpdateReqVO updateReqVO) { - socialUserService.updateSocialUser(updateReqVO); - return success(true); - } - - @DeleteMapping("/delete") - @Operation(summary = "删除社交用户") - @Parameter(name = "id", description = "编号", required = true) - @PreAuthorize("@ss.hasPermission('system:social-user:delete')") - public CommonResult deleteSocialUser(@RequestParam("id") Long id) { - socialUserService.deleteSocialUser(id); - return success(true); - } - @GetMapping("/get") @Operation(summary = "获得社交用户") @Parameter(name = "id", description = "编号", required = true, example = "1024") diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/client/SocialClientBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/client/SocialClientBaseVO.java index 9fe8e2b7ca..86d980ee0a 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/client/SocialClientBaseVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/client/SocialClientBaseVO.java @@ -1,9 +1,17 @@ package cn.iocoder.yudao.module.system.controller.admin.socail.vo.client; +import cn.hutool.core.util.StrUtil; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; +import cn.iocoder.yudao.framework.common.validation.InEnum; +import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; +import com.fasterxml.jackson.annotation.JsonIgnore; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; +import javax.validation.constraints.AssertTrue; import javax.validation.constraints.NotNull; +import java.util.Objects; /** * 社交客户端 Base VO,提供给添加、修改、详细的子 VO 使用 @@ -18,10 +26,12 @@ public class SocialClientBaseVO { @Schema(description = "社交平台的类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "31") @NotNull(message = "社交平台的类型不能为空") + @InEnum(SocialTypeEnum.class) private Integer socialType; @Schema(description = "用户类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") @NotNull(message = "用户类型不能为空") + @InEnum(UserTypeEnum.class) private Integer userType; @Schema(description = "客户端编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "wwd411c69a39ad2e54") @@ -37,6 +47,19 @@ public class SocialClientBaseVO { @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") @NotNull(message = "状态不能为空") + @InEnum(CommonStatusEnum.class) private Integer status; + @SuppressWarnings("RedundantIfStatement") + @AssertTrue(message = "agentId 不能为空") + @JsonIgnore + public boolean isAgentIdValid() { + // 如果是企业微信,必须填写 agentId 属性 + if (Objects.equals(socialType, SocialTypeEnum.WECHAT_ENTERPRISE.getType()) + && StrUtil.isEmpty(agentId)) { + return false; + } + return true; + } + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/client/SocialClientPageReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/client/SocialClientPageReqVO.java index b6c510da7d..a22553082f 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/client/SocialClientPageReqVO.java +++ b/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; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; -import org.springframework.format.annotation.DateTimeFormat; - -import java.time.LocalDateTime; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; @Schema(description = "管理后台 - 社交客户端分页 Request VO") @Data @@ -29,14 +24,7 @@ public class SocialClientPageReqVO extends PageParam { @Schema(description = "客户端编号", example = "145442115") private String clientId; - @Schema(description = "客户端密钥", example = "215151515154446") - private String clientSecret; - @Schema(description = "状态", example = "1") private Integer status; - @Schema(description = "创建时间") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private LocalDateTime[] createTime; - } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/user/SocialUserBaseVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/user/SocialUserBaseVO.java index 8dc7e01f6e..e763d05706 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/user/SocialUserBaseVO.java +++ b/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 { @NotNull(message = "社交 openid不能为空") private String openid; - @Schema(description = "社交 token", example = "666") + @Schema(description = "社交 token", requiredMode = Schema.RequiredMode.REQUIRED, example = "666") private String token; - @Schema(description = "原始 Token 数据,一般是 JSON 格式", example = "{}") + @Schema(description = "原始 Token 数据,一般是 JSON 格式", requiredMode = Schema.RequiredMode.REQUIRED, example = "{}") private String rawTokenInfo; @Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") @@ -33,13 +33,13 @@ public class SocialUserBaseVO { @Schema(description = "用户头像", example = "https://www.iocoder.cn/xxx.png") private String avatar; - @Schema(description = "原始用户数据,一般是 JSON 格式", example = "{}") + @Schema(description = "原始用户数据,一般是 JSON 格式", requiredMode = Schema.RequiredMode.REQUIRED, example = "{}") private String rawUserInfo; - @Schema(description = "最后一次的认证 code", example = "666666") + @Schema(description = "最后一次的认证 code", requiredMode = Schema.RequiredMode.REQUIRED, example = "666666") private String code; - @Schema(description = "最后一次的认证 state", example = "123456") + @Schema(description = "最后一次的认证 state", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456") private String state; } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/user/SocialUserPageReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/user/SocialUserPageReqVO.java index 552234090c..9103157518 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/user/SocialUserPageReqVO.java +++ b/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 { @Schema(description = "用户昵称", example = "李四") private String nickname; + @Schema(description = "社交 openid", example = "oz-Jdt0kd_jdhUxJHQdBJMlOFN7w\n") + private String openid; + @Schema(description = "创建时间") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) private LocalDateTime[] createTime; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/user/SocialUserRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/user/SocialUserRespVO.java index 4b448c7146..fdffa08726 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/user/SocialUserRespVO.java +++ b/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 { @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) private LocalDateTime createTime; + @Schema(description = "更新时间", requiredMode = Schema.RequiredMode.REQUIRED) + private LocalDateTime updateTime; + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/user/SocialUserUpdateReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/user/SocialUserUpdateReqVO.java deleted file mode 100644 index 2e81fc12e0..0000000000 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/user/SocialUserUpdateReqVO.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.yudao.module.system.controller.admin.socail.vo.user; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -import javax.validation.constraints.NotNull; - -@Schema(description = "管理后台 - 社交用户更新 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class SocialUserUpdateReqVO extends SocialUserBaseVO { - - @Schema(description = "主键(自增策略)", requiredMode = Schema.RequiredMode.REQUIRED, example = "14569") - @NotNull(message = "主键(自增策略)不能为空") - private Long id; - -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/social/SocialUserConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/social/SocialUserConvert.java index 6ed4a3e282..c2e8a272ea 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/social/SocialUserConvert.java +++ b/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; import cn.iocoder.yudao.module.system.controller.admin.socail.vo.SocialUserBindReqVO; import cn.iocoder.yudao.module.system.controller.admin.socail.vo.SocialUserUnbindReqVO; import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserRespVO; -import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserUpdateReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO; import org.mapstruct.Mapper; import org.mapstruct.Mapping; @@ -24,8 +23,6 @@ public interface SocialUserConvert { SocialUserUnbindReqDTO convert(Long userId, Integer userType, SocialUserUnbindReqVO reqVO); - SocialUserDO convert(SocialUserUpdateReqVO bean); - SocialUserRespVO convert(SocialUserDO bean); List convertList(List list); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/social/SocialClientDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/social/SocialClientDO.java index 95287a824c..71fc1bc4ae 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/social/SocialClientDO.java +++ b/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 { * 客户端 Secret */ private String clientSecret; + /** - * 授权方的网页应用 ID + * 代理编号 + * + * 目前只有部分“社交类型”在使用: + * 1. 企业微信:对应授权方的网页应用 ID */ private String agentId; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/social/SocialClientMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/social/SocialClientMapper.java index 80ae693ec3..717a261424 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/social/SocialClientMapper.java +++ b/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 { .eqIfPresent(SocialClientDO::getSocialType, reqVO.getSocialType()) .eqIfPresent(SocialClientDO::getUserType, reqVO.getUserType()) .eqIfPresent(SocialClientDO::getClientId, reqVO.getClientId()) - .eqIfPresent(SocialClientDO::getClientSecret, reqVO.getClientSecret()) .eqIfPresent(SocialClientDO::getStatus, reqVO.getStatus()) - .betweenIfPresent(SocialClientDO::getCreateTime, reqVO.getCreateTime()) .orderByDesc(SocialClientDO::getId)); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/social/SocialUserMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/social/SocialUserMapper.java index 25352ea45c..af30ecee29 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/social/SocialUserMapper.java +++ b/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 { return selectPage(reqVO, new LambdaQueryWrapperX() .eqIfPresent(SocialUserDO::getType, reqVO.getType()) .likeIfPresent(SocialUserDO::getNickname, reqVO.getNickname()) + .likeIfPresent(SocialUserDO::getOpenid, reqVO.getOpenid()) .betweenIfPresent(SocialUserDO::getCreateTime, reqVO.getCreateTime()) .orderByDesc(SocialUserDO::getId)); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientService.java index b8fbf2d1cc..35e9d5962c 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientService.java +++ b/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; import me.chanjar.weixin.common.bean.WxJsapiSignature; import javax.validation.Valid; -import java.util.Collection; -import java.util.List; /** * 社交应用 Service 接口 @@ -96,14 +94,6 @@ public interface SocialClientService { */ SocialClientDO getSocialClient(Long id); - /** - * 获得社交客户端列表 - * - * @param ids 编号 - * @return 社交客户端列表 - */ - List getSocialClientList(Collection ids); - /** * 获得社交客户端分页 * diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImpl.java index ceedb024cb..6c8381663f 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImpl.java +++ b/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; import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; import cn.binarywang.wx.miniapp.config.impl.WxMaRedisBetterConfigImpl; import cn.hutool.core.bean.BeanUtil; -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.collection.ListUtil; import cn.hutool.core.lang.Assert; +import cn.hutool.core.util.ObjUtil; import cn.hutool.core.util.ReflectUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; @@ -23,6 +22,7 @@ import cn.iocoder.yudao.module.system.dal.mysql.social.SocialClientMapper; import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; import com.binarywang.spring.starter.wxjava.miniapp.properties.WxMaProperties; import com.binarywang.spring.starter.wxjava.mp.properties.WxMpProperties; +import com.google.common.annotations.VisibleForTesting; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import com.xingyuv.jushauth.config.AuthConfig; @@ -44,8 +44,6 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.time.Duration; -import java.util.Collection; -import java.util.List; import java.util.Objects; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; @@ -224,7 +222,7 @@ public class SocialClientServiceImpl implements SocialClientService { return service.getUserService().getPhoneNoInfo(phoneCode); } catch (WxErrorException e) { log.error("[getPhoneNoInfo][userType({}) phoneCode({}) 获得手机号失败]", userType, phoneCode, e); - throw exception(SOCIAL_APP_WEIXIN_MINI_APP_PHONE_CODE_ERROR); + throw exception(SOCIAL_CLIENT_WEIXIN_MINI_APP_PHONE_CODE_ERROR); } } @@ -270,6 +268,9 @@ public class SocialClientServiceImpl implements SocialClientService { @Override public Long createSocialClient(SocialClientCreateReqVO createReqVO) { + // 校验重复 + validateSocialClientUnique(null, createReqVO.getUserType(), createReqVO.getSocialType()); + // 插入 SocialClientDO socialClient = SocialClientConvert.INSTANCE.convert(createReqVO); socialClientMapper.insert(socialClient); @@ -281,6 +282,9 @@ public class SocialClientServiceImpl implements SocialClientService { public void updateSocialClient(SocialClientUpdateReqVO updateReqVO) { // 校验存在 validateSocialClientExists(updateReqVO.getId()); + // 校验重复 + validateSocialClientUnique(updateReqVO.getId(), updateReqVO.getUserType(), updateReqVO.getSocialType()); + // 更新 SocialClientDO updateObj = SocialClientConvert.INSTANCE.convert(updateReqVO); socialClientMapper.updateById(updateObj); @@ -300,17 +304,31 @@ public class SocialClientServiceImpl implements SocialClientService { } } - @Override - public SocialClientDO getSocialClient(Long id) { - return socialClientMapper.selectById(id); + /** + * 校验社交应用是否重复,需要保证 userType + socialType 唯一 + * + * 原因是,不同端(userType)选择某个社交登录(socialType)时,需要通过 {@link #buildAuthRequest(Integer, Integer)} 构建对应的请求 + * + * @param id 编号 + * @param userType 用户类型 + * @param socialType 社交类型 + */ + @VisibleForTesting + private void validateSocialClientUnique(Long id, Integer userType, Integer socialType) { + SocialClientDO client = socialClientMapper.selectBySocialTypeAndUserType( + socialType, userType); + if (client == null) { + return; + } + if (id == null // 新增时,说明重复 + || ObjUtil.notEqual(id, client.getId())) { // 更新时,如果 id 不一致,说明重复 + throw exception(SOCIAL_CLIENT_UNIQUE); + } } @Override - public List getSocialClientList(Collection ids) { - if (CollUtil.isEmpty(ids)) { - return ListUtil.empty(); - } - return socialClientMapper.selectBatchIds(ids); + public SocialClientDO getSocialClient(Long id) { + return socialClientMapper.selectById(id); } @Override diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserService.java index 6c8a5b15fe..e8fce59027 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserService.java +++ b/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; import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO; 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.controller.admin.socail.vo.user.SocialUserUpdateReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO; import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; import javax.validation.Valid; -import java.util.Collection; import java.util.List; /** @@ -62,20 +60,6 @@ public interface SocialUserService { // ==================== 社交用户 CRUD ==================== - /** - * 更新社交用户 - * - * @param updateReqVO 更新信息 - */ - void updateSocialUser(@Valid SocialUserUpdateReqVO updateReqVO); - - /** - * 删除社交用户 - * - * @param id 编号 - */ - void deleteSocialUser(Long id); - /** * 获得社交用户 * @@ -84,14 +68,6 @@ public interface SocialUserService { */ SocialUserDO getSocialUser(Long id); - /** - * 获得社交用户列表 - * - * @param ids 编号 - * @return 社交用户列表 - */ - List getSocialUserList(Collection ids); - /** * 获得社交用户分页 * diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImpl.java index ee0f5f252e..e9e2fb62c3 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImpl.java +++ b/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; import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO; 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.controller.admin.socail.vo.user.SocialUserUpdateReqVO; import cn.iocoder.yudao.module.system.convert.social.SocialUserConvert; import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserBindDO; import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO; @@ -153,42 +152,11 @@ public class SocialUserServiceImpl implements SocialUserService { // ==================== 社交用户 CRUD ==================== - @Override - public void updateSocialUser(SocialUserUpdateReqVO updateReqVO) { - // 校验存在 - validateSocialUserExists(updateReqVO.getId()); - // 更新 - SocialUserDO updateObj = SocialUserConvert.INSTANCE.convert(updateReqVO); - socialUserMapper.updateById(updateObj); - } - - @Override - public void deleteSocialUser(Long id) { - // 校验存在 - validateSocialUserExists(id); - // 删除 - socialUserMapper.deleteById(id); - } - - private void validateSocialUserExists(Long id) { - if (socialUserMapper.selectById(id) == null) { - throw exception(SOCIAL_USER_NOT_EXISTS); - } - } - @Override public SocialUserDO getSocialUser(Long id) { return socialUserMapper.selectById(id); } - @Override - public List getSocialUserList(Collection ids) { - if (CollUtil.isEmpty(ids)) { - return ListUtil.empty(); - } - return socialUserMapper.selectBatchIds(ids); - } - @Override public PageResult getSocialUserPage(SocialUserPageReqVO pageReqVO) { return socialUserMapper.selectPage(pageReqVO); diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImplTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImplTest.java index 6c008c3a48..01ff6c2028 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImplTest.java +++ b/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; import javax.annotation.Resource; -import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; 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; import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.SOCIAL_CLIENT_NOT_EXISTS; import static org.junit.jupiter.api.Assertions.*; +// TODO 芋艿:单测后续补充下; /** * {@link SocialClientServiceImpl} 的单元测试类 * @@ -133,9 +133,7 @@ public class SocialClientServiceImplTest extends BaseDbUnitTest { reqVO.setSocialType(null); reqVO.setUserType(null); reqVO.setClientId(null); - reqVO.setClientSecret(null); reqVO.setStatus(null); - reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); // 调用 PageResult pageResult = socialClientService.getSocialClientPage(reqVO);