feat(shipping-notice): 增强订单文档 Profile 管理功能,新增复核与草稿管理

- 添加订单复核相关模型及 API,支持复核案例的创建、更新和确认
- 实现复核草稿的管理功能,允许用户对复核内容进行编辑和保存
- 引入复核事件审计,确保复核过程的可追溯性
- 更新数据库模型以支持复核和草稿的关系管理
- 完善相关服务逻辑,确保复核与草稿的状态管理和数据一致性
- 增强文档模板的管理能力,支持更复杂的业务场景
This commit is contained in:
hugo committed 2026-07-29 09:50:25 +08:00
1 parent 61ac6403c4
commit b7307fc573
147 files changed
+15108 -1522

No files matched your search

@@ -8,10 +8,14 @@ import { computeNoticeFilesContentFingerprint } from './shippingNoticeBatchIdemp
describe('shippingNoticeBatchIdempotency', () => {
it('treats duplicate files as one content set', async () => {
const content = 'same-notice-content';
const single = new File([content], 'a.txt', { type: 'text/plain' });
const createFile = (name: string) => ({
name,
arrayBuffer: async () => new TextEncoder().encode(content),
}) as File;
const single = createFile('a.txt');
const duplicatePair = [
new File([content], 'a.txt', { type: 'text/plain' }),
new File([content], 'b.txt', { type: 'text/plain' }),
createFile('a.txt'),
createFile('b.txt'),
];
const singleFp = await computeNoticeFilesContentFingerprint([single]);
@@ -1,6 +1,6 @@
/**
* features/chat/shipping/useChatShippingSendHandler.spec.ts
* 用途:验证阶段 2 发送语义,只冻结当前输入框这批 Intake,并允许空备注启动识别。
* 用途:验证阶段 2 发送语义,只冻结当前输入框这批 Intake,并为仅附件发送补充用户可见的默认请求。
*/
import { computed, ref } from 'vue';
import { beforeEach, describe, expect, it, vi } from 'vitest';
@@ -149,7 +149,7 @@ describe('useChatShippingSendHandler', () => {
expect(attachments.value).toEqual([laterNotice, otherAttachment]);
});
it('allows an empty note when the user only authorizes attachment analysis', async () => {
it('adds a visible default request when the user only sends attachments', async () => {
const startOrderExtractionRun = vi.fn(async () => true);
const ctx = createContext({
attachments: ref([{
@@ -174,7 +174,7 @@ describe('useChatShippingSendHandler', () => {
expect(consumed).toBe(true);
expect(startOrderExtractionRun).toHaveBeenCalledWith(
'',
'chat.shippingOrderExtractionDefaultUserMessage',
['SNI-EMPTY-NOTE'],
[{
name: 'orders.eml',
@@ -236,8 +236,8 @@ export function createShippingSendHandlers(ctx: ShippingSendHandlerContext) {
&& submittedIntakes.has(item.intakeNo.trim().toUpperCase()),
),
);
// 阶段 2:发送是“授权开始识别”,备注允许为空,不能再偷偷注入默认提示词。
const query = trimmed;
// 阶段 2:空备注补充用户可见的默认请求,便于会话记录与审计;不改变 Worker 的确定性识别流程。
const query = trimmed || ctx.t('chat.shippingOrderExtractionDefaultUserMessage');
ctx.shippingAutoFlowRequested.value = false;
if (typeof textOrEvent !== 'string') ctx.input.value = '';
try {
@@ -68,7 +68,7 @@ describe('shipping notice order extraction state', () => {
expect(resolveShippingOrderExtractionStatus(undefined, 'not_started')).toBe('not_started');
});
it('restores in-progress, retryable, and pending-candidate attachments into the input area', () => {
it('restores only in-progress and retryable attachments into the input area', () => {
expect(shouldRestoreShippingNoticeIntake('queued')).toBe(true);
expect(shouldRestoreShippingNoticeIntake('parsing')).toBe(true);
expect(shouldRestoreShippingNoticeIntake('parse_failed')).toBe(true);
@@ -78,15 +78,15 @@ describe('shipping notice order extraction state', () => {
attachment_directory_complete: true,
})).toBe(true);
expect(shouldRestoreShippingNoticeIntake('parsed', 'failed', 0)).toBe(true);
expect(shouldRestoreShippingNoticeIntake('parsed', 'partially_completed', 2)).toBe(true);
expect(shouldRestoreShippingNoticeIntake('parsed', 'not_started', 0, {
preview_status: 'directory_incomplete',
ready_for_extraction: false,
attachment_directory_complete: false,
})).toBe(false);
// 已完成且没有待审核 Candidate 的文件仅保留在用户消息气泡中。
// 已发送的终态文件(包括待人工复核)仅保留在用户消息气泡和结果卡中。
expect(shouldRestoreShippingNoticeIntake('parsed', 'completed')).toBe(false);
expect(shouldRestoreShippingNoticeIntake('parsed', 'partially_completed', 2)).toBe(false);
expect(shouldRestoreShippingNoticeIntake('parsed', 'partially_completed', 0)).toBe(false);
expect(shouldRestoreShippingNoticeIntake('parsed', 'completed', 2)).toBe(false);
expect(shouldRestoreShippingNoticeIntake('consumed')).toBe(false);
@@ -41,16 +41,16 @@ const ACTIVE_ORDER_EXTRACTION = new Set(['extracting']);
* 判断服务端 Intake 是否应恢复到输入栏。
* AI 触发时机:无;页面刷新或重新打开会话时调用。
* 上传快览与发送授权已拆分:未发送但已快览成功的附件,刷新后也必须恢复到输入栏;
* 已进入订单抽取终态的附件仅保留在消息气泡中,避免把旧批次误带回当前输入框。
* 已进入订单抽取终态(包括待人工复核)的附件仅保留在消息气泡和结果卡中,
* 避免把已发送的旧批次误带回当前输入框。
* @param parseStatus - 服务端返回的预解析状态。
* @param orderExtractionStatus - 服务端返回的订单抽取状态。
* @param candidateCount - 当前仍可审核的订单 Candidate 数量。
* @returns 是否恢复为待发送附件卡片
*/
export function shouldRestoreShippingNoticeIntake(
parseStatus: string | null | undefined,
orderExtractionStatus?: string | null,
candidateCount = 0,
_candidateCount = 0,
parseSummary?: ShippingNoticePendingAttachment['parseSummary'],
): boolean {
const status = String(parseStatus || '').trim().toLowerCase();
@@ -62,8 +62,7 @@ export function shouldRestoreShippingNoticeIntake(
&& (!extractionStatus || extractionStatus === 'not_started')
&& !isShippingNoticeAttachmentParseIncomplete(parseSummary)
)
|| extractionStatus === 'failed'
|| (extractionStatus === 'partially_completed' && candidateCount > 0);
|| extractionStatus === 'failed';
}
/** 判断 Intake 是否仍需轮询上传预处理或订单抽取状态。 */
@@ -582,19 +581,6 @@ export function useShippingNoticeIntakes(options: UseShippingNoticeIntakesOption
}
};
/** 保存 Candidate 人工修订后的订单摘要。 */
const updateCandidateSummary = async (candidateNo: string, businessSummary: Record<string, unknown>) => {
const remote = await updateShippingNoticeCandidate(candidateNo, { business_summary: businessSummary });
for (const attachment of noticeAttachments.value) {
if (!(attachment.candidates || []).some((item) => item.candidateNo === candidateNo)) continue;
patchAttachment(attachment.id, {
candidates: (attachment.candidates || []).map((item) =>
item.candidateNo === candidateNo ? mapServerCandidate(remote) : item,
),
});
}
};
/** 人工采纳已复核的 Dify Candidate;后端决定是否已满足履约门禁。 */
const promoteCandidate = async (candidateNo: string) => {
const remote = await promoteShippingNoticeCandidate(candidateNo);
@@ -667,7 +653,6 @@ export function useShippingNoticeIntakes(options: UseShippingNoticeIntakesOption
resolveDuplicateAttachment,
resolveCandidateDuplicate,
setCandidateSelected,
updateCandidateSummary,
promoteCandidate,
rejectCandidate,
getParsedIntakeNos,