feat: Implement real-time warehouse statistics with GraphQL resolver
- Added fulfillmentWarehouseStats GraphQL query and resolver - Updated StatCard component to use percentChange from GraphQL - Added comprehensive logging for debugging warehouse statistics - Implemented 24-hour change tracking for warehouse metrics - Added polling for real-time statistics updates 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -227,10 +227,30 @@ export function FulfillmentWarehouseDashboard() {
|
||||
error: warehouseStatsError,
|
||||
refetch: refetchWarehouseStats,
|
||||
} = useQuery(GET_FULFILLMENT_WAREHOUSE_STATS, {
|
||||
fetchPolicy: "cache-and-network",
|
||||
fetchPolicy: "no-cache", // Принудительно обходим кеш
|
||||
pollInterval: 60000, // Обновляем каждую минуту
|
||||
});
|
||||
|
||||
// Логируем статистику склада для отладки
|
||||
console.log("📊 WAREHOUSE STATS DEBUG:", {
|
||||
loading: warehouseStatsLoading,
|
||||
error: warehouseStatsError?.message,
|
||||
data: warehouseStatsData,
|
||||
hasData: !!warehouseStatsData?.fulfillmentWarehouseStats,
|
||||
});
|
||||
|
||||
// Детальное логирование данных статистики
|
||||
if (warehouseStatsData?.fulfillmentWarehouseStats) {
|
||||
console.log("📈 DETAILED WAREHOUSE STATS:", {
|
||||
products: warehouseStatsData.fulfillmentWarehouseStats.products,
|
||||
goods: warehouseStatsData.fulfillmentWarehouseStats.goods,
|
||||
defects: warehouseStatsData.fulfillmentWarehouseStats.defects,
|
||||
pvzReturns: warehouseStatsData.fulfillmentWarehouseStats.pvzReturns,
|
||||
fulfillmentSupplies: warehouseStatsData.fulfillmentWarehouseStats.fulfillmentSupplies,
|
||||
sellerSupplies: warehouseStatsData.fulfillmentWarehouseStats.sellerSupplies,
|
||||
});
|
||||
}
|
||||
|
||||
// Получаем данные магазинов, заказов и товаров
|
||||
const allCounterparties = counterpartiesData?.myCounterparties || [];
|
||||
const sellerPartners = allCounterparties.filter(
|
||||
@ -974,6 +994,7 @@ export function FulfillmentWarehouseDashboard() {
|
||||
icon: Icon,
|
||||
current,
|
||||
change,
|
||||
percentChange,
|
||||
description,
|
||||
onClick,
|
||||
}: {
|
||||
@ -981,10 +1002,14 @@ export function FulfillmentWarehouseDashboard() {
|
||||
icon: React.ComponentType<{ className?: string }>;
|
||||
current: number;
|
||||
change: number;
|
||||
percentChange?: number;
|
||||
description: string;
|
||||
onClick?: () => void;
|
||||
}) => {
|
||||
const percentChange = current > 0 ? (change / current) * 100 : 0;
|
||||
// Используем percentChange из GraphQL, если доступно, иначе вычисляем локально
|
||||
const displayPercentChange = percentChange !== undefined && percentChange !== null && !isNaN(percentChange)
|
||||
? percentChange
|
||||
: (current > 0 ? (change / current) * 100 : 0);
|
||||
|
||||
return (
|
||||
<div
|
||||
@ -1012,7 +1037,7 @@ export function FulfillmentWarehouseDashboard() {
|
||||
change >= 0 ? "text-green-400" : "text-red-400"
|
||||
}`}
|
||||
>
|
||||
{percentChange.toFixed(1)}%
|
||||
{displayPercentChange.toFixed(1)}%
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
@ -1199,6 +1224,7 @@ export function FulfillmentWarehouseDashboard() {
|
||||
icon={Box}
|
||||
current={warehouseStats.products.current}
|
||||
change={warehouseStats.products.change}
|
||||
percentChange={warehouseStatsData?.fulfillmentWarehouseStats?.products?.percentChange}
|
||||
description="Готовые к отправке"
|
||||
/>
|
||||
<StatCard
|
||||
@ -1206,6 +1232,7 @@ export function FulfillmentWarehouseDashboard() {
|
||||
icon={Package}
|
||||
current={warehouseStats.goods.current}
|
||||
change={warehouseStats.goods.change}
|
||||
percentChange={warehouseStatsData?.fulfillmentWarehouseStats?.goods?.percentChange}
|
||||
description="В обработке"
|
||||
/>
|
||||
<StatCard
|
||||
@ -1213,6 +1240,7 @@ export function FulfillmentWarehouseDashboard() {
|
||||
icon={AlertTriangle}
|
||||
current={warehouseStats.defects.current}
|
||||
change={warehouseStats.defects.change}
|
||||
percentChange={warehouseStatsData?.fulfillmentWarehouseStats?.defects?.percentChange}
|
||||
description="Требует утилизации"
|
||||
/>
|
||||
<StatCard
|
||||
@ -1220,6 +1248,7 @@ export function FulfillmentWarehouseDashboard() {
|
||||
icon={RotateCcw}
|
||||
current={warehouseStats.pvzReturns.current}
|
||||
change={warehouseStats.pvzReturns.change}
|
||||
percentChange={warehouseStatsData?.fulfillmentWarehouseStats?.pvzReturns?.percentChange}
|
||||
description="К обработке"
|
||||
/>
|
||||
<StatCard
|
||||
@ -1227,6 +1256,7 @@ export function FulfillmentWarehouseDashboard() {
|
||||
icon={Wrench}
|
||||
current={warehouseStats.fulfillmentSupplies.current}
|
||||
change={warehouseStats.fulfillmentSupplies.change}
|
||||
percentChange={warehouseStatsData?.fulfillmentWarehouseStats?.fulfillmentSupplies?.percentChange}
|
||||
description="Расходники, этикетки"
|
||||
onClick={() => router.push("/fulfillment-warehouse/supplies")}
|
||||
/>
|
||||
@ -1235,6 +1265,7 @@ export function FulfillmentWarehouseDashboard() {
|
||||
icon={Users}
|
||||
current={warehouseStats.sellerSupplies.current}
|
||||
change={warehouseStats.sellerSupplies.change}
|
||||
percentChange={warehouseStatsData?.fulfillmentWarehouseStats?.sellerSupplies?.percentChange}
|
||||
description="Материалы клиентов"
|
||||
/>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user