From 5bc252d129baf4154b7461b12b9ecfbc39dbaab5 Mon Sep 17 00:00:00 2001 From: lixiaolong <702156524@qq.com> Date: Thu, 26 Nov 2026 11:39:57 +0800 Subject: [PATCH] =?UTF-8?q?feat(warehouse):=20=E6=94=AF=E6=8C=81=E5=85=A5?= =?UTF-8?q?=E5=BA=93=E7=A7=BB=E5=BA=93=E7=85=A7=E7=89=87=E5=8F=8A=E5=BA=93?= =?UTF-8?q?=E5=AD=98=E5=9B=BE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Web 与 App 支持选传最多 9 张、单张 50MB 照片,并与本次入库和移库事务绑定。库存图库按项目、物品、库区归集到货、入库和移库照片,支持来源筛选、缩略图及原图预览,校验只读权限和照片归属。附开发数据库结构脚本、更新说明和相关测试,同时纳入采购明细垂直居中修正。 --- mobile-app/release-notes.json | 10 +- mobile-app/src/core/network.ts | 2 +- mobile-app/src/core/stock-operations.ts | 8 +- mobile-app/src/screens/BatchOperation.tsx | 6 +- mobile-app/src/screens/BusinessList.tsx | 12 ++- .../src/screens/OperationPhotoViewer.tsx | 12 +++ mobile-app/src/screens/OperationPhotos.tsx | 59 ++++++++++++ mobile-app/src/screens/StockPhotos.tsx | 22 +++++ mobile-app/tests/operation-photos.test.mjs | 19 ++++ .../warehouse/InRecordController.java | 11 ++- .../warehouse/StockInfoController.java | 6 +- .../warehouse/StockPhotoController.java | 12 +++ .../WarehouseOperationPhotoController.java | 16 ++++ .../service/impl/StockPhotosTest.java | 33 +++++++ .../impl/WarehouseOperationPhotosTest.java | 55 +++++++++++ .../impl/PurchaseArrivalPhotoService.java | 3 + .../service/impl/StockPhotoService.java | 48 ++++++++++ .../impl/WarehouseOperationPhotoService.java | 94 +++++++++++++++++++ ruoyi-ui-vue3/src/api/warehouse/inRecord.js | 4 +- .../src/api/warehouse/operation-photos.js | 10 ++ .../src/components/OperationPhotos/index.vue | 52 ++++++++++ .../components/Production/StockOperations.vue | 12 ++- .../src/components/PurchaseSheet/index.vue | 2 +- .../src/components/ReceiptDialog/Batch.vue | 13 +-- .../src/components/ReceiptDialog/Move.vue | 5 +- .../src/components/ReceiptDialog/index.vue | 13 ++- .../src/components/StockPhotos/index.vue | 40 ++++++++ .../src/utils/arrival-photo-format.js | 6 +- .../src/views/warehouse/inRecord/index.vue | 5 +- .../src/views/warehouse/stock/index.vue | 16 ++-- .../tests/runtime/operation-photos.spec.js | 21 +++++ .../runtime/stock-fill-available.spec.js | 1 + .../tests/runtime/stock-photo-gallery.spec.js | 18 ++++ .../20261125_warehouse_operation_photos.sql | 13 +++ 34 files changed, 609 insertions(+), 50 deletions(-) create mode 100644 mobile-app/src/screens/OperationPhotoViewer.tsx create mode 100644 mobile-app/src/screens/OperationPhotos.tsx create mode 100644 mobile-app/src/screens/StockPhotos.tsx create mode 100644 mobile-app/tests/operation-photos.test.mjs create mode 100644 ruoyi-admin/src/main/java/com/ruoyi/web/controller/warehouse/StockPhotoController.java create mode 100644 ruoyi-admin/src/main/java/com/ruoyi/web/controller/warehouse/WarehouseOperationPhotoController.java create mode 100644 ruoyi-admin/src/test/java/com/ruoyi/warehouse/service/impl/StockPhotosTest.java create mode 100644 ruoyi-admin/src/test/java/com/ruoyi/warehouse/service/impl/WarehouseOperationPhotosTest.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/warehouse/service/impl/StockPhotoService.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/warehouse/service/impl/WarehouseOperationPhotoService.java create mode 100644 ruoyi-ui-vue3/src/api/warehouse/operation-photos.js create mode 100644 ruoyi-ui-vue3/src/components/OperationPhotos/index.vue create mode 100644 ruoyi-ui-vue3/src/components/StockPhotos/index.vue create mode 100644 ruoyi-ui-vue3/tests/runtime/operation-photos.spec.js create mode 100644 ruoyi-ui-vue3/tests/runtime/stock-photo-gallery.spec.js create mode 100644 sql/projectdev/20261125_warehouse_operation_photos.sql diff --git a/mobile-app/release-notes.json b/mobile-app/release-notes.json index 4382ceb..de13435 100644 --- a/mobile-app/release-notes.json +++ b/mobile-app/release-notes.json @@ -1,6 +1,6 @@ [ - "到货照片按真实图片内容识别,不再因后缀不一致上传失败。", - "网页兼容苹果HEIC/HEIF原图,本地自动转换后上传。", - "增加GIF、BMP、TIFF等常见图片格式兼容。", - "手机相册优先使用兼容格式,保留批量补录和失败重试。" -] + "入库、移库支持拍照或从相册选图,照片选传。", + "每次最多9张、每张不超过50MB,支持批量办理。", + "库存增加照片入口,按到货、入库、移库分类回看。", + "缩略图快速浏览,点击查看原图,可核对单号和日期。" +] \ No newline at end of file diff --git a/mobile-app/src/core/network.ts b/mobile-app/src/core/network.ts index 89482c8..490b1a7 100644 --- a/mobile-app/src/core/network.ts +++ b/mobile-app/src/core/network.ts @@ -106,7 +106,7 @@ export class ApiClient { body: preparedBody === undefined ? undefined : multipart ? preparedBody as FormData : JSON.stringify(preparedBody) }); if(options.responseType==='image'&&response.ok&&/^image\/(png|jpeg|webp)$/.test(response.headers.get('content-type')?.split(';')[0]||'')){ - const limit=Math.max(1,Math.min(options.imageMaxBytes??6*1024*1024,20*1024*1024)); + const limit=Math.max(1,Math.min(options.imageMaxBytes??6*1024*1024,50*1024*1024)); if(Number(response.headers.get('content-length')||0)>limit)throw new ApiError('图片超过预览大小限制,请在电脑端查看。',413); const bytes=new Uint8Array(await response.arrayBuffer()); if(epoch!==this.generation)throw new ApiError('会话已切换,请重新查询。',409); diff --git a/mobile-app/src/core/stock-operations.ts b/mobile-app/src/core/stock-operations.ts index bdd0320..a5330e7 100644 --- a/mobile-app/src/core/stock-operations.ts +++ b/mobile-app/src/core/stock-operations.ts @@ -1,6 +1,6 @@ import {validDate,type Row} from './modules.ts'; export type OperationKind='use'|'move'|'receive'|'borrow'|'check'|'return'; -export type OperationRow={source:Row;quantity:string;area:Row|null;stock?:Row|null;key:string;status:'editing'|'pending'|'success'|'failed'|'uncertain';error:string;payload?:RequestStep[]}; +export type OperationRow={source:Row;quantity:string;area:Row|null;stock?:Row|null;key:string;status:'editing'|'pending'|'success'|'failed'|'uncertain';error:string;photos?:Row[];photosPending?:boolean;payload?:RequestStep[]}; export type RequestStep={path:string;method:string;body:Row}; export type OperationForm={date:string;remark:string;project:Row|null}; export const operationTitles:Record={use:'物料领用',move:'移库',receive:'办理入库',borrow:'借用',check:'登记盘点',return:'归还库存'}; @@ -14,6 +14,8 @@ export function validateOperation(kind:OperationKind,rows:OperationRow[],form:Op for(let i=0;i!p.id||p.error)))return `${label}:请等待照片上传完成,或移除失败照片。`; + if((row.photos||[]).length>9)return `${label}:最多9张照片。`; const quantity=Number(row.quantity); if(!/^\d+(\.\d{1,4})?$/.test(row.quantity)||!Number.isFinite(quantity)||(kind==='check'?quantity<0:quantity<=0))return `${label}:请输入${kind==='check'?'不小于 0':'大于 0'}的数量,最多 4 位小数。`; if(kind!=='check'&&quantity>available(kind,row))return `${label}:本次数量超过${kind==='return'?'未还数量或取料库存':'当前可用数量'}。`; @@ -30,7 +32,7 @@ export function validateOperation(kind:OperationKind,rows:OperationRow[],form:Op return ''; } export function operationPayload(kind:OperationKind,row:OperationRow,form:OperationForm):RequestStep[]{ - const s=row.source,quantity=Number(row.quantity),base={quantity,key:row.key,date:form.date,remark:form.remark}; + const s=row.source,quantity=Number(row.quantity),base={quantity,key:row.key,date:form.date,remark:form.remark,...(row.photos?.length?{photoIds:row.photos.map(p=>p.id)}:{})}; if(kind==='use')return [{path:'/warehouse/stock/out',method:'POST',body:{id:s.id,usageProjectId:s.projectId,outNum:quantity,outType:4,outNo:'MOUT-'+row.key,outTime:form.date+' 00:00:00',remark:form.remark}}]; if(kind==='move')return [{path:'/warehouse/stock/move',method:'POST',body:{...base,projectId:s.projectId,itemId:s.productId,fromAreaId:s.areaId,toAreaId:row.area?.id}}]; if(kind==='borrow')return [{path:'/project/loans',method:'POST',body:{...base,lenderProjectId:s.projectId,borrowerProjectId:form.project?.id,itemId:s.productId,fromAreaId:s.areaId,toAreaId:row.area?.id}}]; @@ -38,7 +40,7 @@ export function operationPayload(kind:OperationKind,row:OperationRow,form:Operat if(kind==='check')return [{path:'/warehouse/check',method:'POST',body:{projectId:s.projectId,productId:s.productId,areaId:s.areaId,realNum:quantity,businessDate:form.date,reason:form.remark,remark:form.remark}}]; return s.receiptRoot?[{path:`/warehouse/in/receive/${s.id}`,method:'POST',body:{...base,areaId:row.area?.id}}]:[ {path:'/warehouse/in',method:'PUT',body:{...s,areaId:row.area?.id,businessDate:form.date,remark:form.remark}}, - {path:`/warehouse/in/confirm/${s.id}`,method:'PUT',body:{}} + {path:`/warehouse/in/confirm/${s.id}`,method:'PUT',body:row.photos?.length?{photoIds:row.photos.map(p=>p.id)}:{}} ]; } /** Persist the frozen payload before sending. Only retryable rows reuse the exact identity/body. */ diff --git a/mobile-app/src/screens/BatchOperation.tsx b/mobile-app/src/screens/BatchOperation.tsx index e1caa63..6d2f205 100644 --- a/mobile-app/src/screens/BatchOperation.tsx +++ b/mobile-app/src/screens/BatchOperation.tsx @@ -1,3 +1,4 @@ +import {OperationPhotos} from './OperationPhotos'; import React,{useEffect,useRef,useState} from 'react'; import {KeyboardAvoidingView,Modal,Platform,ScrollView,View} from 'react-native'; import {Text} from '../typography'; @@ -14,13 +15,13 @@ import {ItemIdentity,RecordMeta} from './ItemIdentity'; type Snapshot={rows:OperationRow[];form:OperationForm;preview:boolean}; export type BatchOperationProps={api:ApiClient;input:Row[];kind:OperationKind;scope:string;close:()=>void;done:()=>void}; export function BatchOperation({api,input,kind,scope,close,done}:BatchOperationProps){ - const t=useTheme(),[rows,setRows]=useState(()=>input.map(source=>({source,quantity:'',area:null,key:Crypto.randomUUID(),status:'editing',error:''}))),[form,setForm]=useState({date:localDate(),remark:'',project:null}); + const t=useTheme(),[rows,setRows]=useState(()=>input.map(source=>({source,quantity:'',area:null,key:Crypto.randomUUID(),status:'editing',error:'',photos:[],photosPending:false}))),[form,setForm]=useState({date:localDate(),remark:'',project:null}); const [areas,setAreas]=useState([]),[projects,setProjects]=useState([]),[stocks,setStocks]=useState([]),[ready,setReady]=useState(false),[loadError,setLoadError]=useState(''),[error,setError]=useState(''),[preview,setPreview]=useState(false),[busy,setBusy]=useState(false),[reload,setReload]=useState(0); const lock=useRef(false),alive=useRef(true),snapshot={rows,form,preview},returnSource=kind==='return'?rows[0]?.source:undefined; const attempted=rows.some(r=>r.payload),succeeded=rows.filter(r=>r.status==='success').length; // One recoverable operation per action/account. Re-selecting a subset cannot // silently create fresh identities for a previously uncertain batch. - const draft=useOperationDraft({scope,suspendAutosave:busy,kind:'stock-'+kind,id:'active',value:snapshot,onRestore:value=>{setRows(value.rows.map(r=>r.status==='pending'?{...r,status:'uncertain'}:r));setForm(value.form);setPreview(value.preview||value.rows.some(r=>r.payload));},hasContent:value=>value.rows.some(r=>r.quantity||r.area||r.payload)||!!value.form.remark||!!value.form.project,isPending:value=>value.rows.some(r=>r.payload&&r.status!=='success')}); + const draft=useOperationDraft({scope,suspendAutosave:busy,kind:'stock-'+kind,id:'active',value:snapshot,onRestore:value=>{setRows(value.rows.map(r=>({...r,status:r.status==='pending'?'uncertain':r.status,photos:(r.photos||[]).map(p=>({...p,uri:undefined,...(!p.id?{error:'照片尚未上传,请移除后重新拍照'}:{})})),photosPending:false})));setForm(value.form);setPreview(value.preview||value.rows.some(r=>r.payload));},hasContent:value=>value.rows.some(r=>r.quantity||r.area||r.payload||r.photos?.length)||!!value.form.remark||!!value.form.project,isPending:value=>value.rows.some(r=>r.payload&&r.status!=='success')}); useEffect(()=>{alive.current=true;const ctl=new AbortController();setReady(false);setLoadError('');void(async()=>{try{ if(['receive','move','borrow','return'].includes(kind)){const result=await api.request('/warehouse/area/optionselect',{signal:ctl.signal});if(!ctl.signal.aborted)setAreas(result.data||[]);} if(kind==='borrow'){const result=await api.request('/project/info/options',{signal:ctl.signal});if(!ctl.signal.aborted)setProjects(result.data||[]);} @@ -70,6 +71,7 @@ export function BatchOperation({api,input,kind,scope,close,done}:BatchOperationP {kind==='return'&&未还 {row.source.outstandingQuantity} {row.source.unit||''}} changeRow(index,{quantity})} keyboard="decimal-pad"/> {['move','receive','borrow','return'].includes(kind)&&changeRow(index,{area})} nameKey="areaName"/>} + {['receive','move'].includes(kind)&&changeRow(index,{photos})} onPending={pending=>{setRows(old=>old[index]?.photosPending===pending?old:old.map((r,i)=>i===index?{...r,photosPending:pending}:r));}}/>} {rows.length>1&&