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

import com.td.boss.common.service.*;
import com.td.boss.game.complayergoods.pojo.ComPlayerGoods;
import com.td.boss.game.complayergoods.vo.ComPlayerGoodsSimpleVo;
import com.td.boss.game.complayergoods.vo.ComPlayerGoodsTypeSumVo;
import com.td.boss.game.complayergoods.vo.ComPlayerGoodsVo;
import com.td.boss.game.complayergoods.repository.ComPlayerGoodsRepository;
import com.td.boss.util.CopyUtil;
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;
import java.util.Optional;

@Service
@Transactional
public class ComPlayerGoodsServiceImpl extends CommonServiceImpl<ComPlayerGoodsVo, ComPlayerGoods, String> implements ComPlayerGoodsService{

    @PersistenceContext
    private EntityManager em;
    @Autowired
    private ComPlayerGoodsRepository comPlayerGoodsRepository;


    @Override
    public ComPlayerGoods findByUserIdAndIndexAndType(String userId,Integer index, Integer type) {
        Optional<ComPlayerGoods>  comPlayerGoods = comPlayerGoodsRepository.findByUserIdAndGoodsIndexAndGoodsType(userId,index,type);
        return comPlayerGoods.orElse(null);
    }

    @Override
    public List<ComPlayerGoods> findAllByUserId(String userId) {
        return comPlayerGoodsRepository.findAllByUserId(userId);
    }


    @Override
    public List<ComPlayerGoodsTypeSumVo> findAllGroupByGoodsType() {
        return comPlayerGoodsRepository.findAmountSumByGoodsType();
    }
}
