package com.fs.ad.service.impl;

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

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fs.ad.domain.AdAccount;
import com.fs.ad.service.IAdAccountService;
import com.fs.common.utils.DateUtils;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fs.ad.mapper.AdYoukuAccountMapper;
import com.fs.ad.domain.AdYoukuAccount;
import com.fs.ad.service.IAdYoukuAccountService;

/**
 * 优酷广告账号Service业务层处理
 * 
 * @author fs
 * @date 2025-02-19
 */
@Service
@AllArgsConstructor
public class AdYoukuAccountServiceImpl extends ServiceImpl<AdYoukuAccountMapper, AdYoukuAccount> implements IAdYoukuAccountService {
    private final IAdAccountService adAccountService;
    /**
     * 查询优酷广告账号
     * 
     * @param id 优酷广告账号主键
     * @return 优酷广告账号
     */
    @Override
    public AdYoukuAccount selectAdYoukuAccountById(Long id)
    {
        return baseMapper.selectAdYoukuAccountById(id);
    }

    /**
     * 查询优酷广告账号列表
     * 
     * @param adYoukuAccount 优酷广告账号
     * @return 优酷广告账号
     */
    @Override
    public List<AdYoukuAccount> selectAdYoukuAccountList(AdYoukuAccount adYoukuAccount)
    {
        return baseMapper.selectAdYoukuAccountList(adYoukuAccount);
    }

    /**
     * 新增优酷广告账号
     * 
     * @param adYoukuAccount 优酷广告账号
     * @return 结果
     */
    @Override
    public int insertAdYoukuAccount(AdYoukuAccount adYoukuAccount)
    {
        adYoukuAccount.setCreateTime(DateUtils.getNowDate());
        int i = baseMapper.insertAdYoukuAccount(adYoukuAccount);
        AdAccount adAccount = new AdAccount();
        adAccount.setName(adYoukuAccount.getAccountName());
        adAccount.setType(1);
        adAccount.setLinkId(adYoukuAccount.getId());
        adAccountService.save(adAccount);
        return i;
    }

    /**
     * 修改优酷广告账号
     * 
     * @param adYoukuAccount 优酷广告账号
     * @return 结果
     */
    @Override
    public int updateAdYoukuAccount(AdYoukuAccount adYoukuAccount)
    {
        adYoukuAccount.setUpdateTime(DateUtils.getNowDate());
        AdAccount adAccount = adAccountService.selectByLinkId(adYoukuAccount.getId());
        adAccount.setName(adYoukuAccount.getAccountName());
        adAccountService.updateById(adAccount);
        return baseMapper.updateAdYoukuAccount(adYoukuAccount);
    }

    /**
     * 批量删除优酷广告账号
     * 
     * @param ids 需要删除的优酷广告账号主键
     * @return 结果
     */
    @Override
    public int deleteAdYoukuAccountByIds(Long[] ids)
    {
        adAccountService.deleteByLinkIds(1, ids);
        return baseMapper.deleteAdYoukuAccountByIds(ids);
    }

    /**
     * 删除优酷广告账号信息
     * 
     * @param id 优酷广告账号主键
     * @return 结果
     */
    @Override
    public int deleteAdYoukuAccountById(Long id)
    {
        adAccountService.deleteByLinkId(1, id);
        return baseMapper.deleteAdYoukuAccountById(id);
    }

    @Override
    public List<AdYoukuAccount> listAll() {
        return super.list();
    }
}
