提交 bb83a418 authored 作者: huyufan's avatar huyufan

冻结资金相关

上级 3ff63f73
......@@ -17,5 +17,8 @@ public interface OwnerAccountDao extends BaseDao<OwnerAccountMapper, OwnerAccoun
OwnerAccount getAccountByOwnerUserNoAndAccountType(Long ownerUserNo, Integer accountType);
int updateAccount(OwnerAccount account, LocalDateTime now);
int updateOwnerAccountForConfirm(OwnerAccount account);
int updateAccountCAS(OwnerAccount account, LocalDateTime now, boolean flag);
}
......@@ -37,14 +37,19 @@ public class OwnerAccountDaoImpl extends BaseDaoImpl<OwnerAccountMapper, OwnerAc
return baseMapper.selectOne(lQrWrapper().eq(OwnerAccount::getAccountType, accountType).eq(OwnerAccount::getOwnerUserNo, ownerUserNo));
}
@Override
public int updateAccount(OwnerAccount account, LocalDateTime now) {
return baseMapper.updateAccount(account, now);
// if (flag) {
// baseMapper.addAccount(account, now);
// } else {
// baseMapper.subAccount(account, now);
// }
public int updateOwnerAccountForConfirm(OwnerAccount account) {
return baseMapper.updateOwnerAccountForConfirm(account);
}
@Override
public int updateAccountCAS(OwnerAccount account, LocalDateTime now, boolean flag) {
if (flag) {
return baseMapper.addAccount(account, now);
} else {
return baseMapper.subAccount(account, now);
}
}
......
......@@ -22,9 +22,12 @@ public interface OwnerAccountMapper extends BaseMapper<OwnerAccount> {
@SelectProvider(type = OwnerAccountSqlProvider.class, method = "pageList")
IPage<OwnerAccountVO> pageList(Page<OwnerAccountVO> page, PageOwnerAccountListParam param);
@SelectProvider(type = OwnerAccountSqlProvider.class, method = "updateAccount")
int updateAccount(OwnerAccount account, LocalDateTime now);
@SelectProvider(type = OwnerAccountSqlProvider.class, method = "addAccount")
int addAccount(OwnerAccount account, LocalDateTime now);
// @SelectProvider(type = OwnerAccountSqlProvider.class, method = "subAccount")
// int subAccount(OwnerAccount account, LocalDateTime now);
@SelectProvider(type = OwnerAccountSqlProvider.class, method = "subAccount")
int subAccount(OwnerAccount account, LocalDateTime now);
@SelectProvider(type = OwnerAccountSqlProvider.class, method = "updateOwnerAccountForConfirm")
int updateOwnerAccountForConfirm(OwnerAccount account);
}
\ No newline at end of file
......@@ -140,11 +140,12 @@ public class OwnerAccountServiceImpl implements OwnerAccountService {
//冻结账户可用金额
OwnerAccount account = ownerAccountDao.getAccountByOwnerUserNoAndAccountType(param.getOwnerUserNo(), param.getAccountType());
OwnerAccount update = new OwnerAccount();
update.setUsableBalance(caseOutBalance.negate());
update.setUsableBalance(caseOutBalance);
update.setFrozenBalance(caseOutBalance);
update.setAccountBalance(caseOutBalance);
update.setModifiedTime(account.getModifiedTime());
update.setId(account.getId());
int flag = ownerAccountDao.updateAccount(update, now);
int flag = ownerAccountDao.updateAccountCAS(update, now, false);
if (flag > 0) {
break;
}
......@@ -190,7 +191,7 @@ public class OwnerAccountServiceImpl implements OwnerAccountService {
update.setFrozenBalance(caseOutBalance);
update.setModifiedTime(account.getModifiedTime());
update.setId(account.getId());
int flag = ownerAccountDao.updateAccount(update, now);
int flag = ownerAccountDao.updateAccountCAS(update, now, false);
if (flag > 0) {
break;
}
......@@ -250,7 +251,7 @@ public class OwnerAccountServiceImpl implements OwnerAccountService {
update.setUsableBalance(topUpBalance);
update.setId(account.getId());
update.setModifiedTime(account.getModifiedTime());
int flag = ownerAccountDao.updateAccount(update, now);
int flag = ownerAccountDao.updateAccountCAS(update, now, true);
if (flag > 0) {
break;
}
......@@ -296,6 +297,8 @@ public class OwnerAccountServiceImpl implements OwnerAccountService {
@Override
public void accountBalanceConfirm(Integer id) {
UserSessionData loginUserInfo = TokenUtil.getLoginUserInfo();
Optional<OwnerCaseOut> optional = ownerCaseOutDao.getEntityByKey(id);
if (!optional.isPresent()) {
throw new ServiceSystemException(PerformanceResultEnum.HTTP_ERROR, "当前ID未查询到有效记录");
......@@ -308,19 +311,24 @@ public class OwnerAccountServiceImpl implements OwnerAccountService {
}
//给对应账户减少金额
while (true) {
OwnerAccount account = ownerAccountDao.getAccountByOwnerUserNoAndAccountType(ownerCaseOut.getOwnerUserNo(), ownerCaseOut.getAccountType());
OwnerAccount update = new OwnerAccount();
update.setAccountBalance(account.getAccountBalance().subtract(caseOutBalance));
update.setUsableBalance(account.getUsableBalance().subtract(caseOutBalance));
update.setFrozenBalance(account.getFrozenBalance().subtract(caseOutBalance));
update.setFrozenBalance(caseOutBalance);
update.setId(account.getId());
ownerAccountDao.updateEntityByKey(update);
update.setModifiedTime(account.getModifiedTime());
int flag = ownerAccountDao.updateOwnerAccountForConfirm(update);
if (flag > 0) {
break;
}
}
//插入提现成功流水
OwnerRunningWaterRecord runningWaterRecord = new OwnerRunningWaterRecord();
runningWaterRecord.setOwnerName("测试");
runningWaterRecord.setMobile("11111111111");
runningWaterRecord.setCreateBy("操作人");
runningWaterRecord.setOwnerName(loginUserInfo.getUserName());
runningWaterRecord.setMobile(loginUserInfo.getUserMobile());
runningWaterRecord.setCreateBy(loginUserInfo.getUserName());
runningWaterRecord.setRelationId(ownerCaseOut.getCaseOutNo());
runningWaterRecord.setAccountBalance(caseOutBalance);
......@@ -600,22 +608,22 @@ public class OwnerAccountServiceImpl implements OwnerAccountService {
throw new ServiceSystemException(PerformanceResultEnum.HTTP_ERROR, "当前货主保证金账户可用余额不够冻结");
}
//冻结金额
entity.setFrozenBalance(ownerAccount.getFrozenBalance().subtract(frozenBalance));
entity.setFrozenBalance(frozenBalance);
//可用余额
entity.setUsableBalance(ownerAccount.getUsableBalance().subtract(frozenBalance));
entity.setUsableBalance(frozenBalance);
//updateList.add(entity);
flag += ownerAccountDao.updateAccount(entity, now);
flag += ownerAccountDao.updateAccountCAS(entity, now, false);
} else {
if (ownerAccount.getUsableBalance().compareTo(ensureBalance) < 0) {
throw new ServiceSystemException(PerformanceResultEnum.HTTP_ERROR, "当前货主预付运费账户可用余额不够冻结");
}
//冻结金额
entity.setFrozenBalance(ownerAccount.getFrozenBalance().subtract(ensureBalance));
entity.setFrozenBalance(ensureBalance);
//可用余额
entity.setUsableBalance(ownerAccount.getUsableBalance().subtract(ensureBalance));
entity.setUsableBalance(ensureBalance);
//updateList.add(entity);
flag += ownerAccountDao.updateAccount(entity, now);
flag += ownerAccountDao.updateAccountCAS(entity, now, false);
}
}
if (flag == 2) {
......
......@@ -37,12 +37,11 @@ public class OwnerAccountSqlProvider {
return sql;
}
public String updateAccount(OwnerAccount account, LocalDateTime now) {
public String addAccount(OwnerAccount account, LocalDateTime now) {
StringBuffer sqlList = new StringBuffer();
sqlList.append("update owner_account set usable_balance = usable_balance +" +
account.getUsableBalance() + ",frozen_balance = frozen_balance +"
+ account.getUsableBalance() + ",account_balance = account_balance +"
account.getUsableBalance() + ",account_balance = account_balance +"
+ account.getAccountBalance()+
",modified_time=" + now
+ "where id = " + account.getId() + "and modified_time = " + account.getModifiedTime()
......@@ -50,16 +49,27 @@ public class OwnerAccountSqlProvider {
return sqlList.toString();
}
//
// public String subAccount(OwnerAccount account, LocalDateTime now) {
// StringBuffer sqlList = new StringBuffer();
//
// sqlList.append("update owner_account set usable_balance = usable_balance -" +
// account.getUsableBalance() + ",frozen_balance = frozen_balance -"
// + account.getUsableBalance() + ",modified_time=" + now
// + "where id = " + account.getId() + "and modified_time = " + account.getModifyTime()
// );
//
// return sqlList.toString();
// }
public String subAccount(OwnerAccount account, LocalDateTime now) {
StringBuffer sqlList = new StringBuffer();
sqlList.append("update owner_account set usable_balance = usable_balance -" +
account.getUsableBalance() + ",frozen_balance = frozen_balance +"
+ account.getFrozenBalance() +",account_balance = account_balance -" + account.getFrozenBalance()
+ ",modified_time=" + now
+ "where id = " + account.getId() + "and modified_time = " + account.getModifiedTime()
);
return sqlList.toString();
}
public String updateOwnerAccountForConfirm(OwnerAccount account) {
StringBuffer sqlList = new StringBuffer();
sqlList.append("update owner_account set frozen_balance = frozen_balance -" +
account.getFrozenBalance()
+ "where id = " + account.getId() + "and modified_time = " + account.getModifiedTime()
);
return sqlList.toString();
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论