业务 14:34 点名 9992097 / 9992098 / 9992924 / 9992925 / 9992926 /
9993284 / 9993285 / 9995464 / 9995465「洛宁仓 16 单都是作废订单,为啥还在
考核之内」,并指明「在聚水潭的销售出库单里面找一下这个作废单据」。
## 查出来的事实
这 9 单在库里**三处全部显示「还在发货」**:
订单表 qmcust status=Delivering、send_date 空
销售出库单 status=WaitConfirm(待出库)
状态镜像表 order_status_name=发货中、logistics=无物流单
不是判据漏了,是**三条数据源全停在作废动作之前**(2026-10-29 15:13 实测):
jst_Orders 14:45 正常
qmcust 13:25 滞后 1.8h
状态镜像表 11:52 滞后 3.4h
出库单(聚水潭/奇门) 03:10 滞后 12.0h ← 作废就落在这张表上
聚水潭的作废落在**出库单** `status='Delete'` 上,而这张表今天凌晨 3 点后
零写入,所以上午作的废一条都没进来
## 改动
1. 新增 `loadOrderIoStatus()`:按 o_id 批量取出库单状态(两表、
分批 500 / 并发 3),判据是 **「该 o_id 下没有任何非 Delete 的出库单」**。
- 只对「发货中」生效:全库「出库单全 Delete」的候选单里 127/131
状态表是「异常」,那批还挂着待处理,删出库单更可能是重开单,
当成作废剔会让业务在「不计考核」里也看不到 → 丢可见性比漏剔更糟
- 拆包/重开的单有多张出库单,删一张不算作废(实测 51 单里 7 单是这种)
- **「没有出库单」绝不判作废**:近 3 天未发单 82%(1467/1790)本来就没出库单
2. 两张出库单表纳入 `loadSourceFreshness()`(用 local_updated / updateTime
灌库时刻,**不能用 modified**,否则没变更时天天误报)
3. 新增 `freshness.voidJudgeReliable` + hint 明说「作废单/取消单可能判不出来」,
告诉业务去聚水潭「销售出库单」核对
4. 明细加「销售出库单」列(已作废/待出库/已出库/未建单),导出同步加列
## 验证
- WST 单测 27/27(新增:出库单全删必剔 / 拆包重开不剔 / 异常单不剔 /
无出库单不剔 / 停更时提示作废判不出来 / 源正常时不误报)
- 后端全量 498/500(2 个既有失败:负缓存 TTL、Windows 文件权限)
- 真实数据:ioVoidSkipped=11(发货中 + 出库单全删),overdue 仍 16 单
- 本地真渲染:表头有「销售出库单」、首行显示「待出库」、
红条列出 5 个数据源停更状态、**pageerror 0**
## 没解决(已在页面明说,不掩盖)
这 9 单今天仍然判不出作废 —— 数据没进来,判据再准也没用。
根子在 ETL:出库单表停 12 小时。ETL 恢复后判据立即生效,
但那 9 单是否作废仍需 IT 修同步或业务在聚水潭复核。
1269 lines
58 KiB
JavaScript
1269 lines
58 KiB
JavaScript
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
||
import {
|
||
Alert, Button, Card, Collapse, Dropdown, Empty, Input, InputNumber, Modal, Space, Spin,
|
||
Statistic, Switch, Table, Tag, TimePicker, Tooltip, Typography, message,
|
||
} from 'antd';
|
||
import { BellOutlined, DownloadOutlined, ReloadOutlined } from '@ant-design/icons';
|
||
import dayjs from 'dayjs';
|
||
import { SycmPage } from '../../components/Common';
|
||
import {
|
||
getShipTimelinessNotifySettings,
|
||
getWarehouseShipTimeliness,
|
||
getWarehouseShipTimelinessExportRows,
|
||
runShipTimelinessNotify,
|
||
saveShipTimelinessNotifySettings,
|
||
} from '../../api/warehouseShipTimeliness';
|
||
import { exportTableFile } from '../../utils/tableExport';
|
||
import './style.css';
|
||
|
||
const { Title, Text } = Typography;
|
||
|
||
// 核验点只有 13:00 / 18:00 两个,10 分钟刷新一次足够。
|
||
// 接口要扫两张订单表 + 出库表(rpt 下全是视图),冷启动 40~60 秒,别跟着其它页面的轮询节奏跑。
|
||
const AUTO_REFRESH_MS = 10 * 60 * 1000;
|
||
|
||
// 「钉钉通知」表单初始值。两个轮次各一个推送时刻(默认核验点 + 5 分钟)。
|
||
// 加签密钥永远不回显明文:留空 = 沿用服务端已存的那份
|
||
const EMPTY_NOTIFY_FORM = {
|
||
enabled: false,
|
||
noonSendTime: '13:05',
|
||
afternoonSendTime: '18:05',
|
||
webhookUrl: '',
|
||
webhookSecret: '',
|
||
maxDetailRows: 30,
|
||
atAll: false,
|
||
pageUrl: '',
|
||
};
|
||
|
||
// 后端「没推」的原因 → 人话(后端 reason 是给日志用的英文标识)
|
||
const NOTIFY_REASON_TEXT = {
|
||
disabled: '推送开关没打开',
|
||
not_configured: 'Webhook 地址还没填',
|
||
already_sent: '这一轮今天已经推过了(同一天同一轮只推一次)',
|
||
not_started: '这一轮还没到核验时刻,没有结论可推',
|
||
before_deadline: '还没到本轮核验时刻,推到群里会是半成品',
|
||
dry_run: '仅预览,未发送',
|
||
error: '执行出错',
|
||
};
|
||
|
||
// 钉钉群机器人 webhook 怎么拿 —— 业务自己配,写清楚省得来问
|
||
const NOTIFY_HELP_ITEMS = [
|
||
{
|
||
key: 'webhook',
|
||
label: '① 拿群机器人 Webhook 地址',
|
||
children: (
|
||
<div className="wst-notify__help">
|
||
电脑版钉钉 → 打开目标群 → 右上角 <b>群设置</b> → <b>机器人</b> → <b>添加机器人</b> →
|
||
选 <b>自定义</b> → 起个名字(如「发货时效通知」)→ 复制 <b>Webhook 地址</b>。
|
||
<br />
|
||
地址形如 <code>https://oapi.dingtalk.com/robot/send?access_token=xxxx</code>,
|
||
整串(含 access_token)直接贴到下面。
|
||
</div>
|
||
),
|
||
},
|
||
{
|
||
key: 'security',
|
||
label: '② 安全设置:加签密钥(可选)',
|
||
children: (
|
||
<div className="wst-notify__help">
|
||
添加机器人时如果安全设置选了 <b>加签</b>,把以 <code>SEC</code> 开头的密钥填到「加签密钥」里。
|
||
<br />
|
||
如果选的是 <b>自定义关键词</b>,密钥留空即可 —— 但关键词必须包含 <b>超时</b>
|
||
(本模块消息抬头固定是「【仓储中心发货时效】」,正文里有「超时未发货 N 单」,天然命中)。
|
||
<br />
|
||
如果选的是 <b>IP 地址(段)</b>,需要把生产服务器 IP 加进白名单,密钥同样留空。
|
||
</div>
|
||
),
|
||
},
|
||
{
|
||
key: 'round',
|
||
label: '③ 为什么一天推两次、时间怎么定',
|
||
children: (
|
||
<div className="wst-notify__help">
|
||
业务口径:<b>13:00 核验 7 点前审核的超时单</b>、<b>18:00 核验 16 点前审核的单</b>,
|
||
各自<b>核验完成后</b>推一次,所以是两个独立时刻,互不影响。
|
||
<br />
|
||
默认给到 <b>13:05 / 18:05</b>(核验点 + 5 分钟):订单表的 updateTime 要晚几分钟才覆盖到核验时刻,
|
||
整点推容易报「数据没覆盖核验点、超时数偏大」。想改成整点也可以,消息里会带这句提醒。
|
||
<br />
|
||
同一轮次同一天只推一次(服务重启不会重复轰炸);要重发点「立即推送」。
|
||
</div>
|
||
),
|
||
},
|
||
{
|
||
key: 'why',
|
||
label: '④ 为什么群里只有文字,没有 Excel 附件',
|
||
children: (
|
||
<div className="wst-notify__help">
|
||
钉钉的<b>自定义机器人 webhook</b> 只支持 text / markdown / link / actionCard,
|
||
<b>不支持发文件</b>。所以这里推的是<b>文本消息</b>:汇总数字 + 前 N 条明细 + 页面链接。
|
||
<br />
|
||
要全量明细或 Excel,点消息末尾的链接进页面查看 / 导出(口径与消息完全一致)。
|
||
</div>
|
||
),
|
||
},
|
||
];
|
||
|
||
const number = (value, digits = 0) => (
|
||
value === null || value === undefined || value === ''
|
||
? '0'
|
||
: Number(value).toLocaleString('zh-CN', {
|
||
minimumFractionDigits: digits,
|
||
maximumFractionDigits: digits,
|
||
})
|
||
);
|
||
|
||
// 超时时长(分钟)→「3 小时 20 分」/「12 天 4 小时」。
|
||
// ⚠️ 口径放开后(含历史未发单)会出现跨天的超时,必须给「天」,否则显示成「8640 小时」。
|
||
const formatOverdue = (minutes) => {
|
||
const m = Number(minutes);
|
||
if (!Number.isFinite(m) || m <= 0) return '—';
|
||
if (m < 60) return `${m} 分钟`;
|
||
const h = Math.floor(m / 60);
|
||
const rest = m % 60;
|
||
if (h < 24) return rest ? `${h} 小时 ${rest} 分` : `${h} 小时`;
|
||
const d = Math.floor(h / 24);
|
||
const hr = h % 24;
|
||
return hr ? `${d} 天 ${hr} 小时` : `${d} 天`;
|
||
};
|
||
|
||
/**
|
||
* 「不计考核」清单的列(待审核 / 订单异常)。
|
||
* 业务反馈(2026-10-20):贴进来的一批单号在聚水潭查不到,实测真实状态是
|
||
* 「已取消(发货前售后)」或「异常」—— 这类单不该算仓库超时。
|
||
* 这里把它们单列出来,回答「为什么这些单没进超时列表」。
|
||
*/
|
||
const HELD_COLUMNS = [
|
||
{ title: '内部单号', dataIndex: 'oId', width: 100 },
|
||
{ title: '线上订单号', dataIndex: 'soId', width: 170, ellipsis: true },
|
||
{ title: '店铺', dataIndex: 'shopName', width: 170, ellipsis: true },
|
||
{ title: '发货仓', dataIndex: 'warehouseName', width: 160, ellipsis: true },
|
||
{
|
||
title: '挂起原因',
|
||
dataIndex: 'holdReason',
|
||
width: 110,
|
||
render: (v) => (
|
||
<Tag bordered={false} color={v === '订单异常' ? 'red' : 'default'}>{v || '—'}</Tag>
|
||
),
|
||
},
|
||
{
|
||
title: '发货时间',
|
||
dataIndex: 'sendTime',
|
||
width: 178,
|
||
ellipsis: true,
|
||
render: (v, row) => {
|
||
if (v) return v;
|
||
const no = row?.logisticId;
|
||
if (no) {
|
||
return (
|
||
<Tooltip title={`已打单:${row.logisticCompany || ''} ${no}(${row.logisticStatus || '未揽收'})`}>
|
||
<Tag bordered={false} color="blue">已打单 · {row.logisticStatus || '未揽收'}</Tag>
|
||
</Tooltip>
|
||
);
|
||
}
|
||
return <Tag bordered={false} color="default">未发货</Tag>;
|
||
},
|
||
},
|
||
{
|
||
title: (
|
||
<Tooltip title="聚水潭「审核时间」= 状态表 last_oa_confirm_time 与订单表 modified 的较晚者(状态表会滞后,9978643 旧值比真实审核早一天)。两者都没有才回退订单创建时间,标 *">
|
||
<span>审核时间</span>
|
||
</Tooltip>
|
||
),
|
||
dataIndex: 'auditTime',
|
||
width: 152,
|
||
ellipsis: true,
|
||
render: (v, row) => {
|
||
if (!v) return <span className="wst-detail__fallback">无审核时间</span>;
|
||
return row?.benchmarkSource === 'created' ? `${v} *` : v;
|
||
},
|
||
},
|
||
{ title: '下单时间', dataIndex: 'createdAt', width: 152, ellipsis: true, render: (v) => v || '—' },
|
||
{ title: '付款时间', dataIndex: 'payTime', width: 152, ellipsis: true, render: (v) => v || '—' },
|
||
{ title: '已挂起', dataIndex: 'heldDays', width: 88, render: (v) => (v > 0 ? `${v} 天` : '—') },
|
||
];
|
||
|
||
const DETAIL_COLUMNS = [
|
||
// 内部单号 = 聚水潭 o_id(系统内部编号,仓管在系统里按它查单)
|
||
{
|
||
title: '内部单号',
|
||
dataIndex: 'oId',
|
||
width: 158,
|
||
// 🔥 来自停更订单表的单必须打标(2026-10-28):
|
||
// 该表停更之后发出的单,send_date 仍是空 → 被判「未发」,实际很可能已经发了。
|
||
// 18:00 轮实测 546 单里 540 单是这种,不标出来业务会以为判定写错。
|
||
render: (v, row) => (
|
||
<span className="wst-detail__oid">
|
||
{v || '—'}
|
||
{row?.sourceStale ? (
|
||
<Tooltip
|
||
title={`这单来自 ${row?.srcLabel || '订单表'},该表已停止同步:停更之后发出的单在这里仍是「未发货」,很可能已经发了。请先在聚水潭核对。`}
|
||
>
|
||
<Tag bordered={false} color="error" className="wst-detail__stale">未同步</Tag>
|
||
</Tooltip>
|
||
) : null}
|
||
</span>
|
||
),
|
||
},
|
||
// 线上订单号 = 平台 so_id(京东/抖音/天猫等平台单号,客服按它对接客户)
|
||
{
|
||
title: '线上订单号',
|
||
dataIndex: 'soId',
|
||
width: 178,
|
||
ellipsis: true,
|
||
render: (v) => (v ? <span className="wst-detail__soid">{v}</span> : '—'),
|
||
},
|
||
{
|
||
title: '店铺',
|
||
dataIndex: 'shopName',
|
||
width: 180,
|
||
ellipsis: true,
|
||
render: (v) => (v || '—'),
|
||
},
|
||
{
|
||
title: '发货仓',
|
||
dataIndex: 'warehouseName',
|
||
width: 170,
|
||
ellipsis: true,
|
||
render: (v) => (v || '—'),
|
||
},
|
||
{
|
||
// 发货时间 = 聚水潭回传的发货时间(业务 2026-10-20:明细里不要创建时间,要发货时间)
|
||
title: (
|
||
<Tooltip title="订单表 jst_Orders.send_date(聚水潭回传的发货时间)。为空但有运单号的,说明仓库已打单、还没揽收/回传发货时间,会显示成「已打单」">
|
||
<span>发货时间</span>
|
||
</Tooltip>
|
||
),
|
||
dataIndex: 'sendTime',
|
||
width: 178,
|
||
ellipsis: true,
|
||
render: (v, row) => {
|
||
if (v) return v;
|
||
const no = row?.logisticId;
|
||
if (no) {
|
||
return (
|
||
<Tooltip title={`已打单:${row.logisticCompany || ''} ${no}(${row.logisticStatus || '未揽收'})。聚水潭还没回传发货时间,所以还没从超时列表里消失`}>
|
||
<Tag bordered={false} color="blue">已打单 · {row.logisticStatus || '未揽收'}</Tag>
|
||
</Tooltip>
|
||
);
|
||
}
|
||
return <Tag bordered={false} color="default">未发货</Tag>;
|
||
},
|
||
},
|
||
{
|
||
// 审核时间 = 本页的**考核起算点**(业务 2026-10-28 下午三次定版)
|
||
// = max(状态表 last_oa_confirm_time, 订单表 modified),都没有才回退创建时间并打 `*`
|
||
title: (
|
||
<Tooltip title="聚水潭「审核时间」= 状态表 last_oa_confirm_time 与订单表 modified 的较晚者。状态表会滞后(9978643 状态表是 10-27 17:08,真实审核 10-28 14:52),所以取较晚的那个。今天 7:00 前审核的 13:00 核验;截止 16:00 前审核的(含历史未发单)18:00 核验。带 * 表示两者都没有,回退订单创建时间">
|
||
<span>审核时间</span>
|
||
</Tooltip>
|
||
),
|
||
dataIndex: 'auditTime',
|
||
width: 152,
|
||
ellipsis: true,
|
||
render: (v, row) => {
|
||
if (!v) return <span className="wst-detail__fallback">—</span>;
|
||
if (row?.benchmarkSource === 'created') {
|
||
return (
|
||
<Tooltip title="状态表审核时间和订单表 modified 都取不到,已回退订单创建时间参与分轮与计时(`*` 为标记)">
|
||
<span>{v} *</span>
|
||
</Tooltip>
|
||
);
|
||
}
|
||
return v;
|
||
},
|
||
},
|
||
// 下单时间 = 客户在平台下单那一刻(只做参考对账,不参与计时)
|
||
{
|
||
title: (
|
||
<Tooltip title="聚水潭订单创建时间(jst_Orders.created),即客户下单时刻。只做参考,不参与分轮与计时">
|
||
<span>下单时间</span>
|
||
</Tooltip>
|
||
),
|
||
dataIndex: 'createdAt',
|
||
width: 152,
|
||
ellipsis: true,
|
||
render: (v) => v || '—',
|
||
},
|
||
// 付款时间 = 客户付款那一刻(并列展示,方便对账)
|
||
{ title: '付款时间', dataIndex: 'payTime', width: 152, ellipsis: true, render: (v) => v || '—' },
|
||
{
|
||
// 发货状态:**优先显示聚水潭终态**(状态镜像表),订单表状态只作对照
|
||
// 🔥 2026-10-29:订单两表会各自停更,停更期间聚水潭里已经「已取消 / 已发货」的单,
|
||
// 订单表里仍是「发货中」——业务看到的「作废的也在考核里」就是这么来的。
|
||
// 状态镜像表比订单表新鲜,`order_status_name` 才是聚水潭的真状态。
|
||
title: (
|
||
<Tooltip title="优先显示聚水潭订单终态(状态镜像表,订单表停更时只有它靠得住)。⚠ = 与订单表 jst_Orders.status 不一致">
|
||
<span>发货状态</span>
|
||
</Tooltip>
|
||
),
|
||
dataIndex: 'stateOrderStatus',
|
||
width: 128,
|
||
render: (v, row) => {
|
||
const lake = v || '';
|
||
const ord = row?.state || '';
|
||
const diff = Boolean(lake && ord && lake !== ord);
|
||
const text = lake || ord || '—';
|
||
const color = text === '已取消' ? 'red' : (text === '发货中' ? 'orange' : 'default');
|
||
return (
|
||
<Tooltip title={`聚水潭:${lake || '—'}|订单表:${ord || '—'}${diff ? '(不一致,订单表没同步到这个状态)' : ''}`}>
|
||
<Tag bordered={false} color={color}>{text}{diff ? ' ⚠' : ''}</Tag>
|
||
</Tooltip>
|
||
);
|
||
},
|
||
},
|
||
{
|
||
// 物流状态:优先用状态表的真实物流节点(未揽收 / 已揽收 / 运输中 / 已签收…),
|
||
// 订单表没有物流轨迹,只能靠「有没有运单号」猜「已打单 · 未揽收」
|
||
title: (
|
||
<Tooltip title="聚水潭物流节点(状态镜像表)。已揽收及之后 = 货已经被快递拿走">
|
||
<span>物流状态</span>
|
||
</Tooltip>
|
||
),
|
||
dataIndex: 'stateLogisticStatus',
|
||
width: 108,
|
||
render: (v, row) => {
|
||
const text = v || row?.logisticStatus || '';
|
||
if (!text) return '—';
|
||
const shipped = ['已揽收', '运输中', '派送中', '已签收', '拒收'].includes(v);
|
||
return <Tag bordered={false} color={shipped ? 'green' : 'default'}>{text}</Tag>;
|
||
},
|
||
},
|
||
{
|
||
// 销售出库单状态(2026-10-29 新增)
|
||
// 🔥 业务点名「这些订单都是作废订单」后挖出来的:聚水潭的作废**落在出库单上**
|
||
// (`status='Delete'`),订单表的 labels 判据在那批单上 0 命中。
|
||
// 这一列让业务能直接对照聚水潭「销售出库单」页面,不用再问「系统里为什么没有」。
|
||
title: (
|
||
<Tooltip title="聚水潭「销售出库单」的单据状态。已作废=单据被删(不考核);待出库=已生成单据但没出库;空白=还没建出库单(正常,近八成未发单本来就没有)">
|
||
<span>销售出库单</span>
|
||
</Tooltip>
|
||
),
|
||
dataIndex: 'ioStatus',
|
||
width: 112,
|
||
render: (v) => {
|
||
const map = {
|
||
Delete: ['已作废', 'red'],
|
||
WaitConfirm: ['待出库', 'blue'],
|
||
Confirmed: ['已出库', 'green'],
|
||
OuterConfirming: ['外部确认中', 'default'],
|
||
};
|
||
const hit = map[v];
|
||
if (!hit) return '—';
|
||
return <Tag bordered={false} color={hit[1]}>{hit[0]}</Tag>;
|
||
},
|
||
},
|
||
{
|
||
title: (
|
||
<Tooltip title="从审核时间(仓库接到单的时刻)到本轮核验时刻(13:00 / 18:00)等了多久">
|
||
<span>已等时长</span>
|
||
</Tooltip>
|
||
),
|
||
dataIndex: 'overdueMinutes',
|
||
width: 112,
|
||
render: (v) => <span className="wst-detail__overdue">{formatOverdue(v)}</span>,
|
||
},
|
||
];
|
||
|
||
/**
|
||
* 导出列(「超时未发」明细)。
|
||
*
|
||
* ⚠️ 必须**单独一份**,不能直接复用 DETAIL_COLUMNS:
|
||
* ① 那里的 title 是 JSX(带 Tooltip),导出时会变成 "[object Object]" 当表头;
|
||
* ② 页面上没有「快递公司 / 运单号」两列,而业务追单恰恰要这两列
|
||
* (有运单号 = 已打单未揽收,能一眼看出卡在哪一步)。
|
||
* 标题一律纯字符串,格式化统一走 exportValue(null 值别导出裸空/裸 0)。
|
||
*/
|
||
const EXPORT_COLUMNS = [
|
||
{ title: '内部单号', dataIndex: 'oId' },
|
||
{ title: '线上订单号', dataIndex: 'soId' },
|
||
{ title: '店铺', dataIndex: 'shopName' },
|
||
{ title: '仓储中心', dataIndex: 'centerName' },
|
||
{ title: '发货仓', dataIndex: 'warehouseName' },
|
||
{ title: '快递公司', dataIndex: 'logisticCompany', exportValue: (v) => v || '未指定' },
|
||
{ title: '运单号', dataIndex: 'logisticId', exportValue: (v) => v || '未打单' },
|
||
{ title: '物流状态', dataIndex: 'stateLogisticStatus', exportValue: (v, row) => v || row?.logisticStatus || '' },
|
||
{ title: '发货状态', dataIndex: 'state' },
|
||
// 聚水潭终态与订单表状态分开导出:两者不一致的单,就是「订单表没同步」的证据
|
||
{ title: '聚水潭状态', dataIndex: 'stateOrderStatus', exportValue: (v) => v || '—' },
|
||
// 销售出库单状态:聚水潭的作废落在这一层(Delete=单据已作废),
|
||
// 业务对账时要拿这一列跟聚水潭「销售出库单」页面对
|
||
{
|
||
title: '销售出库单',
|
||
dataIndex: 'ioStatus',
|
||
exportValue: (v) => ({
|
||
Delete: '已作废',
|
||
WaitConfirm: '待出库',
|
||
Confirmed: '已出库',
|
||
OuterConfirming: '外部确认中',
|
||
}[v] || '未建单'),
|
||
},
|
||
{ title: '状态表抓取时间', dataIndex: 'stateQueryTime', exportValue: (v) => v || '—' },
|
||
// 导出也要带上「这单的来源表 + 该表是否停更」,否则 Excel 脱离页面就没有上下文,
|
||
// 拿着 540 单「未发」去追仓库,实际人家早就发了。
|
||
{ title: '数据源', dataIndex: 'srcLabel', exportValue: (v) => v || '—' },
|
||
{
|
||
title: '数据源是否停更',
|
||
dataIndex: 'sourceStale',
|
||
exportValue: (v) => (v ? '是(该单可能已发)' : '否'),
|
||
},
|
||
{ title: '发货时间', dataIndex: 'sendTime', exportValue: (v) => v || '未发货' },
|
||
{
|
||
title: '审核时间',
|
||
dataIndex: 'auditTime',
|
||
// 起算点 = 审核时间;没取到时回退订单创建时间,导出用 `*` 标出来,否则对账对不上
|
||
exportValue: (v, row) => {
|
||
const t = v || row?.benchmarkTime || '';
|
||
if (!t) return '无审核时间';
|
||
return row?.benchmarkSource === 'created' ? `${t} *` : t;
|
||
},
|
||
},
|
||
{ title: '下单时间', dataIndex: 'createdAt', exportValue: (v) => v || '—' },
|
||
{ title: '付款时间', dataIndex: 'payTime' },
|
||
// 分钟数给一列原始值,业务在 Excel 里能直接排序/筛选;人读的那列再格式化
|
||
{ title: '已等(分钟)', dataIndex: 'overdueMinutes' },
|
||
{ title: '已等时长', dataIndex: 'overdueMinutes', exportValue: (v) => formatOverdue(v) },
|
||
];
|
||
|
||
// key = 导出格式(tableExport 只支持这两种)
|
||
const EXPORT_MENU_ITEMS = [
|
||
{ key: 'xlsx', label: '导出 Excel(.xlsx)' },
|
||
{ key: 'csv', label: '导出 CSV(.csv)' },
|
||
];
|
||
|
||
// 文件名里不能出现 : \ / * ? " < > |,轮次用「13点轮」这种写法避开冒号
|
||
const roundFileText = (roundInfo) => (
|
||
Number.isFinite(Number(roundInfo?.verifyHour))
|
||
? `${String(Number(roundInfo.verifyHour)).padStart(2, '0')}点轮`
|
||
: '本轮'
|
||
);
|
||
|
||
/**
|
||
* 仓储中心发货时效(独立页面)
|
||
* ────────────────────────────────────────────────────────────────
|
||
* 业务口径(yanhui 2026-10-20 定轮次;2026-10-28 定起算点):
|
||
* · 11 个主仓,子仓并入主仓一起算;
|
||
* · 数据源 = 订单表 jst_Orders + jst_qmcust_orderlist(两张表店铺互斥,都要读);
|
||
* · 今天 07:00 前**审核**的订单 13:00 核验,截止今天 16:00 前审核的单 18:00 核验
|
||
* (含 7 点前审核未发出的、含今天之前审核至今未发的历史单;山东两仓 15:00、河南洛宁 13:00);
|
||
* 今天之前仍未发的(历史未发)两个轮次都算;
|
||
* **到核验时刻未发即超时**,没有「满 24 小时」门槛(业务纠偏点);
|
||
* 轮次归属和「已等时长」都按**审核时间**算 ——
|
||
* 业务 2026-10-28 下午三次定版:审核时间 = max(状态表 last_oa_confirm_time, 订单表 modified)。
|
||
* 只取状态表会漏 —— 状态表会滞后(9978643 状态表写的是 10-27 17:08,聚水潭真实审核 10-28 14:52,
|
||
* 整整早一天),导致「今天下午才审核的单」被算进 13:00 轮,冤枉仓库;
|
||
* 两者都没有才回退订单创建时间,页面上带 `*` 标记;
|
||
* · **13:00 之前不核验**,直接显示「未到核验时间」,不拿昨天的结果冒充今天;
|
||
* · 已出库 / 待出库以订单表 **send_date** 为准(SQL 直接 `send_date IS NULL` 才进候选);
|
||
* · 只显示超时未出库(发完的仓显示「—」),点仓库可筛右侧明细。
|
||
*
|
||
* 数据来自 /api/warehouse-ship-timeliness/list(service 层见
|
||
* backend/src/services/warehouseShipTimelinessService.js)。
|
||
*/
|
||
function WarehouseShipTimeliness() {
|
||
const [data, setData] = useState(null);
|
||
const [loading, setLoading] = useState(false);
|
||
const [error, setError] = useState('');
|
||
// 选中的主仓:为空时右侧展示全部仓的超时明细
|
||
const [activeCenter, setActiveCenter] = useState('');
|
||
// 「业务挂起(疑问单)」明细弹窗
|
||
const [heldOpen, setHeldOpen] = useState(false);
|
||
// 「导出明细」按钮 loading(全量导出可能要走一次冷启动查询,必须给反馈)
|
||
const [exporting, setExporting] = useState(false);
|
||
|
||
// ── 钉钉通知(两轮核验完成后各推一次)──────────────────────────────────
|
||
const [notifyOpen, setNotifyOpen] = useState(false);
|
||
const [notifyLoading, setNotifyLoading] = useState(false);
|
||
const [notifySaving, setNotifySaving] = useState(false);
|
||
const [notifyRunning, setNotifyRunning] = useState(false);
|
||
const [notifyConfig, setNotifyConfig] = useState(null);
|
||
const [notifyForm, setNotifyForm] = useState(EMPTY_NOTIFY_FORM);
|
||
// 预览正文:放在弹窗内受控渲染(React 19 下 Modal.info 静态方法弹不出来)
|
||
const [notifyPreview, setNotifyPreview] = useState(null);
|
||
|
||
// force=true 时带 force=1 让后端绕过 5 分钟结果缓存重查库;
|
||
// 定时轮询走缓存(这张视图单次要几十秒,每轮都重查会把库压死)
|
||
const load = useCallback(async (force = false) => {
|
||
setLoading(true);
|
||
setError('');
|
||
try {
|
||
const result = await getWarehouseShipTimeliness({ limit: 1000, force: force ? 1 : 0 });
|
||
if (!result || result.success === false) {
|
||
setError(result?.error || '加载发货时效失败');
|
||
return;
|
||
}
|
||
setData(result.data || null);
|
||
} catch (loadError) {
|
||
setError(loadError?.response?.data?.error || loadError?.message || '加载发货时效失败');
|
||
} finally {
|
||
setLoading(false);
|
||
}
|
||
}, []);
|
||
|
||
useEffect(() => {
|
||
load();
|
||
const timer = window.setInterval(() => load(), AUTO_REFRESH_MS);
|
||
return () => window.clearInterval(timer);
|
||
}, [load]);
|
||
|
||
const centers = useMemo(() => (Array.isArray(data?.centers) ? data.centers : []), [data]);
|
||
const orders = useMemo(() => (Array.isArray(data?.orders) ? data.orders : []), [data]);
|
||
// 业务挂起(疑问单)—— 与 orders 互斥,两者相加才是待出库池
|
||
const heldOrders = useMemo(
|
||
() => (Array.isArray(data?.heldOrders) ? data.heldOrders : []),
|
||
[data]
|
||
);
|
||
const summary = data?.summary || {};
|
||
const round = data?.round || null;
|
||
const freshness = data?.freshness || null;
|
||
// 🔥 超时单里「所在订单表已停更」的数量(2026-10-28 定型):
|
||
// 停更⟹停更之后发出的单 send_date 仍为空⟹被判「未发」,但实际很可能已发。
|
||
// 18:00 轮实测 546 单里 540 单属于这种,必须显著提示,否则业务会以为判定写错。
|
||
const staleUnshipped = Number(summary.sourceStaleUnshipped || 0);
|
||
const staleSources = Array.isArray(data?.dataSources) ? data.dataSources.filter((s) => s && s.stale) : [];
|
||
// 13:00 之前后端返回 round=null + notStarted=true:此时**不展示任何超时数字**
|
||
const notStarted = Boolean(data?.notStarted);
|
||
const hasRound = Boolean(round);
|
||
const cutoffText = String(round?.windowEnd || '').slice(11, 16);
|
||
const windowEndText = String(data?.window?.end || '').slice(11, 16);
|
||
// 仓级例外窗口:18:00 轮里 山东两仓 15:00、河南洛宁 13:00(业务 2026-10-20 指定)
|
||
const windowOverrides = Array.isArray(data?.window?.overrides) ? data.window.overrides : [];
|
||
const overrideText = windowOverrides
|
||
.map((o) => `${o.name} ${String(o.hour).padStart(2, '0')}:00`)
|
||
.join('、');
|
||
// 未到核验时间时的提示文案,全部由后端给,前端不写死时刻
|
||
const nextRoundText = String(data?.nextRoundAt || '').slice(11, 16) || '13:00';
|
||
const nextWindowEndText = String(data?.nextWindowEnd || '').slice(11, 16) || '07:00';
|
||
|
||
const activeCenterName = useMemo(() => {
|
||
if (!activeCenter) return '';
|
||
const hit = centers.find((c) => c.key === activeCenter);
|
||
return hit ? hit.name : activeCenter;
|
||
}, [activeCenter, centers]);
|
||
|
||
// 选中仓时,该仓的超时单数以 centers 里的统计为准(明细可能被截断)
|
||
const activeCenterRow = useMemo(
|
||
() => (activeCenter ? centers.find((c) => c.key === activeCenter) || null : null),
|
||
[activeCenter, centers]
|
||
);
|
||
|
||
const detailOrders = useMemo(() => (
|
||
activeCenter ? orders.filter((o) => o.centerKey === activeCenter) : orders
|
||
), [activeCenter, orders]);
|
||
|
||
// 明细真实总数(后端截断前):页面的「共 N 单」必须用它,
|
||
// 用 detailOrders.length 会把「已截断只显示前 1000 条」写成「一共就这么点」
|
||
const detailTotal = Number.isFinite(Number(data?.detailTotal))
|
||
? Number(data.detailTotal)
|
||
: detailOrders.length;
|
||
|
||
const heldTotal = Number.isFinite(Number(data?.heldTotal))
|
||
? Number(data.heldTotal)
|
||
: heldOrders.length;
|
||
|
||
// 不考核快递清单跟随后端(加/减快递只改服务层一处,别在前端写死)
|
||
const excludedCarrierText = (
|
||
Array.isArray(data?.excludedCarriers) && data.excludedCarriers.length
|
||
? data.excludedCarriers
|
||
: ['自提', '中铁', '壹米滴答', '武进安能']
|
||
).join(' / ');
|
||
|
||
// ── 导出「超时未发」明细 ─────────────────────────────────────────────────
|
||
|
||
/**
|
||
* 导出口径必须和页面明细一致,所以:
|
||
* · 数据源走 `/export`(后端同一个 getShipTimeliness,只是不按 limit 截断);
|
||
* · 选中仓时在前端按 centerKey 过滤,和后端算超时用的主仓归属是同一套。
|
||
* 🔥 不能直接导出页面上的 `orders` —— 它被 limit=1000 截断过,导出会少行,
|
||
* 而业务拿它去考核,少行比报错更危险。
|
||
*/
|
||
const handleExport = async (format) => {
|
||
setExporting(true);
|
||
try {
|
||
const result = await getWarehouseShipTimelinessExportRows({
|
||
round: round?.key || undefined,
|
||
});
|
||
if (!result || result.success === false) {
|
||
message.error(result?.error || '导出失败');
|
||
return;
|
||
}
|
||
const payload = result.data || {};
|
||
if (payload.notStarted) {
|
||
message.warning('本轮还没到核验时间,没有可导出的数据');
|
||
return;
|
||
}
|
||
const allRows = Array.isArray(payload.rows) ? payload.rows : [];
|
||
if (!allRows.length) {
|
||
message.warning('本轮没有超时未发订单,无需导出');
|
||
return;
|
||
}
|
||
const rows = activeCenter
|
||
? allRows.filter((row) => row.centerKey === activeCenter)
|
||
: allRows;
|
||
if (!rows.length) {
|
||
message.warning(`${activeCenterName || '该仓'}本轮没有超时未发订单`);
|
||
return;
|
||
}
|
||
const fileName = [
|
||
'仓储中心发货时效_超时未发',
|
||
activeCenter ? activeCenterName : '全部仓库',
|
||
roundFileText(payload.round || round),
|
||
payload.date || data?.date || dayjs().format('YYYY-MM-DD'),
|
||
].filter(Boolean).join('_');
|
||
await exportTableFile(format, fileName, EXPORT_COLUMNS, rows, '超时未发');
|
||
message.success(`已导出 ${rows.length} 单(${String(format).toUpperCase()})`);
|
||
} catch (exportError) {
|
||
message.error(exportError?.response?.data?.error || exportError?.message || '导出失败');
|
||
} finally {
|
||
setExporting(false);
|
||
}
|
||
};
|
||
|
||
// ── 钉钉通知:配置读写 / 预览 / 立即推送 ─────────────────────────────────
|
||
|
||
// 后端只回加签密钥掩码,所以表单里的 webhookSecret 永远是空的 —— 留空 = 沿用已存的
|
||
const applyNotifyConfig = useCallback((config) => {
|
||
setNotifyConfig(config || null);
|
||
setNotifyForm({
|
||
enabled: config?.enabled === true,
|
||
noonSendTime: config?.noonSendTime || '13:05',
|
||
afternoonSendTime: config?.afternoonSendTime || '18:05',
|
||
webhookUrl: config?.webhookUrl || '',
|
||
webhookSecret: '',
|
||
maxDetailRows: Number.isFinite(Number(config?.maxDetailRows))
|
||
? Number(config.maxDetailRows)
|
||
: 30,
|
||
atAll: config?.atAll === true,
|
||
pageUrl: config?.pageUrl || '',
|
||
});
|
||
}, []);
|
||
|
||
const openNotifySettings = useCallback(async () => {
|
||
setNotifyOpen(true);
|
||
setNotifyPreview(null);
|
||
setNotifyLoading(true);
|
||
try {
|
||
const result = await getShipTimelinessNotifySettings();
|
||
if (!result || result.success === false) {
|
||
message.error(result?.error || '读取发货时效通知配置失败');
|
||
return;
|
||
}
|
||
applyNotifyConfig(result.data);
|
||
} catch (loadError) {
|
||
message.error(loadError?.response?.data?.error || loadError?.message || '读取发货时效通知配置失败');
|
||
} finally {
|
||
setNotifyLoading(false);
|
||
}
|
||
}, [applyNotifyConfig]);
|
||
|
||
const buildNotifyPayload = useCallback(() => ({
|
||
enabled: notifyForm.enabled,
|
||
noonSendTime: notifyForm.noonSendTime,
|
||
afternoonSendTime: notifyForm.afternoonSendTime,
|
||
webhookUrl: String(notifyForm.webhookUrl || '').trim(),
|
||
webhookSecret: String(notifyForm.webhookSecret || '').trim(),
|
||
maxDetailRows: Number(notifyForm.maxDetailRows) || 0,
|
||
atAll: notifyForm.atAll === true,
|
||
pageUrl: String(notifyForm.pageUrl || '').trim(),
|
||
}), [notifyForm]);
|
||
|
||
const handleSaveNotify = async ({ silent = false } = {}) => {
|
||
setNotifySaving(true);
|
||
try {
|
||
const result = await saveShipTimelinessNotifySettings(buildNotifyPayload());
|
||
if (!result || result.success === false) {
|
||
message.error(result?.error || '保存发货时效通知配置失败');
|
||
return null;
|
||
}
|
||
applyNotifyConfig(result.data);
|
||
if (!silent) message.success('发货时效通知配置已保存');
|
||
return result.data;
|
||
} catch (saveError) {
|
||
message.error(saveError?.response?.data?.error || saveError?.message || '保存发货时效通知配置失败');
|
||
return null;
|
||
} finally {
|
||
setNotifySaving(false);
|
||
}
|
||
};
|
||
|
||
/**
|
||
* mode: 'dry' 预览正文(不发送)| 'probe' 只发一句通道测试 | 'send' 立即推送当前轮
|
||
* 都要先保存:否则「改完 webhook 直接点测试」会拿旧地址发,排错时会很迷惑。
|
||
*
|
||
* ⚠️ 预览**不能**用 `Modal.info` 静态方法:本项目跑 React 19,antd v5 的静态方法
|
||
* 拿不到 ConfigProvider context(控制台只给一行 warning),弹窗**静默不渲染**。
|
||
* 所以预览改成弹窗内的受控区块(notifyPreview)。
|
||
*/
|
||
const handleRunNotify = async (mode) => {
|
||
const saved = await handleSaveNotify({ silent: true });
|
||
if (!saved) return;
|
||
setNotifyRunning(true);
|
||
try {
|
||
const payload = mode === 'dry'
|
||
? { dryRun: true, force: true }
|
||
: { probe: mode === 'probe', force: true };
|
||
const result = await runShipTimelinessNotify(payload);
|
||
if (!result || result.success === false) {
|
||
message.error(result?.error || '推送到钉钉群失败');
|
||
return;
|
||
}
|
||
const info = result.data || {};
|
||
if (mode === 'dry') {
|
||
setNotifyPreview({
|
||
text: info.text || '',
|
||
rowCount: info.rowCount ?? 0,
|
||
listedCount: info.listedCount ?? 0,
|
||
bytes: info.bytes || 0,
|
||
truncated: info.truncated === true,
|
||
roundLabel: info.roundLabel || '',
|
||
});
|
||
message.success('已生成预览(未发送),正文见下方');
|
||
} else if (mode === 'probe') {
|
||
message.success('通道测试已发出,去钉钉群看有没有收到那条测试消息');
|
||
} else if (info.sent) {
|
||
setNotifyPreview(null);
|
||
message.success(`已推送到钉钉群(${info.roundLabel || info.round},超时 ${info.rowCount ?? 0} 单,列出 ${info.listedCount ?? 0} 条)`);
|
||
} else {
|
||
message.warning(`未推送:${NOTIFY_REASON_TEXT[info.reason] || info.reason || '未知原因'}`);
|
||
}
|
||
const latest = await getShipTimelinessNotifySettings();
|
||
if (latest?.data) applyNotifyConfig(latest.data);
|
||
} catch (runError) {
|
||
message.error(runError?.response?.data?.error || runError?.message || '推送到钉钉群失败');
|
||
} finally {
|
||
setNotifyRunning(false);
|
||
}
|
||
};
|
||
|
||
const notifyLastState = notifyConfig?.lastState || {};
|
||
const notifyNoonValue = useMemo(
|
||
() => (notifyForm.noonSendTime ? dayjs(notifyForm.noonSendTime, 'HH:mm') : null),
|
||
[notifyForm.noonSendTime]
|
||
);
|
||
const notifyAfternoonValue = useMemo(
|
||
() => (notifyForm.afternoonSendTime ? dayjs(notifyForm.afternoonSendTime, 'HH:mm') : null),
|
||
[notifyForm.afternoonSendTime]
|
||
);
|
||
|
||
return (
|
||
<SycmPage className="wst-page">
|
||
<header className="wst-header">
|
||
<Title level={3}>仓储中心发货时效(到点未发即超时)</Title>
|
||
<Text type="secondary">
|
||
按聚水潭订单表实时状态核验 11 个主仓是否在承诺时效内完成发货,只列超时未发货的单量。
|
||
{/* 2026-10-28 业务定:名字里不再出现「24 小时」—— 规则本身没有 24h 门槛,
|
||
原名会让 10-27 16:00 创建(只等了 21 小时)的单看着像「没到时限也被判超时」。*/}
|
||
</Text>
|
||
<Text type="secondary" className="wst-note">
|
||
每天 <b>13:00</b> 核验「<b>今天 07:00 前审核</b>」、<b>18:00</b> 核验「<b>截止 16:00 前审核</b>」、
|
||
到核验时刻仍未发货的订单;两个轮次都<b>包含今天之前审核、至今未发的历史未发单</b>
|
||
(18:00 轮也会带上 7 点前审核、13:00 还没发出的那批)—— 滚动待发池,不按自然日切。
|
||
13:00 之前不核验,显示「未到核验时间」。
|
||
<b>到点还没发就算超时 —— 不设「满 24 小时」门槛</b>(早上 7 点前那份单,13:00 还没走就是超时)。
|
||
<b>仓级例外</b>:18:00 轮里 <b>山东青岗集仓 / 山东品牌仓</b> 只看 <b>15:00 前审核</b>的单、
|
||
<b>河南洛宁仓</b> 只看 <b>13:00 前审核</b>的单(核验时刻仍是 18:00)。
|
||
<b>轮次与「已等时长」都按审核时间算</b>(= 状态表 last_oa_confirm_time 与订单表 modified 的较晚者:
|
||
审核才是仓库接到单的时刻,按下单时间算会把客服审核积压算到仓库头上;
|
||
状态表的审核时间会滞后,所以要和订单 modified 取较晚的那个);
|
||
明细并列「审核时间 / 下单时间 / 发货时间」,方便直接和聚水潭对账。
|
||
<b>已发 / 未发以订单表 send_date 为准</b>(有值即已发,SQL 侧直接过滤不进候选);
|
||
订单表 send_date 没回写、但状态表 send_time 有值的,也按已发剔除(不漏冤仓库)。
|
||
<b>已打单但还没揽收的</b>(聚水潭已生成运单号、发货时间还空着)会标成「已打单 · 未揽收」,
|
||
鼠标悬停能看到运单号 —— 这类单还留在列表里,等聚水潭回传发货时间才消失。
|
||
<b>{excludedCarrierText} 不考核</b>(客户自提、专线大件或加盟快运网点,揽收与在途仓库控制不了),
|
||
已按物流公司自动剔除。
|
||
<b>「待审核」和「异常」的单不计考核</b>(仓库还没接到或订单本身有问题),单独归入「不计考核」并给出明细;
|
||
<b>作废单(已取消,含发货前售后)不考核也不展示</b> —— 客户付款后取消的单仓库本就不该发。
|
||
</Text>
|
||
</header>
|
||
|
||
<Card className="wst-status" bordered={false}>
|
||
<div className="wst-status__row">
|
||
<div className="wst-status__round">
|
||
{hasRound ? (
|
||
<>
|
||
<span className="wst-status__badge">{round.label}</span>
|
||
<span className="wst-status__label">
|
||
核验今天 {cutoffText} 前审核的订单
|
||
</span>
|
||
<span className="wst-status__window">
|
||
含历史未发 · 到点未发即超时
|
||
{overrideText ? `(${overrideText} 为仓级例外)` : ''}
|
||
</span>
|
||
</>
|
||
) : (
|
||
<>
|
||
<span className="wst-status__badge wst-status__badge--idle">未到核验时间</span>
|
||
<span className="wst-status__label">
|
||
{nextRoundText} 开始首轮核验
|
||
(核验今天 {nextWindowEndText} 前审核的订单)
|
||
</span>
|
||
</>
|
||
)}
|
||
</div>
|
||
<Space size={8}>
|
||
{data?.generatedAt ? (
|
||
<Text type="secondary" className="wst-status__time">
|
||
数据更新于 {String(data.generatedAt).slice(11, 19)}
|
||
{data?.cached ? `(缓存 ${data.cacheAgeSec || 0}s,点刷新重查)` : ''}
|
||
</Text>
|
||
) : null}
|
||
<Button icon={<BellOutlined />} onClick={openNotifySettings}>钉钉通知</Button>
|
||
<Button icon={<ReloadOutlined />} onClick={() => load(true)} loading={loading}>刷新</Button>
|
||
</Space>
|
||
</div>
|
||
</Card>
|
||
|
||
{error ? (
|
||
<Alert
|
||
type="error"
|
||
showIcon
|
||
className="wst-alert"
|
||
message={error}
|
||
action={<Button size="small" onClick={load}>重试</Button>}
|
||
/>
|
||
) : null}
|
||
|
||
{(freshness && (freshness.stale || freshness.coversDeadline === false))
|
||
|| staleUnshipped > 0
|
||
|| staleSources.length > 0 ? (
|
||
<Alert
|
||
// 快照没覆盖到核验时刻 / 有单来自停更的表 → 数字必然偏大,用红色;只是滞后用黄色
|
||
type={staleUnshipped > 0 || freshness?.coversDeadline === false ? 'error' : 'warning'}
|
||
showIcon
|
||
className="wst-alert"
|
||
message={
|
||
staleUnshipped > 0
|
||
? `${number(staleUnshipped)} 单所在订单表已停止同步,这些单很可能已经发货`
|
||
: (freshness?.voidJudgeReliable === false
|
||
// 🔥 2026-10-29:出库单/状态表停更 ⟹ 作废判据失效。
|
||
// 业务当天报「洛宁仓 16 单都是作废单」,但我们三个来源全停在作废动作之前,
|
||
// 判据再准也判不出来 —— 必须明说,别让业务以为是系统认定「没作废」。
|
||
? '出库单数据源已停止同步,作废单可能判不出来'
|
||
: (staleSources.length > 0
|
||
// 状态镜像表也算数据源:它停了,判「已取消 / 已发货」的依据就过期了
|
||
? '数据源已停止同步(订单表 / 状态镜像表)'
|
||
: (freshness?.coversDeadline === false
|
||
? '数据未覆盖本轮核验时刻,超时单量偏大'
|
||
: '发货数据可能滞后')))
|
||
}
|
||
description={(
|
||
<>
|
||
{freshness?.hint}
|
||
{staleSources.length ? (
|
||
<div className="wst-alert__sources">
|
||
{staleSources.map((s) => (
|
||
<span key={s.key} className="wst-alert__source">
|
||
{s.label}:最后同步 {String(s.lastUpdate || '').slice(11, 19) || '—'}
|
||
(已 {Math.round((s.lagMinutes || 0) / 6) / 10} 小时)
|
||
</span>
|
||
))}
|
||
</div>
|
||
) : null}
|
||
</>
|
||
)}
|
||
/>
|
||
) : null}
|
||
|
||
<div className="wst-stats">
|
||
<Card bordered={false} className="wst-stat">
|
||
<Statistic
|
||
title={(
|
||
<Tooltip title="到 13:00 / 18:00 核验时刻仍未发货的订单(按审核时间分轮),不设满 24 小时门槛">
|
||
<span>超时未发货</span>
|
||
</Tooltip>
|
||
)}
|
||
value={notStarted ? 0 : (summary.overdueUnshipped ?? 0)}
|
||
suffix="单"
|
||
formatter={(v) => (notStarted ? '—' : number(v))}
|
||
valueStyle={{ color: (summary.overdueUnshipped || 0) > 0 ? '#cf1322' : undefined }}
|
||
/>
|
||
{staleUnshipped > 0 ? (
|
||
<Tooltip title="这批单来自已停止同步的订单表:停更之后发出的单,在库里 send_date 还是空,会被判成「未发」。先在聚水潭核对,别直接拿去追仓库。">
|
||
<div className="wst-stat__warn">
|
||
其中 {number(staleUnshipped)} 单数据未同步
|
||
</div>
|
||
</Tooltip>
|
||
) : null}
|
||
</Card>
|
||
<Card
|
||
bordered={false}
|
||
className="wst-stat wst-stat--held"
|
||
onClick={() => setHeldOpen(true)}
|
||
>
|
||
<Statistic
|
||
title={(
|
||
<Tooltip title="待审核(订单状态 WaitConfirm,还没审单,仓库没接到)和订单异常(Question)的单。这类单不进仓库考核,点开看明细。">
|
||
<span>不计考核 <span className="wst-stat__more">明细</span></span>
|
||
</Tooltip>
|
||
)}
|
||
value={notStarted ? 0 : (summary.heldCount ?? 0)}
|
||
suffix="单"
|
||
formatter={(v) => (notStarted ? '—' : number(v))}
|
||
valueStyle={{ color: (summary.heldCount || 0) > 0 ? '#8c8c8c' : undefined }}
|
||
/>
|
||
</Card>
|
||
<Card bordered={false} className="wst-stat">
|
||
<Statistic
|
||
title="涉及仓库"
|
||
value={notStarted ? 0 : (summary.overdueCenterCount ?? 0)}
|
||
suffix="个"
|
||
formatter={(v) => (notStarted ? '—' : number(v))}
|
||
/>
|
||
</Card>
|
||
<Card bordered={false} className="wst-stat">
|
||
<Statistic
|
||
title="最久未发货"
|
||
value={notStarted ? 0 : (summary.oldestDays ?? 0)}
|
||
suffix="天"
|
||
formatter={(v) => (notStarted ? '—' : number(v))}
|
||
valueStyle={{ color: (summary.oldestDays || 0) >= 7 ? '#d46b08' : undefined }}
|
||
/>
|
||
</Card>
|
||
</div>
|
||
|
||
<div className="wst-body">
|
||
<Card
|
||
bordered={false}
|
||
className="wst-centers"
|
||
title="仓储中心"
|
||
extra={<Text type="secondary" className="wst-centers__hint">点仓库看明细</Text>}
|
||
>
|
||
<Spin spinning={loading && !data} size="small">
|
||
<ul className="wst-centers__list">
|
||
{centers.map((c) => {
|
||
const isActive = activeCenter === c.key;
|
||
const disabled = c.placeholder || notStarted;
|
||
return (
|
||
<li key={c.key}>
|
||
<Tooltip
|
||
placement="right"
|
||
title={c.placeholder
|
||
? '系统仓库表中暂无同名仓,待上游建仓后自动接入'
|
||
: notStarted
|
||
? `今日 ${nextRoundText} 首轮核验开始后才展示超时数据`
|
||
: `${c.name}:本轮核验 ${String(c.windowEnd || '').slice(11, 16) || windowEndText} 前审核的单,`
|
||
+ `超时未发货 ${c.overdueUnshipped} 单`
|
||
+ `${c.oldestDays > 0 ? `(最久已等 ${c.oldestDays} 天)` : ''}`
|
||
+ `${c.heldCount > 0 ? `\n另有不计考核(待审核/异常)${c.heldCount} 单` : ''}`
|
||
+ (c.warehouseCount > 1 ? `\n含子仓 ${c.warehouseCount} 个` : '')}
|
||
>
|
||
<button
|
||
type="button"
|
||
className={[
|
||
'wst-center',
|
||
isActive ? 'is-active' : '',
|
||
!c.overdueUnshipped ? 'is-empty' : '',
|
||
disabled ? 'is-disabled' : '',
|
||
].filter(Boolean).join(' ')}
|
||
onClick={() => {
|
||
if (disabled) return;
|
||
setActiveCenter(isActive ? '' : c.key);
|
||
}}
|
||
>
|
||
<span className="wst-center__name">{c.name}</span>
|
||
{c.placeholder ? (
|
||
<span className="wst-center__badge wst-center__badge--none">未接入</span>
|
||
) : (
|
||
<span className={`wst-center__badge${c.overdueUnshipped > 0 ? ' is-warn' : ''}`}>
|
||
{notStarted ? '—' : (c.overdueUnshipped > 0 ? c.overdueUnshipped : '—')}
|
||
</span>
|
||
)}
|
||
</button>
|
||
</Tooltip>
|
||
</li>
|
||
);
|
||
})}
|
||
</ul>
|
||
</Spin>
|
||
</Card>
|
||
|
||
<Card
|
||
bordered={false}
|
||
className="wst-detail"
|
||
title={(
|
||
<span>
|
||
超时未发货订单
|
||
<span className="wst-detail__scope">
|
||
{activeCenterName || '全部仓库'} · {activeCenter
|
||
? (activeCenterRow?.overdueUnshipped ?? detailOrders.length)
|
||
: detailTotal} 单
|
||
{!activeCenter && data?.truncated
|
||
? `(页面只显示前 ${data.detailLimit} 条,导出可拿全部 ${detailTotal} 条)`
|
||
: ''}
|
||
</span>
|
||
</span>
|
||
)}
|
||
extra={(
|
||
<Space size={8}>
|
||
{activeCenter ? (
|
||
<button type="button" className="wst-detail__clear" onClick={() => setActiveCenter('')}>
|
||
查看全部
|
||
</button>
|
||
) : null}
|
||
<Dropdown
|
||
trigger={['click']}
|
||
disabled={exporting || notStarted}
|
||
menu={{ items: EXPORT_MENU_ITEMS, onClick: ({ key }) => handleExport(key) }}
|
||
>
|
||
<Button size="small" icon={<DownloadOutlined />} loading={exporting}>
|
||
导出明细
|
||
</Button>
|
||
</Dropdown>
|
||
</Space>
|
||
)}
|
||
>
|
||
<Spin spinning={loading && !data}>
|
||
{notStarted ? (
|
||
<Empty
|
||
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
||
description={`未到核验时间,今日 ${nextRoundText} 开始首轮核验`}
|
||
/>
|
||
) : detailOrders.length ? (
|
||
<Table
|
||
rowKey={(r) => `${r.source}-${r.oId}`}
|
||
size="small"
|
||
pagination={{ pageSize: 20, size: 'small', showSizeChanger: false, showTotal: (t) => `共 ${t} 单` }}
|
||
dataSource={detailOrders}
|
||
columns={DETAIL_COLUMNS}
|
||
scroll={{ x: 1642 }}
|
||
/>
|
||
) : (
|
||
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="本轮没有超时未发货的订单" />
|
||
)}
|
||
</Spin>
|
||
</Card>
|
||
</div>
|
||
|
||
<Modal
|
||
title={`不计考核(待审核 / 异常)· ${heldTotal} 单`}
|
||
open={heldOpen}
|
||
onCancel={() => setHeldOpen(false)}
|
||
footer={null}
|
||
width={1080}
|
||
destroyOnHidden
|
||
>
|
||
<Alert
|
||
type="info"
|
||
showIcon
|
||
className="wst-alert"
|
||
message="「待审核」= 订单状态还没审单(WaitConfirm),仓库根本没接到;「订单异常」= 聚水潭标记 Question(缺货/地址/风控等)。两类都不该算仓库超时,故单列于此。"
|
||
/>
|
||
{heldOrders.length ? (
|
||
<Table
|
||
rowKey={(r) => `${r.oId}`}
|
||
size="small"
|
||
pagination={{ pageSize: 10, size: 'small', showSizeChanger: false, showTotal: (t) => `共 ${t} 单` }}
|
||
dataSource={heldOrders}
|
||
columns={HELD_COLUMNS}
|
||
scroll={{ x: 1280 }}
|
||
/>
|
||
) : (
|
||
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="本轮没有待审核 / 异常的单" />
|
||
)}
|
||
</Modal>
|
||
|
||
<Modal
|
||
title="发货时效通知 · 两轮核验完成后各推一次到钉钉群"
|
||
open={notifyOpen}
|
||
onCancel={() => setNotifyOpen(false)}
|
||
width={760}
|
||
destroyOnHidden
|
||
maskClosable={false}
|
||
styles={{ body: { maxHeight: '62vh', overflowY: 'auto' } }}
|
||
footer={[
|
||
<Button key="close" onClick={() => setNotifyOpen(false)}>关闭</Button>,
|
||
<Button key="probe" onClick={() => handleRunNotify('probe')} loading={notifyRunning} disabled={notifySaving}>
|
||
测试通道
|
||
</Button>,
|
||
<Button key="preview" onClick={() => handleRunNotify('dry')} loading={notifyRunning} disabled={notifySaving}>
|
||
预览正文
|
||
</Button>,
|
||
<Button key="save" onClick={() => handleSaveNotify()} loading={notifySaving}>保存</Button>,
|
||
<Button key="run" type="primary" onClick={() => handleRunNotify('send')} loading={notifyRunning} disabled={notifySaving}>
|
||
立即推送到群
|
||
</Button>,
|
||
]}
|
||
>
|
||
<Spin spinning={notifyLoading}>
|
||
<Space direction="vertical" size={12} style={{ width: '100%' }}>
|
||
<Alert
|
||
type={notifyConfig?.ready ? 'success' : 'warning'}
|
||
showIcon
|
||
message={notifyConfig?.ready
|
||
? `通道已配好:13:00 轮 → ${notifyForm.noonSendTime} 推、18:00 轮 → ${notifyForm.afternoonSendTime} 推(0 单超时也推,用来确认任务在跑)`
|
||
: 'Webhook 地址还没配,填好保存后点「测试通道」验一下'}
|
||
description={notifyConfig?.ready ? null : (
|
||
<span>
|
||
缺:<b>{(notifyConfig?.missingFields || []).join(' / ') || '(尚未读取)'}</b>
|
||
</span>
|
||
)}
|
||
/>
|
||
|
||
<div className="wst-notify__row">
|
||
<span className="wst-notify__label">开启推送</span>
|
||
<Switch
|
||
checked={notifyForm.enabled}
|
||
onChange={(checked) => setNotifyForm((old) => ({ ...old, enabled: checked }))}
|
||
checkedChildren="开"
|
||
unCheckedChildren="关"
|
||
/>
|
||
<Text type="secondary">关掉后定时任务不推,但「立即推送」仍可用(方便先试口径)</Text>
|
||
</div>
|
||
|
||
<div className="wst-notify__row">
|
||
<span className="wst-notify__label">13:00 轮</span>
|
||
<TimePicker
|
||
format="HH:mm"
|
||
value={notifyNoonValue}
|
||
allowClear={false}
|
||
minuteStep={5}
|
||
style={{ width: 96 }}
|
||
onChange={(value) => {
|
||
if (!value) return;
|
||
setNotifyForm((old) => ({ ...old, noonSendTime: value.format('HH:mm') }));
|
||
}}
|
||
/>
|
||
<Text type="secondary">核验「今天 07:00 前审核」的超时单,默认核验点 + 5 分钟</Text>
|
||
</div>
|
||
|
||
<div className="wst-notify__row">
|
||
<span className="wst-notify__label">18:00 轮</span>
|
||
<TimePicker
|
||
format="HH:mm"
|
||
value={notifyAfternoonValue}
|
||
allowClear={false}
|
||
minuteStep={5}
|
||
style={{ width: 96 }}
|
||
onChange={(value) => {
|
||
if (!value) return;
|
||
setNotifyForm((old) => ({ ...old, afternoonSendTime: value.format('HH:mm') }));
|
||
}}
|
||
/>
|
||
<Text type="secondary">核验「截止 16:00 前审核」的超时单(含历史未发),默认核验点 + 5 分钟</Text>
|
||
</div>
|
||
|
||
<div className="wst-notify__row">
|
||
<span className="wst-notify__label">Webhook</span>
|
||
<Input
|
||
value={notifyForm.webhookUrl}
|
||
placeholder="https://oapi.dingtalk.com/robot/send?access_token=xxxx"
|
||
onChange={(e) => setNotifyForm((old) => ({ ...old, webhookUrl: e.target.value }))}
|
||
style={{ flex: 1, minWidth: 380 }}
|
||
/>
|
||
</div>
|
||
|
||
<div className="wst-notify__row">
|
||
<span className="wst-notify__label">加签密钥</span>
|
||
<Input.Password
|
||
value={notifyForm.webhookSecret}
|
||
placeholder={notifyConfig?.webhookSecretConfigured
|
||
? `已保存 ${notifyConfig.webhookSecretPreview || ''},留空表示不修改`
|
||
: 'SEC 开头;安全设置选「关键词 / IP」时留空'}
|
||
onChange={(e) => setNotifyForm((old) => ({ ...old, webhookSecret: e.target.value }))}
|
||
style={{ flex: 1, minWidth: 320 }}
|
||
/>
|
||
</div>
|
||
|
||
<div className="wst-notify__row">
|
||
<span className="wst-notify__label">明细条数</span>
|
||
<InputNumber
|
||
min={0}
|
||
max={notifyConfig?.maxDetailRowsLimit || 50}
|
||
precision={0}
|
||
value={notifyForm.maxDetailRows}
|
||
onChange={(value) => setNotifyForm((old) => ({ ...old, maxDetailRows: value ?? 0 }))}
|
||
style={{ width: 96 }}
|
||
/>
|
||
<Text type="secondary">
|
||
消息里最多列几条明细(0 = 只发汇总,每仓保底 1 条);钉钉文本上限 20000 字节,超了会自动精简
|
||
</Text>
|
||
</div>
|
||
|
||
<div className="wst-notify__row">
|
||
<span className="wst-notify__label">@所有人</span>
|
||
<Switch
|
||
checked={notifyForm.atAll}
|
||
onChange={(checked) => setNotifyForm((old) => ({ ...old, atAll: checked }))}
|
||
checkedChildren="开"
|
||
unCheckedChildren="关"
|
||
/>
|
||
<Text type="secondary">打开后每轮超时都会 @所有人(0 单超时也会推一条平安消息)</Text>
|
||
</div>
|
||
|
||
<div className="wst-notify__row">
|
||
<span className="wst-notify__label">页面链接</span>
|
||
<Input
|
||
value={notifyForm.pageUrl}
|
||
placeholder="消息末尾「查看全部」用的地址(留空用默认生产地址)"
|
||
onChange={(e) => setNotifyForm((old) => ({ ...old, pageUrl: e.target.value }))}
|
||
style={{ flex: 1, minWidth: 380 }}
|
||
/>
|
||
</div>
|
||
|
||
{notifyPreview ? (
|
||
<div className="wst-notify__preview">
|
||
<div className="wst-notify__preview-head">
|
||
<Text type="secondary">
|
||
{notifyPreview.roundLabel || '预览'}
|
||
{' '}| 超时 <b>{notifyPreview.rowCount}</b> 单
|
||
{' '}| 消息里列出 <b>{notifyPreview.listedCount}</b> 条
|
||
{' '}| {Math.round((notifyPreview.bytes / 1024) * 10) / 10} KB
|
||
{notifyPreview.truncated ? '(超长已精简)' : ''}
|
||
</Text>
|
||
<Button type="link" size="small" onClick={() => setNotifyPreview(null)}>收起</Button>
|
||
</div>
|
||
<pre>{notifyPreview.text || '(消息正文为空)'}</pre>
|
||
</div>
|
||
) : null}
|
||
|
||
<div className="wst-notify__last">
|
||
<Text type="secondary">
|
||
上次推送:
|
||
{notifyLastState.lastSentAt
|
||
? <> {String(notifyLastState.lastSentAt).slice(0, 10)} {String(notifyLastState.lastSentAt).slice(11, 19)}
|
||
{' '}· {notifyLastState.lastRoundLabel || notifyLastState.lastRound || '—'}
|
||
{' '}· 超时 {notifyLastState.rowCount ?? 0} 单
|
||
{' '}· 列出 {notifyLastState.listedCount ?? '—'} 条
|
||
{notifyLastState.truncated ? '(超长已精简)' : ''}</>
|
||
: ' 还没有成功推送记录'}
|
||
</Text>
|
||
{notifyLastState.lastError ? (
|
||
<div className="wst-notify__error">
|
||
<Text type="danger">最近一次失败:{String(notifyLastState.lastError).slice(0, 300)}</Text>
|
||
</div>
|
||
) : null}
|
||
</div>
|
||
|
||
<Collapse size="small" items={NOTIFY_HELP_ITEMS} />
|
||
</Space>
|
||
</Spin>
|
||
</Modal>
|
||
|
||
<Text type="secondary" className="wst-foot">
|
||
说明:数据源 = 聚水潭<b>订单表 jst_Orders + jst_qmcust_orderlist</b>(两张表店铺互斥,按 o_id 去重)。
|
||
<b>今天 7:00 前审核</b>的订单 13:00 核验;<b>截止 16:00 前审核</b>的单 18:00 核验
|
||
(含 7 点前审核、13:00 还没发出的,也含今天之前审核至今未发的历史单)。
|
||
<b>到点仍未发货即超时</b>(不设「满 24 小时」门槛);
|
||
轮次与「已等时长」都按<b>审核时间</b>算(= 状态表 last_oa_confirm_time 与订单表 modified 的较晚者,
|
||
审核才是仓库接到单的时刻;状态表会滞后,故取较晚者)。两者都取不到才回退订单创建时间,列上带 <b>*</b>。
|
||
发货 = 订单表 send_date(为空才算未发)。<b>已发货不考核</b>:状态表 send_time 有值、
|
||
聚水潭状态「已发货」、或物流已揽收及之后,任一成立即判已发
|
||
{summary.stateShippedSkipped > 0 ? ` —— 本轮已剔除 ${summary.stateShippedSkipped} 单` : ''}。
|
||
状态只取「发货中」。
|
||
<b>作废单不考核</b>:聚水潭状态「已取消」,或订单表 labels 含「发货前售后」
|
||
{summary.voidCount > 0
|
||
? ` —— 本轮已自动剔除 ${summary.voidCount} 单`
|
||
+ `${summary.stateVoidSkipped > 0 ? `(其中 ${summary.stateVoidSkipped} 单靠聚水潭状态判出,订单表当时没同步)` : ''}`
|
||
: ''};
|
||
⚠️ 售后状态「已作废」<b>不算</b>作废单 —— 那是售后单被撤销、订单照常发货,仍要考核。
|
||
<b>{excludedCarrierText}不考核</b>
|
||
{summary.carrierSkipped > 0 ? ` —— 本轮已剔除 ${summary.carrierSkipped} 单` : ''};
|
||
待审核、订单异常的单归入「不计考核」,避免冤枉仓库。
|
||
</Text>
|
||
</SycmPage>
|
||
);
|
||
}
|
||
|
||
export default WarehouseShipTimeliness;
|