diff --git a/skills/hose-use/references/task.md b/skills/hose-use/references/task.md index f5bbd32..2e06131 100644 --- a/skills/hose-use/references/task.md +++ b/skills/hose-use/references/task.md @@ -6,6 +6,7 @@ hose task todo # 待我审批 hose task approved # 我已审批 hose task records # 审批记录 +hose task submitted # 我发起的单据 hose task cc --unread # 未读抄送 hose task cc --read # 已读抄送 hose task todo --staff <员工工号或ID> # 在当前页结果中按人员过滤 diff --git a/src/cli/commands/task.ts b/src/cli/commands/task.ts index b702eea..b8b53e8 100644 --- a/src/cli/commands/task.ts +++ b/src/cli/commands/task.ts @@ -25,9 +25,11 @@ export async function handleTaskCommand(parsed: CliParsedArgs, runtime: CliRunti ? "processed" : action === "cc" || action === "carboncopy" || action === "carbon-copy" ? "cc" + : action === "submitted" || action === "mine" || action === "created" + ? "submitted" : undefined; if (!view) { - throw new Error("未知 task 子命令。支持: todo, approved, records, cc"); + throw new Error("未知 task 子命令。支持: todo, approved, records, submitted, cc"); } const count = numberOption(parsed.options, ["count", "limit", "n"], 20); const start = numberOption(parsed.options, ["start", "offset"], 0); @@ -56,7 +58,13 @@ export async function handleTaskCommand(parsed: CliParsedArgs, runtime: CliRunti item.nodeName || "-", item.action || "-", ]); - const labels: Record = { todo: "待审批", approved: "已审批", processed: "审批记录", cc: readFilter ? "抄送(已读)" : "抄送(未读)" }; + const labels: Record = { + todo: "待审批", + approved: "已审批", + processed: "审批记录", + submitted: "我发起的", + cc: readFilter ? "抄送(已读)" : "抄送(未读)", + }; return { stdout: `====== ${labels[view]}任务 (企业: ${corp.name} | 总数: ${result.total} | 当前返回: ${result.items.length}) ======\n${printTable(headers, rows)}\n`, stderr: "", diff --git a/src/cli/printer.ts b/src/cli/printer.ts index 41b61f7..3283aa4 100644 --- a/src/cli/printer.ts +++ b/src/cli/printer.ts @@ -121,7 +121,7 @@ export function printHelp(): string { workflow 工作流管理 (list, get, find, toggle) bill 单据与费用明细检索 (list, get <单号|ID>, schema, link <单号|ID>) contact 企业通讯录与人员检索 (list, search <关键词>, get ) - task 待办中心与审批任务 (todo, approved, records, cc) + task 待办中心与审批任务 (todo, approved, records, submitted, cc) platform 自建应用管理 (list) skill Agent Skill 管理 (install, status, dump) probe 连通性诊断 (probe [corpId]) @@ -152,6 +152,7 @@ export function printHelp(): string { hose-use contact list --limit=20 # 采样查看企业通讯录(带防爆截断保护) hose-use task todo --json # 查看当前待我审批任务 hose-use task approved # 查看我已审批任务 + hose-use task submitted # 查看我发起的单据 hose-use task cc --unread # 查看未读抄送 hose-use workflow list # 汇总查看全部工作流 hose-use workflow find --task=code-js2 # 搜索包含自定义脚本的工作流 diff --git a/src/domains/task/api.ts b/src/domains/task/api.ts index 08b7ede..1f394e6 100644 --- a/src/domains/task/api.ts +++ b/src/domains/task/api.ts @@ -23,6 +23,13 @@ function approvedDateFilter(options: TaskQueryOptions): string { return `&&((approvedFlow.updateTime > ${from}) && (approvedFlow.updateTime < ${to}))`; } +function submittedDateFilter(options: TaskQueryOptions): string { + if (options.from === undefined && options.to === undefined) return ""; + const from = options.from ?? 0; + const to = options.to ?? 32503680000000; + return `&&((form.submitDate > ${from}) && (form.submitDate < ${to}))`; +} + function selectForBacklog(): string { return "flowId(ownerId(id,name,enName),form(title,code,specificationId(active,id,name,enName,nameSpell,code),submitDate,submitterId(id,name,enName,nickName,code,email,cellphone,note),reviewStatus,expenseMoney,loanMoney,requisitionMoney,payMoney),`...`),`...`"; } @@ -40,6 +47,23 @@ export async function fetchTaskPage( const start = options.start ?? 0; const count = options.count ?? 20; + if (view === "submitted") { + const response = await client.post("api/flow/v1/flows/my", { + searchParams: { + type: "home5", + delegatedFilter: "DELEGATE_TO_ME", + corpId, + }, + json: { + filterBy: `(state.in("rejected","draft","sending","receiving","receivingExcep","approving","pending","paying","paid"))&&(INSTR(form.specificationId,"${corpId}:system:对账单")==0)${submittedDateFilter(options)}`, + limit: { start, count }, + orderBy: [{ value: "form.submitDate", order: "DESC" }], + }, + }); + const json = (await response.json()) as { count?: number; items?: Record[] }; + return { count: json.count ?? json.items?.length ?? 0, items: json.items ?? [] }; + } + if (view === "cc") { const searchParams = new URLSearchParams({ corpId }); searchParams.append("join", "flowId.id,nodeState,/flow/v2/backlogs/state"); diff --git a/src/domains/task/task.test.ts b/src/domains/task/task.test.ts index cb76084..ae425bb 100644 --- a/src/domains/task/task.test.ts +++ b/src/domains/task/task.test.ts @@ -28,4 +28,25 @@ describe("Task Domain - 待办任务模型", () => { expect(item.amount?.value).toBe("120.00"); expect(item.actions).toEqual(["freeflow.agree", "freeflow.reject"]); }); + + test("normalizes flows returned by the submitted-bills endpoint", () => { + const item = normalizeTask({ + flow: { + id: "flow-submitted-1", + state: "approving", + ownerId: { id: "staff-1", name: "张三" }, + }, + form: { + code: "BX26000002", + title: "差旅报销", + specification: { name: "差旅报销单" }, + submitterId: { id: "staff-1", name: "张三", code: "1001" }, + amount: { standard: "88.00", standardStrCode: "CNY", standardSymbol: "¥" }, + }, + }); + expect(item.taskId).toBe("flow-submitted-1"); + expect(item.state).toBe("approving"); + expect(item.templateName).toBe("差旅报销单"); + expect(item.amount?.value).toBe("88.00"); + }); }); diff --git a/src/domains/task/tools.ts b/src/domains/task/tools.ts index 1c16167..11ddbd4 100644 --- a/src/domains/task/tools.ts +++ b/src/domains/task/tools.ts @@ -29,11 +29,11 @@ function money(value: unknown): TaskItem["amount"] { } export function normalizeTask(raw: Record): TaskItem { - const flow = record(raw.flowId); + const flow = record(raw.flowId ?? raw.flow); const form = record(flow.form ?? raw.form); const nodeState = record(raw.nodeState ?? flow.nodeState); - const amount = money(form.expenseMoney ?? form.payMoney ?? form.requisitionMoney ?? form.loanMoney); - const specification = record(form.specificationId); + const amount = money(form.expenseMoney ?? form.payMoney ?? form.requisitionMoney ?? form.loanMoney ?? form.amount); + const specification = record(form.specificationId ?? form.specification); const submitter = person(form.submitterId); const owner = person(flow.ownerId ?? raw.ownerId); const actionsByStaff = record(flow.actions ?? raw.actions); diff --git a/src/domains/task/types.ts b/src/domains/task/types.ts index 05d3152..c981f4a 100644 --- a/src/domains/task/types.ts +++ b/src/domains/task/types.ts @@ -1,6 +1,6 @@ import { z } from "zod"; -export const TaskViewSchema = z.enum(["todo", "approved", "processed", "cc"]); +export const TaskViewSchema = z.enum(["todo", "approved", "processed", "cc", "submitted"]); export type TaskView = z.infer; export interface TaskQueryOptions {