更新
This commit is contained in:
@@ -183,6 +183,65 @@ router.post("/api/v1/business/outbound-tasks", (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// 6) 业务侧查询发送任务状态(用于业务系统展示)
|
||||
router.get("/api/v1/business/outbound-tasks", (req, res) => {
|
||||
const deviceId = getDeviceIdFromHeader(req);
|
||||
if (!deviceId) return res.status(401).json({ error: "missing api key for device identification" });
|
||||
|
||||
const limit = Math.min(Number(req.query.limit || 50), 200);
|
||||
const status = req.query.status ? String(req.query.status) : "";
|
||||
const phone = req.query.phone ? safeString(req.query.phone) : "";
|
||||
|
||||
try {
|
||||
const where = ["device_id = ?"];
|
||||
const params = [deviceId];
|
||||
|
||||
if (status !== "") {
|
||||
where.push("status = ?");
|
||||
params.push(status);
|
||||
}
|
||||
if (phone !== "") {
|
||||
where.push("phone LIKE ?");
|
||||
params.push(`%${phone}%`);
|
||||
}
|
||||
|
||||
const rows = db
|
||||
.prepare(
|
||||
`
|
||||
SELECT
|
||||
task_id,
|
||||
phone,
|
||||
content,
|
||||
status,
|
||||
retry_count,
|
||||
last_error,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM outbound_tasks
|
||||
WHERE ${where.join(" AND ")}
|
||||
ORDER BY created_at DESC
|
||||
LIMIT ?
|
||||
`
|
||||
)
|
||||
.all(...params, limit);
|
||||
|
||||
res.json({
|
||||
tasks: rows.map((r) => ({
|
||||
taskId: r.task_id,
|
||||
phone: r.phone,
|
||||
content: r.content,
|
||||
status: r.status,
|
||||
retryCount: r.retry_count,
|
||||
lastError: r.last_error,
|
||||
createdAt: r.created_at,
|
||||
updatedAt: r.updated_at,
|
||||
})),
|
||||
});
|
||||
} catch (e) {
|
||||
res.status(500).json({ error: "failed to query outbound tasks", detail: String(e?.message || e) });
|
||||
}
|
||||
});
|
||||
|
||||
// 5) 业务侧读取入站验证码(MVP 用)
|
||||
router.get("/api/v1/business/inbound-sms", (req, res) => {
|
||||
const deviceId = getDeviceIdFromHeader(req);
|
||||
|
||||
Reference in New Issue
Block a user