|
@@ -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());
|
|
|
}
|
|
|
|
|
|
/**
|