Browse Source

头条批量拉去代码

jiequan.bi 4 years ago
parent
commit
f1b0515155

+ 1 - 1
module-common/src/main/java/cn/com/ctop/common/module/constant/CtopRoleCodeConstant.java

@@ -1,5 +1,5 @@
 package cn.com.ctop.common.module.constant;
 
-public class CtopRoleCodeConstant {
+public class  CtopRoleCodeConstant {
     public static final String COMMON_ROLE_CODE_ADMIN = "admin";
 }

+ 1 - 0
module-common/src/main/java/cn/com/ctop/common/module/mapper/UserAllocationMapper.java

@@ -14,4 +14,5 @@ import java.util.List;
  */
 public interface UserAllocationMapper extends BaseMapper<UserAllocation> {
     List<UserAllocation> selectAccountListByProjectId(@Param("projectId")Long projectId);
+    String queryAdvertiserId(@Param("accountId")Long accountId);
 }

+ 8 - 0
module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/UserAllocationMapper.xml

@@ -13,4 +13,12 @@
         left join ctop_project b on a.project_id = b.id
         where b.id = #{projectId}
     </select>
+
+    <select id="queryAdvertiserId" resultType="String">
+        select
+            distinct advertiser_id
+        from
+            ctop_user_allocation
+        where account_id=#{accountId}
+    </select>
 </mapper>

+ 2 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/IUserAllocationService.java

@@ -24,4 +24,6 @@ public interface IUserAllocationService extends IService<UserAllocation> {
     Map<String, Object> getPangolinProjectListByParams(String userId);
 
     List<UserAllocation> getByMediaId(String mediaId);
+
+    String getAdvertiserIdByAccountId(Long accountId);
 }

+ 10 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/impl/UserAllocationServiceImpl.java

@@ -9,6 +9,7 @@ import cn.com.ctop.common.module.utils.StatusCode;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.HashMap;
@@ -23,6 +24,10 @@ import java.util.Map;
  */
 @Service
 public class UserAllocationServiceImpl extends ServiceImpl<UserAllocationMapper, UserAllocation> implements IUserAllocationService {
+
+    @Autowired
+    UserAllocationMapper userAllocationMapper;
+
     @Override
     public UserAllocation getByAccountId(Long accountId) {
         QueryWrapper<UserAllocation> queryWrapper = new QueryWrapper<>();
@@ -88,4 +93,9 @@ public class UserAllocationServiceImpl extends ServiceImpl<UserAllocationMapper,
         queryWrapper.orderByDesc("id");
         return this.list(queryWrapper);
     }
+
+    @Override
+    public String getAdvertiserIdByAccountId(Long accountId) {
+        return userAllocationMapper.queryAdvertiserId(accountId);
+    }
 }

+ 0 - 2
module-common/src/main/java/cn/com/ctop/common/module/utils/HttpUtils.java

@@ -201,8 +201,6 @@ public class HttpUtils {
                 httppost.setEntity(formEntity);
             }
 
-
-
             HttpEntity respentity;
 
             HttpResponse response = httpClient.execute(httppost);

+ 14 - 20
module-common/src/main/java/cn/com/ctop/common/module/utils/HttpUtils2.java

@@ -35,6 +35,7 @@ import java.net.URL;
 import java.net.URLConnection;
 import java.net.URLEncoder;
 import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 import java.security.cert.CertificateException;
 import java.security.cert.X509Certificate;
 import java.util.*;
@@ -132,9 +133,8 @@ public class HttpUtils2 {
             httpGet.setHeader("User-Agent", USER_AGENT);
             response = httpClient.execute(httpGet);
             HttpEntity entity = response.getEntity();
-            InputStream in = entity.getContent();
-            File file = new File(filePath);
-            try {
+            try (InputStream in = entity.getContent()) {
+                File file = new File(filePath);
                 FileOutputStream fout = new FileOutputStream(file);
                 int l = -1;
                 byte[] tmp = new byte[1024];
@@ -143,13 +143,10 @@ public class HttpUtils2 {
                 }
                 fout.flush();
                 fout.close();
-            } catch (Exception e){
+            } catch (Exception e) {
                 e.printStackTrace();
             }
-            finally{
-                // 关闭低层流。
-                in.close();
-            }
+            // 关闭低层流。
         } catch (Exception e) {
             e.printStackTrace();
         }
@@ -168,7 +165,7 @@ public class HttpUtils2 {
                 }
             }
 
-            httppost.setEntity(new StringEntity(new Gson().toJson(param), Charset.forName("UTF-8")));
+            httppost.setEntity(new StringEntity(new Gson().toJson(param), StandardCharsets.UTF_8));
             HttpEntity respentity;
 
             HttpResponse response = httpClient.execute(httppost);
@@ -199,7 +196,7 @@ public class HttpUtils2 {
             for (String key : headers.keySet()) {
                 httppost.setHeader(key, headers.get(key));
             }
-            httppost.setEntity(new StringEntity(body, Charset.forName("UTF-8")));
+            httppost.setEntity(new StringEntity(body, StandardCharsets.UTF_8));
             HttpEntity respentity;
 
             HttpResponse response = httpClient.execute(httppost);
@@ -232,7 +229,7 @@ public class HttpUtils2 {
             }
             httppost.setHeader("User-Agent", USER_AGENT);
             if (!Check.isNull(body)) {
-                httppost.setEntity(new StringEntity(body, Charset.forName("UTF-8")));
+                httppost.setEntity(new StringEntity(body, StandardCharsets.UTF_8));
             }
             HttpEntity respentity;
             HttpResponse response = httpClient.execute(httppost);
@@ -251,7 +248,6 @@ public class HttpUtils2 {
 
 
     public static String httpPostRequest(String url, JSONObject params, Map<String, String> headers) {
-//        HttpClient httpclient = HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build();
         HttpClient httpClient = createSSLClientDefault();
         String strReturn = "";
         try {
@@ -264,7 +260,7 @@ public class HttpUtils2 {
                 }
             }
             if (params != null) {
-                httppost.setEntity(new StringEntity(params.toJSONString(), Charset.forName("UTF-8")));
+                httppost.setEntity(new StringEntity(params.toJSONString(), StandardCharsets.UTF_8));
             }
 
             HttpEntity respentity;
@@ -296,8 +292,7 @@ public class HttpUtils2 {
             response = httpClient.execute(httpGet);
             int statusCode = response.getStatusLine().getStatusCode();
             if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
-                String newUrl = response.getFirstHeader("Location").getValue();
-                return newUrl;
+                return response.getFirstHeader("Location").getValue();
             }
 
         }catch (Exception e){
@@ -341,7 +336,7 @@ public class HttpUtils2 {
 
             HttpPost httppost = new HttpPost(url);
             httppost.addHeader("Content-Type", "application/json");
-            httppost.setEntity(new StringEntity(strParams, Charset.forName("UTF-8")));
+            httppost.setEntity(new StringEntity(strParams, StandardCharsets.UTF_8));
             HttpEntity respentity;
             HttpResponse response = httpClient.execute(httppost);
             int code = response.getStatusLine().getStatusCode();
@@ -389,8 +384,7 @@ public class HttpUtils2 {
     public static HttpClient getHttpclient() {
         RequestConfig defaultRequestConfig = RequestConfig.custom().setSocketTimeout(180000).setConnectTimeout(30000)
                 .setConnectionRequestTimeout(30000).setStaleConnectionCheckEnabled(true).build();
-        CloseableHttpClient httpclient = HttpClients.custom().setDefaultRequestConfig(defaultRequestConfig).build();
-        return httpclient;
+        return HttpClients.custom().setDefaultRequestConfig(defaultRequestConfig).build();
     }
 
     public static String callingGraph(String url, String json) {
@@ -529,7 +523,7 @@ public class HttpUtils2 {
                     }
                 }
             }
-            httpGet.setEntity(new StringEntity(params.toJSONString(), Charset.forName("UTF-8")));
+            httpGet.setEntity(new StringEntity(params.toJSONString(), StandardCharsets.UTF_8));
             HttpEntity respentity;
             HttpResponse response = httpClient.execute(httpGet);
             respentity = response.getEntity();
@@ -600,7 +594,7 @@ public class HttpUtils2 {
                 }
             }
 
-            httppost.setEntity(new StringEntity(new Gson().toJson(param), Charset.forName("UTF-8")));
+            httppost.setEntity(new StringEntity(new Gson().toJson(param), StandardCharsets.UTF_8));
             HttpEntity respentity;
 
             HttpResponse response = httpClient.execute(httppost);

+ 0 - 13
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/batch/service/IBytedanceGroupApiService.java

@@ -1,13 +0,0 @@
-package cn.com.ctop.toutiao.modules.batch.service;
-
-import cn.com.ctop.common.module.entity.CtopOauthToken;
-import cn.com.ctop.toutiao.modules.material.entity.ByteDanceCampaign;
-import com.alibaba.fastjson.JSONArray;
-
-import java.util.List;
-import java.util.Map;
-
-public interface IBytedanceGroupApiService {
-    List<ByteDanceCampaign> getGroupListByParams(CtopOauthToken token, JSONArray ids, String campaignName, String landingType, String status, String campaignCreateTime, int page, int pageSize);
-    Map<String,Object>createGroup(CtopOauthToken token,String campaignName,String operation,String budgetMode,String budget,String landingType,String uniqueFk);
-}

+ 0 - 117
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/batch/service/impl/BytedanceGroupApiServiceImpl.java

@@ -1,117 +0,0 @@
-package cn.com.ctop.toutiao.modules.batch.service.impl;
-
-import cn.com.ctop.common.module.entity.CtopOauthToken;
-import cn.com.ctop.common.module.utils.HttpUtils;
-import cn.com.ctop.common.module.utils.PropertiesUtils;
-import cn.com.ctop.common.module.utils.ResultMapUtils;
-import cn.com.ctop.common.module.utils.StatusCode;
-import cn.com.ctop.toutiao.modules.batch.service.IBytedanceGroupApiService;
-import cn.com.ctop.toutiao.modules.material.entity.ByteDanceCampaign;
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.stereotype.Service;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-@Service
-@Slf4j
-public class BytedanceGroupApiServiceImpl implements IBytedanceGroupApiService {
-
-    @Override
-    /**
-     * 获取广告组数据
-     */
-    public List<ByteDanceCampaign> getGroupListByParams(CtopOauthToken token, JSONArray ids, String campaignName, String landingType, String status, String campaignCreateTime, Integer page, Integer pageSize) {
-        List<ByteDanceCampaign> campaigns = new ArrayList<>();
-        // 请求地址
-        String url = PropertiesUtils.getValue("bytedance_config", "bytedance_api_url") + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_campaign_get");
-        // 请求参数
-        JSONObject filtering = new JSONObject();
-        if(null!=ids&&!ids.isEmpty()){
-            filtering.put("ids",ids);
-        }
-        if(null!=campaignName&&!campaignName.equals("")){
-            filtering.put("campaign_name",campaignName);
-        }
-        if(null!=landingType&&!landingType.equals("")){
-            filtering.put("landing_type",landingType);
-        }
-        if(null!=status&&!status.equals("")){
-            filtering.put("status",status);
-        }
-        if(null!=campaignCreateTime&&!campaignCreateTime.equals("")){
-            filtering.put("campaign_create_time",landingType);
-        }
-
-        JSONObject params = new JSONObject();
-        params.put("advertiser_id", token.getAccountId());
-        params.put("page", page);
-        params.put("page_size", pageSize);
-        params.put("filtering", filtering);
-        JSONObject result = HttpUtils.bytedanceGetRequest(token.getAccessToken(),url,params);
-        if(result == null){
-            log.error("获取广告组数据异常=>param:{}",params.toJSONString());
-            return campaigns;
-        }
-        Integer code = result.getInteger("code");
-        String message = result.getString("message");
-        if(null == code||!code.equals(0)){
-            log.error("获取广告组数据异常=>{},param:{}",message,params.toJSONString());
-            return campaigns;
-        }
-        JSONArray dataList = result.getJSONObject("data").getJSONArray("list");
-        if(null == dataList||dataList.isEmpty()){
-            log.info("获取广告组数据为空=>param:{}",params.toJSONString());
-            return campaigns;
-        }
-        for(int i=0;i<dataList.size();i++){
-            JSONObject data = dataList.getJSONObject(i);
-            ByteDanceCampaign campaign = new ByteDanceCampaign(data,token.getAccountId().toString());
-            campaigns.add(campaign);
-        }
-        return campaigns;
-    }
-
-    @Override
-    public Map<String, Object> createGroup(CtopOauthToken token, String campaignName, String operation, String budgetMode, String budget, String landingType, String uniqueFk) {
-        Map<String,Object>result = new HashMap<>();
-        // 请求地址
-        String url = PropertiesUtils.getValue("bytedance_config", "bytedance_api_url") + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_campaign_create");
-        // 请求参数
-        JSONObject param = new JSONObject();
-        param.put("advertiser_id",token.getAccountId());
-        param.put("campaign_name",campaignName);
-        if(null!=operation&&!operation.trim().equals("")){
-            param.put("operation",operation);
-        }
-        param.put("budget_mode", budgetMode);
-        if(null != budget&&!budget.trim().equals("")){
-            param.put("budget",budget);
-        }
-        param.put("landing_type", landingType);
-        if(null != uniqueFk&&!uniqueFk.trim().equals("")){
-            param.put("unique_fk",uniqueFk);
-        }
-        JSONObject data = HttpUtils.bytedancePostRequest(url,token.getAccessToken(),param);
-        if(data == null){
-            log.error("创建广告组异常=>param:{}",param.toJSONString());
-            ResultMapUtils.setResultMap(result, StatusCode.BYTEDACNE_API_GROUP_CREATE_ERROR);
-            return result;
-        }
-        Integer code = data.getInteger("code");
-        String message = data.getString("message");
-        if(null == code||!code.equals(0)){
-            log.error("获取广告组数据异常=>{},parmas:{}",message,param.toJSONString());
-            ResultMapUtils.setResultMap(result,-1,message,false);
-            return result;
-        }
-        Long campaignId = data.getJSONObject("data").getLong("campaign_id");
-        ResultMapUtils.setResultMap(result,StatusCode.COMMON_SUCCESS);
-        result.put("campaign_id",campaignId);
-        return result;
-    }
-}

+ 363 - 13
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/service/impl/ByteDanceAdvertisePlanServiceImpl.java

@@ -1,35 +1,385 @@
 package cn.com.ctop.toutiao.modules.material.service.impl;
 
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.utils.HttpUtils;
+import cn.com.ctop.common.module.utils.PropertiesUtils;
+import cn.com.ctop.common.module.utils.StringUtils;
 import cn.com.ctop.toutiao.modules.material.entity.ByteDanceAdvertisePlan;
 import cn.com.ctop.toutiao.modules.material.mapper.ByteDanceAdvertisePlanMapper;
 import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertisePlanService;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
-/**
- * @Description: 今日头条广告计划信息
- * @Author: jeecg-boot
- * @Date: 2019-07-22
- * @Version: V1.0
- */
 @Slf4j
 @Service
 public class ByteDanceAdvertisePlanServiceImpl extends ServiceImpl<ByteDanceAdvertisePlanMapper, ByteDanceAdvertisePlan> implements IByteDanceAdvertisePlanService {
+
     @Autowired
     private ByteDanceAdvertisePlanMapper byteDanceAdvertisePlanMapper;
 
-    /**
-     * 查询需要预警的广告计划名称
-     *
-     * @param accountId
-     * @param maxBid
-     * @return
-     */
+    @Override
+    public Map<String, Object> getAdvertiserPlan(CtopOauthToken token, String ids, String date, String updateDate) {
+        getAd(token, 1, ids, date, updateDate);
+        Map<String, Object> resultMap = new HashMap<>();
+        resultMap.put("code", 0);
+        resultMap.put("message", "获取广告计划信息成功");
+        return resultMap;
+    }
+
+    @Override
+    public Map<String, Object> createAdvertiserPlan(CtopOauthToken token,String landingType, ByteDanceAdvertisePlan byteDanceAdvertisePlan) {
+
+        Map<String, Object> resultMap = new HashMap<>();
+        //拼接访问参数
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Content-Type", "application/json");
+        headers.put("Access-Token", token.getAccessToken());
+
+        JSONObject params = new JSONObject();
+        params.put("advertiser_id",byteDanceAdvertisePlan.getAccountId());
+        params.put("campaign_id",byteDanceAdvertisePlan.getCampaignId());
+        params.put("name",byteDanceAdvertisePlan.getName());
+        params.put("operation",byteDanceAdvertisePlan.getOperation()==null?"enable":byteDanceAdvertisePlan.getOperation());
+        params.put("delivery_range",byteDanceAdvertisePlan.getDeliveryRange()==null?"DEFAULT":byteDanceAdvertisePlan.getDeliveryRange());
+        params.put("union_video_type",byteDanceAdvertisePlan.getUnionVideoType()==null?"ORIGINAL_VIDEO":byteDanceAdvertisePlan.getUnionVideoType());
+        params.put("budget_mode",byteDanceAdvertisePlan.getBudgetMode());
+        params.put("budget",byteDanceAdvertisePlan.getBudget());
+        params.put("schedule_type",byteDanceAdvertisePlan.getScheduleType());
+        params.put("start_time",byteDanceAdvertisePlan.getStartTime());
+        params.put("end_time",byteDanceAdvertisePlan.getEndTime());
+        //广告投放时段
+        //params.put("schedule_time",byteDanceAdvertisePlan.getString("scheduleTime"));
+        params.put("pricing",byteDanceAdvertisePlan.getPricing());
+        params.put("bid",byteDanceAdvertisePlan.getBid()==null?0:byteDanceAdvertisePlan.getBid());
+        params.put("cpa_bid",byteDanceAdvertisePlan.getCpaBid()==null?0.1:byteDanceAdvertisePlan.getCpaBid());
+        params.put("flow_control_mode",byteDanceAdvertisePlan.getFlowControlMode());
+        if(byteDanceAdvertisePlan.getPricing().equals("OCPM")){
+            params.put("convert_id",byteDanceAdvertisePlan.getConvertId());
+        }
+        params.put("deep_bid_type",byteDanceAdvertisePlan.getDeepBidType());
+        params.put("deep_cpabid",byteDanceAdvertisePlan.getDeepCpaBid());
+        params.put("hide_if_converted",byteDanceAdvertisePlan.getHideIfConverted());
+        params.put("hide_if_exists",byteDanceAdvertisePlan.getHideIfExists() == null ? 0 : byteDanceAdvertisePlan.getHideIfExists());
+        params.put("converted_time_duration",byteDanceAdvertisePlan.getConvertedTimeDuration());
+        //params.put("luban_roi_goal",byteDanceAdvertisePlan.getLubanRoiGoal()==null?0.00:byteDanceAdvertisePlan.getFloat("lubanRoiGoal"));
+        //params.put("roi_goal",byteDanceAdvertisePlan.getFroiGoal")==null?0.00:byteDanceAdvertisePlan.getFloat("roiGoal"));
+        //params.put("unique_fk",byteDanceAdvertisePlan.getUniqueFk")==null?"":byteDanceAdvertisePlan.getString("uniqueFk"));
+        //params.put("smart_bid_type",byteDanceAdvertisePlan.getSmartBidType")==null?"":byteDanceAdvertisePlan.getString("smartBidType"));
+        params.put("adjust_cpa",0);
+        //params.put("audience_package_id",byteDanceAdvertisePlan.getLong("audiencePackageId"));
+        params.put("open_url",byteDanceAdvertisePlan.getOpenUrl());
+        //判断推广目的
+        if(landingType.equals("Link")){
+            params.put("external_url",byteDanceAdvertisePlan.getExternalUrl());
+        }
+        if(landingType.equals("APP")){
+            params.put("download_type",byteDanceAdvertisePlan.getExternalUrl());
+
+        }
+        JSONObject jsonObject = JSONObject.parseObject( HttpUtils.httpPostRequest(PropertiesUtils.getValue("bytedance_config", "bytedance_api_url") + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_ad_create"), params, headers));
+        if (jsonObject.getInteger("code") != 0) {
+            log.error("广告计划创建失败==》accountId:{},message:{}", token.getAccountId(), jsonObject.getString("message"));
+            resultMap.put("code", -1);
+            resultMap.put("message", jsonObject.getString("message"));
+            return resultMap;
+        }
+        resultMap.put("code", 0);
+        resultMap.put("message", "广告组状态修改成功");
+        return resultMap;
+    }
+
+    @Override
+    public Map<String, Object> updateAdvertiserPlan(CtopOauthToken token,String landingType, ByteDanceAdvertisePlan byteDanceAdvertisePlan) {
+
+        Map<String, Object> resultMap = new HashMap<>();
+
+        //拼接访问参数
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Content-Type", "application/json");
+        headers.put("Access-Token", token.getAccessToken());
+
+        JSONObject params = new JSONObject();
+        params.put("advertiser_id",byteDanceAdvertisePlan.getAccountId());
+        params.put("ad_id",byteDanceAdvertisePlan.getId());
+        params.put("name",byteDanceAdvertisePlan.getName());
+        params.put("modify_time",byteDanceAdvertisePlan.getModifyTime());
+        params.put("budget",byteDanceAdvertisePlan.getBudget());
+        params.put("schedule_type",byteDanceAdvertisePlan.getScheduleType());
+        params.put("start_time",byteDanceAdvertisePlan.getStartTime());
+        params.put("end_time",byteDanceAdvertisePlan.getEndTime());
+        //广告投放时段
+        //params.put("schedule_time",byteDanceAdvertisePlan.getString("scheduleTime"));
+        params.put("bid",byteDanceAdvertisePlan.getBid()==null?0:byteDanceAdvertisePlan.getBid());
+        params.put("cpa_bid",byteDanceAdvertisePlan.getCpaBid()==null?0.1:byteDanceAdvertisePlan.getCpaBid());
+        params.put("flow_control_mode",byteDanceAdvertisePlan.getFlowControlMode());
+        if(byteDanceAdvertisePlan.getPricing().equals("OCPM")){
+            params.put("convert_id",byteDanceAdvertisePlan.getConvertId());
+        }
+        params.put("deep_bid_type",byteDanceAdvertisePlan.getDeepBidType());
+        params.put("deep_cpabid",byteDanceAdvertisePlan.getDeepCpaBid());
+        params.put("hide_if_converted",byteDanceAdvertisePlan.getHideIfConverted());
+        params.put("hide_if_exists",byteDanceAdvertisePlan.getHideIfExists() == null ? 0 : byteDanceAdvertisePlan.getHideIfExists());
+        params.put("converted_time_duration",byteDanceAdvertisePlan.getConvertedTimeDuration());
+        //params.put("luban_roi_goal",byteDanceAdvertisePlan.getLubanRoiGoal()==null?0.00:byteDanceAdvertisePlan.getFloat("lubanRoiGoal"));
+        //params.put("roi_goal",byteDanceAdvertisePlan.getFroiGoal")==null?0.00:byteDanceAdvertisePlan.getFloat("roiGoal"));
+        //params.put("audience_package_id",byteDanceAdvertisePlan.getLong("audiencePackageId"));
+        params.put("open_url",byteDanceAdvertisePlan.getOpenUrl());
+        //判断推广目的
+        if(landingType.equals("Link")){
+            params.put("external_url",byteDanceAdvertisePlan.getExternalUrl());
+        }
+        if(landingType.equals("APP")){
+            params.put("download_type",byteDanceAdvertisePlan.getExternalUrl());
+
+        }
+        JSONObject jsonObject = JSONObject.parseObject( HttpUtils.httpPostRequest(PropertiesUtils.getValue("bytedance_config", "bytedance_api_url") + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_ad_update"), params, headers));
+        if (jsonObject.getInteger("code") != 0) {
+            log.error("广告计划创建失败==》accountId:{},message:{}", token.getAccountId(), jsonObject.getString("message"));
+            resultMap.put("code", -1);
+            resultMap.put("message", jsonObject.getString("message"));
+            return resultMap;
+        }
+        resultMap.put("code", 0);
+        resultMap.put("message", "广告组状态修改成功");
+        return resultMap;
+    }
+
+    @Override
+    public Map<String, Object> updateAdvertiserPlanStatus(CtopOauthToken token, String adIds, String optStatus) {
+        JSONArray ids = new JSONArray();
+        String[] getIds = adIds.split(StringUtils.COMMA);
+        if (getIds.length > 0) {
+            for (String getId : getIds) {
+                ids.add(Long.parseLong(getId));
+            }
+        }
+        //2: 根据token以及用户id获取用户信息数据
+        String url = PropertiesUtils.getValue("bytedance_config", "bytedance_api_url") + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_ad_update_status");
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Content-Type", "application/json");
+        headers.put("Access-Token", token.getAccessToken());
+
+        JSONObject params = new JSONObject();
+        params.put("advertiser_id", token.getAccountId());
+        params.put("ad_ids", ids.toJSONString());
+        params.put("opt_status", optStatus);
+        String result = HttpUtils.httpPostRequest(url, params, headers);
+        JSONObject jsonObject = JSONObject.parseObject(result);
+        int code = jsonObject.getInteger("code");
+        Map<String, Object> resultMap = new HashMap<>();
+        if (code != 0) {
+            log.error("广告计划更新状态接口异常==》accountId:{},message:{}", token.getAccountId(), jsonObject.getString("message"));
+            resultMap.put("code", -1);
+            resultMap.put("message", "广告计划更新状态接口异常");
+            return resultMap;
+        }
+        JSONObject data = jsonObject.getJSONObject("data");
+        if (null == data) {
+            log.info("广告计划更新状态异常==》accountId:{},message:{}", token.getAccountId(), jsonObject.getString("message"));
+            resultMap.put("code", -1);
+            resultMap.put("message", jsonObject.getString("message"));
+            return resultMap;
+        }
+        JSONArray getAdIds = data.getJSONArray("ad_ids");
+        if (null != getAdIds && !getAdIds.isEmpty()) {
+            //获取广告计划信息
+            getAdvertiserPlan(token, adIds, null, null);
+        }
+        resultMap.put("code", 0);
+        resultMap.put("message", "广告组状态修改成功");
+        return resultMap;
+    }
+
+    public Map<String, Object> updateAdvertiserPlanBudget(CtopOauthToken token, String adIds, String budgets) {
+        JSONArray data = new JSONArray();
+        String[] getadIds = adIds.split(StringUtils.COMMA);
+        String[] getBudgets = budgets.split(StringUtils.COMMA);
+        if (getadIds.length > 0) {
+            for (int i = 0; i < getadIds.length; i++) {
+                JSONObject object = new JSONObject();
+                Long adId = Long.parseLong(getadIds[i]);
+                Long budget = Long.parseLong(getBudgets[i]);
+                object.put("ad_id", adId);
+                object.put("budget", budget);
+                data.add(object);
+            }
+        }
+        //2: 根据token以及用户id获取用户信息数据
+        String url = PropertiesUtils.getValue("bytedance_config", "bytedance_api_url") + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_ad_update_budget");
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Content-Type", "application/json");
+        headers.put("Access-Token", token.getAccessToken());
+
+        JSONObject params = new JSONObject();
+        params.put("advertiser_id", token.getAccountId());
+        params.put("data", data.toJSONString());
+        String result = HttpUtils.httpPostRequest(url, params, headers);
+        JSONObject jsonObject = JSONObject.parseObject(result);
+        Map<String, Object> resultMap = new HashMap<>();
+        Integer code = jsonObject.getInteger("code");
+        if (null == code || !code.equals(0)) {
+            log.info("修改计划预算接口异常==》accountId:{},message:{}", token.getAccountId(), jsonObject.getString("message"));
+            resultMap.put("code", -1);
+            resultMap.put("message", jsonObject.getString("message"));
+            return resultMap;
+        }
+        JSONObject getData = jsonObject.getJSONObject("data");
+        if (null == getData) {
+            log.info("修改计划预算异常==》accountId:{},message:{}", token.getAccountId(), jsonObject.getString("message"));
+            resultMap.put("code", -1);
+            resultMap.put("message", jsonObject.getString("message"));
+            return resultMap;
+        }
+        JSONArray getAdIds = getData.getJSONArray("ad_ids");
+        if (null != getAdIds && !getAdIds.isEmpty()) {
+            //获取广告计划信息
+            getAdvertiserPlan(token, adIds, null, null);
+        }
+        resultMap.put("code", 0);
+        resultMap.put("message", "修改计划预算成功");
+        return resultMap;
+    }
+
+    @Override
+    public Map<String, Object> updateAdvertiserPlanBid(CtopOauthToken token, String adIds, String bids) {
+        String[] getadIds = adIds.split(StringUtils.COMMA);
+        String[] getBids = bids.split(StringUtils.COMMA);
+        JSONArray data = new JSONArray();
+        if (getadIds.length > 0) {
+            for (int i = 0; i < getadIds.length; i++) {
+                JSONObject object = new JSONObject();
+                Long adId = Long.parseLong(getadIds[i]);
+                Long bid = Long.parseLong(getBids[i]);
+                object.put("ad_id", adId);
+                object.put("bid", bid);
+                data.add(object);
+            }
+        }
+        //2: 根据token以及用户id获取用户信息数据
+        String url = PropertiesUtils.getValue("bytedance_config", "bytedance_api_url") + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_ad_update_bid");
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Content-Type", "application/json");
+        headers.put("Access-Token", token.getAccessToken());
+
+        JSONObject params = new JSONObject();
+        params.put("advertiser_id", token.getAccountId());
+        params.put("data", data.toJSONString());
+        String result = HttpUtils.httpPostRequest(url, params, headers);
+        JSONObject jsonObject = JSONObject.parseObject(result);
+        int code = jsonObject.getInteger("code");
+        Map<String, Object> resultMap = new HashMap<>();
+        if (code != 0) {
+            log.info("修改计划出价接口异常==》accountId:{},message:{}", token.getAccountId(), jsonObject.getString("message"));
+            resultMap.put("code", -1);
+            resultMap.put("message", jsonObject.getString("message"));
+            return resultMap;
+        }
+        JSONObject getData = jsonObject.getJSONObject("data");
+        if (null == getData) {
+            log.info("修改计划出价异常==》accountId:{},message:{}", token.getAccountId(), jsonObject.getString("message"));
+            resultMap.put("code", -1);
+            resultMap.put("message", jsonObject.getString("message"));
+            return resultMap;
+        }
+        JSONArray getAdIds = getData.getJSONArray("ad_ids");
+        if (null != getAdIds && !getAdIds.isEmpty()) {
+            //获取广告计划信息
+            getAdvertiserPlan(token, adIds, null, null);
+        }
+        resultMap.put("code", 0);
+        resultMap.put("message", "修改计划出价成功");
+        return resultMap;
+    }
+
+    @Override
+    public Map<String, Object> getAdvertiserPlanRejectReason(CtopOauthToken token, Long advertiserId, List<Long> adIds) {
+
+        Map<String, Object> resultMap = new HashMap<>();
+
+        String url = PropertiesUtils.getValue("bytedance_config", "bytedance_api_url") + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_ad_update_reject_reason");
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Content-Type", "application/json");
+        headers.put("Access-Token", token.getAccessToken());
+
+        JSONObject params=new JSONObject();
+        params.put("advertiser_id",advertiserId);
+        params.put("ad_ids",adIds);
+        String result = HttpUtils.httpPostRequest(url, params, headers);
+        JSONObject jsonObject = JSONObject.parseObject(result);
+        int code = jsonObject.getInteger("code");
+        if(code!=0){
+            log.info("获取计划审核建议接口异常==》accountId:{},message:{}", token.getAccountId(), jsonObject.getString("message"));
+            resultMap.put("code", -1);
+            resultMap.put("message",jsonObject.getString("message"));
+            return resultMap;
+        }
+        resultMap.put("code", 0);
+        resultMap.put("message", "获取计划审核建议成功");
+        return resultMap;
+    }
+
+
+    public void getAd(CtopOauthToken token, int pageNum, String ids, String date, String updateDate) {
+        JSONArray getIds = new JSONArray();
+        if (null != ids && !"".equals(ids)) {
+            String[] idString = ids.split(StringUtils.COMMA);
+            if (idString.length > 0) {
+                for (String s : idString) {
+                    Long getId = Long.parseLong(s);
+                    getIds.add(getId);
+                }
+            }
+        }
+        // 请求地址
+        String url = PropertiesUtils.getValue("bytedance_config", "bytedance_api_url") + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_ad_get");
+        // 请求参数
+        Map<String, Object> filtering = new HashMap<>();
+        if (getIds.size() > 0) {
+            filtering.put("ids", getIds);
+        }
+        if (null != date && !"".equals(date)) {
+            filtering.put("ad_create_time", date);
+        }
+        if (null != updateDate && !"".equals(updateDate)) {
+            filtering.put("ad_modify_time", updateDate);
+        }
+
+        JSONObject param = new JSONObject();
+        param.put("advertiser_id", token.getAccountId());
+        param.put("page", pageNum);
+        param.put("page_size", 100);
+        param.put("filtering", filtering);
+        JSONObject resultObject = HttpUtils.bytedanceGetRequest(token.getAccessToken(), url, param);
+        int code = resultObject.getInteger("code");
+        if (code != 0) {
+            log.error("获取广告计划信息接口异常==》accountId:{},message:{}", token.getAccountId(), resultObject.getString("message"));
+            return;
+        }
+        JSONArray data = resultObject.getJSONObject("data").getJSONArray("list");
+        if (null == data || data.isEmpty()) {
+            return;
+        }
+        for (int i = 0; i < data.size(); i++) {
+            JSONObject dataObject = data.getJSONObject(i);
+            ByteDanceAdvertisePlan advertisePlan = new ByteDanceAdvertisePlan(dataObject, String.valueOf(token.getAccountId()));
+            BigDecimal deepCpaBid = dataObject.getBigDecimal("deep_cpabid");
+            if (null != deepCpaBid) {
+                advertisePlan.setDeepCpaBid(deepCpaBid);
+            }
+            this.saveOrUpdate(advertisePlan);
+        }
+        getAd(token, pageNum + 1, ids, date, updateDate);
+    }
+
     @Override
     public List<String> selectWarningGroup(Long accountId, BigDecimal maxBid) {
         return byteDanceAdvertisePlanMapper.selectWarningGroup(accountId, maxBid);

+ 11 - 13
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/service/impl/ByteDanceAdvertiserDataServiceImpl.java

@@ -53,7 +53,7 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
 
             }
 
-            Integer code = jsonObject.getInteger("code");
+            int code = jsonObject.getInteger("code");
             if (code == 0) {
                 JSONObject data = jsonObject.getJSONObject("data");
                 if (Check.isNull(data)) {
@@ -99,9 +99,9 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
         params.put("advertiser_ids", "[" + accountId + "]");
         String result = HttpUtils.httpGetRequest(url, headers, params);
         JSONObject jsonObject = JSONObject.parseObject(result);
-        Integer code = jsonObject.getInteger("code");
+        int code = jsonObject.getInteger("code");
 
-        if (null == code || !code.equals(0)) {
+        if (code!=0) {
             log.info("获取广告主信息接口异常==》accountId:{},message:{}", accountId, jsonObject.getString("message"));
             resultMap.put("success", false);
             resultMap.put("code", -1);
@@ -130,7 +130,7 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
         JSONArray getIds = null;
         if (null != ids && !"".equals(ids)) {
             String[] idString = ids.split(StringUtils.COMMA);
-            if (null != idString && idString.length > 0) {
+            if (idString.length > 0) {
                 for (int i = 0; i < idString.length; i++) {
                     Long getId = Long.parseLong(idString[i]);
                     getIds.add(getId);
@@ -440,8 +440,8 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
         JSONArray ids = new JSONArray();
         String[] getIds = adIds.split(StringUtils.COMMA);
         if (getIds.length > 0) {
-            for (int i = 0; i < getIds.length; i++) {
-                ids.add(Long.parseLong(getIds[i]));
+            for (String getId : getIds) {
+                ids.add(Long.parseLong(getId));
             }
         }
         //2: 根据token以及用户id获取用户信息数据
@@ -456,9 +456,8 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
         params.put("opt_status", optStatus);
         String result = HttpUtils.httpPostRequest(url, params, headers);
         JSONObject jsonObject = JSONObject.parseObject(result);
-        Integer code = jsonObject.getInteger("code");
-
-        if (null == code || !code.equals(0)) {
+        int code = jsonObject.getInteger("code");
+        if (code!=0) {
             log.error("广告计划更新状态接口异常==》accountId:{},message:{}", token.getAccountId(), jsonObject.getString("message"));
             resultMap.put("code", -1);
             resultMap.put("message", "广告计划更新状态接口异常");
@@ -484,9 +483,9 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
     @Override
     public Map<String, Object> advertiserPlanUpdateBid(CtopOauthToken token, String adIds, String bids) {
         Map<String, Object> resultMap = new HashMap<>();
-        JSONArray data = new JSONArray();
         String[] getadIds = adIds.split(StringUtils.COMMA);
         String[] getBids = bids.split(StringUtils.COMMA);
+        JSONArray data = new JSONArray();
         if (getadIds.length > 0) {
             for (int i = 0; i < getadIds.length; i++) {
                 JSONObject object = new JSONObject();
@@ -508,9 +507,8 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
         params.put("data", data.toJSONString());
         String result = HttpUtils.httpPostRequest(url, params, headers);
         JSONObject jsonObject = JSONObject.parseObject(result);
-        Integer code = jsonObject.getInteger("code");
-
-        if (null == code || !code.equals(0)) {
+        int code = jsonObject.getInteger("code");
+        if (code!=0) {
             log.info("修改计划出价接口异常==》accountId:{},message:{}", token.getAccountId(), jsonObject.getString("message"));
             resultMap.put("code", -1);
             resultMap.put("message", "修改计划出价接口异常");

+ 0 - 1
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/service/impl/BytedanceCleanMaterialServiceImpl.java

@@ -12,7 +12,6 @@ import org.springframework.stereotype.Service;
 import java.util.List;
 
 @Service
-@Primary
 public class BytedanceCleanMaterialServiceImpl implements IBytedanceCleanMaterialService {
     @Autowired
     private BytedanceCreativeDailyReportMapper bytedanceCreativeDailyReportMapper;