package com.cirle.scientific.dao;/*
 *24901
 *2022/12/22
 *17:51
 */

import com.cirle.scientific.po.QkjQuestionAnswerApp;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;

/**
 * @author 24901
 */
public interface QkjQuestionAnswerAppDao extends PagingAndSortingRepository<QkjQuestionAnswerApp, Long>, JpaSpecificationExecutor<QkjQuestionAnswerApp> {

    @Query(value = "select sum(score) from qkj_question_answer_app where type =?1 and obj_id = ?2 and mem_card = ?3 and patient_id = ?4 and qu_id in(?5) and status = 0",nativeQuery = true)
    Integer selectScoreSumByTypeAndObjIdAndQuIdaAndMemCard(Integer type, Integer id, String memCard, Integer patientId, List<Integer> quId);

    @Query(value = "select * from qkj_question_answer_app where mem_card = ?1 and  type =?2 and obj_id = ?3 and frequency = ?4 and patient_id = ?5 and status = 0",nativeQuery = true)
    List<QkjQuestionAnswerApp> selectByMemCardAndTypeAndObjIdAndFrequency(String memCard, Integer objType, Integer objId, Integer frequency, Integer patientId);

    @Query(value = "select * from qkj_question_answer_app where type =?1 and obj_id = ?2 and mem_card = ?3 and qu_id in(?4)",nativeQuery = true)
    List<QkjQuestionAnswerApp> listByTypeAndObjIdAndQuIdaAndMemCard(Integer type, Integer id, String memCard, List<Integer> quId);

    @Query(value = "select * from qkj_question_answer_app where type =?1 and mem_card = ?2 and qu_id in(?3)",nativeQuery = true)
    List<QkjQuestionAnswerApp> listByTypeAndQuIdaAndMemCard(Integer type, String memCard, List<Integer> quId);

    @Query(value = "select * from qkj_question_answer_app where type =?1 and mem_card = ?2 ", nativeQuery = true)
    List<QkjQuestionAnswerApp> listByTypeAndMemCard(Integer type, String memCard);

}
