forked from lunanting/cangku
- 看板只展示当日待补 SKU(待发订单>拣货位库存,需存储→拣货补货),去除充足/无待发干扰行 - 库存收紧到崔桥工厂仓主仓(jst_packInventoryInfo 加 wh_id=1),数据源对齐「箱及仓位库存·主仓」 - 补齐「有打单拣货待发单但货位库存视图无记录」的 SKU(拣货位为0也应进待补明细) - 指标卡改为四项:实时代发订单数 / 拣货库存数 / 存储库存数 / 缺货数(缺货=待补SKU数,脚注含存储不足子项) - 各库底待补明细=need+short 行;范围筛「待补货/仅缺货」;移除多仓选择器,固定崔桥 - 待发订单仍取 op_OrderNotDispatched 打单拣货/发货中 每日快照(两步 querySlow) - 副本实测:当日快照待补 45 SKU(need42/short3),待发132件/拣货40件/存储2381件/缺口5件
412 lines
15 KiB
JavaScript
412 lines
15 KiB
JavaScript
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||
import {
|
||
Alert, Button, Empty, Input, Segmented, Spin, Table, Tag, Tooltip,
|
||
message,
|
||
} from 'antd';
|
||
import {
|
||
DownloadOutlined, InfoCircleOutlined, ReloadOutlined, SearchOutlined,
|
||
} from '@ant-design/icons';
|
||
import { exportBinReplenish, getBinReplenishList } from '../../api/binReplenish';
|
||
import { downloadBlobAsFile, readBlobErrorMessage } from '../../utils/tableExport';
|
||
import { SycmPage } from '../../components/Common';
|
||
import './style.css';
|
||
|
||
const num = (value) => (value === null || value === undefined || value === ''
|
||
? '--'
|
||
: Number(value).toLocaleString('zh-CN'));
|
||
|
||
const STATUS_TAGS = {
|
||
short: { color: 'red', label: '存储不足' },
|
||
need: { color: 'gold', label: '需补货' },
|
||
enough: { color: 'green', label: '拣货位充足' },
|
||
no_order: { color: 'default', label: '无待发单' },
|
||
};
|
||
|
||
const STATUS_OPTIONS = [
|
||
{ label: '待补货', value: 'replenish' },
|
||
{ label: '仅缺货', value: 'short' },
|
||
];
|
||
|
||
const BinReplenishMonitor = () => {
|
||
const [warehouse, setWarehouse] = useState('cuiqiao');
|
||
const [status, setStatus] = useState('replenish');
|
||
const [keyword, setKeyword] = useState('');
|
||
const [page, setPage] = useState(1);
|
||
const [pageSize, setPageSize] = useState(50);
|
||
|
||
const [loading, setLoading] = useState(true);
|
||
const [refreshing, setRefreshing] = useState(false);
|
||
const [error, setError] = useState('');
|
||
const [data, setData] = useState({
|
||
rows: [], total: 0, summary: {}, warehouse: null, warehouses: [], orderScope: '', updatedAt: '', cacheHit: false,
|
||
});
|
||
const keywordTimer = useRef(null);
|
||
|
||
const load = useCallback(async (options = {}) => {
|
||
const isRefresh = options.refresh === true;
|
||
if (isRefresh) setRefreshing(true);
|
||
else setLoading(true);
|
||
setError('');
|
||
try {
|
||
const response = await getBinReplenishList({
|
||
warehouse,
|
||
status,
|
||
keyword,
|
||
page: options.page || page,
|
||
pageSize: options.pageSize || pageSize,
|
||
refresh: isRefresh ? 'true' : undefined,
|
||
});
|
||
const payload = response?.data?.data || response?.data || {};
|
||
setData({
|
||
rows: payload.rows || [],
|
||
total: payload.total || 0,
|
||
summary: payload.summary || {},
|
||
warehouse: payload.warehouse || null,
|
||
warehouses: payload.warehouses || [],
|
||
orderScope: payload.orderScope || '',
|
||
updatedAt: payload.updatedAt || '',
|
||
cacheHit: Boolean(payload.cacheHit),
|
||
});
|
||
if (isRefresh) message.success('已重新回源取数');
|
||
} catch (err) {
|
||
setError(err?.message || '加载失败');
|
||
} finally {
|
||
setLoading(false);
|
||
setRefreshing(false);
|
||
}
|
||
}, [warehouse, status, keyword, page, pageSize]);
|
||
|
||
useEffect(() => {
|
||
load();
|
||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||
}, [warehouse, status, page, pageSize]);
|
||
|
||
useEffect(() => {
|
||
if (keywordTimer.current) clearTimeout(keywordTimer.current);
|
||
keywordTimer.current = setTimeout(() => {
|
||
setPage(1);
|
||
load({ page: 1 });
|
||
}, 400);
|
||
return () => { if (keywordTimer.current) clearTimeout(keywordTimer.current); };
|
||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||
}, [keyword]);
|
||
|
||
const summary = data.summary;
|
||
const needCount = (summary.need || 0) + (summary.short || 0);
|
||
|
||
const metrics = useMemo(() => ([
|
||
{
|
||
key: 'order',
|
||
tone: 'blue',
|
||
label: '实时代发订单数',
|
||
value: summary.orderQtyTotal || 0,
|
||
unit: '件',
|
||
foot: `待补 ${num(summary.skuTotal)} 个 SKU`,
|
||
tip: '待补 SKU 的待发订单件数合计(取聚水潭「打单拣货 → 发货中」每日快照,组合装已展开为子件;不含已发/异常/待审核)',
|
||
},
|
||
{
|
||
key: 'pick',
|
||
tone: 'green',
|
||
label: '拣货库存数',
|
||
value: summary.pickTotal || 0,
|
||
unit: '件',
|
||
foot: '待补 SKU 拣货位库存',
|
||
tip: '待补 SKU 在 XA / XD / XE 拣货位上的库存合计(库存取自聚水潭「箱及仓位库存 · 简尚-崔桥工厂仓 主仓」)',
|
||
},
|
||
{
|
||
key: 'store',
|
||
tone: 'orange',
|
||
label: '存储库存数',
|
||
value: summary.storageTotal || 0,
|
||
unit: '件',
|
||
foot: '待补 SKU 存储位库存',
|
||
tip: '待补 SKU 在 XX / X9 / X5 / X4 存储位上的库存合计(同上来源,主仓)',
|
||
},
|
||
{
|
||
key: 'short',
|
||
tone: 'red',
|
||
label: '缺货数',
|
||
value: summary.skuTotal || 0,
|
||
unit: '个',
|
||
foot: `其中存储不足 ${num(summary.short)} 个,缺口 ${num(summary.shortfallTotal)} 件`,
|
||
tip: '需要从存储位补到拣货位的 SKU 数(待发订单量 > 拣货位库存);其中存储位也补不齐的标为「缺货」,需采购 / 紧急调拨',
|
||
},
|
||
]), [summary, needCount]);
|
||
|
||
const handleExport = async () => {
|
||
try {
|
||
const response = await exportBinReplenish({ warehouse, status, keyword });
|
||
downloadBlobAsFile(response.data, `${(data.warehouse || {}).shortName || '仓库'}缺货补货监控_待发订单.xlsx`);
|
||
} catch (error_) {
|
||
const text = await readBlobErrorMessage(error_);
|
||
message.error(text || '导出失败');
|
||
}
|
||
};
|
||
|
||
const columns = [
|
||
{
|
||
title: '状态',
|
||
dataIndex: 'status',
|
||
width: 100,
|
||
fixed: 'left',
|
||
render: (value) => {
|
||
const tag = STATUS_TAGS[value] || STATUS_TAGS.no_order;
|
||
return <Tag color={tag.color} className="brp-status-tag">{tag.label}</Tag>;
|
||
},
|
||
},
|
||
{
|
||
title: '商品编码',
|
||
dataIndex: 'skuId',
|
||
width: 175,
|
||
render: (value, row) => (
|
||
<div className="brp-sku">
|
||
<span className="brp-sku__code">{value}</span>
|
||
{row.supplier ? <span className="brp-sku__supplier">{row.supplier}</span> : null}
|
||
</div>
|
||
),
|
||
},
|
||
{ title: '品名', dataIndex: 'productName', width: 260, ellipsis: true },
|
||
{
|
||
title: '拣货位库存',
|
||
dataIndex: 'pickQty',
|
||
width: 100,
|
||
align: 'right',
|
||
render: (value, row) => (
|
||
<span className={Number(value) <= 0 ? 'brp-qty brp-qty--zero' : 'brp-qty'}>
|
||
{num(value)}{row.pickEmpty ? ' ⚠' : ''}
|
||
</span>
|
||
),
|
||
},
|
||
{
|
||
title: '存储位库存',
|
||
dataIndex: 'storageQty',
|
||
width: 100,
|
||
align: 'right',
|
||
render: (value) => <span className="brp-qty">{num(value)}</span>,
|
||
},
|
||
{
|
||
title: '待发订单',
|
||
dataIndex: 'orderQty',
|
||
width: 100,
|
||
align: 'right',
|
||
render: (value) => <span className="brp-qty">{num(value)}</span>,
|
||
},
|
||
{
|
||
title: '超出订单数',
|
||
dataIndex: 'excess',
|
||
width: 100,
|
||
align: 'right',
|
||
render: (value) => (
|
||
<span className={Number(value) > 0 ? 'brp-qty brp-qty--warn' : 'brp-qty brp-qty--zero'}>{num(value)}</span>
|
||
),
|
||
},
|
||
{
|
||
title: '建议补货量',
|
||
dataIndex: 'suggestQty',
|
||
width: 110,
|
||
align: 'right',
|
||
render: (value) => (
|
||
<span className={Number(value) > 0 ? 'brp-qty brp-qty--suggest' : 'brp-qty brp-qty--zero'}>
|
||
{num(value)}
|
||
</span>
|
||
),
|
||
},
|
||
{
|
||
title: '存储缺口',
|
||
dataIndex: 'shortfall',
|
||
width: 100,
|
||
align: 'right',
|
||
render: (value) => (
|
||
<span className={Number(value) > 0 ? 'brp-qty brp-qty--danger' : 'brp-qty brp-qty--zero'}>{num(value)}</span>
|
||
),
|
||
},
|
||
{
|
||
title: '现有库存',
|
||
dataIndex: 'totalQty',
|
||
width: 100,
|
||
align: 'right',
|
||
render: (value) => <span className="brp-qty">{num(value)}</span>,
|
||
},
|
||
];
|
||
|
||
return (
|
||
<SycmPage className="brp-page">
|
||
<div className="brp-hero">
|
||
<div className="brp-hero__main">
|
||
<h1 className="brp-hero__title">缺货补货监控</h1>
|
||
<p className="brp-hero__desc">
|
||
本看板只盯<b>崔桥工厂仓(主仓)</b>的<b>当日待补</b>数据:也就是那些待发订单超过拣货位库存、
|
||
需要把货从<b>存储位</b>补到<b>拣货位</b>的 SKU。订单取自聚水潭「打单拣货 → 简尚-崔桥工厂仓」的发货中单据,
|
||
库存取自聚水潭「箱及仓位库存 → 简尚-崔桥工厂仓 主仓」。<b>已发货的不再计入</b>(货已发出、不再消耗拣货位)。
|
||
</p>
|
||
</div>
|
||
<div className="brp-hero__meta">
|
||
<div>
|
||
仓库:<b>{(data.warehouse || {}).name || '简尚-崔桥工厂仓'}</b>
|
||
</div>
|
||
<div>
|
||
统计口径:<b>{data.orderScope || '待发订单 = 聚水潭「打单拣货」发货中快照(不含已发/异常/待审核)'}</b>
|
||
</div>
|
||
<div>
|
||
取数时间:<b>{data.updatedAt ? new Date(data.updatedAt).toLocaleString('zh-CN') : '--'}</b>
|
||
{data.cacheHit ? <span className="brp-muted">(缓存)</span> : null}
|
||
</div>
|
||
<div>
|
||
共 <b>{num(summary.skuTotal)}</b> 个待补 SKU,其中存储不足(缺货)<b>{num(summary.short)}</b> 个
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div className="brp-metrics">
|
||
{metrics.map((item) => (
|
||
<div key={item.key} className={`brp-metric brp-metric--${item.tone}`}>
|
||
<Tooltip title={item.tip}>
|
||
<div className="brp-metric__label">
|
||
{item.label}
|
||
<InfoCircleOutlined className="brp-metric__info" />
|
||
</div>
|
||
</Tooltip>
|
||
<div className="brp-metric__value">
|
||
{num(item.value)}
|
||
<span className="brp-metric__unit">{item.unit}</span>
|
||
</div>
|
||
<div className="brp-metric__foot">{item.foot}</div>
|
||
</div>
|
||
))}
|
||
</div>
|
||
|
||
<div className="brp-toolbar">
|
||
<span className="brp-toolbar__field">
|
||
<span className="brp-toolbar__label">仓库</span>
|
||
<span className="brp-toolbar__static">简尚-崔桥工厂仓(主仓)</span>
|
||
</span>
|
||
<span className="brp-toolbar__field">
|
||
<span className="brp-toolbar__label">范围</span>
|
||
<Segmented
|
||
value={status}
|
||
onChange={(value) => { setStatus(value); setPage(1); }}
|
||
options={STATUS_OPTIONS.map((item) => ({
|
||
...item,
|
||
label: item.value === 'replenish'
|
||
? `${item.label} ${num(needCount)}`
|
||
: `${item.label} ${num(summary.short || 0)}`,
|
||
}))}
|
||
/>
|
||
</span>
|
||
<Input
|
||
allowClear
|
||
value={keyword}
|
||
onChange={(event) => setKeyword(event.target.value)}
|
||
placeholder="搜商品编码 / 品名 / 供应商"
|
||
prefix={<SearchOutlined />}
|
||
style={{ width: 260 }}
|
||
/>
|
||
<span className="brp-toolbar__spacer" />
|
||
<Button icon={<DownloadOutlined />} onClick={handleExport}>导出</Button>
|
||
<Button
|
||
type="primary"
|
||
icon={<ReloadOutlined />}
|
||
loading={refreshing}
|
||
onClick={() => load({ refresh: true })}
|
||
>
|
||
刷新数据
|
||
</Button>
|
||
</div>
|
||
|
||
<Alert
|
||
type="info"
|
||
showIcon
|
||
className="brp-alert"
|
||
message="货位口径(崔桥工厂仓 主仓约定)"
|
||
description={(
|
||
<span>
|
||
库存只取 <b>崔桥工厂仓主仓(wh_id=1)</b>;拣货库位以 <b>XA / XD / XE</b> 开头,存储库位以 <b>XX / X9 / X5 / X4</b> 开头;
|
||
其余货位(DB / Y* / Z* 等,占比极小)不计入。
|
||
判断规则:<b>待发订单量 > 拣货位库存</b> 时,超出的订单数 = 需要从存储位补到拣货位的量(上限为存储位现有库存)。
|
||
</span>
|
||
)}
|
||
/>
|
||
|
||
{error ? (
|
||
<Alert
|
||
type="error"
|
||
showIcon
|
||
className="brp-alert"
|
||
message={error}
|
||
action={<Button size="small" onClick={() => load()}>重试</Button>}
|
||
/>
|
||
) : null}
|
||
|
||
<Spin
|
||
spinning={loading}
|
||
tip="正在聚合仓位库存 + 待发订单,首次约 30~90 秒"
|
||
wrapperClassName="brp-table-spin"
|
||
>
|
||
<Table
|
||
rowKey="skuId"
|
||
size="small"
|
||
className="brp-table"
|
||
columns={columns}
|
||
dataSource={data.rows}
|
||
scroll={{ x: 1500 }}
|
||
locale={{
|
||
emptyText: (
|
||
<Empty
|
||
description={status === 'replenish'
|
||
? '当前没有需要补货的拣货位'
|
||
: '没有符合条件的商品'}
|
||
/>
|
||
),
|
||
}}
|
||
pagination={{
|
||
current: page,
|
||
pageSize,
|
||
total: data.total,
|
||
showSizeChanger: true,
|
||
pageSizeOptions: ['20', '50', '100', '200'],
|
||
showTotal: (total) => `共 ${total} 个 SKU`,
|
||
onChange: (nextPage, nextSize) => {
|
||
setPage(nextPage);
|
||
setPageSize(nextSize);
|
||
},
|
||
}}
|
||
/>
|
||
</Spin>
|
||
|
||
<div className="brp-notes">
|
||
<div className="brp-notes__title">数据来源与口径说明</div>
|
||
<ul>
|
||
<li>
|
||
<b>库存</b>:聚水潭「箱及仓位库存 → 简尚-崔桥工厂仓 主仓」(rpt.jst_packInventoryInfo,仅 <b>wh_id=1 主仓</b>),
|
||
按商品编码(sku_id)聚合。「拣货位库存」= 货位号以 XA/XD/XE 开头的库存合计;
|
||
「存储位库存」= 货位号以 XX/X9/X5/X4 开头的库存合计。
|
||
</li>
|
||
<li>
|
||
<b>订单</b>:直接取聚水潭「<b>打单拣货 → 简尚-崔桥工厂仓</b>」的发货中单据快照 = rpt.op_OrderNotDispatched
|
||
(该仓<b>最新快照日</b>、status=发货中),SKU 级、组合装已展开为子件。
|
||
<b>已发货 / 异常挂起 / 已付款待审核 / 待付款均不计入</b>——货已发出或短期不会拣,不该驱动补货。
|
||
口径仅覆盖<b>聚水潭线上店铺渠道</b>(运营中心 / 分销等),<b>不含全民(qmcust) B2B 客户单</b>。
|
||
</li>
|
||
<li>
|
||
<b>看板范围</b>:本看板<b>只显示当日待补</b> SKU —— 即「待发订单量 > 拣货位库存」、需要从存储位补到拣货位的这部分
|
||
(含拣货位为 0、库存视图里查不到但有打单拣货待发单的 SKU)。其余「拣货位充足 / 无待发单」的 SKU 不进本看板。
|
||
</li>
|
||
<li>
|
||
<b>判断规则</b>:对每个待补 SKU,<b>超出订单数</b> = max(0, 待发订单量 − 拣货位库存);
|
||
「建议补货量」= min(超出订单数, 存储位库存);存储位也不够时标记「缺货」,缺口需采购 / 紧急调拨。
|
||
</li>
|
||
<li>
|
||
<b>统计范围</b>:取该仓<b>最新一天的「打单拣货」快照</b>(ETL 约每日 07:00 刷新);已发/异常/待审核一律排除。
|
||
</li>
|
||
<li>
|
||
<b>时效</b>:库存视图聚合约 1~2s,待发快照两步查询约 12s;服务端缓存 10 分钟(启动时已预热);
|
||
点「刷新数据」会强制回源,需要等约 15~30 秒。
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
</SycmPage>
|
||
);
|
||
};
|
||
|
||
export default BinReplenishMonitor;
|