【修改】 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
*/
@Service
public class ExamQuestionServiceImpl implements IExamQuestionService
{
public class ExamQuestionServiceImpl implements IExamQuestionService {
// @Autowired
// private ExamBankMapper examBankMapper;
@Autowired
@@ -73,6 +72,7 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
private IExamQuestionService examQuestionService;
@Autowired
private ConfigApi configApi;
/**
* 查询试题(hyc)
*
@@ -80,8 +80,7 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
* @return 试题(hyc)
*/
@Override
public ExamQuestion selectExamQuestionByQuId(String quId)
{
public ExamQuestion selectExamQuestionByQuId(String quId) {
//查找试题答案
List<ExamQuestionAnswer> examQuestionAnswers = examQuestionAnswerMapper.selectExamQuestionAnswerByQuId(quId);
//查找试题文件
@@ -131,8 +130,7 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
* @return 结果
*/
@Override
public int insertExamQuestion(ExamQuestion examQuestion)
{
public int insertExamQuestion(ExamQuestion examQuestion) {
//更新题库的试题数
// if (examQuestion.getQuBankId()!=null){
// UpdateQuCountNow(examQuestion.getQuBankId());
@@ -219,8 +217,7 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
*/
@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();
@@ -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,9 +358,7 @@ 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> cannotDeleteIds = Arrays.stream(ids).filter(usedIdSet::contains).collect(Collectors.toList());
List<String> quNumList = examQuestionMapper.selectQuNumBuIds(cannotDeleteIds);
return ("部分试题已参与组卷无法删除: " + quNumList);
@@ -381,21 +374,18 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
* @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));
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 结果
*/
@@ -451,6 +442,7 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
/**
* 拉取数据Rabbitmq
*
* @param queueName 客户端ID
* @return 试题内容
*/
@@ -509,8 +501,7 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
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.size() > 0) {
for (QuestionExamineDO questionExamineDO : list) {
String schoolName = questionExamineMapper.selectSchoolName(questionExamineDO.getSource());
@@ -584,7 +575,6 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
}
public boolean getExamQuestionToRabbitMQInsertData(String queueName) {
// 最先判断类型
// TODO 1、拉取数据保存至数据库 2、回调服务器是否拉取成功中心服务器
@@ -605,8 +595,10 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
examQuestion.setQuId(quId);
Long loginTenantId = SecurityFrameworkUtils.getLoginTenantId();
int count = examQuestionMapper.selectCountQu();
// 读取系统创建试题位数设置
String number = configApi.getConfigValueByKey("qu_number");
// 格式化为8位不足前面补0
String formattedNumber = String.format("%08d", ++count);
String formattedNumber = String.format("%0" + number + "d", ++count);
String quNum = loginTenantId + "-" + formattedNumber;
examQuestion.setQuNum(quNum);
@@ -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 -> {
@@ -802,8 +793,10 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
Long loginTenantId = SecurityFrameworkUtils.getLoginTenantId();
int count = examQuestionMapper.selectCountQu();
// 读取系统创建试题位数设置
String number = configApi.getConfigValueByKey("qu_number");
// 格式化为8位不足前面补0
String formattedNumber = String.format("%08d", ++count);
String formattedNumber = String.format("%0" + number + "d", ++count);
String quNum = loginTenantId + "-" + formattedNumber;
examQuestion.setQuNum(quNum);
@@ -861,7 +854,6 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
respVO.getCreateUsernames().add(importUser.getContent());
} else {
if ("选择题".equals(importUser.getSubjectName())) {
@@ -922,7 +914,6 @@ public class ExamQuestionServiceImpl implements IExamQuestionService
});
return respVO;
}
@@ -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) {
@@ -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);
}
}

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),