瀏覽代碼

微小 广告位收入

huangpingkang 1 年之前
父節點
當前提交
71ee93fcef

+ 2 - 0
job-adq/src/main/java/cn/com/ctop/job/adq/data/mapper/AdqAdIncomeMapper.java

@@ -11,4 +11,6 @@ public interface AdqAdIncomeMapper {
     void insertAdqAdIncome(List<AdqPublisherAdunitGeneral> reports);
 
     List<JSONObject> queryAdqIaaMiniApp(@Param("appId")String appId);
+
+    List<JSONObject> queryAdqAdIncomeRetryJob();
 }

+ 5 - 0
job-adq/src/main/java/cn/com/ctop/job/adq/data/mapper/xml/AdqAdIncomeMapper.xml

@@ -28,4 +28,9 @@
             and m.app_id = #{appId}
         </if>
     </select>
+    <select id="queryAdqAdIncomeRetryJob" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT t1.msg as 'msg',t1.is_send AS 'isSend', t1.id AS 'id', t1.advertiser_id AS 'advertiserId', t1.start_date AS 'startDate', t1.end_date AS 'endDate', t1.data_dimension AS 'dataDimension', t1.data_type AS 'dataType', t1.msg
+        FROM media_api.adq_error_log t1
+        where data_dimension = 'adq_ma_ad_income';
+    </select>
 </mapper>

+ 1 - 0
job-adq/src/main/java/cn/com/ctop/job/adq/data/service/IAdqAdIncomeService.java

@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
 import java.util.List;
 
 public interface IAdqAdIncomeService {
+    List<JSONObject> getAdqAdIncomeRetryJob();
     List<JSONObject> getAdqMiniApp(String appId);
     void getAdqAdIncome(String startDt, String endDt, String appId, Long appletId, Integer page, Integer isLog, Long errId, Integer isSend);
 }

+ 15 - 9
job-adq/src/main/java/cn/com/ctop/job/adq/data/service/impl/AdqAdIncomeServiceImpl.java

@@ -32,6 +32,10 @@ public class AdqAdIncomeServiceImpl implements IAdqAdIncomeService {
     @Autowired
     private AdqErrorLogMapper adqErrorLogMapper;
 
+    public List<JSONObject> getAdqAdIncomeRetryJob() {
+        return adqAdIncomeMapper.queryAdqAdIncomeRetryJob();
+    }
+
     public List<JSONObject> getAdqMiniApp(String appId) {
         return adqAdIncomeMapper.queryAdqIaaMiniApp(appId);
     }
@@ -41,7 +45,7 @@ public class AdqAdIncomeServiceImpl implements IAdqAdIncomeService {
             String url = "https://api.weixin.qq.com/publisher/stat";
             Object tokenObj = redis2Template_db5.opsForValue().get("wechat-applet-access-token-key-" + appletId);
             if (tokenObj == null) {
-                log.error("微小广告收入拉取获取token为空 [{}] {}~{} {}", appId, startDt, endDt, appletId);
+                log.error("微小广告细分数据拉取获取token为空 [{}] {}~{} {}", appId, startDt, endDt, appletId);
                 return;
             }
             int pageSize = 1000;
@@ -58,7 +62,7 @@ public class AdqAdIncomeServiceImpl implements IAdqAdIncomeService {
             boolean hasMore = false;
             if (!Check.isNull(jsonObject)) {
                 Integer code = jsonObject.getInteger("ret");
-                if(code == 2009) {
+                if (code == 2009) {
                     return; //无效的流量主
                 }
                 if (code == 0) {
@@ -73,18 +77,20 @@ public class AdqAdIncomeServiceImpl implements IAdqAdIncomeService {
                             AdqPublisherAdunitGeneral report = JSONObject.parseObject(statItem.toJSONString(), AdqPublisherAdunitGeneral.class);
                             report.setAppId(appId);
                             report.setStatDate(Integer.valueOf(report.getDate().replace("-", "")));
-                            System.out.println(report);
+                            //System.out.println(report);
                             reports.add(report);
                         }
                     }
 
                 } else {
-                    log.error("微小广告收入拉取失败,app_id:{} {}~{},返回信息:{}", appId, startDt, endDt, jsonObject);
-                    insertErrorLog(isLog, System.currentTimeMillis(), "adq_ma_ad_income", startDt, endDt, jsonObject.fluentPut("app_id", appId).toJSONString());
+                    log.error("微小广告细分数据拉取失败,app_id:{} {}~{},返回信息:{}", appId, startDt, endDt, jsonObject);
+                    insertErrorLog(isLog, System.currentTimeMillis(), "adq_ma_ad_income", startDt, endDt,
+                            jsonObject.fluentPut("app_id", appId).fluentPut("applet_id", appletId).toJSONString());
                 }
             } else {
-                log.error("微小广告收入拉取失败,app_id:{} {}~{},返回为空。", appId, startDt, endDt);
-                insertErrorLog(isLog, System.currentTimeMillis(), "adq_ma_ad_income", startDt, endDt, new JSONObject().fluentPut("app_id", appId).fluentPut("msg", "返回为空").toJSONString());
+                log.error("微小广告细分数据拉取失败,app_id:{} {}~{},返回为空。", appId, startDt, endDt);
+                insertErrorLog(isLog, System.currentTimeMillis(), "adq_ma_ad_income", startDt, endDt,
+                        new JSONObject().fluentPut("app_id", appId).fluentPut("applet_id", appletId).fluentPut("msg", "返回为空").toJSONString());
             }
             if (!Check.isNull(reports)) {
                 adqAdIncomeMapper.insertAdqAdIncome(reports);
@@ -93,7 +99,7 @@ public class AdqAdIncomeServiceImpl implements IAdqAdIncomeService {
             if (hasMore) {
                 getAdqAdIncome(startDt, endDt, appId, appletId, page + 1, isLog, errId, isSend);
             } else {
-                log.info("微小广告收入拉取完成,app_id:{} {}~{}。", appId, startDt, endDt);
+                log.info("微小广告细分数据拉取完成,app_id:{} {}~{}。", appId, startDt, endDt);
                 if (errId != null) {
                     adqErrorLogMapper.deleteInfoByErrorId(errId);
                 }
@@ -102,7 +108,7 @@ public class AdqAdIncomeServiceImpl implements IAdqAdIncomeService {
                 }
             }
         } catch (Exception e) {
-            log.error("微小广告收入拉取失败,app_id:{} {}~{}。", appId, startDt, endDt,e);
+            log.error("微小广告细分数据拉取失败,app_id:{} {}~{}。", appId, startDt, endDt, e);
         }
     }
 

+ 16 - 3
job-adq/src/main/java/cn/com/ctop/job/adq/handler/AdqAccountReportJob.java

@@ -2,16 +2,18 @@ package cn.com.ctop.job.adq.handler;
 
 
 import cn.com.ctop.job.adq.data.service.IAdqAccountReportService;
+import cn.com.ctop.job.adq.data.service.IAdqAdIncomeService;
 import cn.com.ctop.job.adq.data.service.IAdqAssetReportService;
-import cn.com.ctop.job.adq.data.service.IAdqCreativeReportService;
 import cn.com.ctop.job.adq.data.utils.Check;
 import cn.com.ctop.job.adq.data.utils.DateUtils;
+import com.alibaba.fastjson.JSONObject;
 import com.xxl.job.core.context.XxlJobHelper;
 import com.xxl.job.core.handler.annotation.XxlJob;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.util.List;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
@@ -28,6 +30,8 @@ public class AdqAccountReportJob {
     private IAdqAssetReportService adqAssetReportService;
     @Autowired
     private IAdqAccountReportService accountReportService;
+    @Autowired
+    private IAdqAdIncomeService adqAdIncomeService;
     private static ExecutorService nowDateHourExecutorService = Executors.newFixedThreadPool(5);
     private static ExecutorService yesDateHourExecutorService = Executors.newFixedThreadPool(5);
     private static ExecutorService dailyExecutorService = Executors.newFixedThreadPool(5);
@@ -75,7 +79,6 @@ public class AdqAccountReportJob {
     }
 
 
-
     @XxlJob("yesDateAccountDaily")
     public void yesDateAccountDaily() throws Exception {
         String param = XxlJobHelper.getJobParam(); // 执行参数
@@ -119,6 +122,16 @@ public class AdqAccountReportJob {
         });
     }
 
-
+    @XxlJob("miniAppAdIncome")
+    public void miniAppAdIncome() {
+        List<JSONObject> adqMiniApp = adqAdIncomeService.getAdqMiniApp(null);
+        String start = DateUtils.getNowAddDate("yyyy-MM-dd", -1);
+        String end = DateUtils.getNowDate("yyyy-MM-dd");
+        for (JSONObject jsonObject : adqMiniApp) {
+            String app = jsonObject.getString("app_id");
+            Long appletId = jsonObject.getLong("applet_id");
+            adqAdIncomeService.getAdqAdIncome(start, end, app, appletId, 1, 1, null, null);
+        }
+    }
 
 }

+ 27 - 5
job-adq/src/main/java/cn/com/ctop/job/adq/handler/AdqRetryReportJob.java

@@ -1,10 +1,7 @@
 package cn.com.ctop.job.adq.handler;
 
 
-import cn.com.ctop.job.adq.data.service.IAdqAssetReportService;
-import cn.com.ctop.job.adq.data.service.IAdqCreativeReportService;
-import cn.com.ctop.job.adq.data.service.IAdqFlowDetailsReportService;
-import cn.com.ctop.job.adq.data.service.IAdqRetryReportService;
+import cn.com.ctop.job.adq.data.service.*;
 import cn.com.ctop.job.adq.data.utils.Check;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
@@ -43,6 +40,8 @@ public class AdqRetryReportJob {
     private IAdqRetryReportService retryReportService;
     @Autowired
     private IAdqAssetReportService assetReportService;
+    @Autowired
+    private IAdqAdIncomeService adqAdIncomeService;
 
     @Autowired
     private IAdqFlowDetailsReportService adqFlowDetailsReportService;
@@ -84,7 +83,7 @@ public class AdqRetryReportJob {
                             }
                         });
                     }
-                }else if("account".equals(dataDimension)){
+                } else if ("account".equals(dataDimension)) {
                     if (dataType.equals("hour")) { // 广告时报
                         hourrAccountExecutorService.submit(new Runnable() {
                             @Override
@@ -152,6 +151,29 @@ public class AdqRetryReportJob {
             log.info("重试列表为空");
         }
 
+        List<JSONObject> adqAdIncomeRetryJob = adqAdIncomeService.getAdqAdIncomeRetryJob();
+        if (!Check.isNull(adqAdIncomeRetryJob)) {
+            ExecutorService executorService = Executors.newFixedThreadPool(1);
+            for (int i = 0; i < adqAdIncomeRetryJob.size(); i++) {
+                JSONObject jsonObject = adqAdIncomeRetryJob.get(i);
+                Long id = jsonObject.getLong("id");
+                String startDate = jsonObject.getString("startDate");
+                String endDate = jsonObject.getString("endDate");
+                Integer isSend = jsonObject.getInteger("isSend");
+                JSONObject msg = jsonObject.getJSONObject("msg");
+                String appId = msg.getString("app_id");
+                Long appletId = msg.getLong("applet_id");
+                executorService.submit(new Runnable() {
+                    @Override
+                    public void run() {
+                        adqAdIncomeService.getAdqAdIncome(startDate, endDate, appId, appletId, 1, null, id, isSend);
+                    }
+                });
+            }
+        } else {
+            log.info("微小广告细分数据重试列表为空");
+        }
+
     }
 
 }