zhaobing’ 1 year ago
parent
commit
9327445c87
  1. 44
      api/app/lib/controllers/patrolManage/patrolRecord.js
  2. 4
      api/app/lib/routes/patrolManage/patrolRecord.js
  3. 108
      weapp/package/subSystem/dayPatrolInfo/dayPatrolInfo.js
  4. 11
      weapp/package/subSystem/dayPatrolInfo/dayPatrolInfo.wxml
  5. 3
      weapp/package/subSystem/subSystem.js
  6. 2
      weapp/package/subSystem/subSystem.wxml
  7. 5
      weapp/utils/getApiUrl.js

44
api/app/lib/controllers/patrolManage/patrolRecord.js

@ -685,6 +685,47 @@ function reportQuest(opts){
} }
} }
// 查询子系统每日巡检
function getSubSystemPatrol(opts) {
return async function (ctx, next) {
try {
let rslt = {
dayPatrolPlan: [], // 当日需要巡检的巡检计划
};
const models = ctx.fs.dc.models;
const { day, subType } = ctx.query;
let userInfo = ctx.fs.api.userInfo;
let projectWhere = { subType };
if (userInfo.username !== 'SuperAdmin') {
if (userInfo.structure) {
projectWhere.id = { $in: userInfo.structure };
} else {
projectWhere.id = { $in: [] };
}
}
rslt.dayPatrolPlan = await models.PatrolPlan.findAll({
where: {
startTime: { $lte: day + ' 23:59:59' },
endTime: { $gte: day + ' 00:00:00' }
},
include: [{
attributes: ['id', 'name'],
model: models.Project,
where: projectWhere,
}],
});
ctx.status = 200;
ctx.body = rslt;
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = { message: '查询子系统每日巡检失败' }
}
}
}
//根据子系统查询点位信息 //根据子系统查询点位信息
// function getPointInfo(opts) { // function getPointInfo(opts) {
// return async function (ctx, next){ // return async function (ctx, next){
@ -725,5 +766,6 @@ module.exports = {
getPatrolRecordStatistic, getPatrolRecordStatistic,
getPointInfo, getPointInfo,
getTemplate, getTemplate,
reportQuest reportQuest,
getSubSystemPatrol
} }

4
api/app/lib/routes/patrolManage/patrolRecord.js

@ -49,4 +49,8 @@ module.exports = function (app, router, opts) {
//查询模板 //查询模板
app.fs.api.logAttr['POST/patrolRecord/reportQuest'] = { content: '上报问题', visible: true }; app.fs.api.logAttr['POST/patrolRecord/reportQuest'] = { content: '上报问题', visible: true };
router.post('/patrolRecord/reportQuest', patrolRecord.reportQuest(opts)) router.post('/patrolRecord/reportQuest', patrolRecord.reportQuest(opts))
// 查询子系统每日巡检
app.fs.api.logAttr['GET/subSystemPatrol/day'] = { content: '查询子系统每日巡检', visible: true };
router.get('/subSystemPatrol/day', patrolRecord.getSubSystemPatrol(opts))
}; };

108
weapp/package/subSystem/dayPatrolInfo/dayPatrolInfo.js

@ -1,5 +1,8 @@
// package/subSystem/dayPatrolInfo/dayPatrolInfo.js // package/subSystem/dayPatrolInfo/dayPatrolInfo.js
import * as echarts from '../../components/ec-canvas/echarts'; import * as echarts from '../../components/ec-canvas/echarts';
import { getSubSystemPatrol, getSubSystemPatrolAbout } from "../../../utils/getApiUrl";
import { Request } from "../../../common";
import moment from '../../../utils/moment';
const setPieOptions = ((chart, data) => { const setPieOptions = ((chart, data) => {
const option = { const option = {
@ -42,6 +45,9 @@ Page({
data: { data: {
needEc: { lazyLoad: true }, needEc: { lazyLoad: true },
alreadyEc: { lazyLoad: true }, alreadyEc: { lazyLoad: true },
dayIssues: [], // 今日问题分布
needInspectCount: 0, // 今日待检总次数
inspectedCount: 0, // 今日已检总次数
}, },
// 今日待检分布图表 // 今日待检分布图表
@ -50,45 +56,115 @@ Page({
const chart = echarts.init(canvas, null, { const chart = echarts.init(canvas, null, {
width: width, width: width,
height: height, height: height,
devicePixelRatio: dpr // new devicePixelRatio: dpr
}); });
setPieOptions(chart, data) setPieOptions(chart, data)
return chart; return chart;
}); });
}, },
// 今日已检分布图表 // 今日已检分布图表
initAlreadyChart: function (data) { initAlreadyChart: function (data) {
this.alreadyEcComponent.init((canvas, width, height, dpr) => { this.alreadyEcComponent.init((canvas, width, height, dpr) => {
const chart = echarts.init(canvas, null, { const chart = echarts.init(canvas, null, {
width: width, width: width,
height: height, height: height,
devicePixelRatio: dpr // new devicePixelRatio: dpr
}); });
setPieOptions(chart, data) setPieOptions(chart, data)
return chart; return chart;
}); });
}, },
getData() {
const promiseArr = [
Request.get(getSubSystemPatrol(this.day, this.subType)),
Request.get(getSubSystemPatrolAbout({
STime: moment().startOf('month').format('YYYY-MM-DD HH:mm:ss'),
ETime: moment().endOf('month').format('YYYY-MM-DD HH:mm:ss'),
keywords: this.subType,
})),
]
Promise.all(promiseArr).then(([subSystemPatrol, patrolRecord]) => {
let dayRecord = patrolRecord.filter(r => moment(r.inspectionTime).isSame(this.day, 'day')); // 今日巡检记录
let dayAlarmRecord = dayRecord.filter(r => r.alarm); // 今日异常记录
// 今日问题分布
let nextDayIssues = [];
const colors = ['#1684FF', '#DF6F6F', '#DF9B6F', '#DFBC6F'];
dayAlarmRecord.forEach((record, index) => {
const dayIndex = nextDayIssues.findIndex(d => d.pointName === record.points.itemData.name);
if (dayIndex === -1) {
nextDayIssues.push({
pointName: record.points.itemData.name,
count: 1,
color: colors[index % colors.length],
});
} else {
nextDayIssues[dayIndex].count += 1;
}
});
const total = nextDayIssues.reduce((accumulator, currentValue) => accumulator + currentValue.count, 0);
nextDayIssues = nextDayIssues.map(d => ({ ...d, percent: Math.round((d.count / total) * 100) }));
// 今日已巡分布
let inspectedPoints = [];
dayRecord.forEach((record) => {
const dayIndex = inspectedPoints.findIndex(d => d.name === record.points.itemData.name);
if (dayIndex === -1) {
inspectedPoints.push({
name: record.points.itemData.name,
value: 1,
});
} else {
inspectedPoints[dayIndex].value += 1;
}
})
this.inspectedPoints = inspectedPoints;
// 今日待检分布
// let needInspectPoints = [];
// subSystemPatrol.dayPatrolPlan.forEach((plan) => {
// const unit = plan.frequency.split('/')[1];
// const frequency = plan.frequency.split('/')[0];
// let record = [...patrolRecord];
// switch (unit) {
// case '周':
// record = patrolRecord.filter(r => moment(r.inspectionTime).isSame(this.day, 'day'));
// break;
// case '天':
// record = patrolRecord.filter(r => moment(r.inspectionTime).isSame(this.day, 'day'));
// break;
// default:
// break;
// }
// })
this.initAlreadyChart(inspectedPoints)
this.setData({
dayIssues: nextDayIssues,
inspectedCount: inspectedPoints.reduce((accumulator, currentValue) => accumulator + currentValue.value, 0),
})
})
},
/** /**
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onLoad(options) { onLoad(options) {
wx.setNavigationBarTitle({ title: options.day }) wx.setNavigationBarTitle({ title: options.day })
this.day = options.day;
this.subType = options.subType;
this.getData();
setTimeout(() => { setTimeout(() => {
this.initNeedChart([ this.initNeedChart([
{ value: 1048, name: 'Search Engine' }, { value: 1048, name: '点位1' },
{ value: 735, name: 'Direct' }, { value: 735, name: '点位2' },
{ value: 580, name: 'Email' }, { value: 580, name: '点位3' },
{ value: 580, name: 'Email2' }, { value: 580, name: '点位4' },
{ value: 580, name: 'Email3' }, { value: 580, name: '点位5' },
])
this.initAlreadyChart([
{ value: 1048, name: 'Search Engine' },
{ value: 735, name: 'Direct' },
{ value: 580, name: 'Email' },
{ value: 580, name: 'Email2' },
{ value: 580, name: 'Email3' },
]) ])
}, 1000) }, 1000)
}, },

11
weapp/package/subSystem/dayPatrolInfo/dayPatrolInfo.wxml

@ -8,11 +8,12 @@
</view> </view>
<image src="/images/right_card_bg.png" class="card-bg" /> <image src="/images/right_card_bg.png" class="card-bg" />
</view> </view>
<view wx:for="{{[1,2,3,4]}}" class="problem-box flex"> <view wx:for="{{dayIssues}}" class="problem-box flex">
<view class="problem-title text---">类型1:</view> <view class="problem-title text---">{{item.pointName}}</view>
<progress <progress
style="width: 70%;" style="width: 70%;"
percent="{{80}}" percent="{{item.percent}}"
activeColor="{{item.color}}"
stroke-width="8" stroke-width="8"
show-info show-info
font-size="14" font-size="14"
@ -26,7 +27,7 @@
<image class="card-icon" src="/images/right_icon.png" /> <image class="card-icon" src="/images/right_icon.png" />
<view class="title">今日待检分布</view> <view class="title">今日待检分布</view>
</view> </view>
<view class="card-right">总次数:{{50}}次</view> <view class="card-right">总次数:{{needInspectCount}}次</view>
<image src="/images/right_card_bg.png" class="card-bg" /> <image src="/images/right_card_bg.png" class="card-bg" />
</view> </view>
<view class="pie-chart-box"> <view class="pie-chart-box">
@ -39,7 +40,7 @@
<image class="card-icon" src="/images/right_icon.png" /> <image class="card-icon" src="/images/right_icon.png" />
<view class="title">今日已检分布</view> <view class="title">今日已检分布</view>
</view> </view>
<view class="card-right">总次数:{{50}}次</view> <view class="card-right">总次数:{{inspectedCount}}次</view>
<image src="/images/right_card_bg.png" class="card-bg" /> <image src="/images/right_card_bg.png" class="card-bg" />
</view> </view>
<view class="pie-chart-box"> <view class="pie-chart-box">

3
weapp/package/subSystem/subSystem.js

@ -70,7 +70,7 @@ Page({
onDateSelect(e) { onDateSelect(e) {
wx.navigateTo({ wx.navigateTo({
url: `/package/subSystem/dayPatrolInfo/dayPatrolInfo?day=${moment(e.detail).format('YYYY-MM-DD')}`, url: `/package/subSystem/dayPatrolInfo/dayPatrolInfo?day=${moment(e.detail).format('YYYY-MM-DD')}&subType=${this.subType}`,
}) })
}, },
@ -78,6 +78,7 @@ Page({
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onLoad: function (options) { onLoad: function (options) {
this.subType = options.key
const {windowHeight}=wx.getSystemInfoSync() const {windowHeight}=wx.getSystemInfoSync()
const pageHeight=windowHeight - 48 const pageHeight=windowHeight - 48
const that=this const that=this

2
weapp/package/subSystem/subSystem.wxml

@ -36,6 +36,6 @@
<image src="/images/shape2.png" class="imgStyle"></image> <image src="/images/shape2.png" class="imgStyle"></image>
<view class="yearMonth">{{currentYear+'年'+currentMonth+'月'}}</view> <view class="yearMonth">{{currentYear+'年'+currentMonth+'月'}}</view>
</view> </view>
<van-calendar max-date="{{lastDay}}" v-model="selectedDate" show-title="{{false}}" show-subtitle="{{false}}" poppable="{{ false }}" show-confirm="{{ false }}" default-date="{{selectedDate}}" formatter="{{formatter}}" bind:select="onDateSelect" color="#0000FF" class="calendar" /> <van-calendar min-date="{{firstDay}}" max-date="{{lastDay}}" v-model="selectedDate" show-title="{{false}}" show-subtitle="{{false}}" poppable="{{ false }}" show-confirm="{{ false }}" default-date="{{selectedDate}}" formatter="{{formatter}}" bind:select="onDateSelect" color="#0000FF" class="calendar" />
</view> </view>
</view> </view>

5
weapp/utils/getApiUrl.js

@ -102,3 +102,8 @@ exports.getPatrolReport = (query) => {
exports.getPatrolRecordStatistic = (structures) => { exports.getPatrolRecordStatistic = (structures) => {
return `/patrolRecord/statistic?structures=${structures}` return `/patrolRecord/statistic?structures=${structures}`
} }
// 查询子系统每日巡检
exports.getSubSystemPatrol = (day, subType) => {
return `/subSystemPatrol/day?day=${day}&subType=${subType}`
}
Loading…
Cancel
Save