package com.yihu.wlyy.repository.doctor;

import com.yihu.wlyy.entity.doctor.survey.SurveyTemplateQuestions;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;

/**
 * Created by Reece on 2017/3/10.
 */
public interface SurveyTemplateQuestionsDao extends PagingAndSortingRepository<SurveyTemplateQuestions, Long> {
    @Query("select  t from SurveyTemplateQuestions t where t.templateCode = ?1 and t.del = 1 ")
    List<SurveyTemplateQuestions> findById(String tempCode);

    @Query("select  t from SurveyTemplateQuestions t where t.templateCode = ?1 and t.code = ?2 ")
    SurveyTemplateQuestions findById(String tempCode, String qstCode);

    @Query("select  t.code from SurveyTemplateQuestions t where t.templateCode = ?1 and t.sort = ?2 ")
    String findBySort(String tempCode, Object sort);

    @Modifying
    @Query("update SurveyTemplateQuestions t set t.title=?3,t.questionComment=?4,t.questionType=?5," +
            "t.isRequired=?6,t.minNum=?7,t.maxNum=?8,t.sort=?9,t.questionCodeNext=?10  where t.templateCode = ?1 and t.code = ?2 ")
    int modifyQuestion(String tempCode, String qstCode, String qstTitle, String qstComment, Integer qstType,
                        Integer isRequired, Integer minNum, Integer maxNum, Integer sort, String next);

    /**
     * 修改模板问题状态（删除）
     * @param tempCode
     * @param qstCode
     */
    @Modifying
    @Query("update SurveyTemplateQuestions t set t.del = 0  where t.templateCode = ?1 and t.code = ?2 ")
    void modifyQuestion(String tempCode, String qstCode);
}
