Procházet zdrojové kódy

批量修改监测链接

yumeng před 4 roky
rodič
revize
8b147acc18

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

@@ -13,10 +13,9 @@ import cn.com.ctop.crawler.modules.douyin.service.DouyinMusicService;
 import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouAdvertiserStrategy;
 import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouAdvertiserStrategyService;
 import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouCreateCreativeService;
-import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouCampaign;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouCreative;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouGroup;
-import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouTemplate;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouProgramCreative;
 import cn.com.ctop.kuaishou.modules.batch.service.*;
 import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
 import cn.com.ctop.kuaishou.modules.material.entity.KuaishouAccessToken;
@@ -25,7 +24,6 @@ import cn.com.ctop.kuaishou.modules.report.entity.KuaiShouProjectData;
 import cn.com.ctop.kuaishou.modules.report.service.IKuaiShouDailyAgentService;
 import cn.com.ctop.kuaishou.modules.report.service.IKuaiShouProjectDataService;
 import cn.com.ctop.kuaishou.modules.report.service.IKuaishouAudienceReportDailyService;
-import cn.com.ctop.kuaishou.modules.report.service.IKuaishouReportHourlyGroupService;
 import cn.com.ctop.manage.modules.material.service.IMaterialUploadService;
 import cn.com.ctop.toutiao.modules.link.service.IETLReportBytedanceVideoService;
 import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertiserDataService;
@@ -35,7 +33,6 @@ import cn.com.ctop.toutiao.modules.report.service.*;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.xxl.job.core.context.XxlJobHelper;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.ibatis.annotations.Param;
@@ -53,7 +50,6 @@ import java.math.BigDecimal;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.*;
-import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
@@ -103,7 +99,7 @@ public class TestController {
     @Autowired
     private IKuaiShouHistoryReportTaskService kuaiShouHistoryReportTaskService;
 
-    static ExecutorService executorService = Executors.newFixedThreadPool(5);
+    static ExecutorService executorService = Executors.newFixedThreadPool(10);
     static ExecutorService suzhaoService = Executors.newFixedThreadPool(5);
     @Autowired
     private IKuaiShouDailyAgentService dailyAgentService;
@@ -137,13 +133,293 @@ public class TestController {
 
     @Autowired
     private IBatchService batchService;
-    static ExecutorService videoService = Executors.newFixedThreadPool(3);
+    static ExecutorService videoService = Executors.newFixedThreadPool(8);
     @Autowired
     private IMaterialUploadService materialUploadService;
+    @Autowired
+    private IKuaishouProgramCreativeService kuaishouProgramCreativeService;
 
     @Value("${xxl-job.requestUrl}")
     private String jobUrl;
 
+
+    @GetMapping(value = "/getProgramCreative")
+    public void getProgramCreative() {
+        List<Long> list = new ArrayList();
+
+        list.add(9549277L);
+        list.add(9635234L);
+        list.add(9767697L);
+        list.add(9767717L);
+        list.add(9549313L);
+        list.add(10173200L);
+        list.add(10173385L);
+        list.add(10173389L);
+        list.add(10298840L);
+        list.add(10298859L);
+        list.add(10298871L);
+        list.add(10173366L);
+        list.add(10173375L);
+        list.add(10298910L);
+        list.add(10299210L);
+        list.add(10299221L);
+        list.add(10299241L);
+
+
+        for (int i = 0; i < list.size(); i++) {
+            Long accountId = list.get(i);
+            CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
+            videoService.submit(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                        kuaishouProgramCreativeService.getProgramCreative(oauthToken.getAccountId(), null, oauthToken.getAccessToken(), null, null, 1);
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                }
+            });
+        }
+    }
+
+
+    @GetMapping(value = "/updateProgramCreative")
+    public void updateProgramCreative() {
+        List<Long> list = new ArrayList();
+        list.add(10173366L);
+        list.add(10173375L);
+        list.add(10298910L);
+        list.add(10299210L);
+        list.add(10299221L);
+        list.add(10299241L);
+
+        for (int i = 0; i < list.size(); i++) {
+            Long accountId = list.get(i);
+            CtopOauthToken token = oauthTokenService.getTokenByAccountId(accountId);
+            QueryWrapper<KuaishouProgramCreative> creativeQueryWrapper = new QueryWrapper<>();
+            creativeQueryWrapper.eq("account_id", accountId);
+            creativeQueryWrapper.lt("creative_create_time", "2021-07-11 00:00:00");
+            List<KuaishouProgramCreative> proList = kuaishouProgramCreativeService.list(creativeQueryWrapper);
+            if (Check.isNull(proList)) {
+                continue;
+            }
+            for (KuaishouProgramCreative programCreative : proList) {
+                Long unitId = programCreative.getUnitId();
+                if (Check.isNull(unitId)) {
+                    continue;
+                }
+                executorService.submit(new Runnable() {
+                    @Override
+                    public void run() {
+                        try {
+                            String updateUrl = "https://ad.e.kuaishou.com/rest/openapi/v2/creative/advanced/program/update";
+                            Map<String, String> headers = new HashMap<>();
+                            headers.put("Content-Type", "application/json");
+                            headers.put("Access-Token", token.getAccessToken());
+                            Map<String, Object> param = new HashMap<>();
+                            param.put("advertiser_id", token.getAccountId());
+                            param.put("unit_id", unitId);
+
+                            String replaceUrll = "https://uri6.com/tkio/Yj6773a?imei=__IMEI2__&androidid=__ANDROIDID2__&oaid=__OAID__&mac=__MAC__&ip=__IP__&ry_adcreative_id=__CID__&ry_adplan_id=__DID__&ry_adplan_name=__DNAME__&ry_adgroup_id=__AID__&callback=__CALLBACK__&csite=__CSITE__&accountid=__ACCOUNTID__&ua=__UA__&os=__OS__&noredirect=true";
+                            param.put("click_url", replaceUrll);
+                            String result = HttpUtils.httpPostRequest(updateUrl, param, headers);
+                            JSONObject resultJson = JSONObject.parseObject(result);
+                            Integer code = resultJson.getInteger("code");
+                            if (code == 0) {
+                                log.info("修改成功,accountId:{},unitId:{}", token.getAccountId(), unitId);
+
+                            } else {
+                                log.info("修改失败,accountId:{},unitId:{},原因:{}", token.getAccountId(), unitId, resultJson.getString("message"));
+                            }
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                        }
+                    }
+                });
+            }
+
+
+        }
+    }
+
+
+    @GetMapping(value = "/campaignList")
+    public void campaignList() {
+        List<Long> list = new ArrayList();
+        list.add(9549277L);
+        list.add(9635234L);
+        list.add(9767697L);
+        list.add(9767717L);
+        list.add(9549313L);
+
+
+        for (int i = 0; i < list.size(); i++) {
+            Long accountId = list.get(i);
+            CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
+            // kuaishouInterfaceService.getCampaignList(oauthToken, null, null);
+            videoService.submit(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                        //   kuaishouInterfaceService.getCampaignList(oauthToken, null, null);
+                        kuaishouInterfaceService.getGroupList(oauthToken, null, null);
+                        //     kuaishouInterfaceService.getCreativeList(oauthToken, null, null);
+                        Thread.sleep(1500);
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                }
+            });
+
+        }
+
+    }
+
+
+    @GetMapping(value = "/creativeList")
+    public void creativeList() {
+        List<Long> list = new ArrayList();
+        list.add(9549277L);
+        list.add(9635234L);
+        list.add(9767697L);
+        list.add(9767717L);
+        list.add(9549313L);
+        list.add(10173200L);
+        list.add(10173385L);
+        list.add(10173389L);
+        list.add(10298840L);
+        list.add(10298859L);
+        list.add(10298871L);
+        list.add(10173366L);
+        list.add(10173375L);
+        list.add(10298910L);
+        list.add(10299210L);
+        list.add(10299221L);
+        list.add(10299241L);
+
+        for (int i = 0; i < list.size(); i++) {
+            Long accountId = list.get(i);
+            CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
+
+
+            suzhaoService.submit(new Runnable() {
+                @Override
+                public void run() {
+                    kuaishouInterfaceService.getCreativeList(oauthToken, null, null);
+                }
+            });
+            try {
+                Thread.sleep(400L);
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
+
+        }
+
+    }
+
+
+    @GetMapping(value = "/updateUnit")
+    public void updateUnit() throws Exception {
+        List<Long> list = new ArrayList();
+        list.add(9556344L);
+        list.add(9743738L);
+
+
+        for (int i = 0; i < list.size(); i++) {
+            Long accountId = list.get(i);
+            CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
+            QueryWrapper<KuaiShouGroup> groupQueryWrapper = new QueryWrapper<>();
+            groupQueryWrapper.eq("account_id", accountId);
+            List<KuaiShouGroup> list1 = groupService.list(groupQueryWrapper);
+            for (KuaiShouGroup group : list1) {
+                executorService.submit(new Runnable() {
+                    @Override
+                    public void run() {
+                        try {
+                            JSONObject json = new JSONObject();
+                            json.put("unitId", group.getUnitId());
+                            json.put("cpaBid", 18 * 1000);
+                            //     json.put("gender", "2");
+                            batchService.updateUnit(json, oauthToken);
+                            Thread.sleep(1500);
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                        }
+                    }
+                });
+
+
+            }
+
+
+        }
+
+
+    }
+
+    @Autowired
+    private IKuaiShouUpdateService kuaiShouUpdateService;
+
+    @GetMapping(value = "/updateCreative")
+    public void updateCreative() {
+        List<Long> list = new ArrayList();
+        list.add(10173366L);
+        list.add(10173375L);
+        list.add(10298910L);
+        list.add(10299210L);
+        list.add(10299221L);
+        list.add(10299241L);
+
+        for (int i = 0; i < list.size(); i++) {
+            Long accountId = list.get(i);
+            CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
+            QueryWrapper<KuaiShouCreative> creativeQueryWrapper = new QueryWrapper<>();
+            creativeQueryWrapper.eq("account_id", accountId);
+            creativeQueryWrapper.eq("status", 52);
+            creativeQueryWrapper.lt("creative_create_time", "2021-07-11 00:00:00");
+            List<KuaiShouCreative> creativeList = creativeService.list(creativeQueryWrapper);
+            if (Check.isNull(creativeList)) {
+                continue;
+            }
+            for (KuaiShouCreative creative : creativeList) {
+                QueryWrapper<KuaiShouGroup> groupQueryWrapper = new QueryWrapper<>();
+                groupQueryWrapper.eq("unit_id", creative.getUnitId());
+                groupQueryWrapper.last("limit 1");
+                KuaiShouGroup one = groupService.getOne(groupQueryWrapper);
+                if (Check.isNull(one)) {
+                    continue;
+                }
+                executorService.submit(new Runnable() {
+                    @Override
+                    public void run() {
+                        try {
+                            JSONObject json = new JSONObject();
+                            json.put("creativeId", creative.getCreativeId());
+                            String url = "https://uri6.com/tkio/Yj6773a?imei=__IMEI2__&androidid=__ANDROIDID2__&oaid=__OAID__&mac=__MAC__&ip=__IP__&ry_adcreative_id=__CID__&ry_adplan_id=__DID__&ry_adplan_name=__DNAME__&ry_adgroup_id=__AID__&callback=__CALLBACK__&csite=__CSITE__&accountid=__ACCOUNTID__&ua=__UA__&os=__OS__&noredirect=true";
+
+                            if (creative.getCreativeMaterialType() == 1) {
+                                json.put("clickTrackUrl", url);
+                            } else if (creative.getCreativeMaterialType() == 4) {
+                                json.put("impressionUrl", url);
+                                json.put("clickTrackUrl", url);
+
+                            }
+                            JSONObject jsonObject = batchService.updateCreative(json, oauthToken);
+                            log.info("修改创意返回信息accountId:{},creative:{},结果:{}", creative.getAccountId(), creative.getCreativeId(), jsonObject);
+                            Thread.sleep(1000L);
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                        }
+                    }
+                });
+            }
+
+
+        }
+    }
+
+
     @GetMapping("/testSend")
     public void testSend(String userId) {
 
@@ -1262,29 +1538,29 @@ public class TestController {
     }
 
     @GetMapping("checkCostData")
-    public void checkCostData(String date){
-            //1:初始化
-            checkReportTaskInfoService.initTask(date);
-            //2: checkCost
-            List<BytedanceCheckReportTaskInfo>taskInfos = checkReportTaskInfoService.getListByParams(null,date,0);
-            if(null!=taskInfos&&!taskInfos.isEmpty()){
-                for (BytedanceCheckReportTaskInfo task:taskInfos) {
-                    checkReportTaskInfoService.checkCost(task);
-                }
-                log.info("{}:数据获取完成",date);
+    public void checkCostData(String date) {
+        //1:初始化
+        checkReportTaskInfoService.initTask(date);
+        //2: checkCost
+        List<BytedanceCheckReportTaskInfo> taskInfos = checkReportTaskInfoService.getListByParams(null, date, 0);
+        if (null != taskInfos && !taskInfos.isEmpty()) {
+            for (BytedanceCheckReportTaskInfo task : taskInfos) {
+                checkReportTaskInfoService.checkCost(task);
             }
+            log.info("{}:数据获取完成", date);
+        }
     }
 
     @GetMapping("refreshReportData")
-    public void refreshReportData()throws Exception{
+    public void refreshReportData() throws Exception {
         //1:查询异常任务数据
-        List<BytedanceCheckReportTaskInfo>taskInfos = checkReportTaskInfoService.getListByParams(null,null,50001);
-        if(null!=taskInfos&&!taskInfos.isEmpty()){
+        List<BytedanceCheckReportTaskInfo> taskInfos = checkReportTaskInfoService.getListByParams(null, null, 50001);
+        if (null != taskInfos && !taskInfos.isEmpty()) {
             taskInfos.forEach(taskInfo -> {
                 try {
                     checkReportTaskInfoService.reloadData(taskInfo);
                     checkReportTaskInfoService.checkCost(taskInfo);
-                }catch (Exception e) {
+                } catch (Exception e) {
                 }
             });
             log.info("数据更新完成");

+ 14 - 14
jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java

@@ -5,8 +5,8 @@ import cn.com.ctop.common.module.entity.CtopOauthToken;
 import cn.com.ctop.common.module.service.IBindAccountLoginService;
 import cn.com.ctop.common.module.service.ICtopOauthTokenService;
 import cn.com.ctop.common.module.utils.CtopAdConstant;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
 import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
-import cn.com.ctop.kuaishou.modules.report.entity.EtlKuaishouAccountMaterialReportDaily;
 import cn.com.ctop.kuaishou.modules.report.mapper.EtlKuaishouAccountMaterialReportDailyMapper;
 import cn.com.ctop.kuaishou.modules.report.service.IKuaishouReportDailyImageService;
 import cn.com.ctop.oa.modules.service.IWechatNoListService;
@@ -26,6 +26,7 @@ import org.springframework.test.context.junit4.SpringRunner;
 
 import javax.annotation.Resource;
 import java.text.ParseException;
+import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
@@ -76,19 +77,20 @@ public class SampleTest {
     private IBytedanceReportService bytedanceReportService;
     @Autowired
     private IETLReportBytedanceVideoService etlReportBytedanceVideoService;
+    @Autowired
+    private IKuaishouInterfaceService iKuaishouInterfaceService;
+
 
     @Test
     public void loadKuaishouCookie() throws ParseException {
-        CtopOauthToken tokenByAccountId = tokenService.getTokenByAccountId(1700996735138951L);
-        advertiserDataService.getMaterialList(tokenByAccountId);
-
-        CtopOauthToken tokenByAccountId1 = tokenService.getTokenByAccountId(1700996735589383L);
-        advertiserDataService.getMaterialList(tokenByAccountId1);
+        CtopOauthToken token = tokenService.getTokenByAccountId(10291211L);
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+        Date parse = simpleDateFormat.parse("2021-07-11");
+        Date pars1 = simpleDateFormat.parse("2021-07-12");
+        iKuaishouInterfaceService.getGroupList(token, parse, pars1);
     }
 
 
-
-
     @Test
     public void deleteKuaishouComment() {
         Long start = System.currentTimeMillis();
@@ -123,7 +125,6 @@ public class SampleTest {
     }
 
 
-
     @Test
     public void etlBytedanceVideoInfo() {
         String startDate = "2021-02-01";
@@ -147,7 +148,6 @@ public class SampleTest {
     }
 
 
-
     @Test
     public void formatVideoReportData() {
         for (int i = 1; i < 45; i++) {
@@ -237,11 +237,11 @@ public class SampleTest {
     }
 
     @Test
-    public void loadEffecfData(){
+    public void loadEffecfData() {
         String startDate = "2021-05-01";
-        for(int i=0;i<=70;i++){
-            String getDate = DateUtils.addDay(startDate,i);
-            bytedanceVideoEtlInfoService.etlBytedanceVideoInfo(DateUtils.parseDate(getDate,"yyyy-MM-dd"));
+        for (int i = 0; i <= 70; i++) {
+            String getDate = DateUtils.addDay(startDate, i);
+            bytedanceVideoEtlInfoService.etlBytedanceVideoInfo(DateUtils.parseDate(getDate, "yyyy-MM-dd"));
         }
     }
 }

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

@@ -8,19 +8,8 @@ import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouAppPackageService;
 import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouDirectionalPackageService;
 import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouLandpagePackageService;
 import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouPopulationGroupService;
-import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouCampaign;
-import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouCampaignDayBudget;
-import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouCampaignStatus;
-import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouGroup;
-import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouGroupBid;
-import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouGroupDayBudget;
-import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouCampaignDayBudgetMapper;
-import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouCampaignMapper;
-import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouCampaignStatusMapper;
-import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouCreativeMapper;
-import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouGroupBidMapper;
-import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouGroupDayBudgetMapper;
-import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouGroupMapper;
+import cn.com.ctop.kuaishou.modules.batch.entity.*;
+import cn.com.ctop.kuaishou.modules.batch.mapper.*;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouGroupService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouUpdateService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
@@ -69,6 +58,7 @@ public class KuaiShouUpdateServiceImpl implements IKuaiShouUpdateService {
     private IKuaishouLandpagePackageService landpagePackageService;
     @Autowired
     private IKuaishouAppPackageService appPackageService;
+
     @Override
     public Map<String, Object> updateCampaign(String token, Long advertiserId, Long campaignId, Long dayBudget, String loginId) {
         Map<String, Object> returnMap = new HashMap<>();
@@ -394,6 +384,7 @@ public class KuaiShouUpdateServiceImpl implements IKuaiShouUpdateService {
                     } else {
                         groupService.getGroupByUnitId(token, advertiserId, unitId);
                     }
+                    log.info("删除成功,accountId:{}。unitId:{}", advertiserId, unitId);
                 } else {
                     log.error("修改广告组状态失败,advertiserId:{},unitId:{},返回信息:{}", advertiserId, unitId, resultJson);
                     returnMap.put("code", -1);

+ 1 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouProgramCreativeServiceImpl.java

@@ -107,7 +107,7 @@ public class KuaishouProgramCreativeServiceImpl extends ServiceImpl<KuaishouProg
         }
 
         this.saveOrUpdateBatch(programCreativeList);
-        //    getProgramCreative(accountId, unitId, accessToken, startDate, endDate, page + 1);
+            getProgramCreative(accountId, unitId, accessToken, startDate, endDate, page + 1);
 
 
     }