Bladeren bron

短剧修改 + 导出

yumeng 8 maanden geleden
bovenliggende
commit
fcd715fd0d

+ 7 - 6
jeecg-boot-finance/src/main/resources/application-dev.yml

@@ -106,12 +106,13 @@ spring:
         connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
       datasource:
         master:
-          url: jdbc:mysql://139.186.165.84:3306/jeecg-boot?characterEncoding=UTF-8&useUnicode=true&characterEncoding=utf8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
-          username: hcst
-          password: hcst@2020
-          #url: jdbc:mysql://139.186.27.96:3390/jeecg-boot?characterEncoding=UTF-8&useUnicode=true&characterEncoding=utf8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
-          #username: data
-          #password: hcst@2021
+
+          #url: jdbc:mysql://139.186.165.84:3306/jeecg-boot?characterEncoding=UTF-8&useUnicode=true&characterEncoding=utf8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
+          #username: hcst
+          #password: hcst@2020
+          url: jdbc:mysql://139.186.27.96:3390/jeecg-boot?characterEncoding=UTF-8&useUnicode=true&characterEncoding=utf8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
+          username: data
+          password: hcst@2021
           driver-class-name: com.mysql.jdbc.Driver
           # 多数据源配置
         multi-datasource1:

+ 88 - 5
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/controller/DuanJUReportController.java

@@ -1,21 +1,24 @@
 package cn.com.ctop.kuaishou.modules.report.controller;
 
-import cn.com.ctop.common.module.utils.Check;
-import cn.com.ctop.common.module.utils.HttpUtils;
-import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
-import cn.com.ctop.common.module.utils.PropertiesUtils;
+import cn.com.ctop.common.module.utils.*;
 import cn.com.ctop.kuaishou.modules.report.service.IDuanJUReportService;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import io.swagger.annotations.Api;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.util.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -93,14 +96,78 @@ public class DuanJUReportController {
     }
 
     @GetMapping("/getViodeoList")
-    public Result<Object> getViodeoList(String startDate, String endDate) {
+    public Result<Object> getViodeoList(String startDate, String endDate, String videoName) {
         try {
             Long start = DateUtils.dateToLong(startDate);
             Long end = DateUtils.dateToLong(endDate);
             Map<String, Object> requestMap = new HashMap<>();
             requestMap.put("start", start);
             requestMap.put("end", end);
+            if (!Check.isNull(videoName)) {
+                requestMap.put("videoName", videoName);
+            }
+            List<JSONObject> data = duanJUReportService.getViodeoList(requestMap);
+            return Result.OK(data);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return Result.error("查询失败");
+    }
+
+    @GetMapping("/exportVideoList")
+    public Result<Object> exportVideoList(String startDate, String endDate, String videoName,
+                                          HttpServletRequest request, HttpServletResponse response) {
+        try {
+            Long start = DateUtils.dateToLong(startDate);
+            Long end = DateUtils.dateToLong(endDate);
+            Map<String, Object> requestMap = new HashMap<>();
+            requestMap.put("start", start);
+            requestMap.put("end", end);
+            if (!Check.isNull(videoName)) {
+                requestMap.put("videoName", videoName);
+            }
             List<JSONObject> data = duanJUReportService.getViodeoList(requestMap);
+            List<List<Object>> exportList = new ArrayList<>();
+            if (!Check.isNull(data)) {
+                for (int i = 0; i < data.size(); i++) {
+                    JSONObject date = data.get(i);
+                    List<Object> export = new ArrayList();
+                    export.add(date.getString("photo_id"));
+                    export.add(date.getString("photo_name"));
+                    export.add(date.getString("cover_url"));
+                    export.add(date.getString("photo_url"));
+                    export.add(date.getString("charge"));
+                    export.add(date.getString("roi"));
+                    export.add(date.getString("event_pay_purchase_amount"));
+                    export.add(date.getString("aclick"));
+                    export.add(date.getString("bclick"));
+                    export.add(date.getString("ctr"));
+                    export.add(date.getString("cpc"));
+                    export.add(date.getString("cpm"));
+                    export.add(date.getString("activation"));
+                    export.add(date.getString("active_cost"));
+                    export.add(date.getString("event_pay"));
+                    export.add(date.getString("pay_cost"));
+                    export.add(date.getString("event_new_user_pay"));
+                    export.add(date.getString("new_pay_cost"));
+                    export.add(date.getString("play_3s_rate"));
+                    export.add(date.getString("play_5s_rate"));
+                    export.add(date.getString("play_end_rate"));
+                    exportList.add(export);
+                }
+            }
+            String[] headers = new String[]{"素材ID", "素材名称", "封面", "素材链接", "消耗", "ROI", "付费金额", "曝光", "点击", "ctr", "cpc", "cpm", "激活", "激活成本", "付费次数", "付费成本", "新增付费人数", "新增付费单价", "3s播放率", "5s播放率", "完播率"};
+
+
+            OutputStream os = response.getOutputStream();
+            ExportExcelUtils eeu = new ExportExcelUtils();
+            XSSFWorkbook workbook = new XSSFWorkbook();
+            eeu.exportExcel(workbook, 0, "短剧报表", headers, exportList);
+            this.setResponseHeader(response, "短剧报表.xls");
+            workbook.write(os);
+            os.flush();
+            os.close();
+
             return Result.OK(data);
         } catch (Exception e) {
             e.printStackTrace();
@@ -109,6 +176,22 @@ public class DuanJUReportController {
     }
 
 
+    public void setResponseHeader(HttpServletResponse response, String fileName) {
+        try {
+            try {
+                fileName = new String(fileName.getBytes(), "ISO8859-1");
+            } catch (UnsupportedEncodingException e) {
+                e.printStackTrace();
+            }
+            response.setContentType("application/octet-stream;charset=ISO8859-1");
+            response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
+            response.addHeader("Pargam", "no-cache");
+            response.addHeader("Cache-Control", "no-cache");
+        } catch (Exception ex) {
+            ex.printStackTrace();
+        }
+    }
+
     @GetMapping("/stopPlan")
     public Result<Object> stopPlan(Long accountId) {
         try {

+ 44 - 21
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/DuanJUReportMapper.xml

@@ -78,27 +78,50 @@
         ORDER BY t.charge DESC
     </select>
     <select id="getViodeoList" resultType="com.alibaba.fastjson.JSONObject">
-        SELECT *
-        FROM (SELECT CAST(photo_id AS char)                                                  AS photo_id,
-                     cover_url AS 'cover_url', photo_url AS 'photo_url', SUM(charge) AS charge,
-                     SUM(event_pay_purchase_amount)                                          AS event_pay_purchase_amount,
-                     round(ifnull(SUM(event_pay_purchase_amount) / SUM(charge) * 100, 0), 2) AS roi,
-                     SUM(aclick)                                                             AS aclick,
-                     SUM(bclick)                                                             AS bclick,
-                     concat(round(ifnull(SUM(bclick) / SUM(aclick) * 100, 0), 2), '%')       AS ctr,
-                     round(SUM(charge) / SUM(bclick), 2)                                     AS cpc,
-                     round(SUM(charge) / SUM(aclick) * 1000, 2)                              AS cpm,
-                     SUM(activation)                                                         AS activation,
-                     round(SUM(charge) / SUM(activation), 2)                                 AS active_cost,
-                     SUM(event_pay)                                                          AS event_pay,
-                     round(SUM(charge) / SUM(event_pay), 2)                                  AS pay_cost,
-                     SUM(round(event_new_user_pay))                                          AS event_new_user_pay,
-                     round(SUM(charge) / SUM(event_new_user_pay), 2)                         AS new_pay_cost
-              FROM media_api.compass_bind_kuaishou_material_video_report_daily
-              WHERE stat_date &gt;= #{start}
-                AND stat_date &lt;= #{end}
-              GROUP BY photo_id) t
-        ORDER BY t.charge DESC
+        SELECT t.photo_id,
+        t.photo_name,
+        t.cover_url,
+        t.photo_url,
+        SUM(t.charge) AS charge,
+        SUM(t.event_pay_purchase_amount) AS event_pay_purchase_amount,
+        round(ifnull(SUM(t.event_pay_purchase_amount) / SUM(t.charge) * 100, 0), 2) AS roi,
+        SUM(t.aclick) AS aclick,
+        SUM(t.bclick) AS bclick,
+        concat(round(ifnull(SUM(t.bclick) / SUM(t.aclick) * 100, 0), 2), '%') AS ctr,
+        round(SUM(t.charge) / SUM(t.bclick), 2) AS cpc,
+        round(SUM(t.charge) / SUM(t.aclick) * 1000, 2) AS cpm,
+        SUM(t.activation) AS activation,
+        round(SUM(t.charge) / SUM(t.activation), 2) AS active_cost,
+        SUM(t.event_pay) AS event_pay,
+        round(SUM(t.charge) / SUM(t.event_pay), 2) AS pay_cost,
+        SUM(round(t.event_new_user_pay)) AS event_new_user_pay,
+        round(SUM(t.charge) / SUM(t.event_new_user_pay), 2) AS new_pay_cost,
+        round(SUM(t.charge) / SUM(t.event_new_user_pay), 2) AS new_pay_cost,
+        concat(round(SUM(t.play_3s_count) / SUM(t.aclick) * 100, 2), '%') AS play_3s_rate,
+        concat(round(SUM(t.play_5s_count) / SUM(t.aclick) * 100, 2), '%') AS play_5s_rate,
+        concat(round(SUM(t.play_end_count) / SUM(t.aclick) * 100, 2), '%') AS play_end_rate
+        FROM (SELECT CAST(t1.photo_id AS char) AS 'photo_id',
+        t2.photo_name as 'photo_name',
+        t1.cover_url AS 'cover_url',
+        t1.photo_url AS 'photo_url',
+        t1.charge AS 'charge',
+        t1.event_pay_purchase_amount AS 'event_pay_purchase_amount',
+        t1.aclick AS 'aclick',
+        t1.bclick AS 'bclick',
+        t1.activation AS 'activation',
+        t1.event_pay AS 'event_pay',
+        t1.event_new_user_pay AS 'event_new_user_pay',
+        round(t1.play_3s_ratio * t1.aclick, 0) as 'play_3s_count',
+        round(t1.play_5s_ratio * t1.aclick, 0) as 'play_5s_count',
+        round(t1.play_end_ratio * t1.aclick, 0) as 'play_end_count'
+        FROM media_api.compass_bind_kuaishou_material_video_report_daily t1
+        left join media_api.compass_bind_kuaishou_video_list t2 on t1.photo_id = t2.photo_id
+        WHERE t1.stat_date &gt;= #{start}
+        AND t1.stat_date &lt;= #{end}) t
+        where 1 = 1
+        <if test="videoName!=null and videoName!=''">and t.photo_name like concat('%',#{videoName},'%')</if>
+        group by t.photo_id
+        ORDER BY sum(t.charge) DESC limit 100
     </select>
     <select id="getAgentToken" resultType="java.lang.String" parameterType="java.lang.Long">
         SELECT access_token