WEB/src/api/storage.inventory/inventory.ts
2026-08-23 18:15:02 +08:00

281 lines
8.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import request from '@/utils/request'
const v = "1.0"
/** storage.inventory.list 请求参数 */
export type InventoryListParams = {
/** 统一 where 条件对象,可用字段:stock_id(商品ID)、space_id(库位ID)、store_id(货主ID)、inventory_type(ZP/CC/JS/XS/ZT/DJ/FP)、batch_no(批次号)、inbound_order_no(入库单号)、available_quantity(可用数量,支持 gt/lt)、inbound_time(入库时间,支持 between)、created_at(创建时间,支持 between)、stock_query(虚拟筛选字段:按商品编码/名称/货物编码/条码/SKU ID 模糊匹配,如 { operator: 'like', value: '111' }) */
where?: Record<string, any>
/** 分页参数 { page, pageSize },默认 page=1, pageSize=20 */
pagination?: { page?: number; pageSize?: number }
/** 排序参数 { sortField, sortOrder },默认 sortField='created_at', sortOrder='DESC' */
sort?: { sortField?: string; sortOrder?: 'ASC' | 'DESC' }
/** 是否按批次查询,默认 false。false=合并模式(按库位+商品聚合 quantity/locked_quantity/available_quantity),true=明细模式(逐条返回含 batch_no/production_date/expiry_date 等) */
group_by_batch?: boolean
}
/** 库存明细列表查询 */
export function getInventoryList(data: InventoryListParams = {}): Promise<any> {
return request({
url: '/system',
method: 'post',
params: {
method: 'storage.inventory.list',
v,
timestamp: new Date().getTime()
},
data,
isSystemApi: true
} as any)
}
/** 按商品查询库存明细:group_by_space=false 返回 quantity > 1 的 wms_storage 明细行(按 id 倒序);group_by_space=true 按库位汇总 */
export function getInventoryListByStockId(data: { stock_id: number; group_by_space?: boolean }): Promise<any> {
return request({
url: '/system',
method: 'post',
params: {
method: 'storage.inventory.listByStockId',
v,
timestamp: new Date().getTime()
},
data,
isSystemApi: true
} as any)
}
export function quickPutaway(data: { receiving_id: number; id?: number }): Promise<any> {
const body: Record<string, unknown> = { ...data }
if (body.receiving_id === undefined && body.id != null) {
body.receiving_id = Number(body.id)
}
return request({
url: '/system',
method: 'post',
params: {
method: 'storage.inventory.quickPutaway',
v,
timestamp: new Date().getTime()
},
data: body,
isSystemApi: true
} as any)
}
export type MatchPutawayReceivingResult = {
receiving_id?: number
storage_status?: 'all' | 'partial' | 'none' | string
[key: string]: unknown
}
export type MatchPutawayEntryOrderResult = {
entry_order_id?: number
order_status?: string
callback_triggered?: boolean
callback_result?: Record<string, unknown> | null
[key: string]: unknown
}
export type MatchPutawayResponse = {
code?: number
message?: string
summary?: {
total_products_matched?: number
total_quantity_inbound?: number
[key: string]: unknown
}
receiving_results?: MatchPutawayReceivingResult[]
entry_order_results?: MatchPutawayEntryOrderResult[]
warnings?: string[]
data?: Partial<MatchPutawayResponse>
}
/** 收货单与入库单匹配入库:按商品维度匹配,需传收货单与入库单 ID 列表 */
export function matchPutaway(data: {
receiving_ids: number[]
entry_order_ids: number[]
}): Promise<MatchPutawayResponse> {
return request({
url: '/system',
method: 'post',
params: {
method: 'storage.inventory.matchPutaway',
v,
timestamp: new Date().getTime()
},
data,
isSystemApi: true
} as any)
}
/** 按库位+商品维度移库(合并模式);quantity 必填 */
export function transferByProduct(data: {
space_id: number
stock_id: number
target_space_id: number
quantity: number
}): Promise<any> {
return request({
url: '/system',
method: 'post',
params: {
method: 'storage.inventory.transferByProduct',
v,
timestamp: new Date().getTime()
},
data,
isSystemApi: true
} as any)
}
/** 按单条 wms_storage 记录移库;quantity 可选,不传则全量 */
export function transferLocation(data: {
storage_id: number
target_space_id: number
quantity?: number
}): Promise<any> {
return request({
url: '/system',
method: 'post',
params: {
method: 'storage.inventory.transferLocation',
v,
timestamp: new Date().getTime()
},
data,
isSystemApi: true
} as any)
}
/**
* 出入库记录列表查询
* 支持where条件、分页、排序、批次分组切换。
* 默认按库位合并数量(合并模式),group_by_batch=true时返回每条明细(明细模式)
*/
export function getTransactionList(data: {
/** 统一where条件对象,可用字段:transaction_type(INBOUND/OUTBOUND)、stock_id、space_id、store_id、order_type(SCRK/MATCH)、order_no、inventory_type(ZP/CC/JS/XS/ZT/DJ/FP)、operator_name、created_at(支持between) */
where?: Record<string, any>
/** 分页参数,默认page=1, pageSize=20 */
pagination?: {
page?: number
pageSize?: number
}
/** 排序参数,默认sortField='created_at', sortOrder='DESC' */
sort?: {
sortField?: string
sortOrder?: string
}
/** 是否按批次查询,默认false。false=合并模式(按库位+商品聚合),true=明细模式(逐条返回) */
group_by_batch?: boolean
}): Promise<any> {
return request({
url: '/system',
method: 'post',
params: {
method: 'storage.transaction.list',
v,
timestamp: new Date().getTime()
},
data,
isSystemApi: true
} as any)
}
export function getExpiryList(data: any): Promise<any> {
return request({
url: '/system',
method: 'post',
params: {
method: 'storage.expiry.list',
v,
timestamp: new Date().getTime()
},
data
})
}
/** storage.inventory.export 请求参数 */
export type InventoryExportParams = {
/** 统一 where 条件对象,与 storage.inventory.list 的 where 语义完全一致(暂不支持 stock_query 虚拟筛选)。支持字段:stock_id(商品ID)、space_id(库位ID)、store_id(货主ID)、inventory_type(ZP/CC/JS/XS/ZT/DJ/FP)、batch_no(批次号)、inbound_order_no(入库单号)、available_quantity(可用数量,支持 gt/lt)、inbound_time(入库时间,支持 between)、created_at(创建时间,支持 between) */
where?: Record<string, any>
/** 排序参数,与 storage.inventory.list 的 sort 语义一致。sortField 支持:id/stock_id/space_id/created_at/updated_at/inbound_time/quantity,sortOrder 支持 ASC/DESC。默认 id DESC */
sort?: {
sortField?: string
sortOrder?: 'ASC' | 'DESC'
}
/** 是否按批次导出,默认 false。false=合并模式(按 stock_id+库位聚合导出库存汇总,含总库存/锁定/可用/批次数/最近入库时间),true=明细模式(按 storage_id 逐条导出库存明细,含批次号/库存类型/生产日期/过期日期/入库单号等) */
group_by_batch?: boolean
}
/** storage.inventory.export 响应 data */
export type InventoryExportResponse = {
task_id?: string
status?: string
progress?: number
message?: string
update_time?: number
}
/** 提交库存导出异步任务 */
export function exportInventory(data: InventoryExportParams = {}): Promise<any> {
return request({
url: '/system',
method: 'post',
params: {
method: 'storage.inventory.export',
v,
timestamp: new Date().getTime()
},
data,
isSystemApi: true
} as any)
}
/** storage.inventory.exportTaskProgress 请求参数 */
export type ExportTaskProgressParams = {
task_id?: string
taskId?: string
}
/** storage.inventory.exportTaskProgress 响应 data */
export type ExportTaskProgressResponse = {
task_id?: string
status?: string
progress?: number
message?: string
result?: Record<string, unknown>
error?: string
download_url?: string
}
/** 按 task_id 查询库存导出任务进度 */
export function exportTaskProgress(data: ExportTaskProgressParams): Promise<any> {
const taskId = data.task_id || data.taskId
if (!taskId) {
throw new Error('task_id 不能为空')
}
return request({
url: '/system',
method: 'post',
params: {
method: 'storage.inventory.exportTaskProgress',
v,
timestamp: new Date().getTime()
},
data: { task_id: taskId },
isSystemApi: true
} as any)
}
// export function transaction(data:any) {
// return request({
// url: '/system',
// method: 'post',
// params: {
// method: 'storage.inventory.transaction',
// v,
// timestamp: new Date().getTime()
// },
// data,
// isSystemApi: true
// } as any)
// }