Merge branch 'feature/mall_product_tmp' of https://gitee.com/zhijiantianya/ruoyi-vue-pro into feature/mall_product

# Conflicts:
#	yudao-module-member/yudao-module-member-biz/src/test/java/cn/iocoder/yudao/module/member/service/auth/MemberAuthServiceTest.java
#	yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImpl.java
#	yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImplTest.java
This commit is contained in:
YunaiV 2023-11-04 12:03:54 +08:00
commit e9317bf293
24 changed files with 837 additions and 22 deletions

View File

@ -118,8 +118,9 @@ public interface ErrorCodeConstants {
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, "社交用户不存在");
// ========== 系统敏感词 1-002-019-000 =========
ErrorCode SENSITIVE_WORD_NOT_EXISTS = new ErrorCode(1_002_019_000, "系统敏感词在所有标签中都不存在");

View File

@ -0,0 +1,74 @@
package cn.iocoder.yudao.module.system.controller.admin.socail;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientRespVO;
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientUpdateReqVO;
import cn.iocoder.yudao.module.system.convert.social.SocialClientConvert;
import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO;
import cn.iocoder.yudao.module.system.service.social.SocialClientService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "管理后台 - 社交客户端")
@RestController
@RequestMapping("/system/social-client")
@Validated
public class SocialClientController {
@Resource
private SocialClientService socialClientService;
@PostMapping("/create")
@Operation(summary = "创建社交客户端")
@PreAuthorize("@ss.hasPermission('system:social-client:create')")
public CommonResult<Long> createSocialClient(@Valid @RequestBody SocialClientCreateReqVO createReqVO) {
return success(socialClientService.createSocialClient(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新社交客户端")
@PreAuthorize("@ss.hasPermission('system:social-client:update')")
public CommonResult<Boolean> updateSocialClient(@Valid @RequestBody SocialClientUpdateReqVO updateReqVO) {
socialClientService.updateSocialClient(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除社交客户端")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('system:social-client:delete')")
public CommonResult<Boolean> deleteSocialClient(@RequestParam("id") Long id) {
socialClientService.deleteSocialClient(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得社交客户端")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('system:social-client:query')")
public CommonResult<SocialClientRespVO> getSocialClient(@RequestParam("id") Long id) {
SocialClientDO socialClient = socialClientService.getSocialClient(id);
return success(SocialClientConvert.INSTANCE.convert(socialClient));
}
@GetMapping("/page")
@Operation(summary = "获得社交客户端分页")
@PreAuthorize("@ss.hasPermission('system:social-client:query')")
public CommonResult<PageResult<SocialClientRespVO>> getSocialClientPage(@Valid SocialClientPageReqVO pageVO) {
PageResult<SocialClientDO> pageResult = socialClientService.getSocialClientPage(pageVO);
return success(SocialClientConvert.INSTANCE.convertPage(pageResult));
}
}

View File

@ -2,18 +2,26 @@ package cn.iocoder.yudao.module.system.controller.admin.socail;
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
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.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;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
@Tag(name = "管理后台 - 社交用户")
@ -39,4 +47,40 @@ public class SocialUserController {
return CommonResult.success(true);
}
// ==================== 社交用户 CRUD ====================
@PutMapping("/update")
@Operation(summary = "更新社交用户")
@PreAuthorize("@ss.hasPermission('system:social-user:update')")
public CommonResult<Boolean> 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<Boolean> deleteSocialUser(@RequestParam("id") Long id) {
socialUserService.deleteSocialUser(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得社交用户")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('system:social-user:query')")
public CommonResult<SocialUserRespVO> getSocialUser(@RequestParam("id") Long id) {
SocialUserDO socialUser = socialUserService.getSocialUser(id);
return success(SocialUserConvert.INSTANCE.convert(socialUser));
}
@GetMapping("/page")
@Operation(summary = "获得社交用户分页")
@PreAuthorize("@ss.hasPermission('system:social-user:query')")
public CommonResult<PageResult<SocialUserRespVO>> getSocialUserPage(@Valid SocialUserPageReqVO pageVO) {
PageResult<SocialUserDO> pageResult = socialUserService.getSocialUserPage(pageVO);
return success(SocialUserConvert.INSTANCE.convertPage(pageResult));
}
}

View File

@ -0,0 +1,42 @@
package cn.iocoder.yudao.module.system.controller.admin.socail.vo.client;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotNull;
/**
* 社交客户端 Base VO提供给添加修改详细的子 VO 使用
* 如果子 VO 存在差异的字段请不要添加到这里影响 Swagger 文档生成
*/
@Data
public class SocialClientBaseVO {
@Schema(description = "应用名", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudao商城")
@NotNull(message = "应用名不能为空")
private String name;
@Schema(description = "社交平台的类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "31")
@NotNull(message = "社交平台的类型不能为空")
private Integer socialType;
@Schema(description = "用户类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@NotNull(message = "用户类型不能为空")
private Integer userType;
@Schema(description = "客户端编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "wwd411c69a39ad2e54")
@NotNull(message = "客户端编号不能为空")
private String clientId;
@Schema(description = "客户端密钥", requiredMode = Schema.RequiredMode.REQUIRED, example = "1wTb7hYxnpT2TUbIeHGXGo7T0odav1ic10mLdyyATOw")
@NotNull(message = "客户端密钥不能为空")
private String clientSecret;
@Schema(description = "授权方的网页应用编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2000045")
private String agentId;
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "状态不能为空")
private Integer status;
}

View File

@ -0,0 +1,14 @@
package cn.iocoder.yudao.module.system.controller.admin.socail.vo.client;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@Schema(description = "管理后台 - 社交客户端创建 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class SocialClientCreateReqVO extends SocialClientBaseVO {
}

View File

@ -0,0 +1,42 @@
package cn.iocoder.yudao.module.system.controller.admin.socail.vo.client;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
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
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class SocialClientPageReqVO extends PageParam {
@Schema(description = "应用名", example = "yudao商城")
private String name;
@Schema(description = "社交平台的类型", example = "31")
private Integer socialType;
@Schema(description = "用户类型", example = "2")
private Integer userType;
@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;
}

View File

@ -0,0 +1,22 @@
package cn.iocoder.yudao.module.system.controller.admin.socail.vo.client;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 社交客户端 Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class SocialClientRespVO extends SocialClientBaseVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "27162")
private Long id;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;
}

View File

@ -0,0 +1,20 @@
package cn.iocoder.yudao.module.system.controller.admin.socail.vo.client;
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 SocialClientUpdateReqVO extends SocialClientBaseVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "27162")
@NotNull(message = "编号不能为空")
private Long id;
}

View File

@ -0,0 +1,45 @@
package cn.iocoder.yudao.module.system.controller.admin.socail.vo.user;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotNull;
/**
* 社交用户 Base VO提供给添加修改详细的子 VO 使用
* 如果子 VO 存在差异的字段请不要添加到这里影响 Swagger 文档生成
*/
@Data
public class SocialUserBaseVO {
@Schema(description = "社交平台的类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "30")
@NotNull(message = "社交平台的类型不能为空")
private Integer type;
@Schema(description = "社交 openid", requiredMode = Schema.RequiredMode.REQUIRED, example = "666")
@NotNull(message = "社交 openid不能为空")
private String openid;
@Schema(description = "社交 token", example = "666")
private String token;
@Schema(description = "原始 Token 数据,一般是 JSON 格式", example = "{}")
private String rawTokenInfo;
@Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
@NotNull(message = "用户昵称不能为空")
private String nickname;
@Schema(description = "用户头像", example = "https://www.iocoder.cn/xxx.png")
private String avatar;
@Schema(description = "原始用户数据,一般是 JSON 格式", example = "{}")
private String rawUserInfo;
@Schema(description = "最后一次的认证 code", example = "666666")
private String code;
@Schema(description = "最后一次的认证 state", example = "123456")
private String state;
}

View File

@ -0,0 +1,30 @@
package cn.iocoder.yudao.module.system.controller.admin.socail.vo.user;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
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
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class SocialUserPageReqVO extends PageParam {
@Schema(description = "社交平台的类型", example = "30")
private Integer type;
@Schema(description = "用户昵称", example = "李四")
private String nickname;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

View File

@ -0,0 +1,22 @@
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 java.time.LocalDateTime;
@Schema(description = "管理后台 - 社交用户 Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class SocialUserRespVO extends SocialUserBaseVO {
@Schema(description = "主键(自增策略)", requiredMode = Schema.RequiredMode.REQUIRED, example = "14569")
private Long id;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;
}

View File

@ -0,0 +1,20 @@
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;
}

View File

@ -1,12 +1,19 @@
package cn.iocoder.yudao.module.system.convert.social;
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.system.api.social.dto.SocialWxJsapiSignatureRespDTO;
import cn.iocoder.yudao.module.system.api.social.dto.SocialWxPhoneNumberInfoRespDTO;
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientRespVO;
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientUpdateReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO;
import me.chanjar.weixin.common.bean.WxJsapiSignature;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface SocialClientConvert {
@ -16,4 +23,16 @@ public interface SocialClientConvert {
SocialWxPhoneNumberInfoRespDTO convert(WxMaPhoneNumberInfo bean);
SocialClientDO convert(SocialClientCreateReqVO bean);
SocialClientDO convert(SocialClientUpdateReqVO bean);
SocialClientRespVO convert(SocialClientDO bean);
List<SocialClientRespVO> convertList(List<SocialClientDO> list);
PageResult<SocialClientRespVO> convertPage(PageResult<SocialClientDO> page);
}

View File

@ -1,19 +1,35 @@
package cn.iocoder.yudao.module.system.convert.social;
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.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;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface SocialUserConvert {
SocialUserConvert INSTANCE = Mappers.getMapper(SocialUserConvert.class);
@Mapping(target = "socialType", source = "reqVO.type")
SocialUserBindReqDTO convert(Long userId, Integer userType, SocialUserBindReqVO reqVO);
SocialUserUnbindReqDTO convert(Long userId, Integer userType, SocialUserUnbindReqVO reqVO);
SocialUserDO convert(SocialUserUpdateReqVO bean);
SocialUserRespVO convert(SocialUserDO bean);
List<SocialUserRespVO> convertList(List<SocialUserDO> list);
PageResult<SocialUserRespVO> convertPage(PageResult<SocialUserDO> page);
}

View File

@ -64,5 +64,9 @@ public class SocialClientDO extends TenantBaseDO {
* 客户端 Secret
*/
private String clientSecret;
/**
* 授权方的网页应用 ID
*/
private String agentId;
}

View File

@ -1,6 +1,9 @@
package cn.iocoder.yudao.module.system.dal.mysql.social;
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.controller.admin.socail.vo.client.SocialClientPageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO;
import org.apache.ibatis.annotations.Mapper;
@ -12,4 +15,16 @@ public interface SocialClientMapper extends BaseMapperX<SocialClientDO> {
SocialClientDO::getUserType, userType);
}
default PageResult<SocialClientDO> selectPage(SocialClientPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<SocialClientDO>()
.likeIfPresent(SocialClientDO::getName, reqVO.getName())
.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));
}
}

View File

@ -1,14 +1,13 @@
package cn.iocoder.yudao.module.system.dal.mysql.social;
import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO;
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.controller.admin.socail.vo.user.SocialUserPageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.Collection;
import java.util.List;
@Mapper
public interface SocialUserMapper extends BaseMapperX<SocialUserDO> {
@ -25,4 +24,12 @@ public interface SocialUserMapper extends BaseMapperX<SocialUserDO> {
.eq(SocialUserDO::getOpenid, openid));
}
default PageResult<SocialUserDO> selectPage(SocialUserPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<SocialUserDO>()
.eqIfPresent(SocialUserDO::getType, reqVO.getType())
.likeIfPresent(SocialUserDO::getNickname, reqVO.getNickname())
.betweenIfPresent(SocialUserDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(SocialUserDO::getId));
}
}

View File

@ -1,10 +1,19 @@
package cn.iocoder.yudao.module.system.service.social;
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientUpdateReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO;
import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
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 接口
*
@ -55,4 +64,52 @@ public interface SocialClientService {
*/
WxMaPhoneNumberInfo getWxMaPhoneNumberInfo(Integer userType, String phoneCode);
// =================== 客户端管理 ===================
/**
* 创建社交客户端
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createSocialClient(@Valid SocialClientCreateReqVO createReqVO);
/**
* 更新社交客户端
*
* @param updateReqVO 更新信息
*/
void updateSocialClient(@Valid SocialClientUpdateReqVO updateReqVO);
/**
* 删除社交客户端
*
* @param id 编号
*/
void deleteSocialClient(Long id);
/**
* 获得社交客户端
*
* @param id 编号
* @return 社交客户端
*/
SocialClientDO getSocialClient(Long id);
/**
* 获得社交客户端列表
*
* @param ids 编号
* @return 社交客户端列表
*/
List<SocialClientDO> getSocialClientList(Collection<Long> ids);
/**
* 获得社交客户端分页
*
* @param pageReqVO 分页查询
* @return 社交客户端分页
*/
PageResult<SocialClientDO> getSocialClientPage(SocialClientPageReqVO pageReqVO);
}

View File

@ -5,12 +5,19 @@ 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.ReflectUtil;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.cache.CacheUtils;
import cn.iocoder.yudao.framework.common.util.http.HttpUtils;
import cn.iocoder.yudao.framework.social.core.YudaoAuthRequestFactory;
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientUpdateReqVO;
import cn.iocoder.yudao.module.system.convert.social.SocialClientConvert;
import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO;
import cn.iocoder.yudao.module.system.dal.mysql.social.SocialClientMapper;
import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
@ -37,12 +44,13 @@ 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;
import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.SOCIAL_APP_WEIXIN_MINI_APP_PHONE_CODE_ERROR;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.SOCIAL_USER_AUTH_FAILURE;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
/**
* 社交应用 Service 实现类
@ -151,6 +159,9 @@ public class SocialClientServiceImpl implements SocialClientService {
// 2.2 修改对应的 clientId + clientSecret 密钥
newAuthConfig.setClientId(client.getClientId());
newAuthConfig.setClientSecret(client.getClientSecret());
if (client.getAgentId() != null) { // 如果有 agentId 则修改 agentId
newAuthConfig.setAgentId(client.getAgentId());
}
// 2.3 设置会 request 进行后续使用
ReflectUtil.setFieldValue(request, "config", newAuthConfig);
}
@ -255,4 +266,56 @@ public class SocialClientServiceImpl implements SocialClientService {
return service;
}
// =================== 客户端管理 ===================
@Override
public Long createSocialClient(SocialClientCreateReqVO createReqVO) {
// 插入
SocialClientDO socialClient = SocialClientConvert.INSTANCE.convert(createReqVO);
socialClientMapper.insert(socialClient);
// 返回
return socialClient.getId();
}
@Override
public void updateSocialClient(SocialClientUpdateReqVO updateReqVO) {
// 校验存在
validateSocialClientExists(updateReqVO.getId());
// 更新
SocialClientDO updateObj = SocialClientConvert.INSTANCE.convert(updateReqVO);
socialClientMapper.updateById(updateObj);
}
@Override
public void deleteSocialClient(Long id) {
// 校验存在
validateSocialClientExists(id);
// 删除
socialClientMapper.deleteById(id);
}
private void validateSocialClientExists(Long id) {
if (socialClientMapper.selectById(id) == null) {
throw exception(SOCIAL_CLIENT_NOT_EXISTS);
}
}
@Override
public SocialClientDO getSocialClient(Long id) {
return socialClientMapper.selectById(id);
}
@Override
public List<SocialClientDO> getSocialClientList(Collection<Long> ids) {
if (CollUtil.isEmpty(ids)) {
return ListUtil.empty();
}
return socialClientMapper.selectBatchIds(ids);
}
@Override
public PageResult<SocialClientDO> getSocialClientPage(SocialClientPageReqVO pageReqVO) {
return socialClientMapper.selectPage(pageReqVO);
}
}

View File

@ -1,12 +1,16 @@
package cn.iocoder.yudao.module.system.service.social;
import cn.iocoder.yudao.framework.common.exception.ServiceException;
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;
/**
@ -56,4 +60,44 @@ public interface SocialUserService {
*/
SocialUserRespDTO getSocialUser(Integer userType, Integer type, String code, String state);
// ==================== 社交用户 CRUD ====================
/**
* 更新社交用户
*
* @param updateReqVO 更新信息
*/
void updateSocialUser(@Valid SocialUserUpdateReqVO updateReqVO);
/**
* 删除社交用户
*
* @param id 编号
*/
void deleteSocialUser(Long id);
/**
* 获得社交用户
*
* @param id 编号
* @return 社交用户
*/
SocialUserDO getSocialUser(Long id);
/**
* 获得社交用户列表
*
* @param ids 编号
* @return 社交用户列表
*/
List<SocialUserDO> getSocialUserList(Collection<Long> ids);
/**
* 获得社交用户分页
*
* @param pageReqVO 分页查询
* @return 社交用户分页
*/
PageResult<SocialUserDO> getSocialUserPage(SocialUserPageReqVO pageReqVO);
}

View File

@ -1,10 +1,15 @@
package cn.iocoder.yudao.module.system.service.social;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.lang.Assert;
import cn.iocoder.yudao.framework.common.exception.ServiceException;
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;
import cn.iocoder.yudao.module.system.dal.mysql.social.SocialUserBindMapper;
@ -18,14 +23,14 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.Collection;
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;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
/**
* 社交用户 Service 实现类
@ -146,4 +151,47 @@ public class SocialUserServiceImpl implements SocialUserService {
return socialUser;
}
// ==================== 社交用户 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<SocialUserDO> getSocialUserList(Collection<Long> ids) {
if (CollUtil.isEmpty(ids)) {
return ListUtil.empty();
}
return socialUserMapper.selectBatchIds(ids);
}
@Override
public PageResult<SocialUserDO> getSocialUserPage(SocialUserPageReqVO pageReqVO) {
return socialUserMapper.selectPage(pageReqVO);
}
}

View File

@ -0,0 +1,148 @@
package cn.iocoder.yudao.module.system.service.social;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.client.SocialClientUpdateReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialClientDO;
import cn.iocoder.yudao.module.system.dal.mysql.social.SocialClientMapper;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
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;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId;
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.*;
/**
* {@link SocialClientServiceImpl} 的单元测试类
*
* @author 芋道源码
*/
@Import(SocialClientServiceImpl.class)
public class SocialClientServiceImplTest extends BaseDbUnitTest {
@Resource
private SocialClientServiceImpl socialClientService;
@Resource
private SocialClientMapper socialClientMapper;
@Test
public void testCreateSocialClient_success() {
// 准备参数
SocialClientCreateReqVO reqVO = randomPojo(SocialClientCreateReqVO.class);
// 调用
Long socialClientId = socialClientService.createSocialClient(reqVO);
// 断言
assertNotNull(socialClientId);
// 校验记录的属性是否正确
SocialClientDO socialClient = socialClientMapper.selectById(socialClientId);
assertPojoEquals(reqVO, socialClient);
}
@Test
public void testUpdateSocialClient_success() {
// mock 数据
SocialClientDO dbSocialClient = randomPojo(SocialClientDO.class);
socialClientMapper.insert(dbSocialClient);// @Sql: 先插入出一条存在的数据
// 准备参数
SocialClientUpdateReqVO reqVO = randomPojo(SocialClientUpdateReqVO.class, o -> {
o.setId(dbSocialClient.getId()); // 设置更新的 ID
});
// 调用
socialClientService.updateSocialClient(reqVO);
// 校验是否更新正确
SocialClientDO socialClient = socialClientMapper.selectById(reqVO.getId()); // 获取最新的
assertPojoEquals(reqVO, socialClient);
}
@Test
public void testUpdateSocialClient_notExists() {
// 准备参数
SocialClientUpdateReqVO reqVO = randomPojo(SocialClientUpdateReqVO.class);
// 调用, 并断言异常
assertServiceException(() -> socialClientService.updateSocialClient(reqVO), SOCIAL_CLIENT_NOT_EXISTS);
}
@Test
public void testDeleteSocialClient_success() {
// mock 数据
SocialClientDO dbSocialClient = randomPojo(SocialClientDO.class);
socialClientMapper.insert(dbSocialClient);// @Sql: 先插入出一条存在的数据
// 准备参数
Long id = dbSocialClient.getId();
// 调用
socialClientService.deleteSocialClient(id);
// 校验数据不存在了
assertNull(socialClientMapper.selectById(id));
}
@Test
public void testDeleteSocialClient_notExists() {
// 准备参数
Long id = randomLongId();
// 调用, 并断言异常
assertServiceException(() -> socialClientService.deleteSocialClient(id), SOCIAL_CLIENT_NOT_EXISTS);
}
@Test
@Disabled // TODO 请修改 null 为需要的值然后删除 @Disabled 注解
public void testGetSocialClientPage() {
// mock 数据
SocialClientDO dbSocialClient = randomPojo(SocialClientDO.class, o -> { // 等会查询到
o.setName(null);
o.setSocialType(null);
o.setUserType(null);
o.setClientId(null);
o.setClientSecret(null);
o.setStatus(null);
o.setCreateTime(null);
});
socialClientMapper.insert(dbSocialClient);
// 测试 name 不匹配
socialClientMapper.insert(cloneIgnoreId(dbSocialClient, o -> o.setName(null)));
// 测试 socialType 不匹配
socialClientMapper.insert(cloneIgnoreId(dbSocialClient, o -> o.setSocialType(null)));
// 测试 userType 不匹配
socialClientMapper.insert(cloneIgnoreId(dbSocialClient, o -> o.setUserType(null)));
// 测试 clientId 不匹配
socialClientMapper.insert(cloneIgnoreId(dbSocialClient, o -> o.setClientId(null)));
// 测试 clientSecret 不匹配
socialClientMapper.insert(cloneIgnoreId(dbSocialClient, o -> o.setClientSecret(null)));
// 测试 status 不匹配
socialClientMapper.insert(cloneIgnoreId(dbSocialClient, o -> o.setStatus(null)));
// 测试 createTime 不匹配
socialClientMapper.insert(cloneIgnoreId(dbSocialClient, o -> o.setCreateTime(null)));
// 准备参数
SocialClientPageReqVO reqVO = new SocialClientPageReqVO();
reqVO.setName(null);
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<SocialClientDO> pageResult = socialClientService.getSocialClientPage(reqVO);
// 断言
assertEquals(1, pageResult.getTotal());
assertEquals(1, pageResult.getList().size());
assertPojoEquals(dbSocialClient, pageResult.getList().get(0));
}
}

View File

@ -17,6 +17,7 @@ DELETE FROM "system_sms_template";
DELETE FROM "system_sms_log";
DELETE FROM "system_sms_code";
DELETE FROM "system_error_code";
DELETE FROM "system_social_client";
DELETE FROM "system_social_user";
DELETE FROM "system_social_user_bind";
DELETE FROM "system_tenant";

View File

@ -354,8 +354,25 @@ CREATE TABLE IF NOT EXISTS "system_error_code" (
PRIMARY KEY ("id")
) COMMENT '错误码表';
CREATE TABLE IF NOT EXISTS "system_social_client" (
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"name" varchar(255) NOT NULL,
"social_type" int NOT NULL,
"user_type" int NOT NULL,
"client_id" varchar(255) NOT NULL,
"client_secret" varchar(255) NOT NULL,
"status" int NOT NULL,
"creator" varchar(64) DEFAULT '',
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updater" varchar(64) DEFAULT '',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit NOT NULL DEFAULT FALSE,
"tenant_id" bigint NOT NULL,
PRIMARY KEY ("id")
) COMMENT '社交客户端表';
CREATE TABLE IF NOT EXISTS "system_social_user" (
"id" number NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"type" tinyint NOT NULL,
"openid" varchar(64) NOT NULL,
"token" varchar(256) DEFAULT NULL,
@ -374,7 +391,7 @@ CREATE TABLE IF NOT EXISTS "system_social_user" (
) COMMENT '社交用户';
CREATE TABLE IF NOT EXISTS "system_social_user_bind" (
"id" number NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"user_id" bigint NOT NULL,
"user_type" tinyint NOT NULL,
"social_type" tinyint NOT NULL,