Browse Source

响应判重优化

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

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

@ -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
}
}
}

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

Binary file not shown.

5
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 => {

Loading…
Cancel
Save