package cn.com.ctop.track.service.impl;

import cn.com.ctop.track.entity.TaobaoNotice;
import cn.com.ctop.track.mapper.TaobaoNoticeMapper;
import cn.com.ctop.track.service.TaobaoNoticeService;
import cn.com.ctop.track.utils.HttpUtils;
import cn.hutool.http.HttpUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import org.apache.log4j.Logger;

@Service
public class TaobaoNoticeServiceImpl extends ServiceImpl<TaobaoNoticeMapper, TaobaoNotice> implements TaobaoNoticeService {
    private static Logger logger = Logger.getLogger(TaobaoNoticeServiceImpl.class);
    public void sendNotice(String spaceId,String campaignId,String campaignName,String creativeId,String imei,String idfa,String oaid,String dpaId,String dpaType,String callbackUrl){
        TaobaoNotice taobaoNotice = new TaobaoNotice();
        taobaoNotice.setAdid(campaignId);
        taobaoNotice.setAdname(campaignName);
        taobaoNotice.setAdvertisingSpaceId(spaceId);
        taobaoNotice.setApp("1");
        taobaoNotice.setCallbackUrl(callbackUrl);
        taobaoNotice.setChannel("2200803434135");
        taobaoNotice.setCid(creativeId);
        taobaoNotice.setOaid(oaid);
        taobaoNotice.setIdfaMd5(idfa);
        taobaoNotice.setImeiMd5(imei);
        taobaoNotice.setServiceProviderName("北京汇创思拓数字科技有限公司");
        taobaoNotice.setTaskId("346834137");

        String url = "https://wcp.taobao.com/adstrack/track.json?action=2";
        Map<String,Object> paramMap = new HashMap<>();
        paramMap.put("adid",taobaoNotice.getAdid());
        paramMap.put("oaid",taobaoNotice.getOaid());
        paramMap.put("adname",taobaoNotice.getAdname());
        paramMap.put("advertisingSpaceId",taobaoNotice.getAdvertisingSpaceId());
        paramMap.put("app",taobaoNotice.getApp());
        paramMap.put("callbackUrl",taobaoNotice.getCallbackUrl());
        paramMap.put("channel",taobaoNotice.getChannel());
        paramMap.put("cid",taobaoNotice.getCid());
        paramMap.put("imeiMd5",taobaoNotice.getImeiMd5());
        paramMap.put("serviceProviderName",taobaoNotice.getServiceProviderName());
        paramMap.put("taskId",taobaoNotice.getTaskId());
        if (dpaId != null && !dpaId.equals("")){
            paramMap.put("dpaId",dpaId);
            paramMap.put("dpaType",dpaType);
        }
        String response = HttpUtils.httpPostParamRequest(url,paramMap,null);
        logger.info(response);
//        taobaoNotice.setResponse(response);
//        this.save(taobaoNotice);
    }
}
