同步最新 master 代码
parent
c33ac915f5
commit
e1faae14cc
|
|
@ -16,10 +16,10 @@ import cn.iocoder.yudao.module.infra.convert.codegen.CodegenConvert;
|
|||
import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenColumnDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenTableDO;
|
||||
import cn.iocoder.yudao.module.infra.service.codegen.CodegenService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.Valid;
|
||||
|
|
@ -60,10 +60,19 @@ public class CodegenController {
|
|||
return success(codegenService.getDatabaseTableList(dataSourceConfigId, name, comment));
|
||||
}
|
||||
|
||||
@GetMapping("/table/list")
|
||||
@Operation(summary = "获得表定义列表")
|
||||
@Parameter(name = "dataSourceConfigId", description = "数据源配置的编号", required = true, example = "1")
|
||||
@PreAuthorize("@ss.hasPermission('infra:codegen:query')")
|
||||
public CommonResult<List<CodegenTableRespVO>> getCodegenTableList(@RequestParam(value = "dataSourceConfigId") Long dataSourceConfigId) {
|
||||
List<CodegenTableDO> list = codegenService.getCodegenTableList(dataSourceConfigId);
|
||||
return success(CodegenConvert.INSTANCE.convertList05(list));
|
||||
}
|
||||
|
||||
@GetMapping("/table/page")
|
||||
@Operation(summary = "获得表定义分页")
|
||||
@PreAuthorize("@ss.hasPermission('infra:codegen:query')")
|
||||
public CommonResult<PageResult<CodegenTableRespVO>> getCodeGenTablePage(@Valid CodegenTablePageReqVO pageReqVO) {
|
||||
public CommonResult<PageResult<CodegenTableRespVO>> getCodegenTablePage(@Valid CodegenTablePageReqVO pageReqVO) {
|
||||
PageResult<CodegenTableDO> pageResult = codegenService.getCodegenTablePage(pageReqVO);
|
||||
return success(CodegenConvert.INSTANCE.convertPage(pageResult));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import cn.hutool.core.util.ObjectUtil;
|
|||
import cn.iocoder.yudao.module.infra.controller.admin.codegen.vo.column.CodegenColumnBaseVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.codegen.vo.table.CodegenTableBaseVO;
|
||||
import cn.iocoder.yudao.module.infra.enums.codegen.CodegenSceneEnum;
|
||||
import cn.iocoder.yudao.module.infra.enums.codegen.CodegenTemplateTypeEnum;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.AssertTrue;
|
||||
|
|
@ -37,12 +39,27 @@ public class CodegenUpdateReqVO {
|
|||
private Long id;
|
||||
|
||||
@AssertTrue(message = "上级菜单不能为空,请前往 [修改生成配置 -> 生成信息] 界面,设置“上级菜单”字段")
|
||||
@JsonIgnore
|
||||
public boolean isParentMenuIdValid() {
|
||||
// 生成场景为管理后台时,必须设置上级菜单,不然生成的菜单 SQL 是无父级菜单的
|
||||
return ObjectUtil.notEqual(getScene(), CodegenSceneEnum.ADMIN.getScene())
|
||||
|| getParentMenuId() != null;
|
||||
}
|
||||
|
||||
@AssertTrue(message = "关联的父表信息不全")
|
||||
@JsonIgnore
|
||||
public boolean isSubValid() {
|
||||
return ObjectUtil.notEqual(getTemplateType(), CodegenTemplateTypeEnum.SUB)
|
||||
|| (ObjectUtil.isAllNotEmpty(getMasterTableId(), getSubJoinColumnId(), getSubJoinMany()));
|
||||
}
|
||||
|
||||
@AssertTrue(message = "关联的树表信息不全")
|
||||
@JsonIgnore
|
||||
public boolean isTreeValid() {
|
||||
return ObjectUtil.notEqual(getTemplateType(), CodegenTemplateTypeEnum.TREE)
|
||||
|| (ObjectUtil.isAllNotEmpty(getTreeParentColumnId(), getTreeNameColumnId()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Schema(description = "更新表定义")
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ public class CodegenBuilder {
|
|||
*/
|
||||
public static final String TENANT_ID_FIELD = "tenantId";
|
||||
/**
|
||||
* {@link BaseDO} 的字段
|
||||
* {@link cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO} 的字段
|
||||
*/
|
||||
public static final Set<String> BASE_DO_FIELDS = new HashSet<>();
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package cn.iocoder.yudao.module.infra.controller.admin.test.vo;
|
||||
package cn.iocoder.yudao.module.member.controller.admin.tag.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
|
@ -6,13 +6,13 @@ import lombok.Data;
|
|||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
@Schema(description = "管理后台 - 字典类型更新 Request VO")
|
||||
@Schema(description = "管理后台 - 会员标签更新 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class TestDemoUpdateReqVO extends TestDemoBaseVO {
|
||||
public class MemberTagUpdateReqVO extends MemberTagBaseVO {
|
||||
|
||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "907")
|
||||
@NotNull(message = "编号不能为空")
|
||||
private Long id;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package cn.iocoder.yudao.module.system.controller.admin.notify;
|
||||
|
||||
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.notify.vo.template.*;
|
||||
|
|
@ -75,8 +76,12 @@ public class NotifyTemplateController {
|
|||
@Operation(summary = "发送站内信")
|
||||
@PreAuthorize("@ss.hasPermission('system:notify-template:send-notify')")
|
||||
public CommonResult<Long> sendNotify(@Valid @RequestBody NotifyTemplateSendReqVO sendReqVO) {
|
||||
return success(notifySendService.sendSingleNotifyToAdmin(sendReqVO.getUserId(),
|
||||
sendReqVO.getTemplateCode(), sendReqVO.getTemplateParams()));
|
||||
if (UserTypeEnum.MEMBER.getValue().equals(sendReqVO.getUserType())) {
|
||||
return success(notifySendService.sendSingleNotifyToMember(sendReqVO.getUserId(),
|
||||
sendReqVO.getTemplateCode(), sendReqVO.getTemplateParams()));
|
||||
} else {
|
||||
return success(notifySendService.sendSingleNotifyToAdmin(sendReqVO.getUserId(),
|
||||
sendReqVO.getTemplateCode(), sendReqVO.getTemplateParams()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,17 +2,24 @@ 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.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.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
|
||||
@Tag(name = "管理后台 - 社交用户")
|
||||
|
|
@ -38,4 +45,23 @@ public class SocialUserController {
|
|||
return CommonResult.success(true);
|
||||
}
|
||||
|
||||
// ==================== 社交用户 CRUD ====================
|
||||
|
||||
@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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.*;
|
|||
import cn.iocoder.yudao.module.system.convert.tenant.TenantConvert;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO;
|
||||
import cn.iocoder.yudao.module.system.service.tenant.TenantService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.annotation.security.PermitAll;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
|
@ -37,8 +37,17 @@ public class TenantController {
|
|||
@Operation(summary = "使用租户名,获得租户编号", description = "登录界面,根据用户的租户名,获得租户编号")
|
||||
@Parameter(name = "name", description = "租户名", required = true, example = "1024")
|
||||
public CommonResult<Long> getTenantIdByName(@RequestParam("name") String name) {
|
||||
TenantDO tenantDO = tenantService.getTenantByName(name);
|
||||
return success(tenantDO != null ? tenantDO.getId() : null);
|
||||
TenantDO tenant = tenantService.getTenantByName(name);
|
||||
return success(tenant != null ? tenant.getId() : null);
|
||||
}
|
||||
|
||||
@GetMapping("/get-by-website")
|
||||
@PermitAll
|
||||
@Operation(summary = "使用域名,获得租户信息", description = "登录界面,根据用户的域名,获得租户信息")
|
||||
@Parameter(name = "website", description = "域名", required = true, example = "www.iocoder.cn")
|
||||
public CommonResult<TenantSimpleRespVO> getTenantByWebsite(@RequestParam("website") String website) {
|
||||
TenantDO tenant = tenantService.getTenantByWebsite(website);
|
||||
return success(TenantConvert.INSTANCE.convert03(tenant));
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
|
|
@ -94,5 +103,4 @@ public class TenantController {
|
|||
ExcelUtils.write(response, "租户.xls", "数据", TenantExcelVO.class, datas);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@ import cn.iocoder.yudao.module.system.mq.message.mail.MailSendMessage;
|
|||
import cn.iocoder.yudao.module.system.service.mail.MailSendService;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* 针对 {@link MailSendMessage} 的消费者
|
||||
*
|
||||
|
|
@ -15,14 +15,15 @@ import java.util.function.Consumer;
|
|||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class MailSendConsumer implements Consumer<MailSendMessage> {
|
||||
public class MailSendConsumer {
|
||||
|
||||
@Resource
|
||||
private MailSendService mailSendService;
|
||||
|
||||
@Override
|
||||
public void accept(MailSendMessage message) {
|
||||
log.info("[accept][消息内容({})]", message);
|
||||
@EventListener
|
||||
@Async // Spring Event 默认在 Producer 发送的线程,通过 @Async 实现异步
|
||||
public void onMessage(MailSendMessage message) {
|
||||
log.info("[onMessage][消息内容({})]", message);
|
||||
mailSendService.doSendMail(message);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@ import cn.iocoder.yudao.module.system.mq.message.sms.SmsSendMessage;
|
|||
import cn.iocoder.yudao.module.system.service.sms.SmsSendService;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* 针对 {@link SmsSendMessage} 的消费者
|
||||
*
|
||||
|
|
@ -15,14 +15,16 @@ import java.util.function.Consumer;
|
|||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class SmsSendConsumer implements Consumer<SmsSendMessage> {
|
||||
public class SmsSendConsumer {
|
||||
|
||||
@Resource
|
||||
private SmsSendService smsSendService;
|
||||
|
||||
@Override
|
||||
public void accept(SmsSendMessage message) {
|
||||
log.info("[accept][消息内容({})]", message);
|
||||
@EventListener
|
||||
@Async // Spring Event 默认在 Producer 发送的线程,通过 @Async 实现异步
|
||||
public void onMessage(SmsSendMessage message) {
|
||||
log.info("[onMessage][消息内容({})]", message);
|
||||
smsSendService.doSendSms(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
|||
throw exception(AUTH_LOGIN_BAD_CREDENTIALS);
|
||||
}
|
||||
// 校验是否禁用
|
||||
if (ObjectUtil.notEqual(user.getStatus(), CommonStatusEnum.ENABLE.getStatus())) {
|
||||
if (CommonStatusEnum.isDisable(user.getStatus())) {
|
||||
createLoginLog(user.getId(), username, logTypeEnum, LoginResultEnum.USER_DISABLED);
|
||||
throw exception(AUTH_LOGIN_USER_DISABLED);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqV
|
|||
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.dept.DeptMapper;
|
||||
import cn.iocoder.yudao.module.system.enums.dept.DeptIdEnum;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
|
@ -41,7 +40,7 @@ public class DeptServiceImplTest extends BaseDbUnitTest {
|
|||
public void testCreateDept() {
|
||||
// 准备参数
|
||||
DeptCreateReqVO reqVO = randomPojo(DeptCreateReqVO.class, o -> {
|
||||
o.setParentId(DeptIdEnum.ROOT.getId());
|
||||
o.setParentId(DeptDO.PARENT_ID_ROOT);
|
||||
o.setStatus(randomCommonStatus());
|
||||
});
|
||||
|
||||
|
|
@ -62,7 +61,7 @@ public class DeptServiceImplTest extends BaseDbUnitTest {
|
|||
// 准备参数
|
||||
DeptUpdateReqVO reqVO = randomPojo(DeptUpdateReqVO.class, o -> {
|
||||
// 设置更新的 ID
|
||||
o.setParentId(DeptIdEnum.ROOT.getId());
|
||||
o.setParentId(DeptDO.PARENT_ID_ROOT);
|
||||
o.setId(dbDeptDO.getId());
|
||||
o.setStatus(randomCommonStatus());
|
||||
});
|
||||
|
|
|
|||
|
|
@ -0,0 +1,147 @@
|
|||
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 jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
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.*;
|
||||
|
||||
// TODO 芋艿:单测后续补充下;
|
||||
|
||||
/**
|
||||
* {@link SocialClientServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Import(SocialClientServiceImpl.class)
|
||||
@Disabled
|
||||
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.setStatus(null);
|
||||
|
||||
// 调用
|
||||
PageResult<SocialClientDO> pageResult = socialClientService.getSocialClientPage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbSocialClient, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
package cn.iocoder.yudao.module.system.service.social;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.yudao.framework.social.core.YudaoAuthRequestFactory;
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
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.dal.dataobject.social.SocialUserBindDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.social.SocialUserDO;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.social.SocialUserBindMapper;
|
||||
|
|
@ -14,17 +14,16 @@ import com.xingyuv.jushauth.model.AuthCallback;
|
|||
import com.xingyuv.jushauth.model.AuthResponse;
|
||||
import com.xingyuv.jushauth.model.AuthUser;
|
||||
import com.xingyuv.jushauth.request.AuthRequest;
|
||||
import com.xingyuv.jushauth.utils.AuthStateUtils;
|
||||
import com.xingyuv.justauth.AuthRequestFactory;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static cn.hutool.core.util.RandomUtil.randomLong;
|
||||
import static cn.hutool.core.util.RandomUtil.randomString;
|
||||
import static cn.hutool.core.util.RandomUtil.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
|
||||
|
|
@ -35,6 +34,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||
import static org.mockito.Mockito.*;
|
||||
|
||||
@Import(SocialUserServiceImpl.class)
|
||||
@Disabled // TODO 芋艿:后续统一修复
|
||||
public class SocialUserServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
|
|
@ -46,40 +46,42 @@ public class SocialUserServiceImplTest extends BaseDbUnitTest {
|
|||
private SocialUserBindMapper socialUserBindMapper;
|
||||
|
||||
@MockBean
|
||||
private YudaoAuthRequestFactory authRequestFactory;
|
||||
private AuthRequestFactory authRequestFactory;
|
||||
|
||||
@Test
|
||||
public void testGetAuthorizeUrl() {
|
||||
try (MockedStatic<AuthStateUtils> authStateUtilsMock = mockStatic(AuthStateUtils.class)) {
|
||||
// 准备参数
|
||||
Integer type = SocialTypeEnum.WECHAT_MP.getType();
|
||||
String redirectUri = "sss";
|
||||
// mock 获得对应的 AuthRequest 实现
|
||||
AuthRequest authRequest = mock(AuthRequest.class);
|
||||
when(authRequestFactory.get(eq("WECHAT_MP"))).thenReturn(authRequest);
|
||||
// mock 方法
|
||||
authStateUtilsMock.when(AuthStateUtils::createState).thenReturn("aoteman");
|
||||
when(authRequest.authorize(eq("aoteman"))).thenReturn("https://www.iocoder.cn?redirect_uri=yyy");
|
||||
|
||||
// 调用
|
||||
String url = socialUserService.getAuthorizeUrl(type, redirectUri);
|
||||
// 断言
|
||||
assertEquals("https://www.iocoder.cn?redirect_uri=sss", url);
|
||||
}
|
||||
}
|
||||
// TODO 芋艿:后续统一修复
|
||||
// @Test
|
||||
// public void testGetAuthorizeUrl() {
|
||||
// try (MockedStatic<AuthStateUtils> authStateUtilsMock = mockStatic(AuthStateUtils.class)) {
|
||||
// // 准备参数
|
||||
// Integer type = SocialTypeEnum.WECHAT_MP.getType();
|
||||
// String redirectUri = "sss";
|
||||
// // mock 获得对应的 AuthRequest 实现
|
||||
// AuthRequest authRequest = mock(AuthRequest.class);
|
||||
// when(authRequestFactory.get(eq("WECHAT_MP"))).thenReturn(authRequest);
|
||||
// // mock 方法
|
||||
// authStateUtilsMock.when(AuthStateUtils::createState).thenReturn("aoteman");
|
||||
// when(authRequest.authorize(eq("aoteman"))).thenReturn("https://www.iocoder.cn?redirect_uri=yyy");
|
||||
//
|
||||
// // 调用
|
||||
// String url = socialUserService.getAuthorizeUrl(type, redirectUri);
|
||||
// // 断言
|
||||
// assertEquals("https://www.iocoder.cn?redirect_uri=sss", url);
|
||||
// }
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void testAuthSocialUser_exists() {
|
||||
// 准备参数
|
||||
Integer type = SocialTypeEnum.GITEE.getType();
|
||||
Integer socialType = SocialTypeEnum.GITEE.getType();
|
||||
Integer userType = randomEle(SocialTypeEnum.values()).getType();
|
||||
String code = "tudou";
|
||||
String state = "yuanma";
|
||||
// mock 方法
|
||||
SocialUserDO socialUser = randomPojo(SocialUserDO.class).setType(type).setCode(code).setState(state);
|
||||
SocialUserDO socialUser = randomPojo(SocialUserDO.class).setType(socialType).setCode(code).setState(state);
|
||||
socialUserMapper.insert(socialUser);
|
||||
|
||||
// 调用
|
||||
SocialUserDO result = socialUserService.authSocialUser(type, code, state);
|
||||
SocialUserDO result = socialUserService.authSocialUser(socialType, userType, code, state);
|
||||
// 断言
|
||||
assertPojoEquals(socialUser, result);
|
||||
}
|
||||
|
|
@ -87,7 +89,8 @@ public class SocialUserServiceImplTest extends BaseDbUnitTest {
|
|||
@Test
|
||||
public void testAuthSocialUser_authFailure() {
|
||||
// 准备参数
|
||||
Integer type = SocialTypeEnum.GITEE.getType();
|
||||
Integer socialType = SocialTypeEnum.GITEE.getType();
|
||||
Integer userType = randomEle(SocialTypeEnum.values()).getType();
|
||||
// mock 方法
|
||||
AuthRequest authRequest = mock(AuthRequest.class);
|
||||
when(authRequestFactory.get(anyString())).thenReturn(authRequest);
|
||||
|
|
@ -96,14 +99,15 @@ public class SocialUserServiceImplTest extends BaseDbUnitTest {
|
|||
|
||||
// 调用并断言
|
||||
assertServiceException(
|
||||
() -> socialUserService.authSocialUser(type, randomString(10), randomString(10)),
|
||||
() -> socialUserService.authSocialUser(socialType, userType, randomString(10), randomString(10)),
|
||||
SOCIAL_USER_AUTH_FAILURE, "模拟失败");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAuthSocialUser_insert() {
|
||||
// 准备参数
|
||||
Integer type = SocialTypeEnum.GITEE.getType();
|
||||
Integer socialType = SocialTypeEnum.GITEE.getType();
|
||||
Integer userType = randomEle(SocialTypeEnum.values()).getType();
|
||||
String code = "tudou";
|
||||
String state = "yuanma";
|
||||
// mock 方法
|
||||
|
|
@ -114,9 +118,9 @@ public class SocialUserServiceImplTest extends BaseDbUnitTest {
|
|||
when(authRequest.login(any(AuthCallback.class))).thenReturn(authResponse);
|
||||
|
||||
// 调用
|
||||
SocialUserDO result = socialUserService.authSocialUser(type, code, state);
|
||||
SocialUserDO result = socialUserService.authSocialUser(socialType, userType, code, state);
|
||||
// 断言
|
||||
assertBindSocialUser(type, result, authResponse.getData());
|
||||
assertBindSocialUser(socialType, result, authResponse.getData());
|
||||
assertEquals(code, result.getCode());
|
||||
assertEquals(state, result.getState());
|
||||
}
|
||||
|
|
@ -124,11 +128,12 @@ public class SocialUserServiceImplTest extends BaseDbUnitTest {
|
|||
@Test
|
||||
public void testAuthSocialUser_update() {
|
||||
// 准备参数
|
||||
Integer type = SocialTypeEnum.GITEE.getType();
|
||||
Integer socialType = SocialTypeEnum.GITEE.getType();
|
||||
Integer userType = randomEle(SocialTypeEnum.values()).getType();
|
||||
String code = "tudou";
|
||||
String state = "yuanma";
|
||||
// mock 数据
|
||||
socialUserMapper.insert(randomPojo(SocialUserDO.class).setType(type).setOpenid("test_openid"));
|
||||
socialUserMapper.insert(randomPojo(SocialUserDO.class).setType(socialType).setOpenid("test_openid"));
|
||||
// mock 方法
|
||||
AuthRequest authRequest = mock(AuthRequest.class);
|
||||
when(authRequestFactory.get(eq(SocialTypeEnum.GITEE.getSource()))).thenReturn(authRequest);
|
||||
|
|
@ -138,9 +143,9 @@ public class SocialUserServiceImplTest extends BaseDbUnitTest {
|
|||
when(authRequest.login(any(AuthCallback.class))).thenReturn(authResponse);
|
||||
|
||||
// 调用
|
||||
SocialUserDO result = socialUserService.authSocialUser(type, code, state);
|
||||
SocialUserDO result = socialUserService.authSocialUser(socialType, userType, code, state);
|
||||
// 断言
|
||||
assertBindSocialUser(type, result, authResponse.getData());
|
||||
assertBindSocialUser(socialType, result, authResponse.getData());
|
||||
assertEquals(code, result.getCode());
|
||||
assertEquals(state, result.getState());
|
||||
}
|
||||
|
|
@ -182,9 +187,9 @@ public class SocialUserServiceImplTest extends BaseDbUnitTest {
|
|||
// 准备参数
|
||||
SocialUserBindReqDTO reqDTO = new SocialUserBindReqDTO()
|
||||
.setUserId(1L).setUserType(UserTypeEnum.ADMIN.getValue())
|
||||
.setType(SocialTypeEnum.GITEE.getType()).setCode("test_code").setState("test_state");
|
||||
.setSocialType(SocialTypeEnum.GITEE.getType()).setCode("test_code").setState("test_state");
|
||||
// mock 数据:获得社交用户
|
||||
SocialUserDO socialUser = randomPojo(SocialUserDO.class).setType(reqDTO.getType())
|
||||
SocialUserDO socialUser = randomPojo(SocialUserDO.class).setType(reqDTO.getSocialType())
|
||||
.setCode(reqDTO.getCode()).setState(reqDTO.getState());
|
||||
socialUserMapper.insert(socialUser);
|
||||
// mock 数据:用户可能之前已经绑定过该社交类型
|
||||
|
|
@ -195,10 +200,11 @@ public class SocialUserServiceImplTest extends BaseDbUnitTest {
|
|||
.setSocialType(SocialTypeEnum.GITEE.getType()).setSocialUserId(socialUser.getId()));
|
||||
|
||||
// 调用
|
||||
socialUserService.bindSocialUser(reqDTO);
|
||||
String openid = socialUserService.bindSocialUser(reqDTO);
|
||||
// 断言
|
||||
List<SocialUserBindDO> socialUserBinds = socialUserBindMapper.selectList();
|
||||
assertEquals(1, socialUserBinds.size());
|
||||
assertEquals(socialUser.getOpenid(), openid);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -232,25 +238,26 @@ public class SocialUserServiceImplTest extends BaseDbUnitTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testGetBindUserId() {
|
||||
public void testGetSocialUser() {
|
||||
// 准备参数
|
||||
Integer userType = UserTypeEnum.ADMIN.getValue();
|
||||
Integer type = SocialTypeEnum.GITEE.getType();
|
||||
String code = "tudou";
|
||||
String state = "yuanma";
|
||||
// mock 社交用户
|
||||
SocialUserDO socialUser = randomPojo(SocialUserDO.class).setType(type).setCode(code).setState(state);
|
||||
socialUserMapper.insert(socialUser);
|
||||
SocialUserDO socialUserDO = randomPojo(SocialUserDO.class).setType(type).setCode(code).setState(state);
|
||||
socialUserMapper.insert(socialUserDO);
|
||||
// mock 社交用户的绑定
|
||||
Long userId = randomLong();
|
||||
SocialUserBindDO socialUserBind = randomPojo(SocialUserBindDO.class).setUserType(userType).setUserId(userId)
|
||||
.setSocialType(type).setSocialUserId(socialUser.getId());
|
||||
.setSocialType(type).setSocialUserId(socialUserDO.getId());
|
||||
socialUserBindMapper.insert(socialUserBind);
|
||||
|
||||
// 调用
|
||||
Long result = socialUserService.getBindUserId(userType, type, code, state);
|
||||
SocialUserRespDTO socialUser = socialUserService.getSocialUser(userType, type, code, state);
|
||||
// 断言
|
||||
assertEquals(userId, result);
|
||||
assertEquals(userId, socialUser.getUserId());
|
||||
assertEquals(socialUserDO.getOpenid(), socialUser.getOpenid());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue