schangxiang@126.com
2025-09-18 49a51c068d62084bc4c3e77c4be94a20de556c4a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import BaseService from "../baseService";
import { FinanceBankAccount } from "../../entity/finance/base/financeBankAccount";
import { FinanceFlow } from "../../entity/finance/base/financeFlow";
import { Not } from "typeorm";
 
/**
 * 财务管理
 */
export default class BankAccountService extends BaseService {
  //#region 添加保存前事件
  /**
   * 添加保存后事件
   */
  public async onAddSaveAfter(t: FinanceBankAccount, isAdd: boolean) {
    let userInfo = await this.userInfo; // 当前登录人信息
    this.info.result = true;
    // 只有在添加时才增加流水
    if (isAdd) {
      // 获得最后一条流水
      let lastFlow = await this.dbRead.findOne(FinanceFlow, {
        where: {
          bankAccount_Id: t.bankAccount_Id
        },
        order: {
          bankAccount_Id: "DESC"
        }
      });
      // 获得最终金额
      let balanceRMB = 0;
      if (lastFlow) {
        balanceRMB = lastFlow.balanceRMB;
      }
      // 获得流水编号
      let flowCode = await this.ctx.service.common.getCodeRegular(1698);
      // 增加流水
      let newFlow = new FinanceFlow();
      newFlow.flowCode = flowCode;
      newFlow.bankAccountCode = t.bankAccountCode;
      newFlow.bankAccountName = t.bankAccountName;
      newFlow.bankAccount_Id = t.bankAccount_Id;
      newFlow.outcomeRMB = 0;
      newFlow.incomeRMB = t.originalRMB;
      newFlow.balanceRMB = balanceRMB + t.originalRMB;
 
      newFlow.mainID = t.bankAccount_Id;
      newFlow.detailID = t.bankAccount_Id;
      newFlow.billCode = t.bankAccount;
      newFlow.flowName = "账户初始化";
      newFlow.sourceType = "账户初始化";
 
      newFlow.deptName = userInfo.deptName;
      newFlow.dept_Id = userInfo.dept_Id;
      newFlow.userTrueName = userInfo.userTrueName;
      newFlow.user_Id = userInfo.user_Id;
      await this.setAccountInfo(newFlow);
      await this.dbWrite.save(newFlow);
    }
    return this.info;
  }
  //#endregion
  //#region 添加保存前事件
  /**
   * 添加保存前事件
   */
  public async onAddSaveBefore(t: FinanceBankAccount) {
    let userInfo = await this.userInfo;
    this.info.result = true;
 
    //判断条码是否重复
    let where = {
      consignorName: t.consignorName,
      userProduct_Id: userInfo.userProduct_Id,
      consignor_Id: Not(0)
    };
    let count = await this.dbRead.count(FinanceBankAccount, where);
    if (count) {
      this.info.msg = "当前货主名字,【" + t.consignorName + "】已存在不允许重复添加,无法添加!";
      this.info.result = false;
    }
    return this.info;
  }
  //#endregion
}