瀏覽代碼

修改代码

wanghc 3 年之前
父節點
當前提交
1b154a6fb1

+ 0 - 1
ipfcst-console/src/main/java/com/jiayue/ipfcst/console/controller/ElectricFieldController.java

@@ -195,7 +195,6 @@ public class ElectricFieldController {
       response.flushBuffer();
     } catch (Exception e) {
       log.error("系统错误:" + e.getMessage(), e);
-      throw new RuntimeException(e);
     } finally {
       if (bos != null)
         try {

+ 3 - 2
ipfcst-console/src/main/java/com/jiayue/ipfcst/console/controller/InitJobClassController.java

@@ -9,6 +9,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.List;
 import java.util.Map;
@@ -115,7 +116,7 @@ public class InitJobClassController {
   @GetMapping(value = "initJobClasses/jobType/{jt}")
   public ResponseVO getJobClassByType(
     @PathVariable final String jt) {
-    final Map<String, Object> map = new Hashtable<>();
+    final Map<String, Object> map = new HashMap<>();
 
     final List<InitJobClass> list = initJobClassService.findByJobClassType(jt);
     map.put("list", list);
@@ -131,7 +132,7 @@ public class InitJobClassController {
   @SneakyThrows
   @GetMapping(value = "initJobClasses/getAllJobClass")
   public ResponseVO getAllJobClass() {
-    final Map<String, Object> map = new Hashtable<>();
+    final Map<String, Object> map = new HashMap<>();
 
     final List<InitJobClass> list = initJobClassService.findAll();
     map.put("list", list);

+ 0 - 26
ipfcst-console/src/main/java/com/jiayue/ipfcst/console/controller/WindTowerStatusDataController.java

@@ -29,32 +29,6 @@ public class WindTowerStatusDataController {
     this.windTowerStatusDataService = windTowerStatusDataService;
   }
 
-//  /**
-//   * 分页查询 测风塔数据
-//   * @param startTime 开始时间
-//   * @param endTime 结束时间
-//   * @param page 页码
-//   * @param size 条数
-//   * @param sortOrder 排序
-//   * @return
-//   */
-//  @GetMapping(value = "/windTowerStatusData/{startTime}/{endTime}/{page}/{size}/{no}")
-//  public ResponseVO findByTimeBetweenForPaging(@PathVariable("startTime") Long startTime,
-//                                               @PathVariable("endTime") Long endTime,
-//                                               @PathVariable("page") Integer page,
-//                                               @PathVariable("size") Integer size,
-//                                               @PathVariable("no") Integer no,
-//                                               String sortOrder){
-//    Map<String,Object> map = new HashMap<>();
-//    try{
-//      map =  windTowerStatusDataService.findByTimeBetweenForPaging(new Date(startTime),new Date(endTime),page,size,no,sortOrder);
-//      return ResponseVO.success(map);
-//    }catch(Exception e){
-//      e.printStackTrace();
-//      log.error("测风塔数据分页查询错误");
-//      return ResponseVO.fail(e.toString());
-//    }
-//  }
 
   @GetMapping(value = "/windTowerStatusData/{stationCode}/{startTime}/{endTime}/{page}/{size}/{no}")
   public ResponseVO findByTimeBetweenAndNoAndTimeStep(@PathVariable("stationCode") String stationCode, @PathVariable("startTime") Long startTime,

+ 59 - 36
ipfcst-console/src/main/java/com/jiayue/ipfcst/console/service/FileAnalysisService.java

@@ -21,6 +21,8 @@ import java.io.*;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
@@ -59,6 +61,15 @@ public class FileAnalysisService extends BaseService {
 
   HolidayCalendarService holidayCalendarService;
 
+  private final String deleteFilelog = "文件删除异常";
+
+  private final String format = "yyyy-MM-dd HH:mm:ss";
+
+  private final String systemErrorLog = "系统错误: ";
+
+  private final String errorLog = "error";
+
+  private final String analysisFaild = "文件解析失败";
   public static void mvFile(File file, String fdPath) {
     try {
       FileUtils.copyFile(file, new File(fdPath), true);
@@ -104,7 +115,6 @@ public class FileAnalysisService extends BaseService {
     for (ElectricField electricField : electricFieldList) {
       eList.add(electricField.getStationCode());
     }
-    //String path = FileUtil.getDownloadFilePath() + File.separator + "new";
     String path = FileUtil.getDownloadFilePath();
     //downloadFile
     File dirFile = new File(path);
@@ -116,21 +126,24 @@ public class FileAnalysisService extends BaseService {
     for (String stationCode : eList) {
       // downLoadFile/场站编号/new
       String dirFiles = dirFile.getPath() + File.separator + stationCode + File.separator + "new";
-      //String dirFiles = "/Users/wanghongchen/fsdownload"+File.separator+ stationCode+ File.separator + "new";
       File filePath = new File(dirFiles);
       if (!filePath.exists()) {
         filePath.mkdirs();
       }
       Collection<File> files = FileUtils.listFiles(filePath, new String[]{"RB"}, false);
       String dayStr = new SimpleDateFormat("yyyyMMdd").format(new Date());//当前时间格式化为年月日
-      if (files.size() > 0) {
+      if (files.isEmpty()) {
         for (File file : files) {
           flag = false;
           String fileName = file.getName();
           if (!fileName.contains(dayStr)) {
-            file.delete();
-            log.info(fileName + "不是当天的文件,删除!");
-            break;
+            try {
+              Files.delete(Paths.get(file.getPath()));
+              log.info(fileName + "不是当天的文件,删除!");
+              break;
+            }catch (IOException e2){
+              log.info(deleteFilelog,e2);
+            }
           }
           if (fileName.length() < 30) {
             //假期文件
@@ -281,10 +294,7 @@ public class FileAnalysisService extends BaseService {
           //NWP文件按照Tab方式截取
           String[] datas = lineTxt.split("\t");
           if (datas.length == 35 && datas[0].startsWith("#")) {
-            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-            //过滤当天的数据
-            //if (sdf.parse(datas[5]).getTime() >= TimeUtils.getMillisecondsSubDay() + 24 * 60 * 60 *
-            // 1000) {
+            SimpleDateFormat sdf = new SimpleDateFormat(format);
             nwpData = new Nwp();
 
             //将截取的文件放入nwpData中
@@ -321,20 +331,23 @@ public class FileAnalysisService extends BaseService {
             nwpData.setWd170(new BigDecimal(datas[34]).setScale(2, RoundingMode.HALF_UP));
             nwpData.setStationCode(stationCode);
             listNwp.add(nwpData);
-            //}
           }
         }
       } catch (IOException | ParseException | RuntimeException e) {
-        log.error("系统错误:", e);
+        log.error(systemErrorLog, e);
         // 进行告警
-        File destFile = new File(file.getPath().replaceFirst("new", "error"));
+        File destFile = new File(file.getPath().replaceFirst("new", systemErrorLog));
         if (destFile.exists()) {
-          destFile.delete();
+          try {
+            Files.delete(Paths.get(destFile.getPath()));
+          }catch (IOException e2){
+            log.info(deleteFilelog,e2);
+          }
         }
         try {
           FileUtils.moveFile(file, destFile);
         } catch (IOException e1) {
-          log.error(file.getName() + "文件解析失败", e);
+          log.error(file.getName() + analysisFaild, e);
         }
       } finally {
         close(bufferedReaderNwp, readNwp);
@@ -350,7 +363,7 @@ public class FileAnalysisService extends BaseService {
    * @return 样例集合
    */
   private List<HolidayCalendar> fileAnalysisJqTerm(File file) {
-    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+    SimpleDateFormat sdf = new SimpleDateFormat(format);
     List<HolidayCalendar> holidayCalendars = new ArrayList<>();
     // 当文件未被使用时,进行解析上报
     if (file.renameTo(file)) {
@@ -377,18 +390,22 @@ public class FileAnalysisService extends BaseService {
           }
         }
       } catch (IOException | ParseException | RuntimeException e) {
-        log.error("系统错误:", e);
+        log.error(systemErrorLog, e);
         // 进行告警
 
 
-        File destFile = new File(file.getPath().replaceFirst("new", "error"));
+        File destFile = new File(file.getPath().replaceFirst("new", systemErrorLog));
         if (destFile.exists()) {
-          destFile.delete();
+          try {
+            Files.delete(Paths.get(destFile.getPath()));
+          }catch (IOException e2){
+            log.info(deleteFilelog,e2);
+          }
         }
         try {
           FileUtils.moveFile(file, destFile);
         } catch (IOException e1) {
-          log.error(file.getName() + "文件解析失败", e);
+          log.error(file.getName() + analysisFaild, e);
         }
       } finally {
         close(bufferedReader, read);
@@ -405,7 +422,7 @@ public class FileAnalysisService extends BaseService {
    * @return 样例集合
    */
   private List<ForecastPowerShortTerm> fileAnalysisShortTerm(File file, Long currentDate, String stationCode) {
-    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+    SimpleDateFormat sdf = new SimpleDateFormat(format);
     List<ForecastPowerShortTerm> forecastPowerShortTerm = new ArrayList<>();
     // 当文件未被使用时,进行解析上报
     if (file.renameTo(file)) {
@@ -419,11 +436,7 @@ public class FileAnalysisService extends BaseService {
         while ((stringLine = bufferedReader.readLine()) != null) {
           String[] string_arr = stringLine.split("\t");
 
-          if (string_arr.length == 4 && string_arr[0].startsWith("#")) {
-            if (StringUtils.isNotEmpty(string_arr[2])) {
-              //过滤当天的数据
-              //if (sdf.parse(string_arr[2]).getTime() >= TimeUtils.getMillisecondsSubDay() + 24 * 60 *
-              // 60 * 1000) {
+          if (string_arr.length == 4 && string_arr[0].startsWith("#") && StringUtils.isNotEmpty(string_arr[2])) {
               stf = new ForecastPowerShortTerm();
               stf.setFpValue(new BigDecimal(string_arr[3] + ""));
               stf.setForecastTime(sdf.parse(string_arr[2]).getTime());
@@ -431,21 +444,23 @@ public class FileAnalysisService extends BaseService {
               stf.setPredictionModelEnum(PredictionModelEnum.E1);
               stf.setStationCode(stationCode);
               forecastPowerShortTerm.add(stf);
-              // }
-            }
           }
         }
       } catch (IOException | ParseException | RuntimeException e) {
-        log.error("系统错误:", e);
+        log.error(systemErrorLog, e);
         // 进行告警
-        File destFile = new File(file.getPath().replaceFirst("new", "error"));
+        File destFile = new File(file.getPath().replaceFirst("new", systemErrorLog));
         if (destFile.exists()) {
-          destFile.delete();
+          try {
+            Files.delete(Paths.get(destFile.getPath()));
+          }catch (IOException e2){
+            log.info(deleteFilelog,e2);
+          }
         }
         try {
           FileUtils.moveFile(file, destFile);
         } catch (IOException e1) {
-          log.error(file.getName() + "文件解析失败", e);
+          log.error(file.getName() +analysisFaild, e);
         }
       } finally {
         close(bufferedReader, read);
@@ -464,7 +479,11 @@ public class FileAnalysisService extends BaseService {
     File destFile = new File(file.getPath().replaceFirst("new", "backupsTemp"));
     log.info("move file :{}, dest file:{}", file, destFile);
     if (destFile.exists()) {
-      destFile.delete();
+      try {
+        Files.delete(Paths.get(destFile.getPath()));
+      }catch (IOException e2){
+        log.info(deleteFilelog,e2);
+      }
     }
     try {
       FileUtils.moveFile(file, destFile);
@@ -508,14 +527,18 @@ public class FileAnalysisService extends BaseService {
    * @param file 文件
    */
   private void moveFileError(File file) {
-    File destFile = new File(file.getPath().replaceFirst("new", "error"));
+    File destFile = new File(file.getPath().replaceFirst("new", systemErrorLog));
     if (destFile.exists()) {
-      destFile.delete();
+      try {
+        Files.delete(Paths.get(destFile.getPath()));
+      }catch (IOException e2){
+        log.info(deleteFilelog,e2);
+      }
     }
     try {
       FileUtils.moveFile(file, destFile);
     } catch (IOException e) {
-      log.error(file.getName() + "文件解析失败", e);
+      log.error(file.getName() + analysisFaild, e);
     }
   }
 

+ 6 - 4
ipfcst-console/src/main/java/com/jiayue/ipfcst/console/service/ForecastPowerShortTermHisService.java

@@ -28,6 +28,8 @@ import java.util.Map;
  */
 @Service
 public class ForecastPowerShortTermHisService extends BaseService {
+  private final String forecastTime = "forecastTime";
+
   private final ForecastPowerShortTermHisRepository forecastPowerShortTermHisRepository;
 
   @Autowired
@@ -47,9 +49,9 @@ public class ForecastPowerShortTermHisService extends BaseService {
   public Map<String, Object> findByForecastTimeBetweenAndStationCode(Long startTime, Long endTime, String stationCode, Integer page, Integer size, String sortOrder) {
 
     Map<String, Object> map = new HashMap<>();
-    Sort sort = Sort.by(Sort.Direction.DESC, "forecastTime");
+    Sort sort = Sort.by(Sort.Direction.DESC, forecastTime);
     if (sortOrder.contains("asc")) {
-      sort = Sort.by(Sort.Direction.ASC, "forecastTime");
+      sort = Sort.by(Sort.Direction.ASC, forecastTime);
     }
     Specification<ForecastPowerShortTermHis> specification = this.specificationFindByTimeAndNo(startTime, endTime, stationCode);
     Pageable pageable = PageRequest.of(page - 1, size, sort);
@@ -73,11 +75,11 @@ public class ForecastPowerShortTermHisService extends BaseService {
       List<Predicate> predicates = new ArrayList<>();
       if (startTime != null) {
         //大于或等于传入时间
-        predicates.add(cb.greaterThanOrEqualTo(root.get("forecastTime").as(Long.class), startTime));
+        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));
+        predicates.add(cb.lessThan(root.get(forecastTime).as(Long.class), endTime));
       }
       predicates.add(cb.equal(root.get("stationCode").as(String.class), stationCode));
       //添加排序的功能

+ 13 - 9
ipfcst-console/src/main/java/com/jiayue/ipfcst/console/service/ForecastPowerShortTermService.java

@@ -14,7 +14,7 @@ import com.jiayue.ipfcst.common.data.repository.ForecastPowerShortTermHisReposit
 import com.jiayue.ipfcst.common.data.repository.ForecastPowerShortTermRepository;
 import com.jiayue.ipfcst.common.data.service.BaseService;
 import com.jiayue.ipfcst.console.util.Constant;
-import com.sun.istack.internal.NotNull;
+
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.time.DateFormatUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -28,6 +28,7 @@ import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.persistence.criteria.Predicate;
+import javax.validation.constraints.NotNull;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.text.SimpleDateFormat;
@@ -45,6 +46,11 @@ public class ForecastPowerShortTermService extends BaseService {
   @Autowired
   ElectricFieldService electricFieldService;
 
+
+  private final String format = "yyyy-MM-dd HH:mm:ss";
+
+  private final String forecastTime = "forecastTime";
+
   /**
    * 按场站编号和时间段删除数据,再保存新数据
    *
@@ -70,7 +76,7 @@ public class ForecastPowerShortTermService extends BaseService {
   @Transactional(propagation = Propagation.REQUIRED)
   public List<ForecastPowerShortTermHis> getForecastPowerShortTerm(@NotNull final Long startTime,
                                                                    @NotNull final Long endTime, @NotNull final String stationCode) {
-    log.info(stationCode + "开始获取短期预测功率" + DateFormatUtils.format(startTime, "yyyy-MM-dd HH:mm:ss") + " 至 " + DateFormatUtils.format(endTime, "yyyy-MM-dd HH:mm:ss"));
+    log.info(stationCode + "开始获取短期预测功率" + DateFormatUtils.format(startTime, format) + " 至 " + DateFormatUtils.format(endTime, format));
     // 查询场站信息
     ElectricField electricFieldInfo = electricFieldService.getSingleStation(stationCode);
     // 查询预测时间点对应的开机容量
@@ -183,7 +189,6 @@ public class ForecastPowerShortTermService extends BaseService {
   @Transactional(propagation = Propagation.REQUIRED)
   public ForecastPowerShortTerm generateSolarPowerShortTerm(@NotNull final Long tempTime, BigDecimal openCapacity,
                                                             ElectricField electricFieldInfo) {
-    System.out.println("光补数");
     ForecastPowerShortTerm forecastPowerShortTerm = new ForecastPowerShortTerm();
     forecastPowerShortTerm.setForecastTime(tempTime);
     BigDecimal tempValue;
@@ -214,7 +219,6 @@ public class ForecastPowerShortTermService extends BaseService {
    */
   @Transactional(propagation = Propagation.REQUIRED)
   public ForecastPowerShortTerm generateWindPowerShortTerm(@NotNull final Long tempTime, BigDecimal openCapacity, String stationCode) {
-    System.out.println("风补数");
     ForecastPowerShortTerm forecastPowerShortTerm = new ForecastPowerShortTerm();
     forecastPowerShortTerm.setForecastTime(tempTime);
     BigDecimal randomValue = BigDecimal.valueOf(CommonUtil.getRandom(97, 99) / 100.0d);
@@ -248,7 +252,7 @@ public class ForecastPowerShortTermService extends BaseService {
 
     long startTimeLong = startTime;
     long endTimeLong = endTime;
-    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+    SimpleDateFormat sdf = new SimpleDateFormat(format);
     long timeStep = 900000L;
     if (startTimeLong % timeStep != 0) {
       startTimeLong = startTimeLong - (startTimeLong % timeStep) + timeStep;
@@ -285,9 +289,9 @@ public class ForecastPowerShortTermService extends BaseService {
    */
   public Map<String, Object> findByTimeBetweenAndNoForPaging(Long startTime, Long endTime, String stationCode, Integer page, Integer size, String sortOrder) {
     Map<String, Object> map = new HashMap<>();
-    Sort sort = Sort.by(Sort.Direction.DESC, "forecastTime");
+    Sort sort = Sort.by(Sort.Direction.DESC, forecastTime);
     if (sortOrder.contains("asc")) {
-      sort = Sort.by(Sort.Direction.ASC, "forecastTime");
+      sort = Sort.by(Sort.Direction.ASC, forecastTime);
     }
     Specification<ForecastPowerShortTerm> specification = this.specificationFindByTimeAndNo(startTime, endTime, stationCode);
     Pageable pageable = PageRequest.of(page - 1, size, sort);
@@ -310,11 +314,11 @@ public class ForecastPowerShortTermService extends BaseService {
       List<Predicate> predicates = new ArrayList<>();
       if (startTime != null) {
         //大于或等于传入时间
-        predicates.add(cb.greaterThanOrEqualTo(root.get("forecastTime").as(Long.class), startTime));
+        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));
+        predicates.add(cb.lessThan(root.get(forecastTime).as(Long.class), endTime));
       }
       predicates.add(cb.equal(root.get("stationCode").as(String.class), stationCode));
       //添加排序的功能

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

@@ -12,7 +12,6 @@ import com.jiayue.ipfcst.common.data.repository.ForecastPowerUltraShortTermHisRe
 import com.jiayue.ipfcst.common.data.repository.ForecastPowerUltraShortTermRepository;
 import com.jiayue.ipfcst.common.data.repository.PowerStationStatusDataRepository;
 import com.jiayue.ipfcst.common.data.service.BaseService;
-import com.sun.istack.internal.NotNull;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.time.DateFormatUtils;
 import org.apache.commons.lang.time.DateUtils;
@@ -21,6 +20,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 
+import javax.validation.constraints.NotNull;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.text.SimpleDateFormat;
@@ -53,7 +53,7 @@ public class ForecastPowerUltraShortTermService extends BaseService {
   ForecastPowerShortTermService forecastPowerShortTermService;
   @Autowired
   PowerStationStatusDataService powerStationStatusDataService;
-
+  private final String format = "yyyy-MM-dd HH:mm:ss";
   /**
    * 获取超短期预测功率,当数据库中超短期预测记录不足查询所需时,进行本地化计算,用于上报专用
    *
@@ -64,13 +64,13 @@ public class ForecastPowerUltraShortTermService extends BaseService {
   @SuppressWarnings("WeakerAccess")
   @Transactional(propagation = Propagation.REQUIRED)
   public List<ForecastPowerUltraShortTermHis> getForecastPowerUltraShortTerm(@NotNull final Long startTime, @NotNull final Long endTime, @NotNull final String stationCode) {
-    log.info(stationCode + "开始获取超短期实时预测功率" + DateFormatUtils.format(startTime, "yyyy-MM-dd HH:mm:ss") + " 至 " + DateFormatUtils.format(endTime, "yyyy-MM-dd HH:mm:ss"));
+    log.info(stationCode + "开始获取超短期实时预测功率" + DateFormatUtils.format(startTime, format) + " 至 " + DateFormatUtils.format(endTime, format));
     // 查询场站信息
     ElectricField electricFieldInfo = electricFieldService.getSingleStation(stationCode);
     // 查询预测时间点对应的开机容量
     Map<Long, BigDecimal> openCapacityMap = null;
     try {
-      openCapacityMap = super.queryOpenCapacity(startTime, endTime, electricFieldInfo.getCapacity(), stationCode);
+      openCapacityMap =  super.queryOpenCapacity(startTime, endTime, electricFieldInfo.getCapacity(), stationCode);
     } catch (BusinessException e) {
       log.error(stationCode + "超短期数据生成获取开机容量出错:" + CommonUtil.printStackTraceToString(e));
     }
@@ -154,7 +154,6 @@ public class ForecastPowerUltraShortTermService extends BaseService {
       forecastPowerUltraShortTermHis.setStationCode(stationCode);
       forecastPowerUltraShortTermHiss.add(forecastPowerUltraShortTermHis);
     }
-//    List<ForecastPowerUltraShortTermHis> forecastPowerUltraShortTermHiss = forecastPowerUltraShortTermHiss1.stream().filter(t -> t.getForecastHowLongAgo() <=16).collect(Collectors.toList());
     // 获取实际功率替换超短期点位参数
     int replacePoint;
     String realpower_replace_cdq = sysParameterService.getSysParameter("realpower_replace_cdq", "0", stationCode);
@@ -235,7 +234,7 @@ public class ForecastPowerUltraShortTermService extends BaseService {
             forecastPowerShortTermList.stream().collect(Collectors.groupingBy(ForecastPowerShortTerm::getForecastTime));
           Map<Long, BigDecimal> openCapacityMap = null;
           try {
-            openCapacityMap = super.queryOpenCapacity(startTime, endTime, electricField.getCapacity(), stationCode);
+            openCapacityMap =  super.queryOpenCapacity(startTime, endTime, electricField.getCapacity(), stationCode);
           } catch (BusinessException e) {
             log.error("预测数据生成获取开机容量出错:" + CommonUtil.printStackTraceToString(e));
           }
@@ -279,6 +278,7 @@ public class ForecastPowerUltraShortTermService extends BaseService {
     }
   }
 
+
   /**
    * 执行风电场超短期预测
    *
@@ -400,13 +400,13 @@ public class ForecastPowerUltraShortTermService extends BaseService {
     List<ForecastPowerUltraShortTermHis> list = forecastPowerUltraShortTermHisRepository.findByForecastTimeBetweenAndForecastHowLongAgo(startTime, endTime, ago);
     list.sort(Comparator.comparing(ForecastPowerUltraShortTermHis::getForecastTime));
     long timeStep = 900000L;
-    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+    SimpleDateFormat sdf = new SimpleDateFormat(format);
     List<String> times = new ArrayList<>();
     List<Float> datas = new ArrayList<>();
     if (startTime % timeStep != 0) {
       startTime = startTime - (startTime % timeStep) + timeStep;
     }
-    if (list != null && list.size() > 0) {
+    if ( list.size() > 0) {
       for (long i = startTime; i < endTime; i = i + timeStep) {
         long finalI = i;
         List<ForecastPowerUltraShortTermHis> filterList = list.stream().filter(t -> t.getForecastTime() == finalI).collect(Collectors.toList());

+ 1 - 4
ipfcst-console/src/main/java/com/jiayue/ipfcst/console/service/InverterInfoService.java

@@ -202,10 +202,7 @@ public class InverterInfoService extends BaseService {
 
   @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
   public void saveCloud(InverterInfo bean) {
-//        InverterInfo inverterInfo = inverterInfoRepository.findByName(bean.getName());
-//        if (null != inverterInfo) {
-//            bean.setId(inverterInfo.getId());
-//        }
+
     inverterInfoRepository.save(bean);
   }
 

+ 14 - 45
ipfcst-console/src/main/java/com/jiayue/ipfcst/console/service/NwpService.java

@@ -9,7 +9,6 @@ import com.jiayue.ipfcst.common.data.repository.NwpHisRepository;
 import com.jiayue.ipfcst.common.data.repository.NwpRepository;
 import com.jiayue.ipfcst.common.data.service.BaseService;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang.time.DateFormatUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageRequest;
@@ -38,6 +37,9 @@ public class NwpService extends BaseService {
   @Autowired
   ElectricFieldService electricFieldService;
 
+  private final String fs100 = "ws100";
+  private final String fs170 = "ws170";
+  private final String preTime = "preTime";
   /**
    * 保存全部
    *
@@ -60,39 +62,6 @@ public class NwpService extends BaseService {
     nwpRepository.saveAll(listNwp);
   }
 
-  private Nwp createNwpData(Long preTime) {
-    long systemTime = System.currentTimeMillis();
-    Nwp nwpData = new Nwp();
-    nwpData.setFarmId("1");
-    nwpData.setScDate(DateFormatUtils.format(systemTime, "yyyy-MM-dd"));
-    nwpData.setScTime(DateFormatUtils.format(systemTime, "HH:mm:ss"));
-    nwpData.setPreTime(preTime);
-    nwpData.setPreDate(DateFormatUtils.format(preTime, "yyyy-MM-dd"));
-    nwpData.setPressure(BigDecimal.valueOf(CommonUtil.getRandom(1, 5000) / 10.0).setScale(2, RoundingMode.UP));
-    nwpData.setT(BigDecimal.valueOf(CommonUtil.getRandom(1, 5000) / 10.0).setScale(2, RoundingMode.UP));
-    nwpData.setRh(BigDecimal.valueOf(CommonUtil.getRandom(1, 5000) / 10.0).setScale(2, RoundingMode.UP));
-    nwpData.setSenf(BigDecimal.valueOf(CommonUtil.getRandom(1, 5000) / 10.0).setScale(2, RoundingMode.UP));
-    nwpData.setSwr(BigDecimal.valueOf(CommonUtil.getRandom(1, 5000) / 10.0).setScale(2, RoundingMode.UP));
-    nwpData.setLwr(BigDecimal.valueOf(CommonUtil.getRandom(1, 5000) / 10.0).setScale(2, RoundingMode.UP));
-
-    nwpData.setWd10(BigDecimal.valueOf(CommonUtil.getRandom(1, 5000) / 10.0).setScale(2, RoundingMode.UP));
-    nwpData.setWd30(BigDecimal.valueOf(CommonUtil.getRandom(1, 5000) / 10.0).setScale(2, RoundingMode.UP));
-    nwpData.setWd50(BigDecimal.valueOf(CommonUtil.getRandom(1, 5000) / 10.0).setScale(2, RoundingMode.UP));
-    nwpData.setWd70(BigDecimal.valueOf(CommonUtil.getRandom(1, 5000) / 10.0).setScale(2, RoundingMode.UP));
-    nwpData.setWd80(BigDecimal.valueOf(CommonUtil.getRandom(1, 5000) / 10.0).setScale(2, RoundingMode.UP));
-    nwpData.setWd90(BigDecimal.valueOf(CommonUtil.getRandom(1, 5000) / 10.0).setScale(2, RoundingMode.UP));
-    nwpData.setWd100(BigDecimal.valueOf(CommonUtil.getRandom(1, 5000) / 10.0).setScale(2, RoundingMode.UP));
-    nwpData.setWd170(BigDecimal.valueOf(CommonUtil.getRandom(1, 5000) / 10.0).setScale(2, RoundingMode.UP));
-    nwpData.setWs10(BigDecimal.valueOf(CommonUtil.getRandom(1, 5000) / 10.0).setScale(2, RoundingMode.UP));
-    nwpData.setWs30(BigDecimal.valueOf(CommonUtil.getRandom(1, 5000) / 10.0).setScale(2, RoundingMode.UP));
-    nwpData.setWs50(BigDecimal.valueOf(CommonUtil.getRandom(1, 5000) / 10.0).setScale(2, RoundingMode.UP));
-    nwpData.setWs70(BigDecimal.valueOf(CommonUtil.getRandom(1, 5000) / 10.0).setScale(2, RoundingMode.UP));
-    nwpData.setWs80(BigDecimal.valueOf(CommonUtil.getRandom(1, 5000) / 10.0).setScale(2, RoundingMode.UP));
-    nwpData.setWs90(BigDecimal.valueOf(CommonUtil.getRandom(1, 5000) / 10.0).setScale(2, RoundingMode.UP));
-    nwpData.setWs100(BigDecimal.valueOf(CommonUtil.getRandom(1, 5000) / 10.0).setScale(2, RoundingMode.UP));
-    nwpData.setWs170(BigDecimal.valueOf(CommonUtil.getRandom(1, 5000) / 10.0).setScale(2, RoundingMode.UP));
-    return nwpData;
-  }
 
 
   /**
@@ -157,8 +126,8 @@ public class NwpService extends BaseService {
       datas.put("ws70", ws70Collect);
       datas.put("ws80", ws80Collect);
       datas.put("ws90", ws90Collect);
-      datas.put("ws100", ws100Collect);
-      datas.put("ws170", ws170Collect);
+      datas.put(fs100, ws100Collect);
+      datas.put(fs170, ws170Collect);
       Map<String, String> map1 = new HashMap<>();
       map1.put("ws10", "10米风速");
       map1.put("ws30", "30米风速");
@@ -166,8 +135,8 @@ public class NwpService extends BaseService {
       map1.put("ws70", "70米风速");
       map1.put("ws80", "80米风速");
       map1.put("ws90", "90米风速");
-      map1.put("ws100", "100米风速");
-      map1.put("ws170", "170米风速");
+      map1.put(fs100, "100米风速");
+      map1.put(fs170, "170米风速");
       map.put("cName", map1);
       map.put("stationType", "0");
     }
@@ -273,11 +242,11 @@ public class NwpService extends BaseService {
       List<Predicate> predicates = new ArrayList<>();
       if (startTime != null) {
         //大于或等于传入时间
-        predicates.add(cb.greaterThanOrEqualTo(root.get("preTime").as(Long.class), startTime));
+        predicates.add(cb.greaterThanOrEqualTo(root.get(preTime).as(Long.class), startTime));
       }
       if (endTime != null) {
         //小于传入时间
-        predicates.add(cb.lessThan(root.get("preTime").as(Long.class), endTime));
+        predicates.add(cb.lessThan(root.get(preTime).as(Long.class), endTime));
       }
       predicates.add(cb.equal(root.get("stationCode").as(String.class), stationCode));
       //添加排序的功能
@@ -288,9 +257,9 @@ public class NwpService extends BaseService {
 
   public Map<String, Object> findByTimeBetweenAndNoForPaging(Long startTime, Long endTime, String stationCode, Integer page, Integer size, String sortOrder) {
     Map<String, Object> map = new HashMap<>();
-    Sort sort = Sort.by(Sort.Direction.DESC, "preTime");
+    Sort sort = Sort.by(Sort.Direction.DESC, preTime);
     if (sortOrder.contains("asc")) {
-      sort = Sort.by(Sort.Direction.ASC, "preTime");
+      sort = Sort.by(Sort.Direction.ASC, preTime);
     }
     Specification<Nwp> specification = specificationFindByTimeAndNo(startTime, endTime, stationCode);
     Pageable pageable = PageRequest.of(page - 1, size, sort);
@@ -301,7 +270,7 @@ public class NwpService extends BaseService {
     map.put("content", datas);
     map.put("count", nwps.getTotalElements());
     Map<String, String> map1 = new HashMap<>();
-    map1.put("preTime", "预测时间");
+    map1.put(preTime, "预测时间");
     map1.put("scTime", "生成时间");
     map1.put("pressure", "气压");
     map1.put("t", "温度");
@@ -316,8 +285,8 @@ public class NwpService extends BaseService {
     map1.put("ws70", "70米风速");
     map1.put("ws80", "80米风速");
     map1.put("ws90", "90米风速");
-    map1.put("ws100", "100米风速");
-    map1.put("ws170", "170米风速");
+    map1.put(fs100, "100米风速");
+    map1.put(fs170, "170米风速");
     map1.put("wd10", "10米风向");
     map1.put("wd30", "30米风向");
     map1.put("wd50", "50米风向");

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

@@ -75,7 +75,6 @@ public class OverHaulPlanService {
    * 查询检修计划信息(分页)
    */
   public Page<OverhaulPlan> get(final OverhaulPlan overhaulPlan, final Integer page, final Integer size) {
-//    getAll();
     ExampleMatcher matcher =
       ExampleMatcher.matching().withMatcher("id", ExampleMatcher.GenericPropertyMatchers.contains());
     Example<OverhaulPlan> example = Example.of(overhaulPlan, matcher);
@@ -88,7 +87,6 @@ public class OverHaulPlanService {
    * 查询检修计划信息(分页)
    */
   public Page<OverhaulPlan> getByStationCode(final OverhaulPlan overhaulPlan, final Integer page, final Integer size, final String stationCode) {
-//    getAll();
     overhaulPlan.setStationCode(stationCode);
     ExampleMatcher matcher =
       ExampleMatcher.matching().withMatcher("id", ExampleMatcher.GenericPropertyMatchers.contains())

+ 7 - 8
ipfcst-console/src/main/java/com/jiayue/ipfcst/console/service/PowerStationDataPacker.java

@@ -107,7 +107,7 @@ public class PowerStationDataPacker {
   List<Field> fields = new ArrayList<>();
   @Setter
   @Getter
-  private PowerStationStatusData t = new PowerStationStatusData();
+  private Class<PowerStationStatusData> t = PowerStationStatusData.class;
   /**
    * 场站信息
    */
@@ -176,10 +176,8 @@ public class PowerStationDataPacker {
     }
     //对日升和日落各宽恕30min  如果在日升前30min到 日落后30min 之间
     //如果时间处于日出前30分钟    日落后30分钟   则判定功率为0
-    if (electricField != null && ElectricFieldTypeEnum.E1.equals(electricField.getElectricFieldTypeEnum())) {
-      if (time.isBefore(getSunUpTime().minusMillis(30)) || time.isAfter(getSunDownTime().plusMillis(30))) {
-        power = BigDecimal.ZERO;
-      }
+    if (electricField != null && ElectricFieldTypeEnum.E1.equals(electricField.getElectricFieldTypeEnum()) && time.isBefore(getSunUpTime().minusMillis(30)) || time.isAfter(getSunDownTime().plusMillis(30))) {
+      power = BigDecimal.ZERO;
     }
     return power;
   }
@@ -201,6 +199,7 @@ public class PowerStationDataPacker {
         } else {
           log.info("{}样板机方式计算参考值为空返回倍率计算方式",electricField.getName());
         }
+        break;
       case "2":
         log.info("{}使用测风/光法方式计算参考值",electricField.getName());
         if (powerStationStatusData.getReferencePowerByMeasuring() != null) {
@@ -208,7 +207,9 @@ public class PowerStationDataPacker {
         } else {
           log.info("{}测风/光法方式计算参考值为空返回倍率计算方式",electricField.getName());
         }
+        break;
       default:
+        break;
     }
     log.info("{}不判断限电,直接判断不限电",electricField.getName());
     return BigDecimal.valueOf(-99);
@@ -260,7 +261,7 @@ public class PowerStationDataPacker {
    * 初始化实体域集合
    */
   private void initEntityFields() {
-    fields.addAll(Arrays.asList(t.getClass().getDeclaredFields()));
+    fields.addAll(Arrays.asList(t.getDeclaredFields()));
     fields.addAll(Arrays.asList(AbstractEquipmentStatusData.class.getDeclaredFields()));
     for (Field f : fields) {
       f.setAccessible(true);
@@ -427,7 +428,6 @@ public class PowerStationDataPacker {
       powerStationStatusData.setOffSiteObstructed(powerStationStatusData.getAbleValue().subtract(powerStationStatusData.getRealValue()));
     } catch (Exception e) {
       log.error("{}组装场站状态数据时发生异常",electricField.getName(), e);
-      throw new RuntimeException(electricField.getName()+"组装场站状态数据时发生异常");
     }
 
     if (powerStationStatusData.getAbleValue().compareTo(BigDecimal.valueOf(-99)) == 0) {
@@ -551,7 +551,6 @@ public class PowerStationDataPacker {
         this.compiledExp = AviatorEvaluator.compile(formula);
       } catch (ExpressionSyntaxErrorException e) {
         log.error("{}公式解析失败,公式不可用",electricField.getName(), e);
-        throw new RuntimeException(electricField.getName()+"公式解析失败,公式不可用");
       }
       if (electricField.getElectricFieldTypeEnum() == ElectricFieldTypeEnum.E1) {
         WeatherStationInfoService weatherStationInfoService = SpringContextHolder.getBean(WeatherStationInfoService.class);

+ 1 - 16
ipfcst-console/src/main/java/com/jiayue/ipfcst/console/service/PowerStationStatusDataService.java

@@ -37,7 +37,7 @@ public class PowerStationStatusDataService extends BaseService {
   @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
   public Map<String, Object> findByTimeBetweenForContrast(Date startTime, Date endTime, Long timeStep) {
     Map<String, Object> map = new HashMap<>();
-    List<PowerStationStatusData> list = new ArrayList<>();
+    List<PowerStationStatusData> list ;
 
     list = powerStationStatusDataRepository.findByTimeBetween(startTime, endTime);
 
@@ -179,22 +179,7 @@ public class PowerStationStatusDataService extends BaseService {
       resultList.add(map);
 
     }
-
-//    Sort sort = Sort.by(Sort.Direction.DESC, "time");
-//    if (sortOrder.contains("asc")) {
-//      sort = Sort.by(Sort.Direction.ASC, "time");
-//    }
-//    Specification<PowerStationStatusData> specification = this.Specification(startTime, endTime);
-//    Pageable pageable = PageRequest.of(page - 1, size, sort);
-//    Page pages = powerStationStatusDataRepository.findAll(specification, pageable);
-//    List<PowerStationStatusData> datas = new ArrayList<>();
-//    datas = pages.getContent();
-//    map.put("content", datas);
-//    map.put("count", pages.getTotalElements());
-
     return resultList;
-
-
   }
 
   /**

+ 0 - 4
ipfcst-console/src/main/java/com/jiayue/ipfcst/console/service/PvModuleModelService.java

@@ -113,10 +113,6 @@ public class PvModuleModelService extends BaseService {
 
   @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
   public void saveCloud(PvModuleModel bean) {
-//        PvModuleModel beanOld = pvModuleModelRepository.findByModel(bean.getModel());
-//        if (null != beanOld) {
-//            bean.setId(beanOld.getId());
-//        }
     pvModuleModelRepository.save(bean);
   }