24282 8 months ago
parent
commit
34f817df6c

+ 1 - 0
jy-business/src/main/java/com/jy/business/capital/dao/CapitalTransactionsDao.java

@@ -26,6 +26,7 @@ public class CapitalTransactionsDao extends BaseDao<CapitalTransactionsMapper, C
                 .select(
                         ct.all,
                         ca.accountAlias.as(CapitalTransactionsVo::getAccountAlias),
+                        ca.amount.as(CapitalTransactionsVo::getBalance),
                         c.name.as(CapitalTransactionsVo::getCorporationName)
                 )
                 .from(ct)

+ 7 - 0
jy-business/src/main/java/com/jy/business/capital/model/vo/CapitalTransactionsVo.java

@@ -4,6 +4,8 @@ import com.jy.business.capital.model.entity.CapitalTransactions;
 import lombok.Getter;
 import lombok.Setter;
 
+import java.math.BigDecimal;
+
 /**
  * 资金流水列表查询返回值实体
  *
@@ -24,4 +26,9 @@ public class CapitalTransactionsVo extends CapitalTransactions {
      */
     private String corporationName;
 
+    /**
+     * 账户余额
+     */
+    private BigDecimal balance;
+
 }

+ 6 - 15
jy-business/src/main/java/com/jy/business/capital/service/impl/CapitalTransactionsServiceImpl.java

@@ -1,6 +1,5 @@
 package com.jy.business.capital.service.impl;
 
-import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.jy.business.capital.dao.CapitalAccountDao;
 import com.jy.business.capital.dao.CapitalTransactionsDao;
@@ -14,7 +13,6 @@ import jakarta.annotation.Resource;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.math.BigDecimal;
 import java.util.List;
 
 /**
@@ -61,20 +59,13 @@ public class CapitalTransactionsServiceImpl implements CapitalTransactionsServic
         CapitalTransactions oldCapitalTransactions = capitalTransactionsDao.getById(dto.getId());
         AssertUtil.notNull(oldCapitalTransactions, "未知资金流水");
 
-        BigDecimal amount;
-        Integer type = dto.getType();
-        if (ObjectUtil.equal(type, oldCapitalTransactions.getType())) {
-            amount = dto.getAmount().subtract(oldCapitalTransactions.getAmount());
-        } else {
-            amount = dto.getAmount().add(oldCapitalTransactions.getAmount());
-        }
+        boolean updateOldAmount = capitalAccountDao.updateAmount(
+                oldCapitalTransactions.getCapitalAccountId(),
+                oldCapitalTransactions.getType() == 1 ? 0 : 1,
+                oldCapitalTransactions.getAmount());
+        AssertUtil.eqTrue(updateOldAmount, "账户余额不足");
 
-        if (type == 1 && amount.compareTo(BigDecimal.ZERO) < 0) {
-            amount = amount.abs();
-            type = 0;
-        }
-
-        boolean updateAmount = capitalAccountDao.updateAmount(dto.getCapitalAccountId(), type, amount);
+        boolean updateAmount = capitalAccountDao.updateAmount(dto.getCapitalAccountId(), dto.getType(), dto.getAmount());
         AssertUtil.eqTrue(updateAmount, "账户余额不足");
 
         capitalTransactionsDao.updateById(dto);

+ 40 - 7
jy-ui/src/views/business/capital/transactions/index.vue

@@ -140,17 +140,35 @@ const columnConfig: ColumnConfigType[] = [
     label: '交易时间'
   },
   {
-    prop: 'type',
-    label: '交易类型',
+    prop: 'amount',
+    label: '收入',
     formatter(row) {
-      return row.type == 1 ? '收入' : '支出'
+      return row.type == 1 ? row.amount : ''
     }
   },
   {
     prop: 'amount',
-    label: '交易金额'
+    label: '支出',
+    formatter(row) {
+      return row.type == 1 ? '' :row.amount
+    }
   },
   {
+    prop: 'balance',
+    label: '余额'
+  },
+  // {
+  //   prop: 'type',
+  //   label: '交易类型',
+  //   formatter(row) {
+  //     return row.type == 1 ? '收入' : '支出'
+  //   }
+  // },
+  // {
+  //   prop: 'amount',
+  //   label: '交易金额'
+  // },
+  {
     prop: 'targetType',
     label: '对方类型',
     dict: 'target_type'
@@ -240,6 +258,9 @@ const formConfig: FormConfigType[] = [
     label: '交易金额',
     min: 0.01,
     precision: 2,
+    disabled() {
+      return formData.value.id != null
+    },
     rule: [{ required: true, message: '交易金额不能为空', trigger: 'blur' }]
   },
   {
@@ -247,22 +268,34 @@ const formConfig: FormConfigType[] = [
     prop: 'targetType',
     label: '对方类型',
     dict: 'target_type',
+    disabled() {
+      return formData.value.id != null
+    },
     rule: [{ required: true, message: '对方类型不能为空', trigger: 'blur' }]
   },
   {
     type: 'input',
     prop: 'targetAccountName',
-    label: '对方账户名'
+    label: '对方账户名',
+    disabled() {
+      return formData.value.id != null
+    }
   },
   {
     type: 'input',
     prop: 'targetDepositBank',
-    label: '对方开户银行'
+    label: '对方开户银行',
+    disabled() {
+      return formData.value.id != null
+    }
   },
   {
     type: 'input',
     prop: 'targetAccount',
-    label: '对方账号'
+    label: '对方账号',
+    disabled() {
+      return formData.value.id != null
+    }
   },
   {
     type: 'input',