Przeglądaj źródła

Merge remote-tracking branch 'origin/master'

wanghc 3 lat temu
rodzic
commit
318671d0cd

+ 32 - 9
ipfcst-common/ipfcst-common-data/src/main/java/com/jiayue/ipfcst/common/data/service/uploadfilerule/E63UploadFileRuleService.java

@@ -2,13 +2,17 @@ package com.jiayue.ipfcst.common.data.service.uploadfilerule;
 
 import com.jiayue.ipfcst.common.core.util.DateMomentUtil;
 import com.jiayue.ipfcst.common.data.entity.ElectricField;
+import com.jiayue.ipfcst.common.data.entity.SysParameter;
+import com.jiayue.ipfcst.common.data.repository.SysParameterRepository;
 import org.apache.commons.lang.time.DateFormatUtils;
 import org.apache.commons.lang.time.DateUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.Optional;
 
 /**
  * 青海文件规则
@@ -18,6 +22,9 @@ import java.util.List;
  */
 @Service
 public class E63UploadFileRuleService extends UploadFileRuleCommonService implements IUploadFileRuleService {
+    @Autowired
+    SysParameterRepository sysParameterRepository;
+
     /**
      * 指定日期应该上报文件名称
      *
@@ -62,18 +69,34 @@ public class E63UploadFileRuleService extends UploadFileRuleCommonService implem
                 shouldFileNameList.add(fileName);
                 break;
             case "E2":
-                // 超短期
-                for (Long tempDateTime = super.midNightTime; tempDateTime < super.endTime; tempDateTime = tempDateTime + 15 * 60 * 1000) {
-                    if (DateFormatUtils.format(super.endTime, "yyyyMMdd").equals(DateFormatUtils.format(currentDate, "yyyyMMdd"))) {
-                        // 当天的
-                        if (cronStr != null && !"".equals(cronStr)) {
-                            if (!isEveryTimeShouldFile(tempDateTime, currentDate, cronStr, 15)) {
-                                continue;
+                int cdqUpMin = 0;
+                try {
+                    Optional<SysParameter> optional = sysParameterRepository.findBySysKeyAndStationCode("CDQ_UP_MIN",electricFieldInfo.getStationCode());
+                    cdqUpMin = Integer.parseInt(optional.map(SysParameter::getSysValue).orElse("0"));
+                } catch (RuntimeException e) {
+                    e.printStackTrace();
+                }
+                // 可用超短期
+                midNightTime = midNightTime + cdqUpMin * 1000 * 60;
+                endTime = endTime + cdqUpMin * 1000 * 60;
+                for (Long tempDateTime = midNightTime; tempDateTime < endTime; tempDateTime = tempDateTime + 1 * 60 * 1000) {
+                    if (tempDateTime % (15 * 60 * 1000)==0){
+                        // 整15分钟
+                        if (DateFormatUtils.format(super.endTime, "yyyyMMdd").equals(DateFormatUtils.format(currentDate, "yyyyMMdd"))) {
+                            // 此判断为了当前时刻应上报的文件还没执行定时,产生的多余的应上报
+                            if (cronStr != null && !"".equals(cronStr)) {
+                                if (!isEveryTimeShouldFile(tempDateTime, currentDate, cronStr,15)) {
+                                    continue;
+                                }
                             }
                         }
+                        try {
+                            fileName = getFileNameRule(electricFieldInfo, "E2", DateMomentUtil.getMomentTime(tempDateTime + 15 * 60 * 1000, 1, 15 * 60 * 1000L));
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                        }
+                        shouldFileNameList.add(fileName);
                     }
-                    fileName = getFileNameRule(electricFieldInfo, "E2", tempDateTime + 15 * 60 * 1000);
-                    shouldFileNameList.add(fileName);
                 }
                 break;
             case "E27":

+ 2 - 2
ipfcst-console/src/main/java/com/jiayue/ipfcst/console/service/ForecastPowerUltraShortTermService.java

@@ -98,8 +98,8 @@ public class ForecastPowerUltraShortTermService extends BaseService {
 
     Long momentTime = 15 * 60 * 1000L; // 15分钟一个时刻
     Integer moments = Math.toIntExact((endTime - startTime) / momentTime + 1);
-    log.info(stationCode+"获取所需记录数:" + moments);
-
+    log.info(stationCode+"所需时间moments个数:"+moments);
+    log.info(stationCode+"获取所需记录数:" + forecastPowerUltraShortTermList.size());
     if (moments > forecastPowerUltraShortTermList.size()) {
       Map<Long, List<ForecastPowerUltraShortTerm>> forecastPowerShortTermsMap = forecastPowerUltraShortTermList.stream().collect(Collectors.groupingBy(ForecastPowerUltraShortTerm::getForecastTime));
       for (Long tempTime = startTime; tempTime <= endTime; tempTime = tempTime + momentTime) {

+ 242 - 4
ipfcst-console/src/main/java/com/jiayue/ipfcst/fileupload/service/E63UploadFileService.java

@@ -5,6 +5,7 @@ import com.jiayue.ipfcst.common.core.util.DateMomentUtil;
 import com.jiayue.ipfcst.common.data.constant.enums.FileTypeEnum;
 import com.jiayue.ipfcst.common.data.entity.ElectricField;
 import com.jiayue.ipfcst.common.data.entity.ForecastPowerShortTermHis;
+import com.jiayue.ipfcst.common.data.entity.ForecastPowerUltraShortTermHis;
 import com.jiayue.ipfcst.common.data.service.uploadfilerule.E63UploadFileRuleService;
 import com.jiayue.ipfcst.console.service.ForecastPowerShortTermService;
 import com.jiayue.ipfcst.console.service.ForecastPowerUltraShortTermService;
@@ -16,8 +17,10 @@ import org.apache.velocity.Template;
 import org.apache.velocity.VelocityContext;
 import org.apache.velocity.app.VelocityEngine;
 import org.springframework.stereotype.Service;
+import org.springframework.util.ResourceUtils;
 
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.StringWriter;
 import java.math.BigDecimal;
 import java.util.Comparator;
@@ -120,20 +123,255 @@ public class E63UploadFileService extends BaseUploadFileService {
             template.merge(velocityContext, writer);
 
             // 将文件复制到上报路径中
-            super.copyUploadFile(writer, file, FileTypeEnum.E1.name(), null, date,electricFieldInfo.getStationCode());
+            super.copyUploadFile(writer, file, FileTypeEnum.E1.name(), null, date, stationCode);
           }
         } else {
-          log.error(electricFieldInfo.getStationCode() + "短期上报模板不存在!");
+          log.error(stationCode + "短期上报模板不存在!");
         }
       } catch (Exception e) {
-        log.error(electricFieldInfo.getStationCode() + "生成短期异常");
-        System.out.println(e.toString());
+        log.error(stationCode + "生成短期异常");
       }
+    }
+  }
+
+  /**
+   * 生成短期可用预测上报文件。
+   */
+  public void generateE26File(Date date) {
+    List<ElectricField> electricFieldList = null;
+    try {
+      electricFieldList = super.getMultipleStation();
+    } catch (BusinessException e) {
+      log.error("场站获取失败", e);
+    }
+
+    // 循环场站生成短期
+    for (ElectricField electricFieldInfo : electricFieldList) {
+      String stationCode = electricFieldInfo.getStationCode();
+      try {
+        Template template = null;
+        // 获取短期模板
+        if (electricFieldInfo.getElectricFieldTypeEnum().equals("E1")) {
+          template = this.velocityEngine.getTemplate(this.vmsPath + "/DQ_USE.vm");
+        } else {
+          template = this.velocityEngine.getTemplate(this.vmsPath + "/DQ_USE_F.vm");
+        }
+        if (template != null) {
+          VelocityContext velocityContext;
+          StringWriter writer;
+          String fileName;
+          File file;
+
+          // 获取当前系统时间
+          Date systemDate = new Date();
+          if (date != null) {
+            systemDate = date;
+          }
+          // 短期默认天数
+          int dqDays = super.getTranSysParameter("FILE_FORECAST_DAYS", "3",stationCode);
+            // 开始时间
+            Long startTime = DateMomentUtil.getDayStartTime(DateUtils.addDays(systemDate, 1).getTime());
+            // 结束时间(开始加24小时再减去1秒)
+            Long endTime = DateMomentUtil.getDayLastTime(DateUtils.addDays(systemDate, dqDays).getTime());
+            // 生成上报文件名格式
+            fileName = e63UploadFileRuleService.getFileNameRule(electricFieldInfo, "E26", startTime);
+            if (getFileName(fileName, "E26",stationCode)) {
+              // 查询短期预测功率
+              List<ForecastPowerShortTermHis> forecastPowerShortTermHisList = this.forecastPowerShortTermService.getForecastPowerShortTerm(startTime, endTime,stationCode);
+              if (forecastPowerShortTermHisList.size() > 0) {
+                // 按照预测时间进行升序
+                forecastPowerShortTermHisList.sort(Comparator.comparing(ForecastPowerShortTermHis::getForecastTime));
+              }
+              // 创建上报文件
+              file = super.createTempFile(fileName);
+              // 根据模板生成文件内容
+              velocityContext = new VelocityContext();
+              velocityContext.put("vList", forecastPowerShortTermHisList);
+              //场站标识
+              velocityContext.put("sign", electricFieldInfo.getSign());
+              //系统当前日期
+              velocityContext.put("currentTime", DateFormatUtils.format(systemDate, "yyyy-MM-dd_" + "00:00:00"));
+              //上报数据开始日期
+              velocityContext.put("uploadTime", DateFormatUtils.format(startTime, "yyyy-MM-dd_") + "00:00");
+              writer = new StringWriter();
+              template.merge(velocityContext, writer);
+              // 将文件复制到上报路径中
+              super.copyUploadFile(writer, file, FileTypeEnum.E26.name(), null, date,stationCode);
+            }
+        } else {
+          log.error(stationCode+"可用短期上报模板不存在!");
+        }
+      } catch (Exception e) {
+        log.error(stationCode + "生成可用短期异常");
+      }
+    }
+  }
+
+  /**
+   * 生成超短期预测上报文件。
+   */
+  public void generateE2File(Date date) {
+    List<ElectricField> electricFieldList = null;
+    try {
+      electricFieldList = super.getMultipleStation();
+    } catch (BusinessException e) {
+      log.error("场站获取失败", e);
+    }
+
+    // 循环场站生成短期
+    for (ElectricField electricFieldInfo : electricFieldList) {
+      String stationCode = electricFieldInfo.getStationCode();
+      try {
+        Template template = null;
+        // 获取短期模板
+        if (electricFieldInfo.getElectricFieldTypeEnum().equals("E1")) {
+          template = this.velocityEngine.getTemplate(this.vmsPath + "/CDQ.vm");
+        } else {
+          template = this.velocityEngine.getTemplate(this.vmsPath + "/CDQ_F.vm");
+        }
+        if (template != null) {
+          VelocityContext velocityContext;
+          StringWriter writer;
+          String fileName;
+          File file;
+          // 获取当前系统时间
+          Date systemDate = new Date();
+          if (date != null) {
+            systemDate = date;
+          }
+          // 短期默认天数
+          int cdqPoint = super.getTranSysParameter("FILE_CDQ_POINT", "16",stationCode);
+          // 获取提前几分钟生成超短期
+          int cdqUpMin = super.getTranSysParameter("CDQ_UP_MIN", "0",stationCode);
+            // 开始时间
+            Long startTime = DateMomentUtil.getMomentTime(systemDate.getTime() + 15 * 60 * 1000 + cdqUpMin * 1000 * 60, 1, 15 * 60 * 1000L);
+            // 结束时间
+            Long endTime = startTime + cdqPoint * 15 * 60 * 1000 - 1000;
+            // 生成上报文件名格式
+            fileName = e63UploadFileRuleService.getFileNameRule(electricFieldInfo, "E2", startTime);
+
+            if (getFileName(fileName, "E2",stationCode)) {
+              // 查询超短期预测功率
+              List<ForecastPowerUltraShortTermHis> forecastPowerUltraShortTermHisList = this.forecastPowerUltraShortTermService.getForecastPowerUltraShortTerm(startTime, endTime,stationCode);
+              // 按照预测时间进行升序
+              forecastPowerUltraShortTermHisList.sort(Comparator.comparing(ForecastPowerUltraShortTermHis::getForecastTime));
+
+              // 创建上报文件
+              file = super.createTempFile(fileName);
+              // 根据模板生成文件内容
+              velocityContext = new VelocityContext();
+              velocityContext.put("vList", forecastPowerUltraShortTermHisList);
+              // 场站标识
+              velocityContext.put("sign", electricFieldInfo.getSign());
+              // 场站装机容量
+              velocityContext.put("capacity", electricFieldInfo.getCapacity());
+              // 系统当前日期
+              if (electricFieldInfo.getElectricFieldTypeEnum().equals("E1")) {
+                velocityContext.put("currentTime", DateFormatUtils.format(systemDate, "yyyy-MM-dd_HH:mm" + ":00"));
+              } else {
+                velocityContext.put("currentTime", DateFormatUtils.format(systemDate, "yyyy-MM-dd HH:mm" + ":00"));
+              }
+              // 上报数据开始日期
+              velocityContext.put("uploadTime", DateFormatUtils.format(startTime, "yyyy-MM-dd_HH:mm"));
+              writer = new StringWriter();
+              template.merge(velocityContext, writer);
+
+              super.copyUploadFile(writer, file, FileTypeEnum.E2.name(), null, date,stationCode);
+            }
+        } else {
+          log.error(stationCode+"超短期上报模板不存在!");
+        }
+      } catch (Exception e) {
+        log.error(stationCode + "生成超短期异常");
+      }
+    }
+  }
+
+  /**
+   * 生成超短期可用预测上报文件。
+   */
+  public void generateE27File(Date date) {
+    List<ElectricField> electricFieldList = null;
+    try {
+      electricFieldList = super.getMultipleStation();
+    } catch (BusinessException e) {
+      log.error("场站获取失败", e);
+    }
+
+    // 循环场站生成短期
+    for (ElectricField electricFieldInfo : electricFieldList) {
+      String stationCode = electricFieldInfo.getStationCode();
+      try {
+        Template template = null;
+        // 获取短期模板
+        if (electricFieldInfo.getElectricFieldTypeEnum().equals("E1")) {
+          template = this.velocityEngine.getTemplate(this.vmsPath + "/CDQ_USE.vm");
+        } else {
+          template = this.velocityEngine.getTemplate(this.vmsPath + "/CDQ_USE_F.vm");
+        }
+        if (template != null) {
+          VelocityContext velocityContext;
+          StringWriter writer;
+          String fileName;
+          File file;
+          // 获取当前系统时间
+          Date systemDate = new Date();
+          if (date != null) {
+            systemDate = date;
+          }
+          // 短期默认天数
+          int cdqPoint = super.getTranSysParameter("FILE_CDQ_POINT", "16",stationCode);
+          // 获取提前几分钟生成超短期
+          int cdqUpMin = super.getTranSysParameter("CDQ_UP_MIN", "0",stationCode);
+
+          // 开始时间
+          Long startTime = DateMomentUtil.getMomentTime(systemDate.getTime() + 15 * 60 * 1000 + cdqUpMin * 1000 * 60, 1, 15 * 60 * 1000L);
+          // 结束时间
+          Long endTime = startTime + cdqPoint * 15 * 60 * 1000 - 1000;
 
+          // 生成上报文件名格式
+          fileName = e63UploadFileRuleService.getFileNameRule(electricFieldInfo, "E27", startTime);
+
+          if (getFileName(fileName, "E27",stationCode)) {
+            List<ForecastPowerUltraShortTermHis> forecastPowerUltraShortTermHisList = this.forecastPowerUltraShortTermService.getForecastPowerUltraShortTerm(startTime, endTime,stationCode);
+            // 按照预测时间进行升序
+            if (forecastPowerUltraShortTermHisList.size() > 0) {
+              forecastPowerUltraShortTermHisList.sort(Comparator.comparing(ForecastPowerUltraShortTermHis::getForecastTime));
+            }
+
+            // 创建上报文件
+            file = super.createTempFile(fileName);
+            // 根据模板生成文件内容
+            velocityContext = new VelocityContext();
+            velocityContext.put("vList", forecastPowerUltraShortTermHisList);
+            // 场站标识
+            velocityContext.put("sign", electricFieldInfo.getSign());
+            // 场站装机容量
+            velocityContext.put("capacity", electricFieldInfo.getCapacity());
+            // 系统当前日期
+            if (electricFieldInfo.getElectricFieldTypeEnum().equals("E1")) {
+              velocityContext.put("currentTime", DateFormatUtils.format(systemDate, "yyyy-MM-dd_HH:mm" + ":00"));
+            } else {
+              velocityContext.put("currentTime", DateFormatUtils.format(systemDate, "yyyy-MM-dd HH:mm" + ":00"));
+            }
+            // 上报数据开始日期
+            velocityContext.put("uploadTime", DateFormatUtils.format(startTime - 15 * 60 * 1000, "yyyy-MM-dd_HH:mm"));
+            writer = new StringWriter();
+            template.merge(velocityContext, writer);
+            super.copyUploadFile(writer, file, FileTypeEnum.E27.name(), null, date,stationCode);
+          }
+        } else {
+          log.error(stationCode+"可用超短期上报模板不存在!");
+        }
+      } catch (Exception e) {
+        log.error(stationCode + "生成可用超短期异常");
+      }
     }
   }
 
 
+
+
   /**
    * 除法
    *

+ 3 - 2
ipfcst-console/src/test/java/com/jiayue/ipfcst/fileupload/service/E63UploadFileServiceTest.java

@@ -21,7 +21,8 @@ public class E63UploadFileServiceTest extends BaseTest {
   E63UploadFileService e63UploadFileService;
 
   @Test
-  public void testCreateFile() {
-    e63UploadFileService.generateE1File(new Date());
+  public void testCreateFile() throws Exception{
+    Thread.sleep(60000L);
+    e63UploadFileService.generateE27File(new Date());
   }
 }