package com.fs.ad.service.impl;

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

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fs.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fs.ad.mapper.AdAccountMapper;
import com.fs.ad.domain.AdAccount;
import com.fs.ad.service.IAdAccountService;

/**
 * 推广账户Service业务层处理
 * 
 * @author fs
 * @date 2025-03-04
 */
@Service
public class AdAccountServiceImpl extends ServiceImpl<AdAccountMapper, AdAccount> implements IAdAccountService {

    /**
     * 查询推广账户
     * 
     * @param id 推广账户主键
     * @return 推广账户
     */
    @Override
    public AdAccount selectAdAccountById(Long id)
    {
        return baseMapper.selectAdAccountById(id);
    }

    /**
     * 查询推广账户列表
     * 
     * @param adAccount 推广账户
     * @return 推广账户
     */
    @Override
    public List<AdAccount> selectAdAccountList(AdAccount adAccount)
    {
        return baseMapper.selectAdAccountList(adAccount);
    }

    /**
     * 新增推广账户
     * 
     * @param adAccount 推广账户
     * @return 结果
     */
    @Override
    public int insertAdAccount(AdAccount adAccount)
    {
        adAccount.setCreateTime(DateUtils.getNowDate());
        return baseMapper.insertAdAccount(adAccount);
    }

    /**
     * 修改推广账户
     * 
     * @param adAccount 推广账户
     * @return 结果
     */
    @Override
    public int updateAdAccount(AdAccount adAccount)
    {
        adAccount.setUpdateTime(DateUtils.getNowDate());
        return baseMapper.updateAdAccount(adAccount);
    }

    /**
     * 批量删除推广账户
     * 
     * @param ids 需要删除的推广账户主键
     * @return 结果
     */
    @Override
    public int deleteAdAccountByIds(Long[] ids)
    {
        return baseMapper.deleteAdAccountByIds(ids);
    }

    /**
     * 删除推广账户信息
     * 
     * @param id 推广账户主键
     * @return 结果
     */
    @Override
    public int deleteAdAccountById(Long id)
    {
        return baseMapper.deleteAdAccountById(id);
    }

    @Override
    public AdAccount selectByLinkId(Long id) {
        return getOne(new QueryWrapper<AdAccount>().eq("link_id",id));
    }

    @Override
    public void deleteByLinkId(Integer type, Long id) {
        remove(new QueryWrapper<AdAccount>().eq("type", type).eq("link_id",id));
    }

    @Override
    public void deleteByLinkIds(Integer type, Long[] id) {
        remove(new QueryWrapper<AdAccount>().eq("type", type).in("link_id", Arrays.asList(id)));
    }

    @Override
    public List<AdAccount> listAll() {
        return list();
    }
}
