|
@@ -7,6 +7,7 @@ import cn.com.ctop.toutiao.modules.report.service.IBytedanceVideoReportService;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
+import io.swagger.models.auth.In;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.jeecg.common.api.vo.Result;
|
|
@@ -19,12 +20,16 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import javax.naming.ldap.HasControls;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
|
import java.io.OutputStream;
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* Created by JQ.bi on 2020.09.21
|
|
@@ -37,6 +42,94 @@ public class BytedanceVideoReportCtrl {
|
|
|
@Autowired
|
|
|
IBytedanceVideoReportService bytedanceVideoReportService;
|
|
|
|
|
|
+
|
|
|
+ @PostMapping("/getBytedanceSevenDayCost")
|
|
|
+ public Result<PageInfo<JSONObject>> getBytedanceSevenDayCost(@RequestBody JSONObject requestBody) {
|
|
|
+ Result<PageInfo<JSONObject>> result = new Result<>();
|
|
|
+ if (requestBody.isEmpty()) {
|
|
|
+ log.error("request body is empty");
|
|
|
+ result.setSuccess(false);
|
|
|
+ } else {
|
|
|
+ Long projectId = requestBody.getLong("projectId");
|
|
|
+ Long startDate = Long.valueOf(requestBody.getString("startDate").replace("-", ""));
|
|
|
+ Long endDate = Long.valueOf(requestBody.getString("endDate").replace("-", ""));
|
|
|
+ Map<String, Long> requestMap = new HashMap<>();
|
|
|
+ if (!Check.isNull(projectId)) {
|
|
|
+ requestMap.put("projectId", projectId);
|
|
|
+ }
|
|
|
+ if (!Check.isNull(startDate)) {
|
|
|
+ requestMap.put("startDate", startDate);
|
|
|
+ }
|
|
|
+ if (!Check.isNull(endDate)) {
|
|
|
+ requestMap.put("endDate", endDate);
|
|
|
+ }
|
|
|
+ Integer pageSize = requestBody.getInteger("pageSize");
|
|
|
+ Integer pageNo = requestBody.getInteger("pageNo");
|
|
|
+ try {
|
|
|
+ PageInfo<JSONObject> listData = bytedanceVideoReportService.getBytedanceSevenDayCost(requestMap, pageSize, pageNo);
|
|
|
+ result.setResult(listData);
|
|
|
+ result.setSuccess(true);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ result.setSuccess(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/exportBytedanceSevenDayCost")
|
|
|
+ public void exportBytedanceSevenDayCost(HttpServletRequest request, HttpServletResponse response,@RequestBody JSONObject requestBody) {
|
|
|
+
|
|
|
+ if (requestBody.isEmpty()) {
|
|
|
+ log.error("request body is empty");
|
|
|
+
|
|
|
+ } else {
|
|
|
+ Long projectId = requestBody.getLong("projectId");
|
|
|
+ Long startDate = Long.valueOf(requestBody.getString("startDate").replace("-", ""));
|
|
|
+ Long endDate = Long.valueOf(requestBody.getString("endDate").replace("-", ""));
|
|
|
+ Map<String, Long> requestMap = new HashMap<>();
|
|
|
+ if (!Check.isNull(projectId)) {
|
|
|
+ requestMap.put("projectId", projectId);
|
|
|
+ }
|
|
|
+ if (!Check.isNull(startDate)) {
|
|
|
+ requestMap.put("startDate", startDate);
|
|
|
+ }
|
|
|
+ if (!Check.isNull(endDate)) {
|
|
|
+ requestMap.put("endDate", endDate);
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ List<JSONObject> listData = bytedanceVideoReportService.getBytedanceSevenDayCostNoPage(requestMap);
|
|
|
+ List<List<Object>> exportList = new ArrayList<>();
|
|
|
+ if (!Check.isNull(listData)) {
|
|
|
+ for (int i = 0; i < listData.size(); i++) {
|
|
|
+ JSONObject date = listData.get(i);
|
|
|
+ List<Object> export = new ArrayList();
|
|
|
+ export.add(date.getString("project_name"));
|
|
|
+ export.add(date.getString("material_id"));
|
|
|
+ export.add(date.getString("material_name"));
|
|
|
+ export.add(date.getString("first_cost_time"));
|
|
|
+ export.add(date.getString("diff_day"));
|
|
|
+ export.add(date.getString("seven_day_cost"));
|
|
|
+ exportList.add(export);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String[] headers = {"项目名称", "素材ID", "素材名称", "首次消耗日期", "消耗天数", "消耗"};
|
|
|
+ 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();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
@PostMapping("/list")
|
|
|
public Result<PageInfo<JSONObject>> getListReport(@RequestBody JSONObject requestBody) {
|
|
|
Result<PageInfo<JSONObject>> result = new Result<>();
|
|
@@ -216,4 +309,21 @@ public class BytedanceVideoReportCtrl {
|
|
|
log.error(e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ //发送响应流方法
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|