package com.fs.ad.service.impl;

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

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fs.ad.domain.AdConfig;
import com.fs.common.utils.DateUtils;
import com.fs.common.utils.uuid.IdUtils;
import com.fs.system.domain.SysConfig;
import com.fs.system.mapper.SysConfigMapper;
import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fs.ad.mapper.AdHtmlTemplateMapper;
import com.fs.ad.domain.AdHtmlTemplate;
import com.fs.ad.service.IAdHtmlTemplateService;

/**
 * 广告信息流链接Service业务层处理
 * 
 * @author fs
 * @date 2024-12-31
 */
@Service
public class AdHtmlTemplateServiceImpl extends ServiceImpl<AdHtmlTemplateMapper, AdHtmlTemplate> implements IAdHtmlTemplateService {
    @Autowired
    private AdHtmlTemplateMapper adHtmlTemplateMapper;
    @Autowired
    private SysConfigMapper sysConfigMapper;

    /**
     * 查询广告信息流链接
     * 
     * @param id 广告信息流链接主键
     * @return 广告信息流链接
     */
    @Override
    public AdHtmlTemplate selectAdHtmlUrlById(Long id)
    {
        return adHtmlTemplateMapper.selectAdHtmlUrlById(id);
    }

    /**
     * 查询广告信息流链接列表
     * 
     * @param adHtmlTemplate 广告信息流链接
     * @return 广告信息流链接
     */
    @Override
    public List<AdHtmlTemplate> selectAdHtmlUrlList(AdHtmlTemplate adHtmlTemplate)
    {
        return adHtmlTemplateMapper.selectAdHtmlUrlList(adHtmlTemplate);
    }

    /**
     * 新增广告信息流链接
     * 
     * @param adHtmlTemplate 广告信息流链接
     * @return 结果
     */
    @Override
    public int insertAdHtmlUrl(AdHtmlTemplate adHtmlTemplate)
    {
        adHtmlTemplate.setNo(IdUtils.fastUUID());
        SysConfig sysConfig = sysConfigMapper.selectConfigByConfigKey("his.ad");
        AdConfig adConfig = new Gson().fromJson(sysConfig.getConfigValue(), AdConfig.class);
        adHtmlTemplate.setUrl(adConfig.getBaseUrl() + "?no=" + adHtmlTemplate.getNo());
        adHtmlTemplate.setCreateTime(DateUtils.getNowDate());
        return adHtmlTemplateMapper.insert(adHtmlTemplate);
    }

    /**
     * 修改广告信息流链接
     * 
     * @param adHtmlTemplate 广告信息流链接
     * @return 结果
     */
    @Override
    public int updateAdHtmlUrl(AdHtmlTemplate adHtmlTemplate)
    {
        adHtmlTemplate.setUpdateTime(DateUtils.getNowDate());
        return adHtmlTemplateMapper.updateById(adHtmlTemplate);
    }

    /**
     * 批量删除广告信息流链接
     * 
     * @param ids 需要删除的广告信息流链接主键
     * @return 结果
     */
    @Override
    public int deleteAdHtmlUrlByIds(Long[] ids)
    {
        return adHtmlTemplateMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除广告信息流链接信息
     * 
     * @param id 广告信息流链接主键
     * @return 结果
     */
    @Override
    public int deleteAdHtmlUrlById(Long id)
    {
        return adHtmlTemplateMapper.deleteById(id);
    }
}
