Browse Source

快手素材报表改版

yumeng 4 years ago
parent
commit
8b7880185c

+ 2 - 12
module-common/src/main/java/cn/com/ctop/common/module/utils/ExportExcelUtils.java

@@ -1,18 +1,8 @@
 package cn.com.ctop.common.module.utils;
 package cn.com.ctop.common.module.utils;
 
 
 
 
-import org.apache.poi.ss.usermodel.BorderStyle;
-import org.apache.poi.ss.usermodel.FillPatternType;
-import org.apache.poi.ss.usermodel.HorizontalAlignment;
-import org.apache.poi.ss.usermodel.IndexedColors;
-import org.apache.poi.ss.usermodel.VerticalAlignment;
-import org.apache.poi.xssf.usermodel.XSSFCell;
-import org.apache.poi.xssf.usermodel.XSSFCellStyle;
-import org.apache.poi.xssf.usermodel.XSSFFont;
-import org.apache.poi.xssf.usermodel.XSSFRichTextString;
-import org.apache.poi.xssf.usermodel.XSSFRow;
-import org.apache.poi.xssf.usermodel.XSSFSheet;
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.xssf.usermodel.*;
 
 
 import java.math.BigDecimal;
 import java.math.BigDecimal;
 import java.util.List;
 import java.util.List;

+ 136 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/controller/KsVideoReportCtrl.java

@@ -108,7 +108,8 @@ public class KsVideoReportCtrl {
             if (!Check.isNull(requestBody.getString("order"))) {
             if (!Check.isNull(requestBody.getString("order"))) {
                 requestMap.put("order", requestBody.getString("order"));
                 requestMap.put("order", requestBody.getString("order"));
             }
             }
-            PageInfo<JSONObject> listData = ksVideoReportService.getKuaiShouVideoReportByMap(requestMap, pageSize, pageNo);
+            PageInfo<JSONObject> listData = ksVideoReportService.getKuaiShouVideoPageReportByMap(requestMap, pageSize, pageNo);
+            System.err.println(listData);
             if (Check.isNull(listData)) {
             if (Check.isNull(listData)) {
                 throw new Exception("暂无素材相关信息,请检查账户");
                 throw new Exception("暂无素材相关信息,请检查账户");
             }
             }
@@ -266,4 +267,138 @@ public class KsVideoReportCtrl {
             log.error(e.getMessage());
             log.error(e.getMessage());
         }
         }
     }
     }
+
+
+    @PostMapping("/excelV2")
+    public void excelV2(@RequestBody JSONObject requestBody,
+                        HttpServletRequest request,
+                        HttpServletResponse response) {
+        Result<PageInfo<JSONObject>> result = new Result<>();
+        try {
+
+
+            if (Check.isNull(requestBody)) {
+                throw new Exception("入参不能为空");
+            }
+            JSONArray columns = requestBody.getJSONArray("columns");
+            if (Check.isNull(columns)) {
+                throw new Exception("请传入表头");
+            }
+
+            String startDate = requestBody.getString("startDate");
+            if (Check.isNull(startDate)) {
+                throw new Exception("请输入查询开始时间");
+            }
+            String endDate = requestBody.getString("endDate");
+            if (Check.isNull(endDate)) {
+                throw new Exception("请输入查询结束时间");
+            }
+            String filedAll = JsonResourceUtil.joinAllFiled(AccountReportConstants.kuaishouVideoReportMap);
+            //   System.err.println(filedAll);
+            if (Check.isNull(filedAll)) {
+                throw new Exception("初始化查询 字段返回为空");
+            }
+            Map<String, Object> requestMap = new HashMap<>();
+            requestMap.put("filed", filedAll);
+            requestMap.put("startDate", startDate);
+            requestMap.put("endDate", endDate);
+            if (!Check.isNull(requestBody.getJSONArray("accountIds"))) {
+                requestMap.put("accountIds", requestBody.getJSONArray("accountIds"));
+            }
+            if (!Check.isNull(requestBody.getString("clipId"))) {
+                requestMap.put("clipId", requestBody.getString("clipId"));
+            }
+            if (!Check.isNull(requestBody.getString("shotId"))) {
+                requestMap.put("shotId", requestBody.getString("shotId"));
+            }
+            if (!Check.isNull(requestBody.getString("planId"))) {
+                requestMap.put("planId", requestBody.getString("planId"));
+            }
+            if (!Check.isNull(requestBody.getString("leaderId"))) {
+                requestMap.put("leaderId", requestBody.getString("leaderId"));
+            }
+            if (!Check.isNull(requestBody.getString("target"))) {
+                requestMap.put("target", requestBody.getString("target"));
+            }
+            if (!Check.isNull(requestBody.getString("order"))) {
+                requestMap.put("order", requestBody.getString("order"));
+            }
+            List<JSONObject> listData = ksVideoReportService.getKuaiShouVideoReportByMap(requestMap);
+            if (Check.isNull(listData)) {
+                throw new Exception("暂无素材相关信息,请检查账户");
+            }
+            columns.add(0, "materialName");
+            columns.add(1, "channel");
+            columns.add(2, "designLeader");
+            columns.add(4, "clip");
+            columns.add(4, "plan");
+            columns.add(5, "shot");
+            columns.add(columns.size(), "url");
+
+            List<String> titles = new ArrayList<>();
+            titles.add(0, "素材名称");
+            titles.add(1, "渠道");
+            titles.add(2, "设计负责人");
+            titles.add(3, "剪辑");
+            titles.add(4, "编导");
+            titles.add(5, "拍摄");
+
+
+            //  ArrayList<String> fileIds = JsonResourceUtil.joinTitle(AccountReportConstants.kuaishouVideoReportMap, columns);
+            titles = getfileIds(AccountReportConstants.kuaishouVideoReportMap, columns, titles);
+            titles.add(columns.size(), "素材链接");
+            List<List<Object>> excelList = new ArrayList<>();
+            for (int i = 0; i < listData.size(); i++) {
+                List<Object> temp = new ArrayList<>();
+                JSONObject jsonObject = listData.get(i);
+                for (int j = 0; j < columns.size(); j++) {
+                    String key = columns.getString(j);
+                    String value = jsonObject.getString(key);
+                    temp.add(value);
+                }
+                excelList.add(temp);
+            }
+
+
+            try {
+                //  String[] headers = {"视频", "视频md5", "花费", "安卓下载完成数", "封面曝光数", "封面点击数", "素材曝光数", "行为数", "封面点击率", "行为率", "均千次封面曝光花费(元)", "平均封面点击单价(元)", "平均行为单价(元)", "转化数", "转化单价(元)"};
+                String[] strings = titles.toArray(new String[]{});
+                OutputStream os = response.getOutputStream();
+                ExportExcelUtils eeu = new ExportExcelUtils();
+                XSSFWorkbook workbook = new XSSFWorkbook();
+                eeu.exportExcel(workbook, 0, "快手素材报表", strings, excelList);
+                HttpUtils.setResponseHeader(response, "快手素材.xlsx");
+                workbook.write(os);
+                os.flush();
+                os.close();
+            } catch (IOException e) {
+                log.error(e.getMessage());
+            }
+
+
+            result.setSuccess(true);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.error(e.getMessage(), e);
+            result.setSuccess(false);
+            result.setMessage(e.getMessage());
+        }
+
+
+    }
+
+    private List<String> getfileIds(Map<String, Map<String, Object>> kuaishouVideoReportMap, JSONArray columns, List<String> titles) {
+        for (int i = 0; i < columns.size(); i++) {
+            String string = columns.getString(i);
+            Map<String, Object> stringObjectMap = kuaishouVideoReportMap.get(string);
+            if (Check.isNull(stringObjectMap)) {
+                continue;
+            }
+            Object comment = stringObjectMap.get("comment");
+            titles.add(String.valueOf(comment));
+
+        }
+        return titles;
+    }
 }
 }

+ 3 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/IKsVideoReportService.java

@@ -15,7 +15,9 @@ public interface IKsVideoReportService {
 
 
     List<JSONObject> exportExcelReportBy(JSONArray accountIds, String startDate, String endDate, String filed, String target, String order, String clip, String shot, String plan);
     List<JSONObject> exportExcelReportBy(JSONArray accountIds, String startDate, String endDate, String filed, String target, String order, String clip, String shot, String plan);
 
 
-    PageInfo<JSONObject> getKuaiShouVideoReportByMap(Map<String, Object> requestMap, int pageSize, int pageNo);
+    PageInfo<JSONObject> getKuaiShouVideoPageReportByMap(Map<String, Object> requestMap, int pageSize, int pageNo);
 
 
     List<JSONObject> getDesignList();
     List<JSONObject> getDesignList();
+
+    List<JSONObject> getKuaiShouVideoReportByMap(Map<String, Object> requestMap);
 }
 }

+ 7 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/KsVideoReportServiceImpl.java

@@ -36,7 +36,7 @@ public class KsVideoReportServiceImpl implements IKsVideoReportService {
     }
     }
 
 
     @Override
     @Override
-    public PageInfo<JSONObject> getKuaiShouVideoReportByMap(Map<String, Object> requestMap, int pageSize, int pageNo) {
+    public PageInfo<JSONObject> getKuaiShouVideoPageReportByMap(Map<String, Object> requestMap, int pageSize, int pageNo) {
         PageHelper.startPage(pageNo, pageSize);
         PageHelper.startPage(pageNo, pageSize);
         List<JSONObject> jsonObjectList = ksVideoReportMapper.getKuaiShouVideoReportByMap(requestMap);
         List<JSONObject> jsonObjectList = ksVideoReportMapper.getKuaiShouVideoReportByMap(requestMap);
         return new PageInfo<>(jsonObjectList);
         return new PageInfo<>(jsonObjectList);
@@ -48,4 +48,10 @@ public class KsVideoReportServiceImpl implements IKsVideoReportService {
         return ksVideoReportMapper.getDesignList();
         return ksVideoReportMapper.getDesignList();
     }
     }
 
 
+    @Override
+    public List<JSONObject> getKuaiShouVideoReportByMap(Map<String, Object> requestMap) {
+        List<JSONObject> jsonObjectList = ksVideoReportMapper.getKuaiShouVideoReportByMap(requestMap);
+        return jsonObjectList;
+    }
+
 }
 }

+ 2 - 2
module-kuaishou/src/main/resources/json_template/kuaishou_video_report_filed_mapping.json

@@ -208,10 +208,10 @@
   },
   },
   "play3sCount": {
   "play3sCount": {
     "filed": "sum(t1.play_3s_count) as play3sCount",
     "filed": "sum(t1.play_3s_count) as play3sCount",
-    "comment": "3s播放"
+    "comment": "3s播放"
   },
   },
   "play3sRate": {
   "play3sRate": {
-    "filed": "CASE WHEN sum(photo_show) != 0 THEN CONCAT( ROUND( sum(t1.play_3s_count) / sum(t1.photo_show),2 ) * 100, '%' ) ELSE '-' END AS play3sRate",
+    "filed": "CASE WHEN sum(photo_show) != 0 THEN CONCAT(CAST(ROUND( sum(t1.play_3s_count) / sum(t1.photo_show),2 )  * 100 AS CHAR),'%') ELSE '-' END AS play3sRate",
     "comment": "3s播放率"
     "comment": "3s播放率"
   }
   }
 }
 }