feat: 月度模式全面参数化 - 移除硬编码日期,前后端按月动态查询

This commit is contained in:
freedakgmail
2026-08-01 13:10:22 +08:00
parent a90c133578
commit dab06ba109
43 changed files with 9135 additions and 309 deletions
+13 -6
View File
@@ -21,6 +21,12 @@ router.get('/', async (req: AuthRequest, res) => {
const params: any[] = [month]
let paramIdx = 2
// 默认排除模拟验收记录,除非显式请求
const includeSimulated = req.query.include_simulated === 'true'
if (!includeSimulated) {
conditions.push(`(is_simulated = false OR is_simulated IS NULL)`)
}
if (priority) {
conditions.push(`priority = $${paramIdx++}`)
params.push(priority)
@@ -81,7 +87,7 @@ router.post('/', async (req: AuthRequest, res) => {
router.post('/auto-generate', async (req: AuthRequest, res) => {
try {
const month = req.body.month ? (req.body.month.length === 7 ? `${req.body.month}-01` : req.body.month) : '2026-05-01'
const month = req.body.month ? (req.body.month.length === 7 ? `${req.body.month}-01` : req.body.month) : parseMonth(req)
const result = await query(`SELECT * FROM analytics.f_generate_store_tasks($1)`, [month])
sendSuccess(res, result.rows[0] || { generated: 0, message: 'No tasks generated' })
} catch (err: any) {
@@ -585,7 +591,7 @@ router.get('/monthly-review/completion', async (req: AuthRequest, res) => {
count(*) FILTER (WHERE verification_result = '未改善') as failed,
ROUND(count(*) FILTER (WHERE status = '已验收' OR status = '已回滚') * 100.0 / NULLIF(count(*), 0), 1) as completion_rate
FROM analytics.store_task
WHERE plan_month = $1
WHERE plan_month = $1 AND (is_simulated = false OR is_simulated IS NULL)
GROUP BY priority
ORDER BY priority
`, [month])
@@ -609,22 +615,23 @@ router.get('/monthly-review/activity-list', async (req: AuthRequest, res) => {
router.get('/monthly-review/sku-governance', async (req: AuthRequest, res) => {
try {
const month = parseMonth(req)
const abcResult = await query(`
SELECT abc_class, count(*) as sku_count,
ROUND(sum(revenue_share_pct), 1) as total_revenue_share,
ROUND(avg(revenue_share_pct), 2) as avg_revenue_share
FROM analytics.v_dish_sku_abc_april
FROM analytics.fn_dish_sku_abc($1)
GROUP BY abc_class
ORDER BY abc_class
`)
`, [month])
const longtailResult = await query(`
SELECT dish_name, category_level1, bill_count, sales_quantity,
received_amount, revenue_share_pct, cumulative_revenue_share
FROM analytics.v_dish_sku_abc_april
FROM analytics.fn_dish_sku_abc($1)
WHERE abc_class = 'C-长尾'
ORDER BY received_amount ASC
LIMIT 50
`)
`, [month])
sendSuccess(res, { summary: abcResult.rows, longtail: longtailResult.rows })
} catch (err: any) { sendError(res, err.message) }
})