|
@@ -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 + "生成可用超短期异常");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 除法
|
|
|
*
|