diff --git a/api/app/lib/controllers/record/index.js b/api/app/lib/controllers/record/index.js index 480188c..2006c02 100644 --- a/api/app/lib/controllers/record/index.js +++ b/api/app/lib/controllers/record/index.js @@ -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 } } } diff --git a/web/client/assets/video/login_bg.mp4 b/web/client/assets/video/login_bg.mp4 index 99fb52c..da9d72b 100644 Binary files a/web/client/assets/video/login_bg.mp4 and b/web/client/assets/video/login_bg.mp4 differ diff --git a/web/client/src/sections/service/components/recordModal.jsx b/web/client/src/sections/service/components/recordModal.jsx index 6e2693d..28b909b 100644 --- a/web/client/src/sections/service/components/recordModal.jsx +++ b/web/client/src/sections/service/components/recordModal.jsx @@ -20,7 +20,7 @@ const RecordModal = (props) => { useEffect(() => { setEndTime(recordRow?.solvingTime) setStartTime(recordRow?.occurrenceTime) - setUploadData(recordRow?.files || []) + setUploadData(recordRow?.files[0] || {}) }, [recordRow]) const cancelHandler = () => { onClose() @@ -30,7 +30,6 @@ const RecordModal = (props) => { } const okHandler = () => { FormApi.current.validate().then((res) => { - console.log('recordRow', res) const editVal = { id: recordRow?.id, solvingTime: res.endTime, @@ -40,7 +39,7 @@ const RecordModal = (props) => { settler: res.settler, type: res.type, msg: recordRow ? '编辑响应记录' : '添加响应记录', - files: [{ ...uploadData }] + files: uploadData?.name ? [{ ...uploadData }] : [] } dispatch(service.addRecord(editVal)).then(res => { @@ -135,7 +134,7 @@ const RecordModal = (props) => { ({ url: `/_file-server/${v.url}`, name: v.name, status: 'success', preview: ['png','jpg'].includes(v.name?.split('.')?.pop()?.replace('.', '')), })) || []} + defaultFileList={recordRow?.files?.map(v => ({ url: `/_file-server/${v.url}`, name: v.name, status: 'success', preview: ['png', 'jpg'].includes(v.name?.split('.')?.pop()?.replace('.', '')), })) || []} accept={'.txt, .doc, .docx, .xls, .xlsx, .pdf, .png, .jpg, .rar, .zip'} limit={1} maxSize={51200}