Browse Source

待巡检按点位统计

master
liujiangyong 2 years ago
parent
commit
29154e835e
  1. 30
      api/app/lib/controllers/patrolManage/patrolPlan.js
  2. 30
      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,

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

@ -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
})
@ -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