有已完成考试的重新考试逻辑
This commit is contained in:
parent
08bf170216
commit
7c9fdc8d6f
@ -1399,6 +1399,74 @@ async function continueExam(paperId) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理考生试卷及相关记录
|
||||
* @param {number} paperId - 试卷ID
|
||||
* @returns {Promise<Object>} - 包含操作结果的对象
|
||||
*/
|
||||
async function clearExamineePaper(paperId) {
|
||||
try {
|
||||
// 获取用户数据库连接
|
||||
const userDb = await getDbConnection(getUserDbPath());
|
||||
|
||||
// 开始事务
|
||||
await userDb.runAsync('BEGIN TRANSACTION');
|
||||
try {
|
||||
// 获取paper_questions记录
|
||||
const paperQuestions = await userDb.allAsync(
|
||||
'SELECT id FROM paper_questions WHERE paper_id = ?',
|
||||
paperId
|
||||
);
|
||||
|
||||
// 遍历所有paper_questions,删除相关记录
|
||||
for (const question of paperQuestions) {
|
||||
// 删除question_choices记录
|
||||
await userDb.runAsync(
|
||||
'DELETE FROM question_choices WHERE question_id = ?',
|
||||
question.id
|
||||
);
|
||||
|
||||
// 删除question_fill_blanks记录
|
||||
await userDb.runAsync(
|
||||
'DELETE FROM question_fill_blanks WHERE question_id = ?',
|
||||
question.id
|
||||
);
|
||||
|
||||
// 删除question_datasets记录
|
||||
await userDb.runAsync(
|
||||
'DELETE FROM question_datasets WHERE question_id = ?',
|
||||
question.id
|
||||
);
|
||||
|
||||
// 删除question_images记录
|
||||
await userDb.runAsync(
|
||||
'DELETE FROM question_images WHERE question_id = ?',
|
||||
question.id
|
||||
);
|
||||
}
|
||||
|
||||
// 删除paper_questions记录
|
||||
await userDb.runAsync('DELETE FROM paper_questions WHERE paper_id = ?', paperId);
|
||||
|
||||
// 删除examinee_papers记录
|
||||
await userDb.runAsync('DELETE FROM examinee_papers WHERE id = ?', paperId);
|
||||
|
||||
// 提交事务
|
||||
await userDb.runAsync('COMMIT');
|
||||
console.log(`成功清理试卷ID: ${paperId}的所有相关记录`);
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
// 回滚事务
|
||||
await userDb.runAsync('ROLLBACK');
|
||||
console.error(`清理试卷记录失败: ${error.message}`);
|
||||
throw new Error(`清理试卷记录失败: ${error.message}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取数据库连接失败:', error);
|
||||
throw new Error(`清理试卷记录失败: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
exports = module.exports = {
|
||||
formatDateTime,
|
||||
batchInsert,
|
||||
@ -1413,5 +1481,6 @@ exports = module.exports = {
|
||||
checkPaperAnswers,
|
||||
getPaper,
|
||||
getExamineePaper,
|
||||
continueExam
|
||||
continueExam,
|
||||
clearExamineePaper
|
||||
};
|
@ -147,6 +147,9 @@ contextBridge.exposeInMainWorld("electronAPI", {
|
||||
// 新增:结束考试接口
|
||||
examingEndPaper: ({ paperId }) =>
|
||||
ipcRenderer.invoke("examing-end-paper", { paperId }),
|
||||
// 新增:清理试卷数据接口
|
||||
examingClearPaper: ({ paperId }) =>
|
||||
ipcRenderer.invoke("examing-clear-paper", { paperId }),
|
||||
|
||||
// 文件服务相关接口
|
||||
// 保留一个fileGeneratePaperPdf定义,移除重复的
|
||||
|
@ -11,7 +11,8 @@ const {
|
||||
checkPaperAnswers,
|
||||
getPaper,
|
||||
getExamineePaper,
|
||||
continueExam, // 添加continueExam到导入列表中
|
||||
continueExam,
|
||||
clearExamineePaper,
|
||||
} = require("../db/examing.js");
|
||||
const { getDbConnection, closeAllConnections } = require("../db/index.js");
|
||||
const { getUserDbPath } = require("../db/path.js");
|
||||
@ -75,6 +76,23 @@ async function getExamineePaperStatusService(examineeId) {
|
||||
}
|
||||
}
|
||||
|
||||
async function clearExamineePaperService(paperId) {
|
||||
try {
|
||||
const result = await clearExamineePaper(paperId);
|
||||
return {
|
||||
success: true,
|
||||
message: "试卷数据清理成功",
|
||||
data: result,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("清理试卷数据失败:", error);
|
||||
return {
|
||||
success: false,
|
||||
message: `清理试卷数据失败: ${error.message}`,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 服务层:更新试卷状态
|
||||
* @param {number} paperId - 试卷ID
|
||||
@ -667,6 +685,19 @@ function initExamingIpc(ipcMain) {
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
// 找到initExamingIpc函数,在合适位置添加以下代码
|
||||
ipcMain.handle("examing-clear-paper", async (event, { paperId }) => {
|
||||
try {
|
||||
return await clearExamineePaperService(paperId);
|
||||
} catch (error) {
|
||||
console.error("清理试卷数据失败:", error);
|
||||
return {
|
||||
success: false,
|
||||
message: `清理试卷数据失败: ${error.message}`,
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 导出使用CommonJS格式
|
||||
@ -686,5 +717,6 @@ module.exports = {
|
||||
getExamineePaperService,
|
||||
continueExamService,
|
||||
getPaperService,
|
||||
clearExamineePaperService,
|
||||
initExamingIpc,
|
||||
};
|
||||
|
@ -125,7 +125,7 @@
|
||||
<div class="mt-3 text-sm text-gray-700">
|
||||
你可以继续进行未完成的考试,或者重新开始,重新开始后将清除所有历史考试记录。
|
||||
</div>
|
||||
<div class="mt-4 flex space-x-2">
|
||||
<div class="mt-4 space-x-2 text-center">
|
||||
<el-button type="primary" @click="continueExam">继续考试</el-button>
|
||||
<el-button type="warning" @click="restartExam">重新开始</el-button>
|
||||
</div>
|
||||
@ -718,12 +718,45 @@ export default {
|
||||
}
|
||||
).then(async () => {
|
||||
try {
|
||||
// 清除未完成的试卷状态,然后调用开始考试方法
|
||||
this.isLoading = true
|
||||
|
||||
// 首先获取要清除的试卷ID
|
||||
let paperIdToClear = null
|
||||
if (this.completedPaper && this.completedPaper.id) {
|
||||
paperIdToClear = this.completedPaper.id
|
||||
} else if (this.unfinishedPaper && this.unfinishedPaper.id) {
|
||||
paperIdToClear = this.unfinishedPaper.id
|
||||
}
|
||||
|
||||
// 如果有试卷ID,则调用clear接口清除试卷数据
|
||||
if (paperIdToClear) {
|
||||
console.log('开始清除试卷数据,试卷ID:', paperIdToClear)
|
||||
const clearResult = await window.electronAPI.examingClearPaper({
|
||||
paperId: paperIdToClear
|
||||
})
|
||||
|
||||
if (clearResult && clearResult.success) {
|
||||
console.log('清除试卷数据成功')
|
||||
} else {
|
||||
console.warn('清除试卷数据失败:', clearResult)
|
||||
// 不中断流程,继续尝试开始考试
|
||||
}
|
||||
}
|
||||
|
||||
// 清除本地的试卷状态
|
||||
this.unfinishedPaper = null
|
||||
this.completedPaper = null
|
||||
|
||||
// 重新检查试卷状态,确保本地状态与实际数据同步
|
||||
await this.checkUnfinishedPaper()
|
||||
|
||||
// 调用开始考试方法
|
||||
await this.startExam()
|
||||
} catch (error) {
|
||||
console.error('重新开始考试失败:', error)
|
||||
this.$message.error('重新开始考试失败')
|
||||
} finally {
|
||||
this.isLoading = false
|
||||
}
|
||||
}).catch(() => {
|
||||
// 用户取消操作
|
||||
|
Loading…
Reference in New Issue
Block a user