feat(consignment): 分类家族口径支持二级分类匹配上级寄卖库存
- 新增 consignment-category-scope 作为分类范围单一事实来源(自身 + 祖先 + 子孙,二级分类对祖先库存按系列收窄) - 寄卖库存列表/统计/筛选项按分类范围取数,二级分类(血宴/暗潮/怒嚎)可正常进入下拉并看到挂在一级分类下的货 - 一键查询待匹配看板:订单侧与库存侧都改为分类范围过滤,二级分类页签不再空白 - 手动匹配候选与提交校验统一按分类家族取数(工单分类 + 其一级分类),跨枪型仍不参与自动匹配,人工强制匹配需填原因 - 仓库搜索关键字增加系列、规格文本与当前/上级分类名,可直接搜「血宴」「苏尔南手枪」 - 新增分类范围单测,并补充看板跨层级用例
This commit is contained in:
@@ -8,6 +8,11 @@ import {
|
||||
} from './consignment-allocation-repo.js'
|
||||
import { toJsonString } from './shared.js'
|
||||
import { isWorkOrderGiftDepositForfeitable } from '../../domain/work-order-acceptance-mode.js'
|
||||
import {
|
||||
normalizeConsignmentCategoryScope,
|
||||
pushConsignmentCategoryScopeCondition,
|
||||
type ConsignmentCategoryScope,
|
||||
} from '../../services/worker-platform/consignment-category-scope.js'
|
||||
|
||||
export type ConsignmentInventoryRow = {
|
||||
id: string | number
|
||||
@@ -87,6 +92,8 @@ export type ConsignmentInventoryRow = {
|
||||
created_at: string
|
||||
updated_at: string
|
||||
category_name?: string
|
||||
/** 库存所属分类的父分类 ID(NULL = 自身就是一级分类) */
|
||||
category_parent_id?: string | number | null
|
||||
}
|
||||
|
||||
export type ConsignmentSubmissionRow = {
|
||||
@@ -218,7 +225,13 @@ export async function listConsignmentInventories(filters: {
|
||||
buyerName?: string | undefined
|
||||
shopName?: string | undefined
|
||||
inboundBatch?: string | undefined
|
||||
/** 兼容旧调用:只按该分类自身过滤(等价于 selfCategoryId = categoryId 的 scope) */
|
||||
categoryId?: number | undefined
|
||||
/**
|
||||
* 寄卖分类范围(含祖先/子孙与系列收窄)。
|
||||
* 传了它就以它为准,忽略 categoryId;两者都不传 = 全量。
|
||||
*/
|
||||
categoryScope?: ConsignmentCategoryScope | undefined
|
||||
system?: string | undefined
|
||||
serverZone?: string | undefined
|
||||
series?: string | undefined
|
||||
@@ -256,7 +269,13 @@ export async function listConsignmentInventories(filters: {
|
||||
values.push(filters.inboundBatch)
|
||||
conditions.push(`ci.inbound_batch = $${values.length}`)
|
||||
}
|
||||
if (filters.categoryId) {
|
||||
if (filters.categoryScope) {
|
||||
pushConsignmentCategoryScopeCondition({
|
||||
scope: normalizeConsignmentCategoryScope(filters.categoryScope),
|
||||
values,
|
||||
conditions,
|
||||
})
|
||||
} else if (filters.categoryId) {
|
||||
values.push(filters.categoryId)
|
||||
conditions.push(`ci.category_id = $${values.length}`)
|
||||
}
|
||||
@@ -286,6 +305,11 @@ export async function listConsignmentInventories(filters: {
|
||||
conditions.push(
|
||||
`(ci.item_name ILIKE $${values.length}
|
||||
OR ci.inventory_no ILIKE $${values.length}
|
||||
OR ci.series ILIKE $${values.length}
|
||||
OR ci.spec_values_json ->> 'series' ILIKE $${values.length}
|
||||
OR ci.spec_text ILIKE $${values.length}
|
||||
OR wc.name ILIKE $${values.length}
|
||||
OR parent_wc.name ILIKE $${values.length}
|
||||
OR ci.bound_platform_order_id ILIKE $${values.length}
|
||||
OR ci.seller_contact ILIKE $${values.length}
|
||||
OR ci.seller_game_id ILIKE $${values.length}
|
||||
@@ -319,7 +343,8 @@ export async function listConsignmentInventories(filters: {
|
||||
|
||||
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : ''
|
||||
// 计数与列表必须使用同一组 join,否则新增的提报单 / 供货打手关键字会直接报错。
|
||||
const countSql = `SELECT COUNT(*)::integer AS total FROM consignment_inventories ci LEFT JOIN consignment_submissions cs ON cs.id = ci.source_submission_id LEFT JOIN worker_users supplier_worker ON supplier_worker.id = ci.worker_id LEFT JOIN consignment_contact_supporters ccs ON ccs.id = ci.contact_supporter_id ${whereClause}`
|
||||
// parent_wc(一级分类名)用于「搜索分类名」:库存挂一级、工单挂二级时两边都能搜到。
|
||||
const countSql = `SELECT COUNT(*)::integer AS total FROM consignment_inventories ci LEFT JOIN work_categories wc ON wc.id = ci.category_id LEFT JOIN work_categories parent_wc ON parent_wc.id = wc.parent_id LEFT JOIN consignment_submissions cs ON cs.id = ci.source_submission_id LEFT JOIN worker_users supplier_worker ON supplier_worker.id = ci.worker_id LEFT JOIN consignment_contact_supporters ccs ON ccs.id = ci.contact_supporter_id ${whereClause}`
|
||||
const countRes = await query<{ total: number }>(countSql, values)
|
||||
const total = countRes.rows[0]?.total || 0
|
||||
|
||||
@@ -332,6 +357,7 @@ export async function listConsignmentInventories(filters: {
|
||||
SELECT
|
||||
ci.*,
|
||||
wc.name AS category_name,
|
||||
wc.parent_id AS category_parent_id,
|
||||
cs.submission_no AS source_submission_no,
|
||||
|
||||
cs.created_at AS source_submission_created_at,
|
||||
@@ -348,6 +374,7 @@ export async function listConsignmentInventories(filters: {
|
||||
ccs.name AS contact_supporter_name
|
||||
FROM consignment_inventories ci
|
||||
LEFT JOIN work_categories wc ON wc.id = ci.category_id
|
||||
LEFT JOIN work_categories parent_wc ON parent_wc.id = wc.parent_id
|
||||
LEFT JOIN consignment_submissions cs ON cs.id = ci.source_submission_id
|
||||
LEFT JOIN worker_users supplier_worker ON supplier_worker.id = ci.worker_id
|
||||
LEFT JOIN consignment_contact_supporters ccs ON ccs.id = ci.contact_supporter_id
|
||||
@@ -362,7 +389,10 @@ export async function listConsignmentInventories(filters: {
|
||||
|
||||
export async function getConsignmentInventoryStats(
|
||||
filters: {
|
||||
/** 兼容旧调用:只按该分类自身过滤 */
|
||||
categoryId?: number | undefined
|
||||
/** 寄卖分类范围(含祖先/子孙与系列收窄);传了它就以它为准 */
|
||||
categoryScope?: ConsignmentCategoryScope | undefined
|
||||
specFilters?: ConsignmentInventorySpecFilter[] | undefined
|
||||
dateFrom?: string | undefined
|
||||
dateTo?: string | undefined
|
||||
@@ -371,7 +401,13 @@ export async function getConsignmentInventoryStats(
|
||||
const conditions: string[] = []
|
||||
const values: unknown[] = []
|
||||
|
||||
if (filters.categoryId) {
|
||||
if (filters.categoryScope) {
|
||||
pushConsignmentCategoryScopeCondition({
|
||||
scope: normalizeConsignmentCategoryScope(filters.categoryScope),
|
||||
values,
|
||||
conditions,
|
||||
})
|
||||
} else if (filters.categoryId) {
|
||||
values.push(filters.categoryId)
|
||||
conditions.push(`ci.category_id = $${values.length}`)
|
||||
}
|
||||
@@ -1153,7 +1189,10 @@ export async function returnConsignmentInventoryToStock(
|
||||
/** 查询当前所有可供匹配的在库物品(status = 'in_stock' 且 allow_matching = TRUE) */
|
||||
export async function listActiveConsignmentInventoriesForMatching(options?: {
|
||||
gameName?: string
|
||||
/** 兼容旧调用:只按该分类自身过滤 */
|
||||
categoryId?: number | null
|
||||
/** 寄卖分类范围(含祖先/子孙与系列收窄);传了它就以它为准 */
|
||||
categoryScope?: ConsignmentCategoryScope | null
|
||||
}): Promise<ConsignmentInventoryRow[]> {
|
||||
// 客服看到的匹配候选要显示「寄卖单号」(提报单号),所以必须带出提报单号;
|
||||
// 注意列名一律加 ci. 前缀:consignment_submissions 也有 status/game_name/category_id,
|
||||
@@ -1165,7 +1204,13 @@ export async function listActiveConsignmentInventoriesForMatching(options?: {
|
||||
values.push(options.gameName)
|
||||
conditions.push(`ci.game_name = $${values.length}`)
|
||||
}
|
||||
if (options?.categoryId) {
|
||||
if (options?.categoryScope) {
|
||||
pushConsignmentCategoryScopeCondition({
|
||||
scope: normalizeConsignmentCategoryScope(options.categoryScope),
|
||||
values,
|
||||
conditions,
|
||||
})
|
||||
} else if (options?.categoryId) {
|
||||
values.push(options.categoryId)
|
||||
conditions.push(`ci.category_id = $${values.length}`)
|
||||
}
|
||||
@@ -1173,6 +1218,8 @@ export async function listActiveConsignmentInventoriesForMatching(options?: {
|
||||
const sql = `
|
||||
SELECT
|
||||
ci.*,
|
||||
wc.name AS category_name,
|
||||
wc.parent_id AS category_parent_id,
|
||||
cs.submission_no AS source_submission_no,
|
||||
|
||||
cs.created_at AS source_submission_created_at,
|
||||
@@ -1180,6 +1227,7 @@ export async function listActiveConsignmentInventoriesForMatching(options?: {
|
||||
supplier_worker.phone AS live_worker_phone,
|
||||
ccs.name AS contact_supporter_name
|
||||
FROM consignment_inventories ci
|
||||
LEFT JOIN work_categories wc ON wc.id = ci.category_id
|
||||
LEFT JOIN consignment_submissions cs ON cs.id = ci.source_submission_id
|
||||
LEFT JOIN worker_users supplier_worker ON supplier_worker.id = ci.worker_id
|
||||
LEFT JOIN consignment_contact_supporters ccs ON ccs.id = ci.contact_supporter_id
|
||||
|
||||
Reference in New Issue
Block a user