feat(scheduling): add notify route and wire up scheduling router

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
kkfluous
2026-04-16 20:23:29 +08:00
parent 460c9906e1
commit 86d5bc8738
3 changed files with 53 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ import { cors } from 'hono/cors';
import dotenv from 'dotenv';
import vehiclesRouter from './routes/vehicles.js';
import mileageRouter from './routes/mileage/index.js';
import schedulingRouter from './routes/scheduling/index.js';
import authRouter from './auth/login.js';
import { authMiddleware } from './auth/middleware.js';
@@ -22,6 +23,7 @@ app.use('/api/*', authMiddleware);
app.route('/api/vehicles', vehiclesRouter);
app.route('/api/mileage', mileageRouter);
app.route('/api/scheduling', schedulingRouter);
app.get('/api/health', (c) => c.json({ status: 'ok', time: new Date().toISOString() }));

View File

@@ -0,0 +1,10 @@
import { Hono } from 'hono';
import suggestionsRouter from './suggestions.js';
import notifyRouter from './notify.js';
const app = new Hono();
app.route('/suggestions', suggestionsRouter);
app.route('/notify', notifyRouter);
export default app;

View File

@@ -0,0 +1,41 @@
import { Hono } from 'hono';
import type { AuthUser } from '../../auth/types.js';
import type { NotifyRequest } from './types.js';
const app = new Hono();
// In-memory set of processed suggestion IDs
const processedSuggestions = new Set<string>();
export function isProcessed(suggestionId: string): boolean {
return processedSuggestions.has(suggestionId);
}
app.post('/', async (c) => {
try {
const body = await c.req.json<NotifyRequest>();
const { suggestionId, currentPlate, candidatePlate } = body;
if (!suggestionId || !currentPlate || !candidatePlate) {
return c.json({ success: false, message: '缺少必要参数' }, 400);
}
if (processedSuggestions.has(suggestionId)) {
return c.json({ success: false, message: '该建议已处理' }, 409);
}
const user = (c as any).get('user') as AuthUser | undefined;
const operator = user?.userName || '未知';
console.log(`[scheduling:notify] operator=${operator} suggestion=${suggestionId} current=${currentPlate} candidate=${candidatePlate}`);
processedSuggestions.add(suggestionId);
return c.json({ success: true, message: `替换通知已发送:${currentPlate}${candidatePlate}` });
} catch (e: unknown) {
console.error('scheduling notify error:', e);
return c.json({ success: false, message: '发送通知失败' }, 500);
}
});
export default app;