Browse Source

待巡检按点位统计

master
liujiangyong 2 years ago
parent
commit
29154e835e
  1. 30
      api/app/lib/controllers/patrolManage/patrolPlan.js
  2. 46
      api/app/lib/controllers/patrolManage/patrolRecord.js

30
api/app/lib/controllers/patrolManage/patrolPlan.js

@ -98,9 +98,17 @@ async function updatePatrolPlan (ctx, next) {
inspectionTime: { $between: [sTime.format(), eTime.format()] },
}
});
const groupRecord = curPlanRecord.group(({ pointId }) => pointId);
let isComplete = true;
points.forEach(p => {
if (!groupRecord[p.id] || groupRecord[p.id].length < frequencyNum) {
isComplete = false;
return;
}
});
let plan = { name, way, structureId, startTime, endTime, frequency, points, templateId,
nextTime: curPlanRecord.length >= frequencyNum ? eTime.format() : sTime.format()
nextTime: isComplete ? eTime.format() : sTime.format()
};
if (data && data.id) {
@ -174,6 +182,26 @@ async function delPatrolPlan (ctx, next) {
}
}
Array.prototype.group = function (callback, thisArg = null) {
// 参数合法性判断
if (typeof callback !== "function") {
throw new TypeError(`${callback} is not a function`);
}
const arr = this;
const length = this.length;
const grouper = Object.create(null);
for (let i = 0; i < length; i++) {
const key = callback.call(thisArg, arr[i], i, arr)
if (!grouper[key]) {
grouper[key] = [arr[i]]
} else {
grouper[key].push(arr[i])
}
}
return grouper;
};
module.exports = {
getPatrolPlan,
createPatrolPlan,

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

@ -2,7 +2,7 @@
const moment = require("moment");
async function findPatrolRecord (ctx, next) {
async function findPatrolRecord(ctx, next) {
let rslt = [];
let error = { name: 'FindError', message: '获取巡检记录失败' };
try {
@ -142,7 +142,7 @@ async function findPatrolRecord (ctx, next) {
}
}
async function findPatrolRecordUnlicensed (ctx, next) {
async function findPatrolRecordUnlicensed(ctx, next) {
let rslt = [];
let error = { name: 'FindError', message: '获取巡检记录失败' };
try {
@ -166,7 +166,7 @@ async function findPatrolRecordUnlicensed (ctx, next) {
}
}
async function findPointCurPatrolRecord (ctx, next) {
async function findPointCurPatrolRecord(ctx, next) {
let rslt = [];
let error = { name: 'FindError', message: '获取巡检记录失败' };
try {
@ -189,7 +189,7 @@ async function findPointCurPatrolRecord (ctx, next) {
}
}
async function addPatrolRecord (ctx, next) {
async function addPatrolRecord(ctx, next) {
let error = { name: 'addError', message: '新增巡检记录失败' };
const transaction = await ctx.fs.dc.orm.transaction();
try {
@ -238,8 +238,15 @@ async function addPatrolRecord (ctx, next) {
const sTime = moment().startOf(unit === '天' ? 'day' : unit === '周' ? 'isoWeek' : 'month');
const eTime = moment().endOf(unit === '天' ? 'day' : unit === '周' ? 'isoWeek' : 'month');
const filterRecord = curPlanRecord.rows.filter(r => moment(r.inspectionTime).diff(sTime) >= 0 && moment(r.inspectionTime).diff(eTime) <= 0);
await models.PatrolPlan.update({ patrolCount, nextTime: filterRecord.length + 1 >= frequency ? eTime.format() : sTime.format() }, {
const groupRecord = filterRecord.group(({ pointId }) => pointId);
let isComplete = true;
curPatrolPlan.points.forEach(p => {
if (!groupRecord[p.id] || (pointId === p.id ? groupRecord[p.id].length + 1 : groupRecord[p.id].length) < frequency) {
isComplete = false;
return;
}
});
await models.PatrolPlan.update({ patrolCount, nextTime: isComplete ? eTime.format() : sTime.format() }, {
where: { id: patrolPlanId },
transaction
})
@ -257,7 +264,7 @@ async function addPatrolRecord (ctx, next) {
}
}
async function getPatrolRecordIssueHandle (ctx) {
async function getPatrolRecordIssueHandle(ctx) {
try {
const { models } = ctx.fs.dc;
const { userId, userInfo } = ctx.fs.api
@ -330,7 +337,7 @@ async function getPatrolRecordIssueHandle (ctx) {
}
}
async function getPatrolRecordIssueHandleById (ctx) {
async function getPatrolRecordIssueHandleById(ctx) {
try {
const { models } = ctx.fs.dc;
const { id } = ctx.params
@ -356,7 +363,7 @@ async function getPatrolRecordIssueHandleById (ctx) {
}
// 新建维修处理计划成功
function addPatrolRecordIssueHandle (opts) {
function addPatrolRecordIssueHandle(opts) {
return async function (ctx, next) {
const models = ctx.fs.dc.models;
@ -375,7 +382,7 @@ function addPatrolRecordIssueHandle (opts) {
// 修改维修处理计划
function editPatrolRecordIssueHandle (opts) {
function editPatrolRecordIssueHandle(opts) {
return async function (ctx, next) {
try {
@ -396,6 +403,25 @@ function editPatrolRecordIssueHandle (opts) {
}
}
Array.prototype.group = function (callback, thisArg = null) {
// 参数合法性判断
if (typeof callback !== "function") {
throw new TypeError(`${callback} is not a function`);
}
const arr = this;
const length = this.length;
const grouper = Object.create(null);
for (let i = 0; i < length; i++) {
const key = callback.call(thisArg, arr[i], i, arr)
if (!grouper[key]) {
grouper[key] = [arr[i]]
} else {
grouper[key].push(arr[i])
}
}
return grouper;
};
module.exports = {
findPatrolRecord,

Loading…
Cancel
Save