Merge branch 'dev' into runny827

feat(training): 新增精益培训视频与周任务管理

# Conflicts:
#	backend/app/models/__init__.py
This commit is contained in:
runny committed 2026-09-08 18:30:09 +08:00
1 parent 85d27e9ffa
commit 91b7233872
812 files changed
+73763 -18908

No files matched your search

+15 -12
View File
@@ -541,11 +541,11 @@ export const patchWorkspaceShippingOrderReviewHeaderField = (
{ method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload) },
);
/** 保存一个复核订单行字段;line_key 仅接受当前 Case DTO 返回的稳定标识。 */
/** 保存一个复核订单行字段;draft_line_id 仅接受当前 Case DTO 返回的草稿身份。 */
export const patchWorkspaceShippingOrderReviewLineField = (
caseNo: string, lineKey: string, fieldId: string, payload: ShippingOrderReviewDraftWrite,
caseNo: string, draftLineId: string, fieldId: string, payload: ShippingOrderReviewDraftWrite,
) => requestJson<ShippingOrderReviewCase>(
`/api/workspace/shipping-notice/order-review-cases/${encodeURIComponent(caseNo)}/draft/lines/${encodeURIComponent(lineKey)}/fields/${encodeURIComponent(fieldId)}`,
`/api/workspace/shipping-notice/order-review-cases/${encodeURIComponent(caseNo)}/draft/lines/${encodeURIComponent(draftLineId)}/fields/${encodeURIComponent(fieldId)}`,
{ method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload) },
);
@@ -555,15 +555,15 @@ export const addWorkspaceShippingOrderReviewLine = (caseNo: string, expectedDraf
{ method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ expected_draft_version: expectedDraftVersion }) },
);
export const copyWorkspaceShippingOrderReviewLine = (caseNo: string, lineKey: string, expectedDraftVersion: number) =>
export const copyWorkspaceShippingOrderReviewLine = (caseNo: string, draftLineId: string, expectedDraftVersion: number) =>
requestJson<ShippingOrderReviewCase>(
`/api/workspace/shipping-notice/order-review-cases/${encodeURIComponent(caseNo)}/draft/lines/${encodeURIComponent(lineKey)}/copy`,
`/api/workspace/shipping-notice/order-review-cases/${encodeURIComponent(caseNo)}/draft/lines/${encodeURIComponent(draftLineId)}/copy`,
{ method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ expected_draft_version: expectedDraftVersion }) },
);
export const deleteWorkspaceShippingOrderReviewLine = (caseNo: string, lineKey: string, expectedDraftVersion: number) =>
export const deleteWorkspaceShippingOrderReviewLine = (caseNo: string, draftLineId: string, expectedDraftVersion: number) =>
requestJson<ShippingOrderReviewCase>(
`/api/workspace/shipping-notice/order-review-cases/${encodeURIComponent(caseNo)}/draft/lines/${encodeURIComponent(lineKey)}`,
`/api/workspace/shipping-notice/order-review-cases/${encodeURIComponent(caseNo)}/draft/lines/${encodeURIComponent(draftLineId)}`,
{ method: 'DELETE', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ expected_draft_version: expectedDraftVersion }) },
);
@@ -598,7 +598,7 @@ export const retryWorkspaceShippingOrderStpAutoCreate = (caseNo: string) =>
* 为复核明细人工选定一个或多个已启用库存源候选。
* 核心逻辑:携带 expected_draft_version 乐观锁;服务端写入行级 inventory_routing 后重跑资格校验。
* @param caseNo - 复核 Case 编号
* @param lineKey - Draft 行稳定标识 line_key
* @param draftLineId - Draft 行稳定标识 draft_line_id
* @param payload - 候选编码与强制说明
*/
/**
@@ -619,7 +619,7 @@ export const getWorkspaceTaskInventoryCandidates = (
/**
* 重新匹配整单或指定明细的库存路由规则。
* 核心逻辑:携带 expected_draft_version 与幂等键;可选 line_key 限定单行。
* 核心逻辑:携带 expected_draft_version 与幂等键;可选 draft_line_id 限定单行。
* @param caseNo - 复核 Case 编号
* @param payload - 版本锁、幂等键与可选行键
*/
@@ -905,7 +905,7 @@ export const listWorkspaceShippingOrderReviewAuditTimeline = (
export const decideWorkspaceShippingOrderReviewLineFulfillment = (
caseNo: string,
payload: {
line_key: string;
draft_line_id: string;
decision_code: ShippingOrderReviewLineFulfillmentDecisionCode | string;
reason?: string;
release_field_values?: Record<string, string>;
@@ -927,7 +927,7 @@ export const decideWorkspaceShippingOrderReviewLineFulfillment = (
export const waveWorkspaceShippingOrderReviewLineFulfillment = (
caseNo: string,
payload: {
line_keys: string[];
snapshot_line_ids: number[];
expected_draft_version: number;
idempotency_key: string;
reason?: string;
@@ -939,6 +939,9 @@ export const waveWorkspaceShippingOrderReviewLineFulfillment = (
task_no?: string | null;
wave_no?: number | null;
notice_no?: string | null;
/** 是否已调度异步后置波次推进(生成 Excel → OT 进入货代上传);前端据此决定是否起投影轮询。 */
auto_progress_started?: boolean;
confirm_outcome?: string;
}>(
`/api/workspace/shipping-notice/order-review-cases/${encodeURIComponent(caseNo)}/line-fulfillment/wave`,
{
@@ -958,7 +961,7 @@ export const closeWorkspaceShippingOrderReviewLineFulfillment = (
caseNo: string,
payload: {
reason: string;
line_keys?: string[];
draft_line_ids?: string[];
expected_draft_version?: number;
},
) => requestJson<{
@@ -0,0 +1,78 @@
/**
* features/chat/api/transfer.api.spec.ts
* 用途:锁定在途仓自动调拨 JSON POST 请求头契约——必须携带 Content-Type: application/json,
* 否则后端 Flask request.get_json 解析不到 body,导致默认 source_codes=[] 返回 400。
* 依赖:Vitest、vi.mock(@/shared/api/client)、transfer.api、getAuthHeaders。
* 逻辑:POST(create/execute/cancel/retry/manual-close)断言 headers 含 application/json,
* 且 body 序列化正确;GET/blob 端点不强制 Content-Type。
*/
import { beforeEach, describe, expect, it, vi } from 'vitest';
const requestJson = vi.hoisted(() => vi.fn());
const requestBlob = vi.hoisted(() => vi.fn());
vi.mock('@/shared/api/client', () => ({
BusinessError: class BusinessError extends Error {},
requestJson,
requestBlob,
}));
vi.mock('@/shared/utils/auth', () => ({
getAuthHeaders: () => ({ Authorization: 'Bearer TEST-TOKEN' }),
}));
import {
cancelTransferRun,
createTransferPrecheck,
executeTransferPrecheck,
getTransferBacklogSummary,
getTransferPrecheck,
getTransferRun,
listTransferSources,
manualCloseTransferItem,
retryTransferItem,
} from './transfer.api';
describe('transfer.api JSON request contract', () => {
beforeEach(() => {
requestJson.mockReset();
requestBlob.mockReset();
});
it('创建预检 POST 带 Content-Type: application/json 与序列化 source_codes', () => {
createTransferPrecheck({ source_codes: ['DBS-AWSBI'], business_date: '2026-08-18' });
const [url, init] = requestJson.mock.calls[0] as [string, RequestInit];
expect(url).toBe('/api/in-transit-transfer/prechecks');
expect(init.method).toBe('POST');
expect((init.headers as Record<string, string>)['Content-Type']).toBe('application/json');
expect(init.body).toBe(JSON.stringify({ source_codes: ['DBS-AWSBI'], business_date: '2026-08-18' }));
});
it('直接生成调拨单 POST 带 application/json', () => {
executeTransferPrecheck('TPC-1', ['INV-001']);
const [, init] = requestJson.mock.calls[0] as [string, RequestInit];
expect(init.method).toBe('POST');
expect((init.headers as Record<string, string>)['Content-Type']).toBe('application/json');
expect(init.body).toBe(JSON.stringify({ invoice_nos: ['INV-001'] }));
});
it('重试/关闭/取消 POST 带 application/json', () => {
retryTransferItem(7);
manualCloseTransferItem(7, '线下已处理');
cancelTransferRun('RUN-1', '紧急');
for (const [, init] of requestJson.mock.calls as [string, RequestInit][]) {
expect(init.method).toBe('POST');
expect((init.headers as Record<string, string>)['Content-Type']).toBe('application/json');
}
});
it('GET 端点只需鉴权头,不需要强制 Content-Type', () => {
getTransferPrecheck('TPC-1');
getTransferRun('RUN-1');
getTransferBacklogSummary();
listTransferSources();
for (const [, init] of requestJson.mock.calls as [string, RequestInit][]) {
expect(init.headers).toBeDefined();
}
});
});
@@ -0,0 +1,112 @@
/**
* features/chat/api/transfer.api.ts
* 用途:在途仓自动调拨 API 客户端(统一 requestJson / requestBlob,不重复造客户端)。
* 依赖:@/shared/api/client(requestJson / requestBlob / BusinessError)、getAuthHeaders。
* 逻辑:薄封装后端 /api/in-transit-transfer 全部端点;二进制下载走 requestBlob。
*/
import { requestBlob, requestJson } from '@/shared/api/client';
import { getAuthHeaders } from '@/shared/utils/auth';
import type {
TransferActionResult,
TransferBacklogItem,
TransferBacklogSummary,
TransferExecuteResponse,
TransferPrecheckDetail,
TransferPrecheckSummary,
TransferRunResult,
TransferSourceFileStatus,
TransferSourceOption,
} from '../types/transfer.types';
const BASE = '/api/in-transit-transfer';
/** JSON 请求头:除鉴权外必须带 Content-Type: application/json,否则 Flask request.get_json 解析不到 body。 */
const jsonHeaders = () => ({ 'Content-Type': 'application/json', ...getAuthHeaders() });
export interface CreatePrecheckPayload {
source_codes: string[];
business_date?: string;
}
/** 创建预检(只读) */
export const createTransferPrecheck = (payload: CreatePrecheckPayload) =>
requestJson<TransferPrecheckSummary>(BASE + '/prechecks', {
method: 'POST',
headers: jsonHeaders(),
body: JSON.stringify(payload),
});
/** 恢复预检进度与明细 */
export const getTransferPrecheck = (precheckId: string) =>
requestJson<TransferPrecheckDetail>(`${BASE}/prechecks/${precheckId}`, {
headers: getAuthHeaders(),
});
/** 确认选择范围并直接生成执行 Run */
export const executeTransferPrecheck = (precheckId: string, invoiceNos: string[]) =>
requestJson<TransferExecuteResponse>(`${BASE}/prechecks/${precheckId}/execute`, {
method: 'POST',
headers: jsonHeaders(),
body: JSON.stringify({ invoice_nos: invoiceNos }),
});
/** 恢复 Run 最终结果 */
export const getTransferRun = (runNo: string) =>
requestJson<TransferRunResult>(`${BASE}/runs/${runNo}`, {
headers: getAuthHeaders(),
});
/** 请求停止剩余任务 */
export const cancelTransferRun = (runNo: string, reason: string) =>
requestJson<TransferActionResult>(`${BASE}/runs/${runNo}/cancel`, {
method: 'POST',
headers: jsonHeaders(),
body: JSON.stringify({ reason }),
});
/** 人工重试异常项(仅重新查询 ERP,新 Attempt) */
export const retryTransferItem = (itemId: number) =>
requestJson<TransferActionResult>(`${BASE}/items/${itemId}/retry`, {
method: 'POST',
headers: jsonHeaders(),
body: JSON.stringify({ kind: 'erp_recheck' }),
});
/** 人工关闭异常项 */
export const manualCloseTransferItem = (itemId: number, reason: string) =>
requestJson<TransferActionResult>(`${BASE}/items/${itemId}/manual-close`, {
method: 'POST',
headers: jsonHeaders(),
body: JSON.stringify({ reason }),
});
/** 下载收料来源文件(zip) */
export const downloadTransferReceiptFiles = (runNo: string) =>
requestBlob(`${BASE}/runs/${runNo}/receipt-files`, { headers: getAuthHeaders() });
/** 下载预检冻结的 ERP 库存表(csv) */
export const downloadTransferErpInventory = (runNo: string) =>
requestBlob(`${BASE}/runs/${runNo}/erp-inventory`, { headers: getAuthHeaders() });
/** 下载七 Sheet 异常 Excel */
export const downloadTransferExceptions = (runNo: string) =>
requestBlob(`${BASE}/runs/${runNo}/exceptions.xlsx`, { headers: getAuthHeaders() });
/** 待处理异常列表(可恢复/已关闭/结果未知 + 老化等级) */
export const listTransferBacklog = () =>
requestJson<TransferBacklogItem[]>(`${BASE}/backlog`, { headers: getAuthHeaders() });
/** 待处理异常汇总(含 3/5/7 天老化分级) */
export const getTransferBacklogSummary = () =>
requestJson<TransferBacklogSummary>(`${BASE}/backlog/summary`, { headers: getAuthHeaders() });
/** 来源实例列表(平台 DBS/Crane 仅分组,每来源附收料文件状态) */
export const listTransferSources = () =>
requestJson<TransferSourceOption[]>(`${BASE}/sources`, { headers: getAuthHeaders() });
/** 对指定来源重新触发一次收料 RPA 抓取 */
export const retryTransferSourceRpa = (sourceCode: string) =>
requestJson<TransferSourceFileStatus>(`${BASE}/sources/${encodeURIComponent(sourceCode)}/retry-rpa`, {
method: 'POST',
headers: jsonHeaders(),
});