feat(assist-platform): adapt to live assist backend query and id dialect
- Support filterBy in corporation search for server-side name/id resolution - Normalize corporation ID with leading dollar prefix for detail and ticket endpoints - Include required query object in ticket search payloads - Improve ticket status mapping for live numeric states - Rebuild plugin mcp bundle
This commit is contained in:
1 parent
37cf784ba1
commit
35552944d1
6 files changed
+47
-17
No files matched your search
@@ -45,7 +45,13 @@ export async function handleTickets(
|
||||
t.ticketId,
|
||||
t.applicant,
|
||||
t.principal || "-",
|
||||
t.state === "已提供" ? "🟢 已提供" : t.state === "待提供" ? "🟡 待提供" : t.state === "已过期" ? "⚪ 已过期" : t.state,
|
||||
t.state === "已提供" || t.state === "1"
|
||||
? "🟢 生效中"
|
||||
: t.state === "待提供" || t.state === "0"
|
||||
? "🟡 待提供"
|
||||
: t.state === "已过期" || t.state === "2"
|
||||
? "⚪ 已结束"
|
||||
: t.state,
|
||||
t.duration ? `${t.duration}h` : "-",
|
||||
t.usePeriodDesc || (t.startTime && t.endTime ? `${new Date(t.startTime).toLocaleDateString()} - ${new Date(t.endTime).toLocaleDateString()}` : "-"),
|
||||
]);
|
||||
|
||||
@@ -155,10 +155,11 @@ export async function fetchHoseOpenApiAccessToken(params: {
|
||||
);
|
||||
}
|
||||
|
||||
const token = res.value?.accessToken ?? res.accessToken ?? res.token;
|
||||
if (!token) {
|
||||
const rawToken = res.value?.accessToken ?? res.accessToken ?? res.token;
|
||||
if (!rawToken) {
|
||||
throw new AuthenticationError("合思 OpenAPI getAccessToken 未返回有效 accessToken");
|
||||
}
|
||||
const token = decodeURIComponent(rawToken);
|
||||
|
||||
openapiV1TokenCache.set(cacheKey, {
|
||||
token,
|
||||
|
||||
@@ -31,11 +31,18 @@ export async function searchCorporationsApi(
|
||||
count: params.limit?.count ?? 20,
|
||||
},
|
||||
};
|
||||
|
||||
const conditions: string[] = [];
|
||||
if (params.keyword?.trim()) {
|
||||
requestBody.keyword = params.keyword.trim();
|
||||
const kw = params.keyword.trim().replace(/"/g, '\\"');
|
||||
conditions.push(`(id == "${kw}" || name == "${kw}")`);
|
||||
}
|
||||
if (params.state?.trim()) {
|
||||
requestBody.state = params.state.trim();
|
||||
const st = params.state.trim().replace(/"/g, '\\"');
|
||||
conditions.push(`state == "${st}"`);
|
||||
}
|
||||
if (conditions.length > 0) {
|
||||
requestBody.filterBy = conditions.join(" && ");
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -65,9 +72,12 @@ export async function getCorporationDetailApi(
|
||||
throw new BusinessError("必须指定企业 ID");
|
||||
}
|
||||
|
||||
const cleanId = corpId.trim();
|
||||
const normalizedId = cleanId.startsWith("$") ? cleanId : `$${cleanId}`;
|
||||
|
||||
try {
|
||||
const res = await client
|
||||
.get(`corporation/${encodeURIComponent(corpId.trim())}/getCorporationDetail`)
|
||||
.get(`corporation/${encodeURIComponent(normalizedId)}/getCorporationDetail`)
|
||||
.json<{ items?: CorporationDetail[] }>();
|
||||
|
||||
const detail = res.items?.[0];
|
||||
@@ -93,10 +103,13 @@ export async function searchAssistTicketsApi(
|
||||
throw new BusinessError("必须指定企业 ID");
|
||||
}
|
||||
|
||||
const cleanId = corpId.trim();
|
||||
const normalizedId = cleanId.startsWith("$") ? cleanId : `$${cleanId}`;
|
||||
|
||||
try {
|
||||
const res = await client
|
||||
.post(`assistPlatform/${encodeURIComponent(corpId.trim())}/search`, {
|
||||
json: {},
|
||||
.post(`assistPlatform/${encodeURIComponent(normalizedId)}/search`, {
|
||||
json: { query: {} },
|
||||
})
|
||||
.json<{ items?: Array<Record<string, unknown>> }>();
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ describe("domains/assist-platform - 协助平台业务编排", () => {
|
||||
expect(req.url).toContain("corporation/search");
|
||||
const body = (await req.json()) as any;
|
||||
expect(body.limit.count).toBe(10);
|
||||
expect(body.filterBy).toContain('name == "CSM"');
|
||||
return Response.json({
|
||||
count: 1,
|
||||
items: [
|
||||
@@ -50,7 +51,7 @@ describe("domains/assist-platform - 协助平台业务编排", () => {
|
||||
|
||||
it("getCorporationDetail 返回企业详细配置", async () => {
|
||||
const client = createMockClient(async (req) => {
|
||||
expect(req.url).toContain("corporation/Cxa3oOtQi2eS%24g/getCorporationDetail");
|
||||
expect(req.url).toContain("corporation/%24Cxa3oOtQi2eS%24g/getCorporationDetail");
|
||||
return Response.json({
|
||||
items: [
|
||||
{
|
||||
@@ -70,7 +71,7 @@ describe("domains/assist-platform - 协助平台业务编排", () => {
|
||||
|
||||
it("listAssistTickets 正确映射工单时间、申请人与授权码", async () => {
|
||||
const client = createMockClient(async (req) => {
|
||||
expect(req.url).toContain("assistPlatform/Cxa3oOtQi2eS%24g/search");
|
||||
expect(req.url).toContain("assistPlatform/%24Cxa3oOtQi2eS%24g/search");
|
||||
return Response.json({
|
||||
items: [
|
||||
{
|
||||
@@ -122,7 +123,7 @@ describe("domains/assist-platform - 协助平台业务编排", () => {
|
||||
it("generateAssistSession 管理员模式一键换取免密登录直通链接", async () => {
|
||||
const client = createMockClient(async (req) => {
|
||||
const url = req.url;
|
||||
if (url.includes("assistPlatform/Cxa3oOtQi2eS%24g/search")) {
|
||||
if (url.includes("assistPlatform/%24Cxa3oOtQi2eS%24g/search") || url.includes("assistPlatform/Cxa3oOtQi2eS%24g/search")) {
|
||||
return Response.json({
|
||||
items: [{ ticketId: "ID01Xeh99QmgQn", applicant: "李志财", state: "已提供" }],
|
||||
});
|
||||
@@ -155,7 +156,7 @@ describe("domains/assist-platform - 协助平台业务编排", () => {
|
||||
it("generateAssistSession 用户模式自动定位 staffId 换取免密链接", async () => {
|
||||
const client = createMockClient(async (req) => {
|
||||
const url = req.url;
|
||||
if (url.includes("assistPlatform/Cxa3oOtQi2eS%24g/search")) {
|
||||
if (url.includes("assistPlatform/%24Cxa3oOtQi2eS%24g/search") || url.includes("assistPlatform/Cxa3oOtQi2eS%24g/search")) {
|
||||
return Response.json({
|
||||
items: [{ ticketId: "ID01Xeh99QmgQn", applicant: "李志财", state: "已提供" }],
|
||||
});
|
||||
|
||||
@@ -74,7 +74,13 @@ export async function generateAssistSession(
|
||||
}
|
||||
|
||||
const activeTicket =
|
||||
tickets.find((t) => t.state === "已提供" || t.state === "待提供") ?? tickets[0];
|
||||
tickets.find(
|
||||
(t) =>
|
||||
t.state === "已提供" ||
|
||||
t.state === "待提供" ||
|
||||
t.state === "1" ||
|
||||
t.state === "生效中"
|
||||
) ?? tickets[0];
|
||||
|
||||
if (!activeTicket || !activeTicket.ticketId) {
|
||||
throw new NotFoundError(`企业 [${corpId}] 暂无可用状态的协助授权工单`);
|
||||
@@ -82,7 +88,10 @@ export async function generateAssistSession(
|
||||
ticketId = activeTicket.ticketId;
|
||||
}
|
||||
|
||||
const isAdmin = params.isAdmin !== false;
|
||||
const isAdmin =
|
||||
params.isAdmin !== undefined
|
||||
? params.isAdmin
|
||||
: !(params.staffId || params.staffName);
|
||||
let resolvedStaffId = params.staffId?.trim();
|
||||
let resolvedStaffName = params.staffName?.trim();
|
||||
|
||||
|
||||
Reference in new issue
Block a user