From bb99330cbf01a2ee44c348aa369d3e98d4b8d4bd Mon Sep 17 00:00:00 2001 From: geting <13585118195@163.com> Date: Mon, 20 Jan 2025 13:53:43 +0800 Subject: [PATCH 1/3] bugfixed --- .../backend/statAnalysis/trendComparison.vue | 106 +++++++++--------- 1 file changed, 55 insertions(+), 51 deletions(-) diff --git a/ui/dasadmin/src/views/backend/statAnalysis/trendComparison.vue b/ui/dasadmin/src/views/backend/statAnalysis/trendComparison.vue index 20c46535..c46d508f 100644 --- a/ui/dasadmin/src/views/backend/statAnalysis/trendComparison.vue +++ b/ui/dasadmin/src/views/backend/statAnalysis/trendComparison.vue @@ -609,12 +609,18 @@ const handleRes = (res: any, selectAllDevices: any) => { attIndex = highSpeedExoprtHeader.value.indexOf(attName) } xData.forEach((time: any, index: number) => { - const dataItem = [ - escapeCsvValue(deviceName + '\t'), // 风机名称 - escapeCsvValue(timestampToTime(time) + '\t'), // 时间 - ] - dataItem[attIndex] = escapeCsvValue(yData[index] + '\t') - highSpeedExoprtData.value.push(dataItem.join(',')) + const tableDataIndex = highSpeedExoprtData.value.findIndex( + (data: any) => data.name == deviceName && data.time == timestampToTime(time) + ) + if (tableDataIndex > -1) { + highSpeedExoprtData.value[tableDataIndex][attName] = yData[index] + } else { + highSpeedExoprtData.value.push({ + name: deviceName, + time: timestampToTime(time), + [attName]: yData[index], + }) + } }) } else { let attIndex = lowSpeedExoprtHeader.value.indexOf(attName) @@ -623,26 +629,20 @@ const handleRes = (res: any, selectAllDevices: any) => { attIndex = lowSpeedExoprtHeader.value.indexOf(attName) } xData.forEach((time: any, index: number) => { - const dataItem = [ - escapeCsvValue(deviceName) + '\t', // 风机名称 - escapeCsvValue(timestampToTime(time)) + '\t' + '\t', // 时间 - ] - dataItem[attIndex] = escapeCsvValue(yData[index] + '\t') - lowSpeedExoprtData.value.push(dataItem.join(',')) + const tableDataIndex = lowSpeedExoprtData.value.findIndex( + (data: any) => data.name == deviceName && data.time == timestampToTime(time) + ) + if (tableDataIndex > -1) { + lowSpeedExoprtData.value[tableDataIndex][attName] = yData[index] + } else { + lowSpeedExoprtData.value.push({ + name: deviceName, + time: timestampToTime(time), + [attName]: yData[index], + }) + } }) } - highcsvContent.value = highSpeedExoprtData.value.length - ? highSpeedExoprtHeader.value + '\n' + highSpeedExoprtData.value.join('\n') - : [] - lowcsvContent.value = lowSpeedExoprtData.value.length - ? lowSpeedExoprtHeader.value + '\n' + lowSpeedExoprtData.value.join('\n') - : [] - if (!yData.length) { - ElMessage.info(`${deviceName + attName}数据为空`) - return - } - console.log(selectAllDevicesIndex) - console.log(irnIndex) const seriesData = { name: deviceName + attName, type: 'line', @@ -681,37 +681,41 @@ const handleRes = (res: any, selectAllDevices: any) => { } } -const escapeCsvValue = (value: any) => { - if (value === undefined || value === null) { - return ' ' - } - if (typeof value === 'string') { - if (value.includes(',') || value.includes('"') || value.includes('\n')) { - return `"${value.replace(/"/g, '""')}"` - } - } - - return value -} const statAnalysisExport = () => { const tables = [ - { data: highcsvContent.value, filename: '多机对比_高频' + new Date().getTime() + '.csv' }, - { data: lowcsvContent.value, filename: '多机对比_低频' + new Date().getTime() + '.csv' }, + { header: highSpeedExoprtHeader.value, data: highSpeedExoprtData.value, filename: '多机对比_高频' + new Date().getTime() + '.csv' }, + { header: lowSpeedExoprtHeader.value, data: lowSpeedExoprtData.value, filename: '多机对比_低频' + new Date().getTime() + '.csv' }, ] - tables.forEach((table) => { - const csvContent = table.data - if (csvContent.length) { - const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' }) - const link = document.createElement('a') - if (link.download !== undefined) { - const url = URL.createObjectURL(blob) - link.setAttribute('href', url) - link.setAttribute('download', table.filename) - link.style.visibility = 'hidden' - document.body.appendChild(link) - link.click() - document.body.removeChild(link) + if (table.data.length) { + let str = '' + table.data.forEach((item: any) => { + table.header.forEach((prop: any, index: number) => { + let val = '' + if (index == 0) { + val = item.name + } else if (index == 1) { + val = item.time + } else { + val = typeof item[prop] === 'number' ? String(item[prop]) : item[prop] ? item[prop] : '' + } + str += val + '\t' + ',' + }) + str += '\n' + }) + str = table.header + '\n' + str + if (str.length) { + const blob = new Blob([str], { type: 'text/csv;charset=utf-8;' }) + const link = document.createElement('a') + if (link.download !== undefined) { + const url = URL.createObjectURL(blob) + link.setAttribute('href', url) + link.setAttribute('download', table.filename) + link.style.visibility = 'hidden' + document.body.appendChild(link) + link.click() + document.body.removeChild(link) + } } } }) From 5ddf1ddc5ddf90e89cee6bab858ec17f3e787d6b Mon Sep 17 00:00:00 2001 From: huguanghan Date: Tue, 21 Jan 2025 17:35:44 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=98=A0=E5=B0=84=E8=A1=A8=E7=BB=91?= =?UTF-8?q?=E5=AE=9A=E8=AE=BE=E5=A4=87=E5=88=97=E8=A1=A8bug=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- das/src/main/resources/mapper/SysImpTabMappingMapper.xml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/das/src/main/resources/mapper/SysImpTabMappingMapper.xml b/das/src/main/resources/mapper/SysImpTabMappingMapper.xml index bf60e775..f388d7be 100644 --- a/das/src/main/resources/mapper/SysImpTabMappingMapper.xml +++ b/das/src/main/resources/mapper/SysImpTabMappingMapper.xml @@ -105,7 +105,10 @@ From 4ded09c3d5962d6dcf5c6c429e951a3130318507 Mon Sep 17 00:00:00 2001 From: huguanghan Date: Tue, 21 Jan 2025 17:37:27 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=98=A0=E5=B0=84=E8=A1=A8=E7=BB=91?= =?UTF-8?q?=E5=AE=9A=E8=AE=BE=E5=A4=87=E5=88=97=E8=A1=A8bug=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- das/src/main/resources/mapper/SysImpTabMappingMapper.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/das/src/main/resources/mapper/SysImpTabMappingMapper.xml b/das/src/main/resources/mapper/SysImpTabMappingMapper.xml index f388d7be..2fbf6e7d 100644 --- a/das/src/main/resources/mapper/SysImpTabMappingMapper.xml +++ b/das/src/main/resources/mapper/SysImpTabMappingMapper.xml @@ -105,7 +105,7 @@