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)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -169,7 +169,15 @@ const app = await buildApp({
|
||||
},
|
||||
async stats(input) {
|
||||
calls.push(['stats', input]);
|
||||
return { byStatus: { SUBMITTED: 2 }, pendingSettlementCents: 1200 };
|
||||
return {
|
||||
byStatus: { SUBMITTED: 2, COMPLETED: 1, REJECTED: 1 },
|
||||
taskTotal: 4,
|
||||
completed: 1,
|
||||
rejected: 1,
|
||||
completionRate: 25,
|
||||
pendingSettlementCents: 1200,
|
||||
settledRewardCents: 600
|
||||
};
|
||||
},
|
||||
async managerStatistics(input) {
|
||||
calls.push(['managerStatistics', input]);
|
||||
@@ -594,6 +602,8 @@ const stats = await app.inject({
|
||||
});
|
||||
assert.equal(stats.statusCode, 200);
|
||||
assert.equal(stats.json().data.pendingSettlementCents, 1200);
|
||||
assert.equal(stats.json().data.settledRewardCents, 600);
|
||||
assert.equal(stats.json().data.completionRate, 25);
|
||||
|
||||
const unauthorized = await app.inject({ method: 'GET', url: '/app-api/cleaning/tasks/hall' });
|
||||
assert.equal(unauthorized.statusCode, 401);
|
||||
|
||||
Reference in New Issue
Block a user