package com.ssj.dao.weixin.grword.dao;

import com.ssj.bean.weixin.grword.domain.TbReadScore;
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;

@Repository
public interface ReadScoreDao extends JpaRepository<TbReadScore, String>{

	@Query(nativeQuery = true, value = " SELECT * from tb_read_score t WHERE t.user_id=?1 AND t.isbn13=?2 AND t.state=?3 ORDER BY t.start_time DESC LIMIT  1 ")
	TbReadScore findScoreByState(String userId, String isbn13, String state);
	
	TbReadScore findScoreById(String id);
	
	@Query(nativeQuery = true, value = " SELECT * from tb_read_score t WHERE t.user_id=?1 AND t.isbn13=?2  AND t.end_time is NOT NULL ORDER BY t.end_time DESC LIMIT 1")
	TbReadScore findNewScoreByisbn13(String userId, String isbn13);
	
	@Query(nativeQuery = true, value = "UPDATE tb_read_score t SET t.adopt=1 WHERE t.user_id=?1 AND t.isbn13=?2   ")
	@Modifying
	public void updateReadAnswerAdopt(String userId, String isbn13);
	
}
