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.Collections;
import java.util.List;
        import com.game.common.utils.DateUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.game.business.mapper.AppUserLiveDividedRecordMapper;
import com.game.business.domain.AppUserLiveDividedRecord;
import com.game.business.service.IAppUserLiveDividedRecordService;
import com.game.common.annotation.DataSource;
import com.game.common.enums.DataSourceType;

/**
 * 直播分成记录表Service业务层处理
 *
 * @author game
 * @date 2024-06-30
 */
@Service
public class AppUserLiveDividedRecordServiceImpl extends ServiceImpl<AppUserLiveDividedRecordMapper, AppUserLiveDividedRecord> implements IAppUserLiveDividedRecordService {
    @Autowired
    private AppUserLiveDividedRecordMapper appUserLiveDividedRecordMapper;

    /**
     * 查询直播分成记录表
     *
     * @param id 直播分成记录表主键
     * @return 直播分成记录表
     */
    @Override
    @DataSource(DataSourceType.SLAVE)
    public AppUserLiveDividedRecord selectAppUserLiveDividedRecordById(Long id) {
        return appUserLiveDividedRecordMapper.selectAppUserLiveDividedRecordById(id);
    }

    /**
     * 查询直播分成记录表列表
     *
     * @param appUserLiveDividedRecord 直播分成记录表
     * @return 直播分成记录表
     */
    @Override
    @DataSource(DataSourceType.SLAVE)
    public List<AppUserLiveDividedRecord> selectAppUserLiveDividedRecordList(AppUserLiveDividedRecord appUserLiveDividedRecord) {
        return appUserLiveDividedRecordMapper.selectAppUserLiveDividedRecordList(appUserLiveDividedRecord);
    }

    /**
     * 新增直播分成记录表
     *
     * @param appUserLiveDividedRecord 直播分成记录表
     * @return 结果
     */
    @Override
    @DataSource(DataSourceType.SLAVE)
    public int insertAppUserLiveDividedRecord(AppUserLiveDividedRecord appUserLiveDividedRecord) {
                appUserLiveDividedRecord.setCreateTime(DateUtils.getNowDate());
            return appUserLiveDividedRecordMapper.insertAppUserLiveDividedRecord(appUserLiveDividedRecord);
    }

    /**
     * 修改直播分成记录表
     *
     * @param appUserLiveDividedRecord 直播分成记录表
     * @return 结果
     */
    @Override
    @DataSource(DataSourceType.SLAVE)
    public int updateAppUserLiveDividedRecord(AppUserLiveDividedRecord appUserLiveDividedRecord) {
        return appUserLiveDividedRecordMapper.updateAppUserLiveDividedRecord(appUserLiveDividedRecord);
    }

    /**
     * 批量删除直播分成记录表
     *
     * @param ids 需要删除的直播分成记录表主键
     * @return 结果
     */
    @Override
    @DataSource(DataSourceType.SLAVE)
    public int deleteAppUserLiveDividedRecordByIds(Long[] ids) {
        return appUserLiveDividedRecordMapper.deleteAppUserLiveDividedRecordByIds(ids);
    }

    /**
     * 删除直播分成记录表信息
     *
     * @param id 直播分成记录表主键
     * @return 结果
     */
    @Override
    @DataSource(DataSourceType.SLAVE)
    public int deleteAppUserLiveDividedRecordById(Long id) {
        return appUserLiveDividedRecordMapper.deleteAppUserLiveDividedRecordById(id);
    }

    @Override
    @DataSource(DataSourceType.SLAVE)
    public List<AppUserLiveDividedRecord> selectByDate(Long userId, String beginDate, String endDate) {
        LambdaQueryWrapper<AppUserLiveDividedRecord> queryWrapper = new LambdaQueryWrapper<>();
        if(null != userId && !"".equals(userId)) {
            queryWrapper.eq(AppUserLiveDividedRecord::getUserId, userId);
        }
        if(StringUtils.isNotBlank(beginDate)){
            queryWrapper.ge(AppUserLiveDividedRecord::getCreateTime, beginDate);
        }
        if(StringUtils.isNotBlank(endDate)){
            queryWrapper.le(AppUserLiveDividedRecord::getCreateTime,endDate);
        }
        return appUserLiveDividedRecordMapper.selectList(queryWrapper);
    }
}