题库管理和试卷管理代码提交

main
hujunpeng 4 months ago
parent b9a36ce057
commit d3f6fb7f51
  1. 5
      ccic-entity/src/main/java/com/ccic/safeliab/entity/PaperQuestion.java
  2. 15
      ccic-exam/src/main/java/com/ccic/safeliab/dao/ExamPaperMapper.java
  3. 24
      ccic-exam/src/main/java/com/ccic/safeliab/dao/PaperQuestionMapper.java
  4. 30
      ccic-exam/src/main/java/com/ccic/safeliab/service/ExamPaperService.java
  5. 70
      ccic-exam/src/main/java/com/ccic/safeliab/service/ExamPaperServiceImpl.java
  6. 34
      ccic-exam/src/main/java/com/ccic/safeliab/service/PaperQuestionService.java
  7. 51
      ccic-exam/src/main/java/com/ccic/safeliab/service/PaperQuestionServiceImpl.java
  8. 3
      ccic-exam/src/main/java/com/ccic/safeliab/service/QuestionServiceImpl.java
  9. 4
      ccic-exam/src/main/java/com/ccic/safeliab/vo/InsExamPaperVO.java
  10. 60
      ccic-exam/src/main/java/com/ccic/safeliab/web/ExamPaperController.java
  11. 9
      ccic-exam/src/main/java/com/ccic/safeliab/web/QuestionController.java
  12. 56
      ccic-exam/src/main/resources/mappers/ExamPaperMapper.xml
  13. 8
      ccic-exam/src/main/resources/mappers/PaperQuestionMapper.xml

@ -40,4 +40,9 @@ public class PaperQuestion extends BaseEntity implements Serializable {
* 题目 ID外键关联题库管理表(ex_question_categories.id)
*/
private Long questionId;
/**
* 题目编号
*/
private Integer questionNumber;
}

@ -43,13 +43,21 @@ public interface ExamPaperMapper extends BaseMapper<ExamPapers> {
@Param("paperName") String paperName);
/**
* 查询当题目详情
* 试卷详情
*
* @param id 监管行业
* @return 题目详情
* @param id ID
* @return 试卷详情
*/
ExamPapers getDetail(@Param("id") Long id);
/**
* 试卷详情(试题)
*
* @param id ID
* @return 试卷详情
*/
List<QuestionCategories> getQuestions(@Param("id") Long id);
/**
* 随机获取题目
*
@ -60,4 +68,5 @@ public interface ExamPaperMapper extends BaseMapper<ExamPapers> {
List<QuestionCategories> getRandomQuestions(
@Param("industryId") Long industryId,
@Param("questionCount") Integer questionCount);
}

@ -0,0 +1,24 @@
package com.ccic.safeliab.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ccic.safeliab.entity.PaperQuestion;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* Mapper 接口
*
* @author Chill
*/
@Mapper
public interface PaperQuestionMapper extends BaseMapper<PaperQuestion> {
/**
* 删除试卷的所有试题
*
* @param id 试卷id
* @return 删除件数
*/
boolean deletePaperALlQuestion(@Param("id") Long id);
}

@ -49,26 +49,12 @@ public interface ExamPaperService extends BaseService<ExamPapers> {
*/
boolean batchUpdatePaperStatus(List<InsExamPaperVO> vos);
/**
* 添加试题
* @param vo 试题 VO 列表
* @return 添加是否成功
*/
int add(List<InsExamPaperVO> vo);
/**
* 修改试题
* @param vo 试题 VO 列表
* @return 添加是否成功
*/
boolean update(InsExamPaperVO vo);
/**
* 获取试卷列表
* @param id 题目ID
* @return 题目详情
*/
ExamPapers getDetail(String id);
Map<String, Object> getDetail(String id);
/**
* 随机获取题目
@ -76,4 +62,18 @@ public interface ExamPaperService extends BaseService<ExamPapers> {
* @return 试卷列表
*/
List<QuestionCategories> getRandomQuestions(ExamPapers entity);
/**
* 添加试卷
* @param vo 试卷
* @return 添加是否成功
*/
ExamPapers add(InsExamPaperVO vo);
/**
* 修改试题
* @param vo 试题 VO 列表
* @return 添加是否成功
*/
ExamPapers update(InsExamPaperVO vo);
}

@ -4,6 +4,7 @@ import com.ccic.safeliab.dao.ExamPaperMapper;
import com.ccic.safeliab.entity.*;
import com.ccic.safeliab.support.BaseServiceImpl;
import com.ccic.safeliab.vo.InsExamPaperVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -13,8 +14,12 @@ import java.util.List;
import java.util.Map;
@Service
@Transactional
public class ExamPaperServiceImpl extends BaseServiceImpl<ExamPaperMapper, ExamPapers> implements ExamPaperService {
@Autowired
private PaperQuestionService paperQuestionService;
@Override
public Map<String, Object> getList(int page,int num, ExamPapers entity) {
int offset = (page - 1) * num;
@ -35,18 +40,33 @@ public class ExamPaperServiceImpl extends BaseServiceImpl<ExamPaperMapper, ExamP
@Override
public boolean deleteExamPaperById(Long id) {
boolean flag = false;
List<Long> ids = new ArrayList<>();
ids.add(id);
return deleteLogic(ids);
flag = deleteLogic(ids);
if(flag){
flag = paperQuestionService.delete(id);
}
return flag;
}
@Override
public boolean deleteExamPaperListByIds(List<Long> ids) {
return deleteLogic(ids);
boolean flag = false;
flag = deleteLogic(ids);
if(flag){
for(Long id : ids){
flag = paperQuestionService.delete(id);
if(!flag){
break;
}
}
}
return flag;
}
@Override
@Transactional
public boolean updatePaperStatus(InsExamPaperVO vo) {
ExamPapers entity = baseMapper.getDetail(vo.getId());
if(vo.getPaperStatus()==0){
@ -58,7 +78,6 @@ public class ExamPaperServiceImpl extends BaseServiceImpl<ExamPaperMapper, ExamP
}
@Override
@Transactional
public boolean batchUpdatePaperStatus(List<InsExamPaperVO> vos) {
boolean flag = false;
for(InsExamPaperVO vo : vos){
@ -68,22 +87,49 @@ public class ExamPaperServiceImpl extends BaseServiceImpl<ExamPaperMapper, ExamP
}
@Override
public int add(List<InsExamPaperVO> vo) {
return 0;
public Map<String, Object> getDetail(String id){
Map<String, Object> map = new HashMap<>();
ExamPapers head = baseMapper.getDetail(Long.valueOf(id));
List<QuestionCategories> detail = baseMapper.getQuestions(Long.valueOf(id));
map.put("head", head);
map.put("data", detail);
return map;
}
@Override
public boolean update(InsExamPaperVO vo) {
return true;
public List<QuestionCategories> getRandomQuestions(ExamPapers entity) {
return baseMapper.getRandomQuestions(entity.getIndustryId(), entity.getQuestionCount());
}
@Override
public ExamPapers getDetail(String id){
return baseMapper.getDetail(Long.valueOf(id));
public ExamPapers add(InsExamPaperVO vo){
// 试卷
ExamPapers examPapers = new ExamPapers();
examPapers.setPaperName(vo.getPaperName());
examPapers.setIndustryId(vo.getIndustryId());
examPapers.setQuestionCount(vo.getQuestionCount());
examPapers.setTotalScore(vo.getTotalScore());
examPapers.setExamDuration(vo.getExamDuration());
examPapers.setDurationType(vo.getDurationType());
examPapers.setPaperContent(vo.getPaperContent());
examPapers.setPaperStatus(1);
save(examPapers);
return examPapers;
}
@Override
public List<QuestionCategories> getRandomQuestions(ExamPapers entity) {
return baseMapper.getRandomQuestions(entity.getIndustryId(), entity.getQuestionCount());
public ExamPapers update(InsExamPaperVO vo) {
// 试卷
ExamPapers examPapers = new ExamPapers();
examPapers.setId(vo.getId());
examPapers.setPaperName(vo.getPaperName());
examPapers.setIndustryId(vo.getIndustryId());
examPapers.setQuestionCount(vo.getQuestionCount());
examPapers.setTotalScore(vo.getTotalScore());
examPapers.setExamDuration(vo.getExamDuration());
examPapers.setDurationType(vo.getDurationType());
examPapers.setPaperContent(vo.getPaperContent());
updateById(examPapers);
return examPapers;
}
}

@ -0,0 +1,34 @@
package com.ccic.safeliab.service;
import com.ccic.safeliab.entity.PaperQuestion;
import com.ccic.safeliab.support.BaseService;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public interface PaperQuestionService extends BaseService<PaperQuestion> {
/**
* 添加试卷试题关系
* @param paperID 试卷ID
* @param QuestionIds 题目ID集合
* @return 添加是否成功
*/
int add(Long paperID, List<String> QuestionIds);
/**
* 删除试卷试题关系
* @param paperID 试卷ID
* @return 添加是否成功
*/
boolean delete(Long paperID);
/**
* 更新试卷试题关系
* @param paperID 试卷ID
* @param QuestionIds 题目ID集合
* @return 添加是否成功
*/
int update(Long paperID, List<String> QuestionIds);
}

@ -0,0 +1,51 @@
package com.ccic.safeliab.service;
import com.ccic.safeliab.dao.PaperQuestionMapper;
import com.ccic.safeliab.entity.*;
import com.ccic.safeliab.support.BaseServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service
@Transactional
public class PaperQuestionServiceImpl extends BaseServiceImpl<PaperQuestionMapper, PaperQuestion> implements PaperQuestionService {
@Override
public int add(Long paperID, List<String> QuestionIds){
int number = 0;
for(String QuestionId : QuestionIds){
number++;
PaperQuestion paperQuestion = new PaperQuestion();
paperQuestion.setPaperId(paperID);
paperQuestion.setQuestionId(Long.valueOf(QuestionId));
paperQuestion.setQuestionNumber(number);
save(paperQuestion);
}
return number;
}
@Override
public boolean delete(Long paperID){
return baseMapper.deletePaperALlQuestion(paperID);
}
@Override
public int update(Long paperID, List<String> QuestionIds){
baseMapper.deletePaperALlQuestion(paperID);
int number = 0;
for(String QuestionId : QuestionIds){
number++;
PaperQuestion paperQuestion = new PaperQuestion();
paperQuestion.setPaperId(paperID);
paperQuestion.setQuestionId(Long.valueOf(QuestionId));
paperQuestion.setQuestionNumber(number);
save(paperQuestion);
}
return number;
}
}

@ -13,6 +13,7 @@ import java.util.List;
import java.util.Map;
@Service
@Transactional
public class QuestionServiceImpl extends BaseServiceImpl<QuestionMapper, QuestionCategories> implements QuestionService {
@Override
@ -48,7 +49,6 @@ public class QuestionServiceImpl extends BaseServiceImpl<QuestionMapper, Questio
}
@Override
@Transactional
public int add(List<InsQuestionVO> vo) {
int count =0;
for(InsQuestionVO item :vo){
@ -59,7 +59,6 @@ public class QuestionServiceImpl extends BaseServiceImpl<QuestionMapper, Questio
}
@Override
@Transactional
public boolean update(InsQuestionVO vo) {
return updateById(convertToEntity(vo));
}

@ -4,6 +4,8 @@ import com.ccic.safeliab.entity.ExamPapers;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
/**
* 值对象VO用于在不同层之间传递题目相关数据
* 该类的属性与数据库中题目表的字段相对应以满足数据传输需求
@ -15,6 +17,8 @@ public class InsExamPaperVO extends ExamPapers {
private int num;
// 页码
private int page;
// 试题ID
List<String> questionIds;
}

@ -3,6 +3,7 @@ package com.ccic.safeliab.web;
import com.ccic.safeliab.entity.ExamPapers;
import com.ccic.safeliab.entity.QuestionCategories;
import com.ccic.safeliab.service.ExamPaperService;
import com.ccic.safeliab.service.PaperQuestionService;
import com.ccic.safeliab.util.R;
import com.ccic.safeliab.vo.InsExamPaperVO;
import org.springframework.beans.factory.annotation.Autowired;
@ -18,6 +19,9 @@ public class ExamPaperController {
@Autowired
private ExamPaperService examPaperService;
@Autowired
private PaperQuestionService paperQuestionService;
/**
* 获取试卷
* @param vo 试卷对象VO
@ -37,8 +41,8 @@ public class ExamPaperController {
*/
@GetMapping("/delete")
public R delete(String id) {
boolean resultFlg = examPaperService.deleteExamPaperById(Long.valueOf((id)));
return R.ok().data(resultFlg);
boolean flag = examPaperService.deleteExamPaperById(Long.valueOf((id)));
return R.ok().data(flag);
}
/**
@ -46,8 +50,8 @@ public class ExamPaperController {
*/
@PostMapping("/deleteList")
public R deleteList(@RequestBody List<Long> ids) {
boolean resultFlg = examPaperService.deleteExamPaperListByIds(ids);
return R.ok().data(resultFlg);
boolean flag = examPaperService.deleteExamPaperListByIds(ids);
return R.ok().data(flag);
}
/**
@ -69,41 +73,43 @@ public class ExamPaperController {
}
/**
* 添加试卷
* 随机获取试题
* @param vo 题库对象VO
* @return 查询结果
*/
@PostMapping("/add")
public R add(@RequestBody List<InsExamPaperVO> vo) {
return R.ok().data(examPaperService.add(vo));
@PostMapping("/getRandomQuestions")
public R getRandomQuestions(@RequestBody InsExamPaperVO vo) {
ExamPapers entity = new ExamPapers();
entity.setIndustryId(vo.getIndustryId());
entity.setQuestionCount(vo.getQuestionCount());
List<QuestionCategories> data = examPaperService.getRandomQuestions(entity);
return R.ok().data(data);
}
/**
* 修改试卷
* 试卷详情
*/
@PostMapping("/update")
public R add(@RequestBody InsExamPaperVO vo) {
return R.ok().data(examPaperService.update(vo));
@GetMapping("/getDetail")
public R getDetail(String id) {
Map<String, Object> data = examPaperService.getDetail(id);
return R.ok().data(data);
}
/**
* 题目详情
* 添加试卷
*/
@GetMapping("/getDetail")
public R getDetail(String id) {
ExamPapers data = examPaperService.getDetail(id);
return R.ok().data(data);
@PostMapping("/add")
public R add(@RequestBody InsExamPaperVO vo) {
ExamPapers examPapers = examPaperService.add(vo);
return R.ok().data(paperQuestionService.add(examPapers.getId(), vo.getQuestionIds()));
}
/**
* 随机获取试题
* @param vo 题库对象VO
* @return 查询结果
* 修改试卷
*/
@PostMapping("/getRandomQuestions")
public R getRandomQuestions(@RequestBody InsExamPaperVO vo) {
ExamPapers entity = new ExamPapers();
entity.setIndustryId(vo.getIndustryId());
entity.setQuestionCount(vo.getQuestionCount());
List<QuestionCategories> data = examPaperService.getRandomQuestions(entity);
return R.ok().data(data);
@PostMapping("/update")
public R update(@RequestBody InsExamPaperVO vo) {
ExamPapers examPapers =examPaperService.update(vo);
return R.ok().data(paperQuestionService.update(examPapers.getId(), vo.getQuestionIds()));
}
}

@ -67,15 +67,6 @@ public class QuestionController {
return R.ok().data(questionService.update(vo));
}
/**
* 更新试题
*/
@GetMapping("/update")
public boolean update(@RequestParam InsQuestionVO vo) {
// return questionService.updateQuestion(add);
return true;
}
/**
* 行业查询
* @return 行业

@ -60,6 +60,25 @@
</if>
</where>
</select>
<select id="getRandomQuestions" resultMap="QuestionCategoriesResultMap">
SELECT
id,
question_types,
industry_id,
service_type_id,
question_content,
answer,
options
FROM ex_question_categories
<where>
is_deleted = '0'
<if test="industryId!= null and industryId!= ''">
AND industry_id = #{industryId}
</if>
</where>
ORDER BY RANDOM()
LIMIT #{questionCount};
</select>
<select id="getDetail" resultMap="ExamPapersResultMap">
SELECT
id
@ -79,23 +98,32 @@
</if>
</where>
</select>
<select id="getRandomQuestions" resultMap="QuestionCategoriesResultMap">
<select id="getQuestions" resultMap="QuestionCategoriesResultMap">
SELECT
id,
question_types,
industry_id,
service_type_id,
question_content,
answer,
options
FROM ex_question_categories
qc.id
, qc.question_types
, qc.industry_id
, qc.service_type_id
, qc.question_content
, qc.answer
, qc.options
FROM
ex_exam_papers ep
inner join ex_paper_questions pq
on pq.paper_id = ep.id
and pq.is_deleted = 0
inner join ex_question_categories qc
on qc.id = pq.question_id
and qc.is_deleted = 0
<where>
is_deleted = '0'
<if test="industryId!= null and industryId!= ''">
AND industry_id = #{industryId}
ep.is_deleted = '0'
<if test="id!= null and id!= ''">
AND ep.id = #{id}
</if>
</where>
ORDER BY RANDOM()
LIMIT #{questionCount};
</select>
<delete id="deletePaperALlQuestion">
DELETE FROM ex_paper_questions
WHERE paper_id = #{id}
</delete>
</mapper>

@ -0,0 +1,8 @@
<?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.ccic.safeliab.dao.PaperQuestionMapper">
<delete id="deletePaperALlQuestion">
DELETE FROM ex_paper_questions
WHERE paper_id = #{id}
</delete>
</mapper>
Loading…
Cancel
Save