Merge pull request #17 from yunyingk/feat/issue-10-carbon-copy

feat: add CLI carbon copy task query
This commit is contained in:
yunyingk authored and GitHub committed 2026-09-05 13:41:48 +08:00
commit 12247fd350
5 files changed
+37 -6

No files matched your search

+2
View File
@@ -6,6 +6,8 @@
hose task todo # 待我审批
hose task approved # 我已审批
hose task records # 审批记录
hose task cc --unread # 未读抄送
hose task cc --read # 已读抄送
hose task todo --staff <员工工号或ID> # 在当前页结果中按人员过滤
hose task todo --json --count 50
hose task records --from 2026-01-01 --to 2026-09-05
+10 -4
View File
@@ -1,5 +1,5 @@
import type { CliParsedArgs, CliResult, CliRuntime } from "../types.js";
import { numberOption, stringOption } from "../parser.js";
import { booleanOption, numberOption, stringOption } from "../parser.js";
import { printJson, printTable } from "../printer.js";
import { createEkbClient } from "../../core/auth/ekb.js";
import { listTasks } from "../../domains/task/tools.js";
@@ -23,16 +23,22 @@ export async function handleTaskCommand(parsed: CliParsedArgs, runtime: CliRunti
? "approved"
: action === "processed" || action === "records" || action === "history"
? "processed"
: action === "cc" || action === "carboncopy" || action === "carbon-copy"
? "cc"
: undefined;
if (!view) {
throw new Error("未知 task 子命令。支持: todo, approved, records (processed)");
throw new Error("未知 task 子命令。支持: todo, approved, records, cc");
}
const count = numberOption(parsed.options, ["count", "limit", "n"], 20);
const start = numberOption(parsed.options, ["start", "offset"], 0);
const staffId = stringOption(parsed.options, ["staff", "staff-id", "staffId"]);
const from = dateOption(stringOption(parsed.options, ["from", "start-date"]));
const to = dateOption(stringOption(parsed.options, ["to", "end-date"]));
const result = await listTasks(await createEkbClient(corp), corp.corpId || corp.id, view, { start, count, staffId, from, to });
const read = booleanOption(parsed.options, ["read"]);
const unread = booleanOption(parsed.options, ["unread"]);
// Carbon copy defaults to unread, while the other views do not use this flag.
const readFilter = view === "cc" ? read && !unread : undefined;
const result = await listTasks(await createEkbClient(corp), corp.corpId || corp.id, view, { start, count, staffId, from, to, read: readFilter });
if (runtime.jsonMode) {
return { stdout: printJson({ corpId: corp.corpId || corp.id, corpName: corp.name, ...result }, runtime.outputOptions), stderr: "", exitCode: 0 };
@@ -50,7 +56,7 @@ export async function handleTaskCommand(parsed: CliParsedArgs, runtime: CliRunti
item.nodeName || "-",
item.action || "-",
]);
const labels: Record<TaskView, string> = { todo: "待审批", approved: "已审批", processed: "审批记录" };
const labels: Record<TaskView, string> = { todo: "待审批", approved: "已审批", processed: "审批记录", cc: readFilter ? "抄送(已读)" : "抄送(未读)" };
return {
stdout: `====== ${labels[view]}任务 (企业: ${corp.name} | 总数: ${result.total} | 当前返回: ${result.items.length}) ======\n${printTable(headers, rows)}\n`,
stderr: "",
+2 -1
View File
@@ -121,7 +121,7 @@ export function printHelp(): string {
workflow 工作流管理 (list, get, find, toggle)
bill 单据与费用明细检索 (list, get <单号|ID>, schema, link <单号|ID>)
contact 企业通讯录与人员检索 (list, search <关键词>, get <staffId>)
task 待办中心与审批任务 (todo, approved, records)
task 待办中心与审批任务 (todo, approved, records, 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 cc --unread # 查看未读抄送
hose-use workflow list # 汇总查看全部工作流
hose-use workflow find --task=code-js2 # 搜索包含自定义脚本的工作流
hose-use bill list # 查看当前企业单据与报销列表
+21
View File
@@ -27,6 +27,10 @@ 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),`...`),`...`";
}
function selectForCarbonCopy(): 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),`...`),`...`";
}
export async function fetchTaskPage(
client: KyInstance,
corpId: string,
@@ -36,6 +40,23 @@ export async function fetchTaskPage(
const start = options.start ?? 0;
const count = options.count ?? 20;
if (view === "cc") {
const searchParams = new URLSearchParams({ corpId });
searchParams.append("join", "flowId.id,nodeState,/flow/v2/backlogs/state");
const state = options.read ? "READ" : "UNREAD";
const response = await client.post("api/flow/v2/carbonCopy/search", {
searchParams,
json: {
filterBy: `(state.in(\"${state}\"))&&((type != \"permit\"))`,
limit: { start, count },
select: selectForCarbonCopy(),
orderBy: [{ value: "updateTime", order: "ASC" }],
},
});
const json = (await response.json()) as { count?: number; items?: Record<string, unknown>[] };
return { count: json.count ?? json.items?.length ?? 0, items: json.items ?? [] };
}
if (view === "approved") {
const response = await client.post("api/flow/v1/flows/approved", {
searchParams: {
+2 -1
View File
@@ -1,6 +1,6 @@
import { z } from "zod";
export const TaskViewSchema = z.enum(["todo", "approved", "processed"]);
export const TaskViewSchema = z.enum(["todo", "approved", "processed", "cc"]);
export type TaskView = z.infer<typeof TaskViewSchema>;
export interface TaskQueryOptions {
@@ -9,6 +9,7 @@ export interface TaskQueryOptions {
from?: number;
to?: number;
staffId?: string;
read?: boolean;
}
export interface TaskPerson {