|
@@ -17,11 +17,15 @@ 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.entity.tax.po.TaxRefundDetails;
|
|
|
+import com.fjhx.account.entity.transaction.po.Transaction;
|
|
|
+import com.fjhx.account.entity.transaction.po.TransactionDepartment;
|
|
|
import com.fjhx.account.mapper.account.AccountRunningWaterMapper;
|
|
|
import com.fjhx.account.service.account.AccountManagementService;
|
|
|
import com.fjhx.account.service.account.AccountRemainderService;
|
|
|
import com.fjhx.account.service.account.AccountRunningWaterService;
|
|
|
import com.fjhx.account.service.tax.TaxRefundDetailsService;
|
|
|
+import com.fjhx.account.service.transaction.TransactionDepartmentService;
|
|
|
+import com.fjhx.account.service.transaction.TransactionService;
|
|
|
import com.fjhx.common.constant.SourceConstant;
|
|
|
import com.fjhx.common.entity.corporation.po.Corporation;
|
|
|
import com.fjhx.common.enums.PushBusinessTypeEnum;
|
|
@@ -71,6 +75,10 @@ public class AccountRunningWaterServiceImpl extends ServiceImpl<AccountRunningWa
|
|
|
private AccountManagementService accountManagementService;
|
|
|
@Autowired
|
|
|
private TaxRefundDetailsService taxRefundDetailsService;
|
|
|
+ @Autowired
|
|
|
+ private TransactionService transactionService;
|
|
|
+ @Autowired
|
|
|
+ private TransactionDepartmentService transactionDepartmentService;
|
|
|
|
|
|
@Override
|
|
|
public Page<AccountRunningWaterVo> getPage(AccountRunningWaterSelectDto dto) {
|
|
@@ -179,6 +187,11 @@ public class AccountRunningWaterServiceImpl extends ServiceImpl<AccountRunningWa
|
|
|
if (ObjectUtil.isNotEmpty(corporation)) {
|
|
|
result.setCorporationName(corporation.getName());
|
|
|
}
|
|
|
+ //赋值往来单位名称
|
|
|
+ TransactionDepartment transactionDepartment = transactionDepartmentService.getById(result.getTransactionDeptId());
|
|
|
+ if (ObjectUtil.isNotEmpty(transactionDepartment)) {
|
|
|
+ result.setTransactionDeptName(transactionDepartment.getName());
|
|
|
+ }
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -225,6 +238,21 @@ public class AccountRunningWaterServiceImpl extends ServiceImpl<AccountRunningWa
|
|
|
|
|
|
this.save(dto);
|
|
|
|
|
|
+ //如果是往来
|
|
|
+ if (ObjectUtil.isNotEmpty(dto.getIsTransaction()) && 1 == dto.getIsTransaction()) {
|
|
|
+ //创建往来数据
|
|
|
+ Transaction transaction = new Transaction();
|
|
|
+ transaction.setDepartmentId(dto.getTransactionDeptId());
|
|
|
+ transaction.setType("10".equals(dto.getStatus()) ? 0 : 1);
|
|
|
+ transaction.setCurrency(dto.getCurrency());
|
|
|
+ transaction.setAmount(dto.getAmount());
|
|
|
+ transaction.setIsFlowingWater(1);
|
|
|
+ transaction.setAccountId(dto.getAccountManagementId());
|
|
|
+ transaction.setRemark(dto.getRemarks());
|
|
|
+ transaction.setAccountRunningWaterId(dto.getId());
|
|
|
+ transactionService.save(transaction);
|
|
|
+ }
|
|
|
+
|
|
|
// 发送消息推送
|
|
|
sendSocket(dto);
|
|
|
}
|
|
@@ -272,69 +300,40 @@ public class AccountRunningWaterServiceImpl extends ServiceImpl<AccountRunningWa
|
|
|
*/
|
|
|
@Override
|
|
|
@DSTransactional
|
|
|
- public void edit(AccountRunningWater accountRunningWaterDto) {
|
|
|
+ public void edit(AccountRunningWaterDto accountRunningWaterDto) {
|
|
|
//先回滚历史数据
|
|
|
//获取历史的流水信息信息
|
|
|
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);
|
|
|
+
|
|
|
+ //修改往来信息
|
|
|
+ if (0 == accountRunningWaterDto.getIsTransaction()) {
|
|
|
+ //如果不是往来(删除往来数据,防止原来是往来改为不是往来)
|
|
|
+ transactionService.remove(q -> q.eq(Transaction::getAccountRunningWaterId, accountRunningWaterDto.getId()));
|
|
|
+ } else {
|
|
|
+ //如果是往来(添加/修改)往来信息,防止原来不是往来修改成往来
|
|
|
+ Transaction transaction = transactionService.getOne(q -> q.eq(Transaction::getAccountRunningWaterId, accountRunningWaterDto.getId()));
|
|
|
+ transaction = ObjectUtil.isNotEmpty(transaction) ? transaction : new Transaction();
|
|
|
+
|
|
|
+ transaction.setDepartmentId(accountRunningWaterDto.getTransactionDeptId());
|
|
|
+ transaction.setType("10".equals(accountRunningWaterDto.getStatus()) ? 0 : 1);
|
|
|
+ transaction.setCurrency(accountRunningWaterDto.getCurrency());
|
|
|
+ transaction.setAmount(accountRunningWaterDto.getAmount());
|
|
|
+ transaction.setIsFlowingWater(1);
|
|
|
+ transaction.setAccountId(accountRunningWaterDto.getAccountManagementId());
|
|
|
+ transaction.setRemark(accountRunningWaterDto.getRemarks());
|
|
|
+ transaction.setAccountRunningWaterId(accountRunningWaterDto.getId());
|
|
|
+ transactionService.saveOrUpdate(transaction);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@DSTransactional
|
|
@@ -343,45 +342,19 @@ 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();
|
|
|
+ //操作余额
|
|
|
+ changeRemainder(accountRunningWater);
|
|
|
|
|
|
- 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("账户余额不足");
|
|
|
- }
|
|
|
+ this.removeById(id);
|
|
|
|
|
|
- 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())
|
|
|
- );
|
|
|
+ //删除往来
|
|
|
+ if (1 == accountRunningWater.getIsTransaction()) {
|
|
|
+ transactionService.remove(q -> q.eq(Transaction::getAccountRunningWaterId, id));
|
|
|
}
|
|
|
- Assert.eqTrue(update, "余额操作失败操作失败");
|
|
|
-
|
|
|
- this.removeById(id);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -480,4 +453,96 @@ 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);
|
|
|
+
|
|
|
+ //如果手续费不为0生成手续费
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 余额操作
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public 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, "余额操作失败,请重试!!!");
|
|
|
+ }
|
|
|
+
|
|
|
}
|