feat(supply-chain): map stock monitor daily sales

This commit is contained in:
WuYongJie 2026-08-10 13:55:28 +08:00
parent ff771b7bba
commit a783e4c94b
4 changed files with 40 additions and 1 deletions

View File

@ -42,6 +42,10 @@ export type SupplyChainProductArchiveRow = {
moq: string
firstLeadTime: string
palletSpec: string
dailySales: string
sales3d: string
sales7d: string
sales15d: string
}
export const PRODUCT_ARCHIVE_SALES_STATUSES = ['销售', '停产', '退市'] as const

View File

@ -11,6 +11,10 @@ export type JstStockMonitorProfile = {
minimum: string
produceCycle: string
trayParameter: string
purchaseSale: string
threeAvgSale: string
sevenAvgSale: string
fifteenAvgSale: string
}
export interface JstStockMonitorRepository {
@ -119,6 +123,10 @@ class JstStockMonitorRepositoryClass implements JstStockMonitorRepository {
LTRIM(RTRIM(COALESCE(CAST(minimum AS varchar(50)), ''))) AS minimum,
LTRIM(RTRIM(COALESCE(CAST(produceCycle AS varchar(50)), ''))) AS produceCycle,
LTRIM(RTRIM(COALESCE(CAST(trayParameter AS varchar(50)), ''))) AS trayParameter,
LTRIM(RTRIM(COALESCE(CAST(purchaseSale AS varchar(50)), ''))) AS purchaseSale,
LTRIM(RTRIM(COALESCE(CAST(threeAvgSale AS varchar(50)), ''))) AS threeAvgSale,
LTRIM(RTRIM(COALESCE(CAST(sevenAvgSale AS varchar(50)), ''))) AS sevenAvgSale,
LTRIM(RTRIM(COALESCE(CAST(fifteenAvgSale AS varchar(50)), ''))) AS fifteenAvgSale,
ROW_NUMBER() OVER (
PARTITION BY LTRIM(RTRIM(CAST(sku_id AS varchar(100))))
ORDER BY [date] DESC, created DESC, id DESC
@ -126,7 +134,16 @@ class JstStockMonitorRepositoryClass implements JstStockMonitorRepository {
FROM [${schema}].[pm_stockMonitor]
WHERE ${conditions.join(' OR ')}
)
SELECT sku, barcode, minimum, produceCycle, trayParameter
SELECT
sku,
barcode,
minimum,
produceCycle,
trayParameter,
purchaseSale,
threeAvgSale,
sevenAvgSale,
fifteenAvgSale
FROM ranked_stock
WHERE row_rank = 1
`)

View File

@ -102,6 +102,10 @@ describe('supply-chain product archive field mapping', () => {
minimum: '12',
produceCycle: '7',
trayParameter: '40',
purchaseSale: '35.39',
threeAvgSale: '0',
sevenAvgSale: '32.77',
fifteenAvgSale: '34.72',
},
]),
}
@ -147,6 +151,10 @@ describe('supply-chain product archive field mapping', () => {
moq: '12',
firstLeadTime: '7',
palletSpec: '40',
dailySales: '35.39',
sales3d: '0',
sales7d: '32.77',
sales15d: '34.72',
}),
)
expect(supplierProfileRepository.listByNames).toHaveBeenCalledWith([

View File

@ -58,6 +58,12 @@ function mapProductArchiveRow(
warehouseStorageTypes?: Map<string, string>,
warehouseHeads?: Map<string, string>,
) {
const exactBarcodeStockProfile =
stockProfile &&
normalizeStockKey(stockProfile.barcode) === normalizeStockKey(record.barcode)
? stockProfile
: undefined
return {
id: record.id,
image: record.image?.trim() ?? '',
@ -104,6 +110,10 @@ function mapProductArchiveRow(
moq: stockProfile?.minimum || record.minimumOrderQuantity,
firstLeadTime: stockProfile?.produceCycle ?? '',
palletSpec: stockProfile?.trayParameter ?? '',
dailySales: exactBarcodeStockProfile?.purchaseSale ?? '',
sales3d: exactBarcodeStockProfile?.threeAvgSale ?? '',
sales7d: exactBarcodeStockProfile?.sevenAvgSale ?? '',
sales15d: exactBarcodeStockProfile?.fifteenAvgSale ?? '',
} satisfies SupplyChainProductArchiveRow
}