|
@@ -1,20 +1,31 @@
|
|
|
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.toutiao.modules.report.service.IBytedanceVideoReportService;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.jeecg.common.api.vo.Result;
|
|
|
+import org.jeecg.common.constant.AccountReportConstants;
|
|
|
+import org.jeecg.common.util.JsonResourceUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
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.List;
|
|
|
|
|
|
/**
|
|
|
- * Created by JQ.bi on 2020.09.21
|
|
|
+ * Created by JQ.bi on 2020.09.21
|
|
|
*/
|
|
|
@Slf4j
|
|
|
@RestController
|
|
@@ -25,27 +36,91 @@ public class BytedanceVideoReportCtrl {
|
|
|
IBytedanceVideoReportService bytedanceVideoReportService;
|
|
|
|
|
|
@PostMapping("/list")
|
|
|
- public Result<List<JSONObject>> getListReport(@RequestBody JSONObject requestBody) {
|
|
|
+ public Result<PageInfo<JSONObject>> getListReport(@RequestBody JSONObject requestBody) {
|
|
|
|
|
|
- Result<List<JSONObject>> result = new Result<>();
|
|
|
+ Result<PageInfo<JSONObject>> result = new Result<>();
|
|
|
if (requestBody.isEmpty()) {
|
|
|
log.error("request body is empty");
|
|
|
result.setSuccess(false);
|
|
|
+ } else {
|
|
|
+ JSONArray accountIds = requestBody.getJSONArray("accountIds");
|
|
|
+ String startDate = requestBody.getString("startDate");
|
|
|
+ String endDate = requestBody.getString("endDate");
|
|
|
+ String target = requestBody.getString("target");
|
|
|
+ String order = requestBody.getString("order");
|
|
|
+ int pageSize= requestBody.getInteger("pageSize");
|
|
|
+ int pageNo= requestBody.getInteger("pageNo");
|
|
|
+
|
|
|
+ String filedAll = JsonResourceUtil.joinAllFiled(AccountReportConstants.dicMapByVideo);
|
|
|
+
|
|
|
+ try {
|
|
|
+ if(accountIds.isEmpty()){
|
|
|
+ accountIds=null;
|
|
|
+ }
|
|
|
+ PageInfo<JSONObject> listData = bytedanceVideoReportService.getVideoReportBy(accountIds, startDate, endDate, filedAll, target, order,pageSize,pageNo);
|
|
|
+ result.setResult(listData);
|
|
|
+ result.setSuccess(true);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ result.setSuccess(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/report/excel")
|
|
|
+ public void getExcelReport(@RequestBody JSONObject requestBody,
|
|
|
+ HttpServletRequest request,
|
|
|
+ HttpServletResponse response) {
|
|
|
+ JSONArray columns=requestBody.getJSONArray("columns");
|
|
|
+ if(columns.isEmpty()){
|
|
|
+ log.error("请选择需要导出的字段");
|
|
|
}
|
|
|
+ String filed= JsonResourceUtil.joinFiled(AccountReportConstants.dicMapByVideo,columns);
|
|
|
+ List<String> titles= new ArrayList<>();
|
|
|
+ titles.add("视频");
|
|
|
+ titles.add("视频名称");
|
|
|
+ titles.add("项目名称");
|
|
|
+ titles.add("上传时间");
|
|
|
+ titles.addAll(JsonResourceUtil.joinTitle(AccountReportConstants.dicMapByVideo,columns));
|
|
|
+ //此处增加两个元素是为了保证数据顺序
|
|
|
+ columns.add(0,"url");
|
|
|
+ columns.add(1,"materialName");
|
|
|
+ columns.add(2,"projectName");
|
|
|
+ columns.add(3,"createTime");
|
|
|
JSONArray accountIds = requestBody.getJSONArray("accountIds");
|
|
|
+ if(accountIds.isEmpty()){
|
|
|
+ accountIds=null;
|
|
|
+ }
|
|
|
String startDate = requestBody.getString("startDate");
|
|
|
String endDate = requestBody.getString("endDate");
|
|
|
- String target= requestBody.getString("target");
|
|
|
- String order= requestBody.getString("order");
|
|
|
- try {
|
|
|
- List<JSONObject> listData= null;
|
|
|
- result.setResult(listData);
|
|
|
- result.setSuccess(true);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error(e.getMessage(), e);
|
|
|
- result.setSuccess(false);
|
|
|
+ String target = requestBody.getString("target");
|
|
|
+ String order = requestBody.getString("order");
|
|
|
+ List<JSONObject> excelData= bytedanceVideoReportService.exportExcelReportBy(accountIds,startDate,endDate,filed,target,order);
|
|
|
+ if(excelData.isEmpty()){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<List<Object>> excelList= new ArrayList<>();
|
|
|
+ excelData.forEach(data->{
|
|
|
+ List<Object> temp= new ArrayList<>();
|
|
|
+ columns.forEach(k->{
|
|
|
+ temp.add(data.get(k.toString()));
|
|
|
+ });
|
|
|
+ excelList.add(temp);
|
|
|
+ });
|
|
|
+ try{
|
|
|
+ String[] headers = titles.toArray(new String[titles.size()]);
|
|
|
+ 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());
|
|
|
}
|
|
|
- return result;
|
|
|
}
|
|
|
|
|
|
}
|