|
@@ -3,6 +3,7 @@ package com.fjhx.account.service.account.impl;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
@@ -168,30 +169,36 @@ public class AccountRunningWaterServiceImpl extends ServiceImpl<AccountRunningWa
|
|
* 账户资金流水表新增
|
|
* 账户资金流水表新增
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- @Transactional(rollbackFor = {Exception.class})
|
|
|
|
|
|
+ @DSTransactional
|
|
public void add(AccountRunningWaterDto dto) {
|
|
public void add(AccountRunningWaterDto dto) {
|
|
|
|
|
|
// 修改账户余额表的余额
|
|
// 修改账户余额表的余额
|
|
- AccountRemainder accountRemainder = accountRemainderService.getOne(Wrappers.<AccountRemainder>lambdaQuery()
|
|
|
|
|
|
+ AccountRemainder accountRemainder = accountRemainderService.getOne(q -> q
|
|
.eq(AccountRemainder::getAccountManagementId, dto.getAccountManagementId())
|
|
.eq(AccountRemainder::getAccountManagementId, dto.getAccountManagementId())
|
|
.eq(AccountRemainder::getCurrency, dto.getCurrency())
|
|
.eq(AccountRemainder::getCurrency, dto.getCurrency())
|
|
);
|
|
);
|
|
|
|
+
|
|
if (ObjectUtil.isEmpty(accountRemainder)) {
|
|
if (ObjectUtil.isEmpty(accountRemainder)) {
|
|
throw new ServiceException("该账户不存在此币种,请前往资金账户添加");
|
|
throw new ServiceException("该账户不存在此币种,请前往资金账户添加");
|
|
}
|
|
}
|
|
- accountRemainder.setStatus(dto.getStatus());
|
|
|
|
- // 修改变更余额
|
|
|
|
- accountRemainder.setChangeRemainder(dto.getAmount());
|
|
|
|
- if (dto.getStatus().equals("10")) {
|
|
|
|
- accountRemainder.setRemainder(accountRemainder.getRemainder().add(dto.getAmount()));
|
|
|
|
- } else if (dto.getStatus().equals("20")) {
|
|
|
|
- if (accountRemainder.getRemainder().compareTo(dto.getAmount()) < 0) {
|
|
|
|
|
|
+
|
|
|
|
+ BigDecimal amount = dto.getAmount();
|
|
|
|
+ String status = dto.getStatus();
|
|
|
|
+ BigDecimal remainder = accountRemainder.getRemainder();
|
|
|
|
+
|
|
|
|
+ accountRemainder.setStatus(status);
|
|
|
|
+ accountRemainder.setChangeRemainder(amount);
|
|
|
|
+
|
|
|
|
+ if (status.equals("10")) {
|
|
|
|
+ accountRemainder.setRemainder(remainder.add(amount));
|
|
|
|
+ } else if (status.equals("20")) {
|
|
|
|
+ if (remainder.compareTo(amount) < 0) {
|
|
throw new ServiceException("账户余额不足");
|
|
throw new ServiceException("账户余额不足");
|
|
- } else {
|
|
|
|
- accountRemainder.setRemainder(accountRemainder.getRemainder().subtract(dto.getAmount()));
|
|
|
|
}
|
|
}
|
|
|
|
+ accountRemainder.setRemainder(remainder.subtract(amount));
|
|
}
|
|
}
|
|
accountRemainderService.updateById(accountRemainder);
|
|
accountRemainderService.updateById(accountRemainder);
|
|
|
|
+
|
|
this.save(dto);
|
|
this.save(dto);
|
|
|
|
|
|
// 发送消息推送
|
|
// 发送消息推送
|