package com.xxl.job.executor.batch.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xxl.job.executor.batch.entity.KuaiShouAdvertiserBaseInfo;
import com.xxl.job.executor.batch.mapper.KuaiShouAdvertiserBaseInfoMapper;
import com.xxl.job.executor.batch.service.IKuaiShouAdvertiserBaseInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 快手-广告主基本信息
 *
 * @author jeecg-boot
 * @version V1.0
 * @date 2019-09-18
 */
@Service
public class KuaiShouAdvertiserBaseInfoServiceImpl extends ServiceImpl<KuaiShouAdvertiserBaseInfoMapper, KuaiShouAdvertiserBaseInfo> implements IKuaiShouAdvertiserBaseInfoService {
    @Autowired
    private KuaiShouAdvertiserBaseInfoMapper advertiserBaseInfoMapper;

    /**
     * 根据accountId获取对象
     *
     * @param accountId
     * @return
     */
    @Override
    public KuaiShouAdvertiserBaseInfo getBaseInfo(Long accountId) {
        QueryWrapper<KuaiShouAdvertiserBaseInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("account_id", accountId);
        queryWrapper.last("limit 1");
        return advertiserBaseInfoMapper.selectOne(queryWrapper);
    }

    /**
     * 获取账户列表
     *
     * @param userId
     * @return
     */
    @Override
    public List<KuaiShouAdvertiserBaseInfo> getAccountIdList(String userId) {
        QueryWrapper<KuaiShouAdvertiserBaseInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        queryWrapper.groupBy("account_id");
        return advertiserBaseInfoMapper.selectList(queryWrapper);
    }
}
