🐛 循环引用问题修复
This commit is contained in:
parent
97375a3dbd
commit
db8625005d
26
src/main/java/com/rymcu/forest/handler/AccountHandler.java
Normal file
26
src/main/java/com/rymcu/forest/handler/AccountHandler.java
Normal file
@ -0,0 +1,26 @@
|
||||
package com.rymcu.forest.handler;
|
||||
|
||||
import com.rymcu.forest.handler.event.AccountEvent;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Created on 2022/8/24 14:44.
|
||||
*
|
||||
* @author ronger
|
||||
* @email ronger-x@outlook.com
|
||||
* @packageName com.rymcu.forest.handler
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class AccountHandler {
|
||||
|
||||
@Async
|
||||
@EventListener
|
||||
public void processAccountLastLoginEvent(AccountEvent accountEvent) {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,12 +1,12 @@
|
||||
package com.rymcu.forest.handler;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.rymcu.forest.core.constant.NotificationConstant;
|
||||
import com.rymcu.forest.entity.Comment;
|
||||
import com.rymcu.forest.handler.event.CommentEvent;
|
||||
import com.rymcu.forest.mapper.CommentMapper;
|
||||
import com.rymcu.forest.util.Html2TextUtil;
|
||||
import com.rymcu.forest.util.NotificationUtils;
|
||||
import com.rymcu.forest.wx.mp.utils.JsonUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
@ -32,7 +32,7 @@ public class CommentHandler {
|
||||
@Async
|
||||
@EventListener
|
||||
public void processCommentCreatedEvent(CommentEvent commentEvent) throws InterruptedException {
|
||||
log.info(String.format("开始执行评论发布事件:[%s]", JsonUtils.toJson(commentEvent)));
|
||||
log.info(String.format("开始执行评论发布事件:[%s]", JSON.toJSONString(commentEvent)));
|
||||
String commentContent = commentEvent.getContent();
|
||||
Integer length = commentContent.length();
|
||||
if (length > MAX_PREVIEW) {
|
||||
|
@ -0,0 +1,19 @@
|
||||
package com.rymcu.forest.handler.event;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Created on 2022/8/24 14:45.
|
||||
*
|
||||
* @author ronger
|
||||
* @email ronger-x@outlook.com
|
||||
* @packageName com.rymcu.forest.handler.event
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class AccountEvent {
|
||||
|
||||
private String account;
|
||||
|
||||
}
|
@ -1,13 +1,14 @@
|
||||
package com.rymcu.forest.jwt.service;
|
||||
|
||||
|
||||
import com.rymcu.forest.handler.event.AccountEvent;
|
||||
import com.rymcu.forest.jwt.def.JwtConstants;
|
||||
import com.rymcu.forest.jwt.model.TokenModel;
|
||||
import com.rymcu.forest.service.UserService;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.SignatureAlgorithm;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -27,7 +28,7 @@ public class RedisTokenManager implements TokenManager {
|
||||
@Autowired
|
||||
private StringRedisTemplate redisTemplate;
|
||||
@Resource
|
||||
private UserService userService;
|
||||
private ApplicationEventPublisher applicationEventPublisher;
|
||||
|
||||
/**
|
||||
* 生成TOKEN
|
||||
@ -62,7 +63,7 @@ public class RedisTokenManager implements TokenManager {
|
||||
String result = redisTemplate.boundValueOps(key.toString()).get();
|
||||
if (StringUtils.isBlank(result)) {
|
||||
// 更新最后在线时间
|
||||
userService.updateLastOnlineTimeByEmail(model.getUsername());
|
||||
applicationEventPublisher.publishEvent(new AccountEvent(model.getUsername()));
|
||||
redisTemplate.boundValueOps(key.toString()).set(LocalDateTime.now().toString(), JwtConstants.LAST_ONLINE_EXPIRES_MINUTE, TimeUnit.MINUTES);
|
||||
}
|
||||
return true;
|
||||
|
@ -39,4 +39,11 @@ public interface BankAccountMapper extends Mapper<BankAccount> {
|
||||
* @return
|
||||
*/
|
||||
BankAccountDTO selectByBankAccount(@Param("bankAccount") String bankAccount);
|
||||
|
||||
/**
|
||||
* 查询用户个人银行账户信息
|
||||
* @param idUser
|
||||
* @return
|
||||
*/
|
||||
BankAccountDTO findPersonBankAccountByIdUser(@Param("idUser") Long idUser);
|
||||
}
|
||||
|
@ -9,10 +9,11 @@ import com.rymcu.forest.entity.BankAccount;
|
||||
import com.rymcu.forest.entity.TransactionRecord;
|
||||
import com.rymcu.forest.enumerate.TransactionCode;
|
||||
import com.rymcu.forest.enumerate.TransactionEnum;
|
||||
import com.rymcu.forest.mapper.BankAccountMapper;
|
||||
import com.rymcu.forest.mapper.TransactionRecordMapper;
|
||||
import com.rymcu.forest.service.BankAccountService;
|
||||
import com.rymcu.forest.service.TransactionRecordService;
|
||||
import com.rymcu.forest.util.DateUtil;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@ -32,7 +33,7 @@ public class TransactionRecordServiceImpl extends AbstractService<TransactionRec
|
||||
@Resource
|
||||
private TransactionRecordMapper transactionRecordMapper;
|
||||
@Resource
|
||||
private BankAccountService bankAccountService;
|
||||
private BankAccountMapper bankAccountMapper;
|
||||
@Resource
|
||||
private RedisService redisService;
|
||||
|
||||
@ -62,8 +63,8 @@ public class TransactionRecordServiceImpl extends AbstractService<TransactionRec
|
||||
}
|
||||
|
||||
private TransactionRecordDTO genTransactionRecord(TransactionRecordDTO transactionRecordDTO) {
|
||||
BankAccountDTO toBankAccount = bankAccountService.findByBankAccount(transactionRecordDTO.getToBankAccount());
|
||||
BankAccountDTO formBankAccount = bankAccountService.findByBankAccount(transactionRecordDTO.getFormBankAccount());
|
||||
BankAccountDTO toBankAccount = bankAccountMapper.selectByBankAccount(transactionRecordDTO.getToBankAccount());
|
||||
BankAccountDTO formBankAccount = bankAccountMapper.selectByBankAccount(transactionRecordDTO.getFormBankAccount());
|
||||
transactionRecordDTO.setFormBankAccountInfo(formBankAccount);
|
||||
transactionRecordDTO.setToBankAccountInfo(toBankAccount);
|
||||
return transactionRecordDTO;
|
||||
@ -71,8 +72,8 @@ public class TransactionRecordServiceImpl extends AbstractService<TransactionRec
|
||||
|
||||
@Override
|
||||
public TransactionRecord userTransfer(Long toUserId, Long formUserId, TransactionEnum transactionType) throws Exception {
|
||||
BankAccountDTO toBankAccount = bankAccountService.findBankAccountByIdUser(toUserId);
|
||||
BankAccountDTO formBankAccount = bankAccountService.findBankAccountByIdUser(formUserId);
|
||||
BankAccountDTO toBankAccount = bankAccountMapper.findPersonBankAccountByIdUser(toUserId);
|
||||
BankAccountDTO formBankAccount = bankAccountMapper.findPersonBankAccountByIdUser(formUserId);
|
||||
TransactionRecord transactionRecord = new TransactionRecord();
|
||||
transactionRecord.setToBankAccount(toBankAccount.getBankAccount());
|
||||
transactionRecord.setFormBankAccount(formBankAccount.getBankAccount());
|
||||
@ -83,7 +84,7 @@ public class TransactionRecordServiceImpl extends AbstractService<TransactionRec
|
||||
|
||||
@Override
|
||||
public TransactionRecord bankTransfer(Long idUser, TransactionEnum transactionType) throws Exception {
|
||||
BankAccountDTO toBankAccount = bankAccountService.findBankAccountByIdUser(idUser);
|
||||
BankAccountDTO toBankAccount = bankAccountMapper.findPersonBankAccountByIdUser(idUser);
|
||||
Boolean isTrue;
|
||||
// 校验货币规则
|
||||
switch (transactionType) {
|
||||
@ -95,7 +96,7 @@ public class TransactionRecordServiceImpl extends AbstractService<TransactionRec
|
||||
isTrue = true;
|
||||
}
|
||||
if (isTrue) {
|
||||
BankAccount formBankAccount = bankAccountService.findSystemBankAccount();
|
||||
BankAccount formBankAccount = findSystemBankAccount();
|
||||
TransactionRecord transactionRecord = new TransactionRecord();
|
||||
transactionRecord.setToBankAccount(toBankAccount.getBankAccount());
|
||||
transactionRecord.setFormBankAccount(formBankAccount.getBankAccount());
|
||||
@ -106,6 +107,14 @@ public class TransactionRecordServiceImpl extends AbstractService<TransactionRec
|
||||
return null;
|
||||
}
|
||||
|
||||
private BankAccount findSystemBankAccount() {
|
||||
BankAccount bankAccount = new BankAccount();
|
||||
bankAccount.setIdBank(1L);
|
||||
bankAccount.setAccountType("1");
|
||||
bankAccount.setAccountOwner(2L);
|
||||
return bankAccountMapper.selectOne(bankAccount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransactionRecord newbieRewards(TransactionRecord transactionRecord) throws Exception {
|
||||
// 判断是否重复发放
|
||||
@ -113,7 +122,7 @@ public class TransactionRecordServiceImpl extends AbstractService<TransactionRec
|
||||
if (result) {
|
||||
return transactionRecord;
|
||||
}
|
||||
BankAccount formBankAccount = bankAccountService.findSystemBankAccount();
|
||||
BankAccount formBankAccount = findSystemBankAccount();
|
||||
transactionRecord.setFormBankAccount(formBankAccount.getBankAccount());
|
||||
transactionRecord.setMoney(new BigDecimal(TransactionEnum.NewbieRewards.getMoney()));
|
||||
transactionRecord.setFunds(TransactionEnum.NewbieRewards.getDescription());
|
||||
@ -146,7 +155,7 @@ public class TransactionRecordServiceImpl extends AbstractService<TransactionRec
|
||||
}
|
||||
|
||||
private boolean checkFormAccountStatus(String formBankAccount, BigDecimal money) {
|
||||
BankAccount bankAccount = bankAccountService.findInfoByBankAccount(formBankAccount);
|
||||
BankAccount bankAccount = findInfoByBankAccount(formBankAccount);
|
||||
if (Objects.nonNull(bankAccount)) {
|
||||
if (bankAccount.getAccountBalance().compareTo(money) > 0) {
|
||||
return true;
|
||||
@ -154,4 +163,10 @@ public class TransactionRecordServiceImpl extends AbstractService<TransactionRec
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private BankAccount findInfoByBankAccount(String bankAccount) {
|
||||
BankAccount searchBankAccount = new BankAccount();
|
||||
searchBankAccount.setBankAccount(bankAccount);
|
||||
return bankAccountMapper.selectOne(searchBankAccount);
|
||||
}
|
||||
}
|
||||
|
@ -26,16 +26,27 @@
|
||||
</if>
|
||||
</select>
|
||||
<select id="selectBankAccount" resultMap="DTOResultMap">
|
||||
select fb.bank_name, fu.nickname as account_owner_name, fba.* from forest_bank_account fba
|
||||
select fb.bank_name, fu.nickname as account_owner_name, fba.*
|
||||
from forest_bank_account fba
|
||||
join forest_bank fb on fba.id_bank = fb.id
|
||||
join forest_user fu on fba.account_owner = fu.id where fba.id = #{idBank}
|
||||
join forest_user fu on fba.account_owner = fu.id
|
||||
where fba.id = #{idBank}
|
||||
</select>
|
||||
<select id="selectMaxBankAccount" resultType="java.lang.String">
|
||||
select max(bank_account) as max_bank_account from forest_bank_account where account_type = 0
|
||||
select max(bank_account) as max_bank_account
|
||||
from forest_bank_account
|
||||
where account_type = 0
|
||||
</select>
|
||||
<select id="selectByBankAccount" resultMap="DTOResultMap">
|
||||
select fb.bank_name, ifnull(fu.nickname, '系统') as account_owner_name, fba.bank_account from forest_bank_account fba
|
||||
select fb.bank_name, ifnull(fu.nickname, '系统') as account_owner_name, fba.bank_account
|
||||
from forest_bank_account fba
|
||||
join forest_bank fb on fba.id_bank = fb.id
|
||||
left join forest_user fu on fba.account_owner = fu.id where fba.bank_account = #{bankAccount}
|
||||
left join forest_user fu on fba.account_owner = fu.id
|
||||
where fba.bank_account = #{bankAccount}
|
||||
</select>
|
||||
<select id="findPersonBankAccountByIdUser" resultMap="DTOResultMap">
|
||||
select fba.*
|
||||
from forest_bank_account fba
|
||||
where fba.account_owner = #{idUser}
|
||||
</select>
|
||||
</mapper>
|
Loading…
Reference in New Issue
Block a user