wangyunpeng 2 ماه پیش
والد
کامیت
500fa5b4bf

+ 18 - 0
api-module/src/main/java/com/tzld/piaoquan/api/controller/contentplatform/ContentPlatformDatastatController.java

@@ -1,5 +1,6 @@
 package com.tzld.piaoquan.api.controller.contentplatform;
 
+import com.tzld.piaoquan.api.job.ContentPlatformDatastatJob;
 import com.tzld.piaoquan.api.model.param.contentplatform.GzhDatastatListParam;
 import com.tzld.piaoquan.api.model.param.contentplatform.QwDatastatListParam;
 import com.tzld.piaoquan.api.model.vo.contentplatform.GzhDatastatItemVO;
@@ -19,6 +20,9 @@ public class ContentPlatformDatastatController {
     @Autowired
     ContentPlatformDatastatService datastatService;
 
+    @Autowired
+    ContentPlatformDatastatJob job;
+
     @ApiOperation(value = "公众号数据统计")
     @PostMapping("/gzh")
     public CommonResponse<Page<GzhDatastatItemVO>> gzhDatastatList(@RequestBody GzhDatastatListParam param) {
@@ -43,4 +47,18 @@ public class ContentPlatformDatastatController {
         return CommonResponse.success(datastatService.qwDatastatExport(param));
     }
 
+    @ApiOperation(value = "公众号数据统计同步任务")
+    @GetMapping("/job/syncGzhDatastat")
+    public CommonResponse<String> syncContentPlatformGzhDatastatJob() {
+        job.syncContentPlatformGzhDatastatJob(null);
+        return CommonResponse.success();
+    }
+
+    @ApiOperation(value = "企微数据统计同步任务")
+    @GetMapping("/job/syncQwDatastat")
+    public CommonResponse<String> syncContentPlatformQwDatastatJob() {
+        job.syncContentPlatformQwDatastatJob(null);
+        return CommonResponse.success();
+    }
+
 }

+ 4 - 0
api-module/src/main/java/com/tzld/piaoquan/api/dao/mapper/contentplatform/ext/ContentPlatformDataStatMapperExt.java

@@ -54,4 +54,8 @@ public interface ContentPlatformDataStatMapperExt {
                                                          @Param("createAccountId") Long createAccountId,
                                                          @Param("offset") int offset,
                                                          @Param("pageSize") Integer pageSize);
+
+    void batchInsertGzhDatastat(@Param("records") List<ContentPlatformGzhDataStat> saveList);
+
+    void batchInsertQwDatastat(@Param("records") List<ContentPlatformQwDataStat> saveList);
 }

+ 165 - 50
api-module/src/main/java/com/tzld/piaoquan/api/job/ContentPlatformDatastatJob.java

@@ -1,10 +1,15 @@
 package com.tzld.piaoquan.api.job;
 
 import com.aliyun.odps.data.Record;
-import com.tzld.piaoquan.api.dao.mapper.contentplatform.ContentPlatformVideoMapper;
-import com.tzld.piaoquan.api.dao.mapper.contentplatform.ext.ContentPlatformPlanMapperExt;
-import com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformVideo;
-import com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformVideoExample;
+import com.tzld.piaoquan.api.dao.mapper.contentplatform.ContentPlatformGzhAccountMapper;
+import com.tzld.piaoquan.api.dao.mapper.contentplatform.ContentPlatformGzhDataStatMapper;
+import com.tzld.piaoquan.api.dao.mapper.contentplatform.ContentPlatformQwDataStatMapper;
+import com.tzld.piaoquan.api.dao.mapper.contentplatform.ContentPlatformQwPlanMapper;
+import com.tzld.piaoquan.api.dao.mapper.contentplatform.ext.ContentPlatformDataStatMapperExt;
+import com.tzld.piaoquan.api.model.po.contentplatform.*;
+import com.tzld.piaoquan.api.model.vo.WxAccountDatastatVO;
+import com.tzld.piaoquan.api.remote.AigcApiService;
+import com.tzld.piaoquan.api.service.contentplatform.ContentPlatformPlanService;
 import com.tzld.piaoquan.growth.common.utils.DateUtil;
 import com.tzld.piaoquan.growth.common.utils.OdpsUtil;
 import com.xxl.job.core.biz.model.ReturnT;
@@ -16,91 +21,201 @@ import org.springframework.stereotype.Component;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
 
 @Slf4j
 @Component
 public class ContentPlatformDatastatJob {
 
     @Autowired
-    private ContentPlatformPlanMapperExt planMapperExt;
+    private ContentPlatformGzhDataStatMapper gzhDataStatMapper;
 
     @Autowired
-    private ContentPlatformVideoMapper videoMapper;
+    private ContentPlatformGzhAccountMapper gzhAccountMapper;
+
+    @Autowired
+    private ContentPlatformQwDataStatMapper qwDataStatMapper;
+
+    @Autowired
+    private ContentPlatformQwPlanMapper qwPlanMapper;
+
+    @Autowired
+    private ContentPlatformDataStatMapperExt dataStatMapperExt;
+
+    @Autowired
+    private AigcApiService aigcApiService;
+
+    @Autowired
+    private ContentPlatformPlanService planService;
+
 
     @XxlJob("syncContentPlatformGzhDatastatJob")
     public ReturnT<String> syncContentPlatformGzhDatastatJob(String param) {
-        String dt = DateUtil.getBeforeDayDateString();
-        long videoCount = getVideoCount(dt);
-        if (videoCount > 0) {
+        String dt = DateUtil.getBeforeDayDateString("yyyyMMdd");
+        long count = getGzhDatastatCount(dt);
+        if (count > 0) {
             return ReturnT.SUCCESS;
         }
-        String sql = String.format("SELECT * FROM loghubods.wecom_cooperation_video_candidate_pool WHERE dt=%s;", dt);
-        List<Record> dataList = OdpsUtil.getOdpsData(sql);
         Long now = System.currentTimeMillis();
+        // 公众号自动回复数据统计
+        String sql = String.format("SELECT 合作方, 公众号id, 访问人数, 首层访问人数, dt " +
+                "FROM loghubods.loghubods.gzh_autoreply_behavior_uv_total WHERE dt=%s;", dt);
+        List<Record> dataList = OdpsUtil.getOdpsData(sql);
+        // 所有公众号
+        List<ContentPlatformGzhAccount> accountList = getAllGzhAccount();
+        Map<String, ContentPlatformGzhAccount> accountMap = accountList.stream()
+                .collect(Collectors.toMap(ContentPlatformGzhAccount::getGhId, account -> account));
+        List<Long> accountIds = accountList.stream().map(ContentPlatformGzhAccount::getId).collect(Collectors.toList());
+        List<String> ghIds = accountList.stream().map(ContentPlatformGzhAccount::getGhId).collect(Collectors.toList());
+        List<String> accountExternalIds = accountList.stream().map(ContentPlatformGzhAccount::getExternalId).collect(Collectors.toList());
+        String dateStr = DateUtil.getBeforeDayDateString("yyyy-MM-dd");
+        List<WxAccountDatastatVO> wxAccountDatastatVOList = aigcApiService.getWxAccountDatastat(dateStr, accountExternalIds);
+        Map<String, WxAccountDatastatVO> wxAccountDatastatMap = wxAccountDatastatVOList.stream()
+                .collect(Collectors.toMap(WxAccountDatastatVO::getAccountId, wxAccountDatastatVO -> wxAccountDatastatVO));
+        List<ContentPlatformGzhPlan> gzhPlanList = planService.getGzhPlanListByCooperateAccountIds(accountIds);
+        List<Long> planIds = gzhPlanList.stream().map(ContentPlatformGzhPlan::getId).collect(Collectors.toList());
+        Map<Long, Long> gzhPlanMap = gzhPlanList.stream()
+               .collect(Collectors.toMap(ContentPlatformGzhPlan::getAccountId, ContentPlatformGzhPlan::getId));
+        List<ContentPlatformGzhPlanVideo> gzhPlanVideoList = planService.getGzhPlanVideoList(planIds);
+        Map<Long, List<ContentPlatformGzhPlanVideo>> gzhPlanVideoMap = gzhPlanVideoList.stream()
+              .collect(Collectors.groupingBy(ContentPlatformGzhPlanVideo::getPlanId));
+        List<Long> videoIds = gzhPlanVideoList.stream().map(ContentPlatformGzhPlanVideo::getVideoId).collect(Collectors.toList());
+        List<ContentPlatformVideo> contentPlatformVideoList = planService.getVideoContentListByVideoIds(videoIds);
+        Map<Long, ContentPlatformVideo> videoMap = contentPlatformVideoList.stream()
+              .collect(Collectors.toMap(ContentPlatformVideo::getId, video -> video));
         if (CollectionUtils.isNotEmpty(dataList)) {
-            List<ContentPlatformVideo> saveList = new ArrayList<>();
+            List<ContentPlatformGzhDataStat> saveList = new ArrayList<>();
             for (Record record : dataList) {
-                ContentPlatformVideo item = new ContentPlatformVideo();
-                Long videoId = Long.parseLong((String) record.get(0));
-                String category = (String) record.get(1);
-                String title = (String) record.get(2);
-                String videoUrl = (String) record.get(3);
-                Double score = Double.parseDouble((String) record.get(4));
-                item.setDt(dt);
-                item.setVideoId(videoId);
-                item.setCategory(category);
-                item.setTitle(title);
-                item.setVideo(videoUrl);
-                item.setScore(score);
+                ContentPlatformGzhDataStat item = new ContentPlatformGzhDataStat();
+                String ghId = (String) record.get(1);
+                Integer firstLevelCount = Integer.valueOf((String) record.get(3));
+                item.setDateStr(dt);
+                if (!ghIds.contains(ghId)) {
+                    continue;
+                }
+                ContentPlatformGzhAccount gzhAccount = accountMap.get(ghId);
+                item.setAccountId(gzhAccount.getId());
+                item.setFirstLevelCount(firstLevelCount);
+                WxAccountDatastatVO wxAccountDatastatVO = wxAccountDatastatMap.get(gzhAccount.getExternalId());
+                if (Objects.nonNull(wxAccountDatastatVO)) {
+                    item.setFansIncreaseCount(wxAccountDatastatVO.getFansIncreaseCount());
+                }
+                List<ContentPlatformGzhPlanVideo> videoList = gzhPlanVideoMap.get(gzhPlanMap.get(gzhAccount.getId()));
+                if (CollectionUtils.isNotEmpty(videoList)) {
+                    List<Long> itemVideoIds = videoList.stream().map(ContentPlatformGzhPlanVideo::getVideoId).collect(Collectors.toList());
+                    Double score = 0.0;
+                    for (Long videoId : itemVideoIds) {
+                        score += videoMap.get(videoId).getScore();
+                    }
+                    item.setScore(score / itemVideoIds.size());
+                }
                 item.setCreateTimestamp(now);
                 saveList.add(item);
             }
             if (CollectionUtils.isNotEmpty(saveList)) {
-                planMapperExt.batchInsertContentPlatformVideo(saveList);
+                dataStatMapperExt.batchInsertGzhDatastat(saveList);
             }
         }
         return ReturnT.SUCCESS;
     }
 
-    private long getVideoCount(String dt) {
-        ContentPlatformVideoExample example = new ContentPlatformVideoExample();
-        example.createCriteria().andDtEqualTo(dt);
-        return videoMapper.countByExample(example);
+    private List<ContentPlatformGzhAccount> getAllGzhAccount() {
+        ContentPlatformGzhAccountExample example = new ContentPlatformGzhAccountExample();
+        example.createCriteria().andStatusEqualTo(1);
+        return gzhAccountMapper.selectByExample(example);
+    }
+
+    private long getGzhDatastatCount(String dt) {
+        ContentPlatformGzhDataStatExample example = new ContentPlatformGzhDataStatExample();
+        example.createCriteria().andDateStrEqualTo(dt);
+        return gzhDataStatMapper.countByExample(example);
+    }
+
+    private long getQwDatastatCount(String dt) {
+        ContentPlatformQwDataStatExample example = new ContentPlatformQwDataStatExample();
+        example.createCriteria().andDateStrEqualTo(dt);
+        return qwDataStatMapper.countByExample(example);
     }
 
     @XxlJob("syncContentPlatformQwDatastatJob")
     public ReturnT<String> syncContentPlatformQwDatastatJob(String param) {
-        String dt = DateUtil.getBeforeDayDateString();
-        long videoCount = getVideoCount(dt);
-        if (videoCount > 0) {
+        String dt = DateUtil.getBeforeDayDateString("yyyyMMdd");
+        long count = getQwDatastatCount(dt);
+        if (count > 0) {
             return ReturnT.SUCCESS;
         }
-        String sql = String.format("SELECT * FROM loghubods.wecom_cooperation_video_candidate_pool WHERE dt=%s;", dt);
-        List<Record> dataList = OdpsUtil.getOdpsData(sql);
+        List<ContentPlatformQwPlan> qwPlanList = getAllQwPlan();
+        if (CollectionUtils.isEmpty(qwPlanList)) {
+            return ReturnT.SUCCESS;
+        }
+        Map<String, Long> rootSourceIdMap = qwPlanList.stream()
+            .collect(Collectors.toMap(ContentPlatformQwPlan::getRootSourceId, ContentPlatformQwPlan::getId));
+        List<Long> planIds = qwPlanList.stream().map(ContentPlatformQwPlan::getId).collect(Collectors.toList());
+        List<ContentPlatformQwPlanVideo> planVideoList = planService.getQwPlanVideoList(planIds);
+        Map<Long, Long> planVideoMap = planVideoList.stream()
+              .collect(Collectors.toMap(ContentPlatformQwPlanVideo::getPlanId, ContentPlatformQwPlanVideo::getVideoId));
+        List<Long> videoIds = planVideoList.stream().map(ContentPlatformQwPlanVideo::getVideoId).collect(Collectors.toList());
+        List<ContentPlatformVideo> videoList = planService.getVideoContentListByVideoIds(videoIds);
+        Map<Long, Double> videoScoreMap = videoList.stream()
+              .collect(Collectors.toMap(ContentPlatformVideo::getId, ContentPlatformVideo::getScore));
+        Map<Long, ContentPlatformVideo> videoMap = videoList.stream()
+               .collect(Collectors.toMap(ContentPlatformVideo::getId, video -> video));
+        List<ContentPlatformQwDataStat> saveList = new ArrayList<>();
+        List<String> rootSourceIds = qwPlanList.stream().map(ContentPlatformQwPlan::getRootSourceId).collect(Collectors.toList());
+        String outSql = String.format("SELECT * FROM loghubods.qw_out_touliu_behavior_detail WHERE dt=%s;", dt);
+        List<Record> outDataList = OdpsUtil.getOdpsData(outSql);
         Long now = System.currentTimeMillis();
-        if (CollectionUtils.isNotEmpty(dataList)) {
-            List<ContentPlatformVideo> saveList = new ArrayList<>();
-            for (Record record : dataList) {
-                ContentPlatformVideo item = new ContentPlatformVideo();
-                Long videoId = Long.parseLong((String) record.get(0));
-                String category = (String) record.get(1);
-                String title = (String) record.get(2);
-                String videoUrl = (String) record.get(3);
-                Double score = Double.parseDouble((String) record.get(4));
-                item.setDt(dt);
-                item.setVideoId(videoId);
-                item.setCategory(category);
-                item.setTitle(title);
-                item.setVideo(videoUrl);
+        if (CollectionUtils.isNotEmpty(outDataList)) {
+            for (Record record : outDataList) {
+                ContentPlatformQwDataStat item = new ContentPlatformQwDataStat();
+                String rootSourceId = (String) record.get(0);
+                if (!rootSourceIds.contains(rootSourceId)) {
+                    continue;
+                }
+                Integer firstLevelCount = Integer.valueOf((String) record.get(8));
+                item.setDateStr(dt);
+                Long planId = rootSourceIdMap.get(rootSourceId);
+                Long videoId = planVideoMap.get(planId);
+                Double score = videoScoreMap.get(videoId);
                 item.setScore(score);
+                item.setRootSourceId(rootSourceId);
+                item.setFirstLevelCount(firstLevelCount);
                 item.setCreateTimestamp(now);
                 saveList.add(item);
             }
-            if (CollectionUtils.isNotEmpty(saveList)) {
-                planMapperExt.batchInsertContentPlatformVideo(saveList);
+        }
+        String out2Sql = String.format("SELECT * FROM loghubods.qw_out2_touliu_behavior_detail WHERE dt=%s;", dt);
+        List<Record> out2DataList = OdpsUtil.getOdpsData(out2Sql);
+        if (CollectionUtils.isNotEmpty(out2DataList)) {
+            for (Record record : out2DataList) {
+                ContentPlatformQwDataStat item = new ContentPlatformQwDataStat();
+                String rootSourceId = (String) record.get(0);
+                if (!rootSourceIds.contains(rootSourceId)) {
+                    continue;
+                }
+                Integer firstLevelCount = Integer.valueOf((String) record.get(8));
+                item.setDateStr(dt);
+                Long planId = rootSourceIdMap.get(rootSourceId);
+                Long videoId = planVideoMap.get(planId);
+                Double score = videoScoreMap.get(videoId);
+                item.setScore(score);
+                item.setRootSourceId(rootSourceId);
+                item.setFirstLevelCount(firstLevelCount);
+                item.setCreateTimestamp(now);
+                saveList.add(item);
             }
         }
+        if (CollectionUtils.isNotEmpty(saveList)) {
+            dataStatMapperExt.batchInsertQwDatastat(saveList);
+        }
         return ReturnT.SUCCESS;
     }
 
+    private List<ContentPlatformQwPlan> getAllQwPlan() {
+        ContentPlatformQwPlanExample example = new ContentPlatformQwPlanExample();
+        return qwPlanMapper.selectByExample(example);
+    }
+
 }

+ 1 - 1
api-module/src/main/java/com/tzld/piaoquan/api/job/ContentPlatformVideoJob.java

@@ -29,7 +29,7 @@ public class ContentPlatformVideoJob {
 
     @XxlJob("syncContentPlatformVideoJob")
     public ReturnT<String> syncContentPlatformVideoJob(String param) {
-        String dt = DateUtil.getBeforeDayDateString();
+        String dt = DateUtil.getBeforeDayDateString("yyyyMMdd");
         long videoCount = getVideoCount(dt);
         if (videoCount > 0) {
             return ReturnT.SUCCESS;

+ 11 - 0
api-module/src/main/java/com/tzld/piaoquan/api/model/vo/WxAccountDatastatVO.java

@@ -0,0 +1,11 @@
+package com.tzld.piaoquan.api.model.vo;
+
+import lombok.Data;
+
+@Data
+public class WxAccountDatastatVO {
+    private String dateStr;
+    private String accountId;
+    private Integer fansCount;
+    private Integer fansIncreaseCount;
+}

+ 17 - 0
api-module/src/main/java/com/tzld/piaoquan/api/remote/AigcApiService.java

@@ -2,6 +2,7 @@ package com.tzld.piaoquan.api.remote;
 
 import com.alibaba.fastjson.JSONObject;
 import com.tzld.piaoquan.api.common.exception.CommonException;
+import com.tzld.piaoquan.api.model.vo.WxAccountDatastatVO;
 import com.tzld.piaoquan.growth.common.component.HttpPoolClient;
 import com.tzld.piaoquan.growth.common.utils.DateUtil;
 import lombok.extern.slf4j.Slf4j;
@@ -9,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 
+import java.util.List;
 import java.util.Objects;
 
 @Slf4j
@@ -200,4 +202,19 @@ public class AigcApiService {
             log.error("refreshGzhAutoReplyMsgData error", e);
         }
     }
+
+    public List<WxAccountDatastatVO> getWxAccountDatastat(String dateStr, List<String> accountIds) {
+        String url = aigcApiHost + "/dataStat/getWxAccountDatastat";
+        JSONObject params = new JSONObject();
+        params.put("dateStr", dateStr);
+        params.put("accountIds", accountIds);
+        try {
+            String post = httpPoolClient.post(url, getAigcPostParam(params));
+            JSONObject res = JSONObject.parseObject(post);
+            return res.getJSONArray("data").toJavaList(WxAccountDatastatVO.class);
+        } catch (Exception e) {
+            log.error("closePublishPlan error", e);
+        }
+        return null;
+    }
 }

+ 7 - 0
api-module/src/main/java/com/tzld/piaoquan/api/service/contentplatform/ContentPlatformPlanService.java

@@ -26,10 +26,17 @@ public interface ContentPlatformPlanService {
 
     List<ContentPlatformGzhPlan> getGzhPlanListByCooperateAccountId(Long accountId);
 
+    List<ContentPlatformGzhPlan> getGzhPlanListByCooperateAccountIds(List<Long> accountIds);
+
     List<ContentPlatformGzhPlanVideo> getGzhPlanVideoListByCooperateAccountId(String ghId);
 
     List<ContentPlatformQwPlan> getQwPlanListByRootSourceIds(List<String> rootSourceIds);
 
     List<ContentPlatformQwPlanVideo> getQwPlanVideoListByPlanIds(List<Long> planIds);
 
+    List<ContentPlatformQwPlanVideo> getQwPlanVideoList(List<Long> planIds);
+
+    List<ContentPlatformVideo> getVideoContentListByVideoIds(List<Long> videoIds);
+
+    List<ContentPlatformGzhPlanVideo> getGzhPlanVideoList(List<Long> planIds);
 }

+ 19 - 3
api-module/src/main/java/com/tzld/piaoquan/api/service/contentplatform/impl/ContentPlatformPlanServiceImpl.java

@@ -134,7 +134,8 @@ public class ContentPlatformPlanServiceImpl implements ContentPlatformPlanServic
         return result;
     }
 
-    private List<ContentPlatformGzhPlanVideo> getGzhPlanVideoList(List<Long> planIds) {
+    @Override
+    public List<ContentPlatformGzhPlanVideo> getGzhPlanVideoList(List<Long> planIds) {
         ContentPlatformGzhPlanVideoExample example = new ContentPlatformGzhPlanVideoExample();
         example.createCriteria().andPlanIdIn(planIds);
         return gzhPlanVideoMapper.selectByExample(example);
@@ -271,6 +272,13 @@ public class ContentPlatformPlanServiceImpl implements ContentPlatformPlanServic
         return gzhPlanMapper.selectByExample(example);
     }
 
+    @Override
+    public List<ContentPlatformGzhPlan> getGzhPlanListByCooperateAccountIds(List<Long> accountIds) {
+        ContentPlatformGzhPlanExample example = new ContentPlatformGzhPlanExample();
+        example.createCriteria().andAccountIdIn(accountIds);
+        return gzhPlanMapper.selectByExample(example);
+    }
+
     @Override
     public Page<VideoContentItemVO> getVideoContentList(VideoContentListParam param) {
         Page<VideoContentItemVO> result = new Page<>(param.getPageNum(), param.getPageSize());
@@ -365,12 +373,20 @@ public class ContentPlatformPlanServiceImpl implements ContentPlatformPlanServic
         return result;
     }
 
-    private List<ContentPlatformQwPlanVideo> getQwPlanVideoList(List<Long> planIds) {
+    @Override
+    public List<ContentPlatformQwPlanVideo> getQwPlanVideoList(List<Long> planIds) {
         ContentPlatformQwPlanVideoExample example = new ContentPlatformQwPlanVideoExample();
         example.createCriteria().andPlanIdIn(planIds);
         return qwPlanVideoMapper.selectByExample(example);
     }
 
+    @Override
+    public List<ContentPlatformVideo> getVideoContentListByVideoIds(List<Long> videoIds) {
+        ContentPlatformVideoExample example = new ContentPlatformVideoExample();
+        example.createCriteria().andVideoIdIn(videoIds);
+        return contentPlatformVideoMapper.selectByExample(example);
+    }
+
     @Override
     public void qwPlanSave(QwPlanSaveParam param) {
         ContentPlatformAccount loginUser = LoginUserContext.getUser();
@@ -380,7 +396,7 @@ public class ContentPlatformPlanServiceImpl implements ContentPlatformPlanServic
             qwPlan.setType(param.getType());
             qwPlan.setScene(videoParam.getScene());
             String pageUrl = messageAttachmentService.getPage(loginUser.getChannel(), "wxbdd2a2e93d9a6e25",
-                    "dyyjs", "企微", "社群", "位置X", videoParam.getVideoId());
+                    "dyyqw", "企微", "社群", "位置X", videoParam.getVideoId());
             String rootSourceId = MessageUtil.getRootSourceId(pageUrl);
             qwPlan.setPageUrl(pageUrl);
             qwPlan.setRootSourceId(rootSourceId);

+ 140 - 120
api-module/src/main/resources/mapper/contentplatform/ext/ContentPlatformDataStatMapperExt.xml

@@ -2,126 +2,146 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.tzld.piaoquan.api.dao.mapper.contentplatform.ext.ContentPlatformDataStatMapperExt">
 
-  <select id="getGzhAccountDatastatCount" resultType="java.lang.Integer">
-    select count(1)
-    from content_platform_gzh_datastat cpgd
-    join content_platform_gzh_account cpgza on cpgd.account_id = cpgza.id
-    where cpgza.create_account_id = #{createAccountId}
-    <if test="param.accountId!= null and param.accountId!= ''">
-      and cpgza.account_id = #{param.accountId}
-    </if>
-  </select>
-
-  <select id="getGzhAccountDatastatList"
-          resultType="com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformGzhDataStat">
-    select cpgd.*
-    from content_platform_gzh_datastat cpgd
-    join content_platform_gzh_account cpgza on cpgd.account_id = cpgza.id
-    where cpgza.create_account_id = #{createAccountId}
-    <if test="param.accountId!= null and param.accountId!= ''">
-      and cpgza.account_id = #{param.accountId}
-    </if>
-    order by cpgd.date_str desc
-    limit #{offset}, #{pageSize}
-  </select>
-
-  <select id="getGzhTotalDatastatCount" resultType="java.lang.Integer">
-    select count(1)
-    from content_platform_gzh_datastat cpgd
-    join content_platform_gzh_account cpgza on cpgd.account_id = cpgza.id
-    where cpgza.create_account_id = #{createAccountId}
-    group by cpgd.date_str
-  </select>
-
-  <select id="getGzhTotalDatastatList"
-          resultType="com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformGzhDataStat">
-    select date_str, sum(fans_increase_count) as fans_increase_count, sum(first_level_count) as first_level_count,
-           avg(score) as score
-    from content_platform_gzh_datastat cpgd
-    join content_platform_gzh_account cpgza on cpgd.account_id = cpgza.id
-    where cpgza.create_account_id = #{createAccountId}
-    group by cpgd.date_str
-    order by cpgd.date_str desc
-    limit #{offset}, #{pageSize}
-  </select>
-
-  <select id="getQwRootSourceIdDatastatCount" resultType="java.lang.Integer">
-    select count(1)
-    from content_platform_qw_datastat cpqd
-    join content_platform_qw_plan cpqp on cpqp.root_source_id = cpqd.root_source_id
-    where cpqp.create_account_id = #{createAccountId}
-  </select>
-
-  <select id="getQwRootSourceIdDatastatList"
-          resultType="com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformQwDataStat">
-    select cpqd.*
-    from content_platform_qw_datastat cpqd
-    join content_platform_qw_plan cpqp on cpqp.root_source_id = cpqd.root_source_id
-    where cpqp.create_account_id = #{createAccountId}
-    order by cpqd.date_str desc
-    limit #{offset}, #{pageSize}
-  </select>
-
-  <select id="getQwTotalDatastatCount" resultType="java.lang.Integer">
-    select count(1)
-    from content_platform_qw_datastat cpqd
-     join content_platform_qw_plan cpqp on cpqp.root_source_id = cpqd.root_source_id
-    where cpqp.create_account_id = #{createAccountId}
-    group by cpqd.date_str
-  </select>
-
-  <select id="getQwTotalDatastatList"
-          resultType="com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformQwDataStat">
-    select cpqd.date_str, sum(cpqd.first_level_count) as first_level_count, avg(cpqd.score) as score
-    from content_platform_qw_datastat cpqd
-           join content_platform_qw_plan cpqp on cpqp.root_source_id = cpqd.root_source_id
-    where cpqp.create_account_id = #{createAccountId}
-    group by cpqd.date_str
-    order by cpqd.date_str desc
-    limit #{offset}, #{pageSize}
-  </select>
-
-  <select id="getQwSceneDatastatCount" resultType="java.lang.Integer">
-    select count(1)
-    from content_platform_qw_datastat cpqd
-     join content_platform_qw_plan cpqp on cpqp.root_source_id = cpqd.root_source_id
-    where cpqp.create_account_id = #{createAccountId}
-      and cpqp.scene = #{scene}
-    group by cpqd.date_str
-  </select>
-
-  <select id="getQwSceneDatastatList"
-          resultType="com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformQwDataStat">
-    select cpqd.date_str, sum(cpqd.first_level_count) as first_level_count, avg(cpqd.score) as score
-    from content_platform_qw_datastat cpqd
-     join content_platform_qw_plan cpqp on cpqp.root_source_id = cpqd.root_source_id
-    where cpqp.create_account_id = #{createAccountId}
-      and cpqp.scene = #{scene}
-    group by cpqd.date_str
-    order by cpqd.date_str desc
-    limit #{offset}, #{pageSize}
-  </select>
-
-  <select id="getQwReplyDatastatCount" resultType="java.lang.Integer">
-    select count(1)
-    from content_platform_qw_datastat cpqd
-     join content_platform_qw_plan cpqp on cpqp.root_source_id = cpqd.root_source_id
-    where cpqp.create_account_id = #{createAccountId}
-      and cpqp.type = 0
-    group by cpqd.date_str
-  </select>
-
-  <select id="getReplyDatastatList"
-          resultType="com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformQwDataStat">
-    select cpqd.date_str, sum(cpqd.first_level_count) as first_level_count, avg(cpqd.score) as score
-    from content_platform_qw_datastat cpqd
-     join content_platform_qw_plan cpqp on cpqp.root_source_id = cpqd.root_source_id
-    where cpqp.create_account_id = #{createAccountId}
-      and cpqp.type = 0
-    group by cpqd.date_str
-    order by cpqd.date_str desc
-    limit #{offset}, #{pageSize}
-  </select>
+    <select id="getGzhAccountDatastatCount" resultType="java.lang.Integer">
+        select count(1)
+        from content_platform_gzh_datastat cpgd
+        join content_platform_gzh_account cpgza on cpgd.account_id = cpgza.id
+        where cpgza.create_account_id = #{createAccountId}
+        <if test="param.accountId!= null and param.accountId!= ''">
+            and cpgza.account_id = #{param.accountId}
+        </if>
+    </select>
+
+    <select id="getGzhAccountDatastatList"
+            resultType="com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformGzhDataStat">
+        select cpgd.*
+        from content_platform_gzh_datastat cpgd
+        join content_platform_gzh_account cpgza on cpgd.account_id = cpgza.id
+        where cpgza.create_account_id = #{createAccountId}
+        <if test="param.accountId!= null and param.accountId!= ''">
+            and cpgza.account_id = #{param.accountId}
+        </if>
+        order by cpgd.date_str desc
+        limit #{offset}, #{pageSize}
+    </select>
+
+    <select id="getGzhTotalDatastatCount" resultType="java.lang.Integer">
+        select count(1)
+        from content_platform_gzh_datastat cpgd
+                 join content_platform_gzh_account cpgza on cpgd.account_id = cpgza.id
+        where cpgza.create_account_id = #{createAccountId}
+        group by cpgd.date_str
+    </select>
+
+    <select id="getGzhTotalDatastatList"
+            resultType="com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformGzhDataStat">
+        select date_str,
+               sum(fans_increase_count) as fans_increase_count,
+               sum(first_level_count)   as first_level_count,
+               avg(score)               as score
+        from content_platform_gzh_datastat cpgd
+                 join content_platform_gzh_account cpgza on cpgd.account_id = cpgza.id
+        where cpgza.create_account_id = #{createAccountId}
+        group by cpgd.date_str
+        order by cpgd.date_str desc
+        limit #{offset}, #{pageSize}
+    </select>
+
+    <select id="getQwRootSourceIdDatastatCount" resultType="java.lang.Integer">
+        select count(1)
+        from content_platform_qw_datastat cpqd
+                 join content_platform_qw_plan cpqp on cpqp.root_source_id = cpqd.root_source_id
+        where cpqp.create_account_id = #{createAccountId}
+    </select>
+
+    <select id="getQwRootSourceIdDatastatList"
+            resultType="com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformQwDataStat">
+        select cpqd.*
+        from content_platform_qw_datastat cpqd
+                 join content_platform_qw_plan cpqp on cpqp.root_source_id = cpqd.root_source_id
+        where cpqp.create_account_id = #{createAccountId}
+        order by cpqd.date_str desc
+        limit #{offset}, #{pageSize}
+    </select>
+
+    <select id="getQwTotalDatastatCount" resultType="java.lang.Integer">
+        select count(1)
+        from content_platform_qw_datastat cpqd
+                 join content_platform_qw_plan cpqp on cpqp.root_source_id = cpqd.root_source_id
+        where cpqp.create_account_id = #{createAccountId}
+        group by cpqd.date_str
+    </select>
+
+    <select id="getQwTotalDatastatList"
+            resultType="com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformQwDataStat">
+        select cpqd.date_str, sum(cpqd.first_level_count) as first_level_count, avg(cpqd.score) as score
+        from content_platform_qw_datastat cpqd
+                 join content_platform_qw_plan cpqp on cpqp.root_source_id = cpqd.root_source_id
+        where cpqp.create_account_id = #{createAccountId}
+        group by cpqd.date_str
+        order by cpqd.date_str desc
+        limit #{offset}, #{pageSize}
+    </select>
+
+    <select id="getQwSceneDatastatCount" resultType="java.lang.Integer">
+        select count(1)
+        from content_platform_qw_datastat cpqd
+                 join content_platform_qw_plan cpqp on cpqp.root_source_id = cpqd.root_source_id
+        where cpqp.create_account_id = #{createAccountId}
+          and cpqp.scene = #{scene}
+        group by cpqd.date_str
+    </select>
+
+    <select id="getQwSceneDatastatList"
+            resultType="com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformQwDataStat">
+        select cpqd.date_str, sum(cpqd.first_level_count) as first_level_count, avg(cpqd.score) as score
+        from content_platform_qw_datastat cpqd
+                 join content_platform_qw_plan cpqp on cpqp.root_source_id = cpqd.root_source_id
+        where cpqp.create_account_id = #{createAccountId}
+          and cpqp.scene = #{scene}
+        group by cpqd.date_str
+        order by cpqd.date_str desc
+        limit #{offset}, #{pageSize}
+    </select>
+
+    <select id="getQwReplyDatastatCount" resultType="java.lang.Integer">
+        select count(1)
+        from content_platform_qw_datastat cpqd
+                 join content_platform_qw_plan cpqp on cpqp.root_source_id = cpqd.root_source_id
+        where cpqp.create_account_id = #{createAccountId}
+          and cpqp.type = 0
+        group by cpqd.date_str
+    </select>
+
+    <select id="getReplyDatastatList"
+            resultType="com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformQwDataStat">
+        select cpqd.date_str, sum(cpqd.first_level_count) as first_level_count, avg(cpqd.score) as score
+        from content_platform_qw_datastat cpqd
+                 join content_platform_qw_plan cpqp on cpqp.root_source_id = cpqd.root_source_id
+        where cpqp.create_account_id = #{createAccountId}
+          and cpqp.type = 0
+        group by cpqd.date_str
+        order by cpqd.date_str desc
+        limit #{offset}, #{pageSize}
+    </select>
+
+    <insert id="batchInsertGzhDatastat">
+        insert into content_platform_gzh_datastat (date_str, account_id, fans_increase_count, first_level_count, score,
+        create_timestamp)
+        values
+        <foreach collection="records" item="item" separator=",">
+            (#{item.dateStr}, #{item.accountId}, #{item.fansIncreaseCount}, #{item.firstLevelCount}, #{item.score},
+            #{item.createTimestamp})
+        </foreach>
+    </insert>
+
+    <insert id="batchInsertQwDatastat">
+        insert into content_platform_qw_datastat (date_str, root_source_id, first_level_count, score, create_timestamp)
+        values
+        <foreach collection="records" item="item" separator=",">
+            (#{item.dateStr}, #{item.rootSourceId}, #{item.firstLevelCount}, #{item.score}, #{item.createTimestamp})
+        </foreach>
+    </insert>
 
 
 </mapper>

+ 2 - 2
common-module/src/main/java/com/tzld/piaoquan/growth/common/utils/DateUtil.java

@@ -40,8 +40,8 @@ public class DateUtil {
         return calendar.getTime();
     }
 
-    public static String getBeforeDayDateString() {
-        DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyyMMdd");
+    public static String getBeforeDayDateString(String format) {
+        DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern(format);
         LocalDate today = LocalDate.now();
         LocalDate yesterday = today.minusDays(1);
         return dateFormat.format(yesterday);

+ 2 - 2
offline-module/src/main/java/com/tzld/piaoquan/offline/job/WeComMessageDataJob.java

@@ -88,7 +88,7 @@ public class WeComMessageDataJob {
         try {
             //历史优质视频获取分页获取
             String countSql = String.format("SELECT count(*) FROM loghubods.history_good_video_can_push_user_list where dt = %s;",
-                    DateUtil.getBeforeDayDateString());
+                    DateUtil.getBeforeDayDateString("yyyyMMdd"));
             List<Record> countData = OdpsUtil.getOdpsData(countSql);
             int size = 10;
             if (!CollectionUtils.isEmpty(countData)) {
@@ -97,7 +97,7 @@ public class WeComMessageDataJob {
                     List<Record> dataList = new ArrayList<>();
                     for (int i = 0; i < count; i += 10) {
                         String sql = String.format("SELECT * FROM loghubods.history_good_video_can_push_user_list where dt = %s order by score desc limit %s,%s;",
-                                DateUtil.getBeforeDayDateString(), i, size);
+                                DateUtil.getBeforeDayDateString("yyyyMMdd"), i, size);
                         List<Record> data = OdpsUtil.getOdpsData(sql);
                         if (!CollectionUtils.isEmpty(data)) {
                             dataList.addAll(data);