|
@@ -1,36 +1,37 @@
|
|
|
package com.fjhx.account.service.account.impl;
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fjhx.account.entity.account.bo.AccountRunningWaterBo;
|
|
|
+import com.fjhx.account.entity.account.dto.AccountRunningWaterDto;
|
|
|
+import com.fjhx.account.entity.account.dto.AccountRunningWaterSelectDto;
|
|
|
import com.fjhx.account.entity.account.po.AccountRemainder;
|
|
|
import com.fjhx.account.entity.account.po.AccountRunningWater;
|
|
|
+import com.fjhx.account.entity.account.vo.AccountRunningWaterVo;
|
|
|
import com.fjhx.account.mapper.account.AccountRunningWaterMapper;
|
|
|
import com.fjhx.account.service.account.AccountRemainderService;
|
|
|
import com.fjhx.account.service.account.AccountRunningWaterService;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fjhx.common.constant.SourceConstant;
|
|
|
+import com.fjhx.common.utils.Assert;
|
|
|
import com.fjhx.item.util.excel.util.ExcelUtil;
|
|
|
import com.fjhx.tenant.entity.dict.dto.DictTenantDataSelectDto;
|
|
|
import com.fjhx.tenant.entity.dict.vo.DictTenantDataVo;
|
|
|
import com.fjhx.tenant.service.dict.DictTenantDataService;
|
|
|
import com.obs.services.internal.ServiceException;
|
|
|
-import com.ruoyi.common.annotation.TenantIgnore;
|
|
|
import com.ruoyi.common.core.domain.BaseSelectDto;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
-import org.apache.commons.collections4.ListUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import com.fjhx.account.entity.account.vo.AccountRunningWaterVo;
|
|
|
-import com.fjhx.account.entity.account.dto.AccountRunningWaterSelectDto;
|
|
|
-import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
-import com.fjhx.account.entity.account.dto.AccountRunningWaterDto;
|
|
|
-import cn.hutool.core.bean.BeanUtil;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -131,25 +132,116 @@ public class AccountRunningWaterServiceImpl extends ServiceImpl<AccountRunningWa
|
|
|
* 账户资金流水表编辑
|
|
|
*/
|
|
|
@Override
|
|
|
- @Transactional(rollbackFor = {Exception.class})
|
|
|
+ @DSTransactional
|
|
|
public void edit(AccountRunningWater accountRunningWaterDto) {
|
|
|
-// //查询资金流水表的数据
|
|
|
-// AccountRunningWater accountRunningWater = this.getById(accountRunningWaterDto.getId());
|
|
|
-//
|
|
|
-// //修改账户余额表的余额
|
|
|
-// AccountRemainder accountRemainder = accountRemainderService.getOne(Wrappers.<AccountRemainder>lambdaQuery()
|
|
|
-// .eq(AccountRemainder::getAccountManagementId,accountRunningWater.getAccountManagementId())
|
|
|
-// .eq(AccountRemainder::getCurrency,accountRunningWater.getCurrency())
|
|
|
-// );
|
|
|
-// if (accountRemainder.getStatus().equals("10")){
|
|
|
-// if (accountRemainder.getRemainder().compareTo(accountRunningWater.getAmount())==1)
|
|
|
-// }
|
|
|
+ //先回滚历史数据
|
|
|
+ //获取历史的流水信息信息
|
|
|
+ AccountRunningWater oldAccountRunningWater = getById(accountRunningWaterDto.getId());
|
|
|
+ //获取余额
|
|
|
+ AccountRemainder accountRemainder = accountRemainderService.getOne(q -> q
|
|
|
+ .eq(AccountRemainder::getAccountManagementId, oldAccountRunningWater.getAccountManagementId())
|
|
|
+ .eq(AccountRemainder::getCurrency, oldAccountRunningWater.getCurrency())
|
|
|
+ );
|
|
|
+ if (ObjectUtil.isEmpty(accountRemainder)) {
|
|
|
+ throw new com.ruoyi.common.exception.ServiceException("历史数据 该账户不存在此币种,请前往资金账户添加");
|
|
|
+ }
|
|
|
+ boolean update = false;
|
|
|
+ if ("10".equals(oldAccountRunningWater.getStatus())) {
|
|
|
+ BigDecimal subtract = accountRemainder.getRemainder().subtract(oldAccountRunningWater.getAmount());
|
|
|
+ if (subtract.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
+ throw new com.ruoyi.common.exception.ServiceException("修改前数据 账户余额不足");
|
|
|
+ }
|
|
|
+ update = accountRemainderService.update(q -> q
|
|
|
+ .setSql("remainder = remainder - " + oldAccountRunningWater.getAmount())
|
|
|
+ .setSql("change_remainder = " + oldAccountRunningWater.getAmount())
|
|
|
+ .eq(AccountRemainder::getId, accountRemainder.getId())
|
|
|
+ .apply("remainder - {0} >= 0", oldAccountRunningWater.getAmount())
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ update = accountRemainderService.update(q -> q
|
|
|
+ .setSql("remainder = remainder + " + oldAccountRunningWater.getAmount())
|
|
|
+ .setSql("change_remainder = " + oldAccountRunningWater.getAmount())
|
|
|
+ .eq(AccountRemainder::getId, accountRemainder.getId())
|
|
|
+ );
|
|
|
+ }
|
|
|
+ Assert.eqTrue(update, "余额回滚操作失败");
|
|
|
+ //再操作修改后数据
|
|
|
+ //获取余额
|
|
|
+ AccountRemainder accountRemainder1 = accountRemainderService.getOne(q -> q
|
|
|
+ .eq(AccountRemainder::getAccountManagementId, accountRunningWaterDto.getAccountManagementId())
|
|
|
+ .eq(AccountRemainder::getCurrency, accountRunningWaterDto.getCurrency())
|
|
|
+ );
|
|
|
+ if (ObjectUtil.isEmpty(accountRemainder)) {
|
|
|
+ throw new com.ruoyi.common.exception.ServiceException("修改后数据 该账户不存在此币种,请前往资金账户添加");
|
|
|
+ }
|
|
|
+ boolean update1 = false;
|
|
|
+ if ("10".equals(accountRunningWaterDto.getStatus())) {
|
|
|
+ update1 = accountRemainderService.update(q -> q
|
|
|
+ .setSql("remainder = remainder + " + accountRunningWaterDto.getAmount())
|
|
|
+ .setSql("change_remainder = " + accountRunningWaterDto.getAmount())
|
|
|
+ .eq(AccountRemainder::getId, accountRemainder1.getId())
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ BigDecimal subtract = accountRemainder1.getRemainder().subtract(accountRunningWaterDto.getAmount());
|
|
|
+ if (subtract.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
+ throw new com.ruoyi.common.exception.ServiceException("修改后数据 账户余额不足");
|
|
|
+ }
|
|
|
+ update1 = accountRemainderService.update(q -> q
|
|
|
+ .setSql("remainder = remainder - " + accountRunningWaterDto.getAmount())
|
|
|
+ .setSql("change_remainder = " + accountRunningWaterDto.getAmount())
|
|
|
+ .eq(AccountRemainder::getId, accountRemainder1.getId())
|
|
|
+ .apply("remainder - {0} >= 0", accountRunningWaterDto.getAmount())
|
|
|
+ );
|
|
|
+ }
|
|
|
+ Assert.eqTrue(update1, "余额修改操作失败");
|
|
|
|
|
|
this.updateById(accountRunningWaterDto);
|
|
|
}
|
|
|
|
|
|
+ @DSTransactional
|
|
|
@Override
|
|
|
public void delete(Long id) {
|
|
|
+ AccountRunningWater accountRunningWater = getById(id);
|
|
|
+ Assert.notEmpty(accountRunningWater, "获取不到该流水信息");
|
|
|
+
|
|
|
+
|
|
|
+ // 修改账户余额表的余额
|
|
|
+ AccountRemainder accountRemainder = accountRemainderService.getOne(q -> q
|
|
|
+ .eq(AccountRemainder::getAccountManagementId, accountRunningWater.getAccountManagementId())
|
|
|
+ .eq(AccountRemainder::getCurrency, accountRunningWater.getCurrency())
|
|
|
+ );
|
|
|
+ if (ObjectUtil.isEmpty(accountRemainder)) {
|
|
|
+ throw new com.ruoyi.common.exception.ServiceException("该账户不存在此币种,请前往资金账户添加");
|
|
|
+ }
|
|
|
+ BigDecimal amount = accountRunningWater.getAmount();
|
|
|
+ String status = accountRunningWater.getStatus();
|
|
|
+ BigDecimal remainder = accountRemainder.getRemainder();
|
|
|
+
|
|
|
+ accountRemainder.setStatus(status);
|
|
|
+ accountRemainder.setChangeRemainder(amount);
|
|
|
+
|
|
|
+ boolean update = false;
|
|
|
+ if ("10".equals(accountRunningWater.getStatus())) {
|
|
|
+ BigDecimal subtract = remainder.subtract(amount);
|
|
|
+ if (subtract.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
+ throw new com.ruoyi.common.exception.ServiceException("账户余额不足");
|
|
|
+ }
|
|
|
+
|
|
|
+ update = accountRemainderService.update(q -> q
|
|
|
+ .setSql("remainder = remainder - " + accountRunningWater.getAmount())
|
|
|
+ .setSql("change_remainder = " + accountRunningWater.getAmount())
|
|
|
+ .eq(AccountRemainder::getId, accountRemainder.getId())
|
|
|
+ .apply("remainder - {0} >= 0", accountRunningWater.getAmount())
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ update = accountRemainderService.update(q -> q
|
|
|
+ .setSql("remainder = remainder + " + accountRunningWater.getAmount())
|
|
|
+ .setSql("change_remainder = " + accountRunningWater.getAmount())
|
|
|
+ .eq(AccountRemainder::getId, accountRemainder.getId())
|
|
|
+ );
|
|
|
+ }
|
|
|
+ Assert.eqTrue(update, "余额操作失败操作失败");
|
|
|
+
|
|
|
this.removeById(id);
|
|
|
}
|
|
|
|