|
|
@ -20,7 +20,7 @@ async function getRecord (ctx) { |
|
|
|
}) |
|
|
|
let recordRes = await models.MaintenanceRecord.findAndCountAll({ |
|
|
|
order: [['id', 'DESC']], |
|
|
|
attributes: ['id', 'sketch', 'occurrenceTime', 'solvingTime', 'interruptDuration', 'type', 'record','files'], |
|
|
|
attributes: ['id', 'sketch', 'occurrenceTime', 'solvingTime', 'interruptDuration', 'type', 'record', 'files'], |
|
|
|
offset: (pageIndex - 1) * pageSize, |
|
|
|
limit: pageSize, |
|
|
|
where: { |
|
|
@ -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 |
|
|
@ -111,7 +152,7 @@ async function addRecord (ctx) { |
|
|
|
}) |
|
|
|
await models.MaintenanceRecordExecuteUser.bulkCreate(resArry) |
|
|
|
} else { |
|
|
|
const aa = await models.MaintenanceRecord.create({ solvingTime, occurrenceTime: occurrencTime, sketch, record, settler, type, interruptDuration: breakTime,files: files }) |
|
|
|
const aa = await models.MaintenanceRecord.create({ solvingTime, occurrenceTime: occurrencTime, sketch, record, settler, type, interruptDuration: breakTime, files: files }) |
|
|
|
const recordId = aa.id |
|
|
|
const resArry = settler.map((item) => { |
|
|
|
return { |
|
|
@ -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 |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|