From ed07f80946a2dffed5af59893f347f3607dbb41d Mon Sep 17 00:00:00 2001 From: huababa1 <2037205722@qq.com> Date: Tue, 23 Sep 2025 11:14:58 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E3=80=91=E6=8E=A8?= =?UTF-8?q?=E9=80=81=E8=AF=95=E9=A2=98=E5=A2=9E=E5=8A=A0mysql=E3=80=81ps?= =?UTF-8?q?=E8=80=83=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exam/dal/dataobject/ExamQuestion.java | 6 ++ .../mysql/question/ExamQuestionMapper.java | 4 + .../question/ExamQuestionServiceImpl.java | 94 ++++++++++++++++++- .../mapper/exam/ExamQuestionMapper.xml | 42 +++++++++ .../mysqlkeyword/MysqlKeywordMapper.xml | 7 +- 5 files changed, 151 insertions(+), 2 deletions(-) diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/dataobject/ExamQuestion.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/dataobject/ExamQuestion.java index 384225b6..253c3ffd 100644 --- a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/dataobject/ExamQuestion.java +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/dataobject/ExamQuestion.java @@ -202,4 +202,10 @@ public class ExamQuestion extends TenantBaseDO { */ @TableField(exist = false) private String questionType; + + /** + * ps考点 + */ + @TableField(exist = false) + private List psKeywords; } diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/mysql/question/ExamQuestionMapper.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/mysql/question/ExamQuestionMapper.java index 0a9a0091..e0981a3f 100644 --- a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/mysql/question/ExamQuestionMapper.java +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/dal/mysql/question/ExamQuestionMapper.java @@ -8,6 +8,7 @@ import pc.exam.pp.framework.mybatis.core.query.LambdaQueryWrapperX; import pc.exam.pp.module.exam.controller.admin.question.dto.TenantDto; import pc.exam.pp.module.exam.controller.admin.question.vo.QuestionVo; import pc.exam.pp.module.exam.controller.admin.question.vo.TenantVo; +import pc.exam.pp.module.exam.dal.dataobject.ExamPsKeyword; import pc.exam.pp.module.exam.dal.dataobject.ExamQuestion; import java.util.List; @@ -234,4 +235,7 @@ public interface ExamQuestionMapper extends BaseMapperX { */ List selectQuNumBuIds(List cannotDeleteIds); + List selectExamQuestionPsKeywordByQuId(String quId); + + void insertExamPsKeywordList(List psKeywords); } diff --git a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/question/ExamQuestionServiceImpl.java b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/question/ExamQuestionServiceImpl.java index d3c12e04..ea2dd0a1 100644 --- a/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/question/ExamQuestionServiceImpl.java +++ b/exam-module-exam/exam-module-exam-biz/src/main/java/pc/exam/pp/module/exam/service/question/ExamQuestionServiceImpl.java @@ -641,6 +641,7 @@ public class ExamQuestionServiceImpl implements IExamQuestionService { List fileUploads = examQuestion.getFileUploads(); ExamQuestionScore questionScores = examQuestion.getQuestionScores(); List questionKeywords = examQuestion.getQuestionKeywords(); + List psKeywords = examQuestion.getPsKeywords(); if (answerList != null && answerList.size() > 0) { answerList.replaceAll(answer -> { answer.setAnswerId(IdUtils.simpleUUID()); @@ -649,6 +650,20 @@ public class ExamQuestionServiceImpl implements IExamQuestionService { }); //examQuestionAnswerMapper.insert(answerList); examQuestionAnswerMapper.insertExamQuestionAnswerList(answerList); + List newKeywordList = new ArrayList<>(); + for (ExamQuestionAnswer examQuestionAnswer : answerList) { + if (examQuestionAnswer.getExamMysqlKeywordList()!=null&& examQuestionAnswer.getExamMysqlKeywordList().size()>0){ + List examMysqlKeywordList = examQuestionAnswer.getExamMysqlKeywordList(); + for (ExamMysqlKeyword keyword : examMysqlKeywordList) { + keyword.setAnswerId(examQuestionAnswer.getAnswerId()); + keyword.setKeywordId(IdUtils.simpleUUID()); + } + newKeywordList.addAll(examMysqlKeywordList); + } + } + if (!CollectionUtils.isEmpty(newKeywordList)) { + mysqlKeywordMapper.insert(newKeywordList); + } } if (fileUploads != null && fileUploads.size() > 0) { fileUploads.replaceAll(fileUpload -> { @@ -673,6 +688,32 @@ public class ExamQuestionServiceImpl implements IExamQuestionService { }); examQuestionKeywordMapper.insertExamQuestionKeywordList(questionKeywords); } + if (psKeywords != null && psKeywords.size() > 0) { + // 保存旧ID -> 新ID 的映射 + Map idMap = new HashMap<>(); + + // 第一次遍历,生成新ID,记录映射 + for (ExamPsKeyword psKeyword : psKeywords) { + String newId = IdUtils.simpleUUID(); + idMap.put(psKeyword.getId(), newId); // 保存旧ID到新ID的映射 + psKeyword.setId(newId); // 替换为新ID + psKeyword.setQuId(quId); // 替换为当前试题ID + } + + // 第二次遍历,处理 parentId + for (ExamPsKeyword psKeyword : psKeywords) { + String parentId = psKeyword.getParentId(); + if (!"0".equals(parentId)) { + // 替换成新生成的父ID + String newParentId = idMap.get(parentId); + psKeyword.setParentId(newParentId); + } + } + + // 批量插入 + examQuestionMapper.insertExamPsKeywordList(psKeywords); + } + examQuestionMapper.insert(examQuestion); } //有就是覆盖 @@ -694,7 +735,7 @@ public class ExamQuestionServiceImpl implements IExamQuestionService { List fileUploads = examQuestion.getFileUploads(); ExamQuestionScore questionScores = examQuestion.getQuestionScores(); List questionKeywords = examQuestion.getQuestionKeywords(); - + List psKeywords = examQuestion.getPsKeywords(); if (answerList != null && answerList.size() > 0) { answerList.replaceAll(answer -> { answer.setAnswerId(IdUtils.simpleUUID()); @@ -703,6 +744,20 @@ public class ExamQuestionServiceImpl implements IExamQuestionService { }); //examQuestionAnswerMapper.insert(answerList); examQuestionAnswerMapper.insertExamQuestionAnswerList(answerList); + List newKeywordList = new ArrayList<>(); + for (ExamQuestionAnswer examQuestionAnswer : answerList) { + if (examQuestionAnswer.getExamMysqlKeywordList()!=null&& examQuestionAnswer.getExamMysqlKeywordList().size()>0){ + List examMysqlKeywordList = examQuestionAnswer.getExamMysqlKeywordList(); + for (ExamMysqlKeyword keyword : examMysqlKeywordList) { + keyword.setAnswerId(examQuestionAnswer.getAnswerId()); + keyword.setKeywordId(IdUtils.simpleUUID()); + } + newKeywordList.addAll(examMysqlKeywordList); + } + } + if (!CollectionUtils.isEmpty(newKeywordList)) { + mysqlKeywordMapper.insert(newKeywordList); + } } if (fileUploads != null && fileUploads.size() > 0) { @@ -730,6 +785,31 @@ public class ExamQuestionServiceImpl implements IExamQuestionService { }); examQuestionKeywordMapper.insertExamQuestionKeywordList(questionKeywords); } + if (psKeywords != null && psKeywords.size() > 0) { + // 保存旧ID -> 新ID 的映射 + Map idMap = new HashMap<>(); + + // 第一次遍历,生成新ID,记录映射 + for (ExamPsKeyword psKeyword : psKeywords) { + String newId = IdUtils.simpleUUID(); + idMap.put(psKeyword.getId(), newId); // 保存旧ID到新ID的映射 + psKeyword.setId(newId); // 替换为新ID + psKeyword.setQuId(quId); // 替换为当前试题ID + } + + // 第二次遍历,处理 parentId + for (ExamPsKeyword psKeyword : psKeywords) { + String parentId = psKeyword.getParentId(); + if (!"0".equals(parentId)) { + // 替换成新生成的父ID + String newParentId = idMap.get(parentId); + psKeyword.setParentId(newParentId); + } + } + + // 批量插入 + examQuestionMapper.insertExamPsKeywordList(psKeywords); + } examQuestionMapper.updateBatch(examQuestion); } } @@ -758,8 +838,17 @@ public class ExamQuestionServiceImpl implements IExamQuestionService { //获取试题关键字 List examQuestionKeywords = examQuestionKeywordMapper.selectExamQuestionKeywordByQuId(quId); + List examPsKeywords=examQuestionMapper.selectExamQuestionPsKeywordByQuId(quId); if (examQuestion_obj != null) { if (examQuestionAnswers != null && examQuestionAnswers.size() > 0) { + //获取mysql关键字 + for (ExamQuestionAnswer examQuestionAnswer : examQuestionAnswers) { + String answerId = examQuestionAnswer.getAnswerId(); + List newKeywordList = mysqlKeywordMapper.selectList( + new QueryWrapper().eq("answer_id", answerId) + ); + examQuestionAnswer.setExamMysqlKeywordList(newKeywordList); + } examQuestion_obj.setAnswerList(examQuestionAnswers); } if (sysFileUploads != null && sysFileUploads.size() > 0) { @@ -771,6 +860,9 @@ public class ExamQuestionServiceImpl implements IExamQuestionService { if (examQuestionKeywords != null && examQuestionKeywords.size() > 0) { examQuestion_obj.setQuestionKeywords(examQuestionKeywords); } + if (examPsKeywords!=null&& examPsKeywords.size()>0){ + examQuestion_obj.setPsKeywords(examPsKeywords); + } } // examQuestion_obj.setType(rabbitMQSendInfoVO.getType()); // examQuestion_obj.setSource(SecurityFrameworkUtils.getLoginTenantId()); diff --git a/exam-module-exam/exam-module-exam-biz/src/main/resources/mapper/exam/ExamQuestionMapper.xml b/exam-module-exam/exam-module-exam-biz/src/main/resources/mapper/exam/ExamQuestionMapper.xml index 2629d113..1a23b2bf 100644 --- a/exam-module-exam/exam-module-exam-biz/src/main/resources/mapper/exam/ExamQuestionMapper.xml +++ b/exam-module-exam/exam-module-exam-biz/src/main/resources/mapper/exam/ExamQuestionMapper.xml @@ -51,6 +51,18 @@ + + + + + + + + + + + + select qu_id, qu_bank_id, @@ -181,6 +193,12 @@ #{id} + @@ -278,6 +296,30 @@ update_time = VALUES(update_time), updater = VALUES(updater) + + INSERT INTO exam_ps_keyword ( + id, + qu_id, + parent_id, + key_name, + key_value, + rate, + type, + sort + ) VALUES + + ( + #{item.id}, + #{item.quId}, + #{item.parentId}, + #{item.key}, + #{item.value}, + #{item.rate}, + #{item.type}, + #{item.sort} + ) + + update exam_question diff --git a/exam-module-exam/exam-module-exam-biz/src/main/resources/mapper/mysqlkeyword/MysqlKeywordMapper.xml b/exam-module-exam/exam-module-exam-biz/src/main/resources/mapper/mysqlkeyword/MysqlKeywordMapper.xml index 0d04eea0..ee064ed7 100644 --- a/exam-module-exam/exam-module-exam-biz/src/main/resources/mapper/mysqlkeyword/MysqlKeywordMapper.xml +++ b/exam-module-exam/exam-module-exam-biz/src/main/resources/mapper/mysqlkeyword/MysqlKeywordMapper.xml @@ -3,7 +3,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - + + + + + + delete from exam_mysql_keyword where answer_id=#{answerId}