package com.bizzan.bitrade.dao;

import com.bizzan.bitrade.entity.ContractRewardRecord;

import java.util.Date;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.data.repository.query.Param;

public interface ContractRewardRecordRepository extends JpaRepository<ContractRewardRecord, Long>, JpaSpecificationExecutor<ContractRewardRecord>, QueryDslPredicateExecutor<ContractRewardRecord> {

	@Query("SELECT sum(num) as total_reward FROM ContractRewardRecord WHERE member_id=:memberId")
	Double findRewardSum(@Param("memberId") Long memberId);
	
	@Query("SELECT sum(num) as total_reward FROM ContractRewardRecord WHERE createTime between :startDate and :endDate and member_id=:memberId")
	Double findRewardSum(@Param("startDate") Date startDate, @Param("endDate") Date endDate, @Param("memberId") Long memberId);
}
