🔧 简化 social 模块的 VO

pull/79/head
YunaiV 2023-12-02 23:01:20 +08:00
parent 2014af1c0b
commit 066ba7ece8
17 changed files with 97 additions and 196 deletions

View File

@ -2,9 +2,9 @@ package cn.iocoder.yudao.module.system.api.social;
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
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.convert.social.SocialClientConvert;
import cn.iocoder.yudao.module.system.service.social.SocialClientService;
import me.chanjar.weixin.common.bean.WxJsapiSignature;
import org.springframework.validation.annotation.Validated;
@ -34,13 +34,13 @@ public class SocialClientApiImpl implements SocialClientApi {
@Override
public CommonResult<SocialWxJsapiSignatureRespDTO> createWxMpJsapiSignature(Integer userType, String url) {
WxJsapiSignature signature = socialClientService.createWxMpJsapiSignature(userType, url);
return success(SocialClientConvert.INSTANCE.convert(signature));
return success(BeanUtils.toBean(signature, SocialWxJsapiSignatureRespDTO.class));
}
@Override
public CommonResult<SocialWxPhoneNumberInfoRespDTO> getWxMaPhoneNumberInfo(Integer userType, String phoneCode) {
WxMaPhoneNumberInfo info = socialClientService.getWxMaPhoneNumberInfo(userType, phoneCode);
return success(SocialClientConvert.INSTANCE.convert(info));
return success(BeanUtils.toBean(info, SocialWxPhoneNumberInfoRespDTO.class));
}
}

View File

@ -2,11 +2,10 @@ 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.framework.common.util.object.BeanUtils;
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.controller.admin.socail.vo.client.SocialClientSaveReqVO;
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;
@ -33,14 +32,14 @@ public class SocialClientController {
@PostMapping("/create")
@Operation(summary = "创建社交客户端")
@PreAuthorize("@ss.hasPermission('system:social-client:create')")
public CommonResult<Long> createSocialClient(@Valid @RequestBody SocialClientCreateReqVO createReqVO) {
public CommonResult<Long> createSocialClient(@Valid @RequestBody SocialClientSaveReqVO 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) {
public CommonResult<Boolean> updateSocialClient(@Valid @RequestBody SocialClientSaveReqVO updateReqVO) {
socialClientService.updateSocialClient(updateReqVO);
return success(true);
}
@ -59,8 +58,8 @@ public class SocialClientController {
@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));
SocialClientDO client = socialClientService.getSocialClient(id);
return success(BeanUtils.toBean(client, SocialClientRespVO.class));
}
@GetMapping("/page")
@ -68,7 +67,7 @@ public class SocialClientController {
@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));
return success(BeanUtils.toBean(pageResult, SocialClientRespVO.class));
}
}

View File

@ -3,10 +3,11 @@ 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.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserBindReqVO;
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.SocialUserUnbindReqVO;
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;
@ -35,7 +36,8 @@ public class SocialUserController {
@PostMapping("/bind")
@Operation(summary = "社交绑定,使用 code 授权码")
public CommonResult<Boolean> socialBind(@RequestBody @Valid SocialUserBindReqVO reqVO) {
socialUserService.bindSocialUser(SocialUserConvert.INSTANCE.convert(getLoginUserId(), UserTypeEnum.ADMIN.getValue(), reqVO));
socialUserService.bindSocialUser(SocialUserConvert.INSTANCE.convert(
getLoginUserId(), UserTypeEnum.ADMIN.getValue(), reqVO));
return CommonResult.success(true);
}
@ -54,7 +56,7 @@ public class SocialUserController {
@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));
return success(BeanUtils.toBean(socialUser, SocialUserRespVO.class));
}
@GetMapping("/page")
@ -62,7 +64,7 @@ public class SocialUserController {
@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));
return success(BeanUtils.toBean(pageResult, SocialUserRespVO.class));
}
}

View File

@ -1,14 +0,0 @@
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

@ -2,20 +2,37 @@ 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 {
public class SocialClientRespVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "27162")
private Long id;
@Schema(description = "应用名", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudao商城")
private String name;
@Schema(description = "社交平台的类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "31")
private Integer socialType;
@Schema(description = "用户类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
private Integer userType;
@Schema(description = "客户端编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "wwd411c69a39ad2e54")
private String clientId;
@Schema(description = "客户端密钥", requiredMode = Schema.RequiredMode.REQUIRED, example = "peter")
private String clientSecret;
@Schema(description = "授权方的网页应用编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2000045")
private String agentId;
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer status;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;

View File

@ -13,12 +13,12 @@ import javax.validation.constraints.AssertTrue;
import javax.validation.constraints.NotNull;
import java.util.Objects;
/**
* Base VO VO 使
* VO Swagger
*/
@Schema(description = "管理后台 - 社交客户端创建/修改 Request VO")
@Data
public class SocialClientBaseVO {
public class SocialClientSaveReqVO {
@Schema(description = "编号", example = "27162")
private Long id;
@Schema(description = "应用名", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudao商城")
@NotNull(message = "应用名不能为空")
@ -38,7 +38,7 @@ public class SocialClientBaseVO {
@NotNull(message = "客户端编号不能为空")
private String clientId;
@Schema(description = "客户端密钥", requiredMode = Schema.RequiredMode.REQUIRED, example = "1wTb7hYxnpT2TUbIeHGXGo7T0odav1ic10mLdyyATOw")
@Schema(description = "客户端密钥", requiredMode = Schema.RequiredMode.REQUIRED, example = "peter")
@NotNull(message = "客户端密钥不能为空")
private String clientSecret;
@ -50,16 +50,12 @@ public class SocialClientBaseVO {
@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;
return !Objects.equals(socialType, SocialTypeEnum.WECHAT_ENTERPRISE.getType())
|| !StrUtil.isEmpty(agentId);
}
}

View File

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

@ -1,45 +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 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", requiredMode = Schema.RequiredMode.REQUIRED, example = "666")
private String token;
@Schema(description = "原始 Token 数据,一般是 JSON 格式", requiredMode = Schema.RequiredMode.REQUIRED, 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 格式", requiredMode = Schema.RequiredMode.REQUIRED, example = "{}")
private String rawUserInfo;
@Schema(description = "最后一次的认证 code", requiredMode = Schema.RequiredMode.REQUIRED, example = "666666")
private String code;
@Schema(description = "最后一次的认证 state", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456")
private String state;
}

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.system.controller.admin.socail.vo;
package cn.iocoder.yudao.module.system.controller.admin.socail.vo.user;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;

View File

@ -2,20 +2,43 @@ 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 {
public class SocialUserRespVO {
@Schema(description = "主键(自增策略)", requiredMode = Schema.RequiredMode.REQUIRED, example = "14569")
private Long id;
@Schema(description = "社交平台的类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "30")
private Integer type;
@Schema(description = "社交 openid", requiredMode = Schema.RequiredMode.REQUIRED, example = "666")
private String openid;
@Schema(description = "社交 token", requiredMode = Schema.RequiredMode.REQUIRED, example = "666")
private String token;
@Schema(description = "原始 Token 数据,一般是 JSON 格式", requiredMode = Schema.RequiredMode.REQUIRED, example = "{}")
private String rawTokenInfo;
@Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
private String nickname;
@Schema(description = "用户头像", example = "https://www.iocoder.cn/xxx.png")
private String avatar;
@Schema(description = "原始用户数据,一般是 JSON 格式", requiredMode = Schema.RequiredMode.REQUIRED, example = "{}")
private String rawUserInfo;
@Schema(description = "最后一次的认证 code", requiredMode = Schema.RequiredMode.REQUIRED, example = "666666")
private String code;
@Schema(description = "最后一次的认证 state", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456")
private String state;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.system.controller.admin.socail.vo;
package cn.iocoder.yudao.module.system.controller.admin.socail.vo.user;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;

View File

@ -1,38 +0,0 @@
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 {
SocialClientConvert INSTANCE = Mappers.getMapper(SocialClientConvert.class);
SocialWxJsapiSignatureRespDTO convert(WxJsapiSignature bean);
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,32 +1,17 @@
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.dal.dataobject.social.SocialUserDO;
import cn.iocoder.yudao.module.system.controller.admin.socail.vo.user.SocialUserBindReqVO;
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")
@Mapping(source = "reqVO.type", target = "socialType")
SocialUserBindReqDTO convert(Long userId, Integer userType, SocialUserBindReqVO reqVO);
SocialUserUnbindReqDTO convert(Long userId, Integer userType, SocialUserUnbindReqVO reqVO);
SocialUserRespVO convert(SocialUserDO bean);
List<SocialUserRespVO> convertList(List<SocialUserDO> list);
PageResult<SocialUserRespVO> convertPage(PageResult<SocialUserDO> page);
}

View File

@ -20,7 +20,7 @@ public interface SocialClientMapper extends BaseMapperX<SocialClientDO> {
.likeIfPresent(SocialClientDO::getName, reqVO.getName())
.eqIfPresent(SocialClientDO::getSocialType, reqVO.getSocialType())
.eqIfPresent(SocialClientDO::getUserType, reqVO.getUserType())
.eqIfPresent(SocialClientDO::getClientId, reqVO.getClientId())
.likeIfPresent(SocialClientDO::getClientId, reqVO.getClientId())
.eqIfPresent(SocialClientDO::getStatus, reqVO.getStatus())
.orderByDesc(SocialClientDO::getId));
}

View File

@ -2,9 +2,8 @@ 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.controller.admin.socail.vo.client.SocialClientSaveReqVO;
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;
@ -70,14 +69,14 @@ public interface SocialClientService {
* @param createReqVO
* @return
*/
Long createSocialClient(@Valid SocialClientCreateReqVO createReqVO);
Long createSocialClient(@Valid SocialClientSaveReqVO createReqVO);
/**
*
*
* @param updateReqVO
*/
void updateSocialClient(@Valid SocialClientUpdateReqVO updateReqVO);
void updateSocialClient(@Valid SocialClientSaveReqVO updateReqVO);
/**
*

View File

@ -12,10 +12,9 @@ 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.module.system.controller.admin.socail.vo.client.SocialClientCreateReqVO;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
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.controller.admin.socail.vo.client.SocialClientSaveReqVO;
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;
@ -267,26 +266,25 @@ public class SocialClientServiceImpl implements SocialClientService {
// =================== 客户端管理 ===================
@Override
public Long createSocialClient(SocialClientCreateReqVO createReqVO) {
public Long createSocialClient(SocialClientSaveReqVO createReqVO) {
// 校验重复
validateSocialClientUnique(null, createReqVO.getUserType(), createReqVO.getSocialType());
// 插入
SocialClientDO socialClient = SocialClientConvert.INSTANCE.convert(createReqVO);
socialClientMapper.insert(socialClient);
// 返回
return socialClient.getId();
SocialClientDO client = BeanUtils.toBean(createReqVO, SocialClientDO.class);
socialClientMapper.insert(client);
return client.getId();
}
@Override
public void updateSocialClient(SocialClientUpdateReqVO updateReqVO) {
public void updateSocialClient(SocialClientSaveReqVO updateReqVO) {
// 校验存在
validateSocialClientExists(updateReqVO.getId());
// 校验重复
validateSocialClientUnique(updateReqVO.getId(), updateReqVO.getUserType(), updateReqVO.getSocialType());
// 更新
SocialClientDO updateObj = SocialClientConvert.INSTANCE.convert(updateReqVO);
SocialClientDO updateObj = BeanUtils.toBean(updateReqVO, SocialClientDO.class);
socialClientMapper.updateById(updateObj);
}

View File

@ -2,9 +2,8 @@ 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.controller.admin.socail.vo.client.SocialClientSaveReqVO;
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;
@ -22,7 +21,6 @@ import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.SOCIAL_CLI
import static org.junit.jupiter.api.Assertions.*;
// TODO 芋艿:单测后续补充下;
/**
* {@link SocialClientServiceImpl}
*
@ -41,7 +39,8 @@ public class SocialClientServiceImplTest extends BaseDbUnitTest {
@Test
public void testCreateSocialClient_success() {
// 准备参数
SocialClientCreateReqVO reqVO = randomPojo(SocialClientCreateReqVO.class);
SocialClientSaveReqVO reqVO = randomPojo(SocialClientSaveReqVO.class)
.setId(null); // 防止 id 被赋值
// 调用
Long socialClientId = socialClientService.createSocialClient(reqVO);
@ -49,7 +48,7 @@ public class SocialClientServiceImplTest extends BaseDbUnitTest {
assertNotNull(socialClientId);
// 校验记录的属性是否正确
SocialClientDO socialClient = socialClientMapper.selectById(socialClientId);
assertPojoEquals(reqVO, socialClient);
assertPojoEquals(reqVO, socialClient, "id");
}
@Test
@ -58,7 +57,7 @@ public class SocialClientServiceImplTest extends BaseDbUnitTest {
SocialClientDO dbSocialClient = randomPojo(SocialClientDO.class);
socialClientMapper.insert(dbSocialClient);// @Sql: 先插入出一条存在的数据
// 准备参数
SocialClientUpdateReqVO reqVO = randomPojo(SocialClientUpdateReqVO.class, o -> {
SocialClientSaveReqVO reqVO = randomPojo(SocialClientSaveReqVO.class, o -> {
o.setId(dbSocialClient.getId()); // 设置更新的 ID
});
@ -72,7 +71,7 @@ public class SocialClientServiceImplTest extends BaseDbUnitTest {
@Test
public void testUpdateSocialClient_notExists() {
// 准备参数
SocialClientUpdateReqVO reqVO = randomPojo(SocialClientUpdateReqVO.class);
SocialClientSaveReqVO reqVO = randomPojo(SocialClientSaveReqVO.class);
// 调用, 并断言异常
assertServiceException(() -> socialClientService.updateSocialClient(reqVO), SOCIAL_CLIENT_NOT_EXISTS);