import {GlassButton, html, useState, useToast} from 'vendor'; import {api, download, useApp} from '../api.js'; import {DataTable} from '../components/DataTable.js'; import {Icon} from '../components/icons.js'; import {Loading, Section} from '../components/ui.js'; // 问题行表格:站点工参没有时间列 const ERROR_COLUMNS = [ {key: 'row', title: '文件行号'}, {key: 'key', title: '编号 / 名称'}, {key: 'start_time', title: '时间'}, {key: 'reason', title: '问题原因', render: v => html`${v}`}, ]; const SITE_ERROR_COLUMNS = [ {key: 'row', title: '文件行号'}, {key: 'key', title: '基站编号 / 名称'}, {key: 'reason', title: '问题原因', render: v => html`${v}`}, ]; // 合格数据预览表格,按文件类型显示不同的列 const PREVIEW_COLUMNS = { outage: [ {key: 'record_id', title: '流水号'}, {key: 'ne_id', title: '基站编号'}, {key: 'start_time', title: '开始时间'}, {key: 'end_time', title: '恢复时间'}, {key: 'duration_min', title: '计算时长(分)'}, {key: 'reported_min', title: '上报时长(分)'}, {key: 'cause_category', title: '原因大类'}, {key: 'cause_code', title: '原因码'}, ], alarm: [ {key: 'alarm_id', title: '告警编号'}, {key: 'ne_id', title: '基站编号'}, {key: 'alarm_name', title: '告警名称'}, {key: 'alarm_level', title: '级别'}, {key: 'category', title: '归入类别'}, {key: 'start_time', title: '发生时间'}, {key: 'clear_time', title: '清除时间'}, {key: 'parent_alarm_id', title: '父告警'}, ], site: [ {key: 'action', title: '操作'}, {key: 'ne_id', title: '基站编号'}, {key: 'site_name', title: '基站名称'}, {key: 'district', title: '片区'}, {key: 'scene', title: '推断场景'}, {key: 'site_type', title: '站型'}, {key: 'vendor', title: '厂家'}, {key: 'cells', title: '小区数'}, {key: 'lng', title: '经度'}, {key: 'lat', title: '纬度'}, ], }; /** * 导入分两步:上传预览(服务端识别类型并校验,不入库)→ 确认入库。 * 退服流水入库后对新记录做根因分析;告警入库后对全部流水重新关联;站点入库后刷新下拉选项。 */ export default function Import() { const {refreshMeta} = useApp(); const toast = useToast(); const [dragOver, setDragOver] = useState(false); const [checking, setChecking] = useState(false); const [saving, setSaving] = useState(false); const [preview, setPreview] = useState(null); // 服务端校验结果 const [result, setResult] = useState(null); // 入库结果 const upload = async file => { if (!file) return; const body = new FormData(); body.append('file', file); setChecking(true); setPreview(null); setResult(null); try { setPreview(await api('/api/import/preview', {body})); } catch (e) { toast({message: e.message, tone: 'error'}); } setChecking(false); }; const confirmImport = async () => { setSaving(true); try { const r = await api('/api/import/confirm', {json: {token: preview.token}}); setResult({...r, label: preview.label}); setPreview(null); toast({message: `${preview.label}入库完成`, tone: 'success'}); if (r.kind === 'site') { await refreshMeta(); // 新站点可能带来新的片区、厂家,并改变站点总数 } } catch (e) { toast({message: e.message, tone: 'error'}); } setSaving(false); }; const templateButton = html` <${GlassButton} variant="gray" onClick=${() => download('/api/template')}>下载退服流水模板${GlassButton}>`; return html` <${Section} title="数据批量导入" extra=${templateButton}> ${checking && html`<${Loading}/>`} ${result && html`<${ImportResult} result=${result}/>`} ${preview && html`<${PreviewPanel} preview=${preview} saving=${saving} onConfirm=${confirmImport}/>`} ${Section}>`; } /** 入库完成后的说明 */ function ImportResult({result}) { let detail = `入库 ${result.n} 条`; if (result.kind === 'site') { detail = `新增站点 ${result.added} 个,更新站点 ${result.updated} 个`; } return html`
有 ${preview.ok - preview.matched} 条告警的基站不在站点库中:可以入库留档,但不会参与本系统站点的根因分析。 可先导入对应的站点工参。
`} ${preview.bad > 0 && html`