|
|
@ -96,9 +96,50 @@ async function addRecord (ctx) { |
|
|
|
const params = ctx.request.body |
|
|
|
const { solvingTime, occurrencTime, sketch, record, settler, type, id, msg, files } = params |
|
|
|
const breakTime = (Date.parse(solvingTime) - Date.parse(occurrencTime)) / 1000 |
|
|
|
let message = `${msg}失败` |
|
|
|
try { |
|
|
|
//中断时长
|
|
|
|
//console.log('resss1', Date.parse(solvingTime), occurrencTime)
|
|
|
|
const areArraysEqual = (arr1, arr2) => { |
|
|
|
// 首先检查两个数组的长度是否相同
|
|
|
|
if (arr1.length !== arr2.length) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
// 遍历第一个数组的每个元素
|
|
|
|
return arr1.every(function (element) { |
|
|
|
// 检查第二个数组是否包含当前元素
|
|
|
|
return arr2.includes(element); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
const findOne = await models.MaintenanceRecord.findOne({ |
|
|
|
where: { |
|
|
|
solvingTime: solvingTime, |
|
|
|
occurrenceTime: occurrencTime, |
|
|
|
sketch: sketch, |
|
|
|
record: record, |
|
|
|
type: type, |
|
|
|
}, |
|
|
|
include: [{ |
|
|
|
attributes: ['id', 'maintenanceRecordId', 'pepUserId'], |
|
|
|
model: models.MaintenanceRecordExecuteUser, |
|
|
|
where: { |
|
|
|
pepUserId: { $in: settler } |
|
|
|
} |
|
|
|
}] |
|
|
|
}) |
|
|
|
|
|
|
|
if (id && findOne && findOne.id !== id && areArraysEqual(findOne.files.map(v => v.name), files.map(v => v.name))) { |
|
|
|
message = '已有相同的一条数据' |
|
|
|
throw '' |
|
|
|
} else if (!id && findOne && areArraysEqual(findOne.files.map(v => v.name), files.map(v => v.name))) { |
|
|
|
message = '已有相同的一条数据' |
|
|
|
throw '' |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (id) { |
|
|
|
await models.MaintenanceRecord.update({ |
|
|
|
solvingTime, occurrenceTime: occurrencTime, sketch, record, settler, type, interruptDuration: breakTime, files: files |
|
|
@ -129,7 +170,7 @@ async function addRecord (ctx) { |
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|
|
|
ctx.status = 400; |
|
|
|
ctx.body = { |
|
|
|
message: `${msg}失败` |
|
|
|
message: message |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|