yumeng 5 vuotta sitten
vanhempi
commit
52bc83cfc6

+ 52 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/job/KuaishouSuZaoLoadJob.java

@@ -0,0 +1,52 @@
+package org.jeecg.modules.ctop.job;
+
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+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 lombok.extern.slf4j.Slf4j;
+import org.quartz.Job;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+@Slf4j
+public class KuaishouSuZaoLoadJob implements Job {
+    @Autowired
+    private ICtopOauthTokenService tokenService;
+    @Autowired
+    private IKuaishouInterfaceService kuaishouInterfaceService;
+
+    static ExecutorService executorService = null;
+
+    @Override
+    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
+        Thread thread = new Thread() {
+            @Override
+            public void run() {
+                List<CtopOauthToken> tokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_KUAISHOU);
+                executorService = Executors.newFixedThreadPool(8);
+                tokens.forEach(token -> {
+                    executorService.submit(new Runnable() {
+                        @Override
+                        public void run() {
+                            try {
+                                kuaishouInterfaceService.getSuZaoList(token.getAccessToken(), token.getAccountId(), 1);
+                            } catch (Exception e) {
+                                e.printStackTrace();
+                            } finally {
+                            }
+                        }
+                    });
+                });
+                log.info("快手素造数据同步完成");
+            }
+        };
+        thread.start();
+
+    }
+}

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

@@ -6,8 +6,8 @@ import cn.com.ctop.common.module.entity.UserAllocation;
 import cn.com.ctop.common.module.mapper.CtopOauthTokenMapper;
 import cn.com.ctop.common.module.service.ICtopOauthTokenService;
 import cn.com.ctop.common.module.service.IUserAllocationService;
-import cn.com.ctop.common.module.utils.*;
-import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouCreative;
+import cn.com.ctop.common.module.utils.CtopAdConstant;
+import cn.com.ctop.common.module.utils.HttpUtils;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouCreativeService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouHistoryReportTaskService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
@@ -23,7 +23,8 @@ import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
 
 import java.text.SimpleDateFormat;
-import java.util.*;
+import java.util.Date;
+import java.util.List;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
@@ -211,14 +212,17 @@ public class SampleTest {
     @Autowired
     private IKuaiShouCreativeService creativeService;
 
+
+
     @Test
     public void suZhao() {
 
 
-        /*Long accountId = 3917130L;
-        String token = "9f2caae880367a9477cf1b6bf86e3858";
+        Long accountId = 3917130L;
+        String token = "0a42e23921e486108105263e75561404";
+        kuaishouInterfaceService.getVideoList("e91c778d7de1bd0e9d8f3213d1e0e57c",3820093L, null,null,1);
 
-        String url = "https://ad.e.kuaishou.com/rest/openapi/v1/file/ad/video/su_zao/list";
+      /*  String url = "https://ad.e.kuaishou.com/rest/openapi/v1/file/ad/video/su_zao/list";
 
 
         Map<String, String> headers = new HashMap<String, String>();
@@ -228,118 +232,11 @@ public class SampleTest {
 
         param.put("advertiser_id", accountId);
         param.put("temporal_granularity", "HOURLY");
-        param.put("page_size", 499);
         param.put("page", 1);
         String result = HttpUtils.httpPostRequest(url, param, headers);
         System.err.println(result);*/
 
 
-        String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CREATIVE_LIST;
-        Map<String, String> headers = new HashMap<>();
-        headers.put("Content-Type", " application/json");
-        headers.put("Access-Token", "bd90c55f01d79450c66260bcb15b5c0a");
-        Long advertiserId = 23212L;
-        JSONObject param = new JSONObject();
-        param.put("advertiser_id", 23212);
-        //   param.put("creative_id", creativeId);
-        param.put("page_size", 500);
-        param.put("page", 1);
-
-        System.err.println(param);
-        System.err.println(headers);
-
-        String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
-        JSONObject resultJson = JSONObject.parseObject(result);
-        System.err.println(resultJson);
-
-
-        if (Check.isNull(resultJson)) {
-            log.error("获取广告创意返回结果为空,advertiserId:{}", advertiserId);
-            return;
-        }
-        Integer code = resultJson.getInteger("code");
-        String message = resultJson.getString("message");
-        if (null == code || code != 0) {
-            log.error("获取广告创意返回结果异常,advertiserId:{},message:{}", advertiserId, message);
-            return;
-        }
-        JSONArray details = resultJson.getJSONObject("data").getJSONArray("details");
-        if (null == details || details.size() <= 0) {
-//            log.error("获取广告创意返回结果数据为空,advertiserId:{}", advertiserId);
-            return;
-        }
-        List<KuaiShouCreative> creatives = new ArrayList<>();
-        for (int i = 0; i < details.size(); i++) {
-            JSONObject detailJson = JSONObject.parseObject(details.get(i).toString());
-            if (!Check.isNull(detailJson)) {
-                KuaiShouCreative creative = new KuaiShouCreative();
-                creative.setId("" + advertiserId + detailJson.getLong("creative_id"));
-                creative.setAccountId(advertiserId);
-                creative.setCampaignId(detailJson.getLong("campaign_id"));
-                creative.setUnitId(detailJson.getLong("unit_id"));
-                creative.setCreativeId(detailJson.getLong("creative_id"));
-                creative.setCreativeName(detailJson.getString("creative_name"));
-                creative.setCreativeMaterialType(detailJson.getInteger("creative_material_type"));
-                //
-                if (!Check.isNull(detailJson.getJSONArray("material_url"))) {
-                    creative.setMaterialUrl(detailJson.getJSONArray("material_url").toJSONString());
-                }
-
-                if (!Check.isNull(detailJson.getJSONArray("image_tokens"))) {
-                    creative.setImageTokens(detailJson.getJSONArray("image_tokens").toJSONString());
-                }
-                creative.setStatus(detailJson.getInteger("status"));
-                creative.setPutStatus(detailJson.getInteger("put_status"));
-                creative.setCreateChannel(detailJson.getInteger("create_channel"));
-                creative.setReviewDetail(detailJson.getString("review_detail"));
-                creative.setCoverUrl(detailJson.getString("cover_url"));
-                creative.setImageToken(detailJson.getString("image_token"));
-                creative.setCoverWidth(detailJson.getString("cover_width"));
-                creative.setCoverHeight(detailJson.getString("cover_height"));
-                creative.setOverlayBgUrl(detailJson.getString("overlay_bg_url"));
-                creative.setOverlayBgImageToken(detailJson.getString("overlay_bg_image_token"));
-                creative.setStickerTitle(detailJson.getString("sticker_title"));
-                creative.setOverlayType(detailJson.getString("overlay_type"));
-                creative.setClickTrackUrl(detailJson.getString("click_track_url"));
-                creative.setImpressionUrl(detailJson.getString("impression_url"));
-                creative.setAdPhotoPlayedT3sUrl(detailJson.getString("ad_photo_played_t3s_url"));
-                creative.setCreativeCreateTime(detailJson.getDate("create_time"));
-                JSONObject displayInfoJson = detailJson.getJSONObject("display_info");
-                if (!Check.isNull(displayInfoJson)) {
-                    creative.setDescription(displayInfoJson.getString("description"));
-                    creative.setActionBarText(displayInfoJson.getString("action_bar_text"));
-                }
-                creative.setCreateTime(new Date());
-                creative.setUpdateTime(new Date());
-
-                if (detailJson.getLong("photo_id") == 0) {
-                    JSONObject programmed_creative_material = detailJson.getJSONObject("programmed_creative_material");
-                    if (!Check.isNull(programmed_creative_material)) {
-                        JSONArray materials = programmed_creative_material.getJSONArray("materials");
-                        if (!Check.isNull(materials)) {
-                            for (int j = 0; j < materials.size(); j++) {
-                                JSONObject materialJson = materials.getJSONObject(j);
-                                if (!Check.isNull(materialJson)) {
-                                    Long photo_id = materialJson.getLong("photo_id");
-                                    creative.setPhotoId(String.valueOf(photo_id));
-                                    creatives.add(creative);
-                                }
-                            }
-                        }
-                    }
-
-
-                } else {
-                    creative.setPhotoId(detailJson.getString("photo_id"));
-                    creatives.add(creative);
-                }
-
-
-            }
-        }
-        creativeService.replaceBatch(creatives);
-
-
     }
 
 

+ 2 - 0
module-common/src/main/java/cn/com/ctop/common/module/enums/MaterialEnum.java

@@ -4,6 +4,8 @@ public enum MaterialEnum {
 
 
     VerticalVideoSmall(1, 720, 1280),
+    VerticalVideo787Small(1, 787, 1280),
+    VerticalVideo846Small(1, 846, 1536),
     VerticalVideoBig(1, 1080, 1920),
     HorizontalVideoSmall(2, 1280, 720),
     HorizontalVideoBig(2, 1920, 1080);

+ 3 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/KuaiShouVideoGet.java

@@ -92,4 +92,7 @@ public class KuaiShouVideoGet {
     @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     @ApiModelProperty(value = "修改时间")
     private Date updateTime;
+
+
+    private Integer channelType;
 }

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

@@ -255,7 +255,7 @@ public interface IKuaishouInterfaceService {
 
     void getAdvertiserGroupReportDaily(CtopOauthToken token, Date startDate, Date endDate);
 
-    void getAdvertiserCreativeReportDaily(CtopOauthToken token, Date startDate, Date endDate,JSONArray campaignIds);
+    void getAdvertiserCreativeReportDaily(CtopOauthToken token, Date startDate, Date endDate, JSONArray campaignIds);
 
     void getAdvertiserReportHourly(CtopOauthToken token, Date startDate, Date endDate);
 
@@ -354,6 +354,11 @@ public interface IKuaishouInterfaceService {
 
 
     void getAdvertiserCreativeReportDailyV2(Long campaignId, CtopOauthToken ctopOauthToken, Date startDate, Date endDate);
+
+
+    void getSuZaoList(String token, Long accountId, int page);
+
+
 }
 
 

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

@@ -17,6 +17,7 @@ import cn.com.ctop.kuaishou.modules.report.entity.*;
 import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouReportDailyAccountMapper;
 import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouReportDailyCampaignMapper;
 import cn.com.ctop.kuaishou.modules.report.service.*;
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -3484,8 +3485,15 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
             param.put("start_date", DateUtils.formatDate(startDate));
             param.put("end_date", DateUtils.formatDate(endDate));
         }
+
+        System.err.println(url);
+
+        System.err.println(JSON.toJSONString(param));
+        System.err.println(JSON.toJSONString(headers));
+
         String result = HttpUtils.httpPostRequest(url, param, headers);
         JSONObject resultJson = JSONObject.parseObject(result);
+        System.err.println(resultJson);
         Integer code = resultJson.getInteger("code");
         String message = resultJson.getString("message");
         if (null == code || code != 0) {
@@ -3788,6 +3796,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
         getAdvertiserCreativeReportDailyByPageV2(campaignId, token, startDate, endDate, 1);
     }
 
+
     private void getAdvertiserCreativeReportDailyByPageV2(Long campaignId, CtopOauthToken token, Date startDate, Date endDate, int page) {
         String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CREATIVE_REPORT;
         Map<String, String> headers = new HashMap<String, String>();
@@ -3844,5 +3853,54 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
         getAdvertiserCreativeReportDailyByPageV2(campaignId, token, startDate, endDate, page + 1);
     }
 
+    /**
+     * 获取素造数据
+     *
+     * @param token
+     * @param accountId
+     * @param page
+     */
+    @Override
+    public void getSuZaoList(String token, Long accountId, int page) {
+        String url = "https://ad.e.kuaishou.com/rest/openapi/v1/file/ad/video/su_zao/list";
+        Map<String, String> headers = new HashMap<String, String>();
+        headers.put("Content-Type", "application/json");
+        headers.put("Access-Token", token);
+        Map<String, Object> param = new HashMap<String, Object>();
+        param.put("advertiser_id", accountId);
+        param.put("page", page);
+        param.put("page_size", 500);
+        String result = HttpUtils.httpPostRequest(url, param, headers);
+        JSONObject resultJson = JSONObject.parseObject(result);
+        Integer code = resultJson.getInteger("code");
+        String message = resultJson.getString("message");
+        if (null == code || code != 0) {
+            log.error("获取快手素造列表数据异常:{},accountId:{}", message, accountId);
+            return;
+        }
+        JSONObject dataJson = resultJson.getJSONObject("data");
+        if (!Check.isNull(dataJson)) {
+            JSONArray details = dataJson.getJSONArray("detail");
+            if (Check.isNull(details)) {
+                return;
+            }
+            for (int i = 0; i < details.size(); i++) {
+                var detailJson = details.getJSONObject(i);
+                var kuaiShouVideoGet = JSONObject.toJavaObject(detailJson, KuaiShouVideoGet.class);
+                kuaiShouVideoGet.setAccountId(accountId);
+                kuaiShouVideoGet.setId(accountId + kuaiShouVideoGet.getPhotoId());
+                kuaiShouVideoGet.setCreateTime(new Date());
+                kuaiShouVideoGet.setUpdateTime(new Date());
+                Integer type = MaterialEnum.getTypeBySize(kuaiShouVideoGet.getWidth(), kuaiShouVideoGet.getHeight());
+                if (!Check.isNull(type)) {
+                    kuaiShouVideoGet.setMaterialType(type);
+                }
+                kuaiShouVideoGet.setChannelType(1);
+                kuaiShouVideoGetService.saveOrUpdate(kuaiShouVideoGet);
+            }
+        }
+        getSuZaoList(token, accountId, page + 1);
+
+    }
 
 }