diff --git a/ccic-exam/src/main/java/com/ccic/safeliab/dao/QuestionMapper.java b/ccic-exam/src/main/java/com/ccic/safeliab/dao/QuestionMapper.java index f27e16b..3f404b4 100644 --- a/ccic-exam/src/main/java/com/ccic/safeliab/dao/QuestionMapper.java +++ b/ccic-exam/src/main/java/com/ccic/safeliab/dao/QuestionMapper.java @@ -9,11 +9,6 @@ import org.apache.ibatis.annotations.Param; import java.util.List; -/** - * Mapper 接口 - * - * @author Chill - */ @Mapper public interface QuestionMapper extends BaseMapper { @@ -25,11 +20,11 @@ public interface QuestionMapper extends BaseMapper { /** * 查询试题 * - * @param industryId 监管行业 - * @param serviceTypeId 服务类型 + * @param industryId 监管行业 + * @param serviceTypeId 服务类型 * @param questionContent 题干条件 - * @param offset 偏移量 - * @param num 每页数量 + * @param offset 偏移量 + * @param num 每页数量 * @return 当前页数据 */ List getList( @@ -37,33 +32,35 @@ public interface QuestionMapper extends BaseMapper { @Param("serviceTypeId") Long serviceTypeId, @Param("questionContent") String questionContent, @Param("offset") int offset, - @Param("num") int num); + @Param("num") int num + ); /** - * 查询试题总数量 + * 查询试题数量 * - * @param industryId 监管行业 - * @param serviceTypeId 服务类型 + * @param industryId 监管行业 + * @param serviceTypeId 服务类型 * @param questionContent 题干条件 - * @return 总数量 + * @return 试题数量 */ int getListSize( @Param("industryId") Long industryId, @Param("serviceTypeId") Long serviceTypeId, - @Param("questionContent") String questionContent); + @Param("questionContent") String questionContent + ); /** - * 获取行业 + * 获取字典数据 * - * @return 行业 + * @return 字典数据 */ List getIndustry(); /** - * 题目详情 + * 获取试题详情 * * @param id 试题ID * @return 试题详情 */ QuestionCategories getQuestionDetail(@Param("id") Long id); -} +} \ No newline at end of file diff --git a/ccic-exam/src/main/java/com/ccic/safeliab/service/QuestionService.java b/ccic-exam/src/main/java/com/ccic/safeliab/service/QuestionService.java index e119ad2..025d940 100644 --- a/ccic-exam/src/main/java/com/ccic/safeliab/service/QuestionService.java +++ b/ccic-exam/src/main/java/com/ccic/safeliab/service/QuestionService.java @@ -14,8 +14,9 @@ public interface QuestionService extends BaseService { /** * 查询试题 - * @param page 页码 - * @param num 数量 + * + * @param page 页码 + * @param num 数量 * @param entity 题库entity * @return 查询结果 */ @@ -23,6 +24,7 @@ public interface QuestionService extends BaseService { /** * 删除试题 + * * @param ids 试题ID * @return 删除结果 */ @@ -30,29 +32,32 @@ public interface QuestionService extends BaseService { /** * 添加试题 - * @param vo 试题 VO 列表 - * @return 添加是否成功 + * + * @param vo 试题vo + * @return 添加结果 */ - int add(List vo); + boolean addQuestion(List vo); /** * 修改试题 - * @param vo 试题 VO 列表 - * @return 添加是否成功 - */ - boolean update(InsQuestionVO vo); - - /** - * 获取行业 - * @return 行业 + * + * @param vo 试题vo + * @return 修改结果 */ - List getDictionary(); + boolean editQuestion(InsQuestionVO vo); /** - * 题目详情 + * 获取试题详情 * * @param id 试题ID * @return 试题详情 */ QuestionCategories getQuestionDetail(String id); -} + + /** + * 监管行业字典 + * + * @return 字典数据 + */ + List findDictionary(); +} \ No newline at end of file diff --git a/ccic-exam/src/main/java/com/ccic/safeliab/service/QuestionServiceImpl.java b/ccic-exam/src/main/java/com/ccic/safeliab/service/QuestionServiceImpl.java index 925869e..68af13a 100644 --- a/ccic-exam/src/main/java/com/ccic/safeliab/service/QuestionServiceImpl.java +++ b/ccic-exam/src/main/java/com/ccic/safeliab/service/QuestionServiceImpl.java @@ -16,22 +16,27 @@ import java.util.Map; public class QuestionServiceImpl extends BaseServiceImpl implements QuestionService { @Override - public Map getList(int page,int num, QuestionCategories entity) { + public Map getList(int page, int num, QuestionCategories entity) { int offset = (page - 1) * num; Map map = new HashMap<>(); + List data = baseMapper.getList( entity.getIndustryId(), entity.getServiceTypeId(), entity.getQuestionContent(), offset, - num); + num + ); - int total = baseMapper.getListSize( + int total = baseMapper.getListSize( entity.getIndustryId(), entity.getServiceTypeId(), - entity.getQuestionContent()); + entity.getQuestionContent() + ); + map.put("data", data); map.put("total", total); + return map; } @@ -41,56 +46,60 @@ public class QuestionServiceImpl extends BaseServiceImpl vo) { - int count =0; - for(InsQuestionVO item :vo){ + public boolean addQuestion(List vo) { + int count = 0; + for (InsQuestionVO item : vo) { save(convertToEntity(item)); - count ++; + count++; } - return count; + return count > 0; } @Override - public boolean update(InsQuestionVO vo) { + public boolean editQuestion(InsQuestionVO vo) { return updateById(convertToEntity(vo)); } @Override - public List getDictionary() { - return baseMapper.getIndustry(); + public QuestionCategories getQuestionDetail(String id) { + return baseMapper.getQuestionDetail(Long.valueOf(id)); } @Override - public QuestionCategories getQuestionDetail(String id){ - return baseMapper.getQuestionDetail(Long.valueOf(id)); + public List findDictionary() { + return baseMapper.getIndustry(); } /** - * 将VO转换为实体类 + * 将VO转换为Entity */ private QuestionCategories convertToEntity(InsQuestionVO vo) { QuestionCategories entity = new QuestionCategories(); + entity.setId(vo.getId()); entity.setQuestionTypes(vo.getQuestionTypes()); entity.setIndustryId(vo.getIndustryId()); entity.setServiceTypeId(vo.getServiceTypeId()); entity.setQuestionContent(vo.getQuestionContent()); entity.setAnswer(vo.getAnswer()); + StringBuilder optionsBuilder = new StringBuilder(); if (vo.getOptionA()!= null) { optionsBuilder.append("A:").append(vo.getOptionA()).append(","); } - if (vo.getOptionB() != null) { + if (vo.getOptionB()!= null) { optionsBuilder.append("B:").append(vo.getOptionB()).append(","); } - if (vo.getOptionC() != null) { + if (vo.getOptionC()!= null) { optionsBuilder.append("C:").append(vo.getOptionC()).append(","); } - if (vo.getOptionD() != null) { + if (vo.getOptionD()!= null) { optionsBuilder.append("D:").append(vo.getOptionD()); } + String options = optionsBuilder.toString(); entity.setOptions(options); + return entity; } -} +} \ No newline at end of file diff --git a/ccic-exam/src/main/java/com/ccic/safeliab/web/QuestionController.java b/ccic-exam/src/main/java/com/ccic/safeliab/web/QuestionController.java index d07da76..79ec603 100644 --- a/ccic-exam/src/main/java/com/ccic/safeliab/web/QuestionController.java +++ b/ccic-exam/src/main/java/com/ccic/safeliab/web/QuestionController.java @@ -24,7 +24,7 @@ public class QuestionController { * @return 查询结果 */ @PostMapping("/getList") - public R list(@RequestBody InsQuestionVO vo) { + public R getList(@RequestBody InsQuestionVO vo) { QuestionCategories entity = new QuestionCategories(); entity.setIndustryId(vo.getIndustryId()); entity.setServiceTypeId(vo.getServiceTypeId()); @@ -39,47 +39,63 @@ public class QuestionController { * @return 删除结果 */ @PostMapping("/delQuestion") - public R deleteList(@RequestBody List ids) { + public R delQuestion(@RequestBody List ids) { boolean flag = questionService.delQuestion(ids); - if(flag){ + if (flag) { return R.ok(); - }else{ + } else { return R.error(); } } /** * 添加试题 + * @param vo 试题vo + * @return 添加结果 */ - @PostMapping("/add") - public R add(@RequestBody List vo) { - return R.ok().data(questionService.add(vo)); + @PostMapping("/addQuestion") + public R addQuestion(@RequestBody List vo) { + boolean flag = questionService.addQuestion(vo); + if (flag) { + return R.ok(); + } else { + return R.error(); + } } /** * 修改试题 + * @param vo 试题vo + * @return 修改结果 */ - @PostMapping("/update") - public R add(@RequestBody InsQuestionVO vo) { - return R.ok().data(questionService.update(vo)); + @PostMapping("/editQuestion") + public R editQuestion(@RequestBody InsQuestionVO vo) { + boolean flag = questionService.editQuestion(vo); + if (flag) { + return R.ok(); + } else { + return R.error(); + } } /** - * 行业查询 - * @return 行业 + * 获取试题详情 + * @param id 试题ID + * @return 试题详情 */ - @GetMapping("/findIndustry") - public R findIndustry() { - List tree = questionService.getDictionary(); - return R.ok().data(tree); + @GetMapping("/getQuestionDetail") + public R getQuestionDetail(String id) { + QuestionCategories data = questionService.getQuestionDetail(id); + return R.ok().data(data); } /** - * 题目详情 + * 查询字典数据 + * @return 字典数据 */ - @GetMapping("/getDetail") - public R getDetail(String id) { - QuestionCategories data = questionService.getQuestionDetail(id); - return R.ok().data(data); + @GetMapping("/findIndustry") + public R findIndustry() { + List tree = questionService.findDictionary(); + return R.ok().data(tree); } -} +} \ No newline at end of file diff --git a/ccic-exam/src/main/resources/mappers/QuestionMapper.xml b/ccic-exam/src/main/resources/mappers/QuestionMapper.xml index 31bae1e..fe8bb98 100644 --- a/ccic-exam/src/main/resources/mappers/QuestionMapper.xml +++ b/ccic-exam/src/main/resources/mappers/QuestionMapper.xml @@ -1,22 +1,25 @@ + - - + + + - - - - - - - - - + + + + + + + + + + + + + - + + \ No newline at end of file