mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 18:29:19 +08:00
refacor: 重构目录架构
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import type { AdvertisingCostItem } from '@/types/advertisingCost';
|
||||
|
||||
function itemKey(item: AdvertisingCostItem): string {
|
||||
return `${item.feeDate}::${item.goodsId}`;
|
||||
}
|
||||
|
||||
function compareByAmountDesc(a: AdvertisingCostItem, b: AdvertisingCostItem): number {
|
||||
const byAmount = Number(b.feeAmount) - Number(a.feeAmount);
|
||||
if (byAmount !== 0) return byAmount;
|
||||
const byDate = b.feeDate.localeCompare(a.feeDate);
|
||||
if (byDate !== 0) return byDate;
|
||||
return a.goodsId.localeCompare(b.goodsId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 合并多次单日读取:按 (feeDate, goodsId) upsert。
|
||||
* 换日再读保留已有日期;同日再读覆盖该日同商品。
|
||||
* 合并后按金额降序。
|
||||
*/
|
||||
export function mergeAdvertisingItems(
|
||||
previous: AdvertisingCostItem[],
|
||||
incoming: AdvertisingCostItem[],
|
||||
): AdvertisingCostItem[] {
|
||||
const map = new Map<string, AdvertisingCostItem>();
|
||||
for (const item of previous) {
|
||||
map.set(itemKey(item), item);
|
||||
}
|
||||
for (const item of incoming) {
|
||||
map.set(itemKey(item), item);
|
||||
}
|
||||
return Array.from(map.values()).sort(compareByAmountDesc);
|
||||
}
|
||||
|
||||
export function listFeeDates(items: AdvertisingCostItem[]): string[] {
|
||||
return [...new Set(items.map((item) => item.feeDate))].sort();
|
||||
}
|
||||
Reference in New Issue
Block a user