订单入库: 补规格/生产日期/保质期/产地 + 拍照改识别 + 去 AI 判定
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s

开发者:入库要填规格(商品有就带过去)/生产日期/保质期/生产地区,让仓库侧数据全;「拍照鉴别是否合格」去掉但代码别删;照片改为识别商品信息(复用库存入库那套);结果默认为合格、前端隐式。

- 卡片新增 card-r3:规格/生产日期/保质期/产地(选填);规格由商品库 skus.spec 预填(列表带出)
- 拍照改走 recognizeStockInboundLines(/mobile/inventory/recognize-lines)预填四字段(只补空)
- 去掉 AI 判定:不再调 analyzeInspectionQuality(代码/prompt 保留);去掉 ai-verdict 与结果 picker;移除 !aiDone 入库闸门
- 入库写 inventory.shelf_life + expiry_date(deriveExpiryDate);人工改过的规格/产地才回写 product_catalog.spec/skus.origin(applyArchiveWriteback,同事务)
- 新增契约测试 inspectionInboundFields

注:『合格才入库/须拍照/退回』门槛未动;SQL 无迁移(inventory.shelf_life/expiry_date 既有列)。
This commit is contained in:
雨天
2026-10-16 17:37:02 +08:00
parent 48168925d6
commit deeaf2c3d5
8 changed files with 250 additions and 41 deletions
@@ -2,8 +2,9 @@
> 2026-10-16 v1(补字段)→ **v2 扩写**(开发者追加):「当前入库时需要填写规格(商品有就带过去)、生产日期、保质期、生产地区……那个**拍照鉴别是否合格去掉**,但是**代码别删**,相当于不需要拍照鉴别是否合格了,应该是**拍照识别商品信息**类似于**库存入库的那套逻辑**」。
>
> **本轮先出设计、不写代码**:本需求要动 **验收链路的库存写入 + 商品档案回写 + AI 出口**(三处冻结面),
> 且卡面会变高、照片职责会变 —— 需先定口径与版式,见 §4「待你拍板」。
> **状态:已实现(v3,2026-10-16)**。开发者:「相当于就是默认为合格就行 前端这边隐式展示为合格 你先按照你的理解开工搭建界面我后面来验收」⇒ 按 §4 默认实现(小程序卡片 + 入库写入 + 拍照识别 + 去 AI 判定)。
>
> 背景:本需求要动 **验收链路的库存写入 + 商品档案回写 + AI 出口**(三处冻结面),且卡面会变高、照片职责会变。
## 1. 需求
@@ -66,7 +67,7 @@
- 「结果」仍需**人工选定**(默认「合格」,可改「不合格」→ 退回);`确认入库` / `退回` 门槛、服务端 `inspection_photo_required` 与「合格才能入库」**一概不动**。
- AI 成本:少一次图片 LLM 调用(`inspection.quality.photo`)。
## 4. 待你拍板(附我的默认)
## 4. 口径(已按默认实现)
| # | 问题 | 我的默认 |
| --- | --- | --- |
@@ -105,3 +106,4 @@
| --- | --- | --- |
| v1 | 2026-10-16 | 首版(补规格/生产日期/保质期/产地;含 §4 七项待拍板、§5 冻结面) |
| v2 | 2026-10-16 | 扩写:**拍照改为识别商品信息**(复用库存入库那套,保住 `prepackaged_scan` 闸门)+ **去掉 AI 质量自动判定**(代码/prompt 保留);新增 §3.5/§3.6、§4-⑧⑨⑩⑪ |
| v3 | 2026-10-16 | 实现(按 §4 默认):① 卡片新增 规格/生产日期/保质期/产地 输入(`card-r3`,选填);② 拍照改走 `recognizeStockInboundLines` 预填四字段(只补空);③ 去掉 AI 判定(`analyzeInspectionQuality` 不再接,去掉 ai-verdict 与结果 picker,移除 `!aiDone` 闸门);④ 入库写 `inventory.shelf_life`/`expiry_date`(`deriveExpiryDate`)+ 人工改过时才回写 `product_catalog.spec`/`skus.origin`(`applyArchiveWriteback`);列表带出 `skus.spec` 预填规格 |
+1 -1
View File
@@ -57,7 +57,7 @@ AI 提示词清理已停用条目(7 条归档不删、清单过滤 archived、
订单入库任务卡**「退回」与「商品名」换位**(开发者:点「拍照」易误触「退回」)—— 第一行由 `[退回][商品名][确认入库]` 改为 **`[商品名][退回][确认入库]`**,使第一行左侧=商品名、不再与第二行左侧的「拍照」竖向对齐;退回/入库**语义、门槛、文案、样式一字未动**,见 [20261016-订单入库任务卡退回与品名换位.md](./20261016-订单入库任务卡退回与品名换位.md)。
订单入库**一键上传批次报告 → 提取生产日期 → 随入库落库**(设计草案,待开发者批准 §4 后编码):在「一键全部合格入库」下方加按钮,支持多张图/PDF,复用 AI-29 的 OCR(`quality.report.meta`)抽品名+生产日期,按商品名匹配**当前待验收行**,弹核对表让人改日期后关闭,入库时把日期写进 `inventory.production_date` 并把报告挂到新批次;**关键变更=验收普通行的生产日期由“今天”改为真实日期**(该列本就在写、只是取值只有预包装年月),见 [20261016-订单入库批量上传批次报告并落生产日期.md](./20261016-订单入库批量上传批次报告并落生产日期.md)。
订单入库点「**退回**」**先弹二次确认**(开发者:「点击后需要触发一个弹窗二次确认才行」)—— 退回不可逆(按不合格退回、不入库),现改为确定才置不合格并退供、取消则原地不动(4 行改动,退回语义一字未动;Web 验收页同位置未在本次范围),见 [20261016-订单入库退回二次确认.md](./20261016-订单入库退回二次确认.md)。
订单入库**改造:补字段(规格/生产日期/保质期/产地)+ 拍照改为识别商品信息(去掉质量自动判定)**(设计草案,待拍板 §4 后编码):① 对齐「库存入库」字段集,落点同口径——规格→`product_catalog.spec`(触发器同步 `skus.spec`)、产地→`skus.origin`(复用 `applyArchiveWriteback`,只回写人工改过的字段)、生产日期→`inventory.production_date`、保质期→`inventory.shelf_life` 并由生产日期+保质期推算 `expiry_date`(复用 `deriveExpiryDate`);⚠️ 验收链路现状**既不写 shelf_life/expiry 也不做档案回写**,本需求会新增这两类写入;② **拍照改为识别商品信息**(复用「库存入库」`stock_inbound.recognize.lines` 那套,预填四字段,**必须保住 `prepackaged_scan` 预包装闸门**);③ **去掉 AI 质量自动判定**(`analyzeInspectionQuality`/`inspection.quality.photo`,**代码与 prompt 保留不删**,不再是「拍照鉴别是否合格」;「合格才入库/须拍照/退回」门槛不动),见 [20261016-订单入库补规格生产日期保质期产地.md](./20261016-订单入库补规格生产日期保质期产地.md)。
订单入库**改造:补字段(规格/生产日期/保质期/产地)+ 拍照改为识别商品信息(去掉质量自动判定)**(**已实现**,2026-10-16):① 对齐「库存入库」字段集,落点同口径——规格→`product_catalog.spec`、产地→`skus.origin`(复用 `applyArchiveWriteback`,只回写人工改过的字段)、生产日期→`inventory.production_date`、保质期→`inventory.shelf_life` 并由生产日期+保质期推算 `expiry_date`(复用 `deriveExpiryDate`);② **拍照改为识别商品信息**(复用「库存入库」`stock_inbound.recognize.lines`,预填四字段、只补空,**保住 `prepackaged_scan` 预包装闸门**);③ **去掉 AI 质量自动判定**(`analyzeInspectionQuality`/`inspection.quality.photo` 不再接、**代码与 prompt 保留不删**;去掉 ai-verdict 与结果 picker,结果隐式合格;「合格才入库/须拍照/退回」门槛不动),见 [20261016-订单入库补规格生产日期保质期产地.md](./20261016-订单入库补规格生产日期保质期产地.md)。
订单详情**展示「商品规格」**(**已实现**,2026-10-16):录单已能填规格(`acb652d`)**但原先没落库**(`order_items` 无 spec 列、建单 INSERT 未包含)⇒ 加列 `order_items.spec VARCHAR(60)`(迁移 `20261050`)+ 建单写入,再在详情表(`OrderDetailDeliveryNotePanel.tsx`,**列对齐靠手写 colSpan**)商品名后加只读「规格」列(三语文案 `orders.detail.colSpec`);不动抵扣/成本/状态链,不新增表,见 [20261016-订单详情展示商品规格.md](./20261016-订单详情展示商品规格.md)。
采购页 / 供应商备货表**展示「商品规格」**(**已实现**,2026-10-16):两表**已有「商品描述」列**(= 规格 + 品牌)但取的是**商品库** `skus.spec`/`product_catalog.spec`、**没取录单写的 `order_items.spec`**(上一提交 `ff15808`)⇒ 商品库没维护规格时该列为空(截图显示 `-`);已**新增独立只读「规格」列**(商品名后,三语)。⚠️ **口径(开发者 2026-10-16 更正)**:**与订单详情一致**——只认订单行录单规格 `order_items.spec`(三处查询带出 `order_spec`/`order_item_spec`),**空 ⇒ 不显示,无商品库兜底**(v3 的兜底已撤);不改现「商品描述」(它还喂分组键/复制/导出),不动 `purchase_status` 与备货流转;导出同步本轮不做,见 [20261016-采购与备货表展示商品规格.md](./20261016-采购与备货表展示商品规格.md)。
小程序**自采列表展示「商品规格」**(**已实现**,2026-10-16):工作台「自采列表」= 组件 `purchase-today-panel`,取数走 `GET /mobile/purchase/orders`(共享 `PURCHASE_ORDER_DISPLAY_SELECT`)——已增 `order_spec`(**只取 `oi.spec` 录单规格,与订单详情一致;无商品库兜底**),卡片商品名下加一行灰字「规格:xxx」(有值才显示);不动分组键/数量单价/导出,见 [20261016-小程序自采列表展示商品规格.md](./20261016-小程序自采列表展示商品规格.md)。
@@ -7,7 +7,9 @@ const {
fetchStockInboundStorageZones,
uploadQualityReportStorageFile,
createInspectionBatchReports,
recognizeStockInboundLines,
} = require('../../utils/request');
const { buildArchivePayload } = require('../../utils/stockInboundArchive');
const { getSession } = require('../../utils/auth');
const { ensureMobileRole } = require('../../utils/roleGuard');
const { beginPanelShow, endPanelShow } = require('../../utils/panelShowGate');
@@ -80,6 +82,15 @@ function defaultRatingFromGrade(grade) {
return String(grade || '').trim().toUpperCase() === 'D' ? RESULT_FAIL : RESULT_PASS;
}
/** 识别结果 → 保质期原文(优先识别给的 shelf_life 原文;否则拼「数值+单位」) */
function composeShelfLifeText(item) {
const text = String((item && item.shelf_life) || '').trim();
if (text) return text;
const value = String((item && item.shelf_life_value) || '').trim();
const unit = String((item && item.shelf_life_unit) || '').trim();
return value && unit ? `${value}${unit}` : '';
}
function emptyAiFields() {
return {
aiDone: false,
@@ -414,6 +425,17 @@ Component({
prev && prev.production_date !== undefined ? prev.production_date : '',
batch_report_id:
prev && prev.batch_report_id !== undefined ? prev.batch_report_id : '',
// 规格 / 保质期 / 产地(2026-10-16 补齐):规格「商品有就带过去」= 商品库 skus.spec 预填
input_spec:
prev && prev.input_spec !== undefined
? prev.input_spec
: String(row.spec || '').trim(),
input_shelf_life:
prev && prev.input_shelf_life !== undefined ? prev.input_shelf_life : '',
input_origin:
prev && prev.input_origin !== undefined ? prev.input_origin : '',
specEdited: prev?.specEdited === true,
originEdited: prev?.originEdited === true,
zoneIndex: zoneIndexOf(
prev && prev.storage_zone !== undefined
? prev.storage_zone
@@ -684,6 +706,43 @@ Component({
}
},
/**
* 拍照后「识别商品信息」(2026-10-16,取代「拍照鉴别是否合格」):
* 复用库存入库那套识别,把 规格/生产日期/保质期/产地 **预填**到该行;**只补空、不覆盖已有值**。
* 识别失败不阻断入库(可人工填)。
*/
async runRecognizeForRow(id) {
const image = this._aiImageById && this._aiImageById[id];
if (!image) return;
const row = this.data.rows.find((item) => item.id === id) || {};
try {
const res = await recognizeStockInboundLines({ images_base64: [image] });
const data = (res && (res.data || res)) || {};
const items = Array.isArray(data.items) ? data.items : [];
const first = items[0] || null;
if (!first) return;
const patch = {};
const spec = String(first.spec || '').trim();
const origin = String(first.origin || '').trim();
const pd = String(first.production_date || '').trim().slice(0, 10);
const shelf = composeShelfLifeText(first);
if (spec && !String(row.input_spec || '').trim()) patch.input_spec = spec;
if (origin && !String(row.input_origin || '').trim()) patch.input_origin = origin;
if (/^\d{4}-\d{2}-\d{2}$/.test(pd) && !String(row.production_date || '').trim()) {
patch.production_date = pd;
}
if (shelf && !String(row.input_shelf_life || '').trim()) patch.input_shelf_life = shelf;
if (Object.keys(patch).length) {
this.patchRow(id, patch);
wx.showToast({ title: '已识别商品信息', icon: 'none' });
} else {
wx.showToast({ title: '未识别到新信息,可手动填写', icon: 'none' });
}
} catch (err) {
wx.showToast({ title: err.message || '识别失败,可手动填写', icon: 'none' });
}
},
async completeWithOverQty(payload) {
try {
const body = await completeInspection(payload);
@@ -705,10 +764,7 @@ Component({
const id = e.currentTarget.dataset.id;
const row = this.data.rows.find((item) => item.id === id);
if (row?.input_rating === RESULT_FAIL) {
await alertModal(
'当前为不合格',
'AI 判定为不合格。请先将结果改为合格,再点确认入库。'
);
await alertModal('当前为不合格', '请先将结果改为合格,再点确认入库。');
return;
}
await this.submitInspection(e);
@@ -794,6 +850,27 @@ Component({
this.patchRow(id, { production_month: value });
},
/** 规格(人工改过 ⇒ 标记回写档案) */
onSpecInput(e) {
this.patchRow(e.currentTarget.dataset.id, { input_spec: e.detail.value, specEdited: true });
},
/** 生产日期(手填,优先于批次报告/预包装年月) */
onProductionDateChange(e) {
const raw = String(e.detail.value || '').slice(0, 10);
this.patchRow(e.currentTarget.dataset.id, { production_date: raw });
},
/** 保质期(原文,如 7天/6个月;落 inventory.shelf_life 并推算效期) */
onShelfLifeInput(e) {
this.patchRow(e.currentTarget.dataset.id, { input_shelf_life: e.detail.value });
},
/** 生产产地(人工改过 ⇒ 标记回写档案 skus.origin) */
onOriginInput(e) {
this.patchRow(e.currentTarget.dataset.id, { input_origin: e.detail.value, originEdited: true });
},
choosePhoto(e) {
const id = e.currentTarget.dataset.id;
wx.chooseImage({
@@ -826,8 +903,8 @@ Component({
const rows = await this.loadRows();
const row = (rows || []).find((item) => item.id === id);
if (row?.photoRequired && Number(row.photoCount || 0) > 0) {
wx.showLoading({ title: 'AI分析中…', mask: true });
await this.runAiForRow(id);
wx.showLoading({ title: '识别中…', mask: true });
await this.runRecognizeForRow(id);
} else if (!(latestScan && latestScan.label_matched === false)) {
wx.showToast({ title: '拍照验收已上传', icon: 'success' });
}
@@ -875,8 +952,8 @@ Component({
const rows = await this.loadRows();
const row = (rows || []).find((item) => item.id === id);
if (row?.photoRequired && Number(row.photoCount || 0) > 0) {
wx.showLoading({ title: 'AI分析中…', mask: true });
await this.runAiForRow(id);
wx.showLoading({ title: '识别中…', mask: true });
await this.runRecognizeForRow(id);
} else {
wx.showToast({ title: '已删除', icon: 'success' });
}
@@ -1053,10 +1130,6 @@ Component({
wx.showToast({ title: '请先拍照验收', icon: 'none' });
return;
}
if (!rejectFulfillment && photoRequired && !row.aiDone) {
wx.showToast({ title: '请先完成 AI 质检', icon: 'none' });
return;
}
if (!rejectFulfillment && row?.requires_prepackaged_check) {
if (!row.production_month) {
@@ -1100,8 +1173,15 @@ Component({
loss_qty: 0,
storage_zone: String(row?.storage_zone || '').trim() || undefined,
production_date_month: row?.requires_prepackaged_check ? row.production_month : undefined,
// 批次报告提取的生产日期与报告 id(人工在核对表确认过)——入库时带上
// 批次报告提取 / 卡面手填的生产日期(手填优先)——入库时带上
production_date: String(row?.production_date || '').trim() || undefined,
// 保质期原文(如 7天/6个月)——服务端落 inventory.shelf_life 并推算 expiry_date
shelf_life: String(row?.input_shelf_life || '').trim() || undefined,
// 规格/产地:人工改过才回写商品档案(product_catalog.spec / skus.origin)
archive: buildArchivePayload(
{ archiveSpec: row?.input_spec, archiveOrigin: row?.input_origin },
{ archiveSpec: row?.specEdited === true, archiveOrigin: row?.originEdited === true }
) || undefined,
batch_report_id: String(row?.batch_report_id || '').trim() || undefined,
location: session?.profile?.branch_name || '',
watermark_meta: {
@@ -1134,7 +1214,7 @@ Component({
/**
* 一键全部合格入库:仅非须拍照、非预包装行,按应收量合格入库。
* 须拍照行需单独走 AI 质检,不进入批量。
* 须拍照行需单独拍照后逐行确认入库(2026-10-16 起不再有 AI 质检),不进入批量。
*/
async submitAllEligible() {
if (this.data.batchSubmitting) return;
@@ -1150,7 +1230,7 @@ Component({
}
const confirmed = await confirmModal(
'一键全部合格入库',
`将按应收量合格入库当前列表 ${targets.length} 项(无损耗)。须拍照行请单独完成 AI 质检后处理。继续吗?`
`将按应收量合格入库当前列表 ${targets.length} 项(无损耗)。须拍照行请单独拍照确认后处理。继续吗?`
);
if (!confirmed) return;
@@ -44,14 +44,6 @@
</view>
</view>
<view class="btn-photo" data-id="{{item.id}}" bindtap="choosePhoto">拍照</view>
<view
wx:if="{{item.photoRequired && (analyzingId === item.id || item.aiDone)}}"
class="ai-verdict {{analyzingId === item.id ? 'pending' : (item.aiSource === 'vision_unavailable' ? 'warn' : (item.input_rating === '不合格' ? 'fail' : 'ok'))}}"
>
<text wx:if="{{analyzingId === item.id}}">分析中</text>
<text wx:elif="{{item.aiSource === 'vision_unavailable'}}">人工</text>
<text wx:else>{{item.input_rating === '不合格' ? '不合格' : '合格'}}</text>
</view>
</view>
<view class="r2-field">
<input
@@ -63,16 +55,6 @@
placeholder="实收"
/>
</view>
<picker
class="r2-field r2-picker"
mode="selector"
range="{{resultOptions}}"
value="{{item.input_rating === '不合格' ? 1 : 0}}"
data-id="{{item.id}}"
bindchange="onRatingChange"
>
<view class="rate-pick">{{item.input_rating || '合格'}}</view>
</picker>
<picker
wx:if="{{item.requires_prepackaged_check}}"
class="r2-picker"
@@ -95,6 +77,14 @@
<view class="rate-pick {{item.storage_zone ? '' : 'is-empty'}}">{{item.storage_zone || '区域'}}</view>
</picker>
</view>
<view class="card-r3">
<input class="r3-input" type="text" value="{{item.input_spec}}" data-id="{{item.id}}" bindinput="onSpecInput" placeholder="规格" />
<picker class="r3-picker" mode="date" value="{{item.production_date}}" data-id="{{item.id}}" bindchange="onProductionDateChange">
<view class="r3-pick {{item.production_date ? '' : 'is-empty'}}">{{item.production_date || '生产日期'}}</view>
</picker>
<input class="r3-input" type="text" value="{{item.input_shelf_life}}" data-id="{{item.id}}" bindinput="onShelfLifeInput" placeholder="保质期" />
<input class="r3-input" type="text" value="{{item.input_origin}}" data-id="{{item.id}}" bindinput="onOriginInput" placeholder="产地" />
</view>
</view>
</template>
@@ -266,6 +266,46 @@
flex-wrap: nowrap;
}
/* 第三行:规格 / 生产日期 / 保质期 / 产地(2026-10-16 补齐;选填,放不下自动换行) */
.card-r3 {
margin-top: 10rpx;
display: flex;
flex-wrap: wrap;
gap: 10rpx;
}
.r3-input,
.r3-picker {
flex: 1 1 44%;
min-width: 0;
box-sizing: border-box;
height: 56rpx;
border: 1rpx solid #e4e4e7;
border-radius: 8rpx;
background: #fafafa;
}
.r3-input {
padding: 0 14rpx;
font-size: 24rpx;
color: #18181b;
}
.r3-picker {
display: flex;
align-items: center;
justify-content: center;
}
.r3-pick {
font-size: 24rpx;
color: #18181b;
}
.r3-pick.is-empty {
color: #a1a1aa;
}
.card-title-wrap {
flex: 1;
min-width: 0;
@@ -142,7 +142,9 @@ router.get('/inspection/tasks', authMiddleware, async (req: AuthRequest, res: Re
${INSPECTION_TASK_DISPLAY_SELECT},
${LAST_INBOUND_ZONE_SELECT},
COALESCE(s.is_prepackaged, false) AS is_prepackaged,
COALESCE(s.brand, '') AS brand
COALESCE(s.brand, '') AS brand,
-- 商品库规格:订单入库卡面「规格」预填(商品有就带过去);2026-10-16
COALESCE(s.spec, '') AS spec
FROM inspections i
${INSPECTION_TASK_JOINS}
${LAST_INBOUND_ZONE_JOIN}
@@ -218,8 +220,11 @@ router.post('/inspection/complete', authMiddleware, async (req: AuthRequest, res
production_date_month: req.body?.production_date_month
? String(req.body.production_date_month)
: null,
// 逐行生产日期(批次报告提取、人工确认)与批次报告 id(入库后关联到新批次)
// 逐行生产日期(批次报告提取/卡面手填)与批次报告 id(入库后关联到新批次)
production_date: req.body?.production_date ? String(req.body.production_date) : null,
// 保质期原文(如 7天/6个月)+ 人工改过的档案字段(规格/产地)
shelf_life: req.body?.shelf_life ? String(req.body.shelf_life) : null,
archive: req.body?.archive ?? null,
batch_report_id: req.body?.batch_report_id ? String(req.body.batch_report_id) : null,
confirm_over_qty: parseConfirmOverQty(req.body),
reject_fulfillment: parseRejectFulfillment(req.body),
@@ -1,6 +1,9 @@
import { PoolClient } from 'pg';
import { isZeroSupplyCostAllowed } from './zeroSupplyCostConfigService';
import { pool } from '../db';
import { deriveExpiryDate } from '../utils/shelfLife';
import { applyArchiveWriteback } from './stockInboundService';
import type { ArchiveWritebackInput } from './stockInboundService';
import { clearPlanPriceForZeroCost } from './supplyCostPrice';
import { maybeAdvanceOrderAfterFulfillment, ensureProcessingTaskForInspection } from './processingTaskService';
import {
@@ -78,6 +81,11 @@ export interface InspectionComplianceInput {
production_date?: string | null;
/** 批次报告 id:本次入库成功后把该报告关联到新建的库存批次(落 `inventory_batch_report_matches`) */
batch_report_id?: string | null;
/** 保质期原文(如 7天/6个月)→ 落 `inventory.shelf_life`,并与生产日期推算 `expiry_date`。
* 设计 docs/design/20261016-订单入库补规格生产日期保质期产地.md */
shelf_life?: string | null;
/** 人工改过的商品档案字段(规格→product_catalog.spec / 产地→skus.origin);只写传进来的字段,同事务。 */
archive?: ArchiveWritebackInput | null;
/** 入库后存放区域(批次级 `inventory.storage_zone`,自由文本;不填写 NULL)。独立进货与普通验收共用 */
storage_zone?: string | null;
/** 过手超量二次确认 */
@@ -1621,6 +1629,17 @@ export async function submitInspectionCompliance(
: String(input.production_date_month || '').trim().match(/^(\d{4})-(\d{2})$/)
? `${String(input.production_date_month).trim()}-01`
: null;
const shelfLife = String(input.shelf_life || '').trim() || null;
const expiryDate = deriveExpiryDate(productionDate, shelfLife);
// 人工改过的 规格/产地 ⇒ 回写商品档案(product_catalog.spec / skus.origin);同事务、只写传进来的字段
if (input.archive) {
await applyArchiveWriteback(client, {
skuCode: inboundSku,
branchCode,
archive: input.archive,
});
}
// 过手订单履约:记流水但不增减可用库存;合单从单:跳过入库。
// 独立入库无订单,目的就是落库存,不能因鲜品默认过手而跳过(否则 SPI 一直待入库)。
@@ -1659,9 +1678,9 @@ export async function submitInspectionCompliance(
const invInserted = await client.query(
`INSERT INTO inventory (
batch_no, sku_code, quantity, available_qty, supplier_code, cost_price, status, branch_code,
production_date, storage_zone
production_date, shelf_life, expiry_date, storage_zone
)
VALUES ($1, $2, $3, $4, $5, $6, 10, $7, COALESCE($8::date, (NOW() AT TIME ZONE 'Asia/Shanghai')::date), $9)
VALUES ($1, $2, $3, $4, $5, $6, 10, $7, COALESCE($8::date, (NOW() AT TIME ZONE 'Asia/Shanghai')::date), $9, $10::date, $11)
RETURNING id::text AS id`,
[
batchNo,
@@ -1672,6 +1691,8 @@ export async function submitInspectionCompliance(
purchasePrice || null,
branchCode,
productionDate,
shelfLife,
expiryDate,
String(input.storage_zone || '').trim() || null,
]
);
@@ -0,0 +1,71 @@
import { readFileSync } from 'node:fs';
import { describe, expect, it } from 'vitest';
/**
* 订单入库:补 4 字段(规格 / 生产日期 / 保质期 / 产地)+ 拍照改「识别商品信息」(去掉 AI 质量判定)。
* 设计 docs/design/20261016-订单入库补规格生产日期保质期产地.md。
*
* 口径(开发者 2026-10-16):「相当于就是默认为合格就行,前端这边隐式展示为合格」⇒
* **不再调用** `analyzeInspectionQuality`(代码/prompt 保留、不接),「合格才入库/须拍照/退回」门槛不动。
*/
const read = (rel: string) => readFileSync(new URL(rel, import.meta.url), 'utf8');
const wxml = read('../../miniprogram/components/inspection-panel/index.wxml');
const js = read('../../miniprogram/components/inspection-panel/index.js');
const svc = read('../../server/src/services/inspectionComplianceService.ts');
const route = read('../../server/src/routes/mobile/mobileWarehouseRoutes.ts');
describe('卡片:4 字段 + 去掉 AI 判定', () => {
it('新增规格/生产日期/保质期/产地 输入(card-r3)', () => {
expect(wxml).toContain('placeholder="规格"');
expect(wxml).toContain('placeholder="保质期"');
expect(wxml).toContain('placeholder="产地"');
expect(wxml).toContain('mode="date"');
expect(wxml).toContain('card-r3');
});
it('去掉 AI「合格/不合格」徽标与结果 picker(结果隐式合格)', () => {
expect(wxml).not.toContain('ai-verdict');
expect(wxml).not.toContain('onRatingChange');
});
it('不再调用 AI 质检(runAiForRow / analyzeInspectionQuality 保留但不接)', () => {
// 代码保留(开发者:「代码别删」)
expect(js).toContain('async runAiForRow(id) {');
expect(js).toContain('analyzeInspectionQuality');
// 拍照 / 删图都改走识别
expect(js).not.toContain('await this.runAiForRow(id)');
expect((js.match(/await this\.runRecognizeForRow\(id\)/g) || []).length).toBe(2);
// 入库不再有「请先完成 AI 质检」闸门
expect(js).not.toContain('请先完成 AI 质检');
});
});
describe('拍照 → 识别商品信息(复用库存入库那套)', () => {
it('识别调 recognizeStockInboundLines,只补空不覆盖已有值', () => {
expect(js).toContain('recognizeStockInboundLines({ images_base64: [image] })');
expect(js).toContain("if (spec && !String(row.input_spec || '').trim()) patch.input_spec = spec;");
expect(js).toContain(
"if (shelf && !String(row.input_shelf_life || '').trim()) patch.input_shelf_life = shelf;"
);
});
});
describe('提交:保质期 + 档案回写(只写人工改过的)', () => {
it('前端提交带 shelf_life 与 archive', () => {
expect(js).toContain("shelf_life: String(row?.input_shelf_life || '').trim() || undefined,");
expect(js).toContain('archive: buildArchivePayload(');
});
it('服务端落 inventory.shelf_life/expiry_date 并回写档案(同事务)', () => {
expect(svc).toContain('production_date, shelf_life, expiry_date, storage_zone');
expect(svc).toContain('const expiryDate = deriveExpiryDate(productionDate, shelfLife);');
expect(svc).toContain('applyArchiveWriteback(client, {');
});
it('路由透传 shelf_life/archive;列表带出商品库 spec(商品有就带过去)', () => {
expect(route).toContain('shelf_life: req.body?.shelf_life ? String(req.body.shelf_life) : null,');
expect(route).toContain('archive: req.body?.archive ?? null,');
expect(route).toContain("COALESCE(s.spec, '') AS spec");
});
});