package com.game.business.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.game.business.mapper.CfgCommonMapper;
import com.game.business.domain.CfgCommon;
import com.game.business.service.ICfgCommonService;
import com.game.common.annotation.DataSource;
import com.game.common.enums.DataSourceType;

/**
 * 公共配置Service业务层处理
 *
 * @author game
 * @date 2024-07-13
 */
@Service
public class CfgCommonServiceImpl extends ServiceImpl<CfgCommonMapper, CfgCommon> implements ICfgCommonService {
    @Autowired
    private CfgCommonMapper cfgCommonMapper;

    /**
     * 查询公共配置
     *
     * @param id 公共配置主键
     * @return 公共配置
     */
    @Override
    @DataSource(DataSourceType.SLAVE)
    public CfgCommon selectCfgCommonById(Long id) {
        return cfgCommonMapper.selectCfgCommonById(id);
    }

    /**
     * 查询公共配置列表
     *
     * @param cfgCommon 公共配置
     * @return 公共配置
     */
    @Override
    @DataSource(DataSourceType.SLAVE)
    public List<CfgCommon> selectCfgCommonList(CfgCommon cfgCommon) {
        return cfgCommonMapper.selectCfgCommonList(cfgCommon);
    }

    /**
     * 新增公共配置
     *
     * @param cfgCommon 公共配置
     * @return 结果
     */
    @Override
    @DataSource(DataSourceType.SLAVE)
    public int insertCfgCommon(CfgCommon cfgCommon) {
            return cfgCommonMapper.insertCfgCommon(cfgCommon);
    }

    /**
     * 修改公共配置
     *
     * @param cfgCommon 公共配置
     * @return 结果
     */
    @Override
    @DataSource(DataSourceType.SLAVE)
    public int updateCfgCommon(CfgCommon cfgCommon) {
        return cfgCommonMapper.updateCfgCommon(cfgCommon);
    }

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

    /**
     * 删除公共配置信息
     *
     * @param id 公共配置主键
     * @return 结果
     */
    @Override
    @DataSource(DataSourceType.SLAVE)
    public int deleteCfgCommonById(Long id) {
        return cfgCommonMapper.deleteCfgCommonById(id);
    }

    @Override
    @DataSource(DataSourceType.SLAVE)
    public CfgCommon getCfg(int type) {
        LambdaQueryWrapper<CfgCommon> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CfgCommon::getType, type);
        return cfgCommonMapper.selectOne(queryWrapper);
    }
}