|
@@ -1,7 +1,12 @@
|
|
|
package com.jiayue.ipp.idp.controller;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.io.IoUtil;
|
|
|
+import cn.hutool.poi.excel.ExcelUtil;
|
|
|
+import cn.hutool.poi.excel.ExcelWriter;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.jiayue.ipfcst.common.core.web.vo.ResponseVO;
|
|
|
import com.jiayue.ipp.common.data.entity.PowerStationStatusData;
|
|
|
import com.jiayue.ipp.idp.service.PowerStationStatusDataService;
|
|
|
import com.jiayue.ipp.idp.util.R;
|
|
@@ -11,8 +16,15 @@ import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.BufferedOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.net.URLEncoder;
|
|
|
import java.text.ParseException;
|
|
|
-import java.util.Date;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -92,4 +104,86 @@ public class PowerStationStatusDataController {
|
|
|
Long endTime) {
|
|
|
return R.ok(powerStationStatusDataService.getCenterData(new Date(startTime), new Date(endTime)));
|
|
|
}
|
|
|
+ @GetMapping(value = {"/exportDataEvent/{stationCode}/{startTime}/{endTime}/{cdqPoint}/{dqPoint}/{forecastManufactor}","/exportDataEvent/{stationCode}/{startTime}/{endTime}/{cdqPoint}/{dqPoint}" })
|
|
|
+ public R exportDataEvent(
|
|
|
+ @PathVariable("stationCode") String stationCode,
|
|
|
+ @PathVariable("startTime") Long startTime,
|
|
|
+ @PathVariable("endTime") Long endTime,
|
|
|
+ @PathVariable("cdqPoint") Integer cdqPoint,
|
|
|
+ @PathVariable("dqPoint") Integer dqPoint,
|
|
|
+ @PathVariable(value = "forecastManufactor",required = false) String forecastManufactor,
|
|
|
+ HttpServletResponse response) {
|
|
|
+
|
|
|
+
|
|
|
+ try {
|
|
|
+ Map<String, List> map = powerStationStatusDataService.getCompositeData(stationCode, new Date(startTime), new Date(endTime), forecastManufactor, cdqPoint,dqPoint);
|
|
|
+
|
|
|
+ ExcelWriter writer = ExcelUtil.getWriter(true);
|
|
|
+ writer.renameSheet(0, "数据查询对比");
|
|
|
+ List<String> header = new ArrayList();
|
|
|
+ List<String> headFieldName = new ArrayList();
|
|
|
+
|
|
|
+ List<Map> headerList = map.get("fromHead");
|
|
|
+ for (Map headMap:headerList){
|
|
|
+ header.add(headMap.get("label").toString());
|
|
|
+ headFieldName.add(headMap.get("field").toString());
|
|
|
+ }
|
|
|
+ List<List<String>> rowHeather = CollUtil.newArrayList();
|
|
|
+ rowHeather.add(header);
|
|
|
+
|
|
|
+ List<Map<String,Object>> contentList = map.get("tableList");
|
|
|
+
|
|
|
+ List<List<String>> rowsContent = CollUtil.newArrayList();
|
|
|
+
|
|
|
+ for (Map<String,Object> contentMap : contentList) {
|
|
|
+ List<String> rowList = new ArrayList();
|
|
|
+ for (String fieldStr:headFieldName){
|
|
|
+ if (contentMap.get(fieldStr)==null){
|
|
|
+ rowList.add("");
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ rowList.add(contentMap.get(fieldStr).toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ rowHeather.add(rowList);
|
|
|
+ }
|
|
|
+
|
|
|
+ writer.write(rowHeather, true);
|
|
|
+//
|
|
|
+// ExcelWriter monthSheet = writer.setSheet("月");
|
|
|
+//
|
|
|
+// List<List<String>> rowsMonth = CollUtil.newArrayList();
|
|
|
+// rowsMonth.add(rowHeather);
|
|
|
+// for (Map<String, BigDecimal> monthList : monthLists) {
|
|
|
+// List<String> rowContent = CollUtil.newArrayList();
|
|
|
+// rowContent.add(monthList.get("time") + "");
|
|
|
+// rowContent.add(monthList.get("capacity") + "");
|
|
|
+// rowContent.add(monthList.get("hourDA") + "");
|
|
|
+// rowContent.add(monthList.get("ultraShortTermAccuracy") + "");
|
|
|
+// rowContent.add(monthList.get("theoreticalPowerGeneration") + "");
|
|
|
+// rowContent.add(monthList.get("actualPowerGeneration") + "");
|
|
|
+// rowContent.add(monthList.get("prValue") + "");
|
|
|
+// rowsMonth.add(rowContent);
|
|
|
+// }
|
|
|
+//
|
|
|
+// monthSheet.write(rowsMonth, true);
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+
|
|
|
+ String fileName = "数据对比查询" + simpleDateFormat.format(startTime) + "至" + simpleDateFormat.format(endTime) + ".xlsx";
|
|
|
+ response.setContentType("application/x-msdownload;charset=utf-8");
|
|
|
+ response.setHeader("Content-disposition", "attachment; filename=" + URLEncoder.encode(fileName, "UTF-8"));
|
|
|
+ ServletOutputStream out = null;
|
|
|
+ out = response.getOutputStream();
|
|
|
+ writer.flush(out, true);
|
|
|
+ // 关闭writer,释放内存
|
|
|
+ writer.close();
|
|
|
+ //此处记得关闭输出Servlet流
|
|
|
+ IoUtil.close(out);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.ok();
|
|
|
+
|
|
|
+ }
|
|
|
}
|