package com.rf.psychological.dao.repository;

import com.rf.psychological.base.repository.BaseRepository;
import com.rf.psychological.dao.model.HearingTestEntity;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author zsy
 * @description:
 * @date 2021/5/14 10:54
 */
public interface HearingTestRepository extends BaseRepository<HearingTestEntity,String> {

    /**
     * 根据id修改状态
     * @param id
     */
    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(value="update t_hearing_test set status = '0' where id = :id ",nativeQuery=true)
    void updateStatus(@Param("id")String id);

    /**
     * 根据phone获取用户进行中任务
     * @param phone
     */
    @Query(value="select * from t_hearing_test where status = '1' and binary phone = :phone",nativeQuery=true)
    List<HearingTestEntity> getHearingTestList(@Param("phone") String phone);
    /**
     * 清除进行中任务
     * @param
     */
    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(value="update t_hearing_test set status = '0' where status = '1' and binary phone = :phone",nativeQuery=true)
    void clearHearing(@Param("phone") String phone);}
