feat(corporate-bank-account-payment-order): 基于原模板生成建行制单
这个提交包含在:
@@ -1,42 +1,59 @@
|
||||
const fs = require("node:fs");
|
||||
const os = require("node:os");
|
||||
const path = require("node:path");
|
||||
const { spawnSync } = require("node:child_process");
|
||||
|
||||
const { encryptStringOrThrow } = require("../src/services/crypto");
|
||||
const { generatePaymentOrderXls } = require("../src/services/paymentOrderXls");
|
||||
|
||||
const temporaryDirectory = fs.mkdtempSync(path.join(os.tmpdir(), "payment-order-xls-"));
|
||||
const outputPath = path.join(temporaryDirectory, "synthetic-order.xls");
|
||||
try {
|
||||
const fieldEncryptionKey = Buffer.alloc(32, 7).toString("base64");
|
||||
const config = { fieldEncryptionKey };
|
||||
const encrypt = (value) => encryptStringOrThrow(config, value);
|
||||
const generated = generatePaymentOrderXls(config, {
|
||||
batch_no: "PB-20260802-001",
|
||||
payment_account_snapshot_json: { bankInstitutionCode: "CCB", accountName: "合成测试公司", accountNumberEncrypted: encrypt("6217000000000012345") },
|
||||
items: [{ id: "1", entity_code: "BX-20260802-0001", amount: "1586.00", snapshot_json: { payee: { name: "合成员工", bankName: "中国建设银行", bankInstitutionCode: "CCB", bankAccountEncrypted: encrypt("6222000000000056789") } } }],
|
||||
});
|
||||
fs.writeFileSync(outputPath, generated.buffer);
|
||||
const check = spawnSync("python3", ["-c", [
|
||||
"import sys,xlrd",
|
||||
"book=xlrd.open_workbook(sys.argv[1])",
|
||||
"assert book.sheet_names()==['Sheet1','Sheet2','Sheet3']",
|
||||
"assert [(s.nrows,s.ncols) for s in book.sheets()]==[(2,15),(0,0),(0,0)]",
|
||||
"sheet=book.sheet_by_index(0)",
|
||||
"assert sheet.cell_type(1,1)==xlrd.XL_CELL_TEXT and sheet.cell_value(1,1)=='6217000000000012345'",
|
||||
"assert sheet.cell_type(1,3)==xlrd.XL_CELL_TEXT and sheet.cell_value(1,3)=='01'",
|
||||
"assert sheet.cell_type(1,4)==xlrd.XL_CELL_TEXT and sheet.cell_value(1,4)=='6222000000000056789'",
|
||||
"assert sheet.cell_type(1,8)==xlrd.XL_CELL_TEXT",
|
||||
"assert sheet.cell_type(1,9)==xlrd.XL_CELL_NUMBER and sheet.cell_value(1,9)==1586.0",
|
||||
"assert sheet.cell_value(1,10)=='报销款' and sheet.cell_value(1,5)=='合成员工'",
|
||||
].join(";"), outputPath], { encoding: "utf8" });
|
||||
if (check.status !== 0) {
|
||||
process.stderr.write(check.stderr || check.stdout || "xlrd roundtrip failed\n");
|
||||
process.exitCode = 1;
|
||||
} else {
|
||||
process.stdout.write("[payment-order-xls][PASS] xlrd BIFF8 roundtrip verified\n");
|
||||
}
|
||||
} finally {
|
||||
fs.rmSync(temporaryDirectory, { recursive: true, force: true });
|
||||
const fieldEncryptionKey = Buffer.alloc(32, 7).toString("base64");
|
||||
const config = { fieldEncryptionKey };
|
||||
const encrypt = (value) => encryptStringOrThrow(config, value);
|
||||
const syntheticAccounts = [
|
||||
"6222000000000012345",
|
||||
"6222000000000023456",
|
||||
"6222000000000034567",
|
||||
"6222000000000045678",
|
||||
];
|
||||
|
||||
const generated = generatePaymentOrderXls(config, {
|
||||
batch_no: "PB-20260802-001",
|
||||
payment_account_snapshot_json: {
|
||||
bankInstitutionCode: "CCB",
|
||||
accountName: "合成测试公司",
|
||||
bankName: "中国建设银行",
|
||||
accountNumberEncrypted: encrypt("6217000000000012345"),
|
||||
},
|
||||
items: syntheticAccounts.map((account, index) => ({
|
||||
id: String(index + 1),
|
||||
entity_code: `BX-20260802-${String(index + 1).padStart(4, "0")}`,
|
||||
amount: `${index + 1}.20`,
|
||||
snapshot_json: {
|
||||
payee: {
|
||||
name: `合成员工${index + 1}`,
|
||||
bankName: "中国建设银行",
|
||||
bankInstitutionCode: "CCB",
|
||||
bankAccountEncrypted: encrypt(account),
|
||||
},
|
||||
},
|
||||
})),
|
||||
});
|
||||
|
||||
const pythonBin = process.env.PAYMENT_ORDER_PYTHON_BIN ?? "python3";
|
||||
const verifier = spawnSync(pythonBin, [path.resolve(__dirname, "verify-payment-order-xls.py")], {
|
||||
input: generated.buffer,
|
||||
encoding: "utf8",
|
||||
maxBuffer: 16 * 1024 * 1024,
|
||||
timeout: 15_000,
|
||||
env: {
|
||||
PATH: path.isAbsolute(pythonBin) ? path.dirname(pythonBin) : "/usr/local/bin:/usr/bin:/bin",
|
||||
LANG: "C.UTF-8",
|
||||
PYTHONDONTWRITEBYTECODE: "1",
|
||||
PYTHONNOUSERSITE: "1",
|
||||
},
|
||||
});
|
||||
|
||||
if (verifier.status !== 0 || verifier.error) {
|
||||
process.stderr.write(verifier.stderr || "[payment-order-xls][FAIL] verifier unavailable\n");
|
||||
process.exitCode = 1;
|
||||
} else {
|
||||
process.stdout.write(verifier.stdout);
|
||||
}
|
||||
|
||||
在新工单中引用
屏蔽一个用户