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

main
hujunpeng 4 months ago
parent 81dc613577
commit 59624a3f32
  1. 35
      ccic-exam/src/main/java/com/ccic/safeliab/dao/QuestionMapper.java
  2. 37
      ccic-exam/src/main/java/com/ccic/safeliab/service/QuestionService.java
  3. 47
      ccic-exam/src/main/java/com/ccic/safeliab/service/QuestionServiceImpl.java
  4. 60
      ccic-exam/src/main/java/com/ccic/safeliab/web/QuestionController.java
  5. 41
      ccic-exam/src/main/resources/mappers/QuestionMapper.xml

@ -9,11 +9,6 @@ import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
/**
* Mapper 接口
*
* @author Chill
*/
@Mapper @Mapper
public interface QuestionMapper extends BaseMapper<QuestionCategories> { public interface QuestionMapper extends BaseMapper<QuestionCategories> {
@ -25,11 +20,11 @@ public interface QuestionMapper extends BaseMapper<QuestionCategories> {
/** /**
* 查询试题 * 查询试题
* *
* @param industryId 监管行业 * @param industryId 监管行业
* @param serviceTypeId 服务类型 * @param serviceTypeId 服务类型
* @param questionContent 题干条件 * @param questionContent 题干条件
* @param offset 偏移量 * @param offset 偏移量
* @param num 每页数量 * @param num 每页数量
* @return 当前页数据 * @return 当前页数据
*/ */
List<QuestionCategories> getList( List<QuestionCategories> getList(
@ -37,33 +32,35 @@ public interface QuestionMapper extends BaseMapper<QuestionCategories> {
@Param("serviceTypeId") Long serviceTypeId, @Param("serviceTypeId") Long serviceTypeId,
@Param("questionContent") String questionContent, @Param("questionContent") String questionContent,
@Param("offset") int offset, @Param("offset") int offset,
@Param("num") int num); @Param("num") int num
);
/** /**
* 查询试题数量 * 查询试题数量
* *
* @param industryId 监管行业 * @param industryId 监管行业
* @param serviceTypeId 服务类型 * @param serviceTypeId 服务类型
* @param questionContent 题干条件 * @param questionContent 题干条件
* @return 数量 * @return 试题数量
*/ */
int getListSize( int getListSize(
@Param("industryId") Long industryId, @Param("industryId") Long industryId,
@Param("serviceTypeId") Long serviceTypeId, @Param("serviceTypeId") Long serviceTypeId,
@Param("questionContent") String questionContent); @Param("questionContent") String questionContent
);
/** /**
* 获取行业 * 获取字典数据
* *
* @return 行业 * @return 字典数据
*/ */
List<Industry> getIndustry(); List<Industry> getIndustry();
/** /**
* 详情 * 获取试题详情
* *
* @param id 试题ID * @param id 试题ID
* @return 试题详情 * @return 试题详情
*/ */
QuestionCategories getQuestionDetail(@Param("id") Long id); QuestionCategories getQuestionDetail(@Param("id") Long id);
} }

@ -14,8 +14,9 @@ public interface QuestionService extends BaseService<QuestionCategories> {
/** /**
* 查询试题 * 查询试题
* @param page 页码 *
* @param num 数量 * @param page 页码
* @param num 数量
* @param entity 题库entity * @param entity 题库entity
* @return 查询结果 * @return 查询结果
*/ */
@ -23,6 +24,7 @@ public interface QuestionService extends BaseService<QuestionCategories> {
/** /**
* 删除试题 * 删除试题
*
* @param ids 试题ID * @param ids 试题ID
* @return 删除结果 * @return 删除结果
*/ */
@ -30,29 +32,32 @@ public interface QuestionService extends BaseService<QuestionCategories> {
/** /**
* 添加试题 * 添加试题
* @param vo 试题 VO 列表 *
* @return 添加是否成功 * @param vo 试题vo
* @return 添加结果
*/ */
int add(List<InsQuestionVO> vo); boolean addQuestion(List<InsQuestionVO> vo);
/** /**
* 修改试题 * 修改试题
* @param vo 试题 VO 列表 *
* @return 添加是否成功 * @param vo 试题vo
*/ * @return 修改结果
boolean update(InsQuestionVO vo);
/**
* 获取行业
* @return 行业
*/ */
List<Industry> getDictionary(); boolean editQuestion(InsQuestionVO vo);
/** /**
* 详情 * 获取试题详情
* *
* @param id 试题ID * @param id 试题ID
* @return 试题详情 * @return 试题详情
*/ */
QuestionCategories getQuestionDetail(String id); QuestionCategories getQuestionDetail(String id);
}
/**
* 监管行业字典
*
* @return 字典数据
*/
List<Industry> findDictionary();
}

@ -16,22 +16,27 @@ import java.util.Map;
public class QuestionServiceImpl extends BaseServiceImpl<QuestionMapper, QuestionCategories> implements QuestionService { public class QuestionServiceImpl extends BaseServiceImpl<QuestionMapper, QuestionCategories> implements QuestionService {
@Override @Override
public Map<String, Object> getList(int page,int num, QuestionCategories entity) { public Map<String, Object> getList(int page, int num, QuestionCategories entity) {
int offset = (page - 1) * num; int offset = (page - 1) * num;
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
List<QuestionCategories> data = baseMapper.getList( List<QuestionCategories> data = baseMapper.getList(
entity.getIndustryId(), entity.getIndustryId(),
entity.getServiceTypeId(), entity.getServiceTypeId(),
entity.getQuestionContent(), entity.getQuestionContent(),
offset, offset,
num); num
);
int total = baseMapper.getListSize( int total = baseMapper.getListSize(
entity.getIndustryId(), entity.getIndustryId(),
entity.getServiceTypeId(), entity.getServiceTypeId(),
entity.getQuestionContent()); entity.getQuestionContent()
);
map.put("data", data); map.put("data", data);
map.put("total", total); map.put("total", total);
return map; return map;
} }
@ -41,56 +46,60 @@ public class QuestionServiceImpl extends BaseServiceImpl<QuestionMapper, Questio
} }
@Override @Override
public int add(List<InsQuestionVO> vo) { public boolean addQuestion(List<InsQuestionVO> vo) {
int count =0; int count = 0;
for(InsQuestionVO item :vo){ for (InsQuestionVO item : vo) {
save(convertToEntity(item)); save(convertToEntity(item));
count ++; count++;
} }
return count; return count > 0;
} }
@Override @Override
public boolean update(InsQuestionVO vo) { public boolean editQuestion(InsQuestionVO vo) {
return updateById(convertToEntity(vo)); return updateById(convertToEntity(vo));
} }
@Override @Override
public List<Industry> getDictionary() { public QuestionCategories getQuestionDetail(String id) {
return baseMapper.getIndustry(); return baseMapper.getQuestionDetail(Long.valueOf(id));
} }
@Override @Override
public QuestionCategories getQuestionDetail(String id){ public List<Industry> findDictionary() {
return baseMapper.getQuestionDetail(Long.valueOf(id)); return baseMapper.getIndustry();
} }
/** /**
* 将VO转换为实体类 * 将VO转换为Entity
*/ */
private QuestionCategories convertToEntity(InsQuestionVO vo) { private QuestionCategories convertToEntity(InsQuestionVO vo) {
QuestionCategories entity = new QuestionCategories(); QuestionCategories entity = new QuestionCategories();
entity.setId(vo.getId()); entity.setId(vo.getId());
entity.setQuestionTypes(vo.getQuestionTypes()); entity.setQuestionTypes(vo.getQuestionTypes());
entity.setIndustryId(vo.getIndustryId()); entity.setIndustryId(vo.getIndustryId());
entity.setServiceTypeId(vo.getServiceTypeId()); entity.setServiceTypeId(vo.getServiceTypeId());
entity.setQuestionContent(vo.getQuestionContent()); entity.setQuestionContent(vo.getQuestionContent());
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());
} }
String options = optionsBuilder.toString(); String options = optionsBuilder.toString();
entity.setOptions(options); entity.setOptions(options);
return entity; return entity;
} }
} }

@ -24,7 +24,7 @@ public class QuestionController {
* @return 查询结果 * @return 查询结果
*/ */
@PostMapping("/getList") @PostMapping("/getList")
public R list(@RequestBody InsQuestionVO vo) { public R getList(@RequestBody InsQuestionVO vo) {
QuestionCategories entity = new QuestionCategories(); QuestionCategories entity = new QuestionCategories();
entity.setIndustryId(vo.getIndustryId()); entity.setIndustryId(vo.getIndustryId());
entity.setServiceTypeId(vo.getServiceTypeId()); entity.setServiceTypeId(vo.getServiceTypeId());
@ -39,47 +39,63 @@ public class QuestionController {
* @return 删除结果 * @return 删除结果
*/ */
@PostMapping("/delQuestion") @PostMapping("/delQuestion")
public R deleteList(@RequestBody List<Long> ids) { public R delQuestion(@RequestBody List<Long> ids) {
boolean flag = questionService.delQuestion(ids); boolean flag = questionService.delQuestion(ids);
if(flag){ if (flag) {
return R.ok(); return R.ok();
}else{ } else {
return R.error(); return R.error();
} }
} }
/** /**
* 添加试题 * 添加试题
* @param vo 试题vo
* @return 添加结果
*/ */
@PostMapping("/add") @PostMapping("/addQuestion")
public R add(@RequestBody List<InsQuestionVO> vo) { public R addQuestion(@RequestBody List<InsQuestionVO> vo) {
return R.ok().data(questionService.add(vo)); boolean flag = questionService.addQuestion(vo);
if (flag) {
return R.ok();
} else {
return R.error();
}
} }
/** /**
* 修改试题 * 修改试题
* @param vo 试题vo
* @return 修改结果
*/ */
@PostMapping("/update") @PostMapping("/editQuestion")
public R add(@RequestBody InsQuestionVO vo) { public R editQuestion(@RequestBody InsQuestionVO vo) {
return R.ok().data(questionService.update(vo)); boolean flag = questionService.editQuestion(vo);
if (flag) {
return R.ok();
} else {
return R.error();
}
} }
/** /**
* 行业查询 * 获取试题详情
* @return 行业 * @param id 试题ID
* @return 试题详情
*/ */
@GetMapping("/findIndustry") @GetMapping("/getQuestionDetail")
public R findIndustry() { public R getQuestionDetail(String id) {
List<Industry> tree = questionService.getDictionary(); QuestionCategories data = questionService.getQuestionDetail(id);
return R.ok().data(tree); return R.ok().data(data);
} }
/** /**
* 题目详情 * 查询字典数据
* @return 字典数据
*/ */
@GetMapping("/getDetail") @GetMapping("/findIndustry")
public R getDetail(String id) { public R findIndustry() {
QuestionCategories data = questionService.getQuestionDetail(id); List<Industry> tree = questionService.findDictionary();
return R.ok().data(data); return R.ok().data(tree);
} }
} }

@ -1,22 +1,25 @@
<?xml version="1.0" encoding="UTF-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"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ccic.safeliab.dao.QuestionMapper"> <mapper namespace="com.ccic.safeliab.dao.QuestionMapper">
<!-- 通用查询映射结果 --> <!-- 通用查询映射结果 -->
<resultMap id="IndustryResultMap" type="com.ccic.safeliab.entity.Industry"> <resultMap id="IndustryResultMap" type="com.ccic.safeliab.entity.Industry">
<id column="industry_id" property="industryId"/> <id column="industry_id" property="industryId" />
<result column="industry_name" property="industryName"/> <result column="industry_name" property="industryName" />
</resultMap> </resultMap>
<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" />
<result column="status" property="status"/> <result column="status" property="status" />
<result column="is_deleted" property="isDeleted"/> <result column="is_deleted" property="isDeleted" />
</resultMap> </resultMap>
<select id="getList" resultMap="QuestionCategoriesResultMap"> <select id="getList" resultMap="QuestionCategoriesResultMap">
SELECT SELECT
id, id,
@ -44,6 +47,7 @@
ORDER BY id DESC ORDER BY id DESC
LIMIT #{offset}, #{num}; LIMIT #{offset}, #{num};
</select> </select>
<select id="getListSize" resultType="int"> <select id="getListSize" resultType="int">
SELECT SELECT
COUNT(id) COUNT(id)
@ -61,13 +65,15 @@
</if> </if>
</where> </where>
</select> </select>
<select id="getIndustry" resultMap="IndustryResultMap"> <select id="getIndustry" resultMap="IndustryResultMap">
select SELECT
industry_id, industry_id,
industry_name industry_name
from tbl_industry FROM tbl_industry
where status = 1 WHERE status = 1
</select> </select>
<select id="getQuestionDetail" resultMap="QuestionCategoriesResultMap"> <select id="getQuestionDetail" resultMap="QuestionCategoriesResultMap">
SELECT SELECT
id, id,
@ -87,4 +93,5 @@
</if> </if>
</where> </where>
</select> </select>
</mapper>
</mapper>
Loading…
Cancel
Save