package com.ssj.dao.sys.fx.dao;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import com.ssj.bean.sys.fx.domain.Merchant;

@Repository
public interface MerchantDao extends JpaRepository<Merchant, String> {
	
	public Page<Merchant> findAll(Specification<Merchant> specification, Pageable page);
	
	@Query(nativeQuery = true, value = " SELECT * from fx_merchant t where t.`status`!=4 ORDER BY t.create_time ASC ")
	public List<Merchant> findMerchantByPage();
		
	@Query(nativeQuery = true, value = " SELECT * from fx_merchant t where t.pos_code=?1 LIMIT 1 ")
	public Merchant getMerchantByPosCode(String posCode);
	
	@Query(nativeQuery = true, value = " SELECT * from fx_merchant t where t.lib_id=?1 LIMIT 1 ")
	public Merchant getMerchantByLibId(String libId);
	
	@Query(nativeQuery = true, value = "SELECT * from fx_merchant t where t.parent_pos_code=?1 AND t.`status`!=4 ORDER BY t.create_time ASC   ")
	public List<Merchant> getMerchantByParentPosCode(String ParentPosCode);
	
	@Query(nativeQuery = true, value = "SELECT * from fx_merchant t where t.org_code LIKE  CONCAT(?1,'%')  AND t.`status`!=4 ORDER BY t.create_time ASC ")
	public List<Merchant> getMerchantByLikeOrgCode(String orgCode);
	
	@Query(nativeQuery = true, value = "SELECT * from fx_merchant t where t.pos_code LIKE  CONCAT(?1,'%') ORDER BY t.create_time ASC ")
	public List<Merchant> getMerchantByLikePosCode(String posCode);

	@Query(nativeQuery = true, value = " SELECT * from fx_merchant t where t.type in ?1 ORDER BY t.create_time ASC ")
	public List<Merchant> findMerchantByType(int[] type);
	
	@Query(nativeQuery = true, value = " SELECT * from fx_merchant t where t.org_code!='SSJ-FX' AND (t.parent_pos_code is null OR t.parent_pos_code='') ORDER BY t.create_time ASC  ")
	public List<Merchant> findMerchantByNotParent();
	
	@Query(nativeQuery = true, value = " SELECT t.* from fx_merchant t LEFT JOIN tb_lib_vip v ON t.lib_id=v.lib_id WHERE v.id IS NOT NULL AND v.id=?1 ORDER BY t.create_time DESC LIMIT 1 ")
	public Merchant getMerchantByVipId(String vipId);
	
	@Query(nativeQuery = true, value = " SELECT * from fx_merchant t where t.pos_type in (2,3)  ORDER BY t.create_time ASC ")
	public List<Merchant> findMerchantSignByAll();
	
	@Query(nativeQuery = true, value = " SELECT * from fx_merchant t where t.sign_type>=1 AND TO_DAYS(t.next_summary_time)=TO_DAYS(NOW()) ORDER BY t.create_time ASC ")
	public List<Merchant> findMerchantSignBySummaryTime();
	
	@Query(nativeQuery = true, value = " SELECT * from fx_merchant t where t.sign_type>=1 AND TO_DAYS(t.active_time)=TO_DAYS(NOW()) ORDER BY t.create_time ASC ")
	public List<Merchant> findMerchantSignByActiveTime();
	
	@Query(nativeQuery = true, value = " SELECT * from fx_merchant t where t.sign_type>=1 AND TO_DAYS(t.compute_time)=TO_DAYS(NOW()) ORDER BY t.create_time ASC ")
	public List<Merchant> findMerchantSignByComputeTime();
	
	
	
	
}
