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

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) * 题目 ID外键关联题库管理表(ex_question_categories.id)
*/ */
private Long questionId; private Long questionId;
/**
* 题目编号
*/
private Integer questionNumber;
} }

@ -43,13 +43,21 @@ public interface ExamPaperMapper extends BaseMapper<ExamPapers> {
@Param("paperName") String paperName); @Param("paperName") String paperName);
/** /**
* 查询当题目详情 * 试卷详情
* *
* @param id 监管行业 * @param id ID
* @return 题目详情 * @return 试卷详情
*/ */
ExamPapers getDetail(@Param("id") Long id); 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( List<QuestionCategories> getRandomQuestions(
@Param("industryId") Long industryId, @Param("industryId") Long industryId,
@Param("questionCount") Integer questionCount); @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); 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 * @param id 题目ID
* @return 题目详情 * @return 题目详情
*/ */
ExamPapers getDetail(String id); Map<String, Object> getDetail(String id);
/** /**
* 随机获取题目 * 随机获取题目
@ -76,4 +62,18 @@ public interface ExamPaperService extends BaseService<ExamPapers> {
* @return 试卷列表 * @return 试卷列表
*/ */
List<QuestionCategories> getRandomQuestions(ExamPapers entity); 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.entity.*;
import com.ccic.safeliab.support.BaseServiceImpl; import com.ccic.safeliab.support.BaseServiceImpl;
import com.ccic.safeliab.vo.InsExamPaperVO; import com.ccic.safeliab.vo.InsExamPaperVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -13,8 +14,12 @@ import java.util.List;
import java.util.Map; import java.util.Map;
@Service @Service
@Transactional
public class ExamPaperServiceImpl extends BaseServiceImpl<ExamPaperMapper, ExamPapers> implements ExamPaperService { public class ExamPaperServiceImpl extends BaseServiceImpl<ExamPaperMapper, ExamPapers> implements ExamPaperService {
@Autowired
private PaperQuestionService paperQuestionService;
@Override @Override
public Map<String, Object> getList(int page,int num, ExamPapers entity) { public Map<String, Object> getList(int page,int num, ExamPapers entity) {
int offset = (page - 1) * num; int offset = (page - 1) * num;
@ -35,18 +40,33 @@ public class ExamPaperServiceImpl extends BaseServiceImpl<ExamPaperMapper, ExamP
@Override @Override
public boolean deleteExamPaperById(Long id) { public boolean deleteExamPaperById(Long id) {
boolean flag = false;
List<Long> ids = new ArrayList<>(); List<Long> ids = new ArrayList<>();
ids.add(id); ids.add(id);
return deleteLogic(ids); flag = deleteLogic(ids);
if(flag){
flag = paperQuestionService.delete(id);
}
return flag;
} }
@Override @Override
public boolean deleteExamPaperListByIds(List<Long> ids) { 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 @Override
@Transactional
public boolean updatePaperStatus(InsExamPaperVO vo) { public boolean updatePaperStatus(InsExamPaperVO vo) {
ExamPapers entity = baseMapper.getDetail(vo.getId()); ExamPapers entity = baseMapper.getDetail(vo.getId());
if(vo.getPaperStatus()==0){ if(vo.getPaperStatus()==0){
@ -58,7 +78,6 @@ public class ExamPaperServiceImpl extends BaseServiceImpl<ExamPaperMapper, ExamP
} }
@Override @Override
@Transactional
public boolean batchUpdatePaperStatus(List<InsExamPaperVO> vos) { public boolean batchUpdatePaperStatus(List<InsExamPaperVO> vos) {
boolean flag = false; boolean flag = false;
for(InsExamPaperVO vo : vos){ for(InsExamPaperVO vo : vos){
@ -68,22 +87,49 @@ public class ExamPaperServiceImpl extends BaseServiceImpl<ExamPaperMapper, ExamP
} }
@Override @Override
public int add(List<InsExamPaperVO> vo) { public Map<String, Object> getDetail(String id){
return 0; 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 @Override
public boolean update(InsExamPaperVO vo) { public List<QuestionCategories> getRandomQuestions(ExamPapers entity) {
return true; return baseMapper.getRandomQuestions(entity.getIndustryId(), entity.getQuestionCount());
} }
@Override @Override
public ExamPapers getDetail(String id){ public ExamPapers add(InsExamPaperVO vo){
return baseMapper.getDetail(Long.valueOf(id)); // 试卷
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 @Override
public List<QuestionCategories> getRandomQuestions(ExamPapers entity) { public ExamPapers update(InsExamPaperVO vo) {
return baseMapper.getRandomQuestions(entity.getIndustryId(), entity.getQuestionCount()); // 试卷
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; import java.util.Map;
@Service @Service
@Transactional
public class QuestionServiceImpl extends BaseServiceImpl<QuestionMapper, QuestionCategories> implements QuestionService { public class QuestionServiceImpl extends BaseServiceImpl<QuestionMapper, QuestionCategories> implements QuestionService {
@Override @Override
@ -48,7 +49,6 @@ public class QuestionServiceImpl extends BaseServiceImpl<QuestionMapper, Questio
} }
@Override @Override
@Transactional
public int add(List<InsQuestionVO> vo) { public int add(List<InsQuestionVO> vo) {
int count =0; int count =0;
for(InsQuestionVO item :vo){ for(InsQuestionVO item :vo){
@ -59,7 +59,6 @@ public class QuestionServiceImpl extends BaseServiceImpl<QuestionMapper, Questio
} }
@Override @Override
@Transactional
public boolean update(InsQuestionVO vo) { public boolean update(InsQuestionVO vo) {
return updateById(convertToEntity(vo)); return updateById(convertToEntity(vo));
} }

@ -4,6 +4,8 @@ import com.ccic.safeliab.entity.ExamPapers;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import java.util.List;
/** /**
* 值对象VO用于在不同层之间传递题目相关数据 * 值对象VO用于在不同层之间传递题目相关数据
* 该类的属性与数据库中题目表的字段相对应以满足数据传输需求 * 该类的属性与数据库中题目表的字段相对应以满足数据传输需求
@ -15,6 +17,8 @@ public class InsExamPaperVO extends ExamPapers {
private int num; private int num;
// 页码 // 页码
private int page; 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.ExamPapers;
import com.ccic.safeliab.entity.QuestionCategories; import com.ccic.safeliab.entity.QuestionCategories;
import com.ccic.safeliab.service.ExamPaperService; import com.ccic.safeliab.service.ExamPaperService;
import com.ccic.safeliab.service.PaperQuestionService;
import com.ccic.safeliab.util.R; import com.ccic.safeliab.util.R;
import com.ccic.safeliab.vo.InsExamPaperVO; import com.ccic.safeliab.vo.InsExamPaperVO;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -18,6 +19,9 @@ public class ExamPaperController {
@Autowired @Autowired
private ExamPaperService examPaperService; private ExamPaperService examPaperService;
@Autowired
private PaperQuestionService paperQuestionService;
/** /**
* 获取试卷 * 获取试卷
* @param vo 试卷对象VO * @param vo 试卷对象VO
@ -37,8 +41,8 @@ public class ExamPaperController {
*/ */
@GetMapping("/delete") @GetMapping("/delete")
public R delete(String id) { public R delete(String id) {
boolean resultFlg = examPaperService.deleteExamPaperById(Long.valueOf((id))); boolean flag = examPaperService.deleteExamPaperById(Long.valueOf((id)));
return R.ok().data(resultFlg); return R.ok().data(flag);
} }
/** /**
@ -46,8 +50,8 @@ public class ExamPaperController {
*/ */
@PostMapping("/deleteList") @PostMapping("/deleteList")
public R deleteList(@RequestBody List<Long> ids) { public R deleteList(@RequestBody List<Long> ids) {
boolean resultFlg = examPaperService.deleteExamPaperListByIds(ids); boolean flag = examPaperService.deleteExamPaperListByIds(ids);
return R.ok().data(resultFlg); return R.ok().data(flag);
} }
/** /**
@ -69,41 +73,43 @@ public class ExamPaperController {
} }
/** /**
* 添加试卷 * 随机获取试题
* @param vo 题库对象VO
* @return 查询结果
*/ */
@PostMapping("/add") @PostMapping("/getRandomQuestions")
public R add(@RequestBody List<InsExamPaperVO> vo) { public R getRandomQuestions(@RequestBody InsExamPaperVO vo) {
return R.ok().data(examPaperService.add(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") @GetMapping("/getDetail")
public R add(@RequestBody InsExamPaperVO vo) { public R getDetail(String id) {
return R.ok().data(examPaperService.update(vo)); Map<String, Object> data = examPaperService.getDetail(id);
return R.ok().data(data);
} }
/** /**
* 题目详情 * 添加试卷
*/ */
@GetMapping("/getDetail") @PostMapping("/add")
public R getDetail(String id) { public R add(@RequestBody InsExamPaperVO vo) {
ExamPapers data = examPaperService.getDetail(id); ExamPapers examPapers = examPaperService.add(vo);
return R.ok().data(data); return R.ok().data(paperQuestionService.add(examPapers.getId(), vo.getQuestionIds()));
} }
/** /**
* 随机获取试题 * 修改试卷
* @param vo 题库对象VO
* @return 查询结果
*/ */
@PostMapping("/getRandomQuestions") @PostMapping("/update")
public R getRandomQuestions(@RequestBody InsExamPaperVO vo) { public R update(@RequestBody InsExamPaperVO vo) {
ExamPapers entity = new ExamPapers(); ExamPapers examPapers =examPaperService.update(vo);
entity.setIndustryId(vo.getIndustryId()); return R.ok().data(paperQuestionService.update(examPapers.getId(), vo.getQuestionIds()));
entity.setQuestionCount(vo.getQuestionCount());
List<QuestionCategories> data = examPaperService.getRandomQuestions(entity);
return R.ok().data(data);
} }
} }

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

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