|
@ -238,8 +238,15 @@ async function addPatrolRecord (ctx, next) { |
|
|
const sTime = moment().startOf(unit === '天' ? 'day' : unit === '周' ? 'isoWeek' : 'month'); |
|
|
const sTime = moment().startOf(unit === '天' ? 'day' : unit === '周' ? 'isoWeek' : 'month'); |
|
|
const eTime = moment().endOf(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); |
|
|
const filterRecord = curPlanRecord.rows.filter(r => moment(r.inspectionTime).diff(sTime) >= 0 && moment(r.inspectionTime).diff(eTime) <= 0); |
|
|
|
|
|
const groupRecord = filterRecord.group(({ pointId }) => pointId); |
|
|
await models.PatrolPlan.update({ patrolCount, nextTime: filterRecord.length + 1 >= frequency ? eTime.format() : sTime.format() }, { |
|
|
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 }, |
|
|
where: { id: patrolPlanId }, |
|
|
transaction |
|
|
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 = { |
|
|
module.exports = { |
|
|
findPatrolRecord, |
|
|
findPatrolRecord, |
|
|