Browse Source

响应判重优化

dev
wenlele 1 year ago
parent
commit
c094c6eafd
  1. 47
      api/app/lib/controllers/record/index.js
  2. BIN
      web/client/assets/video/login_bg.mp4
  3. 7
      web/client/src/sections/service/components/recordModal.jsx

47
api/app/lib/controllers/record/index.js

@ -20,7 +20,7 @@ async function getRecord (ctx) {
}) })
let recordRes = await models.MaintenanceRecord.findAndCountAll({ let recordRes = await models.MaintenanceRecord.findAndCountAll({
order: [['id', 'DESC']], 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, offset: (pageIndex - 1) * pageSize,
limit: pageSize, limit: pageSize,
where: { where: {
@ -96,9 +96,50 @@ async function addRecord (ctx) {
const params = ctx.request.body const params = ctx.request.body
const { solvingTime, occurrencTime, sketch, record, settler, type, id, msg, files } = params const { solvingTime, occurrencTime, sketch, record, settler, type, id, msg, files } = params
const breakTime = (Date.parse(solvingTime) - Date.parse(occurrencTime)) / 1000 const breakTime = (Date.parse(solvingTime) - Date.parse(occurrencTime)) / 1000
let message = `${msg}失败`
try { try {
//中断时长 //中断时长
//console.log('resss1', Date.parse(solvingTime), occurrencTime) //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) { if (id) {
await models.MaintenanceRecord.update({ await models.MaintenanceRecord.update({
solvingTime, occurrenceTime: occurrencTime, sketch, record, settler, type, interruptDuration: breakTime, files: files solvingTime, occurrenceTime: occurrencTime, sketch, record, settler, type, interruptDuration: breakTime, files: files
@ -111,7 +152,7 @@ async function addRecord (ctx) {
}) })
await models.MaintenanceRecordExecuteUser.bulkCreate(resArry) await models.MaintenanceRecordExecuteUser.bulkCreate(resArry)
} else { } 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 recordId = aa.id
const resArry = settler.map((item) => { const resArry = settler.map((item) => {
return { return {
@ -129,7 +170,7 @@ async function addRecord (ctx) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400; ctx.status = 400;
ctx.body = { ctx.body = {
message: `${msg}失败` message: message
} }
} }
} }

BIN
web/client/assets/video/login_bg.mp4

Binary file not shown.

7
web/client/src/sections/service/components/recordModal.jsx

@ -20,7 +20,7 @@ const RecordModal = (props) => {
useEffect(() => { useEffect(() => {
setEndTime(recordRow?.solvingTime) setEndTime(recordRow?.solvingTime)
setStartTime(recordRow?.occurrenceTime) setStartTime(recordRow?.occurrenceTime)
setUploadData(recordRow?.files || []) setUploadData(recordRow?.files[0] || {})
}, [recordRow]) }, [recordRow])
const cancelHandler = () => { const cancelHandler = () => {
onClose() onClose()
@ -30,7 +30,6 @@ const RecordModal = (props) => {
} }
const okHandler = () => { const okHandler = () => {
FormApi.current.validate().then((res) => { FormApi.current.validate().then((res) => {
console.log('recordRow', res)
const editVal = { const editVal = {
id: recordRow?.id, id: recordRow?.id,
solvingTime: res.endTime, solvingTime: res.endTime,
@ -40,7 +39,7 @@ const RecordModal = (props) => {
settler: res.settler, settler: res.settler,
type: res.type, type: res.type,
msg: recordRow ? '编辑响应记录' : '添加响应记录', msg: recordRow ? '编辑响应记录' : '添加响应记录',
files: [{ ...uploadData }] files: uploadData?.name ? [{ ...uploadData }] : []
} }
dispatch(service.addRecord(editVal)).then(res => { dispatch(service.addRecord(editVal)).then(res => {
@ -135,7 +134,7 @@ const RecordModal = (props) => {
<Upload <Upload
style={{ display: 'inline-block' }} style={{ display: 'inline-block' }}
action={`${apiRoot}/attachments/p`} action={`${apiRoot}/attachments/p`}
defaultFileList={recordRow?.files?.map(v => ({ 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'} accept={'.txt, .doc, .docx, .xls, .xlsx, .pdf, .png, .jpg, .rar, .zip'}
limit={1} limit={1}
maxSize={51200} maxSize={51200}

Loading…
Cancel
Save