【修改】 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

@@ -43,8 +43,7 @@ import static pc.exam.pp.module.system.enums.ErrorCodeConstants.*;
* @date 2025-03-13 * @date 2025-03-13
*/ */
@Service @Service
public class ExamQuestionServiceImpl implements IExamQuestionService public class ExamQuestionServiceImpl implements IExamQuestionService {
{
// @Autowired // @Autowired
// private ExamBankMapper examBankMapper; // private ExamBankMapper examBankMapper;
@Autowired @Autowired
@@ -73,6 +72,7 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
private IExamQuestionService examQuestionService; private IExamQuestionService examQuestionService;
@Autowired @Autowired
private ConfigApi configApi; private ConfigApi configApi;
/** /**
* 查询试题(hyc) * 查询试题(hyc)
* *
@@ -80,8 +80,7 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
* @return 试题(hyc) * @return 试题(hyc)
*/ */
@Override @Override
public ExamQuestion selectExamQuestionByQuId(String quId) public ExamQuestion selectExamQuestionByQuId(String quId) {
{
//查找试题答案 //查找试题答案
List<ExamQuestionAnswer> examQuestionAnswers = examQuestionAnswerMapper.selectExamQuestionAnswerByQuId(quId); List<ExamQuestionAnswer> examQuestionAnswers = examQuestionAnswerMapper.selectExamQuestionAnswerByQuId(quId);
//查找试题文件 //查找试题文件
@@ -131,8 +130,7 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
* @return 结果 * @return 结果
*/ */
@Override @Override
public int insertExamQuestion(ExamQuestion examQuestion) public int insertExamQuestion(ExamQuestion examQuestion) {
{
//更新题库的试题数 //更新题库的试题数
// if (examQuestion.getQuBankId()!=null){ // if (examQuestion.getQuBankId()!=null){
// UpdateQuCountNow(examQuestion.getQuBankId()); // UpdateQuCountNow(examQuestion.getQuBankId());
@@ -219,8 +217,7 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
*/ */
@Override @Override
@Transactional(rollbackFor = Exception.class) // 所有异常都回滚 @Transactional(rollbackFor = Exception.class) // 所有异常都回滚
public int updateExamQuestion(ExamQuestion examQuestion) public int updateExamQuestion(ExamQuestion examQuestion) {
{
List<ExamQuestionAnswer> answerList = examQuestion.getAnswerList(); List<ExamQuestionAnswer> answerList = examQuestion.getAnswerList();
List<SysFileUpload> fileUploads = examQuestion.getFileUploads(); List<SysFileUpload> fileUploads = examQuestion.getFileUploads();
@@ -338,9 +335,7 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
Set<String> usedIdSet = new HashSet<>(usedIds); Set<String> usedIdSet = new HashSet<>(usedIds);
// 找出未被使用的题目ID // 找出未被使用的题目ID
List<String> canDeleteIds = Arrays.stream(ids) List<String> canDeleteIds = Arrays.stream(ids).filter(id -> !usedIdSet.contains(id)).collect(Collectors.toList());
.filter(id -> !usedIdSet.contains(id))
.collect(Collectors.toList());
if (canDeleteIds.isEmpty()) { if (canDeleteIds.isEmpty()) {
// 全部试题都已被引用,不能删除 // 全部试题都已被引用,不能删除
return ("全部试题都已被引用,不能删除!"); return ("全部试题都已被引用,不能删除!");
@@ -363,9 +358,7 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
examQuestionMapper.deleteExamQuestionByQuIds(deleteIds); examQuestionMapper.deleteExamQuestionByQuIds(deleteIds);
if (!allCanBeDeleted) { if (!allCanBeDeleted) {
// 找出不能删除的ID // 找出不能删除的ID
List<String> cannotDeleteIds = Arrays.stream(ids) List<String> cannotDeleteIds = Arrays.stream(ids).filter(usedIdSet::contains).collect(Collectors.toList());
.filter(usedIdSet::contains)
.collect(Collectors.toList());
List<String> quNumList = examQuestionMapper.selectQuNumBuIds(cannotDeleteIds); List<String> quNumList = examQuestionMapper.selectQuNumBuIds(cannotDeleteIds);
return ("部分试题已参与组卷无法删除: " + quNumList); return ("部分试题已参与组卷无法删除: " + quNumList);
@@ -381,21 +374,18 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
* @return 结果 * @return 结果
*/ */
@Override @Override
public int deleteExamQuestionByQuId(String quId) public int deleteExamQuestionByQuId(String quId) {
{
return examQuestionMapper.deleteExamQuestionByQuId(quId); return examQuestionMapper.deleteExamQuestionByQuId(quId);
} }
@Override @Override
public PageResult<ExamQuestion> selectExamQuestionList(QuestionVo questionVo) { public PageResult<ExamQuestion> selectExamQuestionList(QuestionVo questionVo) {
PageResult<ExamQuestion> examQuestionPageResult = examQuestionMapper.selectExamQuestionList(questionVo); PageResult<ExamQuestion> examQuestionPageResult = examQuestionMapper.selectExamQuestionList(questionVo);
List<ExamQuestion> list = examQuestionPageResult.getList(); List<ExamQuestion> list = examQuestionPageResult.getList();
List<ExamKnowledgePoints> examKnowledgePoints = knowledgePointsMapper.selectKnowledgePoints(); List<ExamKnowledgePoints> examKnowledgePoints = knowledgePointsMapper.selectKnowledgePoints();
// 构造 ID → 名称映射 // 构造 ID → 名称映射
Map<Long, String> idNameMap = examKnowledgePoints.stream() Map<Long, String> idNameMap = examKnowledgePoints.stream().collect(Collectors.toMap(ExamKnowledgePoints::getSpId, ExamKnowledgePoints::getSpName));
.collect(Collectors.toMap(ExamKnowledgePoints::getSpId, ExamKnowledgePoints::getSpName));
for (ExamQuestion examQuestion : list) { for (ExamQuestion examQuestion : list) {
String pointIdStr = examQuestion.getPointNames(); String pointIdStr = examQuestion.getPointNames();
String chapterIdStr = examQuestion.getChapteridDictText(); String chapterIdStr = examQuestion.getChapteridDictText();
@@ -424,6 +414,7 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
/** /**
* 上传试题至Rabbitmq * 上传试题至Rabbitmq
*
* @param rabbitMQSendInfoVO 试题内容 * @param rabbitMQSendInfoVO 试题内容
* @return 结果 * @return 结果
*/ */
@@ -451,6 +442,7 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
/** /**
* 拉取数据Rabbitmq * 拉取数据Rabbitmq
*
* @param queueName 客户端ID * @param queueName 客户端ID
* @return 试题内容 * @return 试题内容
*/ */
@@ -509,8 +501,7 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
List<ExamKnowledgePoints> examKnowledgePoints = knowledgePointsMapper.selectKnowledgePoints(); List<ExamKnowledgePoints> examKnowledgePoints = knowledgePointsMapper.selectKnowledgePoints();
// 构造 ID → 名称映射 // 构造 ID → 名称映射
Map<Long, String> idNameMap = examKnowledgePoints.stream() Map<Long, String> idNameMap = examKnowledgePoints.stream().collect(Collectors.toMap(ExamKnowledgePoints::getSpId, ExamKnowledgePoints::getSpName));
.collect(Collectors.toMap(ExamKnowledgePoints::getSpId, ExamKnowledgePoints::getSpName));
if (list != null && list.size() > 0) { if (list != null && list.size() > 0) {
for (QuestionExamineDO questionExamineDO : list) { for (QuestionExamineDO questionExamineDO : list) {
String schoolName = questionExamineMapper.selectSchoolName(questionExamineDO.getSource()); String schoolName = questionExamineMapper.selectSchoolName(questionExamineDO.getSource());
@@ -584,7 +575,6 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
} }
public boolean getExamQuestionToRabbitMQInsertData(String queueName) { public boolean getExamQuestionToRabbitMQInsertData(String queueName) {
// 最先判断类型 // 最先判断类型
// TODO 1、拉取数据保存至数据库 2、回调服务器是否拉取成功中心服务器 // TODO 1、拉取数据保存至数据库 2、回调服务器是否拉取成功中心服务器
@@ -605,8 +595,10 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
examQuestion.setQuId(quId); examQuestion.setQuId(quId);
Long loginTenantId = SecurityFrameworkUtils.getLoginTenantId(); Long loginTenantId = SecurityFrameworkUtils.getLoginTenantId();
int count = examQuestionMapper.selectCountQu(); int count = examQuestionMapper.selectCountQu();
// 读取系统创建试题位数设置
String number = configApi.getConfigValueByKey("qu_number");
// 格式化为8位不足前面补0 // 格式化为8位不足前面补0
String formattedNumber = String.format("%08d", ++count); String formattedNumber = String.format("%0" + number + "d", ++count);
String quNum = loginTenantId + "-" + formattedNumber; String quNum = loginTenantId + "-" + formattedNumber;
examQuestion.setQuNum(quNum); examQuestion.setQuNum(quNum);
@@ -772,8 +764,7 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
} }
// 2. 遍历,逐个创建 or 更新 // 2. 遍历,逐个创建 or 更新
QueImportRespVO respVO = QueImportRespVO.builder().createUsernames(new ArrayList<>()) QueImportRespVO respVO = QueImportRespVO.builder().createUsernames(new ArrayList<>()).updateUsernames(new ArrayList<>()).failureUsernames(new LinkedHashMap<>()).build();
.updateUsernames(new ArrayList<>()).failureUsernames(new LinkedHashMap<>()).build();
list.forEach(importUser -> { list.forEach(importUser -> {
@@ -802,8 +793,10 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
Long loginTenantId = SecurityFrameworkUtils.getLoginTenantId(); Long loginTenantId = SecurityFrameworkUtils.getLoginTenantId();
int count = examQuestionMapper.selectCountQu(); int count = examQuestionMapper.selectCountQu();
// 读取系统创建试题位数设置
String number = configApi.getConfigValueByKey("qu_number");
// 格式化为8位不足前面补0 // 格式化为8位不足前面补0
String formattedNumber = String.format("%08d", ++count); String formattedNumber = String.format("%0" + number + "d", ++count);
String quNum = loginTenantId + "-" + formattedNumber; String quNum = loginTenantId + "-" + formattedNumber;
examQuestion.setQuNum(quNum); examQuestion.setQuNum(quNum);
@@ -861,7 +854,6 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
respVO.getCreateUsernames().add(importUser.getContent()); respVO.getCreateUsernames().add(importUser.getContent());
} else { } else {
if ("选择题".equals(importUser.getSubjectName())) { if ("选择题".equals(importUser.getSubjectName())) {
@@ -922,7 +914,6 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
}); });
return respVO; return respVO;
} }
@@ -937,8 +928,7 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
List<ExamQuestion> list = examQuestionPageResult.getList(); List<ExamQuestion> list = examQuestionPageResult.getList();
List<ExamKnowledgePoints> examKnowledgePoints = knowledgePointsMapper.selectKnowledgePoints(); List<ExamKnowledgePoints> examKnowledgePoints = knowledgePointsMapper.selectKnowledgePoints();
// 构造 ID → 名称映射 // 构造 ID → 名称映射
Map<Long, String> idNameMap = examKnowledgePoints.stream() Map<Long, String> idNameMap = examKnowledgePoints.stream().collect(Collectors.toMap(ExamKnowledgePoints::getSpId, ExamKnowledgePoints::getSpName));
.collect(Collectors.toMap(ExamKnowledgePoints::getSpId, ExamKnowledgePoints::getSpName));
if (list != null && !list.isEmpty()) { if (list != null && !list.isEmpty()) {
for (ExamQuestion examQuestion : list) { for (ExamQuestion examQuestion : list) {
@@ -984,9 +974,7 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
if (!CollectionUtils.isEmpty(examQuestionAnswers)) { if (!CollectionUtils.isEmpty(examQuestionAnswers)) {
for (ExamQuestionAnswer examQuestionAnswer : examQuestionAnswers) { for (ExamQuestionAnswer examQuestionAnswer : examQuestionAnswers) {
String answerId = examQuestionAnswer.getAnswerId(); String answerId = examQuestionAnswer.getAnswerId();
List<ExamMysqlKeyword> newKeywordList = mysqlKeywordMapper.selectList( List<ExamMysqlKeyword> newKeywordList = mysqlKeywordMapper.selectList(new QueryWrapper<ExamMysqlKeyword>().eq("answer_id", answerId));
new QueryWrapper<ExamMysqlKeyword>().eq("answer_id", answerId)
);
examQuestionAnswer.setExamMysqlKeywordList(newKeywordList); examQuestionAnswer.setExamMysqlKeywordList(newKeywordList);
} }
} }

View File

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