|
@@ -2,7 +2,6 @@ package com.fjhx.account.service.account.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
-import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
@@ -28,7 +27,6 @@ import com.fjhx.common.service.corporation.CorporationService;
|
|
|
import com.fjhx.common.utils.Assert;
|
|
|
import com.fjhx.common.utils.ExchangeRateUtil;
|
|
|
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;
|
|
@@ -37,7 +35,6 @@ import com.ruoyi.common.exception.ServiceException;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.math.BigDecimal;
|
|
@@ -264,63 +261,14 @@ public class AccountRunningWaterServiceImpl extends ServiceImpl<AccountRunningWa
|
|
|
|
|
|
|
|
|
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 ServiceException("历史数据 该账户不存在此币种,请前往资金账户添加");
|
|
|
- }
|
|
|
- boolean update = false;
|
|
|
- if ("10".equals(oldAccountRunningWater.getStatus())) {
|
|
|
- BigDecimal subtract = accountRemainder.getRemainder().subtract(oldAccountRunningWater.getAmount());
|
|
|
- if (subtract.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
- throw new 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, "余额回滚操作失败");
|
|
|
+
|
|
|
+ String status = "10".equals(oldAccountRunningWater.getStatus()) ? "20" : "10";
|
|
|
+ oldAccountRunningWater.setStatus(status);
|
|
|
+
|
|
|
+ changeRemainder(oldAccountRunningWater);
|
|
|
+
|
|
|
|
|
|
-
|
|
|
- AccountRemainder accountRemainder1 = accountRemainderService.getOne(q -> q
|
|
|
- .eq(AccountRemainder::getAccountManagementId, accountRunningWaterDto.getAccountManagementId())
|
|
|
- .eq(AccountRemainder::getCurrency, accountRunningWaterDto.getCurrency())
|
|
|
- );
|
|
|
- if (ObjectUtil.isEmpty(accountRemainder)) {
|
|
|
- throw new 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 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, "余额修改操作失败");
|
|
|
+ changeRemainder(accountRunningWaterDto);
|
|
|
|
|
|
this.updateById(accountRunningWaterDto);
|
|
|
}
|
|
@@ -331,43 +279,12 @@ public class AccountRunningWaterServiceImpl extends ServiceImpl<AccountRunningWa
|
|
|
AccountRunningWater accountRunningWater = getById(id);
|
|
|
Assert.notEmpty(accountRunningWater, "获取不到该流水信息");
|
|
|
|
|
|
+
|
|
|
+ String status = "10".equals(accountRunningWater.getStatus()) ? "20" : "10";
|
|
|
+ accountRunningWater.setStatus(status);
|
|
|
|
|
|
-
|
|
|
- AccountRemainder accountRemainder = accountRemainderService.getOne(q -> q
|
|
|
- .eq(AccountRemainder::getAccountManagementId, accountRunningWater.getAccountManagementId())
|
|
|
- .eq(AccountRemainder::getCurrency, accountRunningWater.getCurrency())
|
|
|
- );
|
|
|
- if (ObjectUtil.isEmpty(accountRemainder)) {
|
|
|
- throw new 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 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, "余额操作失败操作失败");
|
|
|
+
|
|
|
+ changeRemainder(accountRunningWater);
|
|
|
|
|
|
this.removeById(id);
|
|
|
}
|
|
@@ -468,4 +385,95 @@ public class AccountRunningWaterServiceImpl extends ServiceImpl<AccountRunningWa
|
|
|
taxRefundDetailsService.saveBatch(taxRefundDetailsList);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * 内部转账
|
|
|
+ */
|
|
|
+ @DSTransactional
|
|
|
+ @Override
|
|
|
+ public void internalTransfer(AccountRunningWaterDto dto) {
|
|
|
+
|
|
|
+ dto.setStatus("20");
|
|
|
+ dto.setType("50");
|
|
|
+
|
|
|
+ changeRemainder(dto);
|
|
|
+ this.save(dto);
|
|
|
+
|
|
|
+
|
|
|
+ if (ObjectUtil.isNotEmpty(dto.getCommissionAmount()) && dto.getCommissionAmount().compareTo(BigDecimal.ZERO) != 0) {
|
|
|
+ AccountRunningWater commissionAccountRunningWater = new AccountRunningWater();
|
|
|
+ commissionAccountRunningWater.setStatus("20");
|
|
|
+ commissionAccountRunningWater.setType("50");
|
|
|
+ commissionAccountRunningWater.setRemarks(dto.getRemarks());
|
|
|
+ commissionAccountRunningWater.setTransactionTime(dto.getTransactionTime());
|
|
|
+
|
|
|
+ commissionAccountRunningWater.setAccountManagementId(dto.getAccountManagementId());
|
|
|
+ commissionAccountRunningWater.setAmount(dto.getCommissionAmount());
|
|
|
+ Assert.notEmpty(dto.getCommissionCurrency(), "手续费币种不能为空");
|
|
|
+ commissionAccountRunningWater.setCurrency(dto.getCommissionCurrency());
|
|
|
+ commissionAccountRunningWater.setRemarks("手续费");
|
|
|
+
|
|
|
+ changeRemainder(commissionAccountRunningWater);
|
|
|
+ this.save(commissionAccountRunningWater);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ AccountRunningWater inAccountRunningWater = new AccountRunningWater();
|
|
|
+ inAccountRunningWater.setStatus("10");
|
|
|
+ inAccountRunningWater.setType("50");
|
|
|
+ inAccountRunningWater.setRemarks(dto.getRemarks());
|
|
|
+ inAccountRunningWater.setTransactionTime(dto.getTransactionTime());
|
|
|
+
|
|
|
+ inAccountRunningWater.setAccountManagementId(dto.getInAccountManagementId());
|
|
|
+ inAccountRunningWater.setAmount(dto.getInAmount());
|
|
|
+ Assert.notEmpty(dto.getInCurrency(), "收入币种不能为空");
|
|
|
+ inAccountRunningWater.setCurrency(dto.getInCurrency());
|
|
|
+
|
|
|
+ changeRemainder(inAccountRunningWater);
|
|
|
+ this.save(inAccountRunningWater);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 余额操作
|
|
|
+ */
|
|
|
+ private void changeRemainder(AccountRunningWater accountRunningWater) {
|
|
|
+
|
|
|
+ AccountRemainder accountRemainder = accountRemainderService.getOne(q -> q
|
|
|
+ .eq(AccountRemainder::getAccountManagementId, accountRunningWater.getAccountManagementId())
|
|
|
+ .eq(AccountRemainder::getCurrency, accountRunningWater.getCurrency())
|
|
|
+ );
|
|
|
+ if (ObjectUtil.isEmpty(accountRemainder)) {
|
|
|
+ throw new 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())) {
|
|
|
+
|
|
|
+ update = accountRemainderService.update(q -> q
|
|
|
+ .setSql("remainder = remainder + " + accountRunningWater.getAmount())
|
|
|
+ .setSql("change_remainder = " + accountRunningWater.getAmount())
|
|
|
+ .eq(AccountRemainder::getId, accountRemainder.getId())
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+
|
|
|
+ BigDecimal subtract = remainder.subtract(amount);
|
|
|
+ if (subtract.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
+ throw new 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())
|
|
|
+ );
|
|
|
+ }
|
|
|
+ Assert.eqTrue(update, "余额操作失败,请重试!!!");
|
|
|
+ }
|
|
|
+
|
|
|
}
|