From 7e03b61ab1c2b20ffcd26cab01162f161e947d7b Mon Sep 17 00:00:00 2001 From: HH Date: Thu, 26 May 2022 11:21:48 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=80=E4=B8=8B=20Adap?= =?UTF-8?q?ay=20member=5Fid=20=E7=9A=84=E7=94=9F=E6=88=90=E6=96=B9?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../customer/CustomerBankController.java | 3 ++- .../java/com/ghy/common/adapay/MemberType.java | 12 ++++++++++++ .../java/com/ghy/common/utils/AdapayUtils.java | 18 +++++++++++++++--- .../service/impl/CustomerBankServiceImpl.java | 3 ++- 4 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 ghy-common/src/main/java/com/ghy/common/adapay/MemberType.java diff --git a/ghy-admin/src/main/java/com/ghy/web/controller/customer/CustomerBankController.java b/ghy-admin/src/main/java/com/ghy/web/controller/customer/CustomerBankController.java index 16093567..c74bc76c 100644 --- a/ghy-admin/src/main/java/com/ghy/web/controller/customer/CustomerBankController.java +++ b/ghy-admin/src/main/java/com/ghy/web/controller/customer/CustomerBankController.java @@ -3,6 +3,7 @@ package com.ghy.web.controller.customer; import com.alibaba.fastjson.JSON; import com.ghy.common.adapay.AdapayConfig; import com.ghy.common.adapay.AdapayService; +import com.ghy.common.adapay.MemberType; import com.ghy.common.adapay.model.AdapayStatusEnum; import com.ghy.common.adapay.model.Merchant; import com.ghy.common.core.domain.AjaxResult; @@ -40,7 +41,7 @@ public class CustomerBankController { private AjaxResult bindBankCard(BindBankCardRequest request) throws BaseAdaPayException { Set merchants = AdapayConfig.getMerchants(); for (Merchant merchant : merchants) { - String memberId = AdapayUtils.getMemberId(request.getCustomerId(), merchant.getDeptId()); + String memberId = AdapayUtils.getMemberId(request.getCustomerId(), merchant.getDeptId(), MemberType.CUSTOMER); // 先在Adapay创建实名用户 Map result1 = adapayService.createMember(merchant.getDeptId(), memberId, request.getPhone(), request.getName(), request.getCertId(), null, null, null, null); diff --git a/ghy-common/src/main/java/com/ghy/common/adapay/MemberType.java b/ghy-common/src/main/java/com/ghy/common/adapay/MemberType.java new file mode 100644 index 00000000..d264eafd --- /dev/null +++ b/ghy-common/src/main/java/com/ghy/common/adapay/MemberType.java @@ -0,0 +1,12 @@ +package com.ghy.common.adapay; + +public enum MemberType { + WORKER("WK"), + CUSTOMER("CS"); + + public final String code; + + MemberType(String code) { + this.code = code; + } +} diff --git a/ghy-common/src/main/java/com/ghy/common/utils/AdapayUtils.java b/ghy-common/src/main/java/com/ghy/common/utils/AdapayUtils.java index 374534c9..1961759c 100644 --- a/ghy-common/src/main/java/com/ghy/common/utils/AdapayUtils.java +++ b/ghy-common/src/main/java/com/ghy/common/utils/AdapayUtils.java @@ -1,5 +1,6 @@ package com.ghy.common.utils; +import com.ghy.common.adapay.MemberType; import lombok.extern.slf4j.Slf4j; import org.springframework.util.Assert; @@ -9,8 +10,19 @@ import org.springframework.util.Assert; @Slf4j public class AdapayUtils { - public static String getMemberId(Long memberId, Long deptId) { - Assert.isTrue(Math.min(memberId, deptId) > 0, "Invalid [memberId] or [deptId]"); - return String.format("C%dD%d", memberId, deptId); + /** + * 生成 Adapay member_id + * + * @param userId 用户ID + * 当type=WORKER时用worker_id + * 当type=CUSTOMER时用customer_id + * @param deptId 所属公司 + * @param type 用户类型 + * @return member_id + */ + public static String getMemberId(Long userId, Long deptId, MemberType type) { + Assert.isTrue(Math.min(userId, deptId) > 0, "Invalid [userId] or [deptId]"); + return String.format("%sU%dD%d", type.code, userId, deptId); } + } diff --git a/ghy-custom/src/main/java/com/ghy/customer/service/impl/CustomerBankServiceImpl.java b/ghy-custom/src/main/java/com/ghy/customer/service/impl/CustomerBankServiceImpl.java index ea4f5203..f8a44707 100644 --- a/ghy-custom/src/main/java/com/ghy/customer/service/impl/CustomerBankServiceImpl.java +++ b/ghy-custom/src/main/java/com/ghy/customer/service/impl/CustomerBankServiceImpl.java @@ -1,5 +1,6 @@ package com.ghy.customer.service.impl; +import com.ghy.common.adapay.MemberType; import com.ghy.common.utils.AdapayUtils; import com.ghy.customer.domain.CustomerBank; import com.ghy.customer.mapper.CustomerBankMapper; @@ -45,7 +46,7 @@ public class CustomerBankServiceImpl implements CustomerBankService { @Override public int insertCustomerBank(CustomerBank customerBank) { - customerBank.setAdapayMemberId(AdapayUtils.getMemberId(customerBank.getCustomerId(), customerBank.getDeptId())); + customerBank.setAdapayMemberId(AdapayUtils.getMemberId(customerBank.getCustomerId(), customerBank.getDeptId(), MemberType.CUSTOMER)); return customerBankMapper.insertCustomerBank(customerBank); } From f63ba73cd3630553770b487d5b2657f2ccfc1825 Mon Sep 17 00:00:00 2001 From: HH Date: Thu, 26 May 2022 11:27:12 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=90=88=E5=B9=B6=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=87=BA=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../customer/CustomerBankController.java | 3 +-- .../java/com/ghy/common/adapay/MemberType.java | 12 ------------ .../java/com/ghy/common/utils/AdapayUtils.java | 17 +++++++++++++---- .../service/impl/CustomerBankServiceImpl.java | 3 +-- 4 files changed, 15 insertions(+), 20 deletions(-) delete mode 100644 ghy-common/src/main/java/com/ghy/common/adapay/MemberType.java diff --git a/ghy-admin/src/main/java/com/ghy/web/controller/customer/CustomerBankController.java b/ghy-admin/src/main/java/com/ghy/web/controller/customer/CustomerBankController.java index 5e63dac7..c7f98d5a 100644 --- a/ghy-admin/src/main/java/com/ghy/web/controller/customer/CustomerBankController.java +++ b/ghy-admin/src/main/java/com/ghy/web/controller/customer/CustomerBankController.java @@ -3,7 +3,6 @@ package com.ghy.web.controller.customer; import com.alibaba.fastjson.JSON; import com.ghy.common.adapay.AdapayConfig; import com.ghy.common.adapay.AdapayService; -import com.ghy.common.adapay.MemberType; import com.ghy.common.adapay.model.AdapayStatusEnum; import com.ghy.common.adapay.model.Merchant; import com.ghy.common.core.domain.AjaxResult; @@ -44,7 +43,7 @@ public class CustomerBankController { private AjaxResult bindBankCard(@RequestBody BindBankCardRequest request) throws BaseAdaPayException { Set merchants = AdapayConfig.getMerchants(); for (Merchant merchant : merchants) { - String memberId = AdapayUtils.getMemberId(request.getCustomerId(), merchant.getDeptId(), MemberType.CUSTOMER); + String memberId = AdapayUtils.getCustomerMemberId(request.getCustomerId(), merchant.getDeptId()); // 先在Adapay创建实名用户 Map result1 = adapayService.createMember(merchant.getDeptId(), memberId, request.getPhone(), request.getName(), request.getCertId(), null, null, null, null); diff --git a/ghy-common/src/main/java/com/ghy/common/adapay/MemberType.java b/ghy-common/src/main/java/com/ghy/common/adapay/MemberType.java deleted file mode 100644 index d264eafd..00000000 --- a/ghy-common/src/main/java/com/ghy/common/adapay/MemberType.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.ghy.common.adapay; - -public enum MemberType { - WORKER("WK"), - CUSTOMER("CS"); - - public final String code; - - MemberType(String code) { - this.code = code; - } -} diff --git a/ghy-common/src/main/java/com/ghy/common/utils/AdapayUtils.java b/ghy-common/src/main/java/com/ghy/common/utils/AdapayUtils.java index 06249f5d..b09cfd76 100644 --- a/ghy-common/src/main/java/com/ghy/common/utils/AdapayUtils.java +++ b/ghy-common/src/main/java/com/ghy/common/utils/AdapayUtils.java @@ -9,14 +9,23 @@ import org.springframework.util.Assert; @Slf4j public class AdapayUtils { - public static String getMemberId(Long memberId, Long deptId) { - Assert.isTrue(Math.min(memberId, deptId) > 0, "Invalid [memberId] or [deptId]"); - return String.format("C%dD%d", memberId, deptId); + /** + * 生成 Adapay member_id + * + * @param customerId 消费者ID + * @param deptId 分平台id + * @return Adapay member_id + */ + public static String getCustomerMemberId(Long customerId, Long deptId) { + Assert.isTrue(Math.min(customerId, deptId) > 0, "Invalid [customerId] or [deptId]"); + return String.format("C%dD%d", customerId, deptId); } /** + * 生成 Adapay member_id + * * @param workerId 师傅id - * @param deptId 分平台id + * @param deptId 分平台id * @return 生成的唯一id */ public static String getWorkerMemberId(Long workerId, Long deptId) { diff --git a/ghy-custom/src/main/java/com/ghy/customer/service/impl/CustomerBankServiceImpl.java b/ghy-custom/src/main/java/com/ghy/customer/service/impl/CustomerBankServiceImpl.java index f8a44707..e17355f5 100644 --- a/ghy-custom/src/main/java/com/ghy/customer/service/impl/CustomerBankServiceImpl.java +++ b/ghy-custom/src/main/java/com/ghy/customer/service/impl/CustomerBankServiceImpl.java @@ -1,6 +1,5 @@ package com.ghy.customer.service.impl; -import com.ghy.common.adapay.MemberType; import com.ghy.common.utils.AdapayUtils; import com.ghy.customer.domain.CustomerBank; import com.ghy.customer.mapper.CustomerBankMapper; @@ -46,7 +45,7 @@ public class CustomerBankServiceImpl implements CustomerBankService { @Override public int insertCustomerBank(CustomerBank customerBank) { - customerBank.setAdapayMemberId(AdapayUtils.getMemberId(customerBank.getCustomerId(), customerBank.getDeptId(), MemberType.CUSTOMER)); + customerBank.setAdapayMemberId(AdapayUtils.getCustomerMemberId(customerBank.getCustomerId(), customerBank.getDeptId())); return customerBankMapper.insertCustomerBank(customerBank); }