From b8fb7c15dab56cc4e98a312ee69ec9c1c11b570b Mon Sep 17 00:00:00 2001 From: liujiangyong Date: Mon, 20 Mar 2023 18:04:44 +0800 Subject: [PATCH] fix bug --- .../controllers/patrolManage/patrolPlan.js | 19 +++++++++++++----- .../controllers/patrolManage/patrolRecord.js | 20 ++++++++++++++----- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/api/app/lib/controllers/patrolManage/patrolPlan.js b/api/app/lib/controllers/patrolManage/patrolPlan.js index 9678b68..a527643 100644 --- a/api/app/lib/controllers/patrolManage/patrolPlan.js +++ b/api/app/lib/controllers/patrolManage/patrolPlan.js @@ -100,12 +100,21 @@ async function updatePatrolPlan (ctx, next) { }); const groupRecord = curPlanRecord.group(({ pointId }) => pointId); let isComplete = true; - points.forEach(p => { - if (!groupRecord[p.id] || groupRecord[p.id].length < frequencyNum) { - isComplete = false; - return; + for (const p of points) { + if (!groupRecord[p.id]) { + if (points.length === 1 && frequencyNum === 1) { + continue; + } else { + isComplete = false; + continue; + } + } else { + if ((groupRecord[p.id].length) < frequencyNum) { + isComplete = false; + continue; + } } - }); + } let plan = { name, way, structureId, startTime, endTime, frequency, points, templateId, nextTime: isComplete ? eTime.format() : sTime.format() diff --git a/api/app/lib/controllers/patrolManage/patrolRecord.js b/api/app/lib/controllers/patrolManage/patrolRecord.js index 3833aac..4dcf503 100644 --- a/api/app/lib/controllers/patrolManage/patrolRecord.js +++ b/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 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; + for (const p of curPatrolPlan.points) { + if (!groupRecord[p.id]) { + if (curPatrolPlan.points.length === 1 && frequency === 1) { + continue; + } else { + isComplete = false; + 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() }, { where: { id: patrolPlanId }, transaction