🎨 钱包账号激活接口
This commit is contained in:
parent
a97c4c3ee3
commit
f304f80692
@ -70,4 +70,6 @@ public class ArticleDTO {
|
||||
private Integer articleThumbsUpCount;
|
||||
/** 赞赏总数 */
|
||||
private Integer articleSponsorCount;
|
||||
|
||||
private Boolean canSponsor;
|
||||
}
|
||||
|
@ -26,4 +26,6 @@ public class TokenUser {
|
||||
|
||||
private Set<String> scope;
|
||||
|
||||
private String bankAccount;
|
||||
|
||||
}
|
||||
|
@ -5,7 +5,8 @@ package com.rymcu.forest.enumerate;
|
||||
*/
|
||||
public enum TransactionCode {
|
||||
|
||||
InsufficientBalance(901, "余额不足");
|
||||
INSUFFICIENT_BALANCE(901, "余额不足"),
|
||||
UNKNOWN_ACCOUNT(902, "账号不存在");
|
||||
|
||||
private int code;
|
||||
|
||||
|
@ -46,5 +46,19 @@ public interface BankAccountService extends Service<BankAccount> {
|
||||
*/
|
||||
BankAccount findInfoByBankAccount(String formBankAccount);
|
||||
|
||||
/**
|
||||
* 根据时间查询账号交易记录
|
||||
* @param bankAccount
|
||||
* @param startDate
|
||||
* @param endDate
|
||||
* @return
|
||||
*/
|
||||
List<TransactionRecordDTO> findUserTransactionRecords(String bankAccount, String startDate, String endDate);
|
||||
|
||||
/**
|
||||
* 创建钱包账号
|
||||
* @param idUser
|
||||
* @return
|
||||
*/
|
||||
BankAccount createBankAccount(Long idUser);
|
||||
}
|
||||
|
@ -13,10 +13,7 @@ import com.rymcu.forest.entity.User;
|
||||
import com.rymcu.forest.handler.event.ArticleDeleteEvent;
|
||||
import com.rymcu.forest.handler.event.ArticleEvent;
|
||||
import com.rymcu.forest.mapper.ArticleMapper;
|
||||
import com.rymcu.forest.service.ArticleService;
|
||||
import com.rymcu.forest.service.NotificationService;
|
||||
import com.rymcu.forest.service.TagService;
|
||||
import com.rymcu.forest.service.UserService;
|
||||
import com.rymcu.forest.service.*;
|
||||
import com.rymcu.forest.util.Html2TextUtil;
|
||||
import com.rymcu.forest.util.Utils;
|
||||
import com.rymcu.forest.util.XssUtils;
|
||||
@ -52,6 +49,8 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
|
||||
private NotificationService notificationService;
|
||||
@Resource
|
||||
private ApplicationEventPublisher publisher;
|
||||
@Resource
|
||||
private BankAccountService bankAccountService;
|
||||
|
||||
@Value("${resource.domain}")
|
||||
private String domain;
|
||||
@ -282,6 +281,8 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
|
||||
List<PortfolioArticleDTO> portfolioArticleDTOList = articleMapper.selectPortfolioArticles(article.getIdArticle());
|
||||
portfolioArticleDTOList.forEach(this::genPortfolioArticles);
|
||||
article.setPortfolios(portfolioArticleDTOList);
|
||||
// 查询作者是否开通钱包账号
|
||||
article.setCanSponsor(Objects.nonNull(bankAccountService.findBankAccountByIdUser(article.getArticleAuthorId())));
|
||||
} else if (type.equals(articleEdit)) {
|
||||
article.setArticleContent(articleContent.getArticleContent());
|
||||
} else {
|
||||
|
@ -43,19 +43,10 @@ public class BankAccountServiceImpl extends AbstractService<BankAccount> impleme
|
||||
String defaultAccountType = "0";
|
||||
bankAccount.setAccountType(defaultAccountType);
|
||||
List<BankAccount> bankAccounts = bankAccountMapper.select(bankAccount);
|
||||
BankAccountDTO bankAccountDTO;
|
||||
if (Objects.nonNull(bankAccounts) && bankAccounts.size() > 0) {
|
||||
bankAccountDTO = bankAccountMapper.selectBankAccount(bankAccounts.get(0).getIdBankAccount());
|
||||
} else {
|
||||
bankAccount.setAccountBalance(new BigDecimal("0"));
|
||||
// 默认为社区发展与改革银行
|
||||
bankAccount.setIdBank(2L);
|
||||
bankAccount.setBankAccount(nextBankAccount());
|
||||
bankAccount.setCreatedTime(new Date());
|
||||
bankAccountMapper.insertSelective(bankAccount);
|
||||
bankAccountDTO = bankAccountMapper.selectBankAccount(bankAccount.getIdBankAccount());
|
||||
return bankAccountMapper.selectBankAccount(bankAccounts.get(0).getIdBankAccount());
|
||||
}
|
||||
return bankAccountDTO;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -69,6 +60,19 @@ public class BankAccountServiceImpl extends AbstractService<BankAccount> impleme
|
||||
return transactionRecordService.findTransactionRecords(bankAccount, startDate, endDate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BankAccount createBankAccount(Long idUser) {
|
||||
BankAccount bankAccount = new BankAccount();
|
||||
bankAccount.setAccountBalance(new BigDecimal("0"));
|
||||
// 默认为社区发展与改革银行
|
||||
bankAccount.setIdBank(2L);
|
||||
bankAccount.setAccountOwner(idUser);
|
||||
bankAccount.setBankAccount(nextBankAccount());
|
||||
bankAccount.setCreatedTime(new Date());
|
||||
bankAccountMapper.insertSelective(bankAccount);
|
||||
return bankAccount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BankAccountDTO findByBankAccount(String bankAccount) {
|
||||
return bankAccountMapper.selectByBankAccount(bankAccount);
|
||||
|
@ -47,7 +47,7 @@ public class SponsorServiceImpl extends AbstractService<Sponsor> implements Spon
|
||||
ArticleDTO articleDTO = articleService.findArticleDTOById(sponsor.getDataId(), 1);
|
||||
TransactionRecord transactionRecord = transactionRecordService.userTransfer(articleDTO.getArticleAuthorId(), sponsor.getSponsor(), transactionEnum);
|
||||
if (Objects.isNull(transactionRecord.getIdTransactionRecord())) {
|
||||
throw new TransactionException(TransactionCode.InsufficientBalance);
|
||||
throw new TransactionException(TransactionCode.INSUFFICIENT_BALANCE);
|
||||
}
|
||||
// 更新文章赞赏数
|
||||
int result = sponsorMapper.updateArticleSponsorCount(articleDTO.getIdArticle());
|
||||
|
@ -49,7 +49,7 @@ public class TransactionRecordServiceImpl extends AbstractService<TransactionRec
|
||||
transactionRecordMapper.insertSelective(transactionRecord);
|
||||
}
|
||||
} else {
|
||||
throw new TransactionException(TransactionCode.InsufficientBalance);
|
||||
throw new TransactionException(TransactionCode.INSUFFICIENT_BALANCE);
|
||||
}
|
||||
return transactionRecord;
|
||||
}
|
||||
@ -73,6 +73,9 @@ public class TransactionRecordServiceImpl extends AbstractService<TransactionRec
|
||||
public TransactionRecord userTransfer(Long toUserId, Long formUserId, TransactionEnum transactionType) {
|
||||
BankAccountDTO toBankAccount = bankAccountMapper.findPersonBankAccountByIdUser(toUserId);
|
||||
BankAccountDTO formBankAccount = bankAccountMapper.findPersonBankAccountByIdUser(formUserId);
|
||||
if (Objects.isNull(toBankAccount) || Objects.isNull(formBankAccount)) {
|
||||
throw new TransactionException(TransactionCode.UNKNOWN_ACCOUNT);
|
||||
}
|
||||
TransactionRecord transactionRecord = new TransactionRecord();
|
||||
transactionRecord.setToBankAccount(toBankAccount.getBankAccount());
|
||||
transactionRecord.setFormBankAccount(formBankAccount.getBankAccount());
|
||||
@ -84,6 +87,9 @@ public class TransactionRecordServiceImpl extends AbstractService<TransactionRec
|
||||
@Override
|
||||
public TransactionRecord bankTransfer(Long idUser, TransactionEnum transactionType) {
|
||||
BankAccountDTO toBankAccount = bankAccountMapper.findPersonBankAccountByIdUser(idUser);
|
||||
if (Objects.isNull(toBankAccount)) {
|
||||
throw new TransactionException(TransactionCode.UNKNOWN_ACCOUNT);
|
||||
}
|
||||
Boolean isTrue;
|
||||
// 校验货币规则
|
||||
switch (transactionType) {
|
||||
@ -156,9 +162,7 @@ public class TransactionRecordServiceImpl extends AbstractService<TransactionRec
|
||||
private boolean checkFormAccountStatus(String formBankAccount, BigDecimal money) {
|
||||
BankAccount bankAccount = findInfoByBankAccount(formBankAccount);
|
||||
if (Objects.nonNull(bankAccount)) {
|
||||
if (bankAccount.getAccountBalance().compareTo(money) > 0) {
|
||||
return true;
|
||||
}
|
||||
return bankAccount.getAccountBalance().compareTo(money) > 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -4,8 +4,10 @@ import com.alibaba.fastjson2.JSONObject;
|
||||
import com.rymcu.forest.auth.TokenManager;
|
||||
import com.rymcu.forest.core.result.GlobalResult;
|
||||
import com.rymcu.forest.core.result.GlobalResultGenerator;
|
||||
import com.rymcu.forest.dto.BankAccountDTO;
|
||||
import com.rymcu.forest.dto.TokenUser;
|
||||
import com.rymcu.forest.entity.User;
|
||||
import com.rymcu.forest.service.BankAccountService;
|
||||
import com.rymcu.forest.service.UserService;
|
||||
import com.rymcu.forest.util.BeanCopierUtil;
|
||||
import com.rymcu.forest.util.UserUtils;
|
||||
@ -25,6 +27,8 @@ public class AuthController {
|
||||
private UserService userService;
|
||||
@Resource
|
||||
TokenManager tokenManager;
|
||||
@Resource
|
||||
private BankAccountService bankAccountService;
|
||||
|
||||
@PostMapping("/login")
|
||||
public GlobalResult<TokenUser> login(@RequestBody User user) {
|
||||
@ -53,6 +57,10 @@ public class AuthController {
|
||||
TokenUser tokenUser = new TokenUser();
|
||||
BeanCopierUtil.copy(user, tokenUser);
|
||||
tokenUser.setScope(userService.findUserPermissions(user));
|
||||
BankAccountDTO bankAccountDTO = bankAccountService.findBankAccountByIdUser(user.getIdUser());
|
||||
if (Objects.nonNull(bankAccountDTO)) {
|
||||
tokenUser.setBankAccount(bankAccountDTO.getBankAccount());
|
||||
}
|
||||
JSONObject object = new JSONObject();
|
||||
object.put("user", tokenUser);
|
||||
return GlobalResultGenerator.genSuccessResult(object);
|
||||
|
@ -6,13 +6,11 @@ import com.rymcu.forest.core.result.GlobalResult;
|
||||
import com.rymcu.forest.core.result.GlobalResultGenerator;
|
||||
import com.rymcu.forest.dto.BankAccountDTO;
|
||||
import com.rymcu.forest.dto.TransactionRecordDTO;
|
||||
import com.rymcu.forest.entity.BankAccount;
|
||||
import com.rymcu.forest.entity.User;
|
||||
import com.rymcu.forest.service.BankAccountService;
|
||||
import com.rymcu.forest.util.UserUtils;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@ -54,4 +52,10 @@ public class WalletController {
|
||||
PageInfo<TransactionRecordDTO> pageInfo = new PageInfo(list);
|
||||
return GlobalResultGenerator.genSuccessResult(pageInfo);
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
public GlobalResult<BankAccount> create() {
|
||||
User user = UserUtils.getCurrentUserByToken();
|
||||
return GlobalResultGenerator.genSuccessResult(bankAccountService.createBankAccount(user.getIdUser()));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user