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

import com.td.boss.common.service.*;
import com.td.boss.game.complayerprofit.pojo.ComPlayerProfit;
import com.td.boss.game.complayerprofit.vo.ComPlayerProfitVo;
import com.td.boss.game.complayerprofit.repository.ComPlayerProfitRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.List;

@Service
@Transactional
public class ComPlayerProfitServiceImpl extends CommonServiceImpl<ComPlayerProfitVo, ComPlayerProfit, String> implements ComPlayerProfitService{

    @PersistenceContext
    private EntityManager em;
    @Autowired
    private ComPlayerProfitRepository comPlayerProfitRepository;

    @Override
    public List<ComPlayerProfit> findByUserIdAndPlantFlagAndLandId(String userId, String plantFlag, Integer landId) {
        return comPlayerProfitRepository.findByTargetIdAndPlantFlagAndLandId(userId,plantFlag,landId);
    }

    @Override
    public ComPlayerProfit findByUserIdAndPlantFlag(String userId,String plantFlag) {
        return comPlayerProfitRepository.findByUserIdAndPlantFlag(userId,plantFlag).orElse(null);
    }
    @Override
    public ComPlayerProfit findByUserIdAndOtherUserIdAndPlantFlag(String userId,String otherUserId, String plantFlag) {
        return comPlayerProfitRepository.findByUserIdAndTargetIdAndPlantFlag(userId,otherUserId,plantFlag).orElse(null);
    }


    @Override
    public ComPlayerProfit findByUserIdAndTargetIdAndLandIdAndPlantFlag(String userId,String targetId, Integer configLandId, String plantFlag) {
        return comPlayerProfitRepository.findByUserIdAndTargetIdAndLandIdAndPlantFlag(userId,targetId,configLandId,plantFlag).orElse(null);
    }

    @Override
    public Double getStolenSumByOtherUserIdAndPlantFlag(String otherUserId, String plantFlag) {
        return comPlayerProfitRepository.getStolenSumByTargetIdAndPlantFlag(otherUserId,plantFlag);
    }
}
