commit
6791d758f6
@ -70,4 +70,6 @@ public class ArticleDTO {
|
|||||||
private Integer articleThumbsUpCount;
|
private Integer articleThumbsUpCount;
|
||||||
/** 赞赏总数 */
|
/** 赞赏总数 */
|
||||||
private Integer articleSponsorCount;
|
private Integer articleSponsorCount;
|
||||||
|
|
||||||
|
private Boolean canSponsor;
|
||||||
}
|
}
|
||||||
|
@ -26,4 +26,6 @@ public class TokenUser {
|
|||||||
|
|
||||||
private Set<String> scope;
|
private Set<String> scope;
|
||||||
|
|
||||||
|
private String bankAccount;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,8 @@ package com.rymcu.forest.enumerate;
|
|||||||
*/
|
*/
|
||||||
public enum TransactionCode {
|
public enum TransactionCode {
|
||||||
|
|
||||||
InsufficientBalance(901, "余额不足");
|
INSUFFICIENT_BALANCE(901, "余额不足"),
|
||||||
|
UNKNOWN_ACCOUNT(902, "账号不存在");
|
||||||
|
|
||||||
private int code;
|
private int code;
|
||||||
|
|
||||||
|
@ -46,5 +46,19 @@ public interface BankAccountService extends Service<BankAccount> {
|
|||||||
*/
|
*/
|
||||||
BankAccount findInfoByBankAccount(String formBankAccount);
|
BankAccount findInfoByBankAccount(String formBankAccount);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据时间查询账号交易记录
|
||||||
|
* @param bankAccount
|
||||||
|
* @param startDate
|
||||||
|
* @param endDate
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
List<TransactionRecordDTO> findUserTransactionRecords(String bankAccount, String startDate, String endDate);
|
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.ArticleDeleteEvent;
|
||||||
import com.rymcu.forest.handler.event.ArticleEvent;
|
import com.rymcu.forest.handler.event.ArticleEvent;
|
||||||
import com.rymcu.forest.mapper.ArticleMapper;
|
import com.rymcu.forest.mapper.ArticleMapper;
|
||||||
import com.rymcu.forest.service.ArticleService;
|
import com.rymcu.forest.service.*;
|
||||||
import com.rymcu.forest.service.NotificationService;
|
|
||||||
import com.rymcu.forest.service.TagService;
|
|
||||||
import com.rymcu.forest.service.UserService;
|
|
||||||
import com.rymcu.forest.util.Html2TextUtil;
|
import com.rymcu.forest.util.Html2TextUtil;
|
||||||
import com.rymcu.forest.util.Utils;
|
import com.rymcu.forest.util.Utils;
|
||||||
import com.rymcu.forest.util.XssUtils;
|
import com.rymcu.forest.util.XssUtils;
|
||||||
@ -52,6 +49,8 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
|
|||||||
private NotificationService notificationService;
|
private NotificationService notificationService;
|
||||||
@Resource
|
@Resource
|
||||||
private ApplicationEventPublisher publisher;
|
private ApplicationEventPublisher publisher;
|
||||||
|
@Resource
|
||||||
|
private BankAccountService bankAccountService;
|
||||||
|
|
||||||
@Value("${resource.domain}")
|
@Value("${resource.domain}")
|
||||||
private String domain;
|
private String domain;
|
||||||
@ -282,6 +281,8 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
|
|||||||
List<PortfolioArticleDTO> portfolioArticleDTOList = articleMapper.selectPortfolioArticles(article.getIdArticle());
|
List<PortfolioArticleDTO> portfolioArticleDTOList = articleMapper.selectPortfolioArticles(article.getIdArticle());
|
||||||
portfolioArticleDTOList.forEach(this::genPortfolioArticles);
|
portfolioArticleDTOList.forEach(this::genPortfolioArticles);
|
||||||
article.setPortfolios(portfolioArticleDTOList);
|
article.setPortfolios(portfolioArticleDTOList);
|
||||||
|
// 查询作者是否开通钱包账号
|
||||||
|
article.setCanSponsor(Objects.nonNull(bankAccountService.findBankAccountByIdUser(article.getArticleAuthorId())));
|
||||||
} else if (type.equals(articleEdit)) {
|
} else if (type.equals(articleEdit)) {
|
||||||
article.setArticleContent(articleContent.getArticleContent());
|
article.setArticleContent(articleContent.getArticleContent());
|
||||||
} else {
|
} else {
|
||||||
|
@ -43,19 +43,10 @@ public class BankAccountServiceImpl extends AbstractService<BankAccount> impleme
|
|||||||
String defaultAccountType = "0";
|
String defaultAccountType = "0";
|
||||||
bankAccount.setAccountType(defaultAccountType);
|
bankAccount.setAccountType(defaultAccountType);
|
||||||
List<BankAccount> bankAccounts = bankAccountMapper.select(bankAccount);
|
List<BankAccount> bankAccounts = bankAccountMapper.select(bankAccount);
|
||||||
BankAccountDTO bankAccountDTO;
|
|
||||||
if (Objects.nonNull(bankAccounts) && bankAccounts.size() > 0) {
|
if (Objects.nonNull(bankAccounts) && bankAccounts.size() > 0) {
|
||||||
bankAccountDTO = bankAccountMapper.selectBankAccount(bankAccounts.get(0).getIdBankAccount());
|
return 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 bankAccountDTO;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -69,6 +60,19 @@ public class BankAccountServiceImpl extends AbstractService<BankAccount> impleme
|
|||||||
return transactionRecordService.findTransactionRecords(bankAccount, startDate, endDate);
|
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
|
@Override
|
||||||
public BankAccountDTO findByBankAccount(String bankAccount) {
|
public BankAccountDTO findByBankAccount(String bankAccount) {
|
||||||
return bankAccountMapper.selectByBankAccount(bankAccount);
|
return bankAccountMapper.selectByBankAccount(bankAccount);
|
||||||
|
@ -47,7 +47,7 @@ public class SponsorServiceImpl extends AbstractService<Sponsor> implements Spon
|
|||||||
ArticleDTO articleDTO = articleService.findArticleDTOById(sponsor.getDataId(), 1);
|
ArticleDTO articleDTO = articleService.findArticleDTOById(sponsor.getDataId(), 1);
|
||||||
TransactionRecord transactionRecord = transactionRecordService.userTransfer(articleDTO.getArticleAuthorId(), sponsor.getSponsor(), transactionEnum);
|
TransactionRecord transactionRecord = transactionRecordService.userTransfer(articleDTO.getArticleAuthorId(), sponsor.getSponsor(), transactionEnum);
|
||||||
if (Objects.isNull(transactionRecord.getIdTransactionRecord())) {
|
if (Objects.isNull(transactionRecord.getIdTransactionRecord())) {
|
||||||
throw new TransactionException(TransactionCode.InsufficientBalance);
|
throw new TransactionException(TransactionCode.INSUFFICIENT_BALANCE);
|
||||||
}
|
}
|
||||||
// 更新文章赞赏数
|
// 更新文章赞赏数
|
||||||
int result = sponsorMapper.updateArticleSponsorCount(articleDTO.getIdArticle());
|
int result = sponsorMapper.updateArticleSponsorCount(articleDTO.getIdArticle());
|
||||||
|
@ -49,7 +49,7 @@ public class TransactionRecordServiceImpl extends AbstractService<TransactionRec
|
|||||||
transactionRecordMapper.insertSelective(transactionRecord);
|
transactionRecordMapper.insertSelective(transactionRecord);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new TransactionException(TransactionCode.InsufficientBalance);
|
throw new TransactionException(TransactionCode.INSUFFICIENT_BALANCE);
|
||||||
}
|
}
|
||||||
return transactionRecord;
|
return transactionRecord;
|
||||||
}
|
}
|
||||||
@ -73,6 +73,9 @@ public class TransactionRecordServiceImpl extends AbstractService<TransactionRec
|
|||||||
public TransactionRecord userTransfer(Long toUserId, Long formUserId, TransactionEnum transactionType) {
|
public TransactionRecord userTransfer(Long toUserId, Long formUserId, TransactionEnum transactionType) {
|
||||||
BankAccountDTO toBankAccount = bankAccountMapper.findPersonBankAccountByIdUser(toUserId);
|
BankAccountDTO toBankAccount = bankAccountMapper.findPersonBankAccountByIdUser(toUserId);
|
||||||
BankAccountDTO formBankAccount = bankAccountMapper.findPersonBankAccountByIdUser(formUserId);
|
BankAccountDTO formBankAccount = bankAccountMapper.findPersonBankAccountByIdUser(formUserId);
|
||||||
|
if (Objects.isNull(toBankAccount) || Objects.isNull(formBankAccount)) {
|
||||||
|
throw new TransactionException(TransactionCode.UNKNOWN_ACCOUNT);
|
||||||
|
}
|
||||||
TransactionRecord transactionRecord = new TransactionRecord();
|
TransactionRecord transactionRecord = new TransactionRecord();
|
||||||
transactionRecord.setToBankAccount(toBankAccount.getBankAccount());
|
transactionRecord.setToBankAccount(toBankAccount.getBankAccount());
|
||||||
transactionRecord.setFormBankAccount(formBankAccount.getBankAccount());
|
transactionRecord.setFormBankAccount(formBankAccount.getBankAccount());
|
||||||
@ -84,6 +87,9 @@ public class TransactionRecordServiceImpl extends AbstractService<TransactionRec
|
|||||||
@Override
|
@Override
|
||||||
public TransactionRecord bankTransfer(Long idUser, TransactionEnum transactionType) {
|
public TransactionRecord bankTransfer(Long idUser, TransactionEnum transactionType) {
|
||||||
BankAccountDTO toBankAccount = bankAccountMapper.findPersonBankAccountByIdUser(idUser);
|
BankAccountDTO toBankAccount = bankAccountMapper.findPersonBankAccountByIdUser(idUser);
|
||||||
|
if (Objects.isNull(toBankAccount)) {
|
||||||
|
throw new TransactionException(TransactionCode.UNKNOWN_ACCOUNT);
|
||||||
|
}
|
||||||
Boolean isTrue;
|
Boolean isTrue;
|
||||||
// 校验货币规则
|
// 校验货币规则
|
||||||
switch (transactionType) {
|
switch (transactionType) {
|
||||||
@ -156,9 +162,7 @@ public class TransactionRecordServiceImpl extends AbstractService<TransactionRec
|
|||||||
private boolean checkFormAccountStatus(String formBankAccount, BigDecimal money) {
|
private boolean checkFormAccountStatus(String formBankAccount, BigDecimal money) {
|
||||||
BankAccount bankAccount = findInfoByBankAccount(formBankAccount);
|
BankAccount bankAccount = findInfoByBankAccount(formBankAccount);
|
||||||
if (Objects.nonNull(bankAccount)) {
|
if (Objects.nonNull(bankAccount)) {
|
||||||
if (bankAccount.getAccountBalance().compareTo(money) > 0) {
|
return bankAccount.getAccountBalance().compareTo(money) > 0;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,10 @@ import com.alibaba.fastjson2.JSONObject;
|
|||||||
import com.rymcu.forest.auth.TokenManager;
|
import com.rymcu.forest.auth.TokenManager;
|
||||||
import com.rymcu.forest.core.result.GlobalResult;
|
import com.rymcu.forest.core.result.GlobalResult;
|
||||||
import com.rymcu.forest.core.result.GlobalResultGenerator;
|
import com.rymcu.forest.core.result.GlobalResultGenerator;
|
||||||
|
import com.rymcu.forest.dto.BankAccountDTO;
|
||||||
import com.rymcu.forest.dto.TokenUser;
|
import com.rymcu.forest.dto.TokenUser;
|
||||||
import com.rymcu.forest.entity.User;
|
import com.rymcu.forest.entity.User;
|
||||||
|
import com.rymcu.forest.service.BankAccountService;
|
||||||
import com.rymcu.forest.service.UserService;
|
import com.rymcu.forest.service.UserService;
|
||||||
import com.rymcu.forest.util.BeanCopierUtil;
|
import com.rymcu.forest.util.BeanCopierUtil;
|
||||||
import com.rymcu.forest.util.UserUtils;
|
import com.rymcu.forest.util.UserUtils;
|
||||||
@ -25,6 +27,8 @@ public class AuthController {
|
|||||||
private UserService userService;
|
private UserService userService;
|
||||||
@Resource
|
@Resource
|
||||||
TokenManager tokenManager;
|
TokenManager tokenManager;
|
||||||
|
@Resource
|
||||||
|
private BankAccountService bankAccountService;
|
||||||
|
|
||||||
@PostMapping("/login")
|
@PostMapping("/login")
|
||||||
public GlobalResult<TokenUser> login(@RequestBody User user) {
|
public GlobalResult<TokenUser> login(@RequestBody User user) {
|
||||||
@ -53,6 +57,10 @@ public class AuthController {
|
|||||||
TokenUser tokenUser = new TokenUser();
|
TokenUser tokenUser = new TokenUser();
|
||||||
BeanCopierUtil.copy(user, tokenUser);
|
BeanCopierUtil.copy(user, tokenUser);
|
||||||
tokenUser.setScope(userService.findUserPermissions(user));
|
tokenUser.setScope(userService.findUserPermissions(user));
|
||||||
|
BankAccountDTO bankAccountDTO = bankAccountService.findBankAccountByIdUser(user.getIdUser());
|
||||||
|
if (Objects.nonNull(bankAccountDTO)) {
|
||||||
|
tokenUser.setBankAccount(bankAccountDTO.getBankAccount());
|
||||||
|
}
|
||||||
JSONObject object = new JSONObject();
|
JSONObject object = new JSONObject();
|
||||||
object.put("user", tokenUser);
|
object.put("user", tokenUser);
|
||||||
return GlobalResultGenerator.genSuccessResult(object);
|
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.core.result.GlobalResultGenerator;
|
||||||
import com.rymcu.forest.dto.BankAccountDTO;
|
import com.rymcu.forest.dto.BankAccountDTO;
|
||||||
import com.rymcu.forest.dto.TransactionRecordDTO;
|
import com.rymcu.forest.dto.TransactionRecordDTO;
|
||||||
|
import com.rymcu.forest.entity.BankAccount;
|
||||||
import com.rymcu.forest.entity.User;
|
import com.rymcu.forest.entity.User;
|
||||||
import com.rymcu.forest.service.BankAccountService;
|
import com.rymcu.forest.service.BankAccountService;
|
||||||
import com.rymcu.forest.util.UserUtils;
|
import com.rymcu.forest.util.UserUtils;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
@ -54,4 +52,10 @@ public class WalletController {
|
|||||||
PageInfo<TransactionRecordDTO> pageInfo = new PageInfo(list);
|
PageInfo<TransactionRecordDTO> pageInfo = new PageInfo(list);
|
||||||
return GlobalResultGenerator.genSuccessResult(pageInfo);
|
return GlobalResultGenerator.genSuccessResult(pageInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/create")
|
||||||
|
public GlobalResult<BankAccount> create() {
|
||||||
|
User user = UserUtils.getCurrentUserByToken();
|
||||||
|
return GlobalResultGenerator.genSuccessResult(bankAccountService.createBankAccount(user.getIdUser()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,6 +68,9 @@ create table forest_bank_account
|
|||||||
account_type char default '0' null comment '0: 普通账户 1: 银行账户'
|
account_type char default '0' null comment '0: 普通账户 1: 银行账户'
|
||||||
) comment '银行账户表 ' collate = utf8mb4_unicode_ci;
|
) comment '银行账户表 ' collate = utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
create unique index forest_bank_account_pk
|
||||||
|
on forest_bank_account (account_owner, bank_account);
|
||||||
|
|
||||||
create table forest_comment
|
create table forest_comment
|
||||||
(
|
(
|
||||||
id bigint auto_increment comment '主键'
|
id bigint auto_increment comment '主键'
|
||||||
@ -578,3 +581,10 @@ Nebula-Pi 开发板平台
|
|||||||
</table>
|
</table>
|
||||||
<p>表 1-1 主板元器件说明</p>
|
<p>表 1-1 主板元器件说明</p>
|
||||||
', '2022-06-13 22:35:34', '2022-06-13 22:35:34');
|
', '2022-06-13 22:35:34', '2022-06-13 22:35:34');
|
||||||
|
|
||||||
|
INSERT INTO forest.forest_bank (id, bank_name, bank_owner, bank_description, created_by, created_time) VALUES (1, '社区中央银行', 1, '社区中央银行', 1, '2020-11-26 21:24:19');
|
||||||
|
INSERT INTO forest.forest_bank (id, bank_name, bank_owner, bank_description, created_by, created_time) VALUES (2, '社区发展与改革银行', 1, '社区发展与改革银行', 1, '2020-11-26 21:31:27');
|
||||||
|
|
||||||
|
|
||||||
|
INSERT INTO forest.forest_bank_account (id, id_bank, bank_account, account_balance, account_owner, created_time, account_type) VALUES (2, 1, '100000002', 1207980.00000000, 2, '2020-11-26 21:37:18', '1');
|
||||||
|
INSERT INTO forest.forest_bank_account (id, id_bank, bank_account, account_balance, account_owner, created_time, account_type) VALUES (1, 1, '100000001', 997500000.00000000, 1, '2020-11-26 21:36:21', '1');
|
||||||
|
Loading…
Reference in New Issue
Block a user