|
@@ -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.service.ISendMessageService;
|
|
import cn.com.ctop.common.module.utils.Check;
|
|
import cn.com.ctop.common.module.utils.Check;
|
|
import cn.com.ctop.common.module.utils.HttpUtils;
|
|
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.JyClipCooperation;
|
|
import cn.com.ctop.kuaishou.modules.batch.entity.JyOrderList;
|
|
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.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
import org.jeecg.common.util.DateUtils;
|
|
import org.jeecg.common.util.DateUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.FileInputStream;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -123,7 +127,7 @@ public class JiaoYangFenXiaoServiceImpl implements IJiaoYangFenXiaoService {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@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);
|
|
Thread.sleep(500L);
|
|
Map<String, Object> params = new HashMap<>();
|
|
Map<String, Object> params = new HashMap<>();
|
|
params.put("status", status);
|
|
params.put("status", status);
|
|
@@ -173,14 +177,123 @@ public class JiaoYangFenXiaoServiceImpl implements IJiaoYangFenXiaoService {
|
|
clipCooperation.setShopScore(jsonObject.getString("shopScore"));
|
|
clipCooperation.setShopScore(jsonObject.getString("shopScore"));
|
|
clipCooperation.setClipGmv30d(jsonObject.getString("clipGmv30d"));
|
|
clipCooperation.setClipGmv30d(jsonObject.getString("clipGmv30d"));
|
|
clipCooperation.setAuthItemGmv30d(jsonObject.getString("authItemGmv30d"));
|
|
clipCooperation.setAuthItemGmv30d(jsonObject.getString("authItemGmv30d"));
|
|
- clipCooperation.setVideoCount30d(jsonObject.getString("videoCount30d"));
|
|
|
|
clipCooperation.setStatDate(statDate);
|
|
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);
|
|
adds.add(clipCooperation);
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|
|
jiaoYangFenXiaoMapper.replaceClipCooperation(adds);
|
|
jiaoYangFenXiaoMapper.replaceClipCooperation(adds);
|
|
if (list.size() >= 200) {
|
|
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;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|