【修改】 1、考点服务器同步试题,插入数据库BUG修改;2、代码优化

This commit is contained in:
dlaren
2025-07-31 15:41:37 +08:00
parent c3f0d23c9d
commit 0e49548c02
2 changed files with 231 additions and 242 deletions

View File

@@ -38,14 +38,13 @@ import static pc.exam.pp.module.system.enums.ErrorCodeConstants.*;
/**
* 试题(hyc)Service业务层处理
*
*
* @author pengchen
* @date 2025-03-13
*/
@Service
public class ExamQuestionServiceImpl implements IExamQuestionService
{
// @Autowired
public class ExamQuestionServiceImpl implements IExamQuestionService {
// @Autowired
// private ExamBankMapper examBankMapper;
@Autowired
private ExamQuestionMapper examQuestionMapper;
@@ -73,44 +72,44 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
private IExamQuestionService examQuestionService;
@Autowired
private ConfigApi configApi;
/**
* 查询试题(hyc)
*
*
* @param quId 试题(hyc)主键
* @return 试题(hyc)
*/
@Override
public ExamQuestion selectExamQuestionByQuId(String quId)
{
public ExamQuestion selectExamQuestionByQuId(String quId) {
//查找试题答案
List<ExamQuestionAnswer> examQuestionAnswers = examQuestionAnswerMapper.selectExamQuestionAnswerByQuId(quId);
//查找试题文件
List<SysFileUpload> sysFileUploads =sysFileMapper.selectSysFileByQuid(quId);
List<SysFileUpload> sysFileUploads = sysFileMapper.selectSysFileByQuid(quId);
//查找试题判分
ExamQuestionScore examQuestionScore =examQuestionScoreMapper.selectExamQuestionScoreByQuId(quId);
ExamQuestionScore examQuestionScore = examQuestionScoreMapper.selectExamQuestionScoreByQuId(quId);
//获取试题关键字
List<ExamQuestionKeyword> examQuestionKeywords = examQuestionKeywordMapper.selectExamQuestionKeywordByQuId(quId);
ExamQuestion examQuestion = examQuestionMapper.selectExamQuestionByQuId(quId);
if (examQuestion!=null){
if (examQuestionAnswers!=null&&examQuestionAnswers.size()>0){
if (examQuestion != null) {
if (examQuestionAnswers != null && examQuestionAnswers.size() > 0) {
examQuestion.setAnswerList(examQuestionAnswers);
}
if (sysFileUploads!=null&&sysFileUploads.size()>0){
if (sysFileUploads != null && sysFileUploads.size() > 0) {
examQuestion.setFileUploads(sysFileUploads);
}
if (examQuestionScore!=null){
if (examQuestionScore != null) {
examQuestion.setQuestionScores(examQuestionScore);
}
if (examQuestionKeywords!=null&&examQuestionKeywords.size()>0){
if (examQuestionKeywords != null && examQuestionKeywords.size() > 0) {
examQuestion.setQuestionKeywords(examQuestionKeywords);
}
}
String chapteridDictText = examQuestion.getChapteridDictText();
String pointNames = examQuestion.getPointNames();
String point= knowledgePointsMapper.selectKnowledgeNameBySpId(pointNames);
String chapterText= knowledgePointsMapper.selectKnowledgeNameBySpId(chapteridDictText);
String point = knowledgePointsMapper.selectKnowledgeNameBySpId(pointNames);
String chapterText = knowledgePointsMapper.selectKnowledgeNameBySpId(chapteridDictText);
examQuestion.setPointNamesVo(point);
examQuestion.setChapteridDictTextVo(chapterText);
return examQuestion;
@@ -118,7 +117,7 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
/**
* 查询试题(hyc)列表
*
*
* @param examQuestionDto 试题(hyc)
* @return 试题(hyc)
*/
@@ -126,13 +125,12 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
/**
* 新增试题(hyc)
*
*
* @param examQuestion 试题(hyc)
* @return 结果
*/
@Override
public int insertExamQuestion(ExamQuestion examQuestion)
{
public int insertExamQuestion(ExamQuestion examQuestion) {
//更新题库的试题数
// if (examQuestion.getQuBankId()!=null){
// UpdateQuCountNow(examQuestion.getQuBankId());
@@ -146,17 +144,17 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
List<SysFileUpload> fileUploads = examQuestion.getFileUploads();
ExamQuestionScore questionScore = examQuestion.getQuestionScores();
List<ExamQuestionKeyword> examQuestionKeywords = examQuestion.getQuestionKeywords();
if (answerList!=null&&answerList.size()>0){
if (answerList != null && answerList.size() > 0) {
answerList.replaceAll(answer -> {
answer.setAnswerId(IdUtils.simpleUUID());
answer.setQuId(uuid);
return answer;
});
//examQuestionAnswerMapper.insert(answerList);
examQuestionAnswerMapper.insertExamQuestionAnswerList(answerList);
examQuestionAnswerMapper.insertExamQuestionAnswerList(answerList);
}
if (fileUploads!=null&&fileUploads.size()>0){
if (fileUploads != null && fileUploads.size() > 0) {
fileUploads.replaceAll(fileUpload -> {
// 设置文件名(如果文件名为空)
if (fileUpload.getFileName() == null || fileUpload.getFileName().isEmpty()) {
@@ -186,12 +184,12 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
}
if (questionScore!=null){
if (questionScore != null) {
questionScore.setScoreId(IdUtils.simpleUUID());
questionScore.setQuId(uuid);
examQuestionScoreMapper.insertExamQuestionScore(questionScore);
}
if (examQuestionKeywords!=null&&examQuestionKeywords.size()>0){
if (examQuestionKeywords != null && examQuestionKeywords.size() > 0) {
examQuestionKeywords.replaceAll(examQuestionKeyword -> {
examQuestionKeyword.setKeywordId(IdUtils.simpleUUID());
examQuestionKeyword.setQuId(uuid);
@@ -201,26 +199,25 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
}
// return examQuestionMapper.insert(examQuestion);
Long loginTenantId = SecurityFrameworkUtils.getLoginTenantId();
int count= examQuestionMapper.selectCountQu();
int count = examQuestionMapper.selectCountQu();
// 读取系统创建试题位数设置
String number = configApi.getConfigValueByKey("qu_number");
// 格式化为8位不足前面补0
String formattedNumber = String.format("%0" + number + "d", ++count);
String quNum =loginTenantId +"-"+formattedNumber;
String quNum = loginTenantId + "-" + formattedNumber;
examQuestion.setQuNum(quNum);
return examQuestionMapper.insertExamQuestion(examQuestion);
}
/**
* 修改试题(hyc)
*
*
* @param examQuestion 试题(hyc)
* @return 结果
*/
@Override
@Transactional(rollbackFor = Exception.class) // 所有异常都回滚
public int updateExamQuestion(ExamQuestion examQuestion)
{
public int updateExamQuestion(ExamQuestion examQuestion) {
List<ExamQuestionAnswer> answerList = examQuestion.getAnswerList();
List<SysFileUpload> fileUploads = examQuestion.getFileUploads();
@@ -231,7 +228,7 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
if (!excludedSubjects.contains(examQuestion.getSubjectName())) {
//先删除试题的答案
examQuestionAnswerMapper.deleteExamQuestionAnswerByQuesId(examQuestion.getQuId());
if (answerList!=null&&answerList.size()>0){
if (answerList != null && answerList.size() > 0) {
//赋值
answerList.replaceAll(answer -> {
answer.setAnswerId(IdUtils.simpleUUID());
@@ -245,7 +242,7 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
}
//先删除试题的文件
sysFileMapper.deleteSysFileByQuesId(examQuestion.getQuId());
if (fileUploads!=null&&fileUploads.size()>0){
if (fileUploads != null && fileUploads.size() > 0) {
//赋值
fileUploads.replaceAll(fileUpload -> {
@@ -276,7 +273,7 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
sysFileMapper.insertSysFileList(fileUploads);
}
if (questionScore!=null){
if (questionScore != null) {
//先删除试题的判分
examQuestionScoreMapper.deleteExamQuestionScoreByQuesId(examQuestion.getQuId());
//赋值
@@ -286,7 +283,7 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
}
//先删除试题的判分
examQuestionKeywordMapper.deleteExamQuestionScoreByQuesId(examQuestion.getQuId());
if (examQuestionKeywords!=null&&examQuestionKeywords.size()>0){
if (examQuestionKeywords != null && examQuestionKeywords.size() > 0) {
//赋值
examQuestionKeywords.replaceAll(examQuestionKeyword -> {
examQuestionKeyword.setKeywordId(IdUtils.simpleUUID());
@@ -326,7 +323,7 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
/**
* 批量删除试题(hyc)
*
*
* @param ids 需要删除的试题(hyc)主键
* @return 结果
*/
@@ -338,9 +335,7 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
Set<String> usedIdSet = new HashSet<>(usedIds);
// 找出未被使用的题目ID
List<String> canDeleteIds = Arrays.stream(ids)
.filter(id -> !usedIdSet.contains(id))
.collect(Collectors.toList());
List<String> canDeleteIds = Arrays.stream(ids).filter(id -> !usedIdSet.contains(id)).collect(Collectors.toList());
if (canDeleteIds.isEmpty()) {
// 全部试题都已被引用,不能删除
return ("全部试题都已被引用,不能删除!");
@@ -363,10 +358,8 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
examQuestionMapper.deleteExamQuestionByQuIds(deleteIds);
if (!allCanBeDeleted) {
// 找出不能删除的ID
List<String> cannotDeleteIds = Arrays.stream(ids)
.filter(usedIdSet::contains)
.collect(Collectors.toList());
List<String> quNumList=examQuestionMapper.selectQuNumBuIds(cannotDeleteIds);
List<String> cannotDeleteIds = Arrays.stream(ids).filter(usedIdSet::contains).collect(Collectors.toList());
List<String> quNumList = examQuestionMapper.selectQuNumBuIds(cannotDeleteIds);
return ("部分试题已参与组卷无法删除: " + quNumList);
}
@@ -376,26 +369,23 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
/**
* 删除试题(hyc)信息
*
*
* @param quId 试题(hyc)主键
* @return 结果
*/
@Override
public int deleteExamQuestionByQuId(String quId)
{
public int deleteExamQuestionByQuId(String quId) {
return examQuestionMapper.deleteExamQuestionByQuId(quId);
}
@Override
public PageResult<ExamQuestion> selectExamQuestionList(QuestionVo questionVo) {
PageResult<ExamQuestion> examQuestionPageResult = examQuestionMapper.selectExamQuestionList(questionVo);
List<ExamQuestion> list = examQuestionPageResult.getList();
List<ExamKnowledgePoints> examKnowledgePoints = knowledgePointsMapper.selectKnowledgePoints();
// 构造 ID → 名称映射
Map<Long, String> idNameMap = examKnowledgePoints.stream()
.collect(Collectors.toMap(ExamKnowledgePoints::getSpId, ExamKnowledgePoints::getSpName));
// 构造 ID → 名称映射
Map<Long, String> idNameMap = examKnowledgePoints.stream().collect(Collectors.toMap(ExamKnowledgePoints::getSpId, ExamKnowledgePoints::getSpName));
for (ExamQuestion examQuestion : list) {
String pointIdStr = examQuestion.getPointNames();
String chapterIdStr = examQuestion.getChapteridDictText();
@@ -424,6 +414,7 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
/**
* 上传试题至Rabbitmq
*
* @param rabbitMQSendInfoVO 试题内容
* @return 结果
*/
@@ -432,7 +423,7 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
// 1、判断上传题目数量
int quCount = rabbitMQSendInfoVO.getQuIds().size();
List<String> quIds = rabbitMQSendInfoVO.getQuIds();
if (quIds!=null&&quIds.size()>0){
if (quIds != null && quIds.size() > 0) {
examQuestionMapper.setQuestionAuditByids(quIds);
for (String quId : quIds) {
// 2、根据试题ID查找试题详情
@@ -451,11 +442,12 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
/**
* 拉取数据Rabbitmq
*
* @param queueName 客户端ID
* @return 试题内容
*/
@Override
public boolean getExamQuestionToRabbitMQ(String queueName) {
public boolean getExamQuestionToRabbitMQ(String queueName) {
// 最先判断类型
// TODO 1、拉取数据保存至数据库 2、回调服务器是否拉取成功中心服务器
// 1、获取上传的rabbit的试题数组
@@ -463,13 +455,13 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
try {
examQuestions = rabbitMqService.receiveAllMessages(queueName);
} catch (Exception e) {
return false;
return false;
}
if(examQuestions!=null&&examQuestions.size()>0){
if (examQuestions != null && examQuestions.size() > 0) {
// 2、保存至数据库
List<QuestionExamineDO> questionExamineDOS=new ArrayList<>();
List<QuestionExamineDO> questionExamineDOS = new ArrayList<>();
for (ExamQuestion examQuestion : examQuestions) {
QuestionExamineDO questionExamineDO=new QuestionExamineDO();
QuestionExamineDO questionExamineDO = new QuestionExamineDO();
questionExamineDO.setQuId(examQuestion.getQuId());
questionExamineDO.setSource(examQuestion.getSource());
questionExamineDO.setCreateTeacher(examQuestion.getCreateTeacher());
@@ -505,19 +497,18 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
public PageResult<ExamQuestion> selectExamQuestionListNoAudit(QuestionExaminePageReqVO questionVo) {
PageResult<QuestionExamineDO> questionExamineDOPageResult = questionExamineMapper.selectPage(questionVo);
List<QuestionExamineDO> list = questionExamineDOPageResult.getList();
List<ExamQuestion> examQuestionList=new ArrayList<>();
List<ExamQuestion> examQuestionList = new ArrayList<>();
List<ExamKnowledgePoints> examKnowledgePoints = knowledgePointsMapper.selectKnowledgePoints();
// 构造 ID → 名称映射
Map<Long, String> idNameMap = examKnowledgePoints.stream()
.collect(Collectors.toMap(ExamKnowledgePoints::getSpId, ExamKnowledgePoints::getSpName));
if (list!=null&&list.size()>0){
Map<Long, String> idNameMap = examKnowledgePoints.stream().collect(Collectors.toMap(ExamKnowledgePoints::getSpId, ExamKnowledgePoints::getSpName));
if (list != null && list.size() > 0) {
for (QuestionExamineDO questionExamineDO : list) {
String schoolName =questionExamineMapper.selectSchoolName(questionExamineDO.getSource());
String schoolName = questionExamineMapper.selectSchoolName(questionExamineDO.getSource());
ExamQuestion examQuestion = examQuestionMapper.selectExamQuestionByQuId(questionExamineDO.getQuId());
String pointIdStr = examQuestion.getPointNames();
String chapterIdStr = examQuestion.getChapteridDictText();
if (examQuestion!=null){
if (examQuestion != null) {
try {
if (pointIdStr != null) {
Long pointId = Long.valueOf(pointIdStr);
@@ -547,7 +538,7 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
}
}
PageResult<ExamQuestion> examQuestionPageResult=new PageResult<>();
PageResult<ExamQuestion> examQuestionPageResult = new PageResult<>();
examQuestionPageResult.setList(examQuestionList);
examQuestionPageResult.setTotal((long) examQuestionList.size());
@@ -556,11 +547,11 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
}
@Override
public PageResult<TenantVo> getSchoolName(TenantDto tenantDto) {
public PageResult<TenantVo> getSchoolName(TenantDto tenantDto) {
tenantDto.setOffset(tenantDto.getOffset());
List<TenantVo> schoolName = examQuestionMapper.getSchoolName(tenantDto);
long total = examQuestionMapper.getSchoolNameTotal(tenantDto);
PageResult<TenantVo> pageResult=new PageResult<>();
PageResult<TenantVo> pageResult = new PageResult<>();
pageResult.setList(schoolName);
pageResult.setTotal(total);
return pageResult;
@@ -569,13 +560,13 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
@Override
public int auditQueByIds(List<String> quIds) {
examQuestionMapper.updateExamQuestionByIds(SecurityFrameworkUtils.getLoginUserNickname(),quIds);
return examQuestionMapper.auditQueByIds(quIds,SecurityFrameworkUtils.getLoginUserNickname());
examQuestionMapper.updateExamQuestionByIds(SecurityFrameworkUtils.getLoginUserNickname(), quIds);
return examQuestionMapper.auditQueByIds(quIds, SecurityFrameworkUtils.getLoginUserNickname());
}
@Override
public int noAuditQue(List<String> quIds) {
return examQuestionMapper.noAuditQue(quIds);
return examQuestionMapper.noAuditQue(quIds);
}
@Override
@@ -584,7 +575,6 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
}
public boolean getExamQuestionToRabbitMQInsertData(String queueName) {
// 最先判断类型
// TODO 1、拉取数据保存至数据库 2、回调服务器是否拉取成功中心服务器
@@ -595,123 +585,125 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
} catch (Exception e) {
return false;
}
if(examQuestions!=null&&examQuestions.size()>0){
if (examQuestions != null && examQuestions.size() > 0) {
for (ExamQuestion examQuestion : examQuestions) {
ExamQuestion question= examQuestionMapper.selectExamQuestionCountByQuId(examQuestion.getQuBankId());
if (question==null){
//如果没有,就是新增
String quId = IdUtils.simpleUUID();
examQuestion.setQuId(quId);
Long loginTenantId = SecurityFrameworkUtils.getLoginTenantId();
int count= examQuestionMapper.selectCountQu();
// 格式化为8位不足前面补0
String formattedNumber = String.format("%08d", ++count);
String quNum =loginTenantId +"-"+formattedNumber;
examQuestion.setQuNum(quNum);
ExamQuestion question = examQuestionMapper.selectExamQuestionCountByQuId(examQuestion.getQuBankId());
if (question == null) {
//如果没有,就是新增
String quId = IdUtils.simpleUUID();
examQuestion.setQuId(quId);
Long loginTenantId = SecurityFrameworkUtils.getLoginTenantId();
int count = examQuestionMapper.selectCountQu();
// 读取系统创建试题位数设置
String number = configApi.getConfigValueByKey("qu_number");
// 格式化为8位不足前面补0
String formattedNumber = String.format("%0" + number + "d", ++count);
String quNum = loginTenantId + "-" + formattedNumber;
examQuestion.setQuNum(quNum);
//新增
List<ExamQuestionAnswer> answerList = examQuestion.getAnswerList();
List<SysFileUpload> fileUploads = examQuestion.getFileUploads();
ExamQuestionScore questionScores = examQuestion.getQuestionScores();
List<ExamQuestionKeyword> questionKeywords = examQuestion.getQuestionKeywords();
//新增
List<ExamQuestionAnswer> answerList = examQuestion.getAnswerList();
List<SysFileUpload> fileUploads = examQuestion.getFileUploads();
ExamQuestionScore questionScores = examQuestion.getQuestionScores();
List<ExamQuestionKeyword> questionKeywords = examQuestion.getQuestionKeywords();
if (answerList!=null&&answerList.size()>0){
answerList.replaceAll(answer -> {
answer.setAnswerId(IdUtils.simpleUUID());
answer.setQuId(quId);
return answer;
});
//examQuestionAnswerMapper.insert(answerList);
examQuestionAnswerMapper.insertExamQuestionAnswerList(answerList);
}
if (answerList != null && answerList.size() > 0) {
answerList.replaceAll(answer -> {
answer.setAnswerId(IdUtils.simpleUUID());
answer.setQuId(quId);
return answer;
});
//examQuestionAnswerMapper.insert(answerList);
examQuestionAnswerMapper.insertExamQuestionAnswerList(answerList);
}
if (fileUploads!=null&&fileUploads.size()>0){
fileUploads.replaceAll(fileUpload -> {
// 设置 fileId 和 quId
fileUpload.setFileId(IdUtils.simpleUUID());
fileUpload.setQuId(quId);
if (fileUploads != null && fileUploads.size() > 0) {
fileUploads.replaceAll(fileUpload -> {
// 设置 fileId 和 quId
fileUpload.setFileId(IdUtils.simpleUUID());
fileUpload.setQuId(quId);
return fileUpload;
});
sysFileMapper.insertSysFileList(fileUploads);
return fileUpload;
});
sysFileMapper.insertSysFileList(fileUploads);
}
if (questionScores != null) {
questionScores.setScoreId(IdUtils.simpleUUID());
questionScores.setQuId(quId);
examQuestionScoreMapper.insertExamQuestionScore(questionScores);
}
if (questionKeywords != null && questionKeywords.size() > 0) {
questionKeywords.replaceAll(examQuestionKeyword -> {
examQuestionKeyword.setKeywordId(IdUtils.simpleUUID());
examQuestionKeyword.setQuId(quId);
return examQuestionKeyword;
});
examQuestionKeywordMapper.insertExamQuestionKeywordList(questionKeywords);
}
}
//有就是覆盖
else {
examQuestion.setQuId(question.getQuId());
examQuestion.setQuNum(question.getQuNum());
String quId = question.getQuId();
examQuestionAnswerMapper.deleteExamQuestionAnswerByQuesId(quId);
sysFileMapper.deleteSysFileByQuesId(quId);
examQuestionScoreMapper.deleteExamQuestionScoreByQuesId(quId);
examQuestionKeywordMapper.deleteExamQuestionScoreByQuesId(quId);
if (questionScores!=null){
questionScores.setScoreId(IdUtils.simpleUUID());
questionScores.setQuId(quId);
examQuestionScoreMapper.insertExamQuestionScore(questionScores);
//新增
List<ExamQuestionAnswer> answerList = examQuestion.getAnswerList();
List<SysFileUpload> fileUploads = examQuestion.getFileUploads();
ExamQuestionScore questionScores = examQuestion.getQuestionScores();
List<ExamQuestionKeyword> questionKeywords = examQuestion.getQuestionKeywords();
if (answerList != null && answerList.size() > 0) {
answerList.replaceAll(answer -> {
answer.setAnswerId(IdUtils.simpleUUID());
answer.setQuId(quId);
return answer;
});
//examQuestionAnswerMapper.insert(answerList);
examQuestionAnswerMapper.insertExamQuestionAnswerList(answerList);
}
if (fileUploads != null && fileUploads.size() > 0) {
fileUploads.replaceAll(fileUpload -> {
// 设置 fileId 和 quId
fileUpload.setFileId(IdUtils.simpleUUID());
fileUpload.setQuId(quId);
return fileUpload;
});
sysFileMapper.insertSysFileList(fileUploads);
}
if (questionScores != null) {
questionScores.setScoreId(IdUtils.simpleUUID());
questionScores.setQuId(quId);
examQuestionScoreMapper.insertExamQuestionScore(questionScores);
}
if (questionKeywords != null && questionKeywords.size() > 0) {
questionKeywords.replaceAll(examQuestionKeyword -> {
examQuestionKeyword.setKeywordId(IdUtils.simpleUUID());
examQuestionKeyword.setQuId(quId);
return examQuestionKeyword;
});
examQuestionKeywordMapper.insertExamQuestionKeywordList(questionKeywords);
}
}
if (questionKeywords!=null&&questionKeywords.size()>0){
questionKeywords.replaceAll(examQuestionKeyword -> {
examQuestionKeyword.setKeywordId(IdUtils.simpleUUID());
examQuestionKeyword.setQuId(quId);
return examQuestionKeyword;
});
examQuestionKeywordMapper.insertExamQuestionKeywordList(questionKeywords);
}
}
//有就是覆盖
else{
examQuestion.setQuId(question.getQuId());
examQuestion.setQuNum(question.getQuNum());
String quId = question.getQuId();
examQuestionAnswerMapper.deleteExamQuestionAnswerByQuesId(quId);
sysFileMapper.deleteSysFileByQuesId(quId);
examQuestionScoreMapper.deleteExamQuestionScoreByQuesId(quId);
examQuestionKeywordMapper.deleteExamQuestionScoreByQuesId(quId);
//新增
List<ExamQuestionAnswer> answerList = examQuestion.getAnswerList();
List<SysFileUpload> fileUploads = examQuestion.getFileUploads();
ExamQuestionScore questionScores = examQuestion.getQuestionScores();
List<ExamQuestionKeyword> questionKeywords = examQuestion.getQuestionKeywords();
if (answerList!=null&&answerList.size()>0){
answerList.replaceAll(answer -> {
answer.setAnswerId(IdUtils.simpleUUID());
answer.setQuId(quId);
return answer;
});
//examQuestionAnswerMapper.insert(answerList);
examQuestionAnswerMapper.insertExamQuestionAnswerList(answerList);
}
if (fileUploads!=null&&fileUploads.size()>0){
fileUploads.replaceAll(fileUpload -> {
// 设置 fileId 和 quId
fileUpload.setFileId(IdUtils.simpleUUID());
fileUpload.setQuId(quId);
return fileUpload;
});
sysFileMapper.insertSysFileList(fileUploads);
}
if (questionScores!=null){
questionScores.setScoreId(IdUtils.simpleUUID());
questionScores.setQuId(quId);
examQuestionScoreMapper.insertExamQuestionScore(questionScores);
}
if (questionKeywords!=null&&questionKeywords.size()>0){
questionKeywords.replaceAll(examQuestionKeyword -> {
examQuestionKeyword.setKeywordId(IdUtils.simpleUUID());
examQuestionKeyword.setQuId(quId);
return examQuestionKeyword;
});
examQuestionKeywordMapper.insertExamQuestionKeywordList(questionKeywords);
}
}
}
examQuestionMapper.insertOrUpdateList(examQuestions);
}
}
return true;
return true;
}
@@ -720,7 +712,7 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
// 1、判断上传题目数量
int quCount = rabbitMQSendInfoVO.getQuIds().size();
List<String> quIds = rabbitMQSendInfoVO.getQuIds();
if (quIds!=null&&quIds.size()>0){
if (quIds != null && quIds.size() > 0) {
for (String quId : quIds) {
QuestionExamineDO questionExamineDO = questionExamineMapper.selectById(quId);
@@ -730,24 +722,24 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
//查找试题答案
List<ExamQuestionAnswer> examQuestionAnswers = examQuestionAnswerMapper.selectExamQuestionAnswerByQuId(quId);
//查找试题文件
List<SysFileUpload> sysFileUploads =sysFileMapper.selectSysFileByQuid(quId);
List<SysFileUpload> sysFileUploads = sysFileMapper.selectSysFileByQuid(quId);
//查找试题判分
ExamQuestionScore examQuestionScore =examQuestionScoreMapper.selectExamQuestionScoreByQuId(quId);
ExamQuestionScore examQuestionScore = examQuestionScoreMapper.selectExamQuestionScoreByQuId(quId);
//获取试题关键字
List<ExamQuestionKeyword> examQuestionKeywords = examQuestionKeywordMapper.selectExamQuestionKeywordByQuId(quId);
if (examQuestion_obj!=null){
if (examQuestionAnswers!=null&&examQuestionAnswers.size()>0){
if (examQuestion_obj != null) {
if (examQuestionAnswers != null && examQuestionAnswers.size() > 0) {
examQuestion_obj.setAnswerList(examQuestionAnswers);
}
if (sysFileUploads!=null&&sysFileUploads.size()>0){
if (sysFileUploads != null && sysFileUploads.size() > 0) {
examQuestion_obj.setFileUploads(sysFileUploads);
}
if (examQuestionScore!=null){
if (examQuestionScore != null) {
examQuestion_obj.setQuestionScores(examQuestionScore);
}
if (examQuestionKeywords!=null&&examQuestionKeywords.size()>0){
if (examQuestionKeywords != null && examQuestionKeywords.size() > 0) {
examQuestion_obj.setQuestionKeywords(examQuestionKeywords);
}
}
@@ -772,8 +764,7 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
}
// 2. 遍历,逐个创建 or 更新
QueImportRespVO respVO = QueImportRespVO.builder().createUsernames(new ArrayList<>())
.updateUsernames(new ArrayList<>()).failureUsernames(new LinkedHashMap<>()).build();
QueImportRespVO respVO = QueImportRespVO.builder().createUsernames(new ArrayList<>()).updateUsernames(new ArrayList<>()).failureUsernames(new LinkedHashMap<>()).build();
list.forEach(importUser -> {
@@ -781,11 +772,11 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
// 校验,判断是否有不符合的原因
try {
//校验 是否有 专业课程题型
validateQueForCreateOrUpdate(importUser.getSpecialtyName(), importUser.getCourseName(),importUser.getSubjectName());
validateQueForCreateOrUpdate(importUser.getSpecialtyName(), importUser.getCourseName(), importUser.getSubjectName());
//检验是否有章节 知识点
validatePointsForCreateOrUpdate(importUser.getSpecialtyName(),importUser.getChapteridDictText(),importUser.getPointNames(),importUser);
validatePointsForCreateOrUpdate(importUser.getSpecialtyName(), importUser.getChapteridDictText(), importUser.getPointNames(), importUser);
//校验 选项
validateChoice(importUser.getA(),importUser.getB(),importUser.getC(),importUser.getD(),importUser.getAnswer());
validateChoice(importUser.getA(), importUser.getB(), importUser.getC(), importUser.getD(), importUser.getAnswer());
} catch (ServiceException ex) {
@@ -793,18 +784,20 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
return;
}
// 2.2.1 判断如果不存在,在进行插入
ExamQuestion examQuestionSelect = examQuestionMapper.selectByTypes(importUser.getSpecialtyName(),importUser.getCourseName(),importUser.getSubjectName(),importUser.getContent());
if (examQuestionSelect==null){
if ("选择题".equals(importUser.getSubjectName())){
ExamQuestion examQuestionSelect = examQuestionMapper.selectByTypes(importUser.getSpecialtyName(), importUser.getCourseName(), importUser.getSubjectName(), importUser.getContent());
if (examQuestionSelect == null) {
if ("选择题".equals(importUser.getSubjectName())) {
String quId = IdUtils.simpleUUID();
ExamQuestion examQuestion = new ExamQuestion();
Long loginTenantId = SecurityFrameworkUtils.getLoginTenantId();
int count= examQuestionMapper.selectCountQu();
int count = examQuestionMapper.selectCountQu();
// 读取系统创建试题位数设置
String number = configApi.getConfigValueByKey("qu_number");
// 格式化为8位不足前面补0
String formattedNumber = String.format("%08d", ++count);
String quNum =loginTenantId +"-"+formattedNumber;
String formattedNumber = String.format("%0" + number + "d", ++count);
String quNum = loginTenantId + "-" + formattedNumber;
examQuestion.setQuNum(quNum);
examQuestion.setChapteridDictText(importUser.getChapteridDictText());
@@ -831,8 +824,8 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
if (!StringUtils.isBlank(importUser.getD())) {
validAnswerMap.put("D", importUser.getD());
}
List<ExamQuestionAnswer> examQuestionAnswerList=new ArrayList<>();
int i=1;
List<ExamQuestionAnswer> examQuestionAnswerList = new ArrayList<>();
int i = 1;
for (Map.Entry<String, String> entry : validAnswerMap.entrySet()) {
String option = entry.getKey(); // A, B, C, D
String content = entry.getValue(); // 实际内容
@@ -858,27 +851,26 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
}
respVO.getCreateUsernames().add(importUser.getContent());
respVO.getCreateUsernames().add(importUser.getContent());
} else {
if ("选择题".equals(importUser.getSubjectName())) {
} else {
if ("选择题".equals(importUser.getSubjectName())){
String quId=examQuestionSelect.getQuId();
ExamQuestion examQuestion = new ExamQuestion();
examQuestion.setChapteridDictText(importUser.getChapteridDictText());
examQuestion.setSpecialtyName(importUser.getSpecialtyName());
examQuestion.setCourseName(importUser.getCourseName());
examQuestion.setSubjectName(importUser.getSubjectName());
examQuestion.setQuLevel(Integer.valueOf(importUser.getQuLevel()));
examQuestion.setContent(importUser.getContent());
examQuestion.setAnalysis(importUser.getAnalysis());
examQuestion.setPointNames(importUser.getPointNames());
examQuestion.setKeywords(importUser.getKeywords());
String quId = examQuestionSelect.getQuId();
ExamQuestion examQuestion = new ExamQuestion();
examQuestion.setChapteridDictText(importUser.getChapteridDictText());
examQuestion.setSpecialtyName(importUser.getSpecialtyName());
examQuestion.setCourseName(importUser.getCourseName());
examQuestion.setSubjectName(importUser.getSubjectName());
examQuestion.setQuLevel(Integer.valueOf(importUser.getQuLevel()));
examQuestion.setContent(importUser.getContent());
examQuestion.setAnalysis(importUser.getAnalysis());
examQuestion.setPointNames(importUser.getPointNames());
examQuestion.setKeywords(importUser.getKeywords());
examQuestion.setQuId(quId);
examQuestion.setUpdater(SecurityFrameworkUtils.getLoginUserNickname());
examQuestion.setUpdateTime(DateUtils.getNowLocalDateTime());
examQuestion.setUpdater(SecurityFrameworkUtils.getLoginUserNickname());
examQuestion.setUpdateTime(DateUtils.getNowLocalDateTime());
examQuestionMapper.updateById(examQuestion);
Map<String, String> validAnswerMap = new LinkedHashMap<>();
@@ -890,8 +882,8 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
if (!StringUtils.isBlank(importUser.getD())) {
validAnswerMap.put("D", importUser.getD());
}
List<ExamQuestionAnswer> examQuestionAnswerList=new ArrayList<>();
int i=1;
List<ExamQuestionAnswer> examQuestionAnswerList = new ArrayList<>();
int i = 1;
for (Map.Entry<String, String> entry : validAnswerMap.entrySet()) {
String option = entry.getKey(); // A, B, C, D
String content = entry.getValue(); // 实际内容
@@ -913,14 +905,13 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
}
// 保存到集合或数据库
examQuestionAnswerMapper.insertExamQuestionAnswerList(examQuestionAnswerList);
}
respVO.getUpdateUsernames().add(importUser.getContent());
}
});
respVO.getUpdateUsernames().add(importUser.getContent());
}
});
return respVO;
@@ -928,7 +919,7 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
@Override
public boolean changeStatus(String quId, String status) {
return examQuestionMapper.changeStatus(quId,status);
return examQuestionMapper.changeStatus(quId, status);
}
@Override
@@ -937,8 +928,7 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
List<ExamQuestion> list = examQuestionPageResult.getList();
List<ExamKnowledgePoints> examKnowledgePoints = knowledgePointsMapper.selectKnowledgePoints();
// 构造 ID → 名称映射
Map<Long, String> idNameMap = examKnowledgePoints.stream()
.collect(Collectors.toMap(ExamKnowledgePoints::getSpId, ExamKnowledgePoints::getSpName));
Map<Long, String> idNameMap = examKnowledgePoints.stream().collect(Collectors.toMap(ExamKnowledgePoints::getSpId, ExamKnowledgePoints::getSpName));
if (list != null && !list.isEmpty()) {
for (ExamQuestion examQuestion : list) {
@@ -961,13 +951,13 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
examQuestion.setChapteridDictTextVo(idNameMap.get(chapterId));
}
}
}catch (NumberFormatException e) {
} catch (NumberFormatException e) {
// 日志记录或跳过处理
System.err.println("ID格式错误" + e.getMessage());
}
if ("编程题".equals(examQuestion.getSubjectName())) {
ExamQuestion examQuestionNew = examQuestionService.selectExamQuestionByQuId(examQuestion.getQuId());
BeanUtils.copyProperties(examQuestionNew, examQuestion);
ExamQuestion examQuestionNew = examQuestionService.selectExamQuestionByQuId(examQuestion.getQuId());
BeanUtils.copyProperties(examQuestionNew, examQuestion);
}
if ("程序设计".equals(examQuestion.getSubjectName())) {
List<ExamQuestionAnswer> answerList = examQuestionService.getPointById(examQuestion.getQuId());
@@ -984,9 +974,7 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
if (!CollectionUtils.isEmpty(examQuestionAnswers)) {
for (ExamQuestionAnswer examQuestionAnswer : examQuestionAnswers) {
String answerId = examQuestionAnswer.getAnswerId();
List<ExamMysqlKeyword> newKeywordList = mysqlKeywordMapper.selectList(
new QueryWrapper<ExamMysqlKeyword>().eq("answer_id", answerId)
);
List<ExamMysqlKeyword> newKeywordList = mysqlKeywordMapper.selectList(new QueryWrapper<ExamMysqlKeyword>().eq("answer_id", answerId));
examQuestionAnswer.setExamMysqlKeywordList(newKeywordList);
}
}
@@ -1015,34 +1003,34 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
private void validateQueForCreateOrUpdate(String specialtyName, String courseName, String subjectName) {
// 校验专业课程题型
validateSpecCourseSub(specialtyName, courseName,subjectName);
validateSpecCourseSub(specialtyName, courseName, subjectName);
}
private void validatePointsForCreateOrUpdate(String specialtyName,String chapteridDictText, String pointNames,QuemportExcelVO quemportExcelVO) {
validateSpecPointsSub(specialtyName,chapteridDictText,pointNames,quemportExcelVO);
private void validatePointsForCreateOrUpdate(String specialtyName, String chapteridDictText, String pointNames, QuemportExcelVO quemportExcelVO) {
validateSpecPointsSub(specialtyName, chapteridDictText, pointNames, quemportExcelVO);
}
@VisibleForTesting
void validateSpecPointsSub(String specialtyName,String chapteridDictText, String pointNames,QuemportExcelVO quemportExcelVO) {
void validateSpecPointsSub(String specialtyName, String chapteridDictText, String pointNames, QuemportExcelVO quemportExcelVO) {
ExamKnowledgePoints examKnowledgePoints= examSpecialtyMapper.selectByPointsSub(specialtyName,chapteridDictText,pointNames);
if (examKnowledgePoints==null){
ExamKnowledgePoints examKnowledgePoints = examSpecialtyMapper.selectByPointsSub(specialtyName, chapteridDictText, pointNames);
if (examKnowledgePoints == null) {
throw exception(QESESTION_TYPE_POINTS_ERROR);
}else {
} else {
quemportExcelVO.setPointNames(String.valueOf(examKnowledgePoints.getSpId()));
quemportExcelVO.setChapteridDictText(String.valueOf(examKnowledgePoints.getParentId()));
}
}
@VisibleForTesting
void validateSpecCourseSub(String specialtyName, String courseName, String subjectName) {
void validateSpecCourseSub(String specialtyName, String courseName, String subjectName) {
ExamSpecialty examSpecialty= examSpecialtyMapper.selectBySpecCourseSub(specialtyName,courseName,subjectName);
if (examSpecialty==null){
throw exception(QESESTION_TYPE_ERROR);
}
ExamSpecialty examSpecialty = examSpecialtyMapper.selectBySpecCourseSub(specialtyName, courseName, subjectName);
if (examSpecialty == null) {
throw exception(QESESTION_TYPE_ERROR);
}
}
}

View File

@@ -202,16 +202,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</trim>
</insert>
<insert id="insertOrUpdateList">
INSERT INTO exam_question (qu_id, qu_bank_id,tname, qu_num,chapterId_dict_text, subject_name,specialty_name, course_name, qu_level, content, audit, status, content_text, analysis, point_names, keywords, manual)
INSERT INTO exam_question (qu_id, qu_bank_id,tname, qu_num,chapterId_dict_text, subject_name,specialty_name,
course_name, qu_level, content, audit, status, content_text, analysis, point_names, keywords, manual)
VALUES
<foreach collection="collection" item="item" separator=",">
(#{item.quId}, #{item.quBankId},#{item.tname},#{item.quNum}, #{item.chapteridDictText}, #{item.subjectName},
#{item.specialtyName}, #{item.courseName}, #{item.quLevel}, #{item.content}, #{item.audit}
, #{item.status}, #{item.contentText}, #{item.analysis}, #{item.pointNames}, #{item.keywords}, #{item.manual})
, #{item.status}, #{item.contentText}, #{item.analysis}, #{item.pointNames}, #{item.keywords},
#{item.manual})
</foreach>
ON DUPLICATE KEY UPDATE
tname== VALUES(tname),
tname = VALUES(tname),
chapterId_dict_text = VALUES(chapterId_dict_text),
subject_name = VALUES(subject_name),
specialty_name = VALUES(specialty_name),