feat(M08-B): 补保洁员端统计看板
This commit is contained in:
@@ -824,9 +824,27 @@ export class CleaningTaskRepository {
|
||||
AND t.status IN ('SUBMITTED', 'COMPLETED') AND t.deleted_at IS NULL`,
|
||||
[input.tenantId, input.userId]
|
||||
);
|
||||
const [settledRows] = await this.pool.execute<AmountRow[]>(
|
||||
`SELECT COALESCE(SUM(m.reward_cents), 0) AS amount
|
||||
FROM qipai_cleaning_task_members m
|
||||
INNER JOIN qipai_cleaning_tasks t ON t.tenant_id = m.tenant_id AND t.id = m.task_id
|
||||
WHERE m.tenant_id = ? AND m.user_id = ? AND m.removed_at IS NULL
|
||||
AND m.settled_at IS NOT NULL AND m.reward_cents > 0
|
||||
AND t.deleted_at IS NULL`,
|
||||
[input.tenantId, input.userId]
|
||||
);
|
||||
const byStatus = Object.fromEntries(counts.map((row) => [row.status, Number(row.total)]));
|
||||
const taskTotal = Object.values(byStatus).reduce((sum, total) => sum + total, 0);
|
||||
const completed = (byStatus.COMPLETED ?? 0) + (byStatus.SETTLED ?? 0);
|
||||
const rejected = byStatus.REJECTED ?? 0;
|
||||
return {
|
||||
byStatus: Object.fromEntries(counts.map((row) => [row.status, Number(row.total)])),
|
||||
pendingSettlementCents: Number(amountRows[0]?.amount ?? 0)
|
||||
byStatus,
|
||||
taskTotal,
|
||||
completed,
|
||||
rejected,
|
||||
completionRate: taskTotal ? Math.round((completed / taskTotal) * 100) : 0,
|
||||
pendingSettlementCents: Number(amountRows[0]?.amount ?? 0),
|
||||
settledRewardCents: Number(settledRows[0]?.amount ?? 0)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user