Browse Source

fix bug

master
liujiangyong 2 years ago
parent
commit
b8fb7c15da
  1. 17
      api/app/lib/controllers/patrolManage/patrolPlan.js
  2. 18
      api/app/lib/controllers/patrolManage/patrolRecord.js

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

@ -100,12 +100,21 @@ async function updatePatrolPlan (ctx, next) {
}); });
const groupRecord = curPlanRecord.group(({ pointId }) => pointId); const groupRecord = curPlanRecord.group(({ pointId }) => pointId);
let isComplete = true; let isComplete = true;
points.forEach(p => { for (const p of points) {
if (!groupRecord[p.id] || groupRecord[p.id].length < frequencyNum) { if (!groupRecord[p.id]) {
if (points.length === 1 && frequencyNum === 1) {
continue;
} else {
isComplete = false; isComplete = false;
return; continue;
}
} else {
if ((groupRecord[p.id].length) < frequencyNum) {
isComplete = false;
continue;
}
}
} }
});
let plan = { name, way, structureId, startTime, endTime, frequency, points, templateId, let plan = { name, way, structureId, startTime, endTime, frequency, points, templateId,
nextTime: isComplete ? eTime.format() : sTime.format() nextTime: isComplete ? eTime.format() : sTime.format()

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

@ -240,12 +240,22 @@ async function addPatrolRecord(ctx, next) {
const filterRecord = curPlanRecord.rows.filter(r => moment(r.inspectionTime).diff(sTime) >= 0 && moment(r.inspectionTime).diff(eTime) <= 0); const filterRecord = curPlanRecord.rows.filter(r => moment(r.inspectionTime).diff(sTime) >= 0 && moment(r.inspectionTime).diff(eTime) <= 0);
const groupRecord = filterRecord.group(({ pointId }) => pointId); const groupRecord = filterRecord.group(({ pointId }) => pointId);
let isComplete = true; let isComplete = true;
curPatrolPlan.points.forEach(p => { for (const p of curPatrolPlan.points) {
if (!groupRecord[p.id] || (pointId === p.id ? groupRecord[p.id].length + 1 : groupRecord[p.id].length) < frequency) { if (!groupRecord[p.id]) {
if (curPatrolPlan.points.length === 1 && frequency === 1) {
continue;
} else {
isComplete = false; isComplete = false;
return; continue;
} }
}); } else {
if ((pointId === p.id ? groupRecord[p.id].length + 1 : groupRecord[p.id].length) < frequency) {
isComplete = false;
continue;
}
}
}
await models.PatrolPlan.update({ patrolCount, nextTime: isComplete ? eTime.format() : sTime.format() }, { await models.PatrolPlan.update({ patrolCount, nextTime: isComplete ? eTime.format() : sTime.format() }, {
where: { id: patrolPlanId }, where: { id: patrolPlanId },
transaction transaction

Loading…
Cancel
Save