cache for store chard

This commit is contained in:
Timi
2026-08-24 18:32:48 +08:00
parent 6235cb3e3d
commit fe5d190308
8 changed files with 102 additions and 23 deletions
+29 -9
View File
@@ -1,30 +1,48 @@
import { axios } from "timi-web";
import EventAPI from "@/api/EventAPI";
import StoreAPI from "@/api/StoreAPI";
import type { CustomerDailyStatView, CustomerGenderStatView } from "@/types/Customer";
import type { StoreChartReq, StoreEventRecordCalendarView, StoreEventRecordDailyStatView, StoreEventRecordNumberValueDailyStatView } from "@/types/Store";
import type { EventItem } from "@/types/EventItem";
import type { StoreBusinessDay, StoreChartReq, StoreEventRecordCalendarView, StoreEventRecordDailyStatView, StoreEventRecordNumberValueDailyStatView } from "@/types/Store";
import { getStoreChartCache } from "@/utils/storeChartCache";
import { getCurrentStoreId, withCurrentStoreId } from "@/utils/store";
const BASE_URI = "/gao/store/chart";
async function customerDailyStat(req: StoreChartReq): Promise<CustomerDailyStatView[]> {
return await axios.post(`${BASE_URI}/customer/daily`, withCurrentStoreId(req));
const request = withCurrentStoreId(req);
return await getStoreChartCache(`customer-daily:${JSON.stringify(request)}`, async () => await axios.post(`${BASE_URI}/customer/daily`, request));
}
async function customerGenderStat(): Promise<CustomerGenderStatView[]> {
return await axios.post(`${BASE_URI}/customer/gender`, undefined, {
params: { storeId: getCurrentStoreId() }
});
const storeId = getCurrentStoreId();
return await getStoreChartCache(`customer-gender:${storeId}`, async () => await axios.post(`${BASE_URI}/customer/gender`, undefined, {
params: { storeId }
}));
}
async function eventRecordDailyStat(req: StoreChartReq): Promise<StoreEventRecordDailyStatView[]> {
return await axios.post(`${BASE_URI}/event/record/daily`, withCurrentStoreId(req));
const request = withCurrentStoreId(req);
return await getStoreChartCache(`event-record-daily:${JSON.stringify(request)}`, async () => await axios.post(`${BASE_URI}/event/record/daily`, request));
}
async function eventRecordNumberValueDailyStat(req: StoreChartReq): Promise<StoreEventRecordNumberValueDailyStatView[]> {
return await axios.post(`${BASE_URI}/event/record/number-value/daily`, withCurrentStoreId(req));
const request = withCurrentStoreId(req);
return await getStoreChartCache(`event-record-number-value-daily:${JSON.stringify(request)}`, async () => await axios.post(`${BASE_URI}/event/record/number-value/daily`, request));
}
async function eventRecordCalendar(req: StoreChartReq): Promise<StoreEventRecordCalendarView[]> {
return await axios.post(`${BASE_URI}/event/record/calendar`, withCurrentStoreId(req));
const request = withCurrentStoreId(req);
return await getStoreChartCache(`event-record-calendar:${JSON.stringify(request)}`, async () => await axios.post(`${BASE_URI}/event/record/calendar`, request));
}
async function listValidEvents(): Promise<EventItem[]> {
const storeId = getCurrentStoreId();
return await getStoreChartCache(`valid-events:${storeId}`, async () => await EventAPI.listValid());
}
async function businessDayCalendar(storeId: string, beginDateValue: number, endDateValue: number): Promise<StoreBusinessDay[]> {
return await getStoreChartCache(`business-day-calendar:${storeId}:${beginDateValue}:${endDateValue}`, async () => await StoreAPI.businessDayCalendar(storeId, beginDateValue, endDateValue));
}
export default {
@@ -32,5 +50,7 @@ export default {
customerGenderStat,
eventRecordDailyStat,
eventRecordNumberValueDailyStat,
eventRecordCalendar
eventRecordCalendar,
listValidEvents,
businessDayCalendar
};