package com.ssj.dao.sys.homework.dao;

import com.ssj.bean.sys.homework.domain.HomeworkHowDetail;
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;


/**
 * 类名称：HomeworkHowDetailsDao<br>
 * 类描述 作业数据访问接口<br>
 * 
 * @version v1.0
 */
@Repository
public interface HomeworkHowDetailsDao extends JpaRepository<HomeworkHowDetail, String> {

    List<HomeworkHowDetail> findByWrongQuestionIdIn(List<String> homeworkWrongQuestionIdList);

    @Query(nativeQuery = true, value = "delete from scon_homework_how_details where homework_picture_id in ?1 ")
    void deleteByHomeworkPictureIdIn(List<String> homeworkPictureIdList);

    @Query(nativeQuery = true, value = "delete from scon_homework_how_details where homework_picture_id = ?1 and  wrong_question_id is null")
    @Modifying
    void deleteByHomeworkPictureId(String homeworkPictureId);

    @Query(nativeQuery = true, value = "delete from scon_homework_how_details where homework_picture_id = ?1 and  wrong_question_id is not null")
    @Modifying
    void deleteExerciseByHomeworkPictureId(String homeworkPictureId);

    /**
     * 错题本作业删除
     *
     * @param homeworkId
     */
    @Modifying
    @Query(value = "update scon_homework_how_details set is_wrong_ques_delete=1 where homework_id = ?1", nativeQuery = true)
    void deleteWrongQuesByHomeworkId(String homeworkId);

    /**
     * 错题本删除错题
     * @param knowHowDetailId 知识点id
     * @param knowledgeVersion
     * @param homeworkId 作业id
     */
    @Modifying
    @Query(value = "update scon_homework_how_details set is_wrong_ques_delete=1 where how_detail_id = ?1 and knowledge_version = ?2 and homework_id = ?3", nativeQuery = true)
    void deleteWrongBookQuestion(String knowHowDetailId, String knowledgeVersion, String homeworkId);

    @Query(value = "select * from scon_homework_how_details where homework_picture_id=?1 and wrong_question_id is null", nativeQuery = true)
    List<HomeworkHowDetail> findByHomeworkPictureId (String homeworkPictureId);

    /**
     * 根据作业id查询手动选择的知识点
     * @param homeworkId 作业id
     */
    List<HomeworkHowDetail> findByHomeworkIdAndWrongQuestionIdIsNull(String homeworkId);
}
