package com.fs.ad.service.impl;

import java.util.List;

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

/**
 * 抖音账户Service业务层处理
 * 
 * @author 吴树波
 * @date 2025-05-27
 */
@Service
@AllArgsConstructor
public class AdDyAccountServiceImpl extends ServiceImpl<AdDyAccountMapper, AdDyAccount> implements IAdDyAccountService {

    private final IAdAccountService adAccountService;

    /**
     * 查询抖音账户
     * 
     * @param id 抖音账户主键
     * @return 抖音账户
     */
    @Override
    public AdDyAccount selectAdDyAccountById(Long id)
    {
        return baseMapper.selectAdDyAccountById(id);
    }

    /**
     * 查询抖音账户列表
     * 
     * @param adDyAccount 抖音账户
     * @return 抖音账户
     */
    @Override
    public List<AdDyAccount> selectAdDyAccountList(AdDyAccount adDyAccount)
    {
        return baseMapper.selectAdDyAccountList(adDyAccount);
    }

    /**
     * 新增抖音账户
     * 
     * @param adDyAccount 抖音账户
     * @return 结果
     */
    @Override
    public int insertAdDyAccount(AdDyAccount adDyAccount)
    {
        adDyAccount.setCreateTime(DateUtils.getNowDate());
        int i = baseMapper.insertAdDyAccount(adDyAccount);
        AdAccount adAccount = new AdAccount();
        adAccount.setName(adDyAccount.getAdvertiserName());
        adAccount.setType(3);
        adAccount.setLinkId(adDyAccount.getId());
        adAccountService.save(adAccount);
        return i;
    }

    /**
     * 修改抖音账户
     * 
     * @param adDyAccount 抖音账户
     * @return 结果
     */
    @Override
    public int updateAdDyAccount(AdDyAccount adDyAccount)
    {
        adDyAccount.setUpdateTime(DateUtils.getNowDate());
        int i = baseMapper.updateAdDyAccount(adDyAccount);
        AdAccount adAccount = adAccountService.selectByLinkId(3, adDyAccount.getId());
        adAccount.setName(adDyAccount.getAdvertiserName());
        adAccountService.updateById(adAccount);
        return i;
    }

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

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