From 10d245afc3dbc4236d0f36186213919fc4df7413 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 8 Dec 2023 22:17:13 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=F0=9F=90=9B=20=E7=A7=BB=E9=99=A4=E5=A4=9A?= =?UTF-8?q?=E4=BD=99=E7=9A=84=20yudao-spring-boot-starter-security=20?= =?UTF-8?q?=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yudao-spring-boot-starter-websocket/pom.xml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/yudao-framework/yudao-spring-boot-starter-websocket/pom.xml b/yudao-framework/yudao-spring-boot-starter-websocket/pom.xml index b18ee4783..b534f10d3 100644 --- a/yudao-framework/yudao-spring-boot-starter-websocket/pom.xml +++ b/yudao-framework/yudao-spring-boot-starter-websocket/pom.xml @@ -38,17 +38,6 @@ spring-boot-starter-websocket - - - - cn.iocoder.boot - yudao-spring-boot-starter-security - provided - - cn.iocoder.boot From 8c67d1d0ba3259b27dbde8568d4db79d4967ef45 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 9 Dec 2023 01:05:25 +0800 Subject: [PATCH 2/9] =?UTF-8?q?=E2=9C=A8=20=E5=A2=9E=E5=8A=A0=E3=80=8A?= =?UTF-8?q?=E8=BF=81=E7=A7=BB=E5=8A=9F=E8=83=BD=E5=88=B0=E7=B2=BE=E7=AE=80?= =?UTF-8?q?=E7=89=88=E3=80=8B=E7=9A=84=E8=AF=B4=E6=98=8E=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 23fa09d6f..f59f99b2c 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,8 @@ * JDK 21 + Spring Boot 3.2.0 版本: 的 `master` 分支 * JDK 8 + Spring Boot 2.7.18 版本: 的 `master-jdk8` 分支 +如果你想把【完整版】的功能,迁移到【精简版】,可以参考 [《迁移功能到精简版》](https://doc.iocoder.cn/migrate-module/) 文档。 + ## 😎 开源协议 **为什么推荐使用本项目?** From d2c071bbb676bec834f60c81cd46863898a0ab45 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 12 Dec 2023 12:17:50 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=E2=9C=A8=20=E8=80=83=E8=99=91=E5=88=B0?= =?UTF-8?q?=E5=A4=A7=E5=AE=B6=E7=9A=84=E6=8E=A5=E5=8F=97=E5=BA=A6=EF=BC=8C?= =?UTF-8?q?master=20=E8=BF=98=E6=98=AF=E4=BF=9D=E6=8C=81=20jdk8=20?= =?UTF-8?q?=E7=89=88=E6=9C=AC=EF=BC=88=E7=A8=B3=E5=AE=9A=EF=BC=89=EF=BC=8C?= =?UTF-8?q?master-jdk21=20=E4=BD=BF=E7=94=A8=20jdk21=20=E7=89=88=E6=9C=AC?= =?UTF-8?q?=EF=BC=88=E5=88=9B=E6=96=B0=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f59f99b2c..35a1e89b5 100644 --- a/README.md +++ b/README.md @@ -78,15 +78,17 @@ 【完整版】包括系统功能、基础设施、会员中心、数据报表、工作流程、商城系统、微信公众号、CRM 等功能 -* JDK 21 + Spring Boot 3.2.0 版本: 的 `master` 分支 -* JDK 8 + Spring Boot 2.7.18 版本: 的 `master-jdk8` 分支 +* JDK 8 + Spring Boot 2.7.18 版本: 的 `master` 分支 +* JDK 21 + Spring Boot 3.2.0 版本: 的 `master-jdk21` 分支 + +两个分支的功能是一致的,可以放心使用! ### ➡️️ 精简版 【精简版】只包括系统功能、基础设施功能,不包括会员中心、数据报表、工作流程、商城系统、微信公众号、CRM 等功能 -* JDK 21 + Spring Boot 3.2.0 版本: 的 `master` 分支 -* JDK 8 + Spring Boot 2.7.18 版本: 的 `master-jdk8` 分支 +* JDK 8 + Spring Boot 2.7.18 版本: 的 `master` 分支 +* JDK 21 + Spring Boot 3.2.0 版本: 的 `master-jdk21` 分支 如果你想把【完整版】的功能,迁移到【精简版】,可以参考 [《迁移功能到精简版》](https://doc.iocoder.cn/migrate-module/) 文档。 From a7189e74257ee12b9920eab91674e79fc1434d6e Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 12 Dec 2023 12:21:38 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=E2=9C=A8=20=E8=80=83=E8=99=91=E5=88=B0?= =?UTF-8?q?=E5=A4=A7=E5=AE=B6=E7=9A=84=E6=8E=A5=E5=8F=97=E5=BA=A6=EF=BC=8C?= =?UTF-8?q?master=20=E8=BF=98=E6=98=AF=E4=BF=9D=E6=8C=81=20jdk8=20?= =?UTF-8?q?=E7=89=88=E6=9C=AC=EF=BC=88=E7=A8=B3=E5=AE=9A=EF=BC=89=EF=BC=8C?= =?UTF-8?q?master-jdk21=20=E4=BD=BF=E7=94=A8=20jdk21=20=E7=89=88=E6=9C=AC?= =?UTF-8?q?=EF=BC=88=E5=88=9B=E6=96=B0=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 35a1e89b5..2ae3cf9ce 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ ![架构图](/.image/common/ruoyi-vue-pro-architecture.png) -* Java 后端:`master` 分支为 JDK 21 + Spring Boot 3.2.0,`master-jdk8` 分支为 JDK8 + Spring Boot 2.7.18 +* Java 后端:`master` 分支为 JDK 8 + Spring Boot 2.7.18,`master-jdk21` 分支为 JDK21 + Spring Boot 3.2.0 * 管理后台的电脑端:Vue3 提供 `element-plus`、`vben(ant-design-vue)` 两个版本,Vue2 提供 `element-ui` 版本 * 管理后台的移动端:采用 `uni-app` 方案,一份代码多终端适配,同时支持 APP、小程序、H5! * 后端采用 Spring Boot 多模块架构、MySQL + MyBatis Plus、Redis + Redisson From 106c1ecf4c08c9f8b2e52d3e2f60408586a55be2 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 19 Dec 2023 23:11:09 +0800 Subject: [PATCH 5/9] =?UTF-8?q?=F0=9F=93=96=20code=20review=EF=BC=9A?= =?UTF-8?q?=E5=BA=97=E9=93=BA=E8=A3=85=E4=BF=AE=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../promotion/controller/admin/diy/DiyTemplateController.java | 2 ++ .../controller/app/decorate/AppDecorateController.java | 1 + .../promotion/controller/app/diy/AppDiyTemplateController.java | 2 ++ .../yudao/module/promotion/dal/dataobject/diy/DiyPageDO.java | 1 + .../module/promotion/dal/dataobject/diy/DiyTemplateDO.java | 3 ++- .../module/pay/dal/mysql/wallet/PayWalletRechargeMapper.java | 3 ++- 6 files changed, 10 insertions(+), 2 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/DiyTemplateController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/DiyTemplateController.java index f8aa3b180..7a3c85b9e 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/DiyTemplateController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/DiyTemplateController.java @@ -82,6 +82,7 @@ public class DiyTemplateController { return success(DiyTemplateConvert.INSTANCE.convertPage(pageResult)); } + // TODO @疯狂:这个要不和 getDiyTemplate 合并,然后 DiyTemplateRespVO 里面直接把 DiyPagePropertyRespVO 也加上。减少 VO 好了,管理后台 get 多返回点数据,也问题不大的。目的,还是想尽可能降低大家的理解成本哈; @GetMapping("/get-property") @Operation(summary = "获得装修模板属性") @Parameter(name = "id", description = "编号", required = true, example = "1024") @@ -92,6 +93,7 @@ public class DiyTemplateController { return success(DiyTemplateConvert.INSTANCE.convertPropertyVo(diyTemplate, pages)); } + // TODO @疯狂:这个接口,要不和 useDiyTemplate 合并成一个,然后 VO 改成我们新的 VO 规范。不改的字段,就不传递。 @PutMapping("/update-property") @Operation(summary = "更新装修模板属性") @PreAuthorize("@ss.hasPermission('promotion:diy-template:update')") diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/decorate/AppDecorateController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/decorate/AppDecorateController.java index 36ae25b55..6f5b1ec68 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/decorate/AppDecorateController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/decorate/AppDecorateController.java @@ -25,6 +25,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @RestController @RequestMapping("/promotion/decorate") @Validated +@Deprecated // 废弃 public class AppDecorateController { @Resource diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/diy/AppDiyTemplateController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/diy/AppDiyTemplateController.java index fa1ea2d5b..90ecbcac4 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/diy/AppDiyTemplateController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/diy/AppDiyTemplateController.java @@ -33,6 +33,7 @@ public class AppDiyTemplateController { @Resource private DiyPageService diyPageService; + // TODO @疯狂:要不要把 used 和 get 接口合并哈;不传递 id,直接拿默认; @GetMapping("/used") @Operation(summary = "使用中的装修模板") public CommonResult getUsedDiyTemplate() { @@ -54,6 +55,7 @@ public class AppDiyTemplateController { } // 查询模板下的页面 List pages = diyPageService.getDiyPageByTemplateId(diyTemplate.getId()); + // TODO @疯狂:首页、我的,要不枚举到 DiyPageDO 例如说 NAME_USER,NAME_HOME 类似这种哈; String home = findFirst(pages, page -> "首页".equals(page.getName()), DiyPageDO::getProperty); String user = findFirst(pages, page -> "我的".equals(page.getName()), DiyPageDO::getProperty); // 拼接返回 diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/diy/DiyPageDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/diy/DiyPageDO.java index 7e1044104..4a9324dfc 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/diy/DiyPageDO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/diy/DiyPageDO.java @@ -44,6 +44,7 @@ public class DiyPageDO extends BaseDO { * 备注 */ private String remark; + // TODO @疯狂:这个字段要不改成 previewPicUrls,和别的模块一样用 pic 作为图片哇? /** * 预览图,多个逗号分隔 */ diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/diy/DiyTemplateDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/diy/DiyTemplateDO.java index 684a6f9cb..daf1f786d 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/diy/DiyTemplateDO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/diy/DiyTemplateDO.java @@ -50,13 +50,14 @@ public class DiyTemplateDO extends BaseDO { * 备注 */ private String remark; + // TODO @疯狂:这个字段要不改成 previewPicUrls,和别的模块一样用 pic 作为图片哇? /** * 预览图 */ @TableField(typeHandler = StringListTypeHandler.class) private List previewImageUrls; /** - * 底部导航属性,JSON 格式 + * uni-app 底部导航属性,JSON 格式 */ private String property; diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletRechargeMapper.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletRechargeMapper.java index e10d23d74..f82b88582 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletRechargeMapper.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletRechargeMapper.java @@ -24,7 +24,8 @@ public interface PayWalletRechargeMapper extends BaseMapperX selectPage(PageParam pageReqVO, Long walletId, Boolean payStatus) { return selectPage(pageReqVO, new LambdaQueryWrapperX() .eq(PayWalletRechargeDO::getWalletId, walletId) - .eq(PayWalletRechargeDO::getPayStatus, payStatus)); + .eq(PayWalletRechargeDO::getPayStatus, payStatus) + .orderByDesc(PayWalletRechargeDO::getId)); } } \ No newline at end of file From d65c28d7f7e7db4a8c14538ba3cd30d3111bf6d3 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 23 Dec 2023 09:59:58 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=E2=9C=A8=20Member=EF=BC=9A=E7=A4=BE?= =?UTF-8?q?=E4=BA=A4=E7=99=BB=E5=BD=95=E9=80=BB=E8=BE=91=E8=B0=83=E6=95=B4?= =?UTF-8?q?=EF=BC=8C=E5=A6=82=E6=9E=9C=E7=99=BB=E5=BD=95=E6=97=B6=E6=97=A0?= =?UTF-8?q?=E7=94=A8=E6=88=B7=EF=BC=8C=E5=88=99=E8=87=AA=E5=8A=A8=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E7=94=A8=E6=88=B7=EF=BC=8C=E4=BF=9D=E6=8C=81=E5=92=8C?= =?UTF-8?q?=E5=90=84=20App=20=E7=BB=9F=E4=B8=80=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/common/enums/TerminalEnum.java | 1 + .../common/util/servlet/ServletUtils.java | 2 -- .../web/core/util/WebFrameworkUtils.java | 19 +++++++++++++++++++ .../app/order/AppTradeOrderController.java | 5 ++--- .../convert/order/TradeOrderConvert.java | 3 +-- .../order/TradeOrderUpdateService.java | 4 +--- .../order/TradeOrderUpdateServiceImpl.java | 14 ++++++++------ .../app/auth/AppAuthController.java | 5 ++--- .../service/auth/MemberAuthService.java | 4 +--- .../service/auth/MemberAuthServiceImpl.java | 10 +++++++--- .../service/user/MemberUserService.java | 12 ++++++++++++ .../service/user/MemberUserServiceImpl.java | 15 +++++++++++---- .../api/logger/dto/LoginLogCreateReqDTO.java | 4 ++-- .../api/social/dto/SocialUserRespDTO.java | 10 +++++++++- .../service/auth/AdminAuthServiceImpl.java | 2 +- .../service/social/SocialUserServiceImpl.java | 8 +++----- 16 files changed, 80 insertions(+), 38 deletions(-) diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/enums/TerminalEnum.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/enums/TerminalEnum.java index 632675203..f256712b3 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/enums/TerminalEnum.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/enums/TerminalEnum.java @@ -15,6 +15,7 @@ import java.util.Arrays; @Getter public enum TerminalEnum implements IntArrayValuable { + UNKNOWN(0, "未知"), // 目的:在无法解析到 terminal 时,使用它 WECHAT_MINI_PROGRAM(10, "微信小程序"), WECHAT_WAP(11, "微信公众号"), H5(20, "H5 网页"), diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/servlet/ServletUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/servlet/ServletUtils.java index 672c1fa19..bc592d890 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/servlet/ServletUtils.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/servlet/ServletUtils.java @@ -88,8 +88,6 @@ public class ServletUtils { return JakartaServletUtil.getClientIP(request); } - // TODO @疯狂:terminal 还是从 ServletUtils 里拿,更容易全局治理; - public static boolean isJsonRequest(ServletRequest request) { return StrUtil.startWithIgnoreCase(request.getContentType(), MediaType.APPLICATION_JSON_VALUE); } diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/util/WebFrameworkUtils.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/util/WebFrameworkUtils.java index 70c59cb4e..ae18634c2 100644 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/util/WebFrameworkUtils.java +++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/util/WebFrameworkUtils.java @@ -1,8 +1,11 @@ package cn.iocoder.yudao.framework.web.core.util; import cn.hutool.core.util.NumberUtil; +import cn.hutool.extra.servlet.ServletUtil; +import cn.iocoder.yudao.framework.common.enums.TerminalEnum; import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; import cn.iocoder.yudao.framework.web.config.WebProperties; import org.springframework.web.context.request.RequestAttributes; import org.springframework.web.context.request.RequestContextHolder; @@ -25,6 +28,13 @@ public class WebFrameworkUtils { public static final String HEADER_TENANT_ID = "tenant-id"; + /** + * 终端的 Header + * + * @see cn.iocoder.yudao.framework.common.enums.TerminalEnum + */ + public static final String HEADER_TERMINAL = "terminal"; + private static WebProperties properties; public WebFrameworkUtils(WebProperties webProperties) { @@ -107,6 +117,15 @@ public class WebFrameworkUtils { return getLoginUserId(request); } + public static Integer getTerminal() { + HttpServletRequest request = getRequest(); + if (request == null) { + return TerminalEnum.UNKNOWN.getTerminal(); + } + String terminalValue = request.getHeader(HEADER_TERMINAL); + return NumberUtil.parseInt(terminalValue, TerminalEnum.UNKNOWN.getTerminal()); + } + public static void setCommonResult(ServletRequest request, CommonResult result) { request.setAttribute(REQUEST_ATTRIBUTE_COMMON_RESULT, result); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java index 545f0adde..8bae3e35d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java @@ -61,9 +61,8 @@ public class AppTradeOrderController { @PostMapping("/create") @Operation(summary = "创建订单") @PreAuthenticated - public CommonResult createOrder(@Valid @RequestBody AppTradeOrderCreateReqVO createReqVO, - @RequestHeader Integer terminal) { - TradeOrderDO order = tradeOrderUpdateService.createOrder(getLoginUserId(), getClientIP(), createReqVO, terminal); + public CommonResult createOrder(@Valid @RequestBody AppTradeOrderCreateReqVO createReqVO) { + TradeOrderDO order = tradeOrderUpdateService.createOrder(getLoginUserId(), createReqVO); return success(new AppTradeOrderCreateRespVO().setId(order.getId()).setPayOrderId(order.getPayOrderId())); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java index 773bb9e91..e368d0355 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java @@ -69,8 +69,7 @@ public interface TradeOrderConvert { @Mapping(source = "calculateRespBO.price.vipPrice", target = "vipPrice"), @Mapping(source = "calculateRespBO.price.payPrice", target = "payPrice") }) - TradeOrderDO convert(Long userId, String userIp, AppTradeOrderCreateReqVO createReqVO, - TradePriceCalculateRespBO calculateRespBO); + TradeOrderDO convert(Long userId, AppTradeOrderCreateReqVO createReqVO, TradePriceCalculateRespBO calculateRespBO); TradeOrderRespDTO convert(TradeOrderDO orderDO); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java index b26d84c65..e16a08bd7 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java @@ -36,12 +36,10 @@ public interface TradeOrderUpdateService { * 【会员】创建交易订单 * * @param userId 登录用户 - * @param userIp 用户 IP 地址 * @param createReqVO 创建交易订单请求模型 - * @param terminal 终端 {@link TerminalEnum} * @return 交易订单的 */ - TradeOrderDO createOrder(Long userId, String userIp, AppTradeOrderCreateReqVO createReqVO, Integer terminal); + TradeOrderDO createOrder(Long userId, AppTradeOrderCreateReqVO createReqVO); /** * 更新交易订单已支付 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index 40e26a2b7..e0b57d923 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -64,6 +64,8 @@ import java.util.Set; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.minusTime; +import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; +import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getTerminal; import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*; /** @@ -158,11 +160,11 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { @Override @Transactional(rollbackFor = Exception.class) @TradeOrderLog(operateType = TradeOrderOperateTypeEnum.MEMBER_CREATE) - public TradeOrderDO createOrder(Long userId, String userIp, AppTradeOrderCreateReqVO createReqVO, Integer terminal) { + public TradeOrderDO createOrder(Long userId, AppTradeOrderCreateReqVO createReqVO) { // 1.1 价格计算 TradePriceCalculateRespBO calculateRespBO = calculatePrice(userId, createReqVO); // 1.2 构建订单 - TradeOrderDO order = buildTradeOrder(userId, userIp, createReqVO, calculateRespBO, terminal); + TradeOrderDO order = buildTradeOrder(userId, createReqVO, calculateRespBO); List orderItems = buildTradeOrderItems(order, calculateRespBO); // 2. 订单创建前的逻辑 @@ -178,15 +180,15 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { return order; } - private TradeOrderDO buildTradeOrder(Long userId, String clientIp, AppTradeOrderCreateReqVO createReqVO, - TradePriceCalculateRespBO calculateRespBO, Integer terminal) { - TradeOrderDO order = TradeOrderConvert.INSTANCE.convert(userId, clientIp, createReqVO, calculateRespBO); + private TradeOrderDO buildTradeOrder(Long userId, AppTradeOrderCreateReqVO createReqVO, + TradePriceCalculateRespBO calculateRespBO) { + TradeOrderDO order = TradeOrderConvert.INSTANCE.convert(userId, createReqVO, calculateRespBO); order.setType(calculateRespBO.getType()); order.setNo(tradeNoRedisDAO.generate(TradeNoRedisDAO.TRADE_ORDER_NO_PREFIX)); order.setStatus(TradeOrderStatusEnum.UNPAID.getStatus()); order.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus()); order.setProductCount(getSumValue(calculateRespBO.getItems(), TradePriceCalculateRespBO.OrderItem::getCount, Integer::sum)); - order.setTerminal(terminal); + order.setUserIp(getClientIP()).setTerminal(getTerminal()); // 支付 + 退款信息 order.setAdjustPrice(0).setPayStatus(false); order.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus()).setRefundPrice(0); diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/auth/AppAuthController.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/auth/AppAuthController.java index 503ff13bd..16c7db207 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/auth/AppAuthController.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/auth/AppAuthController.java @@ -73,9 +73,8 @@ public class AppAuthController { @PostMapping("/sms-login") @Operation(summary = "使用手机 + 验证码登录") - public CommonResult smsLogin(@RequestBody @Valid AppAuthSmsLoginReqVO reqVO, - @RequestHeader Integer terminal) { - return success(authService.smsLogin(reqVO, terminal)); + public CommonResult smsLogin(@RequestBody @Valid AppAuthSmsLoginReqVO reqVO) { + return success(authService.smsLogin(reqVO)); } @PostMapping("/send-sms-code") diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/auth/MemberAuthService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/auth/MemberAuthService.java index 46bc048dc..3fad6e232 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/auth/MemberAuthService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/auth/MemberAuthService.java @@ -1,6 +1,5 @@ package cn.iocoder.yudao.module.member.service.auth; -import cn.iocoder.yudao.framework.common.enums.TerminalEnum; import cn.iocoder.yudao.module.member.controller.app.auth.vo.*; import jakarta.validation.Valid; @@ -33,10 +32,9 @@ public interface MemberAuthService { * 手机 + 验证码登陆 * * @param reqVO 登陆信息 - * @param terminal 终端 {@link TerminalEnum} * @return 登录结果 */ - AppAuthLoginRespVO smsLogin(@Valid AppAuthSmsLoginReqVO reqVO, Integer terminal); + AppAuthLoginRespVO smsLogin(@Valid AppAuthSmsLoginReqVO reqVO); /** * 社交登录,使用 code 授权码 diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/auth/MemberAuthServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/auth/MemberAuthServiceImpl.java index cb246bd0f..3111034d5 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/auth/MemberAuthServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/auth/MemberAuthServiceImpl.java @@ -36,6 +36,7 @@ import java.util.Objects; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; +import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getTerminal; import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.*; /** @@ -78,13 +79,13 @@ public class MemberAuthServiceImpl implements MemberAuthService { @Override @Transactional - public AppAuthLoginRespVO smsLogin(AppAuthSmsLoginReqVO reqVO, Integer terminal) { + public AppAuthLoginRespVO smsLogin(AppAuthSmsLoginReqVO reqVO) { // 校验验证码 String userIp = getClientIP(); smsCodeApi.useSmsCode(AuthConvert.INSTANCE.convert(reqVO, SmsSceneEnum.MEMBER_LOGIN.getScene(), userIp)); // 获得获得注册用户 - MemberUserDO user = userService.createUserIfAbsent(reqVO.getMobile(), userIp, terminal); + MemberUserDO user = userService.createUserIfAbsent(reqVO.getMobile(), userIp, getTerminal()); Assert.notNull(user, "获取用户失败,结果为空"); // 如果 socialType 非空,说明需要绑定社交用户 @@ -107,10 +108,13 @@ public class MemberAuthServiceImpl implements MemberAuthService { throw exception(AUTH_THIRD_LOGIN_NOT_BIND); } - // 自动登录 + // 情况一:已绑定,自动登录 MemberUserDO user = userService.getUser(socialUser.getUserId()); if (user == null) { throw exception(USER_NOT_EXISTS); + // 情况二:未绑定,注册登录 + } else { + user = userService.createUser(user.getNickname(), user.getAvatar(), getClientIP(), getTerminal()); } // 创建 Token 令牌,记录登录日志 diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java index 1305c5ae3..dcd71ea21 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java @@ -49,6 +49,18 @@ public interface MemberUserService { */ MemberUserDO createUserIfAbsent(@Mobile String mobile, String registerIp, Integer terminal); + /** + * 创建用户 + * 目的:三方登录时,如果未绑定用户时,自动创建对应用户 + * + * @param nickname 昵称 + * @param avtar 头像 + * @param registerIp 注册 IP + * @param terminal 终端 {@link TerminalEnum} + * @return 用户对象 + */ + MemberUserDO createUser(String nickname, String avtar, String registerIp, Integer terminal); + /** * 更新用户的最后登陆信息 * diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java index 37b56f001..b704166b4 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java @@ -81,10 +81,17 @@ public class MemberUserServiceImpl implements MemberUserService { return user; } // 用户不存在,则进行创建 - return createUser(mobile, registerIp, terminal); + return createUser(mobile, null, null, registerIp, terminal); } - private MemberUserDO createUser(String mobile, String registerIp, Integer terminal) { + @Override + @Transactional(rollbackFor = Exception.class) + public MemberUserDO createUser(String nickname, String avtar, String registerIp, Integer terminal) { + return createUser(null, nickname, avtar, registerIp, terminal); + } + + private MemberUserDO createUser(String mobile, String nickname, String avtar, + String registerIp, Integer terminal) { // 生成密码 String password = IdUtil.fastSimpleUUID(); // 插入用户 @@ -92,8 +99,8 @@ public class MemberUserServiceImpl implements MemberUserService { user.setMobile(mobile); user.setStatus(CommonStatusEnum.ENABLE.getStatus()); // 默认开启 user.setPassword(encodePassword(password)); // 加密密码 - user.setRegisterIp(registerIp); - user.setRegisterTerminal(terminal); + user.setRegisterIp(registerIp).setRegisterTerminal(terminal); + user.setNickname(nickname).setAvatar(avtar); // 基础信息 memberUserMapper.insert(user); // 发送 MQ 消息:用户创建 diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/logger/dto/LoginLogCreateReqDTO.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/logger/dto/LoginLogCreateReqDTO.java index 2e7a14210..539c8ee27 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/logger/dto/LoginLogCreateReqDTO.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/logger/dto/LoginLogCreateReqDTO.java @@ -36,9 +36,9 @@ public class LoginLogCreateReqDTO { private Integer userType; /** * 用户账号 + * + * 不再强制校验 username 非空,因为 Member 社交登录时,此时暂时没有 username(mobile)! */ - @NotBlank(message = "用户账号不能为空") - @Size(max = 30, message = "用户账号长度不能超过30个字符") private String username; /** diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialUserRespDTO.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialUserRespDTO.java index ac25b148e..29fef0107 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialUserRespDTO.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialUserRespDTO.java @@ -15,9 +15,17 @@ import lombok.NoArgsConstructor; public class SocialUserRespDTO { /** - * 社交用户 openid + * 社交用户的 openid */ private String openid; + /** + * 社交用户的昵称 + */ + private String nickname; + /** + * 社交用户的头像 + */ + private String avatar; /** * 关联的用户编号 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java index aae67de0d..6ff184544 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java @@ -158,7 +158,7 @@ public class AdminAuthServiceImpl implements AdminAuthService { // 使用 code 授权码,进行登录。然后,获得到绑定的用户编号 SocialUserRespDTO socialUser = socialUserService.getSocialUser(UserTypeEnum.ADMIN.getValue(), reqVO.getType(), reqVO.getCode(), reqVO.getState()); - if (socialUser == null) { + if (socialUser == null || socialUser.getUserId() == null) { throw exception(AUTH_THIRD_LOGIN_NOT_BIND); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImpl.java index 1deecba78..5b7dd5f72 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImpl.java @@ -99,13 +99,11 @@ public class SocialUserServiceImpl implements SocialUserService { SocialUserDO socialUser = authSocialUser(socialType, userType, code, state); Assert.notNull(socialUser, "社交用户不能为空"); - // 如果未绑定的社交用户,则无法自动登录,进行报错 + // 获得绑定用户 SocialUserBindDO socialUserBind = socialUserBindMapper.selectByUserTypeAndSocialUserId(userType, socialUser.getId()); - if (socialUserBind == null) { - throw exception(AUTH_THIRD_LOGIN_NOT_BIND); - } - return new SocialUserRespDTO(socialUser.getOpenid(), socialUserBind.getUserId()); + return new SocialUserRespDTO(socialUser.getOpenid(), socialUser.getNickname(), socialUser.getAvatar(), + socialUserBind != null ? socialUserBind.getUserId() : null); } /** From 59752d43b7dcd2f1cc3e767187640f31c2753e3c Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 23 Dec 2023 17:54:13 +0800 Subject: [PATCH 7/9] =?UTF-8?q?=E2=9C=A8=20Member=EF=BC=9A=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E7=A4=BE=E4=BA=A4=E7=99=BB=E5=BD=95=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=88=9B=E5=BB=BA=20user=20=E5=90=8E?= =?UTF-8?q?=EF=BC=8C=E6=9C=AA=E8=BF=9B=E8=A1=8C=E7=BB=91=E5=AE=9A=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/enums/ErrorCodeConstants.java | 2 +- .../service/auth/MemberAuthServiceImpl.java | 18 ++++++++++++------ .../service/user/MemberUserServiceImpl.java | 8 +++++--- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java index c7dc8b749..ee970a54c 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java @@ -18,7 +18,7 @@ public interface ErrorCodeConstants { // ========== AUTH 模块 1-004-003-000 ========== ErrorCode AUTH_LOGIN_BAD_CREDENTIALS = new ErrorCode(1_004_003_000, "登录失败,账号密码不正确"); ErrorCode AUTH_LOGIN_USER_DISABLED = new ErrorCode(1_004_003_001, "登录失败,账号被禁用"); - ErrorCode AUTH_THIRD_LOGIN_NOT_BIND = new ErrorCode(1_004_003_005, "未绑定账号,需要进行绑定"); + ErrorCode AUTH_SOCIAL_USER_NOT_FOUND = new ErrorCode(1_004_003_005, "登录失败,解析不到三方登录信息"); ErrorCode AUTH_MOBILE_USED = new ErrorCode(1_004_003_007, "手机号已经被使用"); // ========== 用户收件地址 1-004-004-000 ========== diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/auth/MemberAuthServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/auth/MemberAuthServiceImpl.java index 3111034d5..78d534610 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/auth/MemberAuthServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/auth/MemberAuthServiceImpl.java @@ -100,21 +100,27 @@ public class MemberAuthServiceImpl implements MemberAuthService { } @Override + @Transactional public AppAuthLoginRespVO socialLogin(AppAuthSocialLoginReqVO reqVO) { // 使用 code 授权码,进行登录。然后,获得到绑定的用户编号 SocialUserRespDTO socialUser = socialUserApi.getSocialUser(UserTypeEnum.MEMBER.getValue(), reqVO.getType(), reqVO.getCode(), reqVO.getState()); if (socialUser == null) { - throw exception(AUTH_THIRD_LOGIN_NOT_BIND); + throw exception(AUTH_SOCIAL_USER_NOT_FOUND); } - // 情况一:已绑定,自动登录 - MemberUserDO user = userService.getUser(socialUser.getUserId()); + // 情况一:已绑定,直接读取用户信息 + MemberUserDO user; + if (socialUser.getUserId() != null) { + user = userService.getUser(socialUser.getUserId()); + // 情况二:未绑定,注册用户 + 绑定用户 + } else { + user = userService.createUser(socialUser.getNickname(), socialUser.getAvatar(), getClientIP(), getTerminal()); + socialUserApi.bindSocialUser(new SocialUserBindReqDTO(user.getId(), getUserType().getValue(), + reqVO.getType(), reqVO.getCode(), reqVO.getState())); + } if (user == null) { throw exception(USER_NOT_EXISTS); - // 情况二:未绑定,注册登录 - } else { - user = userService.createUser(user.getNickname(), user.getAvatar(), getClientIP(), getTerminal()); } // 创建 Token 令牌,记录登录日志 diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java index b704166b4..9fb385475 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java @@ -2,9 +2,7 @@ package cn.iocoder.yudao.module.member.service.user; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.ListUtil; -import cn.hutool.core.util.IdUtil; -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; +import cn.hutool.core.util.*; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; @@ -101,6 +99,10 @@ public class MemberUserServiceImpl implements MemberUserService { user.setPassword(encodePassword(password)); // 加密密码 user.setRegisterIp(registerIp).setRegisterTerminal(terminal); user.setNickname(nickname).setAvatar(avtar); // 基础信息 + if (StrUtil.isEmpty(nickname)) { + // 昵称为空时,随机一个名字,避免一些依赖 nickname 的逻辑报错,或者有点丑。例如说,短信发送有昵称时~ + user.setNickname("用户" + RandomUtil.randomNumbers(6)); + } memberUserMapper.insert(user); // 发送 MQ 消息:用户创建 From 7b482f572986bda8f3f8e6cbe4b646f2497a0c7e Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 23 Dec 2023 21:48:33 +0800 Subject: [PATCH 8/9] =?UTF-8?q?=E2=9C=A8=20Member=EF=BC=9A=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E8=8E=B7=E5=8F=96=E5=8D=95=E4=B8=AA=E7=A4=BE=E4=BA=A4?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/social/AppSocialUserController.java | 31 +++++++++++++++---- .../app/social/vo/AppSocialUserBindReqVO.java | 3 -- .../app/social/vo/AppSocialUserRespVO.java | 19 ++++++++++++ .../social/vo/AppSocialUserUnbindReqVO.java | 3 -- .../convert/social/SocialUserConvert.java | 19 ------------ .../service/auth/MemberAuthServiceImpl.java | 2 +- .../system/api/social/SocialUserApi.java | 13 ++++++-- .../social/dto/SocialUserUnbindReqDTO.java | 4 +++ .../system/api/social/SocialUserApiImpl.java | 9 ++++-- .../mysql/social/SocialUserBindMapper.java | 7 +++++ .../service/auth/AdminAuthServiceImpl.java | 2 +- .../service/social/SocialUserService.java | 12 ++++++- .../service/social/SocialUserServiceImpl.java | 17 ++++++++-- .../auth/AdminAuthServiceImplTest.java | 2 +- .../social/SocialUserServiceImplTest.java | 2 +- 15 files changed, 103 insertions(+), 42 deletions(-) create mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/vo/AppSocialUserRespVO.java delete mode 100644 yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/social/SocialUserConvert.java diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/AppSocialUserController.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/AppSocialUserController.java index 00a27610b..d93e1eaa3 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/AppSocialUserController.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/AppSocialUserController.java @@ -2,11 +2,16 @@ package cn.iocoder.yudao.module.member.controller.app.social; import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialUserBindReqVO; +import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialUserRespVO; import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialUserUnbindReqVO; -import cn.iocoder.yudao.module.member.convert.social.SocialUserConvert; import cn.iocoder.yudao.module.system.api.social.SocialUserApi; +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.api.social.dto.SocialUserUnbindReqDTO; +import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.Operation; import org.springframework.validation.annotation.Validated; @@ -15,11 +20,12 @@ import org.springframework.web.bind.annotation.*; import jakarta.annotation.Resource; import jakarta.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 = "用户 App - 社交用户") @RestController -@RequestMapping("/system/social-user") +@RequestMapping("/member/social-user") @Validated public class AppSocialUserController { @@ -29,16 +35,29 @@ public class AppSocialUserController { @PostMapping("/bind") @Operation(summary = "社交绑定,使用 code 授权码") public CommonResult socialBind(@RequestBody @Valid AppSocialUserBindReqVO reqVO) { - socialUserApi.bindSocialUser(SocialUserConvert.INSTANCE.convert(getLoginUserId(), UserTypeEnum.MEMBER.getValue(), reqVO)); - return CommonResult.success(true); + SocialUserBindReqDTO reqDTO = new SocialUserBindReqDTO(getLoginUserId(), UserTypeEnum.MEMBER.getValue(), + reqVO.getType(), reqVO.getCode(), reqVO.getState()); + socialUserApi.bindSocialUser(reqDTO); + return success(true); } @DeleteMapping("/unbind") @Operation(summary = "取消社交绑定") @PreAuthenticated public CommonResult socialUnbind(@RequestBody AppSocialUserUnbindReqVO reqVO) { - socialUserApi.unbindSocialUser(SocialUserConvert.INSTANCE.convert(getLoginUserId(), UserTypeEnum.MEMBER.getValue(), reqVO)); - return CommonResult.success(true); + SocialUserUnbindReqDTO reqDTO = new SocialUserUnbindReqDTO(getLoginUserId(), UserTypeEnum.MEMBER.getValue(), + reqVO.getType(), reqVO.getOpenid()); + socialUserApi.unbindSocialUser(reqDTO); + return success(true); + } + + @GetMapping("/get") + @Operation(summary = "获得社交用户") + @Parameter(name = "type", description = "社交平台的类型,参见 SocialTypeEnum 枚举值", required = true, example = "10") + @PreAuthenticated + public CommonResult getSocialUser(@RequestParam("type") Integer type) { + SocialUserRespDTO socialUser = socialUserApi.getSocialUserByUserId(UserTypeEnum.MEMBER.getValue(), getLoginUserId(), type); + return success(BeanUtils.toBean(socialUser, AppSocialUserRespVO.class)); } } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/vo/AppSocialUserBindReqVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/vo/AppSocialUserBindReqVO.java index 3c0080c21..0b455965a 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/vo/AppSocialUserBindReqVO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/vo/AppSocialUserBindReqVO.java @@ -13,9 +13,6 @@ import jakarta.validation.constraints.NotNull; @Schema(description = "用户 APP - 社交绑定 Request VO,使用 code 授权码") @Data -@NoArgsConstructor -@AllArgsConstructor -@Builder public class AppSocialUserBindReqVO { @Schema(description = "社交平台的类型,参见 SocialTypeEnum 枚举值", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/vo/AppSocialUserRespVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/vo/AppSocialUserRespVO.java new file mode 100644 index 000000000..f37ced800 --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/vo/AppSocialUserRespVO.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.member.controller.app.social.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "用户 APP - 社交用户 Response VO") +@Data +public class AppSocialUserRespVO { + + @Schema(description = "社交用户的 openid", requiredMode = Schema.RequiredMode.REQUIRED, example = "IPRmJ0wvBptiPIlGEZiPewGwiEiE") + private String openid; + + @Schema(description = "社交用户的昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道源码") + private String nickname; + + @Schema(description = "社交用户的头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png") + private String avatar; + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/vo/AppSocialUserUnbindReqVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/vo/AppSocialUserUnbindReqVO.java index 43bf067b4..5b3cd8866 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/vo/AppSocialUserUnbindReqVO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/vo/AppSocialUserUnbindReqVO.java @@ -13,9 +13,6 @@ import jakarta.validation.constraints.NotNull; @Schema(description = "用户 APP - 取消社交绑定 Request VO") @Data -@NoArgsConstructor -@AllArgsConstructor -@Builder public class AppSocialUserUnbindReqVO { @Schema(description = "社交平台的类型,参见 SocialTypeEnum 枚举值", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/social/SocialUserConvert.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/social/SocialUserConvert.java deleted file mode 100644 index 3c9288ba8..000000000 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/social/SocialUserConvert.java +++ /dev/null @@ -1,19 +0,0 @@ -package cn.iocoder.yudao.module.member.convert.social; - -import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialUserBindReqVO; -import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialUserUnbindReqVO; -import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO; -import cn.iocoder.yudao.module.system.api.social.dto.SocialUserUnbindReqDTO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -@Mapper -public interface SocialUserConvert { - - SocialUserConvert INSTANCE = Mappers.getMapper(SocialUserConvert.class); - - SocialUserBindReqDTO convert(Long userId, Integer userType, AppSocialUserBindReqVO reqVO); - - SocialUserUnbindReqDTO convert(Long userId, Integer userType, AppSocialUserUnbindReqVO reqVO); - -} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/auth/MemberAuthServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/auth/MemberAuthServiceImpl.java index 78d534610..7fb1926ce 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/auth/MemberAuthServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/auth/MemberAuthServiceImpl.java @@ -103,7 +103,7 @@ public class MemberAuthServiceImpl implements MemberAuthService { @Transactional public AppAuthLoginRespVO socialLogin(AppAuthSocialLoginReqVO reqVO) { // 使用 code 授权码,进行登录。然后,获得到绑定的用户编号 - SocialUserRespDTO socialUser = socialUserApi.getSocialUser(UserTypeEnum.MEMBER.getValue(), reqVO.getType(), + SocialUserRespDTO socialUser = socialUserApi.getSocialUserByCode(UserTypeEnum.MEMBER.getValue(), reqVO.getType(), reqVO.getCode(), reqVO.getState()); if (socialUser == null) { throw exception(AUTH_SOCIAL_USER_NOT_FOUND); diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialUserApi.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialUserApi.java index 5038e94bd..e24f8356d 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialUserApi.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialUserApi.java @@ -29,6 +29,16 @@ public interface SocialUserApi { */ void unbindSocialUser(@Valid SocialUserUnbindReqDTO reqDTO); + /** + * 获得社交用户,基于 userId + * + * @param userType 用户类型 + * @param userId 用户编号 + * @param socialType 社交平台的类型 + * @return 社交用户 + */ + SocialUserRespDTO getSocialUserByUserId(Integer userType, Long userId, Integer socialType); + /** * 获得社交用户 * @@ -40,7 +50,6 @@ public interface SocialUserApi { * @param state state * @return 社交用户 */ - SocialUserRespDTO getSocialUser(Integer userType, Integer socialType, - String code, String state); + SocialUserRespDTO getSocialUserByCode(Integer userType, Integer socialType, String code, String state); } diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialUserUnbindReqDTO.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialUserUnbindReqDTO.java index 55ff5b165..7e559d8ee 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialUserUnbindReqDTO.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/dto/SocialUserUnbindReqDTO.java @@ -3,10 +3,12 @@ package cn.iocoder.yudao.module.system.api.social.dto; import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.common.validation.InEnum; import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; +import lombok.AllArgsConstructor; import lombok.Data; import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; +import lombok.NoArgsConstructor; /** * 社交绑定 Request DTO,使用 code 授权码 @@ -14,6 +16,8 @@ import jakarta.validation.constraints.NotNull; * @author 芋道源码 */ @Data +@AllArgsConstructor +@NoArgsConstructor public class SocialUserUnbindReqDTO { /** diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialUserApiImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialUserApiImpl.java index dc92dfce6..eb8331618 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialUserApiImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialUserApiImpl.java @@ -33,8 +33,13 @@ public class SocialUserApiImpl implements SocialUserApi { } @Override - public SocialUserRespDTO getSocialUser(Integer userType, Integer socialType, String code, String state) { - return socialUserService.getSocialUser(userType, socialType, code, state); + public SocialUserRespDTO getSocialUserByUserId(Integer userType, Long userId, Integer socialType) { + return socialUserService.getSocialUserByUserId(userType, userId, socialType); + } + + @Override + public SocialUserRespDTO getSocialUserByCode(Integer userType, Integer socialType, String code, String state) { + return socialUserService.getSocialUserByCode(userType, socialType, code, state); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/social/SocialUserBindMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/social/SocialUserBindMapper.java index 28619ca51..d9957f76c 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/social/SocialUserBindMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/social/SocialUserBindMapper.java @@ -34,4 +34,11 @@ public interface SocialUserBindMapper extends BaseMapperX { .eq(SocialUserBindDO::getUserType, userType)); } + default SocialUserBindDO selectByUserIdAndUserTypeAndSocialType(Long userId, Integer userType, Integer socialType) { + return selectOne(new LambdaQueryWrapperX() + .eq(SocialUserBindDO::getUserId, userId) + .eq(SocialUserBindDO::getUserType, userType) + .eq(SocialUserBindDO::getSocialType, socialType)); + } + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java index 6ff184544..bd4c93e11 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java @@ -156,7 +156,7 @@ public class AdminAuthServiceImpl implements AdminAuthService { @Override public AuthLoginRespVO socialLogin(AuthSocialLoginReqVO reqVO) { // 使用 code 授权码,进行登录。然后,获得到绑定的用户编号 - SocialUserRespDTO socialUser = socialUserService.getSocialUser(UserTypeEnum.ADMIN.getValue(), reqVO.getType(), + SocialUserRespDTO socialUser = socialUserService.getSocialUserByCode(UserTypeEnum.ADMIN.getValue(), reqVO.getType(), reqVO.getCode(), reqVO.getState()); if (socialUser == null || socialUser.getUserId() == null) { throw exception(AUTH_THIRD_LOGIN_NOT_BIND); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserService.java index c840f19d1..739ff2d94 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserService.java @@ -45,6 +45,16 @@ public interface SocialUserService { */ void unbindSocialUser(Long userId, Integer userType, Integer socialType, String openid); + /** + * 获得社交用户,基于 userId + * + * @param userType 用户类型 + * @param userId 用户编号 + * @param socialType 社交平台的类型 + * @return 社交用户 + */ + SocialUserRespDTO getSocialUserByUserId(Integer userType, Long userId, Integer socialType); + /** * 获得社交用户 * @@ -56,7 +66,7 @@ public interface SocialUserService { * @param state state * @return 社交用户 */ - SocialUserRespDTO getSocialUser(Integer userType, Integer socialType, String code, String state); + SocialUserRespDTO getSocialUserByCode(Integer userType, Integer socialType, String code, String state); // ==================== 社交用户 CRUD ==================== diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImpl.java index 5b7dd5f72..7f1b271ad 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImpl.java @@ -26,7 +26,6 @@ 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; /** @@ -94,7 +93,21 @@ public class SocialUserServiceImpl implements SocialUserService { } @Override - public SocialUserRespDTO getSocialUser(Integer userType, Integer socialType, String code, String state) { + public SocialUserRespDTO getSocialUserByUserId(Integer userType, Long userId, Integer socialType) { + // 获得绑定用户 + SocialUserBindDO socialUserBind = socialUserBindMapper.selectByUserIdAndUserTypeAndSocialType(userId, userType, socialType); + if (socialUserBind == null) { + return null; + } + // 获得社交用户 + SocialUserDO socialUser = socialUserMapper.selectById(socialUserBind.getSocialUserId()); + Assert.notNull(socialUser, "社交用户不能为空"); + return new SocialUserRespDTO(socialUser.getOpenid(), socialUser.getNickname(), socialUser.getAvatar(), + socialUserBind.getUserId()); + } + + @Override + public SocialUserRespDTO getSocialUserByCode(Integer userType, Integer socialType, String code, String state) { // 获得社交用户 SocialUserDO socialUser = authSocialUser(socialType, userType, code, state); Assert.notNull(socialUser, "社交用户不能为空"); diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImplTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImplTest.java index cd6c81f9f..a731d9ab5 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImplTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImplTest.java @@ -236,7 +236,7 @@ public class AdminAuthServiceImplTest extends BaseDbUnitTest { AuthSocialLoginReqVO reqVO = randomPojo(AuthSocialLoginReqVO.class); // mock 方法(绑定的用户编号) Long userId = 1L; - when(socialUserService.getSocialUser(eq(UserTypeEnum.ADMIN.getValue()), eq(reqVO.getType()), + when(socialUserService.getSocialUserByCode(eq(UserTypeEnum.ADMIN.getValue()), eq(reqVO.getType()), eq(reqVO.getCode()), eq(reqVO.getState()))).thenReturn(new SocialUserRespDTO(randomString(), userId)); // mock(用户) AdminUserDO user = randomPojo(AdminUserDO.class, o -> o.setId(userId)); diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImplTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImplTest.java index 3685ed266..32393dd51 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImplTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImplTest.java @@ -147,7 +147,7 @@ public class SocialUserServiceImplTest extends BaseDbUnitTest { socialUserBindMapper.insert(socialUserBind); // 调用 - SocialUserRespDTO socialUser = socialUserService.getSocialUser(userType, type, code, state); + SocialUserRespDTO socialUser = socialUserService.getSocialUserByCode(userType, type, code, state); // 断言 assertEquals(userId, socialUser.getUserId()); assertEquals(socialUserDO.getOpenid(), socialUser.getOpenid()); From bd5c7d57dc962297b05c82da19ef388c80c0f5a3 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 23 Dec 2023 22:54:20 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E2=9C=A8=20Member=EF=BC=9A=E7=A4=BE?= =?UTF-8?q?=E4=BA=A4=EF=BC=88=E4=B8=89=E6=96=B9=EF=BC=89=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=EF=BC=8C=E5=A2=9E=E5=8A=A0=20openid=20?= =?UTF-8?q?=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/app/social/AppSocialUserController.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/AppSocialUserController.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/AppSocialUserController.java index d93e1eaa3..fcdd2132d 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/AppSocialUserController.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/AppSocialUserController.java @@ -34,11 +34,11 @@ public class AppSocialUserController { @PostMapping("/bind") @Operation(summary = "社交绑定,使用 code 授权码") - public CommonResult socialBind(@RequestBody @Valid AppSocialUserBindReqVO reqVO) { + public CommonResult socialBind(@RequestBody @Valid AppSocialUserBindReqVO reqVO) { SocialUserBindReqDTO reqDTO = new SocialUserBindReqDTO(getLoginUserId(), UserTypeEnum.MEMBER.getValue(), reqVO.getType(), reqVO.getCode(), reqVO.getState()); - socialUserApi.bindSocialUser(reqDTO); - return success(true); + String openid = socialUserApi.bindSocialUser(reqDTO); + return success(openid); } @DeleteMapping("/unbind")