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

import com.td.boss.common.repository.*;
import com.td.boss.game.complayergoods.pojo.ComPlayerGoods;
import com.td.boss.game.complayergoods.vo.ComPlayerGoodsTypeSumVo;
import com.td.boss.game.complayergoods.vo.ComPlayerGoodsVo;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

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

@Repository
public interface ComPlayerGoodsRepository extends CommonRepository<ComPlayerGoods, String> {

    Optional<ComPlayerGoods> findByUserIdAndGoodsIndexAndGoodsType(String userId, Integer index , Integer type);


    List<ComPlayerGoods> findAllByUserId(String userId);



    /**
     * 返回一个降序的goods_type统计
     *
     * @return
     */
    @Query(value = "SELECT new com.td.boss.game.complayergoods.vo.ComPlayerGoodsTypeSumVo(u.goodsType,sum(u.amount)) from ComPlayerGoods u GROUP BY u.goodsType ORDER BY sum(u.amount) desc", nativeQuery = false)
    List<ComPlayerGoodsTypeSumVo> findAmountSumByGoodsType();
}
