Ver Fonte

修改头条快手爆款视频计算逻辑

songyh há 4 anos atrás
pai
commit
709ac558f4

+ 12 - 27
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/BytedanceCustomerDdTbtjDataController.java

@@ -1,49 +1,33 @@
 package org.jeecg.modules.ctop.controller;
 
-import java.io.FileInputStream;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
 import cn.com.ctop.common.module.annotation.AutoLog;
 import cn.com.ctop.common.module.utils.QueryGenerator;
 import com.alibaba.excel.event.AnalysisEventListener;
-import org.jeecg.common.api.vo.Result;
-import org.jeecg.common.util.oConvertUtils;
-import java.util.Date;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
-
+import org.jeecg.common.api.vo.Result;
 import org.jeecg.modules.ctop.entity.BytedanceCustomerDdTbtjData;
 import org.jeecg.modules.ctop.service.IBytedanceCustomerDdTbtjDataService;
 import org.jeecg.modules.excelutil.BytedanceCustomTbtjDataExcelListener;
 import org.jeecg.modules.excelutil.ExcelUtils;
-import org.jeecg.modules.excelutil.JhsBakendDataExcelListener;
 import org.jeecg.modules.excelutil.entity.BytedanceCustomTbtjDataEntity;
-import org.jeecg.modules.excelutil.entity.JhsBakendDataEntity;
-import org.jeecgframework.poi.excel.ExcelImportUtil;
-import org.jeecgframework.poi.excel.def.NormalExcelConstants;
-import org.jeecgframework.poi.excel.entity.ExportParams;
-import org.jeecgframework.poi.excel.entity.ImportParams;
-import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
-
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.multipart.MultipartHttpServletRequest;
-import org.springframework.web.servlet.ModelAndView;
-import com.alibaba.fastjson.JSON;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
 
- /**
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Map;
+
+/**
  * 淘宝特价版客户反馈数据
  * @author jeecg-boot
  * @date   2021-04-22
@@ -73,6 +57,7 @@ public class BytedanceCustomerDdTbtjDataController {
 																	HttpServletRequest req) {
 		Result<IPage<BytedanceCustomerDdTbtjData>> result = new Result<>();
 		QueryWrapper<BytedanceCustomerDdTbtjData> queryWrapper = QueryGenerator.initQueryWrapper(bytedanceCustomerDdTbtjData, req.getParameterMap());
+		queryWrapper.orderByDesc("state_date");
 		Page<BytedanceCustomerDdTbtjData> page = new Page<BytedanceCustomerDdTbtjData>(pageNo, pageSize);
 		IPage<BytedanceCustomerDdTbtjData> pageList = bytedanceCustomerDdTbtjDataService.page(page, queryWrapper);
 		result.setSuccess(true);

+ 16 - 3
jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java

@@ -102,15 +102,28 @@ public class SampleTest {
     @Test
     public void loadBytedanceVideoReportData() {
         String startDate = "2021-04-01";
-        String endDate = "2021-04-16";
+        String endDate = "2021-04-26";
         List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
-        for (CtopOauthToken token : tokens) {
+        Long start = System.currentTimeMillis();
+
+        tokens.forEach(token->{
             bytedanceReportService.bytedanceVideoMaterialReport(token, startDate, endDate);
-        }
+        });
+        Long end = System.currentTimeMillis();
+        log.info("查询素材消耗用时:{}毫秒", end - start);
     }
 
     @Autowired
     private IWechatNoListService wechatNoListService;
+    @Autowired
+    private IETLReportBytedanceVideoService bytedanceVideoService;
+    @Test
+    public void etlBytedanceVideoInfo(){
+        String startDate = "2021-02-01";
+        for(int i=0;i<100;i++){
+            bytedanceVideoService.cleanData(DateUtils.addDay(startDate,i));
+        }
+    }
 
     @Test
     public void getData() {

+ 14 - 0
module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/KuaishouDailyAccountReportLoadJob.java

@@ -43,6 +43,20 @@ public class KuaishouDailyAccountReportLoadJob {
         }));
     }
 
+    @XxlJob("kuaishouCurrentDailyAccountReport")
+    public void kuaishouCurrentDailyAccountReport() throws Exception {
+        Date getDate = DateUtils.addDay(new Date(), -1);
+        //1:查询当日数据
+        List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
+        if (null == tokens || tokens.isEmpty()) {
+            XxlJobHelper.log("定时获取快手数据异常:未获取到可用的token");
+            XxlJobHelper.handleFail();
+            return;
+        }
+        tokens.forEach(token -> executorService.submit(() -> {
+            kuaishouInterfaceService.getAdvertiserReportDaily(token, getDate, getDate, null);
+        }));
+    }
 
     @XxlJob("kuaishouDailyAccountAdSceneReport")
     public void kuaishouDailyAccountAdSceneReport() throws Exception {

+ 4 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/link/mapper/ETLReportBytedanceVideoMapper.java

@@ -30,4 +30,8 @@ public interface ETLReportBytedanceVideoMapper extends BaseMapper<ETLReportByted
     List<ETLReportBytedanceVideo> queryETLData(@Param("statDate") String statDate);
 
     void insertBatch(@Param("records") List<ETLReportBytedanceVideo>records);
+
+    List<ETLReportBytedanceVideo> getDuplicateVideoInfo(@Param("date")String date);
+
+    void deleteDuplicateVideoInfo(@Param("video")ETLReportBytedanceVideo video);
 }

+ 13 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/link/mapper/xml/ETLReportBytedanceVideoMapper.xml

@@ -201,6 +201,13 @@
             )
         </foreach>
     </insert>
+    <delete id="deleteDuplicateVideoInfo">
+        delete from
+                    etl_report_bytedance_video
+        where material_id = #{video.materialId}
+          and stat_datetime = #{video.statDatetime}
+          and account_id = #{video.accountId} and id!=#{video.id};
+    </delete>
     <select id="queryVideoInfoByMaterialId"  resultType="com.alibaba.fastjson.JSONObject">
         SELECT
             signature AS md5,
@@ -306,4 +313,10 @@
                 LEFT JOIN (SELECT account_id, advertiser_id,project_id,auth_name from ctop_user_allocation where account_id in (SELECT DISTINCT account_id from base_report_bytedance_video_daily where stat_datetime=#{statDate})) t5 on t1.account_id=t5.account_id
         GROUP BY t1.id
     </select>
+    <select id="getDuplicateVideoInfo"
+            resultType="cn.com.ctop.toutiao.modules.link.entity.ETLReportBytedanceVideo">
+        select material_id,stat_datetime,account_id,id,count(1) as total
+        from etl_report_bytedance_video where stat_datetime =#{date} and cost>0 GROUP BY stat_datetime,material_id,account_id
+        HAVING total >1 ORDER BY total DESC;
+    </select>
 </mapper>

+ 2 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/link/service/IETLReportBytedanceVideoService.java

@@ -14,4 +14,6 @@ public interface IETLReportBytedanceVideoService extends IService<ETLReportByted
     List<BaseReportBytedanceVideoDaily> listByStatDate(String statDate);
 
     void cleanETL(String statDate);
+
+    void cleanData(String data);
 }

+ 11 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/link/service/impl/ETLReportBytedanceVideoServiceImpl.java

@@ -5,6 +5,7 @@ import cn.com.ctop.toutiao.modules.link.entity.ETLReportBytedanceVideo;
 import cn.com.ctop.toutiao.modules.link.mapper.ETLReportBytedanceVideoMapper;
 import cn.com.ctop.toutiao.modules.link.service.IBaseReportBytedanceVideoDailyService;
 import cn.com.ctop.toutiao.modules.link.service.IETLReportBytedanceVideoService;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.extern.slf4j.Slf4j;
@@ -101,4 +102,14 @@ public class ETLReportBytedanceVideoServiceImpl extends ServiceImpl<ETLReportByt
         }
     }
 
+    @Override
+    public void cleanData(String date){
+        List<ETLReportBytedanceVideo> videos = etlReportBytedanceVideoMapper.getDuplicateVideoInfo(date);
+        if(null!=videos&&!videos.isEmpty()){
+            videos.forEach(video->{
+                etlReportBytedanceVideoMapper.deleteDuplicateVideoInfo(video);
+            });
+        }
+    }
+
 }