Explorar o código

实时预测一期二期前后台

zy %!s(int64=2) %!d(string=hai) anos
pai
achega
e8f404e80f

+ 4 - 52
ipfcst/ipfcst-reportquery/src/main/frontend/views/contrastRealTimeQueryOne/index.vue

@@ -59,56 +59,10 @@
       <div class="toolbar" v-show="this.showToolBar">
         <vxe-toolbar ref="nwpToolBar" custom></vxe-toolbar>
       </div>
-      <div class="timeQuery">
-        <el-button size="small" :loading="loading" @click="dialogVisible = true">显示设置</el-button>
-      </div>
 
     </div>
 
 
-    <el-dialog
-      title="选择数据类型"
-      :visible.sync="dialogVisible"
-      :before-close="this.cancelDisplay"
-      width="50%">
-      <div class="drag-box-item">
-        <div class="item-title">隐藏</div>
-
-        <draggable class="list-group" :list="listh" group="people" @change="log">
-          <transition-group id="done" tag="div" class="item-ul">
-            <div
-              v-for="(element, index) in listh"
-              :key="element.value"
-              class="drag-list"
-            >
-              {{ element.key }}
-            </div>
-          </transition-group>
-        </draggable>
-
-      </div>
-      <div class="drag-box-item">
-        <div class="item-title">展示</div>
-
-        <draggable class="list-group" :list="lists" group="people" @change="log">
-          <transition-group id="wdtodo" tag="div" class="item-ul">
-            <div
-              v-for="(element, index) in lists"
-              :key="element.value"
-              class="drag-list"
-            >
-              {{ element.key }}
-            </div>
-          </transition-group>
-        </draggable>
-      </div>
-      <span slot="footer" class="dialog-footer">
-        <el-button @click="this.initShow" style="color: #3d1f25">初始化</el-button>
-    <el-button @click="this.cancelDisplay" style="color: #1f2d3d">取 消</el-button>
-    <el-button type="primary" style="color: #1f2d3d" @click="this.changeDisplay">确 定</el-button>
-  </span>
-    </el-dialog>
-
     <div class="content">
       <el-tabs type="card" v-model="activeName" @tab-click="Byresize">
         <el-tab-pane label="图表" name="first">
@@ -277,7 +231,7 @@ export default {
         formData.append('type', "")
         this.$axios({ // 用axios发送post请求
           method: 'post',
-          url: '/downLoadFile', // 请求地址
+          url: '/downLoadFileOne', // 请求地址
           data: formData, // 参数
           responseType: 'blob', // 表明返回服务器返回的数据类型
           headers: {
@@ -300,7 +254,7 @@ export default {
       formData.append("jgTime",this.jgTime)
       formData.append("base64",this.base64)
       //this.$axios.get('ComprehensiveContrastExports/' + this.startTime + '/' + this.endTime + '/' + this.equipmentId + '/' + this.electricField.electricFieldTypeEnum + '/' + this.jgTime+ '/' +this.base64+ '/' +this.width+ '/' +this.height, {
-      this.$axios.post('/ComprehensiveContrastExports', formData).then((response) => {
+      this.$axios.post('/ComprehensiveContrastOneExports', formData).then((response) => {
         this.downloadFile(response.data)
       }).then((response) => {
         this.loading = false
@@ -310,7 +264,7 @@ export default {
       })
     },
     init() {
-      this.$axios.get("nwp/getNwpDay").then(res=>{
+      this.$axios.get("nwpOne/getNwpDay").then(res=>{
         var days = res.data + 1
         this.endTime = new Date(new Date().toLocaleDateString()).getTime() + 60 * 60 * 24 * 1000*days-1
         this.$axios.get("/comprehensiveContrast/getSpeedColumn").then(res => {
@@ -489,7 +443,7 @@ export default {
       if (isNaN(this.nwpAgo)) {
         this.nwpAgo = 1
       }
-      this.$axios.get('realTimeComprehensiveContrast/' + startTime + '/' + endTime + '/' + this.equipmentId + '/' + this.electricField.electricFieldTypeEnum + '/' + this.jgTime).then((res) => {
+      this.$axios.get('realTimeComprehensiveContrastOne/' + startTime + '/' + endTime + '/' + this.equipmentId + '/' + this.electricField.electricFieldTypeEnum + '/' + this.jgTime).then((res) => {
 
         this.tableColumn = [
           { field: 'times', title: '时间', width:200},
@@ -501,8 +455,6 @@ export default {
           }
           this.tableColumn.push(colunm)
         }
-
-
         this.drawData = {
           times: [],
           realValue: [],

+ 4 - 167
ipfcst/ipfcst-reportquery/src/main/frontend/views/contrastRealTimeQueryTwo/index.vue

@@ -59,56 +59,10 @@
       <div class="toolbar" v-show="this.showToolBar">
         <vxe-toolbar ref="nwpToolBar" custom></vxe-toolbar>
       </div>
-      <div class="timeQuery">
-        <el-button size="small" :loading="loading" @click="dialogVisible = true">显示设置</el-button>
-      </div>
 
     </div>
 
 
-    <el-dialog
-      title="选择数据类型"
-      :visible.sync="dialogVisible"
-      :before-close="this.cancelDisplay"
-      width="50%">
-      <div class="drag-box-item">
-        <div class="item-title">隐藏</div>
-
-        <draggable class="list-group" :list="listh" group="people" @change="log">
-          <transition-group id="done" tag="div" class="item-ul">
-            <div
-              v-for="(element, index) in listh"
-              :key="element.value"
-              class="drag-list"
-            >
-              {{ element.key }}
-            </div>
-          </transition-group>
-        </draggable>
-
-      </div>
-      <div class="drag-box-item">
-        <div class="item-title">展示</div>
-
-        <draggable class="list-group" :list="lists" group="people" @change="log">
-          <transition-group id="wdtodo" tag="div" class="item-ul">
-            <div
-              v-for="(element, index) in lists"
-              :key="element.value"
-              class="drag-list"
-            >
-              {{ element.key }}
-            </div>
-          </transition-group>
-        </draggable>
-      </div>
-      <span slot="footer" class="dialog-footer">
-        <el-button @click="this.initShow" style="color: #3d1f25">初始化</el-button>
-    <el-button @click="this.cancelDisplay" style="color: #1f2d3d">取 消</el-button>
-    <el-button type="primary" style="color: #1f2d3d" @click="this.changeDisplay">确 定</el-button>
-  </span>
-    </el-dialog>
-
     <div class="content">
       <el-tabs type="card" v-model="activeName" @tab-click="Byresize">
         <el-tab-pane label="图表" name="first">
@@ -277,7 +231,7 @@ export default {
         formData.append('type', "")
         this.$axios({ // 用axios发送post请求
           method: 'post',
-          url: '/downLoadFile', // 请求地址
+          url: '/downLoadFileTwo', // 请求地址
           data: formData, // 参数
           responseType: 'blob', // 表明返回服务器返回的数据类型
           headers: {
@@ -300,7 +254,7 @@ export default {
       formData.append("jgTime",this.jgTime)
       formData.append("base64",this.base64)
       //this.$axios.get('ComprehensiveContrastExports/' + this.startTime + '/' + this.endTime + '/' + this.equipmentId + '/' + this.electricField.electricFieldTypeEnum + '/' + this.jgTime+ '/' +this.base64+ '/' +this.width+ '/' +this.height, {
-      this.$axios.post('/ComprehensiveContrastExports', formData).then((response) => {
+      this.$axios.post('/ComprehensiveContrastTwoExports', formData).then((response) => {
         this.downloadFile(response.data)
       }).then((response) => {
         this.loading = false
@@ -310,7 +264,7 @@ export default {
       })
     },
     init() {
-      this.$axios.get("nwp/getNwpDay").then(res=>{
+      this.$axios.get("nwpTwo/getNwpDay").then(res=>{
         var days = res.data + 1
         this.endTime = new Date(new Date().toLocaleDateString()).getTime() + 60 * 60 * 24 * 1000*days-1
         this.$axios.get("/comprehensiveContrast/getSpeedColumn").then(res => {
@@ -489,7 +443,7 @@ export default {
       if (isNaN(this.nwpAgo)) {
         this.nwpAgo = 1
       }
-      this.$axios.get('realTimeComprehensiveContrast/' + startTime + '/' + endTime + '/' + this.equipmentId + '/' + this.electricField.electricFieldTypeEnum + '/' + this.jgTime).then((res) => {
+      this.$axios.get('realTimeComprehensiveContrastTwo/' + startTime + '/' + endTime + '/' + this.equipmentId + '/' + this.electricField.electricFieldTypeEnum + '/' + this.jgTime).then((res) => {
 
         this.tableColumn = [
           { field: 'times', title: '时间', width:200},
@@ -501,8 +455,6 @@ export default {
           }
           this.tableColumn.push(colunm)
         }
-
-
         this.drawData = {
           times: [],
           realValue: [],
@@ -671,121 +623,6 @@ export default {
 </script>
 
 <style scoped>
-/*.chart-container {*/
-  /*position: relative;*/
-  /*width: 100%;*/
-  /*height: calc(100vh - 50px);*/
-/*}*/
-
-/*.filter {*/
-  /*position: relative;*/
-  /*display: flex;*/
-  /*padding: 20px 0 10px 15px;*/
-  /*font-size: 12px;*/
-  /*line-height: 11px;*/
-  /*color: white;*/
-/*}*/
-
-/*input {*/
-  /*background: transparent;*/
-  /*border: none;*/
-  /*color: white;*/
-/*}*/
-
-/*.timeText {*/
-  /*opacity: 0.69;*/
-  /*padding-right: 7px;*/
-  /*font-size: 14px;*/
-/*}*/
-
-/*.startTime {*/
-  /*display: inline-block;*/
-/*}*/
-
-/*.endTime {*/
-  /*display: inline-block;*/
-  /*padding-left: 42px;*/
-/*}*/
-
-
-/*.timeQuery {*/
-  /*background: transparent;*/
-/*}*/
-
-/*.el-button {*/
-  /*background: transparent;*/
-  /*color: white;*/
-/*}*/
-
-/*.filter {*/
-  /*width: 100%;*/
-  /*background-color: transparent;*/
-  /*height: 10%*/
-/*}*/
-
-/*.filter >>> input {*/
-  /*background: transparent;*/
-  /*border: none;*/
-  /*color: white;*/
-/*}*/
-
-/*.content {*/
-  /*width: 100%;*/
-  /*background-color: transparent;*/
-  /*height: 90%;*/
-  /*padding-left: 5px;*/
-  /*padding-right: 5px;*/
-/*}*/
-
-/*.content >>> .el-tabs__item {*/
-  /*color: white;*/
-/*}*/
-
-/*.content >>> .el-tabs__item.is-active {*/
-  /*color: #409EFF;*/
-/*}*/
-
-
-/*.tableContent {*/
-  /*width: 100%;*/
-  /*height: calc(80vh - 50px);*/
-/*}*/
-
-/*.tableContent >>> td {*/
-  /*border: 1px solid #ffffff;*/
-/*}*/
-
-/*.rtPageturning >>> button,*/
-/*.rtPageturning >>> span,*/
-/*.rtPageturning >>> input,*/
-/*.rtPageturning >>> .vxe-pager--btn-wrapper li {*/
-  /*background-color: transparent !important;*/
-  /*color: #ffffff !important;*/
-  /*border: 1px solid #ffffff;*/
-/*}*/
-
-/*.rtPageturning >>> span {*/
-  /*border: none*/
-/*}*/
-
-/*.rtPageturning >>> .vxe-pager--wrapper .vxe-pager--btn-wrapper li:not(.disabled).is--active {*/
-  /*background-color: #9f9fa0 !important;*/
-/*}*/
-
-/*.toolbar {*/
-  /*position: absolute;*/
-  /*right: 0px;*/
-/*}*/
-
-/*.toolbar >>> .vxe-button.type--button.is--circle {*/
-  /*padding: 0 .5em;*/
-  /*min-width: 34px;*/
-  /*border-radius: 10%;*/
-  /*border: none;*/
-  /*background: transparent;*/
-  /*color: white;*/
-/*}*/
-
 .drag-box-item {
   /*margin:10px;*/
   flex: 1;

+ 327 - 0
ipfcst/ipfcst-reportquery/src/main/java/com/jiayue/ipfcst/controller/RealTimeComprehensiveContrastOneController.java

@@ -0,0 +1,327 @@
+package com.jiayue.ipfcst.controller;
+
+import com.jiayue.ipfcst.common.core.web.vo.ResponseVO;
+import com.jiayue.ipfcst.common.data.entity.DisplayConfig;
+import com.jiayue.ipfcst.common.data.entity.ElectricField;
+import com.jiayue.ipfcst.common.data.repository.SysParameterRepository;
+import com.jiayue.ipfcst.service.*;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.poi.hssf.usermodel.*;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RestController;
+import sun.misc.BASE64Decoder;
+
+import javax.imageio.ImageIO;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.awt.image.BufferedImage;
+import java.io.*;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+import java.text.SimpleDateFormat;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 实时对比查询restful接口
+ *
+ * @author tl
+ * @version 1.0
+ * @since 2019/8/7 10:12
+ */
+@RestController
+@Slf4j
+public class RealTimeComprehensiveContrastOneController {
+  private final DisplayConfigService displayConfigService;
+  private final RealTimeComprehensiveContrastOneService realTimeComprehensiveContrastOneService;
+  private final ElectricFieldService electricFieldService;
+
+  @Autowired
+  public RealTimeComprehensiveContrastOneController(DisplayConfigService displayConfigService,
+                                                    RealTimeComprehensiveContrastOneService realTimeComprehensiveContrastOneService,
+                                                    ElectricFieldService electricFieldService) {
+
+
+    this.displayConfigService = displayConfigService;
+    this.realTimeComprehensiveContrastOneService = realTimeComprehensiveContrastOneService;
+    this.electricFieldService = electricFieldService;
+  }
+
+  /**
+   * 综合数据对比查询
+   *
+   * @param startTime 开始时间
+   * @param endTime   结束时间
+   * @param no
+   * @return
+   */
+  @GetMapping(value = "realTimeComprehensiveContrastOne/{startTime}/{endTime}/{no}/{otherType}/{jgTime}")
+  public ResponseVO realTimeComprehensiveQueryForcharts(@PathVariable("startTime") Long startTime,
+                                                        @PathVariable("endTime") Long endTime,
+                                                        @PathVariable("no") Integer no,
+                                                        @PathVariable("otherType") String otherType,
+                                                        @PathVariable("jgTime") Long jgTime
+
+  ) throws Exception {
+    return ResponseVO.success(realTimeComprehensiveContrastOneService.realTimeComprehensiveContrast(startTime, endTime, no, otherType, jgTime));
+  }
+
+
+  /**
+   * 综合数据对比查询
+   *
+   * @param startTime 开始时间
+   * @param endTime   结束时间
+   * @param no
+   * @return
+   */
+  @GetMapping(value = "realTimeComprehensiveContrastOneExport/{startTime}/{endTime}/{no}/{otherType}/{jgTime}")
+  public ResponseVO export(@PathVariable("startTime") Long startTime,
+                           @PathVariable("endTime") Long endTime,
+                           @PathVariable("no") Integer no,
+                           @PathVariable("otherType") String otherType,
+                           @PathVariable("jgTime") Long jgTime,
+                           HttpServletResponse response
+
+  ) throws Exception {
+
+    Map<String, Object> map = realTimeComprehensiveContrastOneService.realTimeComprehensiveContrast(startTime, endTime, no, otherType, jgTime);
+
+    BufferedOutputStream bos = null;
+    try {
+      StringBuilder templateContent = new StringBuilder();
+      response.setCharacterEncoding("UTF-8");
+      ElectricField electricField = electricFieldService.get();
+      DisplayConfig displayConfig = null;
+      displayConfig = displayConfigService.findByDisplayCode("rtWindTowerInfos");
+      String showCode = displayConfig.getShowCode();
+      String[] split = showCode.split(",");
+      String header = "\"时间\",";
+      for (int i = 0; i < split.length; i++) {
+        switch (split[i]) {
+          case "realValue":
+            header += "\"实际功率\",";
+            break;
+          case "rDq":
+            header += "\"实时短期\",";
+            break;
+        }
+      }
+      header += "\r\n";
+      List<Map<String, Float>> tableResult = (List<Map<String, Float>>) map.get("tableResult");
+      List<Map<String, Float>> resultList = (List<Map<String, Float>>) map.get("resultList");
+
+      templateContent.append(header);
+      for (int i = 0; i < tableResult.size(); i++) {
+        StringBuilder content = new StringBuilder();
+
+        content.append(tableResult.get(i).get("time") + ",");
+
+        for (int n = 0; n < split.length; n++) {
+          switch (split[n]) {
+            case "realValue":
+              content.append(tableResult.get(i).get("realValue") + ",");
+              break;
+            case "rDq":
+              content.append(tableResult.get(i).get("rDq") + ",");
+              break;
+          }
+        }
+        content.append("\r\n");
+        templateContent.append(content.toString());
+      }
+
+      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+
+      response.setContentType("application/x-msdownload;charset=UTF-8");// 文件下载必须配置为application/x-msdownload
+      response.setHeader("Content-disposition", "attachment; filename=" + URLEncoder.encode(sdf.format(startTime) + "至" + sdf.format(endTime) + "实时预测查询导出文件" + ".csv", "UTF-8"));// 中文文件名必须使用URLEncoder.encode进行转码
+      byte[] templateContentBytes = templateContent.toString().getBytes("UTF-8");
+      bos = new BufferedOutputStream(response.getOutputStream());// 向response中写入文件流
+      bos.write(new byte[]{(byte) 0xEF, (byte) 0xBB, (byte) 0xBF});// 指定csv文件用UTF-8字符集打开
+      bos.write(templateContentBytes);
+      response.flushBuffer();
+      templateContent = null;
+
+    } catch (Exception e) {
+      log.error("系统错误:" + e.getMessage(), e);
+      throw new RuntimeException(e);
+    } finally {
+      if (bos != null) {
+        try {
+          bos.close();
+        } catch (IOException e) {
+          log.error("系统错误:" + e.getMessage(), e);
+        }
+      }
+    }
+
+
+    return ResponseVO.success();
+  }
+
+  @PostMapping(value = "/ComprehensiveContrastOneExports")
+  public ResponseVO exportExcelForImg(Long startTime,
+                                      Long endTime,
+                                      Integer no,
+                                      String otherType,
+                                      Long jgTime,
+                                      String base64) throws Exception {
+    //创建Excel工作簿,xls格式用HSSFWorkbook,xlsx格式用SXSSFWorkbook
+    HSSFWorkbook wb = new HSSFWorkbook();
+    //创建sheet页
+    HSSFSheet sheet = wb.createSheet();
+    //创建绘图(画布),注明:一个sheet只能创建一个画布,但一个画布中可以添加多张图片
+    HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
+    String fileContent;
+    // 图片编码只要‘base64,’后面的部分
+    fileContent = URLDecoder.decode(base64, "UTF-8").substring(22);
+
+    //#########################插入数据#########################
+    Map<String, Object> map = realTimeComprehensiveContrastOneService.realTimeComprehensiveContrast(startTime, endTime, no, otherType, jgTime);
+    BufferedOutputStream bos = null;
+    StringBuilder templateContent = new StringBuilder();
+    ElectricField electricField = electricFieldService.get();
+    DisplayConfig displayConfig = null;
+    displayConfig = displayConfigService.findByDisplayCode("rtWindTowerInfos");
+    String showCode = displayConfig.getShowCode();
+    String[] split = showCode.split(",");
+    //创建第一行 0为第一行
+    HSSFRow row1 = sheet.createRow(0);
+    //设置第一个单元格
+    row1.createCell(0).setCellValue("时间");
+    int flag = 1;
+    String displayKyLl = (String) map.get("displayKyLl");
+
+    for (int i = 0; i < split.length; i++) {
+      switch (split[i]) {
+        case "realValue":
+          row1.createCell(flag).setCellValue("实际功率");
+          flag++;
+          break;
+        case "rDq":
+          row1.createCell(flag).setCellValue("实时短期");
+          flag++;
+          break;
+      }
+    }
+    List<Map<String, Float>> tableResult = (List<Map<String, Float>>) map.get("tableResult");
+    List<Map<String, Float>> resultList = (List<Map<String, Float>>) map.get("resultList");
+
+    for (int i = 0; i < tableResult.size(); i++) {
+      int flags = 0;
+      HSSFRow row = sheet.createRow(i + 1);
+      row.createCell(flags).setCellValue(String.valueOf(tableResult.get(i).get("time")));
+      flags++;
+      for (int n = 0; n < split.length; n++) {
+        switch (split[n]) {
+          case "realValue":
+            row.createCell(flags).setCellValue(String.valueOf(tableResult.get(i).get("realValue")));
+            flags++;
+            break;
+
+          case "rDq":
+            row.createCell(flags).setCellValue(String.valueOf(tableResult.get(i).get("rDq")));
+            flags++;
+            break;
+        }
+      }
+    }
+
+    //画图
+    createPictureInExcel(fileContent, patriarch, wb);
+    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+    String filename = sdf.format(startTime) + "至" + sdf.format(endTime) + "实时预测查询导出文件" + ".xls";
+    File filepath = new File("/home/syjy/ipfcstV3/reportForm/");
+    File file = new File("/home/syjy/ipfcstV3/reportForm/", filename);
+    //File file = new File("/Users/wanghongchen/"+filename);
+    if (!filepath.exists()) {
+      filepath.mkdir();
+    }
+    if (!file.exists()) {
+      file.createNewFile();
+    }
+    OutputStream out = new FileOutputStream(file);
+    wb.write(out);
+    wb.close();
+    return ResponseVO.success(filename);
+    //将文件生成到本地 读取本地文件调用浏览器下载
+  }
+
+  public static void createPictureInExcel(String dataChart, HSSFPatriarch patriarch, HSSFWorkbook wb) throws Exception {
+    //用于将BASE64编码格式转为byte数组
+    BASE64Decoder base64Decoder = new BASE64Decoder();
+    ByteArrayOutputStream dataChartoutStream = new ByteArrayOutputStream();
+    //将dataChartStringin作为输入流,读取图片存入image中
+    ByteArrayInputStream dataChartin = new ByteArrayInputStream(base64Decoder.decodeBuffer(dataChart));
+
+    BufferedImage dataChartbufferImg = ImageIO.read(dataChartin);
+    //利用HSSFPatriarch将图片写入EXCEL
+    ImageIO.write(dataChartbufferImg, "png", dataChartoutStream);
+    /*
+     * 指定绘图区域位置及大小
+     * HSSFClientAnchor(int dx1, int dy1, int dx2, int dy2, short col1, int row1, short col2, int row2)
+     * 参数说明:
+     * dx1 dy1 起始单元格中的x,y坐标.
+     * dx2 dy2 结束单元格中的x,y坐标.
+     * col1,row1 指定起始的单元格,下标从0开始.
+     * col2,row2 指定结束的单元格 ,下标从0开始.
+     */
+    HSSFClientAnchor anchorCostStr = new HSSFClientAnchor(10, 10, 255, 255, (short) 10, 10, (short) 20, 28);
+    //画图
+    patriarch.createPicture(anchorCostStr, wb.addPicture(dataChartoutStream.toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG));
+  }
+
+  /**
+   * 文件下载
+   *
+   * @param request  HttpServletRequest
+   * @param response HttpServletResponse
+   * @param path     路径
+   * @param name     文件名
+   * @param type     文件类型
+   */
+  @PostMapping(value = "/downLoadFileOne")
+  public void downLoadFile(HttpServletRequest request,
+                           HttpServletResponse response,
+                           String path,
+                           String name,
+                           String type) {
+    response.setContentType("text/html;charset=utf-8");
+    try {
+      request.setCharacterEncoding("UTF-8");
+    } catch (UnsupportedEncodingException e1) {
+      log.error("系统错误:" + e1.getMessage(), e1);
+    }
+
+    String downLoadPath = path + File.separator + name;
+    if (name.isEmpty()) {//传入name为空,说明是一级目录,路径中已经包涵最后一级目录
+      name = path.substring(path.lastIndexOf(File.separator) + 1, path.length());
+      downLoadPath = path;
+    }
+    try {
+      File df = new File(downLoadPath);
+      InputStream ins = new FileInputStream(df);
+      BufferedInputStream bins = new BufferedInputStream(ins);
+      OutputStream outs = response.getOutputStream();
+      BufferedOutputStream bouts = new BufferedOutputStream(outs);
+      response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(name, "UTF-8"));
+      response.setContentType("application/x-msdownload; charset=utf-8");
+      int bytesRead = 0;
+      byte[] buffer = new byte[8192];
+      while ((bytesRead = bins.read(buffer, 0, 8192)) != -1) {
+        bouts.write(buffer, 0, bytesRead);
+      }
+      bouts.flush();
+      ins.close();
+      bins.close();
+      bouts.close();
+      File deleteFile = new File(downLoadPath);
+      deleteFile.delete();
+    } catch (Exception e) {
+      log.error("系统错误:" + e.getMessage(), e);
+    }
+  }
+}

+ 328 - 0
ipfcst/ipfcst-reportquery/src/main/java/com/jiayue/ipfcst/controller/RealTimeComprehensiveContrastTwoController.java

@@ -0,0 +1,328 @@
+package com.jiayue.ipfcst.controller;
+
+import com.jiayue.ipfcst.common.core.web.vo.ResponseVO;
+import com.jiayue.ipfcst.common.data.entity.DisplayConfig;
+import com.jiayue.ipfcst.common.data.entity.ElectricField;
+import com.jiayue.ipfcst.common.data.repository.SysParameterRepository;
+import com.jiayue.ipfcst.service.*;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.poi.hssf.usermodel.*;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RestController;
+import sun.misc.BASE64Decoder;
+
+import javax.imageio.ImageIO;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.awt.image.BufferedImage;
+import java.io.*;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+import java.text.SimpleDateFormat;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 实时对比查询restful接口
+ *
+ * @author tl
+ * @version 1.0
+ * @since 2019/8/7 10:12
+ */
+@RestController
+@Slf4j
+public class RealTimeComprehensiveContrastTwoController {
+  private final DisplayConfigService displayConfigService;
+  private final RealTimeComprehensiveContrastTwoService realTimeComprehensiveContrastTwoService;
+  private final ElectricFieldService electricFieldService;
+
+  @Autowired
+  public RealTimeComprehensiveContrastTwoController(
+    DisplayConfigService displayConfigService,
+    RealTimeComprehensiveContrastTwoService realTimeComprehensiveContrastTwoService,
+    ElectricFieldService electricFieldService) {
+
+    this.displayConfigService = displayConfigService;
+    this.realTimeComprehensiveContrastTwoService = realTimeComprehensiveContrastTwoService;
+    this.electricFieldService = electricFieldService;
+  }
+
+  /**
+   * 综合数据对比查询
+   *
+   * @param startTime 开始时间
+   * @param endTime   结束时间
+   * @param no
+   * @return
+   */
+  @GetMapping(value = "realTimeComprehensiveContrastTwo/{startTime}/{endTime}/{no}/{otherType}/{jgTime}")
+  public ResponseVO realTimeComprehensiveQueryForcharts(@PathVariable("startTime") Long startTime,
+                                                        @PathVariable("endTime") Long endTime,
+                                                        @PathVariable("no") Integer no,
+                                                        @PathVariable("otherType") String otherType,
+                                                        @PathVariable("jgTime") Long jgTime
+
+  ) throws Exception {
+    return ResponseVO.success(realTimeComprehensiveContrastTwoService.realTimeComprehensiveContrast(startTime, endTime, no, otherType, jgTime));
+  }
+
+
+  /**
+   * 综合数据对比查询
+   *
+   * @param startTime 开始时间
+   * @param endTime   结束时间
+   * @param no
+   * @return
+   */
+  @GetMapping(value = "realTimeComprehensiveContrastTwoExport/{startTime}/{endTime}/{no}/{otherType}/{jgTime}")
+  public ResponseVO export(@PathVariable("startTime") Long startTime,
+                           @PathVariable("endTime") Long endTime,
+                           @PathVariable("no") Integer no,
+                           @PathVariable("otherType") String otherType,
+                           @PathVariable("jgTime") Long jgTime,
+                           HttpServletResponse response
+
+  ) throws Exception {
+
+    Map<String, Object> map = realTimeComprehensiveContrastTwoService.realTimeComprehensiveContrast(startTime, endTime, no, otherType, jgTime);
+
+    BufferedOutputStream bos = null;
+    try {
+      StringBuilder templateContent = new StringBuilder();
+      response.setCharacterEncoding("UTF-8");
+      ElectricField electricField = electricFieldService.get();
+      DisplayConfig displayConfig = null;
+      displayConfig = displayConfigService.findByDisplayCode("rtWindTowerInfos");
+      String showCode = displayConfig.getShowCode();
+      String[] split = showCode.split(",");
+      String header = "\"时间\",";
+      for (int i = 0; i < split.length; i++) {
+        switch (split[i]) {
+          case "realValue":
+            header += "\"实际功率\",";
+            break;
+          case "rDq":
+            header += "\"实时短期\",";
+            break;
+        }
+      }
+      header += "\r\n";
+      List<Map<String, Float>> tableResult = (List<Map<String, Float>>) map.get("tableResult");
+      List<Map<String, Float>> resultList = (List<Map<String, Float>>) map.get("resultList");
+
+      templateContent.append(header);
+      for (int i = 0; i < tableResult.size(); i++) {
+        StringBuilder content = new StringBuilder();
+
+        content.append(tableResult.get(i).get("time") + ",");
+
+        for (int n = 0; n < split.length; n++) {
+          switch (split[n]) {
+            case "realValue":
+              content.append(tableResult.get(i).get("realValue") + ",");
+              break;
+            case "rDq":
+              content.append(tableResult.get(i).get("rDq") + ",");
+              break;
+          }
+        }
+        content.append("\r\n");
+        templateContent.append(content.toString());
+      }
+
+
+      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+
+      response.setContentType("application/x-msdownload;charset=UTF-8");// 文件下载必须配置为application/x-msdownload
+      response.setHeader("Content-disposition", "attachment; filename=" + URLEncoder.encode(sdf.format(startTime) + "至" + sdf.format(endTime) + "实时预测查询导出文件" + ".csv", "UTF-8"));// 中文文件名必须使用URLEncoder.encode进行转码
+      byte[] templateContentBytes = templateContent.toString().getBytes("UTF-8");
+      bos = new BufferedOutputStream(response.getOutputStream());// 向response中写入文件流
+      bos.write(new byte[]{(byte) 0xEF, (byte) 0xBB, (byte) 0xBF});// 指定csv文件用UTF-8字符集打开
+      bos.write(templateContentBytes);
+      response.flushBuffer();
+      templateContent = null;
+
+    } catch (Exception e) {
+      log.error("系统错误:" + e.getMessage(), e);
+      throw new RuntimeException(e);
+    } finally {
+      if (bos != null) {
+        try {
+          bos.close();
+        } catch (IOException e) {
+          log.error("系统错误:" + e.getMessage(), e);
+        }
+      }
+    }
+
+
+    return ResponseVO.success();
+  }
+
+  @PostMapping(value = "/ComprehensiveContrastTwoExports")
+  public ResponseVO exportExcelForImg(Long startTime,
+                                      Long endTime,
+                                      Integer no,
+                                      String otherType,
+                                      Long jgTime,
+                                      String base64) throws Exception {
+    //创建Excel工作簿,xls格式用HSSFWorkbook,xlsx格式用SXSSFWorkbook
+    HSSFWorkbook wb = new HSSFWorkbook();
+    //创建sheet页
+    HSSFSheet sheet = wb.createSheet();
+    //创建绘图(画布),注明:一个sheet只能创建一个画布,但一个画布中可以添加多张图片
+    HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
+    String fileContent;
+    // 图片编码只要‘base64,’后面的部分
+    fileContent = URLDecoder.decode(base64, "UTF-8").substring(22);
+
+    //#########################插入数据#########################
+    Map<String, Object> map = realTimeComprehensiveContrastTwoService.realTimeComprehensiveContrast(startTime, endTime, no, otherType, jgTime);
+    BufferedOutputStream bos = null;
+    StringBuilder templateContent = new StringBuilder();
+    ElectricField electricField = electricFieldService.get();
+    DisplayConfig displayConfig = null;
+    displayConfig = displayConfigService.findByDisplayCode("rtWindTowerInfos");
+    String showCode = displayConfig.getShowCode();
+    String[] split = showCode.split(",");
+    //创建第一行 0为第一行
+    HSSFRow row1 = sheet.createRow(0);
+    //设置第一个单元格
+    row1.createCell(0).setCellValue("时间");
+    int flag = 1;
+    String displayKyLl = (String) map.get("displayKyLl");
+
+    for (int i = 0; i < split.length; i++) {
+      switch (split[i]) {
+        case "realValue":
+          row1.createCell(flag).setCellValue("实际功率");
+          flag++;
+          break;
+        case "rDq":
+          row1.createCell(flag).setCellValue("实时短期");
+          flag++;
+          break;
+      }
+    }
+    List<Map<String, Float>> tableResult = (List<Map<String, Float>>) map.get("tableResult");
+    List<Map<String, Float>> resultList = (List<Map<String, Float>>) map.get("resultList");
+
+    for (int i = 0; i < tableResult.size(); i++) {
+      int flags = 0;
+      HSSFRow row = sheet.createRow(i + 1);
+      row.createCell(flags).setCellValue(String.valueOf(tableResult.get(i).get("time")));
+      flags++;
+      for (int n = 0; n < split.length; n++) {
+        switch (split[n]) {
+          case "realValue":
+            row.createCell(flags).setCellValue(String.valueOf(tableResult.get(i).get("realValue")));
+            flags++;
+            break;
+
+          case "rDq":
+            row.createCell(flags).setCellValue(String.valueOf(tableResult.get(i).get("rDq")));
+            flags++;
+            break;
+        }
+      }
+    }
+
+    //画图
+    createPictureInExcel(fileContent, patriarch, wb);
+    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+    String filename = sdf.format(startTime) + "至" + sdf.format(endTime) + "实时预测查询导出文件" + ".xls";
+    File filepath = new File("/home/syjy/ipfcstV3/reportForm/");
+    File file = new File("/home/syjy/ipfcstV3/reportForm/", filename);
+    //File file = new File("/Users/wanghongchen/"+filename);
+    if (!filepath.exists()) {
+      filepath.mkdir();
+    }
+    if (!file.exists()) {
+      file.createNewFile();
+    }
+    OutputStream out = new FileOutputStream(file);
+    wb.write(out);
+    wb.close();
+    return ResponseVO.success(filename);
+    //将文件生成到本地 读取本地文件调用浏览器下载
+  }
+
+  public static void createPictureInExcel(String dataChart, HSSFPatriarch patriarch, HSSFWorkbook wb) throws Exception {
+    //用于将BASE64编码格式转为byte数组
+    BASE64Decoder base64Decoder = new BASE64Decoder();
+    ByteArrayOutputStream dataChartoutStream = new ByteArrayOutputStream();
+    //将dataChartStringin作为输入流,读取图片存入image中
+    ByteArrayInputStream dataChartin = new ByteArrayInputStream(base64Decoder.decodeBuffer(dataChart));
+
+    BufferedImage dataChartbufferImg = ImageIO.read(dataChartin);
+    //利用HSSFPatriarch将图片写入EXCEL
+    ImageIO.write(dataChartbufferImg, "png", dataChartoutStream);
+    /*
+     * 指定绘图区域位置及大小
+     * HSSFClientAnchor(int dx1, int dy1, int dx2, int dy2, short col1, int row1, short col2, int row2)
+     * 参数说明:
+     * dx1 dy1 起始单元格中的x,y坐标.
+     * dx2 dy2 结束单元格中的x,y坐标.
+     * col1,row1 指定起始的单元格,下标从0开始.
+     * col2,row2 指定结束的单元格 ,下标从0开始.
+     */
+    HSSFClientAnchor anchorCostStr = new HSSFClientAnchor(10, 10, 255, 255, (short) 10, 10, (short) 20, 28);
+    //画图
+    patriarch.createPicture(anchorCostStr, wb.addPicture(dataChartoutStream.toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG));
+  }
+
+  /**
+   * 文件下载
+   *
+   * @param request  HttpServletRequest
+   * @param response HttpServletResponse
+   * @param path     路径
+   * @param name     文件名
+   * @param type     文件类型
+   */
+  @PostMapping(value = "/downLoadFileTwo")
+  public void downLoadFile(HttpServletRequest request,
+                           HttpServletResponse response,
+                           String path,
+                           String name,
+                           String type) {
+    response.setContentType("text/html;charset=utf-8");
+    try {
+      request.setCharacterEncoding("UTF-8");
+    } catch (UnsupportedEncodingException e1) {
+      log.error("系统错误:" + e1.getMessage(), e1);
+    }
+
+    String downLoadPath = path + File.separator + name;
+    if (name.isEmpty()) {//传入name为空,说明是一级目录,路径中已经包涵最后一级目录
+      name = path.substring(path.lastIndexOf(File.separator) + 1, path.length());
+      downLoadPath = path;
+    }
+    try {
+      File df = new File(downLoadPath);
+      InputStream ins = new FileInputStream(df);
+      BufferedInputStream bins = new BufferedInputStream(ins);
+      OutputStream outs = response.getOutputStream();
+      BufferedOutputStream bouts = new BufferedOutputStream(outs);
+      response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(name, "UTF-8"));
+      response.setContentType("application/x-msdownload; charset=utf-8");
+      int bytesRead = 0;
+      byte[] buffer = new byte[8192];
+      while ((bytesRead = bins.read(buffer, 0, 8192)) != -1) {
+        bouts.write(buffer, 0, bytesRead);
+      }
+      bouts.flush();
+      ins.close();
+      bins.close();
+      bouts.close();
+      File deleteFile = new File(downLoadPath);
+      deleteFile.delete();
+    } catch (Exception e) {
+      log.error("系统错误:" + e.getMessage(), e);
+    }
+  }
+}

+ 199 - 0
ipfcst/ipfcst-reportquery/src/main/java/com/jiayue/ipfcst/service/ForecastPowerShortTermOneService.java

@@ -0,0 +1,199 @@
+package com.jiayue.ipfcst.service;
+
+import com.jiayue.ipfcst.common.core.exception.BusinessException;
+import com.jiayue.ipfcst.common.data.entity.ElectricField;
+import com.jiayue.ipfcst.common.data.entity.ForecastPowerShortTermOne;
+import com.jiayue.ipfcst.common.data.repository.ForecastPowerShortTermOneRepository;
+import com.jiayue.ipfcst.common.data.repository.PowerStationStatusDataRepository;
+import com.jiayue.ipfcst.common.data.service.BaseService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.persistence.criteria.Predicate;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * 短期预测实时业务层(一期)
+ *
+ * @author yh
+ * @version 1.0
+ * @since 2019/8/5 16:02
+ */
+@Service
+public class ForecastPowerShortTermOneService extends BaseService {
+
+  private final ForecastPowerShortTermOneRepository forecastPowerShortTermOneRepository;
+  private final PowerStationStatusDataRepository powerStationStatusDataRepository;
+
+  @Autowired
+  public ForecastPowerShortTermOneService(ForecastPowerShortTermOneRepository forecastPowerShortTermOneRepository, PowerStationStatusDataRepository powerStationStatusDataRepository) {
+    this.forecastPowerShortTermOneRepository = forecastPowerShortTermOneRepository;
+    this.powerStationStatusDataRepository = powerStationStatusDataRepository;
+  }
+
+  /**
+   * 按时间查询实时预测短期 yh
+   *
+   * @param startTime 开始时间
+   * @param endTime   结束时间
+   * @return 结果集
+   */
+
+  @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
+  public Map<String, Object> findByForecastTimeBetween(Long startTime, Long endTime) throws BusinessException {
+    Map<String, Object> map = new HashMap<>();
+    ElectricField electricField = super.getElectricField();
+    map.put("cap",electricField.getCapacity());
+    List<ForecastPowerShortTermOne> list = new ArrayList<>();
+    list = forecastPowerShortTermOneRepository.findByForecastTimeBetween(startTime, endTime);
+    list.sort(Comparator.comparing(ForecastPowerShortTermOne::getForecastTime));
+
+    long startTimeLong = startTime;
+    long endTimeLong = endTime;
+    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+    long timeStep = 900000L;
+    if (startTimeLong % timeStep != 0) {
+      startTimeLong = startTimeLong - (startTimeLong % timeStep)+timeStep;
+    }
+    List<Float> datas = new ArrayList<>();
+    List<String> times = new ArrayList<>();
+
+    for (long i = startTimeLong; i < endTimeLong; i = i + timeStep) {
+      long finalI = i;
+      List<ForecastPowerShortTermOne> p = list.stream().filter(t -> t.getForecastTime() == finalI).collect(Collectors.toList());
+      if (p != null && p.size() > 0) {
+        datas.add(p.get(0).getFpValue().floatValue());
+      } else {
+        datas.add(null);
+      }
+      String timeFormat = sdf.format(new Date(i));
+      times.add(timeFormat);
+    }
+    map.put("times", times);
+    map.put("datas", datas);
+    return map;
+  }
+
+
+  @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
+  public Map<String, Object> findByForecastTimeBetweenForComprehensive(Long startTime, Long endTime,Long timeStep) throws BusinessException {
+    Map<String, Object> map = new HashMap<>();
+    List<ForecastPowerShortTermOne> list = new ArrayList<>();
+    list = forecastPowerShortTermOneRepository.findByForecastTimeBetween(startTime, endTime);
+    list.sort(Comparator.comparing(ForecastPowerShortTermOne::getForecastTime));
+
+    long startTimeLong = startTime;
+    long endTimeLong = endTime;
+    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+    if (startTimeLong % timeStep != 0) {
+      startTimeLong = startTimeLong - (startTimeLong % timeStep)+timeStep;
+    }
+    List<Float> datas = new ArrayList<>();
+    List<String> times = new ArrayList<>();
+
+    for (long i = startTimeLong; i < endTimeLong; i = i + timeStep) {
+      long finalI = i;
+      List<ForecastPowerShortTermOne> p = list.stream().filter(t -> t.getForecastTime() == finalI).collect(Collectors.toList());
+      if (p != null && p.size() > 0) {
+        datas.add(p.get(0).getFpValue().floatValue());
+      } else {
+        datas.add(null);
+      }
+      String timeFormat = sdf.format(new Date(i));
+      times.add(timeFormat);
+    }
+    map.put("times", times);
+    map.put("datas", datas);
+    return map;
+  }
+
+  /**
+   * 根据时间 分页查询 实时预测短期数据 yh
+   *
+   * @param startTime 开始时间
+   * @param endTime   结束时间
+   * @param page      页码
+   * @param size      条数
+   * @param sortOrder 排序
+   * @return
+   */
+  @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
+  public Map<String, Object> findByTimeBetweenAndNoForPaging(Long startTime, Long endTime,
+                                                             Integer page, Integer size,
+                                                             String sortOrder) {
+    Map<String, Object> map = new HashMap<>();
+    Sort sort = Sort.by(Sort.Direction.DESC, "forecastTime");
+    if (sortOrder.contains("asc")) {
+      sort = Sort.by(Sort.Direction.ASC, "forecastTime");
+    }
+    Specification<ForecastPowerShortTermOne> specification = this.specificationFindByTimeAndNo(startTime, endTime);
+    Pageable pageable = PageRequest.of(page - 1, size, sort);
+    Page forecastPowerShortTerms = forecastPowerShortTermOneRepository.findAll(specification, pageable);
+    List<ForecastPowerShortTermOne> datas = new ArrayList<>();
+    datas = forecastPowerShortTerms.getContent();
+    map.put("content", datas);
+    map.put("count", forecastPowerShortTerms.getTotalElements());
+    return map;
+  }
+
+  /**
+   * 根据时间和编号 分页查询条件 yh
+   *
+   * @param startTime 开始时间
+   * @param endTime   结束时间
+   * @return 过滤条件
+   */
+  Specification<ForecastPowerShortTermOne> specificationFindByTimeAndNo(final Long startTime, final Long endTime) {
+    return (Specification<ForecastPowerShortTermOne>) (root, criteriaQuery, cb) -> {
+      List<Predicate> predicates = new ArrayList<>();
+      if (startTime != null) {
+        //大于或等于传入时间
+        predicates.add(cb.greaterThanOrEqualTo(root.get("forecastTime").as(Long.class), startTime));
+      }
+      if (endTime != null) {
+        //小于传入时间
+        predicates.add(cb.lessThan(root.get("forecastTime").as(Long.class), endTime));
+      }
+
+      //添加排序的功能
+      return cb.and(predicates.toArray(new Predicate[predicates.size()]));
+
+    };
+  }
+
+  /**
+   * 查询回传数据
+   * @param stTime         开始时间
+   * @param eTime          结束时间
+   * @return
+   */
+  @Transactional(propagation = Propagation.REQUIRED)
+  public String[] findSendData(Long stTime,Long eTime,List<ForecastPowerShortTermOne> list){
+
+    List<ForecastPowerShortTermOne> collect = list.stream().filter(s -> s.getForecastTime() >= stTime && s.getForecastTime() <= eTime).collect(Collectors.toList());
+    String[] datas = new String[list.size()];
+    if(null != collect && collect.size() > 0){
+      int index = 0;
+      for(ForecastPowerShortTermOne f:collect){
+        datas[index] = String.valueOf(f.getFpValue());
+        index++;
+      }
+    }
+    return datas;
+  }
+
+  @Transactional(propagation = Propagation.REQUIRED)
+  public List<ForecastPowerShortTermOne> findSendDataForTimeBetween(Long stTime,Long eTime){
+    return forecastPowerShortTermOneRepository.findByForecastTimeBetween(stTime,eTime);
+  }
+
+}

+ 199 - 0
ipfcst/ipfcst-reportquery/src/main/java/com/jiayue/ipfcst/service/ForecastPowerShortTermTwoService.java

@@ -0,0 +1,199 @@
+package com.jiayue.ipfcst.service;
+
+import com.jiayue.ipfcst.common.core.exception.BusinessException;
+import com.jiayue.ipfcst.common.data.entity.ElectricField;
+import com.jiayue.ipfcst.common.data.entity.ForecastPowerShortTermTwo;
+import com.jiayue.ipfcst.common.data.repository.ForecastPowerShortTermTwoRepository;
+import com.jiayue.ipfcst.common.data.repository.PowerStationStatusDataRepository;
+import com.jiayue.ipfcst.common.data.service.BaseService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.persistence.criteria.Predicate;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * 短期预测实时业务层(一期)
+ *
+ * @author yh
+ * @version 1.0
+ * @since 2019/8/5 16:02
+ */
+@Service
+public class ForecastPowerShortTermTwoService extends BaseService {
+
+  private final ForecastPowerShortTermTwoRepository ForecastPowerShortTermTwoRepository;
+  private final PowerStationStatusDataRepository powerStationStatusDataRepository;
+
+  @Autowired
+  public ForecastPowerShortTermTwoService(ForecastPowerShortTermTwoRepository ForecastPowerShortTermTwoRepository, PowerStationStatusDataRepository powerStationStatusDataRepository) {
+    this.ForecastPowerShortTermTwoRepository = ForecastPowerShortTermTwoRepository;
+    this.powerStationStatusDataRepository = powerStationStatusDataRepository;
+  }
+
+  /**
+   * 按时间查询实时预测短期 yh
+   *
+   * @param startTime 开始时间
+   * @param endTime   结束时间
+   * @return 结果集
+   */
+
+  @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
+  public Map<String, Object> findByForecastTimeBetween(Long startTime, Long endTime) throws BusinessException {
+    Map<String, Object> map = new HashMap<>();
+    ElectricField electricField = super.getElectricField();
+    map.put("cap",electricField.getCapacity());
+    List<ForecastPowerShortTermTwo> list = new ArrayList<>();
+    list = ForecastPowerShortTermTwoRepository.findByForecastTimeBetween(startTime, endTime);
+    list.sort(Comparator.comparing(ForecastPowerShortTermTwo::getForecastTime));
+
+    long startTimeLong = startTime;
+    long endTimeLong = endTime;
+    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+    long timeStep = 900000L;
+    if (startTimeLong % timeStep != 0) {
+      startTimeLong = startTimeLong - (startTimeLong % timeStep)+timeStep;
+    }
+    List<Float> datas = new ArrayList<>();
+    List<String> times = new ArrayList<>();
+
+    for (long i = startTimeLong; i < endTimeLong; i = i + timeStep) {
+      long finalI = i;
+      List<ForecastPowerShortTermTwo> p = list.stream().filter(t -> t.getForecastTime() == finalI).collect(Collectors.toList());
+      if (p != null && p.size() > 0) {
+        datas.add(p.get(0).getFpValue().floatValue());
+      } else {
+        datas.add(null);
+      }
+      String timeFormat = sdf.format(new Date(i));
+      times.add(timeFormat);
+    }
+    map.put("times", times);
+    map.put("datas", datas);
+    return map;
+  }
+
+
+  @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
+  public Map<String, Object> findByForecastTimeBetweenForComprehensive(Long startTime, Long endTime,Long timeStep) throws BusinessException {
+    Map<String, Object> map = new HashMap<>();
+    List<ForecastPowerShortTermTwo> list = new ArrayList<>();
+    list = ForecastPowerShortTermTwoRepository.findByForecastTimeBetween(startTime, endTime);
+    list.sort(Comparator.comparing(ForecastPowerShortTermTwo::getForecastTime));
+
+    long startTimeLong = startTime;
+    long endTimeLong = endTime;
+    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+    if (startTimeLong % timeStep != 0) {
+      startTimeLong = startTimeLong - (startTimeLong % timeStep)+timeStep;
+    }
+    List<Float> datas = new ArrayList<>();
+    List<String> times = new ArrayList<>();
+
+    for (long i = startTimeLong; i < endTimeLong; i = i + timeStep) {
+      long finalI = i;
+      List<ForecastPowerShortTermTwo> p = list.stream().filter(t -> t.getForecastTime() == finalI).collect(Collectors.toList());
+      if (p != null && p.size() > 0) {
+        datas.add(p.get(0).getFpValue().floatValue());
+      } else {
+        datas.add(null);
+      }
+      String timeFormat = sdf.format(new Date(i));
+      times.add(timeFormat);
+    }
+    map.put("times", times);
+    map.put("datas", datas);
+    return map;
+  }
+
+  /**
+   * 根据时间 分页查询 实时预测短期数据 yh
+   *
+   * @param startTime 开始时间
+   * @param endTime   结束时间
+   * @param page      页码
+   * @param size      条数
+   * @param sortOrder 排序
+   * @return
+   */
+  @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
+  public Map<String, Object> findByTimeBetweenAndNoForPaging(Long startTime, Long endTime,
+                                                             Integer page, Integer size,
+                                                             String sortOrder) {
+    Map<String, Object> map = new HashMap<>();
+    Sort sort = Sort.by(Sort.Direction.DESC, "forecastTime");
+    if (sortOrder.contains("asc")) {
+      sort = Sort.by(Sort.Direction.ASC, "forecastTime");
+    }
+    Specification<ForecastPowerShortTermTwo> specification = this.specificationFindByTimeAndNo(startTime, endTime);
+    Pageable pageable = PageRequest.of(page - 1, size, sort);
+    Page forecastPowerShortTerms = ForecastPowerShortTermTwoRepository.findAll(specification, pageable);
+    List<ForecastPowerShortTermTwo> datas = new ArrayList<>();
+    datas = forecastPowerShortTerms.getContent();
+    map.put("content", datas);
+    map.put("count", forecastPowerShortTerms.getTotalElements());
+    return map;
+  }
+
+  /**
+   * 根据时间和编号 分页查询条件 yh
+   *
+   * @param startTime 开始时间
+   * @param endTime   结束时间
+   * @return 过滤条件
+   */
+  Specification<ForecastPowerShortTermTwo> specificationFindByTimeAndNo(final Long startTime, final Long endTime) {
+    return (Specification<ForecastPowerShortTermTwo>) (root, criteriaQuery, cb) -> {
+      List<Predicate> predicates = new ArrayList<>();
+      if (startTime != null) {
+        //大于或等于传入时间
+        predicates.add(cb.greaterThanOrEqualTo(root.get("forecastTime").as(Long.class), startTime));
+      }
+      if (endTime != null) {
+        //小于传入时间
+        predicates.add(cb.lessThan(root.get("forecastTime").as(Long.class), endTime));
+      }
+
+      //添加排序的功能
+      return cb.and(predicates.toArray(new Predicate[predicates.size()]));
+
+    };
+  }
+
+  /**
+   * 查询回传数据
+   * @param stTime         开始时间
+   * @param eTime          结束时间
+   * @return
+   */
+  @Transactional(propagation = Propagation.REQUIRED)
+  public String[] findSendData(Long stTime,Long eTime,List<ForecastPowerShortTermTwo> list){
+
+    List<ForecastPowerShortTermTwo> collect = list.stream().filter(s -> s.getForecastTime() >= stTime && s.getForecastTime() <= eTime).collect(Collectors.toList());
+    String[] datas = new String[list.size()];
+    if(null != collect && collect.size() > 0){
+      int index = 0;
+      for(ForecastPowerShortTermTwo f:collect){
+        datas[index] = String.valueOf(f.getFpValue());
+        index++;
+      }
+    }
+    return datas;
+  }
+
+  @Transactional(propagation = Propagation.REQUIRED)
+  public List<ForecastPowerShortTermTwo> findSendDataForTimeBetween(Long stTime,Long eTime){
+    return ForecastPowerShortTermTwoRepository.findByForecastTimeBetween(stTime,eTime);
+  }
+
+}

+ 84 - 0
ipfcst/ipfcst-reportquery/src/main/java/com/jiayue/ipfcst/service/RealTimeComprehensiveContrastOneService.java

@@ -0,0 +1,84 @@
+package com.jiayue.ipfcst.service;
+
+import com.jiayue.ipfcst.common.core.exception.BusinessException;
+import com.jiayue.ipfcst.common.data.entity.*;
+import com.jiayue.ipfcst.common.data.repository.SysParameterRepository;
+import com.jiayue.ipfcst.common.data.service.BaseService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.*;
+
+@Service
+public class RealTimeComprehensiveContrastOneService extends BaseService {
+
+
+  private final ForecastPowerShortTermOneService forecastPowerShortTermOneService;
+  private final PowerStationStatusDataService powerStationStatusDataService;
+  private final DisplayConfigService displayConfigService;
+
+  @Autowired
+  public RealTimeComprehensiveContrastOneService(ForecastPowerShortTermOneService forecastPowerShortTermOneService,
+                                                 PowerStationStatusDataService powerStationStatusDataService,
+                                                 DisplayConfigService displayConfigService) {
+    this.forecastPowerShortTermOneService = forecastPowerShortTermOneService;
+    this.powerStationStatusDataService = powerStationStatusDataService;
+    this.displayConfigService = displayConfigService;
+  }
+
+
+  public Map<String, Object> realTimeComprehensiveContrast(Long startTime,
+                                                           Long endTime,
+                                                           Integer no,
+                                                           String otherType,
+                                                           Long jgTime) throws BusinessException {
+    Map<String, Object> map = new HashMap<>();
+    Map<String, Object> rpMap = new HashMap<>();
+    Map<String, Object> rDqMap = new HashMap<>();
+    List<WindTowerStatusData> windTowerStatusDataList = new ArrayList<>();
+
+    rpMap = powerStationStatusDataService.findByTimeBetweenForContrast(new Date(startTime), new Date(endTime), jgTime);
+
+    rDqMap = forecastPowerShortTermOneService.findByForecastTimeBetweenForComprehensive(startTime, endTime, jgTime);
+    List<Float> rDqList = (List<Float>) rDqMap.get("datas");
+    List<String> times = new ArrayList<>();
+    List<Map<String, Object>> tableResult = new ArrayList<>();
+    times = (List<String>) rpMap.get("times");
+    List<Float> realvalueList = (List<Float>) rpMap.get("realDatas");
+
+    List<Map<String, Object>> resultList = new ArrayList<>();
+
+    String displayKyLl = "0";
+    DisplayConfig displayConfig = displayConfigService.findByDisplayCode("rtWindTowerInfos");
+    for (int i = 0; i < times.size(); i++) {
+      Map<String, Object> resultMap = new HashMap<>();
+
+      Map<String, Object> dtoMap = new HashMap<>();
+      //
+      String[] showCode = displayConfig.getShowCode().split(",");
+      dtoMap.put("time", times.get(i));
+
+      if (Arrays.asList(showCode).contains("realValue")) {
+        if (realvalueList.get(i) != null) {
+          dtoMap.put("realValue", realvalueList.get(i));
+        } else {
+          dtoMap.put("realValue", "");
+        }
+      }
+
+      if (Arrays.asList(showCode).contains("rDq")) {
+        if (rDqList.get(i) != null) {
+          dtoMap.put("rDq", rDqList.get(i));
+        } else {
+          dtoMap.put("rDq", "");
+        }
+      }
+      tableResult.add(dtoMap);
+    }
+
+    map.put("tableResult", tableResult);
+    map.put("resultList", resultList);
+    map.put("displayKyLl", displayKyLl);
+    return map;
+  }
+}

+ 84 - 0
ipfcst/ipfcst-reportquery/src/main/java/com/jiayue/ipfcst/service/RealTimeComprehensiveContrastTwoService.java

@@ -0,0 +1,84 @@
+package com.jiayue.ipfcst.service;
+
+import com.jiayue.ipfcst.common.core.exception.BusinessException;
+import com.jiayue.ipfcst.common.data.entity.DisplayConfig;
+import com.jiayue.ipfcst.common.data.entity.WindTowerStatusData;
+import com.jiayue.ipfcst.common.data.service.BaseService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.*;
+
+@Service
+public class RealTimeComprehensiveContrastTwoService extends BaseService {
+
+
+  private final ForecastPowerShortTermTwoService forecastPowerShortTermTwoService;
+  private final PowerStationStatusDataService powerStationStatusDataService;
+  private final DisplayConfigService displayConfigService;
+
+  @Autowired
+  public RealTimeComprehensiveContrastTwoService(ForecastPowerShortTermTwoService forecastPowerShortTermTwoService,
+                                                 PowerStationStatusDataService powerStationStatusDataService,
+                                                 DisplayConfigService displayConfigService) {
+    this.forecastPowerShortTermTwoService = forecastPowerShortTermTwoService;
+    this.powerStationStatusDataService = powerStationStatusDataService;
+    this.displayConfigService = displayConfigService;
+  }
+
+
+  public Map<String, Object> realTimeComprehensiveContrast(Long startTime,
+                                                           Long endTime,
+                                                           Integer no,
+                                                           String otherType,
+                                                           Long jgTime) throws BusinessException {
+    Map<String, Object> map = new HashMap<>();
+    Map<String, Object> rpMap = new HashMap<>();
+    Map<String, Object> rDqMap = new HashMap<>();
+    List<WindTowerStatusData> windTowerStatusDataList = new ArrayList<>();
+
+    rpMap = powerStationStatusDataService.findByTimeBetweenForContrast(new Date(startTime), new Date(endTime), jgTime);
+
+    rDqMap = forecastPowerShortTermTwoService.findByForecastTimeBetweenForComprehensive(startTime, endTime, jgTime);
+    List<Float> rDqList = (List<Float>) rDqMap.get("datas");
+    List<String> times = new ArrayList<>();
+    List<Map<String, Object>> tableResult = new ArrayList<>();
+    times = (List<String>) rpMap.get("times");
+    List<Float> realvalueList = (List<Float>) rpMap.get("realDatas");
+
+    List<Map<String, Object>> resultList = new ArrayList<>();
+
+    String displayKyLl = "0";
+    DisplayConfig displayConfig = displayConfigService.findByDisplayCode("rtWindTowerInfos");
+    for (int i = 0; i < times.size(); i++) {
+      Map<String, Object> resultMap = new HashMap<>();
+
+      Map<String, Object> dtoMap = new HashMap<>();
+      //
+      String[] showCode = displayConfig.getShowCode().split(",");
+      dtoMap.put("time", times.get(i));
+
+      if (Arrays.asList(showCode).contains("realValue")) {
+        if (realvalueList.get(i) != null) {
+          dtoMap.put("realValue", realvalueList.get(i));
+        } else {
+          dtoMap.put("realValue", "");
+        }
+      }
+
+      if (Arrays.asList(showCode).contains("rDq")) {
+        if (rDqList.get(i) != null) {
+          dtoMap.put("rDq", rDqList.get(i));
+        } else {
+          dtoMap.put("rDq", "");
+        }
+      }
+      tableResult.add(dtoMap);
+    }
+
+    map.put("tableResult", tableResult);
+    map.put("resultList", resultList);
+    map.put("displayKyLl", displayKyLl);
+    return map;
+  }
+}