fix(clearance): 移除清货价页面自动对账
This commit is contained in:
parent
e223b086f6
commit
abe3cd3887
@ -261,7 +261,8 @@ describe('supply chain clearance price push service', () => {
|
||||
}],
|
||||
}),
|
||||
})
|
||||
const service = new SupplyChainClearancePricePushService(repo, { getTasks: jest.fn() } as never)
|
||||
const taskReader = { getTasks: jest.fn() }
|
||||
const service = new SupplyChainClearancePricePushService(repo, taskReader as never)
|
||||
|
||||
await expect(service.getPage({ periodKey: '2026-11', page: 1, pageSize: 50 }))
|
||||
.resolves.toMatchObject({
|
||||
@ -274,6 +275,8 @@ describe('supply chain clearance price push service', () => {
|
||||
historicalCostPrice: 60,
|
||||
}],
|
||||
})
|
||||
expect(repo.replaceSnapshot).not.toHaveBeenCalled()
|
||||
expect(taskReader.getTasks).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('restores abnormal prior-month discounted products to their cost price', async () => {
|
||||
|
||||
@ -15,8 +15,6 @@ import {
|
||||
} from './supply-chain-clearance.service'
|
||||
|
||||
const PERIOD_PATTERN = /^\d{4}-(0[1-9]|1[0-2])$/
|
||||
const AUTO_SYNC_TTL_MS = 5 * 60 * 1_000
|
||||
const lastAutomaticSyncAt = new Map<string, number>()
|
||||
|
||||
type PricePushRepository = Pick<
|
||||
typeof supplyChainClearancePricePushRepository,
|
||||
@ -77,37 +75,10 @@ export class SupplyChainClearancePricePushService {
|
||||
pageSize?: number
|
||||
filters?: ClearancePricePushFilters
|
||||
}) {
|
||||
const requestedPeriod = PERIOD_PATTERN.test(String(input.periodKey ?? '').trim())
|
||||
? String(input.periodKey).trim()
|
||||
: ''
|
||||
if (requestedPeriod) {
|
||||
const lastSyncAt = lastAutomaticSyncAt.get(requestedPeriod) ?? 0
|
||||
if (Date.now() - lastSyncAt >= AUTO_SYNC_TTL_MS) {
|
||||
try {
|
||||
await this.syncApprovedTasks(requestedPeriod)
|
||||
} catch (error) {
|
||||
console.error('[clearance-price-push] automatic task sync failed', {
|
||||
periodKey: requestedPeriod,
|
||||
error,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
let snapshots = await this.repository.listSnapshots()
|
||||
const snapshots = await this.repository.listSnapshots()
|
||||
const periodKey = PERIOD_PATTERN.test(String(input.periodKey ?? '').trim())
|
||||
? String(input.periodKey).trim()
|
||||
: snapshots[0]?.periodKey ?? shanghaiPeriodKey()
|
||||
if (!snapshots.some((snapshot) => snapshot.periodKey === periodKey)) {
|
||||
try {
|
||||
await this.syncApprovedTasks(periodKey)
|
||||
snapshots = await this.repository.listSnapshots()
|
||||
} catch (error) {
|
||||
console.error('[clearance-price-push] initial task sync failed', {
|
||||
periodKey,
|
||||
error,
|
||||
})
|
||||
}
|
||||
}
|
||||
const page = Math.max(1, Math.floor(input.page ?? 1))
|
||||
const pageSize = Math.min(200, Math.max(20, Math.floor(input.pageSize ?? 50)))
|
||||
try {
|
||||
@ -281,7 +252,6 @@ export class SupplyChainClearancePricePushService {
|
||||
generatedByName: input.user.name,
|
||||
items: plan.items,
|
||||
})
|
||||
lastAutomaticSyncAt.set(periodKey, Date.now())
|
||||
return {
|
||||
periodKey,
|
||||
startDate: `${periodKey}-01`,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user