死锁问题

This commit is contained in:
wanggeng 2024-06-25 14:02:58 +08:00
parent cbdf804c9c
commit e00d6f413e

View File

@ -53,6 +53,8 @@ import java.util.*;
@Service @Service
public class AccountRechargeServiceImpl extends DefaultBaseService implements IAccountRechargeService { public class AccountRechargeServiceImpl extends DefaultBaseService implements IAccountRechargeService {
private final Object lock = new Object();
@Autowired @Autowired
private IAccountRechargeDao accountRechargeDao; private IAccountRechargeDao accountRechargeDao;
@ -277,6 +279,8 @@ public class AccountRechargeServiceImpl extends DefaultBaseService implements IA
@Override @Override
public AccountRechargePayDTO saveAccount(String thirdParty, AccountRechargeVO accountRechargeVO) { public AccountRechargePayDTO saveAccount(String thirdParty, AccountRechargeVO accountRechargeVO) {
AccountRechargePayDTO payDTO = new AccountRechargePayDTO();
synchronized (lock) {
String userId = StringUtils.isEmpty(accountRechargeVO.getUserId()) ? userUtil.getUserId(null) : accountRechargeVO.getUserId(); String userId = StringUtils.isEmpty(accountRechargeVO.getUserId()) ? userUtil.getUserId(null) : accountRechargeVO.getUserId();
// 查看该用户今日的记录, 超过50条不能再创建 // 查看该用户今日的记录, 超过50条不能再创建
Integer count = accountRechargeDao.getTodayByAccountId(userId); Integer count = accountRechargeDao.getTodayByAccountId(userId);
@ -291,7 +295,7 @@ public class AccountRechargeServiceImpl extends DefaultBaseService implements IA
/* if (totalMoney < 10 || totalMoney > 200000) { // 最大2000块,最小1毛 /* if (totalMoney < 10 || totalMoney > 200000) { // 最大2000块,最小1毛
throw new SaveException("金额输入错误"); throw new SaveException("金额输入错误");
}*/ }*/
AccountRechargePayDTO payDTO = new AccountRechargePayDTO();
Map<String, Object> params = HashMapUtil.beanToMap(accountRechargeVO); Map<String, Object> params = HashMapUtil.beanToMap(accountRechargeVO);
if ("微信".equals(thirdParty)) { if ("微信".equals(thirdParty)) {
@ -335,6 +339,7 @@ public class AccountRechargeServiceImpl extends DefaultBaseService implements IA
params.put("gmtModified", currentDate); params.put("gmtModified", currentDate);
params.put("isDelete", 0); params.put("isDelete", 0);
accountRechargeDao.save(params); accountRechargeDao.save(params);
}
return payDTO; return payDTO;
} }