package com.ssj.dao.kmt.kmt.dao;

import com.ssj.bean.kmt.kmt.domain.KmtHomeworkWrongQuestion;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface KmtHomeworkWrongQuestionDao extends JpaRepository<KmtHomeworkWrongQuestion, String> {

    /**
     * 根据作业的id查询错题
     */
    List<KmtHomeworkWrongQuestion> findByHomeworkIdAndIsDelete(String homeworkId, boolean isDelete);

    /**
     * 根据作业图片的id查询错题
     */
    @Query(value = "select  * from  kmt_homework_wrong_question where homework_picture_id= ?1 and is_delete=?2 ", nativeQuery = true)
    List<KmtHomeworkWrongQuestion> findByHomeworkPictureIdAndIsDelete(String homeworkPictureId, int isDelete);

    /**
     * 根据作业图片的id列表查询批改的题目
     * @param isDelete false有效记录   true无效记录
     */
    List<KmtHomeworkWrongQuestion> findByHomeworkPictureIdInAndIsDelete(List<String> homeworkPictureIdList, boolean isDelete);

    @Query(nativeQuery = true, value = "delete from kmt_homework_wrong_question where homework_picture_id = ?1 ")
    @Modifying
    void deleteByHomeworkPictureId(String homeworkId);

    /**
     * 错题本错题删除
     *
     * @param questionId
     */
    @Modifying
    @Query(value = "update kmt_homework_wrong_question set is_wrong_ques_delete=1 where question_id = ?1", nativeQuery = true)
    void deleteWrongQuesByQuestionId(String questionId);
}
