题库列表二次校验

main
hujunpeng 4 months ago
parent c841eabdcb
commit 3c64adaa06
  1. 8
      ccic-exam/src/main/java/com/ccic/safeliab/dao/QuestionMapper.java
  2. 2
      ccic-exam/src/main/java/com/ccic/safeliab/service/QuestionService.java
  3. 24
      ccic-exam/src/main/java/com/ccic/safeliab/service/QuestionServiceImpl.java
  4. 8
      ccic-exam/src/main/java/com/ccic/safeliab/web/QuestionController.java
  5. 30
      ccic-exam/src/main/resources/mappers/QuestionMapper.xml

@ -72,4 +72,12 @@ public interface QuestionMapper extends BaseMapper<QuestionCategories> {
*/ */
List<PageQuestionCategoriesVO> getListByPaperId(@Param("paperId") Long id); List<PageQuestionCategoriesVO> getListByPaperId(@Param("paperId") Long id);
/**
* 查询试题是否被引用
*
* @param ids 试题ID
* @return 查询结果
*/
int getQuestiongInExamSize(@Param("ids") List<Long> ids);
} }

@ -28,7 +28,7 @@ public interface QuestionService extends BaseService<QuestionCategories> {
* @param ids 试题ID * @param ids 试题ID
* @return 删除结果 * @return 删除结果
*/ */
boolean delQuestion(List<Long> ids); Map<String, Object> delQuestion(List<Long> ids);
/** /**
* 添加试题 * 添加试题

@ -41,8 +41,28 @@ public class QuestionServiceImpl extends BaseServiceImpl<QuestionMapper, Questio
} }
@Override @Override
public boolean delQuestion(List<Long> ids) { public Map<String, Object> delQuestion(List<Long> ids) {
return deleteLogic(ids); Map<String, Object> map = new HashMap<>();
int size = baseMapper.getQuestiongInExamSize(ids);
if( size > 0 )
{
map.put("success", "error");
if (ids.size() > 1){
map.put("message", "选中的试题中有" + size + "个已被引用,需删除引用的考试后方可删除");
}else{
map.put("message", "该试题已被引用,需删除引用的考试后方可删除");
}
return map;
}
boolean deleteResult = deleteLogic(ids);
if (deleteResult) {
map.put("success", "true");
map.put("message", "试题删除成功");
} else {
map.put("success", "false");
map.put("message", "试题删除失败");
}
return map;
} }
@Override @Override

@ -41,12 +41,8 @@ public class QuestionController {
*/ */
@PostMapping("/delQuestion") @PostMapping("/delQuestion")
public R delQuestion(@RequestBody List<Long> ids) { public R delQuestion(@RequestBody List<Long> ids) {
boolean flag = questionService.delQuestion(ids); Map<String, Object> map = questionService.delQuestion(ids);
if (flag) { return R.ok().data(map);
return R.ok();
} else {
return R.error();
}
} }
/** /**

@ -45,7 +45,7 @@
FROM FROM
ex_question_categories 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>
@ -68,7 +68,7 @@
FROM FROM
ex_question_categories 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>
@ -105,7 +105,7 @@
FROM FROM
ex_question_categories ex_question_categories
<where> <where>
is_deleted = '0' is_deleted = 0
<if test="id!= null and id!= ''"> <if test="id!= null and id!= ''">
AND id = #{id} AND id = #{id}
</if> </if>
@ -124,13 +124,33 @@
a.status, a.status,
b.question_number b.question_number
FROM ex_question_categories a FROM ex_question_categories a
LEFT JOIN ex_paper_questions b ON b.question_id = a.id AND b.is_deleted = '0' LEFT JOIN ex_paper_questions b ON b.question_id = a.id AND b.is_deleted = 0
<where> <where>
a.is_deleted = '0' a.is_deleted = 0
<if test="paperId!= null and paperId!= ''"> <if test="paperId!= null and paperId!= ''">
AND b.paper_id = #{paperId} AND b.paper_id = #{paperId}
</if> </if>
</where> </where>
ORDER BY b.question_number asc ORDER BY b.question_number asc
</select> </select>
<select id="getQuestiongInExamSize" resultType="int">
SELECT
count(DISTINCT qc.id)
FROM
ex_question_categories qc
INNER JOIN ex_paper_questions pq ON pq.question_id = qc.id
AND pq.is_deleted = 0
INNER JOIN ex_exam_papers ep ON ep.id = pq.paper_id
AND ep.is_deleted = 0
<where>
qc.is_deleted = 0
<if test="ids!= null and ids.size() > 0">
AND qc.id IN
<foreach item="item" index="index" collection="ids"
open="(" separator="," close=")">
#{item}
</foreach>
</if>
</where>
</select>
</mapper> </mapper>
Loading…
Cancel
Save