package com.ssj.service.mapper;

import com.ssj.bean.mybatis.KnowledgeMBDto;
import com.ssj.bean.sys.opentest.OpenTestQuestion;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * @author yanghuan
 * @title: RecordQuestionMapper
 * @projectName ssj
 * @description: TODO
 * @date 2020/5/15 10:00
 */
@Mapper
public interface RecordQuestionMapper {

    /**
     * 删除题目
     *
     * @param questionId 题目id
     */
    @Update("update tb_test_question set update_version = -1 where id = #{questionId}")
    void deleteQuestion(@Param("questionId") String questionId);

    List<KnowledgeMBDto> findZtKnowledgeList(@Param("map") Map<String, Object> params);

    List<KnowledgeMBDto> findKnowledgeList(@Param("map") Map<String, Object> params);

    /**
     * 更新题目题号
     *
     * @param openTestQuestion 被删除的题目（此题目被删除引起题号更新，被删除的题目含有下属题目时，openTestQuestion为最后一道小题）
     * @param step 题号前移步长（被删除的题目含有下属题目时，step为下属题目总数）
     */
    int updateQuestionNum(@Param("openTestQuestion") OpenTestQuestion openTestQuestion, @Param("step") int step);

    /**
     * 查询所有下属题目
     *
     * @param parentId 题目id
     */
    @Select("select * from tb_test_question where parent_id = #{parentId} and update_version > -1 order by question_num desc")
    List<OpenTestQuestion> findAllChild(@Param("parentId") String parentId);

    /**
     * 删除所有下属题目
     *
     * @param parentId 题目id
     */
    @Update("update tb_test_question set update_version = -1 where parent_id = #{parentId}")
    void deleteChild(@Param("parentId") String parentId);
}
