소스 검색

修改定时任务时报数据获取逻辑

syh 5 년 전
부모
커밋
dd11a7a0c5

+ 9 - 3
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/job/KuaishouHourlyReportLoadJob.java

@@ -5,11 +5,13 @@ 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.jeecg.common.util.DateUtils;
 import org.quartz.Job;
 import org.quartz.JobExecutionContext;
 import org.quartz.JobExecutionException;
 import org.springframework.beans.factory.annotation.Autowired;
 
+import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.List;
 
@@ -26,6 +28,11 @@ public class KuaishouHourlyReportLoadJob implements Job {
     @Override
     public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
         Date getDate = new Date();
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH");
+        String hour = simpleDateFormat.format(getDate);
+        if (null != hour && hour.equals("00")) {
+            getDate = DateUtils.addDay(getDate, -1);
+        }
         //1:查询当日数据
         List<CtopOauthToken> tokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_KUAISHOU);
         if (null == tokens || tokens.size() <= 0) {
@@ -33,8 +40,7 @@ public class KuaishouHourlyReportLoadJob implements Job {
             return;
         }
 
-        tokens.forEach(token -> {
-            //1: 获取广告主信息数据
+        for (CtopOauthToken token : tokens) {
             kuaishouInterfaceService.getAdvertiserReportHourly(token, getDate, getDate);
             //2:获取广告计划信息数据
             kuaishouInterfaceService.getAdvertiserCampaignReportHourly(token, getDate, getDate);
@@ -42,6 +48,6 @@ public class KuaishouHourlyReportLoadJob implements Job {
             kuaishouInterfaceService.getAdvertiserGroupReportHourly(token, getDate, getDate);
             //4: 获取广告创意信息数据
             kuaishouInterfaceService.getAdvertiserCreativeReportHourly(token, getDate, getDate);
-        });
+        }
     }
 }

+ 1 - 2
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/KuaiShouCreative.java

@@ -1,6 +1,5 @@
 package cn.com.ctop.kuaishou.modules.batch.entity;
 
-import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.fasterxml.jackson.annotation.JsonFormat;
@@ -30,7 +29,7 @@ public class KuaiShouCreative {
     /**
      * id
      */
-    @TableId(type = IdType.AUTO)
+    @TableId
     @ApiModelProperty(value = "id")
     private Long id;
     /**

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

@@ -4,6 +4,7 @@ import cn.com.ctop.common.module.entity.CtopOauthToken;
 import cn.com.ctop.common.module.utils.*;
 import cn.com.ctop.kuaishou.modules.batch.entity.*;
 import cn.com.ctop.kuaishou.modules.batch.mapper.*;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouCreativeService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
 import cn.com.ctop.kuaishou.modules.material.entity.KuaishouResult;
 import cn.com.ctop.kuaishou.modules.material.entity.KuaishouResultToken;
@@ -66,7 +67,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
     @Autowired
     private KuaiShouScheduleMapper shouScheduleMapper;
     @Autowired
-    private KuaiShouCreativeMapper creativeMapper;
+    private IKuaiShouCreativeService creativeService;
     @Autowired
     private KuaiShouConversionInfosMapper conversionInfosMapper;
     @Autowired
@@ -1190,8 +1191,62 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
 
             }
         }
+    }
 
+    public void getCreativeListByPage(String accessToken, Long advertiserId, Integer page) {
+        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", accessToken);
+        JSONObject param = new JSONObject();
+        param.put("advertiser_id", advertiserId);
+        param.put("page_size", 200);
+        param.put("page", page);
 
+        String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
+        JSONObject resultJson = JSONObject.parseObject(result);
+        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;
+        }
+        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(detailJson.getLong("creative_id"));
+                creative.setAccountId(advertiserId);
+                creative.setStatus(detailJson.getInteger("status"));
+                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.setPhotoId(detailJson.getString("photo_id"));
+                creative.setReviewDetail(detailJson.getString("review_detail"));
+                creative.setCoverUrl(detailJson.getString("cover_url"));
+                creative.setCoverHeight(detailJson.getString("cover_height"));
+                creative.setCoverWidth(detailJson.getString("cover_width"));
+                creative.setClickTrackUrl(detailJson.getString("click_track_url"));
+                JSONObject displayInfoJson = detailJson.getJSONObject("display_info");
+                if (!Check.isNull(displayInfoJson)) {
+                    creative.setDescription(displayInfoJson.getString("description"));
+                    creative.setActionBarText(displayInfoJson.getString("action_bar_text"));
+                }
+                creativeService.saveOrUpdate(creative);
+            }
+
+        }
+        getCreativeList(accessToken, advertiserId, page + 1);
     }
 
     /**
@@ -1202,11 +1257,6 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
      */
     @Override
     public void getCreativeList(String accessToken, Long advertiserId, Integer page) {
-        if (page == 1) { // 第一次请求删除历史数据
-            Map<String, Object> map = new HashMap<>();
-            map.put("account_id", advertiserId);
-            creativeMapper.deleteByMap(map);
-        }
         String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CREATIVE_LIST;
         Map<String, String> headers = new HashMap<String, String>();
         headers.put("Content-Type", " application/json");
@@ -1229,24 +1279,25 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                                 JSONObject detailJson = JSONObject.parseObject(details.get(i).toString());
                                 if (!Check.isNull(detailJson)) {
                                     KuaiShouCreative creative = new KuaiShouCreative();
+                                    creative.setId(detailJson.getLong("creative_id"));
                                     creative.setAccountId(advertiserId);
                                     creative.setStatus(detailJson.getInteger("status"));
-                                    creative.setCampaignId(dataJson.getLong("campaign_id"));
-                                    creative.setUnitId(dataJson.getLong("unit_id"));
-                                    creative.setCreativeId(dataJson.getLong("creative_id"));
-                                    creative.setCreativeName(dataJson.getString("creative_name"));
-                                    creative.setPhotoId(dataJson.getString("photo_id"));
-                                    creative.setReviewDetail(dataJson.getString("review_detail"));
-                                    creative.setCoverUrl(dataJson.getString("cover_url"));
-                                    creative.setCoverHeight(dataJson.getString("cover_height"));
-                                    creative.setCoverWidth(dataJson.getString("cover_width"));
-                                    creative.setClickTrackUrl(dataJson.getString("click_track_url"));
+                                    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.setPhotoId(detailJson.getString("photo_id"));
+                                    creative.setReviewDetail(detailJson.getString("review_detail"));
+                                    creative.setCoverUrl(detailJson.getString("cover_url"));
+                                    creative.setCoverHeight(detailJson.getString("cover_height"));
+                                    creative.setCoverWidth(detailJson.getString("cover_width"));
+                                    creative.setClickTrackUrl(detailJson.getString("click_track_url"));
                                     JSONObject displayInfoJson = detailJson.getJSONObject("display_info");
                                     if (!Check.isNull(displayInfoJson)) {
                                         creative.setDescription(displayInfoJson.getString("description"));
                                         creative.setActionBarText(displayInfoJson.getString("action_bar_text"));
                                     }
-                                    creativeMapper.insert(creative);
+                                    creativeService.saveOrUpdate(creative);
                                 }
 
                             }

+ 3 - 1
module-toutiao/src/main/java/cn/com/ctop/toutiao/service/impl/ByteDanceAdvertiserDataServiceImpl.java

@@ -215,7 +215,9 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
 
         TreeMap<String, Object> params = new TreeMap<>();
         params.put("advertiser_id", cTopOauthToken.getAccountId());
-        params.put("creative_ids", "[" + creativeIds + "]");
+        if (null != creativeIds && !"".equals(creativeIds.trim())) {
+            params.put("creative_ids", "[" + creativeIds + "]");
+        }
         String result = HttpUtils.httpGetRequest(url, headers, params);
         JSONObject jsonObject = JSONObject.parseObject(result);
         Integer code = jsonObject.getInteger("code");