package com.game.business.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.game.business.domain.AppGameItemMultiple;
import com.game.business.mapper.AppGameItemMultipleMapper;
import com.game.business.service.IAppGameItemMultipleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class AppGameItemMultipleServiceImpl extends ServiceImpl<AppGameItemMultipleMapper, AppGameItemMultiple> implements IAppGameItemMultipleService {

    @Autowired
    private AppGameItemMultipleMapper appGameItemMultipleMapper;

    @Override
    public Boolean checkAooGameItemMultiple(Long gameId, String gameDate) {
        LambdaQueryWrapper<AppGameItemMultiple> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AppGameItemMultiple::getGameId, gameId);
        queryWrapper.eq(AppGameItemMultiple::getGameDate, gameDate);
        return appGameItemMultipleMapper.selectCount(queryWrapper) > 0;
    }

    @Override
    public AppGameItemMultiple getAppGameItemMultiple(Long gameId, String gameDate) {
        LambdaQueryWrapper<AppGameItemMultiple> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AppGameItemMultiple::getGameId, gameId);
        queryWrapper.eq(AppGameItemMultiple::getGameDate, gameDate);
        return appGameItemMultipleMapper.selectOne(queryWrapper);
    }

    @Override
    public List<AppGameItemMultiple> getAppGameItemMultipleList(Long gameId) {
        LambdaQueryWrapper<AppGameItemMultiple> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AppGameItemMultiple::getGameId, gameId);
        queryWrapper.orderByDesc(AppGameItemMultiple::getCreateTime).orderByDesc(AppGameItemMultiple::getGameDate);
        queryWrapper.last(" limit 2100");
        return appGameItemMultipleMapper.selectList(queryWrapper);
    }
}
