yumeng преди 1 година
родител
ревизия
02ffd438c6

+ 38 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/TestController.java

@@ -15,6 +15,7 @@ import cn.com.ctop.crawler.modules.core.service.CrawlerDouyinMusicTaskService;
 import cn.com.ctop.crawler.modules.douyin.service.DouyinMusicService;
 import cn.com.ctop.kuaishou.modules.batch.Enums.KuaishouHourEnum;
 import cn.com.ctop.kuaishou.modules.batch.Enums.KuaishouMinSecEnum;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouGroup;
 import cn.com.ctop.kuaishou.modules.batch.service.*;
 import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
 import cn.com.ctop.kuaishou.modules.report.service.IKuaiShouDailyAgentService;
@@ -42,6 +43,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.xxl.job.core.context.XxlJobHelper;
 import com.xxl.job.core.enums.NoEn;
 import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.util.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -155,6 +157,42 @@ public class TestController {
     @Autowired
     private IKuaiShouActivityItemListService activityItemListService;
 
+
+    @GetMapping(value = "/campaignList")
+    public void campaignList() {
+
+
+        CtopOauthToken oauthToken = new CtopOauthToken();
+        oauthToken.setAccountId(16226959L);
+        oauthToken.setAccessToken("959ffa0bc0939170e3d7f87854eae13e");
+        kuaishouInterfaceService.getGroupList(oauthToken, null, null);
+
+
+    }
+
+    @Autowired
+    private IKuaiShouUpdateService updateService;
+
+    @GetMapping(value = "/updateGropup")
+    public void updateGropup() {
+
+
+        CtopOauthToken oauthToken = new CtopOauthToken();
+        oauthToken.setAccountId(16226959L);
+        oauthToken.setAccessToken("959ffa0bc0939170e3d7f87854eae13e");
+
+        JSONObject unitJson = new JSONObject();
+        unitJson.put("advertiser_id", 16226959L);
+        unitJson.put("unit_id", 2763184086L);
+
+        JSONObject jsonObject = updateService.updateUnit(oauthToken.getAccessToken(), unitJson);
+
+    }
+
+
+
+
+
     @GetMapping(value = "/getData")
     public void getDate(String startDate, String endDate) throws Exception {
 

+ 53 - 52
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouUpdateServiceImpl.java

@@ -604,64 +604,65 @@ public class KuaiShouUpdateServiceImpl implements IKuaiShouUpdateService {
     public JSONObject updateUnit(String accessToken, JSONObject unitJson) {
         JSONObject returnJson = new JSONObject();
         try {
-            String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.UPDATE_UNIT;
+            String url = "https://ad.e.kuaishou.com/rest/openapi/gw/dsp/unit/update";
             Map<String, String> headers = new HashMap<>();
             headers.put("Access-Token", accessToken);
             headers.put("Content-Type", "application/json");
+            headers.put("K-RealUser-IP", "103.46.170.107");
             String result = HttpUtils.kuaiShouhttpPostRequest(url, unitJson.toJSONString(), headers);
             JSONObject resultJson = JSONObject.parseObject(result);
             log.info("修改广告组返回信息:{}", resultJson);
-            if (!Check.isNull(resultJson)) {
-                Integer code = resultJson.getInteger("code");
-                if (code == 0) {
-                    JSONObject data = resultJson.getJSONObject("data");
-                    if (!Check.isNull(data)) {
-                        //添加广告组和定向模板、人群包绑定关系
-                        Thread thread2 = new Thread() {
-                            @Override
-                            public void run() {
-                                try {
-                                    JSONObject request = new JSONObject();
-                                    request.put("accountId", unitJson.getLong("advertiser_id"));
-                                    request.put("unitId", data.getLong("unit_id"));
-                                    JSONObject target = unitJson.getJSONObject("target");
-                                    if (!Check.isNull(target)) {
-                                        request.put("excludePopulation", target.getJSONArray("exclude_population"));
-                                        request.put("population", target.getJSONArray("population"));
-                                        request.put("paidAudience", target.getJSONArray("paid_audience"));
-                                        populationGroupService.createPopulationAndGroupRel(request);
-                                    }
-                                    if (!Check.isNull(unitJson.getLong("template_id"))) {
-                                        request.put("templateId", unitJson.getLong("template_id"));
-                                        directionalPackageService.createUnitAndTemplate(request);
-                                    }
-                                    if (!Check.isNull(unitJson.getLong("app_id"))) {
-                                        request.put("appId", unitJson.getLong("app_id"));
-                                        appPackageService.createAppAndGroupRel(request);
-                                    }
-                                } catch (Exception e) {
-                                    log.error("添加广告组和定向模板、人群包绑定关系异常,", e);
-                                }
-                            }
-                        };
-                        thread2.start();
-                        try {
-                            Thread.sleep(500);
-                            groupService.getGroupByUnitId(accessToken, unitJson.getLong("advertiser_id"), data.getLong("unit_id"));
-                        } catch (InterruptedException e) {
-                            e.printStackTrace();
-                        }
-                        returnJson.put("code", 0);
-                    } else {
-                        returnJson.put("code", -1);
-                        returnJson.put("message", "返回信息为空");
-                    }
-
-                } else {
-                    returnJson.put("code", -1);
-                    returnJson.put("message", resultJson.getString("message"));
-                }
-            }
+//            if (!Check.isNull(resultJson)) {
+//                Integer code = resultJson.getInteger("code");
+//                if (code == 0) {
+//                    JSONObject data = resultJson.getJSONObject("data");
+//                    if (!Check.isNull(data)) {
+//                        //添加广告组和定向模板、人群包绑定关系
+//                        Thread thread2 = new Thread() {
+//                            @Override
+//                            public void run() {
+//                                try {
+//                                    JSONObject request = new JSONObject();
+//                                    request.put("accountId", unitJson.getLong("advertiser_id"));
+//                                    request.put("unitId", data.getLong("unit_id"));
+//                                    JSONObject target = unitJson.getJSONObject("target");
+//                                    if (!Check.isNull(target)) {
+//                                        request.put("excludePopulation", target.getJSONArray("exclude_population"));
+//                                        request.put("population", target.getJSONArray("population"));
+//                                        request.put("paidAudience", target.getJSONArray("paid_audience"));
+//                                        populationGroupService.createPopulationAndGroupRel(request);
+//                                    }
+//                                    if (!Check.isNull(unitJson.getLong("template_id"))) {
+//                                        request.put("templateId", unitJson.getLong("template_id"));
+//                                        directionalPackageService.createUnitAndTemplate(request);
+//                                    }
+//                                    if (!Check.isNull(unitJson.getLong("app_id"))) {
+//                                        request.put("appId", unitJson.getLong("app_id"));
+//                                        appPackageService.createAppAndGroupRel(request);
+//                                    }
+//                                } catch (Exception e) {
+//                                    log.error("添加广告组和定向模板、人群包绑定关系异常,", e);
+//                                }
+//                            }
+//                        };
+//                        thread2.start();
+//                        try {
+//                            Thread.sleep(500);
+//                            groupService.getGroupByUnitId(accessToken, unitJson.getLong("advertiser_id"), data.getLong("unit_id"));
+//                        } catch (InterruptedException e) {
+//                            e.printStackTrace();
+//                        }
+//                        returnJson.put("code", 0);
+//                    } else {
+//                        returnJson.put("code", -1);
+//                        returnJson.put("message", "返回信息为空");
+//                    }
+//
+//                } else {
+//                    returnJson.put("code", -1);
+//                    returnJson.put("message", resultJson.getString("message"));
+//                }
+//            }
         } catch (Exception e) {
             e.printStackTrace();
             returnJson.put("code", -1);

+ 35 - 31
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouInterfaceServiceImpl.java

@@ -39,17 +39,7 @@ import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouGroupMapper;
 import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouRegionListChildrenMapper;
 import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouRegionListParentMapper;
 import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouTargetingTagsMapper;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouCampaignService;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouCreativeService;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouDailyFlowsService;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouGroupService;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouHistoryReportTaskService;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouImageGetService;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouOverRunSendMessageService;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouVideoGetService;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouPopulationService;
-import cn.com.ctop.kuaishou.modules.batch.service.IWarningOperationService;
+import cn.com.ctop.kuaishou.modules.batch.service.*;
 import cn.com.ctop.kuaishou.modules.material.entity.KuaishouResult;
 import cn.com.ctop.kuaishou.modules.material.entity.KuaishouResultToken;
 import cn.com.ctop.kuaishou.modules.report.entity.KuaishouReportDailyAccount;
@@ -1265,9 +1255,9 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
     }
 
 
-  @Override
+    @Override
     public Map getKuaishouUnitList(CtopOauthToken token, Long unitId, Date startDate,
-                                  Date endDate, int time_filter_type,Integer pageNum, Integer pageSize) {
+                                   Date endDate, int time_filter_type, Integer pageNum, Integer pageSize) {
         String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.GROUP_LIST;
         JSONObject param = new JSONObject();
         param.put("advertiser_id", token.getAccountId());
@@ -1276,16 +1266,15 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
             param.put("end_date", DateUtils.formatDate(endDate));
         }
 
-        if (!Check.isNull(unitId)){
+        if (!Check.isNull(unitId)) {
             param.put("unit_id", unitId);
         }
-          param.put("page_size", pageSize);
-          param.put("page", pageNum);
-          param.put("time_filter_type", time_filter_type);
-
+        param.put("page_size", pageSize);
+        param.put("page", pageNum);
+        param.put("time_filter_type", time_filter_type);
 
 
-      Map<String, String> headers = new HashMap<>();
+        Map<String, String> headers = new HashMap<>();
         headers.put("Access-Token", token.getAccessToken());
         headers.put("Content-Type", "application/json");
 
@@ -1303,12 +1292,12 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
         Map resultMap = new HashMap();
         JSONArray details = resultJson.getJSONObject("data").getJSONArray("details");
         Integer totalCount = resultJson.getJSONObject("data").getInteger("total_count");
-      resultMap.put("details",details );
-      resultMap.put("totalCount",totalCount );
+        resultMap.put("details", details);
+        resultMap.put("totalCount", totalCount);
 
-      if (!Check.isNull(resultMap)){
-          return resultMap;
-      }
+        if (!Check.isNull(resultMap)) {
+            return resultMap;
+        }
 
 
         if (Check.isNull(details)) {
@@ -1328,6 +1317,9 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
     @Autowired
     IRuleKuaiShouPlanService ruleKuaiShouPlanService;
 
+    @Autowired
+    private IKuaiShouUpdateService updateService;
+
     private void getGroupListByPage(CtopOauthToken token, Date startDate, Date endDate, int page) {
         String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.GROUP_LIST;
         JSONObject param = new JSONObject();
@@ -1341,9 +1333,11 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
         Map<String, String> headers = new HashMap<>();
         headers.put("Access-Token", token.getAccessToken());
         headers.put("Content-Type", "application/json");
+        headers.put("K-RealUser-IP", "103.46.170.107");
 
         String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
         JSONObject resultJson = JSONObject.parseObject(result);
+        System.err.println(resultJson);
         if (Check.isNull(resultJson)) {
             log.error("获取广告组接口异常,advertiserId:{}", token.getAccountId());
             return;
@@ -1357,8 +1351,18 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
         if (Check.isNull(details)) {
             return;
         }
-        addGroup(token.getAccountId(), details);
-        //   ruleKuaiShouPlanService.insertTarget(token.getAccountId(), details);
+
+
+        for (int i = 0; i < details.size(); i++) {
+            JSONObject jsonObject = details.getJSONObject(i);
+            Long unit_id = jsonObject.getLong("unit_id");
+            JSONObject unitJson = new JSONObject();
+            unitJson.put("advertiser_id", token.getAccountId());
+            unitJson.put("unit_id", unit_id);
+            updateService.updateUnit(token.getAccessToken(), unitJson);
+
+        }
+
         getGroupListByPage(token, startDate, endDate, page + 1);
     }
 
@@ -1451,7 +1455,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                                 if (ocpxActionType == 2 && dayBudget != 0 && dayBudget <= 500 * 1000) {
                                     // 转化目标为2行为数,并且预算小于等于500且不是不限,则允许启动
                                     typeFalg = true;
-                                }else{
+                                } else {
                                     //通过key未获取值,说明不包含该目标,进行关停
                                     typeFalg = false;
                                 }
@@ -1461,7 +1465,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                                     bidFalg = false;
                                 }
                             }
-                        }else if (ocpxActionType == 2 && (dayBudget == 0 || dayBudget > 500 * 1000)) {
+                        } else if (ocpxActionType == 2 && (dayBudget == 0 || dayBudget > 500 * 1000)) {
                             // 转化目标为2行为数,并且预算大于500 或者不限,则关停
                             typeFalg = false;
                         }
@@ -2716,7 +2720,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                 kuaiShouImageGet.setId(token.getAccountId() + kuaiShouImageGet.getImageToken());
                 kuaiShouImageGet.setAccountId(token.getAccountId());
 
-                Map<String, Integer> typeBySize =  MaterialEnum.getTypeBySize(kuaiShouImageGet.getWidth(), kuaiShouImageGet.getHeight());
+                Map<String, Integer> typeBySize = MaterialEnum.getTypeBySize(kuaiShouImageGet.getWidth(), kuaiShouImageGet.getHeight());
                 if (!Check.isNullMap(typeBySize)) {
                     kuaiShouImageGet.setMaterialType(typeBySize.get("type"));
                 }
@@ -2904,7 +2908,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                     if (!Check.isNull(addList)) {
                         populationService.replaceBatch(addList);
                     }
-                  //  getPopulationList(accountId, accessToken, page + 1);
+                    //  getPopulationList(accountId, accessToken, page + 1);
                 } else {
                     log.error("获取人群包管理返回数据为空,accountId:{}", accountId);
 
@@ -3447,7 +3451,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                             appList.setAppIconUrl(dataJson.getString("app_icon_url"));
                             appList.setImageToken(dataJson.getString("image_token"));
                             appList.setPackageName(dataJson.getString("package_name"));
-                         //   appList.setReturnTime(DateUtils.timeStamp2Date(dataJson.getTimestamp("update_time")));
+                            //   appList.setReturnTime(DateUtils.timeStamp2Date(dataJson.getTimestamp("update_time")));
                             addList.add(appList);
                         }
                     }