Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
mingxing.ai committed Sep 11, 2023
1 parent 4461ec1 commit 28bd300
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -146,10 +148,25 @@ public R<ClientUserInfoVo> getClientUserInfo() {
}

@PostMapping("/register")
@Transactional(rollbackFor = Exception.class)
public R<Boolean> 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,10 @@ public interface IClientUserService

public ClientUser selectUserByUserName(String username);


/**
* 账户注册
* @param clientUser
* @return
*/
public boolean register(ClientUser clientUser);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,7 +18,7 @@
* @date 2023-08-29
*/
@Service
public class ClientUserWalletServiceImpl implements IClientUserWalletService
public class ClientUserWalletServiceImpl implements IClientUserWalletService
{
@Autowired
private ClientUserWalletMapper clientUserWalletMapper;
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 28bd300

Please sign in to comment.