فهرست منبع

流水是否往来相关功能处理

yzc 1 سال پیش
والد
کامیت
c408ed19b8

+ 10 - 0
hx-account/src/main/java/com/fjhx/account/entity/account/po/AccountRunningWater.java

@@ -105,4 +105,14 @@ public class AccountRunningWater extends BasePo {
     @TableField(exist = false)
     private Integer count;
 
+    /**
+     * 是否往来 1是 0不是
+     */
+    private Integer isTransaction;
+
+    /**
+     * 往来单位id
+     */
+    private Long transactionDeptId;
+
 }

+ 6 - 2
hx-account/src/main/java/com/fjhx/account/entity/transaction/po/Transaction.java

@@ -5,6 +5,8 @@ import com.ruoyi.common.core.domain.BasePo;
 import lombok.Getter;
 import lombok.Setter;
 
+import java.math.BigDecimal;
+
 /**
  * <p>
  * 往来管理
@@ -36,12 +38,12 @@ public class Transaction extends BasePo {
     /**
      * 往来金额
      */
-    private String amount;
+    private BigDecimal amount;
 
     /**
      * 是否流水 1是 0否
      */
-    private String isFlowingWater;
+    private Integer isFlowingWater;
 
     /**
      * 往来账户
@@ -53,4 +55,6 @@ public class Transaction extends BasePo {
      */
     private String remark;
 
+    private Long accountRunningWaterId;
+
 }

+ 6 - 1
hx-account/src/main/java/com/fjhx/account/service/account/AccountRunningWaterService.java

@@ -45,7 +45,7 @@ public interface AccountRunningWaterService extends BaseService<AccountRunningWa
     /**
      * 账户资金流水表编辑
      */
-    void edit(AccountRunningWater accountRunningWater);
+    void edit(AccountRunningWaterDto accountRunningWaterDto);
 
     /**
      * 账户资金流水表删除
@@ -71,4 +71,9 @@ public interface AccountRunningWaterService extends BaseService<AccountRunningWa
      * 内部转账
      */
     void internalTransfer(AccountRunningWaterDto dto);
+
+    /**
+     * 操作余额
+     */
+    void changeRemainder(AccountRunningWater accountRunningWater);
 }

+ 47 - 2
hx-account/src/main/java/com/fjhx/account/service/account/impl/AccountRunningWaterServiceImpl.java

@@ -17,11 +17,13 @@ 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.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.TransactionService;
 import com.fjhx.common.constant.SourceConstant;
 import com.fjhx.common.entity.corporation.po.Corporation;
 import com.fjhx.common.enums.PushBusinessTypeEnum;
@@ -71,6 +73,8 @@ public class AccountRunningWaterServiceImpl extends ServiceImpl<AccountRunningWa
     private AccountManagementService accountManagementService;
     @Autowired
     private TaxRefundDetailsService taxRefundDetailsService;
+    @Autowired
+    private TransactionService transactionService;
 
     @Override
     public Page<AccountRunningWaterVo> getPage(AccountRunningWaterSelectDto dto) {
@@ -225,6 +229,21 @@ public class AccountRunningWaterServiceImpl extends ServiceImpl<AccountRunningWa
 
         this.save(dto);
 
+        //如果是往来
+        if (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,7 +291,7 @@ public class AccountRunningWaterServiceImpl extends ServiceImpl<AccountRunningWa
      */
     @Override
     @DSTransactional
-    public void edit(AccountRunningWater accountRunningWaterDto) {
+    public void edit(AccountRunningWaterDto accountRunningWaterDto) {
         //先回滚历史数据
         //获取历史的流水信息信息
         AccountRunningWater oldAccountRunningWater = getById(accountRunningWaterDto.getId());
@@ -286,6 +305,26 @@ public class AccountRunningWaterServiceImpl extends ServiceImpl<AccountRunningWa
         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
@@ -302,6 +341,11 @@ public class AccountRunningWaterServiceImpl extends ServiceImpl<AccountRunningWa
         changeRemainder(accountRunningWater);
 
         this.removeById(id);
+
+        //删除往来
+        if (1 == accountRunningWater.getIsTransaction()) {
+            transactionService.remove(q -> q.eq(Transaction::getAccountRunningWaterId, id));
+        }
     }
 
     /**
@@ -450,7 +494,8 @@ public class AccountRunningWaterServiceImpl extends ServiceImpl<AccountRunningWa
     /**
      * 余额操作
      */
-    private void changeRemainder(AccountRunningWater accountRunningWater) {
+    @Override
+    public void changeRemainder(AccountRunningWater accountRunningWater) {
         // 修改账户余额表的余额
         AccountRemainder accountRemainder = accountRemainderService.getOne(q -> q
                 .eq(AccountRemainder::getAccountManagementId, accountRunningWater.getAccountManagementId())

+ 34 - 0
hx-account/src/main/java/com/fjhx/account/service/transaction/impl/TransactionServiceImpl.java

@@ -1,21 +1,26 @@
 package com.fjhx.account.service.transaction.impl;
 
 import cn.hutool.core.util.ObjectUtil;
+import com.baomidou.dynamic.datasource.annotation.DSTransactional;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fjhx.account.entity.account.po.AccountManagement;
+import com.fjhx.account.entity.account.po.AccountRunningWater;
 import com.fjhx.account.entity.transaction.dto.TransactionDto;
 import com.fjhx.account.entity.transaction.dto.TransactionSelectDto;
 import com.fjhx.account.entity.transaction.po.Transaction;
 import com.fjhx.account.entity.transaction.vo.TransactionVo;
 import com.fjhx.account.mapper.transaction.TransactionMapper;
 import com.fjhx.account.service.account.AccountManagementService;
+import com.fjhx.account.service.account.AccountRunningWaterService;
 import com.fjhx.account.service.transaction.TransactionDepartmentService;
 import com.fjhx.account.service.transaction.TransactionService;
+import com.fjhx.common.utils.ExchangeRateUtil;
 import com.ruoyi.common.utils.wrapper.IWrapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.math.BigDecimal;
 import java.util.List;
 
 
@@ -34,6 +39,8 @@ public class TransactionServiceImpl extends ServiceImpl<TransactionMapper, Trans
     private AccountManagementService accountManagementService;
     @Autowired
     private TransactionDepartmentService transactionDepartmentService;
+    @Autowired
+    private AccountRunningWaterService accountRunningWaterService;
 
     @Override
     public Page<TransactionVo> getPage(TransactionSelectDto dto) {
@@ -68,7 +75,34 @@ public class TransactionServiceImpl extends ServiceImpl<TransactionMapper, Trans
     }
 
     @Override
+    @DSTransactional
     public void add(TransactionDto transactionDto) {
+        //如果是流水就创建流水数据
+        if (1 == transactionDto.getIsFlowingWater()) {
+            AccountRunningWater accountRunningWater = new AccountRunningWater();
+            accountRunningWater.setAccountManagementId(transactionDto.getAccountId());
+            accountRunningWater.setStatus(transactionDto.getType() == 0 ? "10" : "20");
+            accountRunningWater.setCurrency(transactionDto.getCurrency());
+            accountRunningWater.setAmount(transactionDto.getAmount());
+            accountRunningWater.setRemarks(transactionDto.getRemark());
+            accountRunningWater.setIsTransaction(1);
+            accountRunningWater.setTransactionDeptId(transactionDto.getDepartmentId());
+
+            accountRunningWater.setClaimAmount(BigDecimal.ZERO);
+            accountRunningWater.setReceived("20");
+            accountRunningWater.setIsClaim(0);
+
+            accountRunningWater.setRate(ExchangeRateUtil.getCnyToCodeRate(accountRunningWater.getCurrency()));
+
+            accountRunningWaterService.save(accountRunningWater);
+
+            //赋值流水id
+            transactionDto.setAccountRunningWaterId(accountRunningWater.getId());
+
+            //操作余额
+            accountRunningWaterService.changeRemainder(accountRunningWater);
+        }
+
         this.save(transactionDto);
     }