|
|
@ -102,6 +102,8 @@ Page({ |
|
|
|
// 创建一个对象来存储每个pointId的最大inspectionTime
|
|
|
|
const maxInspectionTimeByPointId = {}; |
|
|
|
const sevenDaysAgo = moment().subtract(7, 'days'); // 获取七天前的日期
|
|
|
|
//把设备数据全部弄成未知状态
|
|
|
|
const len=complexArray.map(item=>{return {id:item.id,name:item.name,status:'unknown'}})?.length |
|
|
|
// 过滤出近七天内的最新记录(同点位+同一天的最新记录)
|
|
|
|
const latestRecords = patrolRecord.filter((record) => { |
|
|
|
const inspectionDate = moment(record.inspectionTime).format('YYYY-MM-DD'); |
|
|
@ -117,7 +119,7 @@ Page({ |
|
|
|
}); |
|
|
|
}); |
|
|
|
//调用每天的函数处理每天的正常-异常-未知的个数
|
|
|
|
const sevenDays= that.calculateDailyDeviceStatusCounts(latestRecords) |
|
|
|
const sevenDays= that.calculateDailyDeviceStatusCounts(latestRecords,len) |
|
|
|
// 遍历数据并更新maxInspectionTimeByPointId
|
|
|
|
patrolRecord.forEach((item) => { |
|
|
|
const {pointId,inspectionTime} = item; |
|
|
@ -139,7 +141,7 @@ Page({ |
|
|
|
return false; |
|
|
|
}); |
|
|
|
//七天内最新的数据(正常)
|
|
|
|
const statusCounts =that.classifiedStatistics(filteredData) |
|
|
|
const statusCounts =that.classifiedStatistics(filteredData,len) |
|
|
|
const {unknown,normal,abnormal}=statusCounts |
|
|
|
const deviceCount=complexArray.length |
|
|
|
that.setData({ |
|
|
@ -159,10 +161,10 @@ Page({ |
|
|
|
|
|
|
|
}, |
|
|
|
//分类统计设备,异常-正常-未知个数
|
|
|
|
classifiedStatistics:function(list){ |
|
|
|
classifiedStatistics:function(list,len){ |
|
|
|
let normal = 0; |
|
|
|
let abnormal = 0; |
|
|
|
let unknown = 0; |
|
|
|
let unknown = len; |
|
|
|
list.forEach((item) => { |
|
|
|
const inspectContent = item.alarm ? (item?.points?.inspectContent || []) : []; |
|
|
|
if (inspectContent && inspectContent.length && Array.isArray(inspectContent)) { |
|
|
@ -174,17 +176,20 @@ Page({ |
|
|
|
if (state === 6) { |
|
|
|
// 正常
|
|
|
|
normal += 1; |
|
|
|
unknown-=1 |
|
|
|
} else if (state === 5) { |
|
|
|
// 未知
|
|
|
|
unknown += 1; |
|
|
|
// unknown += 1;
|
|
|
|
} else { |
|
|
|
// 异常
|
|
|
|
abnormal += 1; |
|
|
|
unknown-=1 |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
// 正常
|
|
|
|
normal += 1; |
|
|
|
unknown-=1 |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
@ -192,7 +197,7 @@ Page({ |
|
|
|
return {normal,unknown,abnormal} |
|
|
|
}, |
|
|
|
//统计每天异常-正常-未知个数
|
|
|
|
calculateDailyDeviceStatusCounts:function(data) { |
|
|
|
calculateDailyDeviceStatusCounts:function(data,len) { |
|
|
|
const dateRange = [] |
|
|
|
const today = moment() |
|
|
|
for (let i = 6; i >= 0; i--) { |
|
|
@ -203,7 +208,7 @@ Page({ |
|
|
|
dateRange.forEach((date) => { |
|
|
|
dailyCounts[date] = { |
|
|
|
normal: 0, |
|
|
|
unknown: 0, |
|
|
|
unknown: len, |
|
|
|
abnormal: 0 |
|
|
|
}; |
|
|
|
}); |
|
|
@ -214,14 +219,15 @@ Page({ |
|
|
|
const status = item.patrolRecordIssueHandles.length ? item.patrolRecordIssueHandles[0].state : 6; |
|
|
|
if (status === 6) { |
|
|
|
dailyCounts[inspectionDate].normal += 1; |
|
|
|
dailyCounts[inspectionDate].unknown -= 1; |
|
|
|
} else if (status === 5) { |
|
|
|
dailyCounts[inspectionDate].unknown += 1; |
|
|
|
// dailyCounts[inspectionDate].unknown += 1;
|
|
|
|
} else { |
|
|
|
dailyCounts[inspectionDate].abnormal += 1; |
|
|
|
dailyCounts[inspectionDate].unknown -= 1; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
return dailyCounts; |
|
|
|
}, |
|
|
|
/** |
|
|
|