feat: 部门/业务负责人列表补齐无车辆业务员
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

/dept-stats 在按车辆聚合后,查询 tab_user 把业务部门内所有在职用户补进 managers 列表,无车辆显示为 0 辆。跳过公务车部门。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
kkfluous
2026-04-14 22:44:01 +08:00
parent e4f682dff5
commit b4c4929dbb

View File

@@ -690,6 +690,28 @@ app.get('/dept-stats', async (c) => {
mgrMap.get(mgr)!.push(v); mgrMap.get(mgr)!.push(v);
} }
// 补齐:业务部门内所有在职用户,即使当前无车辆也需显示
const deptNames = Array.from(deptMap.keys()).filter((d) => d !== '公务车');
if (deptNames.length > 0) {
const placeholders = deptNames.map(() => '?').join(',');
const [userRows] = await pool.query<any[]>(
`SELECT u.user_name, dep.dep_name
FROM tab_user u
LEFT JOIN tab_department dep ON dep.id = u.dep_id AND dep.is_deleted = 0
WHERE u.is_deleted = 0
AND dep.dep_name IN (${placeholders})`,
deptNames,
);
for (const r of userRows as any[]) {
const dept = r.dep_name as string | null;
const mgr = r.user_name as string | null;
if (!dept || !mgr) continue;
const mgrMap = deptMap.get(dept);
if (!mgrMap) continue;
if (!mgrMap.has(mgr)) mgrMap.set(mgr, []);
}
}
// Compute attendance & avg mileage from realtime data // Compute attendance & avg mileage from realtime data
const getMileageStats = (vList: Vehicle[]) => { const getMileageStats = (vList: Vehicle[]) => {
const todayActive = vList.filter((v) => (todayMileageMap.get(v.plateNumber) || 0) > 0).length; const todayActive = vList.filter((v) => (todayMileageMap.get(v.plateNumber) || 0) > 0).length;