src/main/java/com/mindskip/xzs/controller/admin/ExamTemplatesController.java
@@ -5,12 +5,15 @@ import com.mindskip.xzs.base.RestResponse; import com.mindskip.xzs.context.WebContext; import com.mindskip.xzs.domain.ExamTemplates; import com.mindskip.xzs.domain.ExamTemplatesConfig; import com.mindskip.xzs.domain.ExamTemplatesSubject; import com.mindskip.xzs.domain.vo.ExamTemplatesVO; import com.mindskip.xzs.repository.ExamTemplatesSubjectMapper; import com.mindskip.xzs.service.ExamPaperDepartmentService; import com.mindskip.xzs.service.ExamTemplatesConfigService; import com.mindskip.xzs.service.ExamTemplatesService; import com.mindskip.xzs.utility.PageInfoHelper; import com.mindskip.xzs.utility.minio.DateUtils; import com.mindskip.xzs.viewmodel.admin.exam.ExamPaperEditRequestVM; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.ObjectUtils; @@ -18,6 +21,7 @@ import javax.validation.Valid; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @RestController("AdminExamTemplatesController") @@ -26,6 +30,7 @@ public class ExamTemplatesController extends BaseApiController { private final ExamTemplatesService examTemplatesService; private final ExamTemplatesConfigService examTemplatesConfigService; private final ExamTemplatesSubjectMapper examTemplatesSubjectMapper; private final WebContext webContext; private final ExamPaperDepartmentService examPaperDepartmentService; @@ -70,10 +75,18 @@ return RestResponse.ok(); } // @RequestMapping(value = "/random", method = RequestMethod.POST) // public RestResponse<Integer> randomExam() throws Exception { // User user = getCurrentUser(); // Integer id = examTemplatesService.randomExam(user); // return RestResponse.ok(id); // } @PostMapping("/setConfig") public RestResponse<Boolean> setConfig(@RequestBody ExamTemplatesConfig examTemplatesConfig) { if (Objects.isNull(examTemplatesConfig.getId())) { examTemplatesConfig.setCreateUser(getCurrentUser().getId()); examTemplatesConfig.setCreateTime(DateUtils.getNowDate()); } return RestResponse.ok(examTemplatesConfigService.saveOrUpdate(examTemplatesConfig)); } @GetMapping("/getConfig") public RestResponse<ExamTemplatesConfig> getConfig() { return RestResponse.ok(examTemplatesConfigService.getConfig()); } } src/main/java/com/mindskip/xzs/domain/ExamTemplatesConfig.java
New file @@ -0,0 +1,46 @@ package com.mindskip.xzs.domain; import com.baomidou.mybatisplus.annotation.*; import lombok.Data; import java.io.Serializable; import java.util.Date; /** * 随机试卷配置表 * * @author gonghl */ @TableName(value = "t_exam_templates_config") @Data public class ExamTemplatesConfig implements Serializable { @TableId(type = IdType.AUTO) private Integer id; /** * 单选题 */ private Integer radioNum; /** * 多选题 */ private Integer checkNum; /** * 判断题 */ private Integer judgingNum; private Integer createUser; @OrderBy private Date createTime; @TableLogic private Integer deleted; @TableField(exist = false) private static final long serialVersionUID = 1L; } src/main/java/com/mindskip/xzs/repository/ExamTemplatesConfigMapper.java
New file @@ -0,0 +1,14 @@ package com.mindskip.xzs.repository; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.mindskip.xzs.domain.ExamTemplatesConfig; import org.apache.ibatis.annotations.Mapper; /** * @author gonghl */ @Mapper public interface ExamTemplatesConfigMapper extends BaseMapper<ExamTemplatesConfig> { } src/main/java/com/mindskip/xzs/repository/QuestionSubjectMapper.java
@@ -51,4 +51,7 @@ /** 根据课目和题型查找题目数据 */ List<QuestionVO> bySubjectIdAndQuestionType(Integer subjectId, Integer dataBaseValueByValue); /** 根据科目查询题目 **/ List<QuestionSubject> getSubjectBySubjectIds(Integer[] subjectIds); } src/main/java/com/mindskip/xzs/service/ExamTemplatesConfigService.java
New file @@ -0,0 +1,16 @@ package com.mindskip.xzs.service; import com.mindskip.xzs.domain.ExamTemplatesConfig; import com.baomidou.mybatisplus.extension.service.IService; /** * @author gonghl */ public interface ExamTemplatesConfigService extends IService<ExamTemplatesConfig> { /** * 获取随机试卷配置 * @return 结果 */ ExamTemplatesConfig getConfig(); } src/main/java/com/mindskip/xzs/service/QuestionSubjectService.java
@@ -43,4 +43,11 @@ Integer removeSubjectId(Integer subjectId); List<QuestionSubject> getSubject(Integer id); /** * 根据科目查询题目 * @param subjectIds 科目 * @return 题目 */ List<QuestionSubject> getSubjectBySubjectIds(Integer[] subjectIds); } src/main/java/com/mindskip/xzs/service/impl/ExamPaperServiceImpl.java
@@ -529,9 +529,10 @@ Integer order = 0; for (QuestionTypeVM questionTypeVM : questionTypeVMList) { List<Integer> questions = questionSubjectService.getSubject(questionTypeVM.getSubjectId()) List<Integer> questions = questionSubjectService.getSubjectBySubjectIds(examPaperEditRequestVM.getSubjectId()) .stream().map(QuestionSubject::getQuestionId).collect(Collectors.toList()); List<Question> list = questionService.selectByIds(questions); // List<Question> list = questionService.getAll(); Map<Integer, Integer> multiple = new HashMap<>(); //多选 src/main/java/com/mindskip/xzs/service/impl/ExamTemplatesConfigServiceImpl.java
New file @@ -0,0 +1,25 @@ package com.mindskip.xzs.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.mindskip.xzs.domain.ExamTemplatesConfig; import com.mindskip.xzs.repository.ExamTemplatesConfigMapper; import com.mindskip.xzs.service.ExamTemplatesConfigService; import org.springframework.stereotype.Service; /** * @author gonghl */ @Service public class ExamTemplatesConfigServiceImpl extends ServiceImpl<ExamTemplatesConfigMapper, ExamTemplatesConfig> implements ExamTemplatesConfigService { @Override public ExamTemplatesConfig getConfig() { return baseMapper.selectOne(new QueryWrapper<ExamTemplatesConfig>().last("limit 1")); } } src/main/java/com/mindskip/xzs/service/impl/ExamTemplatesServiceImpl.java
@@ -5,10 +5,7 @@ import com.mindskip.xzs.domain.*; import com.mindskip.xzs.domain.vo.ExamTemplatesVO; import com.mindskip.xzs.repository.*; import com.mindskip.xzs.service.DepartmentService; import com.mindskip.xzs.service.ExamPaperService; import com.mindskip.xzs.service.ExamTemplatesService; import com.mindskip.xzs.service.ExamTemplatesUserCountService; import com.mindskip.xzs.service.*; import com.mindskip.xzs.utility.convert.ExamTemplatesClassConvert; import com.mindskip.xzs.viewmodel.admin.exam.ExamPaperEditRequestVM; import com.mindskip.xzs.viewmodel.admin.exam.ExamPaperEditRequestVO; @@ -20,10 +17,7 @@ import org.springframework.util.CollectionUtils; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.*; import java.util.stream.Collectors; @Service @@ -37,8 +31,9 @@ private final ExamPaperService examPaperService; private final ExamTemplatesUserCountService examTemplatesUserCountService; private final ExamTemplatesUserMapper examTemplatesUserMapper; private final ExamTemplatesConfigService examTemplatesConfigService; public ExamTemplatesServiceImpl(BaseMapper<ExamTemplates> baseMapper, ExamTemplatesMapper examTemplatesMapper, ExamTemplatesQuestionMapper examTemplatesQuestionMapper, ExamTemplatesSubjectMapper examTemplatesSubjectMapper, DepartmentService departmentService, ExamPaperService examPaperService, ExamTemplatesUserCountService examTemplatesUserCountService, ExamTemplatesUserMapper examTemplatesUserMapper) { public ExamTemplatesServiceImpl(BaseMapper<ExamTemplates> baseMapper, ExamTemplatesMapper examTemplatesMapper, ExamTemplatesQuestionMapper examTemplatesQuestionMapper, ExamTemplatesSubjectMapper examTemplatesSubjectMapper, DepartmentService departmentService, ExamPaperService examPaperService, ExamTemplatesUserCountService examTemplatesUserCountService, ExamTemplatesUserMapper examTemplatesUserMapper, ExamTemplatesConfigService examTemplatesConfigService) { super(baseMapper); this.examTemplatesMapper = examTemplatesMapper; this.examTemplatesQuestionMapper = examTemplatesQuestionMapper; @@ -47,6 +42,7 @@ this.examPaperService = examPaperService; this.examTemplatesUserCountService = examTemplatesUserCountService; this.examTemplatesUserMapper = examTemplatesUserMapper; this.examTemplatesConfigService = examTemplatesConfigService; } @Transactional(rollbackFor = Exception.class) @@ -76,12 +72,8 @@ examTemplates.setCreateUser(model.getCreateUser()); examTemplatesMapper.add(examTemplates); List<ExamTemplatesQuestion> examTemplatesQuestions = ExamTemplatesClassConvert.INSTANCE.QuestionTypeVMListToExamTemplatesQuestionList(model.getQuestionTypeVMS()) .stream().map(e -> { e.setTemplatesId(examTemplates.getId()); return e; }).collect(Collectors.toList()); examTemplatesQuestionMapper.saves(examTemplatesQuestions); // 随机时间题目配置 examTemplatesQuestionMapper.add(getExamTemplatesQuestion(examTemplates.getId())); List<ExamTemplatesSubject> subjects = new ArrayList<>(); for (Integer e : model.getSubjectId()) { @@ -106,6 +98,17 @@ } } private ExamTemplatesQuestion getExamTemplatesQuestion(Integer templatesId) { ExamTemplatesConfig examTemplatesConfig = examTemplatesConfigService.getConfig(); if (Objects.isNull(examTemplatesConfig)) { throw new RuntimeException("请先配置试卷模板"); } ExamTemplatesQuestion examTemplatesQuestion = new ExamTemplatesQuestion(); examTemplatesQuestion.setSingleChoice(examTemplatesConfig.getRadioNum().toString()); examTemplatesQuestion.setMultipleChoice(examTemplatesConfig.getCheckNum().toString()); examTemplatesQuestion.setTrueFalse(examTemplatesConfig.getJudgingNum().toString()); examTemplatesQuestion.setTemplatesId(templatesId); return examTemplatesQuestion; } @Override public List<ExamTemplatesVO> list(ExamTemplatesVO examTemplatesVO) { return null; src/main/java/com/mindskip/xzs/service/impl/QuestionSubjectServiceImpl.java
@@ -55,5 +55,8 @@ return questionSubjectMapper.getSubject(id); } @Override public List<QuestionSubject> getSubjectBySubjectIds(Integer[] subjectIds) { return questionSubjectMapper.getSubjectBySubjectIds(subjectIds); } } src/main/resources/mapper/ExamTemplatesConfigMapper.xml
New file @@ -0,0 +1,20 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.mindskip.xzs.repository.ExamTemplatesConfigMapper"> <resultMap id="BaseResultMap" type="com.mindskip.xzs.domain.ExamTemplatesConfig"> <id property="id" column="id" jdbcType="INTEGER"/> <result property="radioNum" column="radio_num" jdbcType="INTEGER"/> <result property="checkNum" column="check_num" jdbcType="INTEGER"/> <result property="judgingNum" column="Judging_num" jdbcType="INTEGER"/> <result property="createUser" column="create_user" jdbcType="INTEGER"/> <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/> </resultMap> <sql id="Base_Column_List"> id,radio_num,check_num, Judging_num,create_user,create_time </sql> </mapper> src/main/resources/mapper/ExamTemplatesQuestionMapper.xml
@@ -16,7 +16,7 @@ </sql> <insert id="add" parameterType="com.mindskip.xzs.domain.ExamTemplatesQuestion" useGeneratedKeys="true" keyProperty="id"> insert into t_department (label, multiple_choice, single_choice, true_false, templates_id, subject_id) insert into t_exam_templates_question (label, multiple_choice, single_choice, true_false, templates_id, subject_id) values (#{label}, #{multipleChoice}, #{singleChoice}, #{trueFalse}, #{templatesId}, #{subjectId}) </insert> src/main/resources/mapper/QuestionSubjectMapper.xml
@@ -148,4 +148,17 @@ tq.id DESC </select> <select id="getSubjectBySubjectIds" resultType="com.mindskip.xzs.domain.QuestionSubject"> select qs.*,s.name as subName from t_question_subject qs left join t_subject s on qs.subject_id = s.id where qs.deleted = 0 and s.deleted = 0 <if test="subjectIds != null and subjectIds.length > 0"> and qs.subject_id in <foreach collection="subjectIds" item="subjectId" open="(" separator="," close=")"> #{subjectId} </foreach> </if> </select> </mapper>