复用行内「拍照」按钮,上传出库照后用第 1 张照片让 AI 只读生产日期(不认商品名),按 production_date 匹配本行候选批次:唯一命中则先取该批次、余量按 FIFO 补,并在同一个「调整批次」弹窗里高亮该行;多命中/无命中/日期为 null 回退 FIFO。无论是否匹配都打开同一弹窗,未配多模态或识别失败静默降级为手动选批次,不阻断分拣。 - 后端: 提示词 picking.batch.production_date、解析纯函数 parseProductionDateJson、服务 pickingBatchDateService、路由 POST /mobile/picking/recognize-production-date - 小程序: request.recognizePickingProductionDate;抽出 buildEditorState 与 openBatchEditor 共用;新增 .batch-row-ai 高亮 - 零新增界面文案;登记 AI-30;补设计文档与契约测试
47 lines
2.2 KiB
TypeScript
47 lines
2.2 KiB
TypeScript
/**
|
||
* 分拣 · 拍包装读**生产日期**(用于按生产日期匹配出库批次)。
|
||
*
|
||
* 背景(2026-10-15 开发者):供应商的货放久了,拣货员不知道手上这件是哪一批次 ⇒
|
||
* 拍照 → AI 只产出**生产日期**(商品名不必识别,因为就是当前分拣的那件)→ 界面拿它去
|
||
* `listPickingOutboundBatches` 返回的批次里按 `production_date` 比对,命中就预选该批次,
|
||
* 未命中/多个同日期的就由拣货员在同一个批次弹窗里手动选。
|
||
*
|
||
* 设计:docs/design/20261015-分拣拍照识别生产日期对批次.md
|
||
* AI 登记:docs/design/20260929-AI门槛与计量登记表.md(AI-30)
|
||
*/
|
||
import { buildWeighStationLlmOptions, callWithImage, hasRuntimeConfig } from './llmService';
|
||
import { resolvePrompt } from './promptRegistryService';
|
||
import { parseProductionDateJson } from '../utils/shelfLife';
|
||
|
||
export interface RecognizedProductionDate {
|
||
/** `YYYY-MM-DD`;识别不出/没配置多模态 ⇒ null */
|
||
production_date: string | null;
|
||
/** 是否真的调了模型(false = 未配置,界面照旧手动选批次) */
|
||
recognized: boolean;
|
||
}
|
||
|
||
/** 从模型输出里抠出 `{production_date}` —— 实现已移到 `utils/shelfLife.ts`(纯函数,单测更轻) */
|
||
|
||
/**
|
||
* 拍一张包装照 → 生产日期(`YYYY-MM-DD`)或 null。
|
||
* 未配置多模态模型时**不报错**:返回 `recognized: false` 让界面走手动选批次(不阻断分拣)。
|
||
*/
|
||
export async function recognizeProductionDateFromImage(input: {
|
||
branchCode?: string | null;
|
||
content: string;
|
||
ext?: string;
|
||
}): Promise<RecognizedProductionDate> {
|
||
const content = String(input.content || '').trim();
|
||
if (!content) {
|
||
throw Object.assign(new Error('缺少照片内容'), { status: 400 });
|
||
}
|
||
const branchCode = input.branchCode ? String(input.branchCode) : null;
|
||
const options = buildWeighStationLlmOptions(branchCode);
|
||
if (!(await hasRuntimeConfig(options))) {
|
||
return { production_date: null, recognized: false };
|
||
}
|
||
const resolved = await resolvePrompt('picking.batch.production_date', { branchCode });
|
||
const raw = await callWithImage(resolved.systemPrompt, content, options);
|
||
return { production_date: parseProductionDateJson(raw), recognized: true };
|
||
}
|