From 0c9922ce9481643c9f159797f3b93cc7faf9733f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E5=AE=87=E5=A5=87?= Date: Wed, 23 Apr 2025 15:57:15 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BB=93=E7=AE=97=E8=B4=A6=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ruoyi/xkt/domain/ExternalAccount.java | 4 - .../ruoyi/xkt/dto/account/AccountInfoDTO.java | 23 +++++ .../ruoyi/xkt/dto/account/AlipayBindDTO.java | 31 +++++++ .../dto/account/ExternalAccountAddDTO.java | 43 +++++++++ .../ExternalAccountDTO.java | 6 +- .../ExternalAccountTransDetailDTO.java | 2 +- .../dto/account/InternalAccountAddDTO.java | 25 ++++++ .../InternalAccountDTO.java | 2 +- .../InternalAccountTransDetailDTO.java | 2 +- .../account/TransactionPasswordSetDTO.java | 27 ++++++ .../ruoyi/xkt/service/IAccountService.java | 40 ++++++++- .../xkt/service/IExternalAccountService.java | 27 +++++- .../xkt/service/IInternalAccountService.java | 27 +++++- .../xkt/service/impl/AccountServiceImpl.java | 87 +++++++++++++++++-- .../impl/ExternalAccountServiceImpl.java | 41 ++++++++- .../service/impl/FinanceBillServiceImpl.java | 6 +- .../impl/InternalAccountServiceImpl.java | 44 +++++++++- 17 files changed, 409 insertions(+), 28 deletions(-) create mode 100644 xkt/src/main/java/com/ruoyi/xkt/dto/account/AccountInfoDTO.java create mode 100644 xkt/src/main/java/com/ruoyi/xkt/dto/account/AlipayBindDTO.java create mode 100644 xkt/src/main/java/com/ruoyi/xkt/dto/account/ExternalAccountAddDTO.java rename xkt/src/main/java/com/ruoyi/xkt/dto/{finance => account}/ExternalAccountDTO.java (93%) rename xkt/src/main/java/com/ruoyi/xkt/dto/{finance => account}/ExternalAccountTransDetailDTO.java (97%) create mode 100644 xkt/src/main/java/com/ruoyi/xkt/dto/account/InternalAccountAddDTO.java rename xkt/src/main/java/com/ruoyi/xkt/dto/{finance => account}/InternalAccountDTO.java (97%) rename xkt/src/main/java/com/ruoyi/xkt/dto/{finance => account}/InternalAccountTransDetailDTO.java (97%) create mode 100644 xkt/src/main/java/com/ruoyi/xkt/dto/account/TransactionPasswordSetDTO.java diff --git a/xkt/src/main/java/com/ruoyi/xkt/domain/ExternalAccount.java b/xkt/src/main/java/com/ruoyi/xkt/domain/ExternalAccount.java index b44ccf234..e25553ec5 100644 --- a/xkt/src/main/java/com/ruoyi/xkt/domain/ExternalAccount.java +++ b/xkt/src/main/java/com/ruoyi/xkt/domain/ExternalAccount.java @@ -47,10 +47,6 @@ public class ExternalAccount extends SimpleEntity { * 归属人认证通过 */ private Boolean accountAuthAccess; - /** - * 密码 - */ - private String password; /** * 备注 */ diff --git a/xkt/src/main/java/com/ruoyi/xkt/dto/account/AccountInfoDTO.java b/xkt/src/main/java/com/ruoyi/xkt/dto/account/AccountInfoDTO.java new file mode 100644 index 000000000..8ec752385 --- /dev/null +++ b/xkt/src/main/java/com/ruoyi/xkt/dto/account/AccountInfoDTO.java @@ -0,0 +1,23 @@ +package com.ruoyi.xkt.dto.account; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author liangyq + * @date 2025-04-23 14:17 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class AccountInfoDTO { + /** + * 内部账户 + */ + private InternalAccountDTO internalAccount; + /** + * 支付宝账户 + */ + private ExternalAccountDTO alipayAccount; +} diff --git a/xkt/src/main/java/com/ruoyi/xkt/dto/account/AlipayBindDTO.java b/xkt/src/main/java/com/ruoyi/xkt/dto/account/AlipayBindDTO.java new file mode 100644 index 000000000..231a5f0ab --- /dev/null +++ b/xkt/src/main/java/com/ruoyi/xkt/dto/account/AlipayBindDTO.java @@ -0,0 +1,31 @@ +package com.ruoyi.xkt.dto.account; + +import lombok.Data; + +/** + * @author liangyq + * @date 2025-04-23 14:41 + */ +@Data +public class AlipayBindDTO { + /** + * 档口ID + */ + private Long storeId; + /** + * 账号 + */ + private String accountOwnerNumber; + /** + * 姓名 + */ + private String accountOwnerName; + /** + * 手机号 + */ + private String accountOwnerPhoneNumber; + /** + * 验证码 + */ + private String verifyCode; +} diff --git a/xkt/src/main/java/com/ruoyi/xkt/dto/account/ExternalAccountAddDTO.java b/xkt/src/main/java/com/ruoyi/xkt/dto/account/ExternalAccountAddDTO.java new file mode 100644 index 000000000..481ab4f46 --- /dev/null +++ b/xkt/src/main/java/com/ruoyi/xkt/dto/account/ExternalAccountAddDTO.java @@ -0,0 +1,43 @@ +package com.ruoyi.xkt.dto.account; + +import lombok.Data; + +/** + * @author liangyq + * @date 2025-04-23 15:03 + */ +@Data +public class ExternalAccountAddDTO { + /** + * 归属[1:平台 2:档口 3:用户] + */ + private Integer ownerType; + /** + * 归属ID(平台=-1,档口=store_id,用户=user_id) + */ + private Long ownerId; + /** + * 账户类型[1:支付宝账户] + */ + private Integer accountType; + /** + * 归属人实际账户 + */ + private String accountOwnerNumber; + /** + * 归属人真实姓名 + */ + private String accountOwnerName; + /** + * 归属人手机号 + */ + private String accountOwnerPhoneNumber; + /** + * 归属人认证通过 + */ + private Boolean accountAuthAccess; + /** + * 备注 + */ + private String remark; +} diff --git a/xkt/src/main/java/com/ruoyi/xkt/dto/finance/ExternalAccountDTO.java b/xkt/src/main/java/com/ruoyi/xkt/dto/account/ExternalAccountDTO.java similarity index 93% rename from xkt/src/main/java/com/ruoyi/xkt/dto/finance/ExternalAccountDTO.java rename to xkt/src/main/java/com/ruoyi/xkt/dto/account/ExternalAccountDTO.java index aeb9f8a8c..d42186e3f 100644 --- a/xkt/src/main/java/com/ruoyi/xkt/dto/finance/ExternalAccountDTO.java +++ b/xkt/src/main/java/com/ruoyi/xkt/dto/account/ExternalAccountDTO.java @@ -1,4 +1,4 @@ -package com.ruoyi.xkt.dto.finance; +package com.ruoyi.xkt.dto.account; import lombok.Data; @@ -48,10 +48,6 @@ public class ExternalAccountDTO { * 归属人认证通过 */ private Boolean accountAuthAccess; - /** - * 密码 - */ - private String password; /** * 备注 */ diff --git a/xkt/src/main/java/com/ruoyi/xkt/dto/finance/ExternalAccountTransDetailDTO.java b/xkt/src/main/java/com/ruoyi/xkt/dto/account/ExternalAccountTransDetailDTO.java similarity index 97% rename from xkt/src/main/java/com/ruoyi/xkt/dto/finance/ExternalAccountTransDetailDTO.java rename to xkt/src/main/java/com/ruoyi/xkt/dto/account/ExternalAccountTransDetailDTO.java index 81da922fb..3ac1db4db 100644 --- a/xkt/src/main/java/com/ruoyi/xkt/dto/finance/ExternalAccountTransDetailDTO.java +++ b/xkt/src/main/java/com/ruoyi/xkt/dto/account/ExternalAccountTransDetailDTO.java @@ -1,4 +1,4 @@ -package com.ruoyi.xkt.dto.finance; +package com.ruoyi.xkt.dto.account; import lombok.Data; diff --git a/xkt/src/main/java/com/ruoyi/xkt/dto/account/InternalAccountAddDTO.java b/xkt/src/main/java/com/ruoyi/xkt/dto/account/InternalAccountAddDTO.java new file mode 100644 index 000000000..dc9c8c9b1 --- /dev/null +++ b/xkt/src/main/java/com/ruoyi/xkt/dto/account/InternalAccountAddDTO.java @@ -0,0 +1,25 @@ +package com.ruoyi.xkt.dto.account; + +import lombok.Data; + +/** + * 内部账户 + * + * @author liangyq + * @date 2025-04-01 11:57:52.493 + **/ +@Data +public class InternalAccountAddDTO { + /** + * 归属[1:平台 2:档口 3:用户] + */ + private Integer ownerType; + /** + * 归属ID(平台=-1,档口=store_id) + */ + private Long ownerId; + /** + * 备注 + */ + private String remark; +} diff --git a/xkt/src/main/java/com/ruoyi/xkt/dto/finance/InternalAccountDTO.java b/xkt/src/main/java/com/ruoyi/xkt/dto/account/InternalAccountDTO.java similarity index 97% rename from xkt/src/main/java/com/ruoyi/xkt/dto/finance/InternalAccountDTO.java rename to xkt/src/main/java/com/ruoyi/xkt/dto/account/InternalAccountDTO.java index f7df2eba0..309e3ce5e 100644 --- a/xkt/src/main/java/com/ruoyi/xkt/dto/finance/InternalAccountDTO.java +++ b/xkt/src/main/java/com/ruoyi/xkt/dto/account/InternalAccountDTO.java @@ -1,4 +1,4 @@ -package com.ruoyi.xkt.dto.finance; +package com.ruoyi.xkt.dto.account; import lombok.Data; diff --git a/xkt/src/main/java/com/ruoyi/xkt/dto/finance/InternalAccountTransDetailDTO.java b/xkt/src/main/java/com/ruoyi/xkt/dto/account/InternalAccountTransDetailDTO.java similarity index 97% rename from xkt/src/main/java/com/ruoyi/xkt/dto/finance/InternalAccountTransDetailDTO.java rename to xkt/src/main/java/com/ruoyi/xkt/dto/account/InternalAccountTransDetailDTO.java index 577721570..b877920c0 100644 --- a/xkt/src/main/java/com/ruoyi/xkt/dto/finance/InternalAccountTransDetailDTO.java +++ b/xkt/src/main/java/com/ruoyi/xkt/dto/account/InternalAccountTransDetailDTO.java @@ -1,4 +1,4 @@ -package com.ruoyi.xkt.dto.finance; +package com.ruoyi.xkt.dto.account; import lombok.Data; diff --git a/xkt/src/main/java/com/ruoyi/xkt/dto/account/TransactionPasswordSetDTO.java b/xkt/src/main/java/com/ruoyi/xkt/dto/account/TransactionPasswordSetDTO.java new file mode 100644 index 000000000..82921f7d7 --- /dev/null +++ b/xkt/src/main/java/com/ruoyi/xkt/dto/account/TransactionPasswordSetDTO.java @@ -0,0 +1,27 @@ +package com.ruoyi.xkt.dto.account; + +import lombok.Data; + +/** + * @author liangyq + * @date 2025-04-23 15:32 + */ +@Data +public class TransactionPasswordSetDTO { + /** + * 档口ID + */ + private Long storeId; + /** + * 手机号 + */ + private String phoneNumber; + /** + * 验证码 + */ + private String verifyCode; + /** + * 交易密码 + */ + private String transactionPassword; +} diff --git a/xkt/src/main/java/com/ruoyi/xkt/service/IAccountService.java b/xkt/src/main/java/com/ruoyi/xkt/service/IAccountService.java index 053146b0f..9b468c1bb 100644 --- a/xkt/src/main/java/com/ruoyi/xkt/service/IAccountService.java +++ b/xkt/src/main/java/com/ruoyi/xkt/service/IAccountService.java @@ -1,5 +1,8 @@ package com.ruoyi.xkt.service; +import com.ruoyi.xkt.dto.account.AccountInfoDTO; +import com.ruoyi.xkt.dto.account.AlipayBindDTO; +import com.ruoyi.xkt.dto.account.TransactionPasswordSetDTO; import com.ruoyi.xkt.dto.finance.FinanceBillExt; import com.ruoyi.xkt.enums.EPayChannel; @@ -15,11 +18,11 @@ public interface IAccountService { * * @param storeId * @param amount - * @param password + * @param transactionPassword * @param payChannel * @return */ - FinanceBillExt prepareWithdraw(Long storeId, BigDecimal amount, String password, EPayChannel payChannel); + FinanceBillExt prepareWithdraw(Long storeId, BigDecimal amount, String transactionPassword, EPayChannel payChannel); /** * 档口提现成功 @@ -27,4 +30,37 @@ public interface IAccountService { * @param financeBillId */ void withdrawSuccess(Long financeBillId); + + /** + * 获取档口账户信息 + * + * @param storeId + * @return + */ + AccountInfoDTO getStoreAccountInfo(Long storeId); + + /** + * 创建档口账户 + * + * @param storeId + * @return + */ + AccountInfoDTO createInternalAccountIfNotExists(Long storeId); + + /** + * 设置支付密码 + * + * @param transactionPasswordSet + * @return + */ + AccountInfoDTO setTransactionPassword(TransactionPasswordSetDTO transactionPasswordSet); + + /** + * 绑定支付宝 + * + * @param alipayBind + * @return + */ + AccountInfoDTO bindAlipay(AlipayBindDTO alipayBind); + } diff --git a/xkt/src/main/java/com/ruoyi/xkt/service/IExternalAccountService.java b/xkt/src/main/java/com/ruoyi/xkt/service/IExternalAccountService.java index 3bae1d982..67405100c 100644 --- a/xkt/src/main/java/com/ruoyi/xkt/service/IExternalAccountService.java +++ b/xkt/src/main/java/com/ruoyi/xkt/service/IExternalAccountService.java @@ -1,6 +1,7 @@ package com.ruoyi.xkt.service; import com.ruoyi.xkt.domain.ExternalAccount; +import com.ruoyi.xkt.dto.account.ExternalAccountAddDTO; import com.ruoyi.xkt.dto.finance.TransInfo; import com.ruoyi.xkt.enums.*; @@ -25,7 +26,17 @@ public interface IExternalAccountService { * @param accountType * @return */ - ExternalAccount getExternalAccount(Long ownerId, EAccountOwnerType ownerType, EAccountType accountType); + ExternalAccount getAccount(Long ownerId, EAccountOwnerType ownerType, EAccountType accountType); + + /** + * 获取外部账户 + * + * @param ownerId + * @param ownerType + * @param accountType + * @return + */ + ExternalAccount getAccountAndCheck(Long ownerId, EAccountOwnerType ownerType, EAccountType accountType); /** * 添加交易明细 @@ -47,4 +58,18 @@ public interface IExternalAccountService { */ void entryTransDetail(Long srcBillId, EFinBillType srcBillType); + /** + * 创建账户 + * + * @param add + */ + ExternalAccount createAccount(ExternalAccountAddDTO add); + + /** + * 修改账户 + * + * @param externalAccount + * @return + */ + int modifyAccount(ExternalAccount externalAccount); } diff --git a/xkt/src/main/java/com/ruoyi/xkt/service/IInternalAccountService.java b/xkt/src/main/java/com/ruoyi/xkt/service/IInternalAccountService.java index 63780f1fe..0a55e2064 100644 --- a/xkt/src/main/java/com/ruoyi/xkt/service/IInternalAccountService.java +++ b/xkt/src/main/java/com/ruoyi/xkt/service/IInternalAccountService.java @@ -1,6 +1,7 @@ package com.ruoyi.xkt.service; import com.ruoyi.xkt.domain.InternalAccount; +import com.ruoyi.xkt.dto.account.InternalAccountAddDTO; import com.ruoyi.xkt.dto.finance.TransInfo; import com.ruoyi.xkt.enums.EAccountOwnerType; import com.ruoyi.xkt.enums.EEntryStatus; @@ -27,7 +28,16 @@ public interface IInternalAccountService { * @param ownerType * @return */ - InternalAccount getInternalAccount(Long ownerId, EAccountOwnerType ownerType); + InternalAccount getAccount(Long ownerId, EAccountOwnerType ownerType); + + /** + * 获取内部账户 + * + * @param ownerId + * @param ownerType + * @return + */ + InternalAccount getAccountAndCheck(Long ownerId, EAccountOwnerType ownerType); /** * 添加交易明细 @@ -50,4 +60,19 @@ public interface IInternalAccountService { */ void entryTransDetail(Long srcBillId, EFinBillType srcBillType); + /** + * 创建账户 + * + * @param add + * @return + */ + InternalAccount createAccount(InternalAccountAddDTO add); + + /** + * 设置支付密码 + * + * @param id ID + * @param transactionPassword md5 + */ + void setTransactionPassword(Long id, String transactionPassword); } diff --git a/xkt/src/main/java/com/ruoyi/xkt/service/impl/AccountServiceImpl.java b/xkt/src/main/java/com/ruoyi/xkt/service/impl/AccountServiceImpl.java index 870b31db9..ac821077a 100644 --- a/xkt/src/main/java/com/ruoyi/xkt/service/impl/AccountServiceImpl.java +++ b/xkt/src/main/java/com/ruoyi/xkt/service/impl/AccountServiceImpl.java @@ -1,11 +1,14 @@ package com.ruoyi.xkt.service.impl; +import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.lang.Assert; import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.StrUtil; +import cn.hutool.crypto.SecureUtil; import com.ruoyi.common.exception.ServiceException; import com.ruoyi.xkt.domain.ExternalAccount; import com.ruoyi.xkt.domain.InternalAccount; +import com.ruoyi.xkt.dto.account.*; import com.ruoyi.xkt.dto.finance.FinanceBillExt; import com.ruoyi.xkt.enums.EAccountOwnerType; import com.ruoyi.xkt.enums.EAccountStatus; @@ -40,21 +43,22 @@ public class AccountServiceImpl implements IAccountService { @Transactional(rollbackFor = Exception.class) @Override - public FinanceBillExt prepareWithdraw(Long storeId, BigDecimal amount, String password, EPayChannel payChannel) { + public FinanceBillExt prepareWithdraw(Long storeId, BigDecimal amount, String transactionPassword, + EPayChannel payChannel) { Assert.notNull(storeId); - Assert.notEmpty(password); + Assert.notEmpty(transactionPassword); Assert.isTrue(NumberUtil.isLessOrEqual(amount, BigDecimal.ZERO), "提现金额异常"); - InternalAccount internalAccount = internalAccountService.getInternalAccount(storeId, EAccountOwnerType.STORE); - ExternalAccount externalAccount = externalAccountService.getExternalAccount(storeId, EAccountOwnerType.STORE, + InternalAccount internalAccount = internalAccountService.getAccountAndCheck(storeId, EAccountOwnerType.STORE); + ExternalAccount externalAccount = externalAccountService.getAccountAndCheck(storeId, EAccountOwnerType.STORE, EAccountType.getByChannel(payChannel)); if (!EAccountStatus.NORMAL.getValue().equals(internalAccount.getAccountStatus()) || !EAccountStatus.NORMAL.getValue().equals(externalAccount.getAccountStatus())) { throw new ServiceException("档口账户已冻结"); } - if (StrUtil.isEmpty(externalAccount.getPassword())) { + if (StrUtil.isEmpty(internalAccount.getTransactionPassword())) { throw new ServiceException("请先设置支付密码"); } - if (!StrUtil.equals(password, externalAccount.getPassword())) { + if (!StrUtil.equals(SecureUtil.md5(transactionPassword), internalAccount.getTransactionPassword())) { throw new ServiceException("支付密码错误"); } return financeBillService.createWithdrawPaymentBill(storeId, amount, payChannel); @@ -66,5 +70,76 @@ public class AccountServiceImpl implements IAccountService { financeBillService.entryWithdrawPaymentBill(financeBillId); } + @Override + public AccountInfoDTO getStoreAccountInfo(Long storeId) { + Assert.notNull(storeId); + InternalAccount internalAccount = internalAccountService.getAccount(storeId, EAccountOwnerType.STORE); + ExternalAccount alipayExternalAccount = externalAccountService.getAccount(storeId, EAccountOwnerType.STORE, + EAccountType.ALI_PAY); + return new AccountInfoDTO(BeanUtil.toBean(internalAccount, InternalAccountDTO.class), + BeanUtil.toBean(alipayExternalAccount, ExternalAccountDTO.class)); + } + + @Transactional(rollbackFor = Exception.class) + @Override + public AccountInfoDTO createInternalAccountIfNotExists(Long storeId) { + Assert.notNull(storeId); + InternalAccount internalAccount = internalAccountService.getAccount(storeId, EAccountOwnerType.STORE); + if (internalAccount == null) { + InternalAccountAddDTO addDTO = new InternalAccountAddDTO(); + addDTO.setOwnerId(storeId); + addDTO.setOwnerType(EAccountOwnerType.STORE.getValue()); + internalAccountService.createAccount(addDTO); + } + return getStoreAccountInfo(storeId); + } + + @Transactional(rollbackFor = Exception.class) + @Override + public AccountInfoDTO setTransactionPassword(TransactionPasswordSetDTO transactionPasswordSet) { + Assert.notNull(transactionPasswordSet.getStoreId()); + Assert.notEmpty(transactionPasswordSet.getPhoneNumber()); + Assert.notEmpty(transactionPasswordSet.getVerifyCode()); + Assert.notEmpty(transactionPasswordSet.getTransactionPassword()); + //TODO 验证码 + InternalAccount internalAccount = internalAccountService.getAccountAndCheck(transactionPasswordSet.getStoreId(), + EAccountOwnerType.STORE); + internalAccountService.setTransactionPassword(internalAccount.getId(), + SecureUtil.md5(transactionPasswordSet.getTransactionPassword())); + return getStoreAccountInfo(transactionPasswordSet.getStoreId()); + } + + @Transactional(rollbackFor = Exception.class) + @Override + public AccountInfoDTO bindAlipay(AlipayBindDTO alipayBind) { + Assert.notNull(alipayBind.getStoreId()); + Assert.notEmpty(alipayBind.getAccountOwnerName()); + Assert.notEmpty(alipayBind.getAccountOwnerNumber()); + Assert.notEmpty(alipayBind.getAccountOwnerPhoneNumber()); + //TODO 验证码 + ExternalAccount alipayExternalAccount = externalAccountService.getAccount(alipayBind.getStoreId(), + EAccountOwnerType.STORE, EAccountType.ALI_PAY); + if (alipayExternalAccount != null) { + //修改 + alipayExternalAccount.setAccountOwnerName(alipayBind.getAccountOwnerName()); + alipayExternalAccount.setAccountOwnerNumber(alipayBind.getAccountOwnerNumber()); + alipayExternalAccount.setAccountOwnerPhoneNumber(alipayBind.getAccountOwnerPhoneNumber()); + alipayExternalAccount.setAccountAuthAccess(true); + externalAccountService.modifyAccount(alipayExternalAccount); + } else { + //新增 + ExternalAccountAddDTO addDTO = new ExternalAccountAddDTO(); + addDTO.setOwnerId(alipayBind.getStoreId()); + addDTO.setOwnerType(EAccountOwnerType.STORE.getValue()); + addDTO.setAccountType(EAccountType.ALI_PAY.getValue()); + addDTO.setAccountOwnerName(alipayBind.getAccountOwnerName()); + addDTO.setAccountOwnerNumber(alipayBind.getAccountOwnerNumber()); + addDTO.setAccountOwnerPhoneNumber(alipayBind.getAccountOwnerPhoneNumber()); + addDTO.setAccountAuthAccess(true); + externalAccountService.createAccount(addDTO); + } + return getStoreAccountInfo(alipayBind.getStoreId()); + } + } diff --git a/xkt/src/main/java/com/ruoyi/xkt/service/impl/ExternalAccountServiceImpl.java b/xkt/src/main/java/com/ruoyi/xkt/service/impl/ExternalAccountServiceImpl.java index 581e04a7a..00f7517a3 100644 --- a/xkt/src/main/java/com/ruoyi/xkt/service/impl/ExternalAccountServiceImpl.java +++ b/xkt/src/main/java/com/ruoyi/xkt/service/impl/ExternalAccountServiceImpl.java @@ -1,5 +1,6 @@ package com.ruoyi.xkt.service.impl; +import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.text.CharSequenceUtil; import cn.hutool.core.util.NumberUtil; @@ -10,6 +11,7 @@ import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.bean.BeanValidators; import com.ruoyi.xkt.domain.ExternalAccount; import com.ruoyi.xkt.domain.ExternalAccountTransDetail; +import com.ruoyi.xkt.dto.account.ExternalAccountAddDTO; import com.ruoyi.xkt.dto.finance.TransInfo; import com.ruoyi.xkt.enums.*; import com.ruoyi.xkt.mapper.ExternalAccountMapper; @@ -46,7 +48,19 @@ public class ExternalAccountServiceImpl implements IExternalAccountService { } @Override - public ExternalAccount getExternalAccount(Long ownerId, EAccountOwnerType ownerType, EAccountType accountType) { + public ExternalAccount getAccount(Long ownerId, EAccountOwnerType ownerType, EAccountType accountType) { + Assert.notNull(ownerId); + Assert.notNull(ownerType); + Assert.notNull(accountType); + return externalAccountMapper.selectOne(Wrappers.lambdaQuery(ExternalAccount.class) + .eq(ExternalAccount::getOwnerId, ownerId) + .eq(ExternalAccount::getOwnerType, ownerType.getValue()) + .eq(ExternalAccount::getAccountType, accountType.getValue()) + .eq(SimpleEntity::getDelFlag, Constants.UNDELETED)); + } + + @Override + public ExternalAccount getAccountAndCheck(Long ownerId, EAccountOwnerType ownerType, EAccountType accountType) { Assert.notNull(ownerId); Assert.notNull(ownerType); Assert.notNull(accountType); @@ -124,6 +138,31 @@ public class ExternalAccountServiceImpl implements IExternalAccountService { } } + @Transactional(rollbackFor = Exception.class) + @Override + public ExternalAccount createAccount(ExternalAccountAddDTO add) { + Assert.notNull(add.getOwnerType()); + Assert.notNull(add.getOwnerId()); + Assert.notNull(add.getAccountType()); + ExternalAccount externalAccount = BeanUtil.toBean(add, ExternalAccount.class); + externalAccount.setAccountStatus(EAccountStatus.NORMAL.getValue()); + externalAccount.setDelFlag(Constants.UNDELETED); + externalAccountMapper.insert(externalAccount); + return externalAccount; + } + + @Transactional(rollbackFor = Exception.class) + @Override + public int modifyAccount(ExternalAccount externalAccount) { + Assert.notNull(externalAccount); + Assert.notNull(externalAccount.getId()); + int r = externalAccountMapper.updateById(externalAccount); + if (r == 0) { + throw new ServiceException(Constants.VERSION_LOCK_ERROR_COMMON_MSG); + } + return r; + } + /** * 检查账户状态 * diff --git a/xkt/src/main/java/com/ruoyi/xkt/service/impl/FinanceBillServiceImpl.java b/xkt/src/main/java/com/ruoyi/xkt/service/impl/FinanceBillServiceImpl.java index a0a93c3be..37d63116b 100644 --- a/xkt/src/main/java/com/ruoyi/xkt/service/impl/FinanceBillServiceImpl.java +++ b/xkt/src/main/java/com/ruoyi/xkt/service/impl/FinanceBillServiceImpl.java @@ -117,7 +117,7 @@ public class FinanceBillServiceImpl implements IFinanceBillService { //业务唯一键 String businessUniqueKey = "STORE_ORDER_COMPLETED_" + orderExt.getOrder().getId(); bill.setBusinessUniqueKey(businessUniqueKey); - Long inputInternalAccountId = internalAccountService.getInternalAccount(orderExt.getOrder().getStoreId(), + Long inputInternalAccountId = internalAccountService.getAccountAndCheck(orderExt.getOrder().getStoreId(), EAccountOwnerType.STORE).getId(); bill.setInputInternalAccountId(inputInternalAccountId); bill.setOutputInternalAccountId(Constants.PLATFORM_INTERNAL_ACCOUNT_ID); @@ -240,9 +240,9 @@ public class FinanceBillServiceImpl implements IFinanceBillService { //业务唯一键 String businessUniqueKey = IdUtil.simpleUUID(); bill.setBusinessUniqueKey(businessUniqueKey); - Long outputInternalAccountId = internalAccountService.getInternalAccount(storeId, EAccountOwnerType.STORE) + Long outputInternalAccountId = internalAccountService.getAccountAndCheck(storeId, EAccountOwnerType.STORE) .getId(); - Long inputExternalAccountId = externalAccountService.getExternalAccount(storeId, EAccountOwnerType.STORE, + Long inputExternalAccountId = externalAccountService.getAccountAndCheck(storeId, EAccountOwnerType.STORE, EAccountType.getByChannel(payChannel)).getId(); bill.setOutputInternalAccountId(outputInternalAccountId); bill.setInputExternalAccountId(inputExternalAccountId); diff --git a/xkt/src/main/java/com/ruoyi/xkt/service/impl/InternalAccountServiceImpl.java b/xkt/src/main/java/com/ruoyi/xkt/service/impl/InternalAccountServiceImpl.java index 5158a3d79..6c3f91eb5 100644 --- a/xkt/src/main/java/com/ruoyi/xkt/service/impl/InternalAccountServiceImpl.java +++ b/xkt/src/main/java/com/ruoyi/xkt/service/impl/InternalAccountServiceImpl.java @@ -1,6 +1,7 @@ package com.ruoyi.xkt.service.impl; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.lang.Assert; import cn.hutool.core.text.CharSequenceUtil; import cn.hutool.core.util.NumberUtil; import com.baomidou.mybatisplus.core.toolkit.Wrappers; @@ -10,12 +11,12 @@ import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.bean.BeanValidators; import com.ruoyi.xkt.domain.InternalAccount; import com.ruoyi.xkt.domain.InternalAccountTransDetail; +import com.ruoyi.xkt.dto.account.InternalAccountAddDTO; import com.ruoyi.xkt.dto.finance.TransInfo; import com.ruoyi.xkt.enums.*; import com.ruoyi.xkt.mapper.InternalAccountMapper; import com.ruoyi.xkt.mapper.InternalAccountTransDetailMapper; import com.ruoyi.xkt.service.IInternalAccountService; -import io.jsonwebtoken.lang.Assert; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -47,7 +48,17 @@ public class InternalAccountServiceImpl implements IInternalAccountService { } @Override - public InternalAccount getInternalAccount(Long ownerId, EAccountOwnerType ownerType) { + public InternalAccount getAccount(Long ownerId, EAccountOwnerType ownerType) { + Assert.notNull(ownerId); + Assert.notNull(ownerType); + return internalAccountMapper.selectOne(Wrappers.lambdaQuery(InternalAccount.class) + .eq(InternalAccount::getOwnerId, ownerId) + .eq(InternalAccount::getOwnerType, ownerType.getValue()) + .eq(SimpleEntity::getDelFlag, Constants.UNDELETED)); + } + + @Override + public InternalAccount getAccountAndCheck(Long ownerId, EAccountOwnerType ownerType) { Assert.notNull(ownerId); Assert.notNull(ownerType); InternalAccount account = internalAccountMapper.selectOne(Wrappers.lambdaQuery(InternalAccount.class) @@ -204,6 +215,35 @@ public class InternalAccountServiceImpl implements IInternalAccountService { } } + @Transactional(rollbackFor = Exception.class) + @Override + public InternalAccount createAccount(InternalAccountAddDTO add) { + Assert.notNull(add.getOwnerId()); + Assert.notNull(add.getOwnerType()); + InternalAccount internalAccount = new InternalAccount(); + internalAccount.setOwnerType(add.getOwnerType()); + internalAccount.setOwnerId(add.getOwnerId()); + internalAccount.setAccountStatus(EAccountStatus.NORMAL.getValue()); + internalAccount.setBalance(BigDecimal.ZERO); + internalAccount.setUsableBalance(BigDecimal.ZERO); + internalAccount.setPaymentAmount(BigDecimal.ZERO); + internalAccount.setRemark(add.getRemark()); + internalAccount.setDelFlag(Constants.UNDELETED); + internalAccountMapper.insert(internalAccount); + return internalAccount; + } + + @Transactional(rollbackFor = Exception.class) + @Override + public void setTransactionPassword(Long id, String transactionPassword) { + Assert.notNull(id); + Assert.notEmpty(transactionPassword); + InternalAccount update = new InternalAccount(); + update.setId(id); + update.setTransactionPassword(transactionPassword); + internalAccountMapper.updateById(update); + } + /** * 检查账户状态