PaperBasicInfo
parent
7534893261
commit
82747a18ff
|
|
@ -0,0 +1,15 @@
|
|||
-- =====================================================================
|
||||
-- 变更说明:
|
||||
-- 1. paper_question_rel 表新增 score(分值, decimal(5,1), 非空, 默认0.0)
|
||||
-- 2. 存量数据回填:以试题库 question.score 初始化关系分值
|
||||
-- 变更时间: 2026-08-20
|
||||
-- =====================================================================
|
||||
|
||||
ALTER TABLE `paper_question_rel`
|
||||
ADD COLUMN `score` decimal(5, 1) NOT NULL DEFAULT 0.0 COMMENT '分值' AFTER `question_id`;
|
||||
|
||||
-- 存量数据回填(如无需保留历史分值可跳过)
|
||||
UPDATE `paper_question_rel` pqr
|
||||
JOIN `question` q ON pqr.`question_id` = q.`id`
|
||||
SET pqr.`score` = q.`score`
|
||||
WHERE pqr.`delete_enum` = 'false';
|
||||
|
|
@ -8,6 +8,8 @@ import io.swagger.annotations.ApiModelProperty;
|
|||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 试卷试题关系
|
||||
*/
|
||||
|
|
@ -31,4 +33,7 @@ public class PaperQuestionRelDO extends BaseEntity {
|
|||
|
||||
@ApiModelProperty("试题号")
|
||||
private Integer questionNum;
|
||||
|
||||
@ApiModelProperty("分值")
|
||||
private BigDecimal score;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -262,6 +262,7 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, PaperDO> implemen
|
|||
|
||||
// 创建试卷
|
||||
PaperDO paper = new PaperDO();
|
||||
paper.setPaperType(PaperTypeEnum.FIXED.getValue());
|
||||
paper.setPaperName(importDTO.getPaperName().trim());
|
||||
paper.setPaperTotalScore(importDTO.getPaperTotalScore());
|
||||
paper.setPaperPassScore(importDTO.getPaperPassScore());
|
||||
|
|
@ -280,6 +281,7 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, PaperDO> implemen
|
|||
PaperQuestionRelDO rel = new PaperQuestionRelDO();
|
||||
rel.setPaperId(paper.getId());
|
||||
rel.setQuestionId(questions.get(i).getId());
|
||||
rel.setScore(questions.get(i).getScore());
|
||||
rel.setQuestionNum(i + 1);
|
||||
InsertFieldDefaults.applyIgnoreOrgId(rel);
|
||||
rels.add(rel);
|
||||
|
|
@ -296,8 +298,9 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, PaperDO> implemen
|
|||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public PaperBasicInfoVO coursewareQuestionRule(PaperCoursewareQuestionRuleDTO dto) {
|
||||
// 1. 循环题型规则从关联课件下随机抽题,某题型数量不足直接报错
|
||||
List<Long> questionIds = new ArrayList<>();
|
||||
// 1. 循环题型规则从关联课件下随机抽题,某题型数量不足直接报错;按题型规则初始化关系(试题id+每题分值+试题号)
|
||||
List<PaperQuestionRelDO> rels = new ArrayList<>();
|
||||
int questionNum = 1;
|
||||
for (PaperConfigRuleDTO.QuestionTypeRule rule : dto.getQuestionTypeRuleList()) {
|
||||
List<Long> ids = questionMapper.listRandomQuestionIds(
|
||||
dto.getCoursewareManagementIdList(), rule.getQuestionType(), rule.getNum());
|
||||
|
|
@ -307,7 +310,14 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, PaperDO> implemen
|
|||
throw new IllegalArgumentException(
|
||||
typeDesc + "题数量不足:需要" + rule.getNum() + "道,当前仅有" + ids.size() + "道");
|
||||
}
|
||||
questionIds.addAll(ids);
|
||||
for (Long questionId : ids) {
|
||||
PaperQuestionRelDO rel = new PaperQuestionRelDO();
|
||||
rel.setQuestionId(questionId);
|
||||
rel.setQuestionNum(questionNum++);
|
||||
rel.setScore(rule.getScore());
|
||||
InsertFieldDefaults.applyIgnoreOrgId(rel);
|
||||
rels.add(rel);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 创建试卷(规则试卷,保存抽题规则)
|
||||
|
|
@ -321,16 +331,8 @@ public class PaperServiceImpl extends ServiceImpl<PaperMapper, PaperDO> implemen
|
|||
InsertFieldDefaults.applyIgnoreOrgId(paper);
|
||||
this.savePaper(paper);
|
||||
|
||||
// 3. 绑定试卷试题关系(含试题号)
|
||||
List<PaperQuestionRelDO> rels = new ArrayList<>(questionIds.size());
|
||||
for (int i = 0; i < questionIds.size(); i++) {
|
||||
PaperQuestionRelDO rel = new PaperQuestionRelDO();
|
||||
rel.setPaperId(paper.getId());
|
||||
rel.setQuestionId(questionIds.get(i));
|
||||
rel.setQuestionNum(i + 1);
|
||||
InsertFieldDefaults.applyIgnoreOrgId(rel);
|
||||
rels.add(rel);
|
||||
}
|
||||
// 3. 绑定试卷试题关系(回填试卷id后批量保存)
|
||||
rels.forEach(rel -> rel.setPaperId(paper.getId()));
|
||||
Db.saveBatch(rels);
|
||||
return paperConvertor.convertEToBasicVo(paper);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
<mapper namespace="org.qinan.cedu.mapper.QuestionMapper">
|
||||
|
||||
<select id="pagePaperQuestions" resultType="org.qinan.cedu.model.vo.PaperQuestionVO">
|
||||
SELECT q.id, q.title, q.score, q.answer_question_option_ids, q.analysis
|
||||
SELECT q.id, q.title, pqr.score, q.answer_question_option_ids, q.analysis
|
||||
, q.question_type, q.tag_type, pqr.question_num,q.answer
|
||||
, cm.courseware_name
|
||||
FROM paper_question_rel pqr
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ CREATE TABLE `paper_question_rel`
|
|||
`id` bigint NOT NULL COMMENT 'id',
|
||||
`paper_id` bigint NOT NULL COMMENT '试卷id',
|
||||
`question_id` bigint NOT NULL COMMENT '试题id',
|
||||
`score` decimal(5, 1) NOT NULL DEFAULT 0.0 COMMENT '分值',
|
||||
`delete_enum` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '删除标识true false',
|
||||
`remarks` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '备注',
|
||||
`create_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '创建人姓名',
|
||||
|
|
|
|||
Loading…
Reference in New Issue