This commit is contained in:
高云鹏 2025-01-22 09:01:09 +08:00
commit 05f1629803
2 changed files with 59 additions and 52 deletions

View File

@ -105,7 +105,10 @@
</select> </select>
<select id="getBindDeviceByLink" resultMap="EquipmentMap"> <select id="getBindDeviceByLink" resultMap="EquipmentMap">
select t.id ,t."name",t.iot_model_id,t.iot_addr from sys_equipment t where t.id in (select distinct equipment_id from sys_imptabmapping where link_id =#{linkId}) select se.id ,se."name",se.iot_model_id,se.iot_addr,min(imp.porder) as porder from sys_imptabmapping imp
left join sys_equipment se on imp.equipment_id = se.id
where link_id = #{linkId}
group by se.id ,se."name",se.iot_model_id,se.iot_addr order by porder
</select> </select>
<delete id="deleteMappingByLinkId"> <delete id="deleteMappingByLinkId">

View File

@ -609,12 +609,18 @@ const handleRes = (res: any, selectAllDevices: any) => {
attIndex = highSpeedExoprtHeader.value.indexOf(attName) attIndex = highSpeedExoprtHeader.value.indexOf(attName)
} }
xData.forEach((time: any, index: number) => { xData.forEach((time: any, index: number) => {
const dataItem = [ const tableDataIndex = highSpeedExoprtData.value.findIndex(
escapeCsvValue(deviceName + '\t'), // (data: any) => data.name == deviceName && data.time == timestampToTime(time)
escapeCsvValue(timestampToTime(time) + '\t'), // )
] if (tableDataIndex > -1) {
dataItem[attIndex] = escapeCsvValue(yData[index] + '\t') highSpeedExoprtData.value[tableDataIndex][attName] = yData[index]
highSpeedExoprtData.value.push(dataItem.join(',')) } else {
highSpeedExoprtData.value.push({
name: deviceName,
time: timestampToTime(time),
[attName]: yData[index],
})
}
}) })
} else { } else {
let attIndex = lowSpeedExoprtHeader.value.indexOf(attName) let attIndex = lowSpeedExoprtHeader.value.indexOf(attName)
@ -623,26 +629,20 @@ const handleRes = (res: any, selectAllDevices: any) => {
attIndex = lowSpeedExoprtHeader.value.indexOf(attName) attIndex = lowSpeedExoprtHeader.value.indexOf(attName)
} }
xData.forEach((time: any, index: number) => { xData.forEach((time: any, index: number) => {
const dataItem = [ const tableDataIndex = lowSpeedExoprtData.value.findIndex(
escapeCsvValue(deviceName) + '\t', // (data: any) => data.name == deviceName && data.time == timestampToTime(time)
escapeCsvValue(timestampToTime(time)) + '\t' + '\t', // )
] if (tableDataIndex > -1) {
dataItem[attIndex] = escapeCsvValue(yData[index] + '\t') lowSpeedExoprtData.value[tableDataIndex][attName] = yData[index]
lowSpeedExoprtData.value.push(dataItem.join(',')) } 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 = { const seriesData = {
name: deviceName + attName, name: deviceName + attName,
type: 'line', 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 statAnalysisExport = () => {
const tables = [ const tables = [
{ data: highcsvContent.value, filename: '多机对比_高频' + new Date().getTime() + '.csv' }, { header: highSpeedExoprtHeader.value, data: highSpeedExoprtData.value, filename: '多机对比_高频' + new Date().getTime() + '.csv' },
{ data: lowcsvContent.value, filename: '多机对比_低频' + new Date().getTime() + '.csv' }, { header: lowSpeedExoprtHeader.value, data: lowSpeedExoprtData.value, filename: '多机对比_低频' + new Date().getTime() + '.csv' },
] ]
tables.forEach((table) => { tables.forEach((table) => {
const csvContent = table.data if (table.data.length) {
if (csvContent.length) { let str = ''
const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' }) table.data.forEach((item: any) => {
const link = document.createElement('a') table.header.forEach((prop: any, index: number) => {
if (link.download !== undefined) { let val = ''
const url = URL.createObjectURL(blob) if (index == 0) {
link.setAttribute('href', url) val = item.name
link.setAttribute('download', table.filename) } else if (index == 1) {
link.style.visibility = 'hidden' val = item.time
document.body.appendChild(link) } else {
link.click() val = typeof item[prop] === 'number' ? String(item[prop]) : item[prop] ? item[prop] : ''
document.body.removeChild(link) }
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)
}
} }
} }
}) })