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


import java.util.Map;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import com.ssj.bean.sys.award.domain.AwardActivity;

@Repository
public interface AwardActivityDao extends JpaRepository<AwardActivity, String>{
	
	
	@Query(nativeQuery = true, value = " SELECT * from tb_award_activity t WHERE t.merchant_id=?1 AND t.status=?2 LIMIT 1 ")
	public AwardActivity getAwardActivityByMerchantId(String merchantId,Integer status);
	
	
	@Query(nativeQuery = true, value = 
			  " SELECT t.*, "
			+ " m1.`name` as level1_material_name ,m1.img as level1_material_img,m1.`level` as level1_material_level,m1.exchange_integral as level1_material_exchange_integral, "
			+ " m2.`name` as level2_material_name ,m2.img as level2_material_img,m2.`level` as level2_material_level,m2.exchange_integral as level2_material_exchange_integral, "
			+ " m3.`name` as level3_material_name ,m3.img as level3_material_img,m1.`level` as level3_material_level,m3.exchange_integral as level3_material_exchange_integral "
			+ " from tb_award_activity t  "
			+ " LEFT JOIN tb_award_material m1 ON t.level1_material_id=m1.id "
			+ " LEFT JOIN tb_award_material m2 ON t.level2_material_id=m2.id "
			+ " LEFT JOIN tb_award_material m3 ON t.level3_material_id=m3.id "
			+ " WHERE t.merchant_id=?1 AND t.status=?2 LIMIT 1 ")
	public Map<String,Object> getAwardActivityMapByMerchantId(String merchantId,Integer status);
	
	
}
