From ac1551560e20f4e49c1fcd80e1d6931fd9c3a25e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?zhaobing=E2=80=99?= Date: Mon, 25 Dec 2023 20:22:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E8=AE=BE=E5=A4=87=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E6=98=8E=E7=BB=86=E5=8A=A0=E8=BD=BD=E6=85=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../deviceBigdataGraph/deviceBigdataGraph.js | 10 ++++++---- .../statusDetail/statusDetail.js | 19 ++++++++++--------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/weapp/package/deviceBigdataGraph/deviceBigdataGraph.js b/weapp/package/deviceBigdataGraph/deviceBigdataGraph.js index 9dde9dc..9bee0cc 100644 --- a/weapp/package/deviceBigdataGraph/deviceBigdataGraph.js +++ b/weapp/package/deviceBigdataGraph/deviceBigdataGraph.js @@ -47,7 +47,7 @@ Page({ */ data: { ec: {}, - // dataList: [], //巡检记录的列表 + dataList: [], //巡检记录的列表 guaranteedRate: 0, //过保率 warrantyPeriod: 0, //质保期 count: 0, //设备总数 @@ -57,8 +57,10 @@ Page({ }, navigator(e) { const res = JSON.stringify(this.deviceList) + const patrolRecord=JSON.stringify(this.data.dataList) + wx.navigateTo({ - url: `/package/deviceBigdataGraph/statusDetail/statusDetail?arrayData=${encodeURIComponent(res)}`, + url: `/package/deviceBigdataGraph/statusDetail/statusDetail?arrayData=${encodeURIComponent(res)}&patrolRecord=${encodeURIComponent(patrolRecord)}`, }) }, navigatorToLifeWarning(e) { @@ -149,7 +151,7 @@ Page({ } }) - 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:true})).then(res => { + 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) { let normal = 0; let abnormal = 0; @@ -229,7 +231,7 @@ Page({ break; } }); - // that.setData({dataList:res}) + that.setData({dataList:res}) var optionDevice = { tooltip: { trigger: 'item' diff --git a/weapp/package/deviceBigdataGraph/statusDetail/statusDetail.js b/weapp/package/deviceBigdataGraph/statusDetail/statusDetail.js index 6ec760b..b459dc9 100644 --- a/weapp/package/deviceBigdataGraph/statusDetail/statusDetail.js +++ b/weapp/package/deviceBigdataGraph/statusDetail/statusDetail.js @@ -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) - } - }) + + }, //分类统计设备,异常-正常-未知个数