fix(supply-chain): 完善组合限价筛选与运营负责人

This commit is contained in:
居居 2026-10-19 13:53:39 +08:00
parent d22126e354
commit 7eaa1b49ae
7 changed files with 47 additions and 9 deletions

View File

@ -28,11 +28,13 @@ const COMBO_COLUMNS: LimitTableColumn[] = COMBO_LIMIT_FIELDS.map((field) => ({
numeric: field.numeric,
}))
const COMBO_FILTER_FIELDS: LimitTableFilterField[] = COMBO_LIMIT_FIELDS.map((field) => ({
key: field.key,
label: field.label,
optionsEndpoint: OPTIONS_ENDPOINT,
}))
const COMBO_FILTER_FIELDS: LimitTableFilterField[] = COMBO_LIMIT_FIELDS
.filter((field) => field.key === 'comboCode')
.map((field) => ({
key: field.key,
label: field.label,
optionsEndpoint: OPTIONS_ENDPOINT,
}))
const COLUMN_MAP = new Map(COMBO_COLUMNS.map((column) => [column.key, column]))
const FIELD_LABEL_MAP = new Map(COMBO_LIMIT_FIELDS.map((field) => [field.key, field.label]))

View File

@ -180,6 +180,7 @@ function mockLimitManagementFetch(rows: SupplyChainProductArchiveRow[]) {
data: {
rows: [{
comboCode: 'COMBO-AB',
opsHead: '运营甲',
ownerLimitPrice: '69.00',
nonOwnerLimitPriceNew: '79.00',
jxLimitPrice: '50.00',
@ -263,10 +264,14 @@ describe('限价管理', () => {
fireEvent.click(screen.getByRole('button', { name: '组合限价' }))
expect(await screen.findByText('COMBO-AB')).toBeInTheDocument()
for (const label of ['组合编码', '负责人限价', '非负责人限价', '京喜限价', '阿里页面限价', '分销商89折', '分销商85折', '分销商8折']) {
for (const label of ['组合编码', '运营负责人', '负责人限价', '非负责人限价', '京喜限价', '阿里页面限价', '分销商89折', '分销商85折', '分销商8折']) {
expect(screen.getByRole('columnheader', { name: new RegExp(`^${label}`) })).toBeInTheDocument()
}
expect(screen.getByText('69.00')).toBeInTheDocument()
expect(screen.getByText('运营甲')).toBeInTheDocument()
expect(document.querySelectorAll('[data-limit-filter]')).toHaveLength(1)
const columnLabels = screen.getAllByRole('columnheader').map((cell) => (cell.textContent ?? '').replace(/[↕↑↓▾]/g, '').trim())
expect(columnLabels.indexOf('运营负责人')).toBe(columnLabels.indexOf('组合编码') + 1)
expect(screen.queryByRole('button', { name: '导出明细' })).not.toBeInTheDocument()
})

View File

@ -10,6 +10,7 @@ describe('supply-chain combo limit price', () => {
it('formats the A(50) + B(19) combination as 69.00 and derives the other price fields', () => {
const row = buildComboLimitRow({
combineCode: 'COMBO-AB',
opsHead: '运营甲、运营乙',
itemCount: 2,
costCount: 2,
ownerTotal: 69,
@ -19,6 +20,7 @@ describe('supply-chain combo limit price', () => {
expect(row).toEqual({
comboCode: 'COMBO-AB',
opsHead: '运营甲、运营乙',
ownerLimitPrice: '69.00',
nonOwnerLimitPriceNew: '79.00',
jxLimitPrice: '50.00',
@ -32,6 +34,7 @@ describe('supply-chain combo limit price', () => {
it('leaves Jingxi blank when any child product has no cost price', () => {
const row = buildComboLimitRow({
combineCode: 'COMBO-MISSING-COST',
opsHead: '运营甲',
itemCount: 3,
costCount: 2,
ownerTotal: 120,
@ -47,6 +50,7 @@ describe('supply-chain combo limit price', () => {
const rows = [
buildComboLimitRow({
combineCode: 'COMBO-2',
opsHead: '运营乙',
itemCount: 1,
costCount: 1,
ownerTotal: 90,
@ -55,6 +59,7 @@ describe('supply-chain combo limit price', () => {
}),
buildComboLimitRow({
combineCode: 'COMBO-1',
opsHead: '运营甲',
itemCount: 1,
costCount: 1,
ownerTotal: 50,
@ -63,6 +68,7 @@ describe('supply-chain combo limit price', () => {
}),
buildComboLimitRow({
combineCode: 'OTHER',
opsHead: '运营丙',
itemCount: 1,
costCount: 1,
ownerTotal: 10,
@ -88,6 +94,7 @@ describe('supply-chain combo limit price', () => {
const rows = [
buildComboLimitRow({
combineCode: 'COMBO-AB',
opsHead: '运营甲',
itemCount: 2,
costCount: 2,
ownerTotal: 69,
@ -96,6 +103,7 @@ describe('supply-chain combo limit price', () => {
}),
buildComboLimitRow({
combineCode: 'COMBO-AC',
opsHead: '运营乙',
itemCount: 2,
costCount: 2,
ownerTotal: 80,

View File

@ -1,5 +1,6 @@
export const COMBO_LIMIT_FIELDS = [
{ key: 'comboCode', label: '组合编码', numeric: false },
{ key: 'opsHead', label: '运营负责人', numeric: false },
{ key: 'ownerLimitPrice', label: '负责人限价', numeric: true },
{ key: 'nonOwnerLimitPriceNew', label: '非负责人限价', numeric: true },
{ key: 'jxLimitPrice', label: '京喜限价', numeric: true },
@ -22,6 +23,8 @@ export type ComboLimitSort = {
export type ComboLimitAggregate = {
combineCode: string
/** 同一组合的多个子项可能由不同运营负责,去重后用「、」连接 */
opsHead: string
itemCount: number
costCount: number
ownerTotal: number
@ -77,6 +80,7 @@ export function buildComboLimitRow(input: ComboLimitAggregate): ComboLimitRow {
: null
return {
comboCode: input.combineCode,
opsHead: input.opsHead,
ownerLimitPrice: formatComboLimitPrice(input.ownerTotal),
nonOwnerLimitPriceNew: formatComboLimitPrice(nonOwnerTotal),
jxLimitPrice: formatComboLimitPrice(jxTotal),

View File

@ -3,6 +3,7 @@ import type { ComboLimitAggregate } from '@/lib/supply-chain-combo-limit-price'
export type ComboLimitPricedProduct = {
barcode: string
opsHead: string
ownerLimitPrice: number
costPrice: number | null
}
@ -52,6 +53,7 @@ class JstComboLimitSourceRepository {
.input('products', sql.NVarChar(sql.MAX), JSON.stringify(products))
.query<{
combineCode: string
opsHeadList: string | null
itemCount: number
costCount: number
ownerTotal: number
@ -61,11 +63,13 @@ class JstComboLimitSourceRepository {
WITH prices AS (
SELECT
barcode,
opsHead,
ownerPrice,
costPrice
FROM OPENJSON(@products)
WITH (
barcode nvarchar(120) '$.barcode',
opsHead nvarchar(60) '$.opsHead',
ownerPrice decimal(18,4) '$.ownerLimitPrice',
costPrice decimal(18,4) '$.costPrice'
)
@ -83,6 +87,10 @@ class JstComboLimitSourceRepository {
i.combine_sku_id,
COUNT(*) AS matchedCount,
COUNT(p.costPrice) AS costCount,
STRING_AGG(
CASE WHEN LTRIM(RTRIM(p.opsHead)) <> '' THEN p.opsHead END,
N'、'
) AS opsHeadList,
SUM(p.ownerPrice * i.qty) AS ownerTotal,
SUM((
p.ownerPrice
@ -98,6 +106,7 @@ class JstComboLimitSourceRepository {
)
SELECT
CAST(cp.combine_sku_id AS nvarchar(200)) AS combineCode,
CAST(cp.opsHeadList AS nvarchar(1000)) AS opsHeadList,
CAST(t.itemCount AS int) AS itemCount,
CAST(cp.costCount AS int) AS costCount,
CAST(cp.ownerTotal AS decimal(28,4)) AS ownerTotal,
@ -109,6 +118,12 @@ class JstComboLimitSourceRepository {
`)
return result.recordset.map((row) => ({
combineCode: String(row.combineCode ?? '').trim(),
opsHead: [...new Set(
String(row.opsHeadList ?? '')
.split('、')
.map((value) => value.trim())
.filter(Boolean),
)].join('、'),
itemCount: Number(row.itemCount),
costCount: Number(row.costCount),
ownerTotal: Number(row.ownerTotal),

View File

@ -9,6 +9,7 @@ import { SupplyChainComboLimitService } from '../supply-chain-combo-limit.servic
function aggregate(combineCode: string, ownerTotal: number) {
return {
combineCode,
opsHead: '运营甲',
itemCount: 2,
costCount: 2,
ownerTotal,
@ -25,8 +26,8 @@ describe('SupplyChainComboLimitService', () => {
.mockResolvedValueOnce([aggregate('COMBO-C', 100)]),
}
const loader = jest.fn().mockResolvedValue([
{ barcode: 'A', ownerLimitPrice: 50, costPrice: 10 },
{ barcode: 'B', ownerLimitPrice: 19, costPrice: 10 },
{ barcode: 'A', opsHead: '运营甲', ownerLimitPrice: 50, costPrice: 10 },
{ barcode: 'B', opsHead: '运营乙', ownerLimitPrice: 19, costPrice: 10 },
])
let now = 1_000
const service = new SupplyChainComboLimitService(repository, loader, () => now)
@ -55,7 +56,7 @@ describe('SupplyChainComboLimitService', () => {
}
const service = new SupplyChainComboLimitService(
repository,
jest.fn().mockResolvedValue([{ barcode: 'A', ownerLimitPrice: 50, costPrice: 10 }]),
jest.fn().mockResolvedValue([{ barcode: 'A', opsHead: '运营甲', ownerLimitPrice: 50, costPrice: 10 }]),
() => 1_000,
)

View File

@ -29,6 +29,7 @@ type CacheEntry = {
type PriceSourceRow = {
barcode: string
opsHead: string
ownerLimitPrice: string | number
costPrice: string | null
}
@ -42,6 +43,7 @@ async function loadPricedArchiveProducts(): Promise<ComboLimitPricedProduct[]> {
const rows = await prisma.$queryRaw<PriceSourceRow[]>`
SELECT
a."barcode" AS "barcode",
a."opsHead" AS "opsHead",
l."ownerLimitPrice"::text AS "ownerLimitPrice",
a."costPrice" AS "costPrice"
FROM "SupplyChainProductArchive" a
@ -54,6 +56,7 @@ async function loadPricedArchiveProducts(): Promise<ComboLimitPricedProduct[]> {
if (!barcode || !Number.isFinite(ownerLimitPrice) || ownerLimitPrice <= 0) return []
return [{
barcode,
opsHead: String(row.opsHead ?? '').trim(),
ownerLimitPrice,
costPrice: parseCostPrice(row.costPrice),
}]