总进度

This commit is contained in:
cheney 2026-07-13 21:47:00 +08:00
parent 0ad25ce261
commit 5424d61de9

View File

@ -122,25 +122,49 @@ async function confirmReconciliation(statementSeq, id) {
// ======================== 主流程 ======================== // ======================== 主流程 ========================
async function main() { async function main() {
const teamIds = readTeamIds(); const teamIds = readTeamIds();
console.log(`\nTEAM IDs: ${teamIds.join(', ')}\n`); console.log(`
TEAM IDs: ${teamIds.join(', ')}
`);
// 预查询所有结算单,计算总任务数
console.log('预查询结算单列表...');
const allTasks = [];
for (const teamId of teamIds) {
const accounts = await querySettlementAccountIds(teamId);
if (!accounts.length) continue;
for (const account of accounts) {
const statements = await listReceiveStatements(account.id);
for (const st of statements) {
allTasks.push({ teamId, accountId: account.id, statement: st });
}
}
}
const total = allTasks.length;
const pendingTasks = allTasks.filter(t => t.statement.statementStatus !== '5');
const pendingTotal = pendingTasks.length;
const skipCount = total - pendingTotal;
console.log(`总任务: ${total} | 跳过(已完成): ${skipCount} | 待处理: ${pendingTotal}
`);
if (pendingTotal === 0) {
console.log('所有结算单已完成,无需处理。');
return;
}
const allResults = []; const allResults = [];
let completed = 0;
for (const teamId of teamIds) { for (const task of allTasks) {
console.log(`${'='.repeat(50)}\n 处理 ${teamId}\n${'='.repeat(50)}`); const { teamId, accountId, statement: st } = task;
const accounts = await querySettlementAccountIds(teamId);
if (!accounts.length) { console.log(' ⚠ 未找到'); continue; }
for (const account of accounts) {
const accountId = account.id;
console.log(`\n --> 结算单列表 settlementAccountId: ${accountId}`);
const statements = await listReceiveStatements(accountId);
console.log(` --> 共 ${statements.length}`);
for (const st of statements) {
const { id, statementSeq, statementName, receivableTotalPrice, statementStatus } = st; const { id, statementSeq, statementName, receivableTotalPrice, statementStatus } = st;
console.log(`\n --- [${statementSeq}] ${statementName}`);
const pct = Math.round((completed / pendingTotal) * 100);
console.log(`
${'='.repeat(50)}`);
console.log(` 进度: ${pct}% (${completed}/${pendingTotal}) | ${teamId} | ${statementSeq}`);
console.log(`${'='.repeat(50)}`);
console.log(` 结算单: ${statementName}`);
console.log(` 应收: \u00a5${receivableTotalPrice} | 状态: ${statementStatus}`); console.log(` 应收: \u00a5${receivableTotalPrice} | 状态: ${statementStatus}`);
if (statementStatus === '5') { if (statementStatus === '5') {
@ -155,10 +179,9 @@ async function main() {
const confirmResult = await confirmReconciliation(statementSeq, id); const confirmResult = await confirmReconciliation(statementSeq, id);
allResults.push({ teamId, settlementAccountId: accountId, statementSeq, statementName, receivableTotalPrice, autoReconResult: autoResult, confirmResult }); allResults.push({ teamId, settlementAccountId: accountId, statementSeq, statementName, receivableTotalPrice, autoReconResult: autoResult, confirmResult });
completed++;
console.log(` >>> 进度: ${Math.round((completed / pendingTotal) * 100)}% (${completed}/${pendingTotal})`);
} }
}
}
// ======================== 汇总 ======================== // ======================== 汇总 ========================
console.log('\n\n' + '='.repeat(70)); console.log('\n\n' + '='.repeat(70));
console.log(' 最终汇总'); console.log(' 最终汇总');