|
|
@ -101,23 +101,24 @@ Page({ |
|
|
|
const that = this |
|
|
|
//上次菜单传入设备列表
|
|
|
|
const complexArray = JSON.parse(decodeURIComponent(options.arrayData)); |
|
|
|
//上级菜单传入巡检记录
|
|
|
|
const patrolRecord = JSON.parse(decodeURIComponent(options.patrolRecord)) |
|
|
|
const today = moment(); |
|
|
|
const date1 = new Date('1970-01-01 00:00:00'); |
|
|
|
Request.get(getPatrolRecord('all', moment(date1).format('YYYY-MM-DD') + ' 00:00:00', moment('2099-12-31').format('YYYY-MM-DD') + ' 23:59:59', 'null', 'null',{home:false})).then(res=>{ |
|
|
|
if(res){ |
|
|
|
|
|
|
|
// console.log('xx111',res)
|
|
|
|
// 创建一个对象来存储每个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 = res.filter((record) => { |
|
|
|
const latestRecords = patrolRecord?.filter((record) => { |
|
|
|
const inspectionDate = moment(record.inspectionTime).format('YYYY-MM-DD'); |
|
|
|
const isWithin7Days = moment(today).diff(inspectionDate, 'days') <= 7; |
|
|
|
if (!isWithin7Days) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
return res.every((r) => { |
|
|
|
return patrolRecord?.every((r) => { |
|
|
|
if (r.pointId === record.pointId && moment(r.inspectionTime).isSame(moment(record.inspectionTime), 'day')) { |
|
|
|
return moment(r.inspectionTime).isSameOrBefore(moment(record.inspectionTime)); |
|
|
|
} |
|
|
@ -127,7 +128,7 @@ Page({ |
|
|
|
//调用每天的函数处理每天的正常-异常-未知的个数
|
|
|
|
const sevenDays= that.calculateDailyDeviceStatusCounts(latestRecords,len) |
|
|
|
// 遍历数据并更新maxInspectionTimeByPointId
|
|
|
|
res.forEach((item) => { |
|
|
|
patrolRecord?.forEach((item) => { |
|
|
|
const {pointId,inspectionTime} = item; |
|
|
|
if (pointId in maxInspectionTimeByPointId) { |
|
|
|
if (inspectionTime > maxInspectionTimeByPointId[pointId]) { |
|
|
@ -138,7 +139,7 @@ Page({ |
|
|
|
} |
|
|
|
}); |
|
|
|
// 过滤数据以获取相同pointId中inspectionTime最大的记录
|
|
|
|
const filteredData = res.filter((item) => { |
|
|
|
const filteredData = patrolRecord?.filter((item) => { |
|
|
|
const { pointId,inspectionTime} = item; |
|
|
|
const inspectionDate = moment(inspectionTime); |
|
|
|
if (inspectionDate.isBetween(sevenDaysAgo, today, null, '[]')) { |
|
|
@ -167,8 +168,8 @@ Page({ |
|
|
|
that.initChart(normaldata,abnormaldata,xData) |
|
|
|
}, 1000) |
|
|
|
|
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}, |
|
|
|
//分类统计设备,异常-正常-未知个数
|
|
|
|