package com.game.business.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

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

import com.game.common.annotation.DataSource;
import com.game.common.enums.DataSourceType;
import com.game.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.game.business.mapper.AppGameMapper;
import com.game.business.domain.AppGame;
import com.game.business.service.IAppGameService;

/**
 * 游戏配置Service业务层处理
 *
 * @author game
 * @date 2024-06-14
 */
@Service
public class AppGameServiceImpl extends ServiceImpl<AppGameMapper, AppGame> implements IAppGameService {
    @Autowired
    private AppGameMapper appGameMapper;

    /**
     * 查询游戏配置
     *
     * @param id 游戏配置主键
     * @return 游戏配置
     */
    @Override
    @DataSource(DataSourceType.SLAVE)
    public AppGame selectAppGameById(Long id) {
        return appGameMapper.selectAppGameById(id);
    }

    /**
     * 查询游戏配置列表
     *
     * @param appGame 游戏配置
     * @return 游戏配置
     */
    @Override
    @DataSource(DataSourceType.SLAVE)
    public List<AppGame> selectAppGameList(AppGame appGame) {
        return appGameMapper.selectAppGameList(appGame);
    }

    /**
     * 新增游戏配置
     *
     * @param appGame 游戏配置
     * @return 结果
     */
    @Override
    @DataSource(DataSourceType.SLAVE)
    public int insertAppGame(AppGame appGame) {
                appGame.setCreateTime(DateUtils.getNowDate());
            return appGameMapper.insertAppGame(appGame);
    }

    /**
     * 修改游戏配置
     *
     * @param appGame 游戏配置
     * @return 结果
     */
    @Override
    @DataSource(DataSourceType.SLAVE)
    public int updateAppGame(AppGame appGame) {
        return appGameMapper.updateAppGame(appGame);
    }

    /**
     * 批量删除游戏配置
     *
     * @param ids 需要删除的游戏配置主键
     * @return 结果
     */
    @Override
    @DataSource(DataSourceType.SLAVE)
    public int deleteAppGameByIds(Long[] ids) {
        return appGameMapper.deleteAppGameByIds(ids);
    }

    /**
     * 删除游戏配置信息
     *
     * @param id 游戏配置主键
     * @return 结果
     */
    @Override
    @DataSource(DataSourceType.SLAVE)
    public int deleteAppGameById(Long id) {
        return appGameMapper.deleteAppGameById(id);
    }

    @Override
    @DataSource(DataSourceType.SLAVE)
    public List<AppGame> selectAppGameByClassId(Long classId) {
        LambdaQueryWrapper<AppGame> queryGameWrapper = Wrappers.lambdaQuery();;
        queryGameWrapper.eq(AppGame::getClassifyId, classId);
        return appGameMapper.selectList(queryGameWrapper);
    }

    @Override
    @DataSource(DataSourceType.SLAVE)
    public AppGame selectAppGameByClassIdAndCode(Long classId, String code) {
        LambdaQueryWrapper<AppGame> queryGameWrapper = Wrappers.lambdaQuery();;
        queryGameWrapper.eq(AppGame::getCode, code);
        queryGameWrapper.eq(AppGame::getClassifyId, classId);
        return appGameMapper.selectOne(queryGameWrapper);
    }

    @Override
    @DataSource(DataSourceType.SLAVE)
    public List<AppGame> selectByIds(List<Long> ids) {
        LambdaQueryWrapper<AppGame> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.in(AppGame::getId, ids);
        return appGameMapper.selectList(queryWrapper);
    }
}