1
This commit is contained in:
@@ -109,7 +109,7 @@ module.exports = {
|
||||
* /api/apply/statistics:
|
||||
* get:
|
||||
* summary: 获取投递统计
|
||||
* description: 根据设备SN码获取投递统计数据
|
||||
* description: 根据设备SN码获取投递统计数据(包含今日、本周、本月统计)
|
||||
* tags: [前端-投递管理]
|
||||
* parameters:
|
||||
* - in: query
|
||||
@@ -124,7 +124,7 @@ module.exports = {
|
||||
*/
|
||||
'GET /apply/statistics': async (ctx) => {
|
||||
const models = Framework.getModels();
|
||||
const { apply_records } = models;
|
||||
const { apply_records, op } = models;
|
||||
const { sn_code } = ctx.query;
|
||||
const final_sn_code = sn_code;
|
||||
|
||||
@@ -132,18 +132,61 @@ module.exports = {
|
||||
return ctx.fail('请提供设备SN码');
|
||||
}
|
||||
|
||||
// 计算时间范围
|
||||
const now = new Date();
|
||||
|
||||
// 今天的开始时间(00:00:00)
|
||||
const todayStart = new Date(now);
|
||||
todayStart.setHours(0, 0, 0, 0);
|
||||
|
||||
// 本周的开始时间(周一00:00:00)
|
||||
const weekStart = new Date(now);
|
||||
const dayOfWeek = weekStart.getDay();
|
||||
const diff = dayOfWeek === 0 ? 6 : dayOfWeek - 1; // 周日算作上周
|
||||
weekStart.setDate(weekStart.getDate() - diff);
|
||||
weekStart.setHours(0, 0, 0, 0);
|
||||
|
||||
// 本月的开始时间(1号00:00:00)
|
||||
const monthStart = new Date(now.getFullYear(), now.getMonth(), 1);
|
||||
monthStart.setHours(0, 0, 0, 0);
|
||||
|
||||
const [
|
||||
totalCount,
|
||||
successCount,
|
||||
failedCount,
|
||||
pendingCount,
|
||||
interviewCount
|
||||
interviewCount,
|
||||
todayCount,
|
||||
weekCount,
|
||||
monthCount
|
||||
] = await Promise.all([
|
||||
// 总计
|
||||
apply_records.count({ where: { sn_code: final_sn_code } }),
|
||||
apply_records.count({ where: { sn_code: final_sn_code, applyStatus: 'success' } }),
|
||||
apply_records.count({ where: { sn_code: final_sn_code, applyStatus: 'failed' } }),
|
||||
apply_records.count({ where: { sn_code: final_sn_code, applyStatus: 'pending' } }),
|
||||
apply_records.count({ where: { sn_code: final_sn_code, feedbackStatus: 'interview' } })
|
||||
apply_records.count({ where: { sn_code: final_sn_code, feedbackStatus: 'interview' } }),
|
||||
// 今日
|
||||
apply_records.count({
|
||||
where: {
|
||||
sn_code: final_sn_code,
|
||||
applyTime: { [op.gte]: todayStart }
|
||||
}
|
||||
}),
|
||||
// 本周
|
||||
apply_records.count({
|
||||
where: {
|
||||
sn_code: final_sn_code,
|
||||
applyTime: { [op.gte]: weekStart }
|
||||
}
|
||||
}),
|
||||
// 本月
|
||||
apply_records.count({
|
||||
where: {
|
||||
sn_code: final_sn_code,
|
||||
applyTime: { [op.gte]: monthStart }
|
||||
}
|
||||
})
|
||||
]);
|
||||
|
||||
return ctx.success({
|
||||
@@ -152,6 +195,9 @@ module.exports = {
|
||||
failedCount,
|
||||
pendingCount,
|
||||
interviewCount,
|
||||
todayCount,
|
||||
weekCount,
|
||||
monthCount,
|
||||
successRate: totalCount > 0 ? ((successCount / totalCount) * 100).toFixed(2) : 0,
|
||||
interviewRate: totalCount > 0 ? ((interviewCount / totalCount) * 100).toFixed(2) : 0
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user