|
|
|
|
@ -115,8 +115,8 @@ type DeviceTreeNode = {
|
|
|
|
|
tag?: TreeNodeTag
|
|
|
|
|
children?: DeviceTreeNode[]
|
|
|
|
|
orgClass?: string
|
|
|
|
|
deviceId?: number
|
|
|
|
|
modelId?: number
|
|
|
|
|
deviceId?: string
|
|
|
|
|
modelId?: string
|
|
|
|
|
paramKey?: string
|
|
|
|
|
unit?: string
|
|
|
|
|
paramCount?: number
|
|
|
|
|
@ -124,14 +124,14 @@ type DeviceTreeNode = {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ApiTreeParameter = {
|
|
|
|
|
id: number
|
|
|
|
|
id: string | number
|
|
|
|
|
name: string
|
|
|
|
|
code?: string
|
|
|
|
|
unit?: string | null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ApiTreeEquipment = {
|
|
|
|
|
id: number
|
|
|
|
|
id: string | number
|
|
|
|
|
name: string
|
|
|
|
|
parameters?: ApiTreeParameter[]
|
|
|
|
|
}
|
|
|
|
|
@ -192,8 +192,8 @@ type ChartState = 'idle' | 'loading' | 'empty' | 'ready'
|
|
|
|
|
type SelectedGroup = {
|
|
|
|
|
id: string
|
|
|
|
|
param: DeviceTreeNode
|
|
|
|
|
deviceId?: number
|
|
|
|
|
modelId?: number
|
|
|
|
|
deviceId?: string
|
|
|
|
|
modelId?: string
|
|
|
|
|
dateRange: [string, string]
|
|
|
|
|
requestSeq: number
|
|
|
|
|
chartLoading: boolean
|
|
|
|
|
@ -226,28 +226,18 @@ const handleTreeRefresh = async () => {
|
|
|
|
|
await loadTree()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const toFiniteId = (value: any): number | undefined => {
|
|
|
|
|
if (typeof value === 'number') return Number.isFinite(value) ? value : undefined
|
|
|
|
|
if (typeof value === 'string') {
|
|
|
|
|
if (/^\d+$/.test(value.trim())) return Number(value)
|
|
|
|
|
const n = Number(value)
|
|
|
|
|
return Number.isFinite(n) ? n : undefined
|
|
|
|
|
}
|
|
|
|
|
return undefined
|
|
|
|
|
const toIdString = (value: unknown): string | undefined => {
|
|
|
|
|
const id = String(value ?? '').trim()
|
|
|
|
|
return id || undefined
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const toNodeIds = (node: DeviceTreeNode): { deviceId?: number; modelId?: number } => {
|
|
|
|
|
const modelId = typeof node.modelId === 'number' && Number.isFinite(node.modelId) ? node.modelId : undefined
|
|
|
|
|
const deviceId = typeof node.deviceId === 'number' && Number.isFinite(node.deviceId) ? node.deviceId : undefined
|
|
|
|
|
if (typeof deviceId === 'number') return { deviceId, modelId }
|
|
|
|
|
const toNodeIds = (node: DeviceTreeNode): { deviceId?: string; modelId?: string } => {
|
|
|
|
|
const modelId = toIdString(node.modelId)
|
|
|
|
|
const deviceId = toIdString(node.deviceId)
|
|
|
|
|
if (deviceId) return { deviceId, modelId }
|
|
|
|
|
|
|
|
|
|
const parts = String(node.id ?? '').split('-').filter(Boolean)
|
|
|
|
|
const last = parts.length ? parts[parts.length - 1] : undefined
|
|
|
|
|
const parsed = toFiniteId(last)
|
|
|
|
|
if (typeof parsed !== 'number' || !Number.isFinite(parsed) || parsed <= 0) {
|
|
|
|
|
return { modelId }
|
|
|
|
|
}
|
|
|
|
|
return { deviceId: parsed, modelId }
|
|
|
|
|
return { deviceId: toIdString(parts[parts.length - 1]), modelId }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const buildParamTitle = (param: DeviceTreeNode) => {
|
|
|
|
|
@ -312,8 +302,8 @@ const buildTreeFromApi = (orgs: ApiTreeOrg[]): DeviceTreeNode[] => {
|
|
|
|
|
id: `param-${eq.id}-${p.id}`,
|
|
|
|
|
label: p?.name ?? p?.code ?? String(p?.id ?? ''),
|
|
|
|
|
type: 'param',
|
|
|
|
|
deviceId: toFiniteId(eq.id),
|
|
|
|
|
modelId: toFiniteId(p.id),
|
|
|
|
|
deviceId: toIdString(eq.id),
|
|
|
|
|
modelId: toIdString(p.id),
|
|
|
|
|
paramKey: p?.code ? String(p.code) : undefined,
|
|
|
|
|
unit: p?.unit ? String(p.unit) : undefined,
|
|
|
|
|
disabled: false
|
|
|
|
|
@ -324,7 +314,7 @@ const buildTreeFromApi = (orgs: ApiTreeOrg[]): DeviceTreeNode[] => {
|
|
|
|
|
label: eq?.name ?? String(eq?.id ?? ''),
|
|
|
|
|
type: 'device',
|
|
|
|
|
tag: 'equipment',
|
|
|
|
|
deviceId: toFiniteId(eq.id),
|
|
|
|
|
deviceId: toIdString(eq.id),
|
|
|
|
|
paramCount: params.length,
|
|
|
|
|
children: paramNodes.length ? paramNodes : undefined,
|
|
|
|
|
disabled: true
|
|
|
|
|
@ -506,7 +496,7 @@ const extractChartRows = (res: any): Record<string, any>[] => {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const fetchGroupChart = async (group: SelectedGroup, notify: boolean) => {
|
|
|
|
|
if (typeof group.deviceId !== 'number' || !Number.isFinite(group.deviceId)) return
|
|
|
|
|
if (!group.deviceId) return
|
|
|
|
|
|
|
|
|
|
ensureDateRange(group)
|
|
|
|
|
const [start, end] = group.dateRange
|
|
|
|
|
@ -526,7 +516,7 @@ const fetchGroupChart = async (group: SelectedGroup, notify: boolean) => {
|
|
|
|
|
collectionStartTime: buildDateTime(start, '00:00:00'),
|
|
|
|
|
collectionEndTime: buildDateTime(end, '23:59:59')
|
|
|
|
|
}
|
|
|
|
|
if (typeof group.modelId === 'number' && Number.isFinite(group.modelId)) {
|
|
|
|
|
if (group.modelId) {
|
|
|
|
|
req.modelId = group.modelId
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -537,9 +527,6 @@ const fetchGroupChart = async (group: SelectedGroup, notify: boolean) => {
|
|
|
|
|
group.chartXAxis = []
|
|
|
|
|
group.chartSeries = []
|
|
|
|
|
group.chartState = 'empty'
|
|
|
|
|
if (notify) {
|
|
|
|
|
message.warning(t('DataCollection.DeviceParamAnalysis.messageNodeNoParams'))
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -643,7 +630,7 @@ const syncGroupsByCheckedNodes = (checkedNodes: DeviceTreeNode[]) => {
|
|
|
|
|
const addedGroups: SelectedGroup[] = []
|
|
|
|
|
for (const node of toAdd) {
|
|
|
|
|
const { deviceId, modelId } = toNodeIds(node)
|
|
|
|
|
if (typeof deviceId !== 'number') {
|
|
|
|
|
if (!deviceId) {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
const group: SelectedGroup = {
|
|
|
|
|
|