🐛 循环引用问题修复

This commit is contained in:
ronger 2022-08-24 15:12:04 +08:00
parent 97375a3dbd
commit db8625005d
7 changed files with 101 additions and 22 deletions

View 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) {
}
}

View File

@ -1,12 +1,12 @@
package com.rymcu.forest.handler; package com.rymcu.forest.handler;
import com.alibaba.fastjson.JSON;
import com.rymcu.forest.core.constant.NotificationConstant; import com.rymcu.forest.core.constant.NotificationConstant;
import com.rymcu.forest.entity.Comment; import com.rymcu.forest.entity.Comment;
import com.rymcu.forest.handler.event.CommentEvent; import com.rymcu.forest.handler.event.CommentEvent;
import com.rymcu.forest.mapper.CommentMapper; import com.rymcu.forest.mapper.CommentMapper;
import com.rymcu.forest.util.Html2TextUtil; import com.rymcu.forest.util.Html2TextUtil;
import com.rymcu.forest.util.NotificationUtils; import com.rymcu.forest.util.NotificationUtils;
import com.rymcu.forest.wx.mp.utils.JsonUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener; import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
@ -32,7 +32,7 @@ public class CommentHandler {
@Async @Async
@EventListener @EventListener
public void processCommentCreatedEvent(CommentEvent commentEvent) throws InterruptedException { 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(); String commentContent = commentEvent.getContent();
Integer length = commentContent.length(); Integer length = commentContent.length();
if (length > MAX_PREVIEW) { if (length > MAX_PREVIEW) {

View File

@ -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;
}

View File

@ -1,13 +1,14 @@
package com.rymcu.forest.jwt.service; 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.def.JwtConstants;
import com.rymcu.forest.jwt.model.TokenModel; import com.rymcu.forest.jwt.model.TokenModel;
import com.rymcu.forest.service.UserService;
import io.jsonwebtoken.Jwts; import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm; import io.jsonwebtoken.SignatureAlgorithm;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -27,7 +28,7 @@ public class RedisTokenManager implements TokenManager {
@Autowired @Autowired
private StringRedisTemplate redisTemplate; private StringRedisTemplate redisTemplate;
@Resource @Resource
private UserService userService; private ApplicationEventPublisher applicationEventPublisher;
/** /**
* 生成TOKEN * 生成TOKEN
@ -62,7 +63,7 @@ public class RedisTokenManager implements TokenManager {
String result = redisTemplate.boundValueOps(key.toString()).get(); String result = redisTemplate.boundValueOps(key.toString()).get();
if (StringUtils.isBlank(result)) { 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); redisTemplate.boundValueOps(key.toString()).set(LocalDateTime.now().toString(), JwtConstants.LAST_ONLINE_EXPIRES_MINUTE, TimeUnit.MINUTES);
} }
return true; return true;

View File

@ -39,4 +39,11 @@ public interface BankAccountMapper extends Mapper<BankAccount> {
* @return * @return
*/ */
BankAccountDTO selectByBankAccount(@Param("bankAccount") String bankAccount); BankAccountDTO selectByBankAccount(@Param("bankAccount") String bankAccount);
/**
* 查询用户个人银行账户信息
* @param idUser
* @return
*/
BankAccountDTO findPersonBankAccountByIdUser(@Param("idUser") Long idUser);
} }

View File

@ -9,10 +9,11 @@ import com.rymcu.forest.entity.BankAccount;
import com.rymcu.forest.entity.TransactionRecord; import com.rymcu.forest.entity.TransactionRecord;
import com.rymcu.forest.enumerate.TransactionCode; import com.rymcu.forest.enumerate.TransactionCode;
import com.rymcu.forest.enumerate.TransactionEnum; import com.rymcu.forest.enumerate.TransactionEnum;
import com.rymcu.forest.mapper.BankAccountMapper;
import com.rymcu.forest.mapper.TransactionRecordMapper; import com.rymcu.forest.mapper.TransactionRecordMapper;
import com.rymcu.forest.service.BankAccountService;
import com.rymcu.forest.service.TransactionRecordService; import com.rymcu.forest.service.TransactionRecordService;
import com.rymcu.forest.util.DateUtil; import com.rymcu.forest.util.DateUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -32,7 +33,7 @@ public class TransactionRecordServiceImpl extends AbstractService<TransactionRec
@Resource @Resource
private TransactionRecordMapper transactionRecordMapper; private TransactionRecordMapper transactionRecordMapper;
@Resource @Resource
private BankAccountService bankAccountService; private BankAccountMapper bankAccountMapper;
@Resource @Resource
private RedisService redisService; private RedisService redisService;
@ -62,8 +63,8 @@ public class TransactionRecordServiceImpl extends AbstractService<TransactionRec
} }
private TransactionRecordDTO genTransactionRecord(TransactionRecordDTO transactionRecordDTO) { private TransactionRecordDTO genTransactionRecord(TransactionRecordDTO transactionRecordDTO) {
BankAccountDTO toBankAccount = bankAccountService.findByBankAccount(transactionRecordDTO.getToBankAccount()); BankAccountDTO toBankAccount = bankAccountMapper.selectByBankAccount(transactionRecordDTO.getToBankAccount());
BankAccountDTO formBankAccount = bankAccountService.findByBankAccount(transactionRecordDTO.getFormBankAccount()); BankAccountDTO formBankAccount = bankAccountMapper.selectByBankAccount(transactionRecordDTO.getFormBankAccount());
transactionRecordDTO.setFormBankAccountInfo(formBankAccount); transactionRecordDTO.setFormBankAccountInfo(formBankAccount);
transactionRecordDTO.setToBankAccountInfo(toBankAccount); transactionRecordDTO.setToBankAccountInfo(toBankAccount);
return transactionRecordDTO; return transactionRecordDTO;
@ -71,8 +72,8 @@ public class TransactionRecordServiceImpl extends AbstractService<TransactionRec
@Override @Override
public TransactionRecord userTransfer(Long toUserId, Long formUserId, TransactionEnum transactionType) throws Exception { public TransactionRecord userTransfer(Long toUserId, Long formUserId, TransactionEnum transactionType) throws Exception {
BankAccountDTO toBankAccount = bankAccountService.findBankAccountByIdUser(toUserId); BankAccountDTO toBankAccount = bankAccountMapper.findPersonBankAccountByIdUser(toUserId);
BankAccountDTO formBankAccount = bankAccountService.findBankAccountByIdUser(formUserId); BankAccountDTO formBankAccount = bankAccountMapper.findPersonBankAccountByIdUser(formUserId);
TransactionRecord transactionRecord = new TransactionRecord(); TransactionRecord transactionRecord = new TransactionRecord();
transactionRecord.setToBankAccount(toBankAccount.getBankAccount()); transactionRecord.setToBankAccount(toBankAccount.getBankAccount());
transactionRecord.setFormBankAccount(formBankAccount.getBankAccount()); transactionRecord.setFormBankAccount(formBankAccount.getBankAccount());
@ -83,7 +84,7 @@ public class TransactionRecordServiceImpl extends AbstractService<TransactionRec
@Override @Override
public TransactionRecord bankTransfer(Long idUser, TransactionEnum transactionType) throws Exception { public TransactionRecord bankTransfer(Long idUser, TransactionEnum transactionType) throws Exception {
BankAccountDTO toBankAccount = bankAccountService.findBankAccountByIdUser(idUser); BankAccountDTO toBankAccount = bankAccountMapper.findPersonBankAccountByIdUser(idUser);
Boolean isTrue; Boolean isTrue;
// 校验货币规则 // 校验货币规则
switch (transactionType) { switch (transactionType) {
@ -95,7 +96,7 @@ public class TransactionRecordServiceImpl extends AbstractService<TransactionRec
isTrue = true; isTrue = true;
} }
if (isTrue) { if (isTrue) {
BankAccount formBankAccount = bankAccountService.findSystemBankAccount(); BankAccount formBankAccount = findSystemBankAccount();
TransactionRecord transactionRecord = new TransactionRecord(); TransactionRecord transactionRecord = new TransactionRecord();
transactionRecord.setToBankAccount(toBankAccount.getBankAccount()); transactionRecord.setToBankAccount(toBankAccount.getBankAccount());
transactionRecord.setFormBankAccount(formBankAccount.getBankAccount()); transactionRecord.setFormBankAccount(formBankAccount.getBankAccount());
@ -106,6 +107,14 @@ public class TransactionRecordServiceImpl extends AbstractService<TransactionRec
return null; return null;
} }
private BankAccount findSystemBankAccount() {
BankAccount bankAccount = new BankAccount();
bankAccount.setIdBank(1L);
bankAccount.setAccountType("1");
bankAccount.setAccountOwner(2L);
return bankAccountMapper.selectOne(bankAccount);
}
@Override @Override
public TransactionRecord newbieRewards(TransactionRecord transactionRecord) throws Exception { public TransactionRecord newbieRewards(TransactionRecord transactionRecord) throws Exception {
// 判断是否重复发放 // 判断是否重复发放
@ -113,7 +122,7 @@ public class TransactionRecordServiceImpl extends AbstractService<TransactionRec
if (result) { if (result) {
return transactionRecord; return transactionRecord;
} }
BankAccount formBankAccount = bankAccountService.findSystemBankAccount(); BankAccount formBankAccount = findSystemBankAccount();
transactionRecord.setFormBankAccount(formBankAccount.getBankAccount()); transactionRecord.setFormBankAccount(formBankAccount.getBankAccount());
transactionRecord.setMoney(new BigDecimal(TransactionEnum.NewbieRewards.getMoney())); transactionRecord.setMoney(new BigDecimal(TransactionEnum.NewbieRewards.getMoney()));
transactionRecord.setFunds(TransactionEnum.NewbieRewards.getDescription()); transactionRecord.setFunds(TransactionEnum.NewbieRewards.getDescription());
@ -146,7 +155,7 @@ public class TransactionRecordServiceImpl extends AbstractService<TransactionRec
} }
private boolean checkFormAccountStatus(String formBankAccount, BigDecimal money) { private boolean checkFormAccountStatus(String formBankAccount, BigDecimal money) {
BankAccount bankAccount = bankAccountService.findInfoByBankAccount(formBankAccount); BankAccount bankAccount = findInfoByBankAccount(formBankAccount);
if (Objects.nonNull(bankAccount)) { if (Objects.nonNull(bankAccount)) {
if (bankAccount.getAccountBalance().compareTo(money) > 0) { if (bankAccount.getAccountBalance().compareTo(money) > 0) {
return true; return true;
@ -154,4 +163,10 @@ public class TransactionRecordServiceImpl extends AbstractService<TransactionRec
} }
return false; return false;
} }
private BankAccount findInfoByBankAccount(String bankAccount) {
BankAccount searchBankAccount = new BankAccount();
searchBankAccount.setBankAccount(bankAccount);
return bankAccountMapper.selectOne(searchBankAccount);
}
} }

View File

@ -26,16 +26,27 @@
</if> </if>
</select> </select>
<select id="selectBankAccount" resultMap="DTOResultMap"> <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_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>
<select id="selectMaxBankAccount" resultType="java.lang.String"> <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>
<select id="selectByBankAccount" resultMap="DTOResultMap"> <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 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> </select>
</mapper> </mapper>