package cn.com.ctop.alarm.modules.service.impl;

import cn.com.ctop.alarm.modules.service.ExternalLinkService;
import cn.com.ctop.common.module.utils.Check;
import cn.com.ctop.common.module.utils.HttpUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * 调取外部接口
 */
@Slf4j
@Service
public class ExternalLinkServiceImpl implements ExternalLinkService {
    //修改头条CPABID出价,投放时间
    private static final String URL_UPDATE_CPABID = "http://139.186.165.84:8808/bytedance-api/advertiser/bytedanceReportController/updateADCpaBid";
    //线上IP  http://118.24.244.213:8808/bytedance-api/advertiser/bytedanceReportController/updateADCpaBid
    //测试IP  http://139.186.165.84:8808/bytedance-api/advertiser/bytedanceReportController/updateADCpaBid

    @Override
    public String editBytedancePlanCpaBidOrBudget(Long accountId, String adId, BigDecimal cpaBid, String adScheduleTime, Long budget) {
        StringBuffer buf = new StringBuffer();
        buf.append("?accountId=").append(accountId).append("&adId=").append(adId);
        if (!Check.isNull(cpaBid)) {
            buf.append("&cpaBid=").append(cpaBid);
        }
        if (!Check.isNull(adScheduleTime)) {
            buf.append("&adScheduleTime=").append(adScheduleTime);
        }
        if (!Check.isNull(budget)) {
            buf.append("&budget=").append(budget);
        }
        log.info("调用微服务接口，修改头条计划出价、预算、投放时间段。。。。。。start");
        HttpUtils.httpGet(URL_UPDATE_CPABID + buf.toString(), null, null);
        log.info("调用微服务接口，修改头条计划出价、预算、投放时间段。。。。。。end");
        return null;
    }


}
