package com.ssj.dao.sys.award.dao;


import com.ssj.bean.sys.award.domain.AwardSncode;
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;

import java.util.List;

@Repository
public interface AwardSncodeDao extends JpaRepository<AwardSncode, String>{
	
	@Query(nativeQuery = true, value = " SELECT * from tb_award_sncode t WHERE t.award_activity_id=?1 ")
	List<AwardSncode> findAwardSncodeByAwardActivityId(String awardActivityId);
	
	@Query(nativeQuery = true, value = " SELECT * from tb_award_sncode t WHERE t.award_activity_id=?1 AND t.status=?2 ")
	List<AwardSncode> findAwardSncodeByAwardActivityId(String awardActivityId,Integer status);
	
	@Query(nativeQuery = true, value = " SELECT * from tb_award_sncode t WHERE t.award_activity_id=?1 AND t.award_material_id=?2 AND t.status=?3 ")
	List<AwardSncode> findAwardSncodeByAwardMaterialId(String awardActivityId,String awardMaterialId,Integer status);
	
	@Query(nativeQuery = true, value = " SELECT * from tb_award_sncode t WHERE t.`status`=0 AND t.award_activity_id=?1 AND t.award_material_id=?2 ORDER BY RAND() LIMIT 1 ")
	AwardSncode randomAwardSncodeByActivityIdAndMaterialId(String awardActivityId,String materialId);
	
	@Query(nativeQuery = true, value = " SELECT * from tb_award_sncode t WHERE t.sn_code=?1  LIMIT 1 ")
	AwardSncode getAwardSncodeBySnCode(String snCode);
	
	@Query(nativeQuery = true, value = "update tb_award_sncode set sn_img =?2 where sn_code = ?1  ")
	@Modifying
	void updateSnCodeImgBySnCode(String snCode, String snCodeImg);
	
}
