|
@@ -1,10 +1,13 @@
|
|
|
package cn.com.ctop.toutiao.modules.report.controller;
|
|
|
|
|
|
+import cn.com.ctop.common.module.utils.ExportExcelUtils;
|
|
|
+import cn.com.ctop.common.module.utils.HttpUtils;
|
|
|
import cn.com.ctop.kuaishou.modules.report.service.NewMonitorService;
|
|
|
import cn.com.ctop.toutiao.modules.report.service.IBytedanceNewPlanReportService;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.jeecg.common.api.vo.Result;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
@@ -12,6 +15,11 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|
|
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.IOException;
|
|
|
+import java.io.OutputStream;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -76,6 +84,56 @@ public class BytedanceNewPlanReportCtrl {
|
|
|
return resultBody;
|
|
|
}
|
|
|
|
|
|
+ @PostMapping("/report/excel")
|
|
|
+ public void getExcelReport(@RequestBody JSONObject requestBody,
|
|
|
+ HttpServletRequest request,
|
|
|
+ HttpServletResponse response) {
|
|
|
+
|
|
|
+ JSONArray accountIds = requestBody.getJSONArray("accountIds");
|
|
|
+ String userId = requestBody.getString("userId");
|
|
|
+ //TODO 没有维护快手事业部负责人角色,增加判断
|
|
|
+ if ("6b4c821adc414dc8b7718ab63ccbfcaf".equals(userId)) {
|
|
|
+ accountIds = newPlanReportService.getAccountIdsByMedia();
|
|
|
+ } else {
|
|
|
+ if (!userId.isEmpty()) {
|
|
|
+ accountIds = newPlanReportService.getAccountIdsByUserId(userId);
|
|
|
+ }
|
|
|
+ if (accountIds.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String startDate = requestBody.getString("startDate");
|
|
|
+ String endDate = requestBody.getString("endDate");
|
|
|
+ String target = requestBody.getString("target");
|
|
|
+ String order = requestBody.getString("order");
|
|
|
+ List<JSONObject> listData = newMonitorService.getPlanMessage(accountIds, startDate, endDate, target, "0");
|
|
|
+
|
|
|
+ List<List<Object>> excelList = new ArrayList<>();
|
|
|
+ listData.forEach(data -> {
|
|
|
+ List<Object> temp = new ArrayList<>();
|
|
|
+ temp.add(data.getString("authName"));
|
|
|
+ temp.add(data.getLong("accountId"));
|
|
|
+ temp.add(data.getString("userName"));
|
|
|
+ temp.add(data.getLong("new"));
|
|
|
+ temp.add(data.getLong("valid"));
|
|
|
+ temp.add(data.getString("maxCreateTime"));
|
|
|
+ excelList.add(temp);
|
|
|
+ });
|
|
|
+ try {
|
|
|
+ String[] headers = {"账户名称","账户ID","账户所属人","新上计划数","有效计划数","最近上新时间"};
|
|
|
+ OutputStream os = response.getOutputStream();
|
|
|
+ ExportExcelUtils eeu = new ExportExcelUtils();
|
|
|
+ XSSFWorkbook workbook = new XSSFWorkbook();
|
|
|
+ eeu.exportExcel(workbook, 0, "头条新上计划数", headers, excelList);
|
|
|
+ HttpUtils.setResponseHeader(response, "头条新上计划数.xlsx");
|
|
|
+ workbook.write(os);
|
|
|
+ os.flush();
|
|
|
+ os.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 查询素材报表表格数据
|
|
|
*/
|