From 28bd300d3a20d4eee944b0f412ff26ddaaf3d3d3 Mon Sep 17 00:00:00 2001 From: "mingxing.ai" Date: Mon, 11 Sep 2023 13:16:15 +0800 Subject: [PATCH] init --- .../controller/ClientUserController.java | 17 +++++++++++++++++ .../client/service/IClientUserService.java | 7 ++++++- .../service/IClientUserWalletService.java | 8 ++++++++ .../service/impl/ClientUserServiceImpl.java | 12 ++++++++++++ .../impl/ClientUserWalletServiceImpl.java | 18 +++++++++++++++++- 5 files changed, 60 insertions(+), 2 deletions(-) diff --git a/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/controller/ClientUserController.java b/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/controller/ClientUserController.java index 525101318..a8b66d68e 100644 --- a/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/controller/ClientUserController.java +++ b/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/controller/ClientUserController.java @@ -10,11 +10,13 @@ import com.ruoyi.common.core.constant.SecurityConstants; import com.ruoyi.common.core.context.SecurityContextHolder; import com.ruoyi.common.core.domain.R; +import com.ruoyi.common.core.exception.base.BaseException; import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.security.annotation.InnerAuth; import com.ruoyi.system.api.model.LoginUser; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; import com.ruoyi.common.log.annotation.Log; import com.ruoyi.common.log.enums.BusinessType; @@ -146,10 +148,25 @@ public R getClientUserInfo() { } @PostMapping("/register") + @Transactional(rollbackFor = Exception.class) public R register(@RequestBody ClientUser clientUser) { if (clientUser == null || StringUtils.isAllBlank(clientUser.getUserName(), clientUser.getPassword())) { return R.fail("Username or password must not blank!"); } + ClientUser existUser = clientUserService.selectUserByUserName(clientUser.getUserName()); + if (existUser != null) { + return R.fail("Username has exists!"); + } + boolean registerUserResult = clientUserService.register(clientUser); + logger.info("注册账号结果:{}", registerUserResult); + if (!registerUserResult) { + return R.fail("Unknown exception"); + } + boolean createUserWalletResult = clientUserWalletService.createUserWallet(clientUser.getUserId(), clientUser.getUserName()); + logger.info("创建钱包账户结果:{}", createUserWalletResult); + if (!createUserWalletResult) { + return R.fail("Unknown exception"); + } return R.ok(true); } diff --git a/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/service/IClientUserService.java b/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/service/IClientUserService.java index 8c78e7311..98e5747f0 100644 --- a/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/service/IClientUserService.java +++ b/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/service/IClientUserService.java @@ -62,5 +62,10 @@ public interface IClientUserService public ClientUser selectUserByUserName(String username); - + /** + * 账户注册 + * @param clientUser + * @return + */ + public boolean register(ClientUser clientUser); } diff --git a/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/service/IClientUserWalletService.java b/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/service/IClientUserWalletService.java index 5c0c57233..9d9dfe759 100644 --- a/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/service/IClientUserWalletService.java +++ b/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/service/IClientUserWalletService.java @@ -60,4 +60,12 @@ public interface IClientUserWalletService * @return 结果 */ public int deleteClientUserWalletById(Long id); + + /** + * 创建用户钱包账户 + * @param userId + * @param userName + * @return + */ + public boolean createUserWallet(long userId, String userName); } diff --git a/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/service/impl/ClientUserServiceImpl.java b/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/service/impl/ClientUserServiceImpl.java index 83499668a..8fe68b6a6 100644 --- a/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/service/impl/ClientUserServiceImpl.java +++ b/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/service/impl/ClientUserServiceImpl.java @@ -3,10 +3,13 @@ import com.ruoyi.client.domain.ClientUser; import com.ruoyi.client.mapper.ClientUserMapper; import com.ruoyi.client.service.IClientUserService; +import com.ruoyi.common.core.exception.base.BaseException; +import com.ruoyi.common.core.utils.ExceptionUtil; import org.apache.commons.collections4.CollectionUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.util.Date; import java.util.List; /** @@ -103,4 +106,13 @@ public ClientUser selectUserByUserName(String username) { } return clientUsers.get(0); } + + @Override + public boolean register(ClientUser clientUser) { + clientUser.setCreateBy(clientUser.getUserName()); + clientUser.setUpdateBy(clientUser.getUserName()); + clientUser.setCreateTime(new Date()); + clientUser.setUpdateTime(new Date()); + return clientUserMapper.insertClientUser(clientUser) == 1; + } } diff --git a/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/service/impl/ClientUserWalletServiceImpl.java b/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/service/impl/ClientUserWalletServiceImpl.java index a9e09d2af..1faedb7ea 100644 --- a/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/service/impl/ClientUserWalletServiceImpl.java +++ b/ruoyi-modules/ruoyi-client/src/main/java/com/ruoyi/client/service/impl/ClientUserWalletServiceImpl.java @@ -1,5 +1,7 @@ package com.ruoyi.client.service.impl; +import java.math.BigDecimal; +import java.util.Date; import java.util.List; import com.ruoyi.common.core.utils.DateUtils; import org.apache.commons.collections4.CollectionUtils; @@ -16,7 +18,7 @@ * @date 2023-08-29 */ @Service -public class ClientUserWalletServiceImpl implements IClientUserWalletService +public class ClientUserWalletServiceImpl implements IClientUserWalletService { @Autowired private ClientUserWalletMapper clientUserWalletMapper; @@ -105,4 +107,18 @@ public int deleteClientUserWalletById(Long id) { return clientUserWalletMapper.deleteClientUserWalletById(id); } + + @Override + public boolean createUserWallet(long userId, String userName) { + ClientUserWallet clientUserWallet = new ClientUserWallet(); + clientUserWallet.setUserId(userId); + clientUserWallet.setCurrency("USD"); + clientUserWallet.setTotalAmount(BigDecimal.ZERO); + clientUserWallet.setStatus("normal"); + clientUserWallet.setCreateBy(userName); + clientUserWallet.setUpdateBy(userName); + clientUserWallet.setCreateTime(new Date()); + clientUserWallet.setUpdateTime(new Date()); + return clientUserWalletMapper.insertClientUserWallet(clientUserWallet) == 1; + } }