diff --git a/api/app/lib/controllers/device/index.js b/api/app/lib/controllers/device/index.js index a84fb43..6ae8a08 100644 --- a/api/app/lib/controllers/device/index.js +++ b/api/app/lib/controllers/device/index.js @@ -148,10 +148,61 @@ function deleteDevice(opts) { } } } +//获取相应设备信息 +function getDevices(opts) { + return async function (ctx, next) { + const models = ctx.fs.dc.models; + const { page, limit } = ctx.query; + const Op = ctx.fs.dc.ORM.Op; + let errMsg = { message: '获取设备失败' } + try { + let rslt=[] + let searchWhere = {} + let option = { + where: searchWhere, + order: [["id", "desc"]], + include: [{ model: models.PointDevice,include:{model:models.Point} }] + } + option.where = searchWhere + let limit_ = limit || 10; + let page_ = page || 1; + let offset = (page_ - 1) * limit_; + if (limit && page) { + option.limit = limit_ + option.offset = offset + } + let userInfo = ctx.fs.api.userInfo; + rslt = await models.Device.findAll(option); + rslt = rslt.filter(f => f) + if (userInfo.username != 'SuperAdmin') { + if (userInfo.structure) { + rslt = rslt.filter(s => + { + if(s.pointDevices){ + return s.pointDevices.some((item) => + userInfo.structure.find((x) => x === item.point.projectId)) + } + } + ) + } else { + rslt = [] + } + } + ctx.status = 200; + ctx.body = rslt; + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = errMsg + } + } +} + module.exports = { getDeviceList, addDevice, editDevice, - deleteDevice + deleteDevice, + getDevices } \ No newline at end of file diff --git a/api/app/lib/controllers/patrolManage/patrolRecord.js b/api/app/lib/controllers/patrolManage/patrolRecord.js index 7da84ca..4157c09 100644 --- a/api/app/lib/controllers/patrolManage/patrolRecord.js +++ b/api/app/lib/controllers/patrolManage/patrolRecord.js @@ -596,7 +596,7 @@ function getPointInfo(opts) { rslt = rslt.filter(f => f) if (userInfo.username != 'SuperAdmin') { if (userInfo.structure) { - rslt = rslt.filter(s => userInfo.structure.find(x => x == s.project.userId)) + rslt = rslt.filter(s => userInfo.structure.find(x => x == s.projectId)) } else { rslt = [] } @@ -628,7 +628,7 @@ function getTemplate(opts){ rslt = rslt.filter(f => f) if (userInfo.username != 'SuperAdmin') { if (userInfo.structure) { - rslt = rslt.filter(s => userInfo.structure.find(x => x == s.project.userId)) + rslt = rslt.filter(s => userInfo.structure.find(x => x == s.project.id)) } else { rslt = [] } @@ -732,6 +732,31 @@ function getSubSystemPatrol(opts) { // } // } +//查询用户所有的巡检记录 +function getAllPatrol(opts) { + return async function (ctx, next) { + try{ + let rslt=[] + const models = ctx.fs.dc.models; + let userInfo = ctx.fs.api.userInfo; + rslt=await models.PatrolRecord.findAll() + rslt = rslt.filter(f => f) + if (userInfo.username != 'SuperAdmin') { + if (userInfo.structure) { + rslt = rslt.filter(s => userInfo.structure.find(x => x == s.projectId)) + } else { + rslt = [] + } + } + ctx.status=200 + ctx.body=rslt + }catch(error){ + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { message: '查询所有的巡检记录' } + } + } +} Array.prototype.group = function (callback, thisArg = null) { // 参数合法性判断 @@ -767,5 +792,6 @@ module.exports = { getPointInfo, getTemplate, reportQuest, - getSubSystemPatrol + getSubSystemPatrol, + getAllPatrol } \ No newline at end of file diff --git a/api/app/lib/routes/device/index.js b/api/app/lib/routes/device/index.js index a27e264..cf68edb 100644 --- a/api/app/lib/routes/device/index.js +++ b/api/app/lib/routes/device/index.js @@ -19,5 +19,8 @@ module.exports = function (app, router, opts, AuthCode) { app.fs.api.logAttr['GET/device'] = { content: '获取设备信息列表', visible: true }; router.get('/device', device.getDeviceList(opts)); + // 获取设备信息 + app.fs.api.logAttr['GET/devices'] = { content: '获取设备信息', visible: true }; + router.get('/devices', device.getDevices(opts)); }; diff --git a/api/app/lib/routes/patrolManage/patrolRecord.js b/api/app/lib/routes/patrolManage/patrolRecord.js index 8ddf3c5..c1b54f5 100644 --- a/api/app/lib/routes/patrolManage/patrolRecord.js +++ b/api/app/lib/routes/patrolManage/patrolRecord.js @@ -53,4 +53,8 @@ module.exports = function (app, router, opts) { // 查询子系统每日巡检 app.fs.api.logAttr['GET/subSystemPatrol/day'] = { content: '查询子系统每日巡检', visible: true }; router.get('/subSystemPatrol/day', patrolRecord.getSubSystemPatrol(opts)) + + // 查询所有的巡检记录 + app.fs.api.logAttr['GET/allPatrol'] = { content: '查询所有的巡检记录', visible: true }; + router.get('/allPatrol', patrolRecord.getAllPatrol(opts)) }; \ No newline at end of file diff --git a/weapp/package/deviceBigdataGraph/deviceBigdataGraph.js b/weapp/package/deviceBigdataGraph/deviceBigdataGraph.js index 74df8da..9a17c4a 100644 --- a/weapp/package/deviceBigdataGraph/deviceBigdataGraph.js +++ b/weapp/package/deviceBigdataGraph/deviceBigdataGraph.js @@ -1,5 +1,10 @@ // package/riskManagement/riskCalendar/riskCalendar.js import * as echarts from '../components/ec-canvas/echarts'; +import { + getAllPatrol,getDevices,getProjectList +} from "../../utils/getApiUrl"; +import { Request } from "../../common"; +const moment = require("../../utils/moment"); Page({ initECharts(option) { @@ -30,7 +35,11 @@ Page({ * 页面的初始数据 */ data: { - ec:{} + ec:{}, + dataList:[],//巡检记录的列表 + guaranteedRate:0,//过保率 + warrantyPeriod:0,//质保期 + projectList:[],//结构物列表 }, navigator(e) { wx.navigateTo({ @@ -38,8 +47,9 @@ Page({ }) }, navigatorToLifeWarning(e) { + const res=JSON.stringify(this.data.projectList.rows) wx.navigateTo({ - url: '/package/deviceBigdataGraph/lifeWarning/lifeWarning', + url: `/package/deviceBigdataGraph/lifeWarning/lifeWarning?arrayData=${encodeURIComponent(res)}`, }) }, /** @@ -119,6 +129,42 @@ Page({ }; that.initECharts(option); that.initDeviceECharts(optionDevice); + Request.get(getAllPatrol()).then(res=>{ + if(res){ + that.setData({dataList:res}) + const rslt=res.filter(item=>{ + console.log('dsadasda',item) + }) + console.log('resss',rslt) + }else{ + wx.hideLoading() + } + }) + Request.get(getProjectList()).then(res=>{ + if(res){ + that.setData({ + projectList:res + }) + }else{ + + } + }) + Request.get(getDevices()).then(res=>{ + if(res&&res.length){ + //总的 + const count=res.length + //过期的 + const guaranteedRate=res.filter(item=>moment(item.dateGuarantee).isBefore(moment()))?.length||0 + //没过期的 + const warrantyPeriod=res.filter(item=>moment(item.dateGuarantee).isAfter(moment()))?.length||0 + that.setData({ + guaranteedRate: Math.round((guaranteedRate/count)*100), + warrantyPeriod: Math.round((warrantyPeriod/count)*100), + }) + }else{ + + } + }) }, /** diff --git a/weapp/package/deviceBigdataGraph/deviceBigdataGraph.wxml b/weapp/package/deviceBigdataGraph/deviceBigdataGraph.wxml index 57a70a7..0a3f0d5 100644 --- a/weapp/package/deviceBigdataGraph/deviceBigdataGraph.wxml +++ b/weapp/package/deviceBigdataGraph/deviceBigdataGraph.wxml @@ -16,15 +16,15 @@ 过保比率: - - 50% + + {{guaranteedRate}}% 质保期比例: - - 50% + + {{warrantyPeriod?0:0}}% diff --git a/weapp/package/deviceBigdataGraph/lifeWarning/lifeWarning.js b/weapp/package/deviceBigdataGraph/lifeWarning/lifeWarning.js index 8c0c266..4bdd874 100644 --- a/weapp/package/deviceBigdataGraph/lifeWarning/lifeWarning.js +++ b/weapp/package/deviceBigdataGraph/lifeWarning/lifeWarning.js @@ -1,123 +1,216 @@ // package/deviceBigdataGraph/lifeWarning/lifeWarning.js import * as echarts from '../../components/ec-canvas/echarts'; -function setOption(chart, data) { +import { + getAllPatrol, + getDevices,getProjectList +} from "../../../utils/getApiUrl"; +import { + Request +} from "../../../common"; +const moment = require("../../../utils/moment"); + +function setOption(chart, seriesData, xData) { const option = { - grid: { - top: '5%', - left: '3%', - right: '4%', - bottom: '3%', - containLabel: true - }, - xAxis: { - type: 'category', - data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] - }, - yAxis: { - type: 'value', - }, - series: [ - { - data: data, - type: 'line' + grid: { + top: '5%', + left: '3%', + right: '4%', + bottom: '3%', + containLabel: true }, - ] + xAxis: { + type: 'category', + data: xData + }, + yAxis: { + type: 'value', + }, + series: [{ + data: seriesData, + type: 'line' + }, ] }; chart.setOption(option); - } +} Page({ - /** - * 页面的初始数据 - */ - data: { - ec: { - // onInit: initChart, - lazyLoad: true, // 将 lazyLoad 设为 true 后,需要手动初始化图表 - }, - isLoaded: false, - list: [1,2,3] - }, - initChart: function (data) { - this.ecComponent = this.selectComponent('#device-status-chart'); - this.ecComponent.init((canvas, width, height, dpr) => { - const chart = echarts.init(canvas, null, { - width: width, - height: height, - devicePixelRatio: dpr // new - }); - setOption(chart, data); - - // 将图表实例绑定到 this 上,可以在其他成员函数中访问 - this.chart = chart; - - this.setData({ - isLoaded: true, - }); - - // 注意这里一定要返回 chart 实例,否则会影响事件处理等 - return chart; - }); - }, - /** - * 生命周期函数--监听页面加载 - */ - onLoad(options) { - const {windowHeight}=wx.getSystemInfoSync() - const pageHeight=windowHeight - 48 - setTimeout(() => { - this.initChart([1,2,3,4,5,6]) - }, 1000) - const that = this - that.setData({pageHeight:pageHeight+'px'}) - }, - - /** - * 生命周期函数--监听页面初次渲染完成 - */ - onReady() { - - }, - - /** - * 生命周期函数--监听页面显示 - */ - onShow() { - - }, - - /** - * 生命周期函数--监听页面隐藏 - */ - onHide() { - - }, - - /** - * 生命周期函数--监听页面卸载 - */ - onUnload() { - - }, - - /** - * 页面相关事件处理函数--监听用户下拉动作 - */ - onPullDownRefresh() { - - }, - - /** - * 页面上拉触底事件的处理函数 - */ - onReachBottom() { - - }, - - /** - * 用户点击右上角分享 - */ - onShareAppMessage() { - - } + /** + * 页面的初始数据 + */ + data: { + ec: { + // onInit: initChart, + lazyLoad: true, // 将 lazyLoad 设为 true 后,需要手动初始化图表 + }, + isLoaded: false, + list: [1, 2, 3], + count: 0, //总设备数 + guaranteedRate: 0, //过保率 + warrantyPeriod: 0, //质保期 + next30days: [], //未来30天过期的设备列表 + }, + initChart: function (seriesData, xData) { + this.ecComponent = this.selectComponent('#device-status-chart'); + this.ecComponent.init((canvas, width, height, dpr) => { + const chart = echarts.init(canvas, null, { + width: width, + height: height, + devicePixelRatio: dpr // new + }); + setOption(chart, seriesData, xData); + + // 将图表实例绑定到 this 上,可以在其他成员函数中访问 + this.chart = chart; + + this.setData({ + isLoaded: true, + }); + + // 注意这里一定要返回 chart 实例,否则会影响事件处理等 + return chart; + }); + }, + /** + * 生命周期函数--监听页面加载 + */ + onLoad(options) { + const projectList=decodeURIComponent(options.arrayData) + const complexArray = JSON.parse(projectList); + const { + windowHeight + } = wx.getSystemInfoSync() + const pageHeight = windowHeight - 48 + const that = this + that.setData({ + pageHeight: pageHeight + 'px' + }) + Request.get(getDevices()).then(res => { + if (res && res.length) { + // 获取当前日期 + const currentDate = new Date(); + // 计算 30 天后的日期 + const thirtyDaysLater = new Date(currentDate); + thirtyDaysLater.setDate(thirtyDaysLater.getDate() + 30); + // 计算半年后的日期 + const sixMonthsLater = new Date(); + sixMonthsLater.setMonth(sixMonthsLater.getMonth() + 6); + // 初始化每个月的设备计数数组 + const monthlyCounts = new Array(6).fill(0); + // 创建日期范围 + const dateRange = []; + //30天内过期设备列表 + const expiringDevices = []; + for (let i = 0; i < 6; i++) { + const startOfMonth = new Date(currentDate.getFullYear(), currentDate.getMonth() + i, 1); + dateRange.push({ + start: startOfMonth, + end: new Date(startOfMonth.getFullYear(), startOfMonth.getMonth() + 1, 0) + }); + } + // 遍历设备列表 + res.forEach((device) => { + const guaranteeDate = new Date(device.dateGuarantee); + if (guaranteeDate >= currentDate && guaranteeDate <= thirtyDaysLater) { + const pointDevices = device.pointDevices; + pointDevices.forEach((pointDevice) => { + const point = pointDevice.point; + // 查找匹配项目 + const project = complexArray.find((project) => project.id === point.projectId); + if (project) { + device.project = project; + } + }); + expiringDevices.push(device); + } + // 检查设备的 dateGuarantee 是否在日期范围内 + for (let i = 0; i < dateRange.length; i++) { + if (guaranteeDate >= dateRange[i].start && guaranteeDate <= dateRange[i].end) { + // 设备在当前月内到期 + monthlyCounts[i]++; + break; // 结束循环,不需要继续检查其他月份 + } + } + }); + const xAxisLabels = []; + // 生成未来六个月的月份 + for (let i = 0; i < 6; i++) { + // const nextMonth = new Date(currentDate.getFullYear(), currentDate.getMonth() + i, 1); + // const year = nextMonth.getFullYear(); + // const month = String(nextMonth.getMonth() + 1).padStart(2, '0'); // 月份格式化为两位数 + // const label = `${year}-${month}`; + // xAxisLabels.push(label); + const nextMonth = new Date(currentDate.getFullYear(), currentDate.getMonth() + i, 1); + const month = nextMonth.toLocaleDateString('en-US', { + month: 'short' + }); // 获取月份的缩写 + xAxisLabels.push(month); + } + //过期的 + const guaranteedRate = res.filter(item => moment(item.dateGuarantee).isBefore(moment()))?.length || 0 + //没过期的 + const warrantyPeriod = res.filter(item => moment(item.dateGuarantee).isAfter(moment()))?.length || 0 + that.setData({ + count: res.length, + guaranteedRate: guaranteedRate, + warrantyPeriod: warrantyPeriod, + next30days:expiringDevices + }) + setTimeout(() => { + this.initChart(monthlyCounts, xAxisLabels) + }, 1000) + } else { + + } + }) + + }, + + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady() { + + }, + + /** + * 生命周期函数--监听页面显示 + */ + onShow() { + + }, + + /** + * 生命周期函数--监听页面隐藏 + */ + onHide() { + + }, + + /** + * 生命周期函数--监听页面卸载 + */ + onUnload() { + + }, + + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh() { + + }, + + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom() { + + }, + + /** + * 用户点击右上角分享 + */ + onShareAppMessage() { + + } }) \ No newline at end of file diff --git a/weapp/package/deviceBigdataGraph/lifeWarning/lifeWarning.wxml b/weapp/package/deviceBigdataGraph/lifeWarning/lifeWarning.wxml index a85595e..907349f 100644 --- a/weapp/package/deviceBigdataGraph/lifeWarning/lifeWarning.wxml +++ b/weapp/package/deviceBigdataGraph/lifeWarning/lifeWarning.wxml @@ -8,18 +8,18 @@ 设备总数 - 300个 + {{count}}个 过保个数 - {{86}} + {{guaranteedRate}} 质保个数 - {{300}} + {{warrantyPeriod}} @@ -46,43 +46,25 @@ - 30天内你有1000个设备即将过保,请及时更换设备 + 30天内你有{{next30days.length}}个设备即将过保,请及时更换设备 - + - 设备A + {{item.name}} 所属结构物 - 管廊A + {{item.project.name}} 安装时间 - 2022-02-11 + {{item.dateInstall}} 质保期 - 2022-02-11 - - - - - - 设备A - - - 所属结构物 - 管廊A - - - 安装时间 - 2022-02-11 - - - 质保期 - 2022-02-11 + {{item.dateGuarantee}} diff --git a/weapp/package/report/report.js b/weapp/package/report/report.js index edb5c7f..ba3b910 100644 --- a/weapp/package/report/report.js +++ b/weapp/package/report/report.js @@ -245,7 +245,7 @@ Page({ } } const { id, name, departmentId, deptName } = wx.getStorageSync('userInfo'); - const curPlan = that.data.planList.find(item=>item.id=patrolTemplate[patrolTemplateIndex].id) + const curPlan = that.data.planList.find(item=>item.id==patrolTemplate[patrolTemplateIndex].id) const nextItemData = curPlan.points.find(p => p.id == this.data.scenePointId) const aboutSend=templateData.find(item=>item.patrolTemplate.id===patrolTemplate[patrolTemplateIndex].id) let datas = { diff --git a/weapp/pages/home/home.js b/weapp/pages/home/home.js index 830617a..95badc7 100644 --- a/weapp/pages/home/home.js +++ b/weapp/pages/home/home.js @@ -90,7 +90,8 @@ Page({ ] }; wx.showLoading({ title: '加载中' }) - promiseArr.push(Request.get(getPatrolRecord('all', moment('1970-1-1').format('YYYY-MM-DD') + ' 00:00:00', moment('2099-12-31').format('YYYY-MM-DD') + ' 23:59:59', 'null', 'null'))); + const date1 = new Date('1970-01-01 00:00:00'); + promiseArr.push(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'))); Promise.all(promiseArr).then(res => { wx.hideLoading() //与自己相关的所有巡检记录 diff --git a/weapp/utils/getApiUrl.js b/weapp/utils/getApiUrl.js index b2f53b4..0ed7925 100644 --- a/weapp/utils/getApiUrl.js +++ b/weapp/utils/getApiUrl.js @@ -43,10 +43,18 @@ exports.reportQuest = () => { exports.getPatrolRecord = (patrolPlanId, startTime, endTime, alarm, pointId) => { return `/patrolRecord/${patrolPlanId}/${startTime}/${endTime}/${alarm}/${pointId}` } +exports.getAllPatrol = () => { + return `/allPatrol` +} +//设备 +exports.getDevices = () => { + return `/devices` +} + + //获取子系统的巡检记录 exports.getSubSystemPatrolAbout = (query) => { const { STime, ETime,keywords } = query; - return `/patrolRecord/subSystemPatrolAbout?STime=${STime}&ETime=${ETime}&keywords=${keywords}` }