package com.td.boss.game.complayerprofit.repository;

import com.td.boss.common.repository.*;
import com.td.boss.game.complayerprofit.pojo.ComPlayerProfit;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface ComPlayerProfitRepository extends CommonRepository<ComPlayerProfit, String> {

    /**
     * 查询用户被偷取的信息，使用targetId
     * @param targetId
     * @param plantFlag
     * @param landId
     * @return
     */
    List<ComPlayerProfit> findByTargetIdAndPlantFlagAndLandId(String targetId, String plantFlag, Integer landId);

    Optional<ComPlayerProfit> findByUserIdAndPlantFlag(String userId, String plantFlag);

    Optional<ComPlayerProfit> findByUserIdAndTargetIdAndPlantFlag(String userId,String otherUserId, String plantFlag);

    Optional<ComPlayerProfit> findByUserIdAndTargetIdAndLandIdAndPlantFlag(String userId, String targetId, Integer landId, String plantFlag);

    @Query(value = "SELECT IFNULL(sum(u.stolen), 0.0) AS sum FROM  com_player_profit u  where u.target_id=:targetId and u.plant_flag = :plantFlag", nativeQuery = true)
    Double getStolenSumByTargetIdAndPlantFlag(String targetId,String plantFlag);
}
