package com.game.business.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.AppChargeChannelMapper;
import com.game.business.domain.AppChargeChannel;
import com.game.business.service.IAppChargeChannelService;
import com.game.common.annotation.DataSource;
import com.game.common.enums.DataSourceType;

/**
 * 充值渠道Service业务层处理
 *
 * @author game
 * @date 2024-08-13
 */
@Service
public class AppChargeChannelServiceImpl extends ServiceImpl<AppChargeChannelMapper, AppChargeChannel> implements IAppChargeChannelService {
    @Autowired
    private AppChargeChannelMapper appChargeChannelMapper;

    /**
     * 查询充值渠道
     *
     * @param id 充值渠道主键
     * @return 充值渠道
     */
    @Override
    @DataSource(DataSourceType.SLAVE)
    public AppChargeChannel selectAppChargeChannelById(Long id) {
        return appChargeChannelMapper.selectAppChargeChannelById(id);
    }

    /**
     * 查询充值渠道列表
     *
     * @param appChargeChannel 充值渠道
     * @return 充值渠道
     */
    @Override
    @DataSource(DataSourceType.SLAVE)
    public List<AppChargeChannel> selectAppChargeChannelList(AppChargeChannel appChargeChannel) {
        return appChargeChannelMapper.selectAppChargeChannelList(appChargeChannel);
    }

    /**
     * 新增充值渠道
     *
     * @param appChargeChannel 充值渠道
     * @return 结果
     */
    @Override
    @DataSource(DataSourceType.SLAVE)
    public int insertAppChargeChannel(AppChargeChannel appChargeChannel) {
            return appChargeChannelMapper.insertAppChargeChannel(appChargeChannel);
    }

    /**
     * 修改充值渠道
     *
     * @param appChargeChannel 充值渠道
     * @return 结果
     */
    @Override
    @DataSource(DataSourceType.SLAVE)
    public int updateAppChargeChannel(AppChargeChannel appChargeChannel) {
        return appChargeChannelMapper.updateAppChargeChannel(appChargeChannel);
    }

    /**
     * 批量删除充值渠道
     *
     * @param ids 需要删除的充值渠道主键
     * @return 结果
     */
    @Override
    @DataSource(DataSourceType.SLAVE)
    public int deleteAppChargeChannelByIds(Long[] ids) {
        return appChargeChannelMapper.deleteAppChargeChannelByIds(ids);
    }

    /**
     * 删除充值渠道信息
     *
     * @param id 充值渠道主键
     * @return 结果
     */
    @Override
    @DataSource(DataSourceType.SLAVE)
    public int deleteAppChargeChannelById(Long id) {
        return appChargeChannelMapper.deleteAppChargeChannelById(id);
    }

    @Override
    @DataSource(DataSourceType.SLAVE)
    public AppChargeChannel selectByKey(String key) {
        LambdaQueryWrapper<AppChargeChannel> queryWrapper = new LambdaQueryWrapper<AppChargeChannel>();
        queryWrapper.eq(AppChargeChannel::getCKey,key);
        List<AppChargeChannel> list = appChargeChannelMapper.selectList(queryWrapper);
        if(null != list && list.size()>0){
            return list.get(0);
        }
        return null;
    }
}