package com.ssj.dao.weixin.user.dao;

import com.ssj.bean.weixin.user.domain.SubActivity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public interface SubActivityDao  extends JpaRepository<SubActivity, String>{
	
	 @Query(nativeQuery = true, value = " SELECT * from tb_sub_activity t where t.type=2 AND t.remarks=?1 ORDER BY t.create_time DESC  ")
	 List<SubActivity> findSubActivityByRemarks(String remarks);
	
	 @Query(nativeQuery = true, value = " SELECT * from tb_sub_activity t WHERE  t.type=2 and t.remarks=?1 and t.openid=?2 ORDER BY t.create_time DESC  ")
	 List<SubActivity> findSubActivityByPO(String remarks,String openId);

	 @Query(nativeQuery = true, value = " SELECT * from tb_sub_activity t WHERE  t.type=2 and t.openid=?1 ORDER BY t.create_time DESC  ")
	 List<SubActivity> findSubActivityByOpenid(String openId);

	@Query(nativeQuery = true, value = " SELECT * from tb_sub_activity t WHERE  t.type=?3 and t.openid=?1 and t.parent_id=?2 limit 1  ")
    SubActivity findByOpenidAndParentId(String openId, String objectId,int type);

	@Query(nativeQuery = true, value = " SELECT count(DISTINCT openid) from tb_sub_activity  WHERE  type=?2 and  parent_id=?1   ")
	int findCountByParentId(String objectId,int type);
	 @Query(nativeQuery = true, value = " SELECT * from tb_sub_activity t WHERE  t.type=?2 and t.openid=?1 ORDER BY t.create_time DESC  LIMIT 1  ")
	 SubActivity getSubActivityByOpenidAndType(String openId,int type);

}
