yumeng 1 anno fa
parent
commit
bc225db2a9

+ 47 - 0
module-common/src/main/java/cn/com/ctop/common/module/utils/LoadFileUtil.java

@@ -59,6 +59,53 @@ public class LoadFileUtil {
 
     }
 
+
+
+    public static String downLoadExcel(String urlStr, String savePath,String clipId,String cookie) {
+        try {
+
+            URL url = new URL(urlStr);
+
+            System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2,SSLv3");
+            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+            //设置超时间为3秒
+            conn.setConnectTimeout(60 * 1000);
+            //防止屏蔽程序抓取而返回403错误
+            conn.setRequestProperty("Cookie", cookie);
+            conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
+            conn.setRequestProperty("", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
+            //得到输入流
+            InputStream inputStream = conn.getInputStream();
+            //获取自己数组
+            byte[] getData = readInputStream(inputStream);
+
+            //文件保存位置
+            File saveDir = new File(savePath);
+            if (!saveDir.exists()) {
+                saveDir.mkdirs();
+            }
+            String localPath = saveDir + File.separator + clipId;
+            File file = new File(localPath);
+            if (!file.exists()) {
+                file.getParentFile().mkdirs();
+            }
+            FileOutputStream fos = new FileOutputStream(file);
+            fos.write(getData);
+            if (fos != null) {
+                fos.close();
+            }
+            if (inputStream != null) {
+                inputStream.close();
+            }
+            return localPath;
+        } catch (Exception e) {
+            return null;
+        }
+
+
+    }
+
+
     public static byte[] readInputStream(InputStream inputStream) throws IOException {
         byte[] buffer = new byte[1024];
         int len = 0;

+ 16 - 6
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/JyClipCooperation.java

@@ -101,7 +101,8 @@ public class JyClipCooperation {
      * 挂车视频
      */
     @Excel(name = "挂车视频")
-    private String videoCount30d;
+    private String videoCount;
+    private String videoShow;
 
     /**
      * 日期
@@ -225,12 +226,20 @@ public class JyClipCooperation {
         this.authItemGmv30d = authItemGmv30d;
     }
 
-    public String getVideoCount30d() {
-        return videoCount30d;
+    public String getVideoCount() {
+        return videoCount;
     }
 
-    public void setVideoCount30d(String videoCount30d) {
-        this.videoCount30d = videoCount30d;
+    public void setVideoCount(String videoCount) {
+        this.videoCount = videoCount;
+    }
+
+    public String getVideoShow() {
+        return videoShow;
+    }
+
+    public void setVideoShow(String videoShow) {
+        this.videoShow = videoShow;
     }
 
     public Long getStatDate() {
@@ -258,7 +267,8 @@ public class JyClipCooperation {
                 ", shopScore='" + shopScore + '\'' +
                 ", clipGmv30d='" + clipGmv30d + '\'' +
                 ", authItemGmv30d='" + authItemGmv30d + '\'' +
-                ", videoCount30d='" + videoCount30d + '\'' +
+                ", videoCount='" + videoCount + '\'' +
+                ", videoShow='" + videoShow + '\'' +
                 ", statDate=" + statDate +
                 '}';
     }

+ 4 - 2
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/JiaoYangFenXiaoMapper.xml

@@ -90,7 +90,8 @@
         shop_score,
         clip_gmv_30d,
         auth_item_gmv_30d,
-        video_count_30d,
+        video_count,
+        video_show,
         stat_date
         )
         values
@@ -110,7 +111,8 @@
         #{add.shopScore},
         #{add.clipGmv30d},
         #{add.authItemGmv30d},
-        #{add.videoCount30d},
+        #{add.videoCount},
+        #{add.videoShow},
         #{add.statDate}
 
         )

+ 116 - 3
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/JiaoYangFenXiaoServiceImpl.java

@@ -3,6 +3,7 @@ package cn.com.ctop.kuaishou.modules.batch.service.impl;
 import cn.com.ctop.common.module.service.ISendMessageService;
 import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.HttpUtils;
+import cn.com.ctop.common.module.utils.LoadFileUtil;
 import cn.com.ctop.kuaishou.modules.batch.entity.JyClipCooperation;
 import cn.com.ctop.kuaishou.modules.batch.entity.JyOrderList;
 
@@ -11,10 +12,13 @@ import cn.com.ctop.kuaishou.modules.batch.service.IJiaoYangFenXiaoService;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.poi.ss.usermodel.*;
 import org.jeecg.common.util.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.io.File;
+import java.io.FileInputStream;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -123,7 +127,7 @@ public class JiaoYangFenXiaoServiceImpl implements IJiaoYangFenXiaoService {
     }
 
     @Override
-    public void getClipCooperation(String cookie, Integer offset, Long statDate,Integer status) throws Exception {
+    public void getClipCooperation(String cookie, Integer offset, Long statDate, Integer status) throws Exception {
         Thread.sleep(500L);
         Map<String, Object> params = new HashMap<>();
         params.put("status", status);
@@ -173,14 +177,123 @@ public class JiaoYangFenXiaoServiceImpl implements IJiaoYangFenXiaoService {
             clipCooperation.setShopScore(jsonObject.getString("shopScore"));
             clipCooperation.setClipGmv30d(jsonObject.getString("clipGmv30d"));
             clipCooperation.setAuthItemGmv30d(jsonObject.getString("authItemGmv30d"));
-            clipCooperation.setVideoCount30d(jsonObject.getString("videoCount30d"));
             clipCooperation.setStatDate(statDate);
+            JSONObject getData = this.getClipData(jsonObject.getLong("clipId"), cookie);
+            if(!Check.isNull(getData)){
+                clipCooperation.setVideoCount(getData.getString("videoCount"));
+                clipCooperation.setVideoShow(getData.getString("videoShow"));
+            }
+
             adds.add(clipCooperation);
+
+
         }
         jiaoYangFenXiaoMapper.replaceClipCooperation(adds);
         if (list.size() >= 200) {
-            getClipCooperation(cookie, offset + 200, statDate,status);
+            getClipCooperation(cookie, offset + 200, statDate, status);
+        }
+    }
+
+    private JSONObject getClipData(Long clipId, String cookie) {
+        JSONObject returnJson = new JSONObject();
+        Map<String, Object> params = new HashMap<>();
+        params.put("clipId", clipId);
+        params.put("dimensionType", 1);
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Cookie", cookie);
+        String postUrl = "https://cps.kwaixiaodian.com/gateway/distribute/platform/recreate/leader/clip/cooperation/detail/export";
+        String resultStr = HttpUtils.httpPostRequest(postUrl, params, headers);
+        JSONObject result = JSONObject.parseObject(resultStr);
+        Integer code = result.getInteger("result");
+        if (code == 1) {
+            JSONObject data = result.getJSONObject("data");
+            if (!Check.isNull(data)) {
+                String fileUrl = data.getString("fileUrl");
+                try {
+                    // 创建Workbook对象
+                    String localPath = LoadFileUtil.downLoadExcel(fileUrl, "/data/file/jy/", clipId + ".xlsx", cookie);
+                    // FileFormat.Ver
+                    Workbook workbook = WorkbookFactory.create(new FileInputStream(new File(localPath)));
+                    // 获取第一个Sheet对象
+                    Sheet sheet = workbook.getSheet("概况");
+                    int firstRowNum = sheet.getFirstRowNum();
+                    int lastRowNum = sheet.getLastRowNum();
+                    for (int rowNum = firstRowNum + 1; rowNum <= lastRowNum; rowNum++) {
+                        Row row = sheet.getRow(rowNum);
+                        if (row == null) {
+                            continue;
+                        }
+                        int firstCellNum = row.getFirstCellNum();
+                        int lastCellNum = row.getLastCellNum();
+
+                        for (int cellNum = firstCellNum; cellNum < lastCellNum; cellNum++) {
+                            Cell cell = row.getCell(cellNum);
+                            String cellValue = getCellValue(cell);
+                            if (cellNum == 4) {
+                                returnJson.put("videoCount", cellValue);
+                            }
+                            if (cellNum == 6) {
+                                returnJson.put("videoShow", cellValue);
+                            }
+                        }
+                    }
+                    LoadFileUtil.delFile(localPath);
+                    // 关闭Workbook对象
+                    workbook.close();
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+        } else {
+            log.info("获取文件失败");
+        }
+
+        return returnJson;
+
+    }
+
+
+    public static String getCellValue(Cell cell) {
+        String cellValue = "";
+        if (cell == null) {
+            return cellValue;
         }
+        // 把数字当成String来读,避免出现1读成1.0的情况
+        if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
+            cell.setCellType(Cell.CELL_TYPE_STRING);
+        }
+        // 判断数据的类型
+        switch (cell.getCellType()) {
+            case Cell.CELL_TYPE_NUMERIC:
+                // 数字
+                cellValue = String.valueOf(cell.getNumericCellValue());
+                break;
+            case Cell.CELL_TYPE_STRING:
+                // 字符串
+                cellValue = String.valueOf(cell.getStringCellValue());
+                break;
+            case Cell.CELL_TYPE_BOOLEAN:
+                // Boolean
+                cellValue = String.valueOf(cell.getBooleanCellValue());
+                break;
+            case Cell.CELL_TYPE_FORMULA:
+                // 公式
+                cellValue = String.valueOf(cell.getCellFormula());
+                break;
+            case Cell.CELL_TYPE_BLANK:
+                // 空值
+                cellValue = "";
+                break;
+            case Cell.CELL_TYPE_ERROR:
+                // 故障
+                cellValue = "非法字符";
+                break;
+            default:
+                cellValue = "未知类型";
+                break;
+        }
+
+        return cellValue;
     }