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

main
hujunpeng 4 months ago
parent 6b861b8382
commit 5d9106f6c7
  1. 26
      ccic-exam/src/main/java/com/ccic/safeliab/dao/ExamPaperMapper.java
  2. 2
      ccic-exam/src/main/java/com/ccic/safeliab/dao/PaperQuestionMapper.java
  3. 67
      ccic-exam/src/main/java/com/ccic/safeliab/service/ExamPaperService.java
  4. 101
      ccic-exam/src/main/java/com/ccic/safeliab/service/ExamPaperServiceImpl.java
  5. 25
      ccic-exam/src/main/java/com/ccic/safeliab/service/PaperQuestionService.java
  6. 45
      ccic-exam/src/main/java/com/ccic/safeliab/service/PaperQuestionServiceImpl.java
  7. 23
      ccic-exam/src/main/java/com/ccic/safeliab/service/QuestionServiceImpl.java
  8. 25
      ccic-exam/src/main/java/com/ccic/safeliab/vo/InsExamPaperVO.java
  9. 36
      ccic-exam/src/main/java/com/ccic/safeliab/vo/InsQuestionVO.java
  10. 106
      ccic-exam/src/main/java/com/ccic/safeliab/web/ExamPaperController.java
  11. 1
      ccic-exam/src/main/java/com/ccic/safeliab/web/QuestionController.java
  12. 132
      ccic-exam/src/main/resources/mappers/ExamPaperMapper.xml
  13. 2
      ccic-exam/src/main/resources/mappers/PaperQuestionMapper.xml
  14. 21
      ccic-exam/src/main/resources/mappers/QuestionMapper.xml

@ -17,12 +17,12 @@ import java.util.List;
public interface ExamPaperMapper extends BaseMapper<ExamPapers> { public interface ExamPaperMapper extends BaseMapper<ExamPapers> {
/** /**
* 查询当前页数据 * 查询试卷
* *
* @param industryId 监管行业 * @param industryId 监管行业
* @param paperName 试卷名称 * @param paperName 试卷名称
* @param offset 偏移量 * @param offset 偏移量
* @param num 每页显示的记录 * @param num 每页数
* @return 当前页数据 * @return 当前页数据
*/ */
List<ExamPapers> getList( List<ExamPapers> getList(
@ -32,11 +32,11 @@ public interface ExamPaperMapper extends BaseMapper<ExamPapers> {
@Param("num") int num); @Param("num") int num);
/** /**
* 查询数量 * 查询试卷数量
* *
* @param industryId 监管行业 * @param industryId 监管行业
* @param paperName 试卷名称 * @param paperName 试卷名称
* @return 数量 * @return 试卷数量
*/ */
int getListSize( int getListSize(
@Param("industryId") Long industryId, @Param("industryId") Long industryId,
@ -45,10 +45,10 @@ public interface ExamPaperMapper extends BaseMapper<ExamPapers> {
/** /**
* 试卷详情 * 试卷详情
* *
* @param id ID * @param id 试卷ID
* @return 试卷详情 * @return 试卷详情
*/ */
ExamPapers getDetail(@Param("id") Long id); ExamPapers getExamPaperDetail(@Param("id") Long id);
/** /**
* 试卷详情(试题) * 试卷详情(试题)
@ -59,11 +59,11 @@ public interface ExamPaperMapper extends BaseMapper<ExamPapers> {
List<QuestionCategories> getQuestions(@Param("id") Long id); List<QuestionCategories> getQuestions(@Param("id") Long id);
/** /**
* 随机获取题 * 随机获取
* *
* @param industryId 监管行业 * @param industryId 监管行业
* @param questionCount 题目数量 * @param questionCount 题目数量
* @return 题目列表 * @return 题目
*/ */
List<QuestionCategories> getRandomQuestions( List<QuestionCategories> getRandomQuestions(
@Param("industryId") Long industryId, @Param("industryId") Long industryId,

@ -17,7 +17,7 @@ public interface PaperQuestionMapper extends BaseMapper<PaperQuestion> {
* 删除试卷的所有试题 * 删除试卷的所有试题
* *
* @param id 试卷id * @param id 试卷id
* @return 删除件数 * @return 删除结果
*/ */
boolean deletePaperALlQuestion(@Param("id") Long id); boolean deletePaperALlQuestion(@Param("id") Long id);

@ -11,69 +11,62 @@ import java.util.Map;
@Service @Service
public interface ExamPaperService extends BaseService<ExamPapers> { public interface ExamPaperService extends BaseService<ExamPapers> {
/** /**
* 获取试卷列表 * 获取试卷列表
* @param page 页码 *
* @param num 每页数量 * @param page 页码
* @param num 每页数量
* @param entity 试卷表 * @param entity 试卷表
* @return 试卷列表 * @return 试卷列表
*/ */
Map<String, Object> getList(int page, int num, ExamPapers entity); Map<String, Object> getList(int page, int num, ExamPapers entity);
/**
* 根据主键删除试卷记录
* @param id 试卷记录的主键
* @return 删除操作是否成功
*/
boolean deleteExamPaperById(Long id);
/** /**
* 根据主键批量删除试卷记录 * 删除试卷
* @param ids 试卷记录的主键列表 *
* @return 删除操作是否成功 * @param ids 试卷ID
* @return 删除结果
*/ */
boolean deleteExamPaperListByIds(List<Long> ids); boolean delExamPaper(List<Long> ids);
/** /**
* 更新试卷状态 * 更新试卷状态
* @param vo 试题 VO 列表 *
* @return 添加是否成功 * @param vo 试卷vo
* @return 更新结果
*/ */
boolean updatePaperStatus(InsExamPaperVO vo); boolean upPaperStatus(InsExamPaperVO vo);
/** /**
* 批量更新试卷状态 * 获取试卷详情
* @param vos 试卷记录的主键列表 *
* @return 删除操作是否成功 * @param id 试卷ID
* @return 试卷详情
*/ */
boolean batchUpdatePaperStatus(List<InsExamPaperVO> vos); Map<String, Object> getExamPaperDetail(String id);
/** /**
* 获取试卷列表 * 随机获取试题
* @param id 题目ID *
* @return 题目详情
*/
Map<String, Object> getDetail(String id);
/**
* 随机获取题目
* @param entity 试卷表 * @param entity 试卷表
* @return 卷列表 * @return 试题
*/ */
List<QuestionCategories> getRandomQuestions(ExamPapers entity); List<QuestionCategories> getRandomQuestions(ExamPapers entity);
/** /**
* 添加试卷 * 添加试卷
*
* @param vo 试卷 * @param vo 试卷
* @return 添加是否成功 * @return 添加结果
*/ */
ExamPapers add(InsExamPaperVO vo); boolean addExamPaper(InsExamPaperVO vo);
/** /**
* 修改试题 * 修改试卷
* @param vo 试题 VO 列表 *
* @return 添加是否成功 * @param vo 试卷
* @return 修改结果
*/ */
ExamPapers update(InsExamPaperVO vo); boolean editExamPaper(InsExamPaperVO vo);
} }

@ -8,7 +8,6 @@ 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;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -21,44 +20,36 @@ public class ExamPaperServiceImpl extends BaseServiceImpl<ExamPaperMapper, ExamP
private PaperQuestionService paperQuestionService; 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;
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
List<ExamPapers> data = baseMapper.getList( List<ExamPapers> data = baseMapper.getList(
entity.getIndustryId(), entity.getIndustryId(),
entity.getPaperName(), entity.getPaperName(),
offset, offset,
num); num
);
int total = baseMapper.getListSize( int total = baseMapper.getListSize(
entity.getIndustryId(), entity.getIndustryId(),
entity.getPaperName()); entity.getPaperName()
);
map.put("data", data); map.put("data", data);
map.put("total", total); map.put("total", total);
return map; return map;
} }
@Override @Override
public boolean deleteExamPaperById(Long id) { public boolean delExamPaper(List<Long> ids) {
boolean flag = false; boolean flag = false;
List<Long> ids = new ArrayList<>();
ids.add(id);
flag = deleteLogic(ids); flag = deleteLogic(ids);
if(flag){ if (flag) {
flag = paperQuestionService.delete(id); for (Long id : ids) {
}
return flag;
}
@Override
public boolean deleteExamPaperListByIds(List<Long> ids) {
boolean flag = false;
flag = deleteLogic(ids);
if(flag){
for(Long id : ids){
flag = paperQuestionService.delete(id); flag = paperQuestionService.delete(id);
if(!flag){ if (!flag) {
break; break;
} }
} }
@ -67,61 +58,66 @@ public class ExamPaperServiceImpl extends BaseServiceImpl<ExamPaperMapper, ExamP
} }
@Override @Override
public boolean updatePaperStatus(InsExamPaperVO vo) { public boolean upPaperStatus(InsExamPaperVO vo) {
ExamPapers entity = baseMapper.getDetail(vo.getId());
if(vo.getPaperStatus()==0){
entity.setPaperStatus(1);
}else if(vo.getPaperStatus()==1){
entity.setPaperStatus(0);
}
return updateById(entity);
}
@Override
public boolean batchUpdatePaperStatus(List<InsExamPaperVO> vos) {
boolean flag = false; boolean flag = false;
for(InsExamPaperVO vo : vos){ for (Long id : vo.getIds()) {
flag = updatePaperStatus(vo); ExamPapers entity = baseMapper.getExamPaperDetail(id);
entity.setPaperStatus(vo.getPaperStatus());
flag = updateById(entity);
if (!flag) {
break;
}
} }
return flag; return flag;
} }
@Override @Override
public Map<String, Object> getDetail(String id){ public Map<String, Object> getExamPaperDetail(String id) {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
ExamPapers head = baseMapper.getDetail(Long.valueOf(id)); ExamPapers head = baseMapper.getExamPaperDetail(Long.valueOf(id));
List<QuestionCategories> detail = baseMapper.getQuestions(Long.valueOf(id)); List<QuestionCategories> detail = baseMapper.getQuestions(Long.valueOf(id));
map.put("head", head); map.put("head", head);
map.put("data", detail); map.put("data", detail);
return map; return map;
} }
@Override @Override
public List<QuestionCategories> getRandomQuestions(ExamPapers entity) { public List<QuestionCategories> getRandomQuestions(ExamPapers entity) {
return baseMapper.getRandomQuestions(entity.getIndustryId(), entity.getQuestionCount()); return baseMapper.getRandomQuestions(entity.getIndustryId(), entity.getQuestionCount());
} }
@Override @Override
public ExamPapers add(InsExamPaperVO vo){ public boolean addExamPaper(InsExamPaperVO vo) {
// 试卷 // 试卷
ExamPapers examPapers = new ExamPapers(); boolean flag = false;
examPapers.setPaperName(vo.getPaperName()); ExamPapers examPapers = voToEntity(vo);
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); examPapers.setPaperStatus(1);
save(examPapers); flag = save(examPapers);
return examPapers;
if (flag) {
flag = paperQuestionService.addPaperQuestion(examPapers.getId(), vo.getQuestionIds());
}
return flag;
} }
@Override @Override
public ExamPapers update(InsExamPaperVO vo) { public boolean editExamPaper(InsExamPaperVO vo) {
// 试卷 // 试卷
ExamPapers examPapers = new ExamPapers(); boolean flag = false;
ExamPapers examPapers = voToEntity(vo);
examPapers.setId(vo.getId()); examPapers.setId(vo.getId());
flag = updateById(examPapers);
if (flag) {
flag = paperQuestionService.editPaperQuestion(examPapers.getId(), vo.getQuestionIds());
}
return flag;
}
// vo转entity
private ExamPapers voToEntity(InsExamPaperVO vo) {
ExamPapers examPapers = new ExamPapers();
examPapers.setPaperName(vo.getPaperName()); examPapers.setPaperName(vo.getPaperName());
examPapers.setIndustryId(vo.getIndustryId()); examPapers.setIndustryId(vo.getIndustryId());
examPapers.setQuestionCount(vo.getQuestionCount()); examPapers.setQuestionCount(vo.getQuestionCount());
@ -129,7 +125,6 @@ public class ExamPaperServiceImpl extends BaseServiceImpl<ExamPaperMapper, ExamP
examPapers.setExamDuration(vo.getExamDuration()); examPapers.setExamDuration(vo.getExamDuration());
examPapers.setDurationType(vo.getDurationType()); examPapers.setDurationType(vo.getDurationType());
examPapers.setPaperContent(vo.getPaperContent()); examPapers.setPaperContent(vo.getPaperContent());
updateById(examPapers);
return examPapers; return examPapers;
} }
} }

@ -11,24 +11,27 @@ public interface PaperQuestionService extends BaseService<PaperQuestion> {
/** /**
* 添加试卷试题关系 * 添加试卷试题关系
* @param paperID 试卷ID *
* @param QuestionIds 题目ID集合 * @param paperID 试卷ID
* @return 添加是否成功 * @param questionIds 题目ID集合
* @return 添加结果
*/ */
int add(Long paperID, List<String> QuestionIds); boolean addPaperQuestion(Long paperID, List<String> questionIds);
/** /**
* 删除试卷试题关系 * 删除试卷试题关系
*
* @param paperID 试卷ID * @param paperID 试卷ID
* @return 添加是否成功 * @return 删除是否成功
*/ */
boolean delete(Long paperID); boolean delete(Long paperID);
/** /**
* 更新试卷试题关系 * 修改试卷试题关系
* @param paperID 试卷ID *
* @param QuestionIds 题目ID集合 * @param paperID 试卷ID
* @return 添加是否成功 * @param questionIds 题目ID集合
* @return 修改结果
*/ */
int update(Long paperID, List<String> QuestionIds); boolean editPaperQuestion(Long paperID, List<String> questionIds);
} }

@ -13,39 +13,40 @@ import java.util.List;
public class PaperQuestionServiceImpl extends BaseServiceImpl<PaperQuestionMapper, PaperQuestion> implements PaperQuestionService { public class PaperQuestionServiceImpl extends BaseServiceImpl<PaperQuestionMapper, PaperQuestion> implements PaperQuestionService {
@Override @Override
public int add(Long paperID, List<String> QuestionIds){ public boolean addPaperQuestion(Long paperID, List<String> questionIds) {
int number = 0; return addPaperQuestions(paperID, questionIds);
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 @Override
public boolean delete(Long paperID){ public boolean delete(Long paperID) {
return baseMapper.deletePaperALlQuestion(paperID); return baseMapper.deletePaperALlQuestion(paperID);
} }
@Override @Override
public int update(Long paperID, List<String> QuestionIds){ public boolean editPaperQuestion(Long paperID, List<String> questionIds) {
baseMapper.deletePaperALlQuestion(paperID); boolean flag = false;
flag = baseMapper.deletePaperALlQuestion(paperID);
if (!flag) {
return false;
}
return addPaperQuestions(paperID, questionIds);
}
// 添加试卷试题关联
private boolean addPaperQuestions(Long paperID, List<String> questionIds) {
boolean flag = false;
int number = 0; int number = 0;
for(String QuestionId : QuestionIds){ for (String questionId : questionIds) {
number++; number++;
PaperQuestion paperQuestion = new PaperQuestion(); PaperQuestion paperQuestion = new PaperQuestion();
paperQuestion.setPaperId(paperID); paperQuestion.setPaperId(paperID);
paperQuestion.setQuestionId(Long.valueOf(QuestionId)); paperQuestion.setQuestionId(Long.valueOf(questionId));
paperQuestion.setQuestionNumber(number); paperQuestion.setQuestionNumber(number);
save(paperQuestion); flag = save(paperQuestion);
if (!flag) {
return flag;
}
} }
return number; return flag;
} }
} }

@ -47,17 +47,19 @@ public class QuestionServiceImpl extends BaseServiceImpl<QuestionMapper, Questio
@Override @Override
public boolean addQuestion(List<InsQuestionVO> vo) { public boolean addQuestion(List<InsQuestionVO> vo) {
int count = 0; boolean flag = false;
for (InsQuestionVO item : vo) { for (InsQuestionVO item : vo) {
save(convertToEntity(item)); flag = save(voToEntity(item));
count++; if (!flag) {
return false;
}
} }
return count > 0; return flag;
} }
@Override @Override
public boolean editQuestion(InsQuestionVO vo) { public boolean editQuestion(InsQuestionVO vo) {
return updateById(convertToEntity(vo)); return updateById(voToEntity(vo));
} }
@Override @Override
@ -73,7 +75,7 @@ public class QuestionServiceImpl extends BaseServiceImpl<QuestionMapper, Questio
/** /**
* 将VO转换为Entity * 将VO转换为Entity
*/ */
private QuestionCategories convertToEntity(InsQuestionVO vo) { private QuestionCategories voToEntity(InsQuestionVO vo) {
QuestionCategories entity = new QuestionCategories(); QuestionCategories entity = new QuestionCategories();
entity.setId(vo.getId()); entity.setId(vo.getId());
@ -84,16 +86,17 @@ public class QuestionServiceImpl extends BaseServiceImpl<QuestionMapper, Questio
entity.setAnswer(vo.getAnswer()); entity.setAnswer(vo.getAnswer());
StringBuilder optionsBuilder = new StringBuilder(); StringBuilder optionsBuilder = new StringBuilder();
if (vo.getOptionA()!= null) {
if (vo.getOptionA() != null) {
optionsBuilder.append("A:").append(vo.getOptionA()).append(","); optionsBuilder.append("A:").append(vo.getOptionA()).append(",");
} }
if (vo.getOptionB()!= null) { if (vo.getOptionB() != null) {
optionsBuilder.append("B:").append(vo.getOptionB()).append(","); optionsBuilder.append("B:").append(vo.getOptionB()).append(",");
} }
if (vo.getOptionC()!= null) { if (vo.getOptionC() != null) {
optionsBuilder.append("C:").append(vo.getOptionC()).append(","); optionsBuilder.append("C:").append(vo.getOptionC()).append(",");
} }
if (vo.getOptionD()!= null) { if (vo.getOptionD() != null) {
optionsBuilder.append("D:").append(vo.getOptionD()); optionsBuilder.append("D:").append(vo.getOptionD());
} }

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

@ -5,23 +5,39 @@ import lombok.Getter;
import lombok.Setter; import lombok.Setter;
/** /**
* vo 试题vo * 试题vo
*/ */
@Getter @Getter
@Setter @Setter
public class InsQuestionVO extends QuestionCategories { public class InsQuestionVO extends QuestionCategories {
// 每页数量
/**
* 每页数量
*/
private int num; private int num;
// 页码
/**
* 页码
*/
private int page; private int page;
// 答案A
/**
* 答案A
*/
public String optionA; public String optionA;
// 答案B
/**
* 答案B
*/
public String optionB; public String optionB;
// 答案C
public String optionC;
// 答案D
public String optionD;
}
/**
* 答案C
*/
public String optionC;
/**
* 答案D
*/
public String optionD;
}

@ -3,7 +3,6 @@ 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;
@ -19,97 +18,108 @@ public class ExamPaperController {
@Autowired @Autowired
private ExamPaperService examPaperService; private ExamPaperService examPaperService;
@Autowired
private PaperQuestionService paperQuestionService;
/** /**
* 获取试卷 * 查询试卷
* @param vo 试卷对象VO * @param vo 试卷vo
* @return 查询结果 * @return 查询结果
*/ */
@PostMapping("/list") @PostMapping("/getList")
public R list(@RequestBody InsExamPaperVO vo) { public R list(@RequestBody InsExamPaperVO vo) {
ExamPapers entity = new ExamPapers(); ExamPapers entity = new ExamPapers();
entity.setIndustryId(vo.getIndustryId()); entity.setIndustryId(vo.getIndustryId());
entity.setPaperName(vo.getPaperName()); entity.setPaperName(vo.getPaperName());
Map<String, Object> map = examPaperService.getList(vo.getPage(), vo.getNum(), entity); Map<String, Object> map = examPaperService.getList(vo.getPage(), vo.getNum(), entity);
return R.ok().data(map); return R.ok().data(map);
} }
/** /**
* 删除单个试卷 * 删除试卷
*/ * @param ids 试卷ID
@GetMapping("/delete") * @return 删除结果
public R delete(String id) {
boolean flag = examPaperService.deleteExamPaperById(Long.valueOf((id)));
return R.ok().data(flag);
}
/**
* 删除多个试卷
*/ */
@PostMapping("/deleteList") @PostMapping("/delExamPaper")
public R deleteList(@RequestBody List<Long> ids) { public R delExamPaper(@RequestBody List<Long> ids) {
boolean flag = examPaperService.deleteExamPaperListByIds(ids); boolean flag = examPaperService.delExamPaper(ids);
return R.ok().data(flag); if (flag) {
return R.ok();
} else {
return R.error();
}
} }
/** /**
* 更新试卷状态 * 更新试卷状态
* @param vo 试卷vo
* @return 更新结果
*/ */
@PostMapping("/updatePaperStatus") @PostMapping("/upPaperStatus")
public R updatePaperStatus(@RequestBody InsExamPaperVO vo) { public R upPaperStatus(@RequestBody InsExamPaperVO vo) {
return R.ok().data(examPaperService.updatePaperStatus(vo) boolean flag = examPaperService.upPaperStatus(vo);
); if (flag) {
} return R.ok();
} else {
/** return R.error();
* 批量更新试卷状态 }
*/
@PostMapping("/batchUpdatePaperStatus")
public R batchUpdatePaperStatus(@RequestBody List<InsExamPaperVO> vos) {
boolean resultFlg = examPaperService.batchUpdatePaperStatus(vos);
return R.ok().data(resultFlg);
} }
/** /**
* 随机获取试题 * 随机获取试题
* @param vo 题库对象VO * @param vo 试卷vo
* @return 查询结果 * @return 试题
*/ */
@PostMapping("/getRandomQuestions") @PostMapping("/getRandomQuestions")
public R getRandomQuestions(@RequestBody InsExamPaperVO vo) { public R getRandomQuestions(@RequestBody InsExamPaperVO vo) {
ExamPapers entity = new ExamPapers(); ExamPapers entity = new ExamPapers();
entity.setIndustryId(vo.getIndustryId()); entity.setIndustryId(vo.getIndustryId());
entity.setQuestionCount(vo.getQuestionCount()); entity.setQuestionCount(vo.getQuestionCount());
List<QuestionCategories> data = examPaperService.getRandomQuestions(entity); List<QuestionCategories> data = examPaperService.getRandomQuestions(entity);
return R.ok().data(data); return R.ok().data(data);
} }
/** /**
* 试卷详情 * 获取试卷详情
* @param id 试卷ID
* @return 试卷详情
*/ */
@GetMapping("/getDetail") @GetMapping("/getExamPaperDetail")
public R getDetail(String id) { public R getDetail(String id) {
Map<String, Object> data = examPaperService.getDetail(id); Map<String, Object> data = examPaperService.getExamPaperDetail(id);
return R.ok().data(data); return R.ok().data(data);
} }
/** /**
* 添加试卷 * 添加试卷
* @param vo 试卷vo
* @return 添加结果
*/ */
@PostMapping("/add") @PostMapping("/addExamPaper")
public R add(@RequestBody InsExamPaperVO vo) { public R addExamPaper(@RequestBody InsExamPaperVO vo) {
ExamPapers examPapers = examPaperService.add(vo); boolean flag = false;
return R.ok().data(paperQuestionService.add(examPapers.getId(), vo.getQuestionIds())); flag = examPaperService.addExamPaper(vo);
if (flag) {
return R.ok();
} else {
return R.error();
}
} }
/** /**
* 修改试卷 * 修改试卷
* @param vo 试卷vo
* @return 修改结果
*/ */
@PostMapping("/update") @PostMapping("/editExamPaper")
public R update(@RequestBody InsExamPaperVO vo) { public R editExamPaper(@RequestBody InsExamPaperVO vo) {
ExamPapers examPapers =examPaperService.update(vo); boolean flag = false;
return R.ok().data(paperQuestionService.update(examPapers.getId(), vo.getQuestionIds())); flag = examPaperService.editExamPaper(vo);
if (flag) {
return R.ok();
} else {
return R.error();
}
} }
} }

@ -29,6 +29,7 @@ public class QuestionController {
entity.setIndustryId(vo.getIndustryId()); entity.setIndustryId(vo.getIndustryId());
entity.setServiceTypeId(vo.getServiceTypeId()); entity.setServiceTypeId(vo.getServiceTypeId());
entity.setQuestionContent(vo.getQuestionContent()); entity.setQuestionContent(vo.getQuestionContent());
Map<String, Object> map = questionService.getList(vo.getPage(), vo.getNum(), entity); Map<String, Object> map = questionService.getList(vo.getPage(), vo.getNum(), entity);
return R.ok().data(map); return R.ok().data(map);
} }

@ -3,37 +3,40 @@
<mapper namespace="com.ccic.safeliab.dao.ExamPaperMapper"> <mapper namespace="com.ccic.safeliab.dao.ExamPaperMapper">
<!-- 通用查询映射结果 --> <!-- 通用查询映射结果 -->
<resultMap id="QuestionCategoriesResultMap" type="com.ccic.safeliab.entity.QuestionCategories"> <resultMap id="QuestionCategoriesResultMap" type="com.ccic.safeliab.entity.QuestionCategories">
<id column="id" property="id"/> <id column="id" property="id" />
<result column="question_types" property="questionTypes"/> <result column="question_types" property="questionTypes" />
<result column="industry_id" property="industryId"/> <result column="industry_id" property="industryId" />
<result column="service_type_id" property="serviceTypeId"/> <result column="service_type_id" property="serviceTypeId" />
<result column="question_content" property="questionContent"/> <result column="question_content" property="questionContent" />
<result column="answer" property="answer"/> <result column="answer" property="answer" />
<result column="options" property="options"/> <result column="options" property="options" />
</resultMap> </resultMap>
<resultMap id="ExamPapersResultMap" type="com.ccic.safeliab.entity.ExamPapers"> <resultMap id="ExamPapersResultMap" type="com.ccic.safeliab.entity.ExamPapers">
<id column="id" property="id"/> <id column="id" property="id" />
<result column="paper_name" property="paperName"/> <result column="paper_name" property="paperName" />
<result column="industry_id" property="industryId"/> <result column="industry_id" property="industryId" />
<result column="question_count" property="questionCount"/> <result column="question_count" property="questionCount" />
<result column="total_score" property="totalScore"/> <result column="total_score" property="totalScore" />
<result column="exam_duration" property="examDuration"/> <result column="exam_duration" property="examDuration" />
<result column="duration_type" property="durationType"/> <result column="duration_type" property="durationType" />
<result column="paper_content" property="paperContent"/> <result column="paper_content" property="paperContent" />
<result column="paper_status" property="paperStatus"/> <result column="paper_status" property="paperStatus" />
</resultMap> </resultMap>
<select id="getList" resultMap="ExamPapersResultMap"> <select id="getList" resultMap="ExamPapersResultMap">
SELECT SELECT
id id,
, paper_name paper_name,
, industry_id industry_id,
, question_count question_count,
, total_score total_score,
, exam_duration exam_duration,
, duration_type duration_type,
, paper_content paper_content,
, paper_status paper_status
FROM ex_exam_papers FROM
ex_exam_papers
<where> <where>
is_deleted = '0' is_deleted = '0'
<if test="industryId!= null and industryId!= ''"> <if test="industryId!= null and industryId!= ''">
@ -43,13 +46,17 @@
AND paper_name LIKE '%' || #{paperName} || '%' AND paper_name LIKE '%' || #{paperName} || '%'
</if> </if>
</where> </where>
ORDER BY id DESC ORDER BY
LIMIT #{offset}, #{num}; id DESC
LIMIT
#{offset}, #{num};
</select> </select>
<select id="getListSize" resultType="int"> <select id="getListSize" resultType="int">
SELECT SELECT
COUNT(id) COUNT(id)
FROM ex_exam_papers FROM
ex_exam_papers
<where> <where>
is_deleted = '0' is_deleted = '0'
<if test="industryId!= null and industryId!= ''"> <if test="industryId!= null and industryId!= ''">
@ -60,6 +67,7 @@
</if> </if>
</where> </where>
</select> </select>
<select id="getRandomQuestions" resultMap="QuestionCategoriesResultMap"> <select id="getRandomQuestions" resultMap="QuestionCategoriesResultMap">
SELECT SELECT
id, id,
@ -69,28 +77,33 @@
question_content, question_content,
answer, answer,
options options
FROM ex_question_categories FROM
ex_question_categories
<where> <where>
is_deleted = '0' is_deleted = '0'
<if test="industryId!= null and industryId!= ''"> <if test="industryId!= null and industryId!= ''">
AND industry_id = #{industryId} AND industry_id = #{industryId}
</if> </if>
</where> </where>
ORDER BY RANDOM() ORDER BY
LIMIT #{questionCount}; RANDOM()
LIMIT
#{questionCount};
</select> </select>
<select id="getDetail" resultMap="ExamPapersResultMap">
<select id="getExamPaperDetail" resultMap="ExamPapersResultMap">
SELECT SELECT
id id,
, paper_name paper_name,
, industry_id industry_id,
, question_count question_count,
, total_score total_score,
, exam_duration exam_duration,
, duration_type duration_type,
, paper_content paper_content,
, paper_status paper_status
FROM ex_exam_papers FROM
ex_exam_papers
<where> <where>
is_deleted = '0' is_deleted = '0'
<if test="id!= null and id!= ''"> <if test="id!= null and id!= ''">
@ -98,23 +111,24 @@
</if> </if>
</where> </where>
</select> </select>
<select id="getQuestions" resultMap="QuestionCategoriesResultMap"> <select id="getQuestions" resultMap="QuestionCategoriesResultMap">
SELECT SELECT
qc.id qc.id,
, qc.question_types qc.question_types,
, qc.industry_id qc.industry_id,
, qc.service_type_id qc.service_type_id,
, qc.question_content qc.question_content,
, qc.answer qc.answer,
, qc.options qc.options
FROM FROM
ex_exam_papers ep ex_exam_papers ep
inner join ex_paper_questions pq INNER JOIN ex_paper_questions pq
on pq.paper_id = ep.id ON pq.paper_id = ep.id
and pq.is_deleted = 0 AND pq.is_deleted = 0
inner join ex_question_categories qc INNER JOIN ex_question_categories qc
on qc.id = pq.question_id ON qc.id = pq.question_id
and qc.is_deleted = 0 AND qc.is_deleted = 0
<where> <where>
ep.is_deleted = '0' ep.is_deleted = '0'
<if test="id!= null and id!= ''"> <if test="id!= null and id!= ''">
@ -122,8 +136,4 @@
</if> </if>
</where> </where>
</select> </select>
<delete id="deletePaperALlQuestion"> </mapper>
DELETE FROM ex_paper_questions
WHERE paper_id = #{id}
</delete>
</mapper>

@ -5,4 +5,4 @@
DELETE FROM ex_paper_questions DELETE FROM ex_paper_questions
WHERE paper_id = #{id} WHERE paper_id = #{id}
</delete> </delete>
</mapper> </mapper>

@ -42,7 +42,8 @@
options, options,
status, status,
is_deleted is_deleted
FROM ex_question_categories FROM
ex_question_categories
<where> <where>
is_deleted = '0' is_deleted = '0'
<if test="industryId!= null and industryId!= ''"> <if test="industryId!= null and industryId!= ''">
@ -55,14 +56,17 @@
AND question_content LIKE '%' || #{questionContent} || '%' AND question_content LIKE '%' || #{questionContent} || '%'
</if> </if>
</where> </where>
ORDER BY id DESC ORDER BY
LIMIT #{offset}, #{num}; id ASC
LIMIT
#{offset}, #{num};
</select> </select>
<select id="getListSize" resultType="int"> <select id="getListSize" resultType="int">
SELECT SELECT
COUNT(id) COUNT(id)
FROM ex_question_categories FROM
ex_question_categories
<where> <where>
is_deleted = '0' is_deleted = '0'
<if test="industryId!= null and industryId!= ''"> <if test="industryId!= null and industryId!= ''">
@ -81,8 +85,10 @@
SELECT SELECT
industry_id, industry_id,
industry_name industry_name
FROM tbl_industry FROM
WHERE status = 1 tbl_industry
WHERE
status = 1
</select> </select>
<select id="getQuestionDetail" resultMap="QuestionCategoriesResultMap"> <select id="getQuestionDetail" resultMap="QuestionCategoriesResultMap">
@ -96,7 +102,8 @@
options, options,
status, status,
is_deleted is_deleted
FROM ex_question_categories FROM
ex_question_categories
<where> <where>
is_deleted = '0' is_deleted = '0'
<if test="id!= null and id!= ''"> <if test="id!= null and id!= ''">

Loading…
Cancel
Save