Jelajahi Sumber

长文供需看板(公众号投流)-全局

wangyunpeng 3 jam lalu
induk
melakukan
c883493bf0

+ 75 - 2
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/service/recommend/DataDashboardService.java

@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollectionUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.aliyun.odps.data.Record;
 import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
 import com.google.common.collect.Lists;
 import com.tzld.longarticle.recommend.server.common.enums.ContentPositionEnum;
@@ -45,6 +46,7 @@ import com.tzld.longarticle.recommend.server.service.recommend.score.ScoreStrate
 import com.tzld.longarticle.recommend.server.util.DateUtils;
 import com.tzld.longarticle.recommend.server.util.MapBuilder;
 import com.tzld.longarticle.recommend.server.util.Md5Util;
+import com.tzld.longarticle.recommend.server.util.OdpsUtil;
 import com.tzld.longarticle.recommend.server.util.feishu.FeiShu;
 import com.tzld.longarticle.recommend.server.util.feishu.FeishuMessageSender;
 import com.xxl.job.core.biz.model.ReturnT;
@@ -4473,7 +4475,7 @@ public class DataDashboardService {
         List<LongArticlesSupplyAndDemandExport> exportList = new ArrayList<>();
         dateStrList = Lists.reverse(dateStrList);
         for (String dateStr : dateStrList) {
-            exportList.addAll(buildContentSupplyAndDemandExport(dateStr));
+            exportList.addAll(buildContentSupplyAndDemandExport(dateStr, null));
         }
         if (CollectionUtil.isEmpty(exportList)) {
             return;
@@ -4510,7 +4512,7 @@ public class DataDashboardService {
                 2, styles, null, null);
     }
 
-    private List<LongArticlesSupplyAndDemandExport> buildContentSupplyAndDemandExport(String dateStr) {
+    private List<LongArticlesSupplyAndDemandExport> buildContentSupplyAndDemandExport(String dateStr, List<String> filterAccountList) {
         List<LongArticlesSupplyAndDemandExport> result = new ArrayList<>();
         Long start = DateUtils.getStartOfDay(dateStr, "yyyyMMdd") * 1000;
         Long end = start + 86400000;
@@ -4626,6 +4628,11 @@ public class DataDashboardService {
         long totalFansCount = 0L;
 
         for (DatastatSortStrategy item : firstLevelSortList) {
+            // 账号过滤
+            if (CollectionUtil.isNotEmpty(filterAccountList) && !filterAccountList.contains(item.getAccountName())) {
+                continue;
+            }
+
             // 获取品类
             String category = item.getCategory();
             if (!categoryExportMap.containsKey(category)) {
@@ -4775,4 +4782,70 @@ public class DataDashboardService {
 
         return sumExport;
     }
+
+    @XxlJob("contentSupplyAndDemandDashBoardGzhTouliuJob")
+    public ReturnT<String> contentSupplyAndDemandDashBoardGzhTouliuJob(String param) {
+        List<String> dateStrList = DateUtils.getBeforeDays(null, null, 1);
+        contentSupplyAndDemandDashBoardGzhTouliu(dateStrList);
+        return ReturnT.SUCCESS;
+    }
+
+    public void contentSupplyAndDemandDashBoardGzhTouliu(String dateStr) {
+        if (!StringUtils.hasText(dateStr)) {
+            dateStr = DateUtils.getBeforeDaysDateStr("yyyyMMdd", 1);
+        }
+        contentSupplyAndDemandDashBoardGzhTouliu(Collections.singletonList(dateStr));
+    }
+
+    public void contentSupplyAndDemandDashBoardGzhTouliu(List<String> dateStrList) {
+        List<LongArticlesSupplyAndDemandExport> exportList = new ArrayList<>();
+        dateStrList = Lists.reverse(dateStrList);
+
+        // 查询所有公众号投流账号
+        String accountMapSql = "SELECT account_id, account_name from loghubods.feishu_wechat_mp_account_base where account_status = '开';";
+        List<Record> accountList = OdpsUtil.getOdpsData(accountMapSql);
+        List<String> touliuAccountList = new ArrayList<>();
+        if (CollectionUtils.isNotEmpty(accountList)) {
+            for (Record record : accountList) {
+                String accountName = record.getString(1);
+                touliuAccountList.add(accountName);
+            }
+        }
+        for (String dateStr : dateStrList) {
+            exportList.addAll(buildContentSupplyAndDemandExport(dateStr, touliuAccountList));
+        }
+        if (CollectionUtil.isEmpty(exportList)) {
+            return;
+        }
+        int rowNum = exportList.size();
+        List<List<Object>> rows = new ArrayList<>();
+        Field[] fields = LongArticlesSupplyAndDemandExport.class.getDeclaredFields();
+        for (LongArticlesSupplyAndDemandExport datum : exportList) {
+            List<Object> rowDatas = new ArrayList<>();
+            rows.add(rowDatas);
+
+            for (Field field : fields) {
+                field.setAccessible(true);
+                try {
+                    rowDatas.add(field.get(datum));
+                } catch (IllegalAccessException e) {
+                    log.error("获取值出错:{}", field.getName());
+                } catch (Exception e) {
+                    throw new RuntimeException(e.getMessage());
+                }
+            }
+        }
+
+        List<Pair<String, String>> styles = Arrays
+                .asList(
+                        Pair.of("E", "0.00%"),
+                        Pair.of("G", "0.00%"),
+                        Pair.of("K", "0.00%"),
+                        Pair.of("M", "0.00%"),
+                        Pair.of("N", "0.00%"),
+                        Pair.of("O", "0.00%")
+                );
+        doSendFeishuSheet(FeiShu.requestPQAccessToken(), dateStrList, "FD47w23TaiITHSkKCmqcM85FnBd", "DhIku2", rowNum, rows,
+                2, styles, null, null);
+    }
 }

+ 33 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/util/OdpsUtil.java

@@ -0,0 +1,33 @@
+package com.tzld.longarticle.recommend.server.util;
+
+import com.aliyun.odps.Instance;
+import com.aliyun.odps.Odps;
+import com.aliyun.odps.OdpsException;
+import com.aliyun.odps.account.Account;
+import com.aliyun.odps.account.AliyunAccount;
+import com.aliyun.odps.data.Record;
+import com.aliyun.odps.task.SQLTask;
+
+import java.util.List;
+
+public class OdpsUtil {
+
+    public static List<Record> getOdpsData(String sql) {
+        String accessId = "LTAI9EBa0bd5PrDa";
+        String accessKey = "vAalxds7YxhfOA2yVv8GziCg3Y87v5";
+        String endpoint = "http://service.odps.aliyun.com/api";
+        Account account = new AliyunAccount(accessId, accessKey);
+        Odps odps = new Odps(account);
+        odps.setEndpoint(endpoint);
+        odps.setDefaultProject("loghubods");
+        Instance i;
+        try {
+            i = SQLTask.run(odps, sql);
+            i.waitForSuccess();
+            return SQLTask.getResult(i);
+        } catch (OdpsException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+}

+ 7 - 0
long-article-recommend-service/src/main/java/com/tzld/longarticle/recommend/server/web/recommend/DataDashboardController.java

@@ -120,4 +120,11 @@ public class DataDashboardController {
         }).start();
     }
 
+    @GetMapping("/export/contentSupplyAndDemandDashBoardGzhTouliu")
+    public void contentSupplyAndDemandDashBoardGzhTouliu(String dateStr) {
+        new Thread(() -> {
+            service.contentSupplyAndDemandDashBoardGzhTouliu(dateStr);
+        }).start();
+    }
+
 }