add product/order chart
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
import { axios } from "timi-web-api";
|
||||
import type {
|
||||
GaoProductCategoryStatView,
|
||||
GaoProductChartReq,
|
||||
GaoProductFulfillmentDailyStatView,
|
||||
GaoProductFulfillmentRankView,
|
||||
GaoProductSalesDailyStatView,
|
||||
GaoProductSalesRankView,
|
||||
GaoProductStockHealthView,
|
||||
GaoProductStockMovementDailyStatView,
|
||||
GaoProductTypeStatView,
|
||||
GaoProductSkuUnitSalesRankView
|
||||
} from "@/types/GaoChart";
|
||||
import { getStoreChartCache } from "@/utils/storeChartCache";
|
||||
import { withCurrentStoreId } from "@/utils/store";
|
||||
|
||||
const BASE_URI = "/gao/product/chart";
|
||||
|
||||
async function salesDaily(req: GaoProductChartReq): Promise<GaoProductSalesDailyStatView[]> {
|
||||
return await requestList("sales-daily", "/sales/daily", req);
|
||||
}
|
||||
|
||||
async function salesRank(req: GaoProductChartReq): Promise<GaoProductSalesRankView[]> {
|
||||
return await requestList("sales-rank", "/sales/rank", req);
|
||||
}
|
||||
|
||||
async function unitSalesRank(req: GaoProductChartReq): Promise<GaoProductSkuUnitSalesRankView[]> {
|
||||
const list = await requestList<GaoProductSkuUnitSalesRankView & Record<string, unknown>>("sales-unit-rank", "/sales/unit/rank", req);
|
||||
return list.map(item => ({
|
||||
...item,
|
||||
skuUnitId: item.skuUnitId || (typeof item["productUnitId"] === "string" ? item["productUnitId"] : undefined)
|
||||
}));
|
||||
}
|
||||
|
||||
async function fulfillmentDaily(req: GaoProductChartReq): Promise<GaoProductFulfillmentDailyStatView[]> {
|
||||
return await requestList("fulfillment-daily", "/fulfillment/daily", req);
|
||||
}
|
||||
|
||||
async function fulfillmentRank(req: GaoProductChartReq): Promise<GaoProductFulfillmentRankView[]> {
|
||||
return await requestList("fulfillment-rank", "/fulfillment/rank", req);
|
||||
}
|
||||
|
||||
async function stockMovementDaily(req: GaoProductChartReq): Promise<GaoProductStockMovementDailyStatView[]> {
|
||||
return await requestList("stock-movement-daily", "/stock/movement/daily", req);
|
||||
}
|
||||
|
||||
async function stockHealth(req: GaoProductChartReq): Promise<GaoProductStockHealthView[]> {
|
||||
return await requestList("stock-health", "/stock/health", req);
|
||||
}
|
||||
|
||||
async function type(req: GaoProductChartReq): Promise<GaoProductTypeStatView[]> {
|
||||
return await requestList("structure-type", "/structure/type", req);
|
||||
}
|
||||
|
||||
async function category(req: GaoProductChartReq): Promise<GaoProductCategoryStatView[]> {
|
||||
return await requestList("structure-category", "/structure/category", req);
|
||||
}
|
||||
|
||||
async function requestList<T>(name: string, path: string, req: GaoProductChartReq): Promise<T[]> {
|
||||
const request = withCurrentStoreId(req);
|
||||
return await getStoreChartCache(`gao-product:${name}:${JSON.stringify(request)}`, async () => await axios.post(`${BASE_URI}${path}`, request));
|
||||
}
|
||||
|
||||
export default {
|
||||
salesDaily,
|
||||
salesRank,
|
||||
unitSalesRank,
|
||||
fulfillmentDaily,
|
||||
fulfillmentRank,
|
||||
stockMovementDaily,
|
||||
stockHealth,
|
||||
type,
|
||||
category
|
||||
};
|
||||
@@ -0,0 +1,83 @@
|
||||
import { axios } from "timi-web-api";
|
||||
import type {
|
||||
GaoCustomerOrderProductRankView,
|
||||
GaoCustomerOrderRankView,
|
||||
GaoCustomerRepeatDailyStatView,
|
||||
GaoCustomerRepeatIntervalStatView,
|
||||
GaoSalesOrderCalendarStatView,
|
||||
GaoSalesOrderChartReq,
|
||||
GaoSalesOrderConsumptionDailyStatView,
|
||||
GaoSalesOrderDailyStatView,
|
||||
GaoSalesOrderPaymentStatView,
|
||||
GaoSalesOrderReceivableStatView,
|
||||
GaoSalesOrderStatusStatView,
|
||||
GaoSalesOrderTypeStatView
|
||||
} from "@/types/GaoChart";
|
||||
import { getStoreChartCache } from "@/utils/storeChartCache";
|
||||
import { withCurrentStoreId } from "@/utils/store";
|
||||
|
||||
const BASE_URI = "/gao/sales/order/chart";
|
||||
|
||||
async function daily(req: GaoSalesOrderChartReq): Promise<GaoSalesOrderDailyStatView[]> {
|
||||
return await requestList("daily", "/daily", req);
|
||||
}
|
||||
|
||||
async function type(req: GaoSalesOrderChartReq): Promise<GaoSalesOrderTypeStatView[]> {
|
||||
return await requestList("type", "/type", req);
|
||||
}
|
||||
|
||||
async function payment(req: GaoSalesOrderChartReq): Promise<GaoSalesOrderPaymentStatView[]> {
|
||||
return await requestList("payment", "/payment", req);
|
||||
}
|
||||
|
||||
async function status(req: GaoSalesOrderChartReq): Promise<GaoSalesOrderStatusStatView[]> {
|
||||
return await requestList("status", "/status", req);
|
||||
}
|
||||
|
||||
async function receivable(req: GaoSalesOrderChartReq): Promise<GaoSalesOrderReceivableStatView> {
|
||||
const request = withCurrentStoreId(req);
|
||||
return await getStoreChartCache(`gao-order:receivable:${JSON.stringify(request)}`, async () => await axios.post(`${BASE_URI}/receivable`, request));
|
||||
}
|
||||
|
||||
async function customerRank(req: GaoSalesOrderChartReq): Promise<GaoCustomerOrderRankView[]> {
|
||||
return await requestList("customer-rank", "/customer/rank", req);
|
||||
}
|
||||
|
||||
async function customerProductRank(req: GaoSalesOrderChartReq): Promise<GaoCustomerOrderProductRankView[]> {
|
||||
return await requestList("customer-product-rank", "/customer/product/rank", req);
|
||||
}
|
||||
|
||||
async function consumptionDaily(req: GaoSalesOrderChartReq): Promise<GaoSalesOrderConsumptionDailyStatView[]> {
|
||||
return await requestList("customer-consumption-daily", "/customer/consumption/daily", req);
|
||||
}
|
||||
|
||||
async function calendar(req: GaoSalesOrderChartReq): Promise<GaoSalesOrderCalendarStatView[]> {
|
||||
return await requestList("customer-calendar", "/customer/calendar", req);
|
||||
}
|
||||
|
||||
async function repeatDaily(req: GaoSalesOrderChartReq): Promise<GaoCustomerRepeatDailyStatView[]> {
|
||||
return await requestList("customer-repeat-daily", "/customer/repeat/daily", req);
|
||||
}
|
||||
|
||||
async function repeatInterval(req: GaoSalesOrderChartReq): Promise<GaoCustomerRepeatIntervalStatView[]> {
|
||||
return await requestList("customer-repeat-interval", "/customer/repeat/interval", req);
|
||||
}
|
||||
|
||||
async function requestList<T>(name: string, path: string, req: GaoSalesOrderChartReq): Promise<T[]> {
|
||||
const request = withCurrentStoreId(req);
|
||||
return await getStoreChartCache(`gao-order:${name}:${JSON.stringify(request)}`, async () => await axios.post(`${BASE_URI}${path}`, request));
|
||||
}
|
||||
|
||||
export default {
|
||||
daily,
|
||||
type,
|
||||
payment,
|
||||
status,
|
||||
receivable,
|
||||
customerRank,
|
||||
customerProductRank,
|
||||
consumptionDaily,
|
||||
calendar,
|
||||
repeatDaily,
|
||||
repeatInterval
|
||||
};
|
||||
Reference in New Issue
Block a user