Преглед на файлове

添加 MaterialReportAccountUpdateJob

jiequan.bi преди 5 години
родител
ревизия
fb9ad9ead9

+ 37 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/job/MaterialReportAccountUpdateJob.java

@@ -0,0 +1,37 @@
+package org.jeecg.modules.ctop.job;
+
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.constant.SystemDateConstant;
+import org.jeecg.common.util.DateUtils;
+import org.jeecg.modules.ctop.service.IMaterialTopService;
+import org.quartz.Job;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ *  Created by JQ.bi on 2020.5.25
+ *  定时更新素材报表的 快手头条整合数据
+ */
+@Slf4j
+public class MaterialReportAccountUpdateJob implements Job {
+
+    @Autowired
+    IMaterialTopService materialTopService;
+
+    @Override
+    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
+
+        log.info("MaterialReportAccountUpdateJob is start");
+
+        boolean result=materialTopService.insertMaterialReportAccount(DateUtils.getAnotherDay(SystemDateConstant.yyyy_MM_dd,
+                DateUtils.getNowDate(SystemDateConstant.yyyy_MM_dd), -1));
+
+        if(!result){
+            log.error("MaterialReportAccountUpdateJob is error");
+        } else {
+            log.info("MaterialReportAccountUpdateJob is done");
+        }
+    }
+
+}

+ 8 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/mapper/MaterialTopMapper.java

@@ -8,5 +8,13 @@ import org.apache.ibatis.annotations.Param;
 import org.jeecg.modules.ctop.vo.MaterialTopVO;
 
 public interface MaterialTopMapper {
+
     IPage<MaterialTopVO> selectMapsPage(Page<MaterialTopVO> page, @Param(Constants.WRAPPER)QueryWrapper<MaterialTopVO> wrapper);
+
+    int insertByteDanceMaterialReportAccountByDate(@Param("statDate") String statDate);
+
+    int insertKuaiShouMaterialReportAccountByDate(@Param("statDate") String statDate);
+
+    int deletedMaterialReportAccountByDate(@Param("statDate") String statDate);
+
 }

+ 199 - 19
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/mapper/xml/MaterialTopMapper.xml

@@ -2,26 +2,206 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="org.jeecg.modules.ctop.mapper.MaterialTopMapper">
     <select id="selectMapsPage" resultType="org.jeecg.modules.ctop.vo.MaterialTopVO">
-        SELECT
-        url,
-        name,
-        stat_date ,
-        sum(cost) as cost,
-        sum(click) as click,
-        sum(show_num) as show_num,
-        sum(active) as active,
-        sum(register) as register,
-        sum(pay) as pay,
-        sum(phone_convert) as phone_convert,
-        sum(form_convert) as form_convert,
-        convert_rate,
-        sum(residue) as residue,
-        sum(play3s) as play3s,
-        sum(play10s) as play10s
-        FROM
-        ctop_material_report_total_result
-        where
+       SELECT
+          url,
+          name,
+          stat_date ,
+          sum(cost) as cost,
+          sum(click) as click,
+          sum(show_num) as show_num,
+          sum(active) as active,
+          sum(register) as register,
+          sum(pay) as pay,
+          sum(phone_convert) as phone_convert,
+          sum(form_convert) as form_convert,
+          convert_rate,
+          sum(residue) as residue,
+          sum(play3s) as play3s,
+          sum(play10s) as play10s
+       FROM
+          ctop_material_report_total_result
+       where
         ${ew.sqlSegment}
     </select>
 
+    <insert id="insertByteDanceMaterialReportAccountByDate">
+        INSERT INTO ctop_material_report_total_result (
+            CODE,
+            url,
+            NAME,
+            stat_date,
+            cost,
+            click,
+            show_num,
+            active,
+            register,
+            pay,
+            phone_convert,
+            form_convert,
+            residue,
+            play3s,
+            play10s,
+            media_type
+        ) SELECT
+              t2.signature,
+              CASE
+                  WHEN (
+                      SELECT
+                          info.url
+                      FROM
+                          ctop_material_info info
+                      WHERE
+                          info. CODE = t2.signature
+                      ORDER BY
+                          create_time DESC
+                      LIMIT 1
+                  ) IS NULL THEN
+                      ""
+                  ELSE
+                      (
+                          SELECT
+                              info.url
+                          FROM
+                              ctop_material_info info
+                          WHERE
+                              info. CODE = t2.signature
+                          ORDER BY
+                              create_time DESC
+                          LIMIT 1
+                      )
+                  END AS url,
+              CASE
+                  WHEN (
+                      SELECT
+                          info.material_name
+                      FROM
+                          ctop_material_info info
+                      WHERE
+                          info. CODE = t2.signature
+                      ORDER BY
+                          create_time DESC
+                      LIMIT 1
+                  ) IS NULL THEN
+                      ""
+                  ELSE
+                      (
+                          SELECT
+                              info.material_name
+                          FROM
+                              ctop_material_info info
+                          WHERE
+                              info. CODE = t2.signature
+                          ORDER BY
+                              create_time DESC
+                          LIMIT 1
+                      )
+                  END AS NAME,
+              t1.stat_datetime AS statDate,
+              sum(t1.cost) AS cost,
+              sum(t1.click) click,
+              0 AS showNum,
+              sum(t1.active) AS active,
+              sum(t1.register) AS register,
+              sum(t1.pay_count) AS pay,
+              sum(t1.phone_confirm) AS phoneConvert,
+              sum(t1.form) AS formConvert,
+              sum(t1.next_day_open) AS residue,
+              sum(t1.play_duration_3s) AS play3s,
+              sum(t1.play_duration_10s) AS play3s,
+              0 AS mediaType
+        FROM
+            ctop_bytedance_report_material_daily t1
+                LEFT JOIN ctop_bytedance_video_info t2 ON t1.material_id = t2.material_id
+        WHERE
+            1 = 1
+          AND t1.stat_datetime = #{statDate}
+          AND t1.image_mode != 'MATERIAL_IMAGE_MODE_TITLE'
+          AND t2.signature IS NOT NULL
+          AND t2.signature != ""
+        GROUP BY
+            t2.signature,
+            t1.stat_datetime;
+    </insert>
+
+    <insert id ="insertKuaiShouMaterialReportAccountByDate">
+        INSERT INTO ctop_material_report_total_result (
+            CODE,
+            url,
+            NAME,
+            stat_date,
+            cost,
+            click,
+            show_num,
+            active,
+            register,
+            form_convert,
+            media_type
+        ) SELECT
+              t1.signature AS 'code',
+              CASE
+                  WHEN (
+                      SELECT
+                          url
+                      FROM
+                          ctop_material_info
+                      WHERE
+                          `code` = t1.signature
+                      LIMIT 1
+                  ) IS NULL THEN
+                      ""
+                  ELSE
+                      (
+                          SELECT
+                              url
+                          FROM
+                              ctop_material_info
+                          WHERE
+                              `code` = t1.signature
+                          LIMIT 1
+                      )
+                  END AS 'url',
+              CASE
+                  WHEN (
+                      SELECT
+                          material_name
+                      FROM
+                          ctop_material_info
+                      WHERE
+                          `code` = t1.signature
+                      LIMIT 1
+                  ) IS NULL THEN
+                      ""
+                  ELSE
+                      (
+                          SELECT
+                              material_name
+                          FROM
+                              ctop_material_info
+                          WHERE
+                              `code` = t1.signature
+                          LIMIT 1
+                      )
+                  END AS 'name',
+              t1.stat_date AS 'stat_date',
+              sum(t1.charge) AS 'cost',
+              sum(t1.photo_click) AS 'click',
+              sum(t1.photo_show) AS 'show_num',
+              sum(t1.activation) AS 'active',
+              sum(t1.event_register) AS 'register',
+              sum(t1.form_count) AS 'form_convert',
+              '2' AS 'media_type'
+        FROM
+            ctop_kuaishou_report_daily_creative t1
+        WHERE
+            t1.signature IS NOT NULL
+          AND t1.stat_date = #{statDate}
+        GROUP BY
+            t1.stat_date,
+            t1.signature;
+    </insert>
+
+    <delete id="deletedMaterialReportAccountByDate">
+        DELETE FROM ctop_material_report_total_result where stat_date= #{statDate}
+    </delete>
+
 </mapper>

+ 1 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/IMaterialTopService.java

@@ -5,4 +5,5 @@ import org.jeecg.modules.ctop.vo.MaterialTopVO;
 
 public interface IMaterialTopService {
     IPage<MaterialTopVO> selectByPage(String endDate, String startDate, String target, String order, int pageNo, int pageSize);
+    boolean insertMaterialReportAccount(String statDate);
 }

+ 19 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/MaterialTopServiceImpl.java

@@ -5,6 +5,7 @@ import cn.com.ctop.common.module.utils.StringUtils;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import lombok.extern.slf4j.Slf4j;
 import org.jeecg.modules.ctop.mapper.MaterialTopMapper;
 import org.jeecg.modules.ctop.service.IMaterialTopService;
 import org.jeecg.modules.ctop.vo.MaterialTopVO;
@@ -14,11 +15,13 @@ import org.springframework.stereotype.Service;
 /**
  *  Created by JQ.bi on 2020.05.22
  */
+@Slf4j
 @Service
 public class MaterialTopServiceImpl  implements IMaterialTopService {
 
     @Autowired
     MaterialTopMapper materialTopMapper;
+
     @Override
     public IPage<MaterialTopVO> selectByPage(String endDate, String startDate, String target, String order, int pageNo, int pageSize) {
         QueryWrapper<MaterialTopVO> wrapper = new QueryWrapper();
@@ -35,4 +38,20 @@ public class MaterialTopServiceImpl  implements IMaterialTopService {
         return mapIPage;
     }
 
+    @Override
+    public boolean insertMaterialReportAccount(String statDate) {
+
+        int resultByteDance=materialTopMapper.insertByteDanceMaterialReportAccountByDate(statDate);
+        int resultKuaishou=materialTopMapper.insertKuaiShouMaterialReportAccountByDate(statDate);
+
+        if(resultByteDance == 0 || resultKuaishou == 0){
+            log.error("整合素材报表信息失败");
+            log.info("delete dirty data is start");
+            materialTopMapper.deletedMaterialReportAccountByDate(statDate);
+            log.info("delete dirty data is success");
+        }
+
+        return resultByteDance != 0 && resultKuaishou != 0;
+    }
+
 }