Prechádzať zdrojové kódy

增加气象站数据从redis获取及数据表获取

xusl 3 rokov pred
rodič
commit
da39462823

+ 5 - 1
ipfcst-common/ipfcst-common-data/src/main/java/com/jiayue/ipfcst/common/data/abst/equipmentinfo/AbstractEquipmentInfo.java

@@ -73,5 +73,9 @@ public class AbstractEquipmentInfo extends AbstractBaseEntity {
     @Column
     private Integer interval;
 
-
+    /**
+     * 设备编号
+     */
+    @Column
+    private String equipmentNo;
 }

+ 1 - 1
ipfcst-common/ipfcst-common-data/src/main/java/com/jiayue/ipfcst/common/data/abst/equipmentstatus/AbstractEquipmentStatusData.java

@@ -35,7 +35,7 @@ public class AbstractEquipmentStatusData implements Serializable {
      * 设备编号
      */
     @Column
-    private Integer equipmentNo;
+    private String equipmentNo;
 
     /**
      * 状态

+ 26 - 0
ipfcst-common/ipfcst-common-data/src/main/java/com/jiayue/ipfcst/common/data/repository/WeatherStationStatusDataRepository.java

@@ -0,0 +1,26 @@
+package com.jiayue.ipfcst.common.data.repository;
+
+import com.jiayue.ipfcst.common.data.entity.WeatherStationStatusData;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 环境检测仪数据实体仓储
+ *
+ * @author zzy
+ * @version 1.0
+ * @since 2019/8/6 13:10
+ */
+public interface WeatherStationStatusDataRepository extends BaseRepository<WeatherStationStatusData, Integer> {
+	/**
+	 * 按时间段设备编号查询数据并按时间正序排序
+	 * yh
+	 *
+	 * @param startTime 开始时间
+	 * @param endTime   结束时间
+	 * @param no        设备编号
+	 */
+	List<WeatherStationStatusData> findByTimeBetweenAndEquipmentNo(Date startTime, Date endTime, String no);
+
+}

+ 106 - 71
ipfcst-console/src/main/java/com/jiayue/ipfcst/fileupload/service/E63UploadFileService.java

@@ -5,10 +5,12 @@ import com.jiayue.ipfcst.common.core.util.DateMomentUtil;
 import com.jiayue.ipfcst.common.data.constant.enums.FileTypeEnum;
 import com.jiayue.ipfcst.common.data.entity.*;
 import com.jiayue.ipfcst.common.data.repository.WeatherStationInfoRepository;
+import com.jiayue.ipfcst.common.data.repository.WeatherStationStatusDataRepository;
 import com.jiayue.ipfcst.common.data.repository.WindTurbineInfoRepository;
 import com.jiayue.ipfcst.common.data.service.uploadfilerule.E63UploadFileRuleService;
 import com.jiayue.ipfcst.console.service.ForecastPowerShortTermService;
 import com.jiayue.ipfcst.console.service.ForecastPowerUltraShortTermService;
+import com.jiayue.ipfcst.console.util.RedisUtils;
 import com.jiayue.ipfcst.fileupload.util.FileUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.time.DateFormatUtils;
@@ -16,6 +18,7 @@ import org.apache.commons.lang.time.DateUtils;
 import org.apache.velocity.Template;
 import org.apache.velocity.VelocityContext;
 import org.apache.velocity.app.VelocityEngine;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.io.File;
@@ -49,13 +52,19 @@ public class E63UploadFileService extends BaseUploadFileService {
 
   private final WindTurbineInfoRepository windTurbineInfoRepository;
 
-  public E63UploadFileService(VelocityEngine velocityEngine, ForecastPowerShortTermService forecastPowerShortTermService, ForecastPowerUltraShortTermService forecastPowerUltraShortTermService, E63UploadFileRuleService e63UploadFileRuleService, WeatherStationInfoRepository weatherStationInfoRepository, WindTurbineInfoRepository windTurbineInfoRepository) {
+  private final WeatherStationStatusDataRepository weatherStationStatusDataRepository;
+
+  @Autowired
+  private RedisUtils redisUtils;
+
+  public E63UploadFileService(VelocityEngine velocityEngine, ForecastPowerShortTermService forecastPowerShortTermService, ForecastPowerUltraShortTermService forecastPowerUltraShortTermService, E63UploadFileRuleService e63UploadFileRuleService, WeatherStationInfoRepository weatherStationInfoRepository, WindTurbineInfoRepository windTurbineInfoRepository, WeatherStationStatusDataRepository weatherStationStatusDataRepository) {
     this.velocityEngine = velocityEngine;
     this.forecastPowerShortTermService = forecastPowerShortTermService;
     this.forecastPowerUltraShortTermService = forecastPowerUltraShortTermService;
     this.e63UploadFileRuleService = e63UploadFileRuleService;
     this.weatherStationInfoRepository = weatherStationInfoRepository;
     this.windTurbineInfoRepository = windTurbineInfoRepository;
+    this.weatherStationStatusDataRepository = weatherStationStatusDataRepository;
   }
 
   /**
@@ -423,77 +432,103 @@ public class E63UploadFileService extends BaseUploadFileService {
    * 生成测风塔上报文件
    */
   private void generateQxzFile(String fileName, Template template, ElectricField electricFieldInfo, Date date, Long startTime, Long endTime) throws Exception {
-    ///////////////////此处从缓存取///////////////////////////////////////
-    WeatherStationStatusData weatherStationStatusData = null;
-    // 数据格式化
-    DecimalFormat df = new DecimalFormat("0.00");
-    BigDecimal globalR = new BigDecimal(0);
-    BigDecimal directR = new BigDecimal(0);
-    BigDecimal diffuseR = new BigDecimal(0);
-    BigDecimal ws = new BigDecimal(0);
-    BigDecimal wd = new BigDecimal(0);
-    BigDecimal airT = new BigDecimal(0);
-    BigDecimal p = new BigDecimal(0);
-    BigDecimal rh = new BigDecimal(0);
-    BigDecimal cellT = new BigDecimal(0);
-
-    if (weatherStationStatusData == null) {
-      // 总辐射产生500-1000随机数
-      globalR = new BigDecimal(df.format(Math.random() * 500 + 500));
-      // 直辐射产生400-500随机数
-      directR = new BigDecimal(df.format(Math.random() * 100 + 400));
-      // 散辐射 = 总 - 直
-      diffuseR = globalR.subtract(directR);
-      airT = new BigDecimal(df.format(Math.random() * 4 + 8));
-      p = new BigDecimal(df.format(Math.random() * 200 + 800));
-      rh = new BigDecimal(df.format(Math.random() * 10 + 30));
-      cellT = new BigDecimal(df.format(Math.random() * 26 + 4));
-      ws = new BigDecimal(df.format(Math.random() * 9 + 1));
-      wd = new BigDecimal(df.format(Math.random() * 100 + 200));
-    } else {
-      globalR = weatherStationStatusData.getGlobalR();
-      directR = weatherStationStatusData.getDirectR();
-      diffuseR = weatherStationStatusData.getDiffuseR();
-      airT = weatherStationStatusData.getAirT();
-      p = weatherStationStatusData.getP();
-      rh = weatherStationStatusData.getRh();
-      cellT = weatherStationStatusData.getCellT();
-      ws = weatherStationStatusData.getWs();
-      wd = weatherStationStatusData.getWd();
-    }
-    // 创建上报文件
-    File file = super.createTempFile(fileName);
-    //青海要求 直=总-散;但是当散辐射大于总辐射时直辐射为负数不符合该规则。所以比较总直散三个值,用最大的当总辐射去减去
-    log.info("qxz  实际值 总GlobalR:" + globalR + " 直DirectR:" + directR + " 散DiffuseR:" + diffuseR);
-    if (globalR.compareTo(diffuseR) == -1) {
-      //当散辐射大于总辐射时,数值互换
-      BigDecimal a = globalR;
-      globalR = diffuseR;
-      diffuseR = a;
+    // 获取气象站信息
+    List<WeatherStationInfo> weatherStationInfoList = weatherStationInfoRepository.findAll();
+    // 将测风塔信息过滤出上报的塔
+    List<WeatherStationInfo> weatherStationInfos = weatherStationInfoList.stream().filter(w -> w.getReport() == true).collect(Collectors.toList());
+    if (!weatherStationInfos.isEmpty()) {
+      String uploadWeatherStationNo = weatherStationInfos.get(0).getEquipmentNo();
+      Map<String,String> qxzMap = redisUtils.hgetall("qxz-"+electricFieldInfo.getStationCode()+"-"+uploadWeatherStationNo);
+      // 数据格式化
+      DecimalFormat df = new DecimalFormat("0.00");
+      BigDecimal globalR = new BigDecimal(0);
+      BigDecimal directR = new BigDecimal(0);
+      BigDecimal diffuseR = new BigDecimal(0);
+      BigDecimal ws = new BigDecimal(0);
+      BigDecimal wd = new BigDecimal(0);
+      BigDecimal airT = new BigDecimal(0);
+      BigDecimal p = new BigDecimal(0);
+      BigDecimal rh = new BigDecimal(0);
+      BigDecimal cellT = new BigDecimal(0);
+      if (qxzMap.isEmpty()){
+        // 缓存是空的,再查询数据表中,时间段里是否有数据
+        List<WeatherStationStatusData> weatherStationStatusDataList = weatherStationStatusDataRepository.findByTimeBetweenAndEquipmentNo(new Date(startTime),new Date(endTime),uploadWeatherStationNo);
+        if (weatherStationStatusDataList.isEmpty()){
+          // 总辐射产生500-1000随机数
+          globalR = new BigDecimal(df.format(Math.random() * 500 + 500));
+          // 直辐射产生400-500随机数
+          directR = new BigDecimal(df.format(Math.random() * 100 + 400));
+          // 散辐射 = 总 - 直
+          diffuseR = globalR.subtract(directR);
+          airT = new BigDecimal(df.format(Math.random() * 4 + 8));
+          p = new BigDecimal(df.format(Math.random() * 200 + 800));
+          rh = new BigDecimal(df.format(Math.random() * 10 + 30));
+          cellT = new BigDecimal(df.format(Math.random() * 26 + 4));
+          ws = new BigDecimal(df.format(Math.random() * 9 + 1));
+          wd = new BigDecimal(df.format(Math.random() * 100 + 200));
+        }
+        else{
+          // 从数据表里赋值
+          weatherStationStatusDataList.sort(Comparator.comparing(WeatherStationStatusData::getTime).reversed());
+          WeatherStationStatusData weatherStationStatusData = weatherStationStatusDataList.get(0);
+          globalR = weatherStationStatusData.getGlobalR();
+          directR = weatherStationStatusData.getDirectR();
+          // 散辐射 = 总 - 直
+          diffuseR = globalR.subtract(directR);
+          airT = weatherStationStatusData.getAirT();
+          p = weatherStationStatusData.getP();
+          rh = weatherStationStatusData.getRh();
+          cellT = weatherStationStatusData.getCellT();
+          ws = weatherStationStatusData.getWs();
+          wd = weatherStationStatusData.getWd();
+        }
+      }
+      else{
+        // 从缓存里赋值
+        globalR = new BigDecimal(qxzMap.get("globalR"));
+        directR = new BigDecimal(qxzMap.get("directR"));
+        diffuseR = new BigDecimal(qxzMap.get("diffuseR"));
+        airT = new BigDecimal(qxzMap.get("airT"));
+        p = new BigDecimal(qxzMap.get("p"));
+        rh = new BigDecimal(qxzMap.get("rh"));
+        cellT = new BigDecimal(qxzMap.get("cellT"));
+        ws = new BigDecimal(qxzMap.get("ws"));
+        wd = new BigDecimal(qxzMap.get("wd"));
+      }
+      // 创建上报文件
+      File file = super.createTempFile(fileName);
+      //青海要求 直=总-散;但是当散辐射大于总辐射时直辐射为负数不符合该规则。所以比较总直散三个值,用最大的当总辐射去减去
+      log.info("qxz  实际值 总GlobalR:" + globalR + " 直DirectR:" + directR + " 散DiffuseR:" + diffuseR);
+      if (globalR.compareTo(diffuseR) == -1) {
+        //当散辐射大于总辐射时,数值互换
+        BigDecimal a = globalR;
+        globalR = diffuseR;
+        diffuseR = a;
+      }
+      directR = globalR.subtract(diffuseR);
+      // 根据模板生成文件内容
+      VelocityContext velocityContext = new VelocityContext();
+      velocityContext.put("GlobalR", df.format(globalR));
+      velocityContext.put("AirT", df.format(airT));
+      velocityContext.put("P", df.format(p));
+      velocityContext.put("RH", df.format(rh));
+      velocityContext.put("CellT", df.format(cellT));
+      velocityContext.put("DirectR", df.format(directR));
+      velocityContext.put("DiffuseR", df.format(diffuseR));
+      velocityContext.put("WS", df.format(ws));
+      velocityContext.put("WD", df.format(wd));
+      // 场站标识
+      velocityContext.put("sign", electricFieldInfo.getSign());
+      // 场站装机容量
+      velocityContext.put("capacity", electricFieldInfo.getCapacity());
+      // 系统当前日期
+      velocityContext.put("currentTime", DateFormatUtils.format(endTime + 1000, "yyyy-MM-dd_HH:mm") + ":00");
+      // 上报数据开始日期
+      velocityContext.put("uploadTime", DateFormatUtils.format(endTime + 1000, "yyyy-MM-dd_HH:mm"));
+      StringWriter writer = new StringWriter();
+      template.merge(velocityContext, writer);
+      super.copyUploadFile(writer, file, FileTypeEnum.E6.name(), null, date, electricFieldInfo.getStationCode());
     }
-    directR = globalR.subtract(diffuseR);
-    // 根据模板生成文件内容
-    VelocityContext velocityContext = new VelocityContext();
-    velocityContext.put("GlobalR", globalR.compareTo(new BigDecimal(-99)) == 0 ? "0.00" : df.format(globalR));
-    velocityContext.put("AirT", airT.compareTo(new BigDecimal(-99)) == 0 ? "0.00" : df.format(airT));
-    velocityContext.put("P", p.compareTo(new BigDecimal(-99)) == 0 ? "0.00" : df.format(p));
-    velocityContext.put("RH", rh.compareTo(new BigDecimal(-99)) == 0 ? "0.00" : df.format(rh));
-    velocityContext.put("CellT", cellT.compareTo(new BigDecimal(-99)) == 0 ? "0.00" : df.format(cellT));
-    velocityContext.put("DirectR", directR.compareTo(new BigDecimal(-99)) == 0 ? "0.00" : df.format(directR));
-    velocityContext.put("DiffuseR", diffuseR.compareTo(new BigDecimal(-99)) == 0 ? "0.00" : df.format(diffuseR));
-    velocityContext.put("WS", ws.compareTo(new BigDecimal(-99)) == 0 ? "0.00" : df.format(ws));
-    velocityContext.put("WD", wd.compareTo(new BigDecimal(-99)) == 0 ? "0.00" : df.format(wd));
-    // 场站标识
-    velocityContext.put("sign", electricFieldInfo.getSign());
-    // 场站装机容量
-    velocityContext.put("capacity", electricFieldInfo.getCapacity());
-    // 系统当前日期
-    velocityContext.put("currentTime", DateFormatUtils.format(endTime + 1000, "yyyy-MM-dd_HH:mm") + ":00");
-    // 上报数据开始日期
-    velocityContext.put("uploadTime", DateFormatUtils.format(endTime + 1000, "yyyy-MM-dd_HH:mm"));
-    StringWriter writer = new StringWriter();
-    template.merge(velocityContext, writer);
-    super.copyUploadFile(writer, file, FileTypeEnum.E6.name(), null, date, electricFieldInfo.getStationCode());
   }
 
   /**

+ 16 - 0
ipfcst-console/src/main/resources/application.yml

@@ -6,6 +6,22 @@ server:
     key-store-password: jiayue6677*
     key-store-type: JKS
 spring:
+  redis:
+    host: 127.0.0.1
+    port: 6379
+    password: 'null'
+    maxIdle: 10
+    maxTotal: 30
+    maxWaitMillis: 1500
+    minEvictableIdleTimeMillis: 1800000
+    numTestsPerEvictionRun: 1024
+    softMinEvictableIdleTimeMillis: 10000
+    testOnBorrow: true
+    testWhileIdle: true
+    timeBetweenEvictionRunsMillis: 30000
+    timeout: 30000
+    JmxEnabled: true
+    blockWhenExhausted: false
   servlet:
     multipart:
       max-file-size: 4096MB  # 单个文件的大小

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

@@ -49,7 +49,8 @@ public class E63UploadFileServiceTest extends BaseTest {
 
     redisUtils.hmset("qxz-J00026-qazwsxedc",map);
     System.out.println("===========================================================");
-    Map<String,String> getMap = redisUtils.hgetall("qxz-J00026-qazwsxedc");
+    Map<String,String> getMap = redisUtils.hgetall("qxz-J00026-123");
+    System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$:"+getMap.isEmpty());
     getMap.keySet().forEach(key -> System.out.println("map.get(" + key + ") = " + map.get(key)));
 
     WeatherStationStatusData weatherStationStatusData = JSON.parseObject(JSON.toJSONString(getMap), WeatherStationStatusData.class);