package com.yihu.wlyy.repository.doctor;

import com.yihu.wlyy.entity.doctor.survey.SurveyTemplateOptions;
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 SurveyTemplateOptionsDao extends PagingAndSortingRepository<SurveyTemplateOptions, Long> {
    @Query("select t from  SurveyTemplateOptions t where  t.templateQuestionCode = ?1 and t.templateCode = ?2 and t.del = 1 ")
    List<SurveyTemplateOptions> findById(String qstcode, String tempCode);

    @Modifying
    @Query("update SurveyTemplateOptions t set t.haveComment=?4,t.content=?5," +
            "t.questionCodeNext=?6,t.isRequired=?7,t.sort=?8 where  t.templateQuestionCode = ?2 and t.templateCode = ?1 and t.code=?3")
    int modifyOption(String tempCode, String qstcode, String optcode, Integer haveCommment, String content, String nextCode, Integer isRequired, Integer sort);

    /**
     * 修改选项状态（删除）
     * @param tempCode
     * @param qstcode
     * @param optcode
     */
    @Modifying
    @Query("update SurveyTemplateOptions t set t.del = 0 where  t.templateQuestionCode = ?2 and t.templateCode = ?1 and t.code=?3")
    void modifyOption(String tempCode, String qstcode, String optcode);
}
