refactor(escort): 取消状态与 status 解耦

- 新增 cancelStatus(none/requested/cancelled),status 只描述服务生命周期
- record_state 拆分 canCancelTransition 与 CANCEL_TRANSITIONS
- 管理端 Agent 工具、查询工具与接口层统一走取消状态机
- 列表默认隐藏已取消订单,支持 cancelStatus / includeCancelled 筛选
This commit is contained in:
lik
2026-11-05 18:54:52 +08:00
parent 23b9de16a6
commit fb1210106e
8 changed files with 286 additions and 74 deletions
@@ -3,9 +3,12 @@ import { z } from "zod";
import { DBModel } from "../../../../../models/index.js";
import { escapeRegex, parseObjectId } from "../utils.js";
const STATUS_VALUES = ["pending", "confirmed", "in_progress", "completed", "cancelled"];
const STATUS_VALUES = ["pending", "confirmed", "in_progress", "completed"];
const STATUS_DESC =
"Appointment status: pending (待确认), confirmed (已确认), in_progress (进行中), completed (已完成), cancelled (已取消)";
"Service status: pending (待确认), confirmed (已确认), in_progress (进行中), completed (已完成). Cancellation is a separate cancelStatus.";
const CANCEL_STATUS_VALUES = ["none", "requested", "cancelled"];
const CANCEL_STATUS_DESC =
"Cancel status: none (未取消), requested (待取消), cancelled (已取消)";
/**
* 严格解析 YYYY-MM-DD(东八区零点)
@@ -41,6 +44,7 @@ function buildEscortRecordQueryTool({ userId = null, allowMobile = false, boundA
const shape = {
patientName: z.string().optional().describe("Patient name for fuzzy search"),
status: z.enum(STATUS_VALUES).optional().describe(STATUS_DESC),
cancelStatus: z.enum(CANCEL_STATUS_VALUES).optional().describe(CANCEL_STATUS_DESC),
page: z.number().int().min(1).optional().describe("Page number, starting from 1"),
pageSize: z
.number()
@@ -71,7 +75,7 @@ function buildEscortRecordQueryTool({ userId = null, allowMobile = false, boundA
}
return tool(
async ({ patientName, mobile, attendantId, dateFrom, dateTo, status, page = 1, pageSize = 20 }) => {
async ({ patientName, mobile, attendantId, dateFrom, dateTo, status, cancelStatus, page = 1, pageSize = 20 }) => {
try {
if (!userId && !allowMobile && !attendantScope) {
return { success: false, error: "用户未登录,无法查询陪诊记录" };
@@ -124,6 +128,16 @@ function buildEscortRecordQueryTool({ userId = null, allowMobile = false, boundA
filter.status = status;
}
if (cancelStatus === "cancelled") {
// 兼容旧数据:取消曾存放在 status 中
filter.$or = [{ cancelStatus: "cancelled" }, { status: "cancelled" }];
} else if (cancelStatus) {
filter.cancelStatus = cancelStatus;
} else if (!status) {
// 与列表口径一致:未显式查询时隐藏旧数据里的 status=cancelled
filter.status = { $ne: "cancelled" };
}
// 用户端按订单归属过滤;不能用手机号作为隔离键(手机号可由用户自行修改)
if (userId) {
filter.userId = userId;