|
@@ -0,0 +1,276 @@
|
|
|
+package com.jiayue.insu.inclientqn.service.client;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.date.LocalDateTimeUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.jiayue.insu.inclientqn.constant.CommonStant;
|
|
|
+import com.jiayue.insu.inclientqn.entity.BackForeUsForecastData;
|
|
|
+import com.jiayue.insu.inclientqn.entity.BackStatData;
|
|
|
+import com.jiayue.insu.inclientqn.inenum.ElectricFieldTypeEnum;
|
|
|
+import com.jiayue.insu.inclientqn.inenum.QNHLEnum;
|
|
|
+import com.jiayue.insu.inclientqn.model.RequestVo;
|
|
|
+import com.jiayue.insu.inclientqn.service.BackStatDataService;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.cloud.context.config.annotation.RefreshScope;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.Comparator;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * @description: 回传数据请求生成
|
|
|
+ * @author: yuanhao
|
|
|
+ * @createDate: 2022/6/17
|
|
|
+ * @version: 1.0
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+@RequiredArgsConstructor
|
|
|
+@RefreshScope
|
|
|
+public class BackDataGenService {
|
|
|
+
|
|
|
+ private String headerTemplate = "<! Entity={} time='{}' !>" + CommonStant.LINE_CONSTANT;
|
|
|
+
|
|
|
+ private final BackStatDataService backStatDataService;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成回传实际功率
|
|
|
+ *
|
|
|
+ * @param el 场站标识
|
|
|
+ * @return RequestVo
|
|
|
+ */
|
|
|
+ public RequestVo genStateRealPowerData(String el, long signTime, List<BackStatData> backStatDatas) throws Exception {
|
|
|
+
|
|
|
+ RequestVo requestVo = null;
|
|
|
+
|
|
|
+ if (CollectionUtil.isNotEmpty(backStatDatas) && backStatDatas.get(0).getRealPower() != null) {
|
|
|
+ StringBuilder content = new StringBuilder();
|
|
|
+
|
|
|
+ String header = StrUtil.format(headerTemplate, el, DateUtil.parse(DateUtil.now()).toString("yyyy-MM-dd HH:mm:ss"));
|
|
|
+ String labelStart = StrUtil.format("<{}>" + CommonStant.LINE_CONSTANT, QNHLEnum.DATA_STAT_TYPE_RealPower.getCode());
|
|
|
+ String labelEnd = StrUtil.format("</{}>" + CommonStant.LINE_CONSTANT, QNHLEnum.DATA_STAT_TYPE_RealPower.getCode());
|
|
|
+ String title = "@" + CommonStant.SPACE1_CONSTANT + "序号" + CommonStant.SPACE2_CONSTANT + "实发功率值" + CommonStant.LINE_CONSTANT;
|
|
|
+ content.append(header);
|
|
|
+ content.append(labelStart);
|
|
|
+ content.append(title);
|
|
|
+
|
|
|
+ String template = "# 1" + CommonStant.SPACE2_CONSTANT + "{}" + CommonStant.LINE_CONSTANT;
|
|
|
+
|
|
|
+ String dataContent = StrUtil.format(template, backStatDatas.get(0).getRealPower().toString());
|
|
|
+
|
|
|
+ content.append(dataContent);
|
|
|
+ content.append(labelEnd);
|
|
|
+
|
|
|
+ requestVo = RequestVo.UPLOAD_STAT(el, content.toString(), signTime);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return requestVo;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成回传实际气象
|
|
|
+ *
|
|
|
+ * @param el 场站标识
|
|
|
+ * @param stationType 场站类型
|
|
|
+ * @return RequestVo
|
|
|
+ */
|
|
|
+ public RequestVo genStateRealWeatherData(String el, String stationType, long signTime, List<BackStatData> backStatDatas) throws Exception {
|
|
|
+
|
|
|
+ RequestVo requestVo = null;
|
|
|
+
|
|
|
+ if (CollectionUtil.isNotEmpty(backStatDatas)) {
|
|
|
+ StringBuilder content = new StringBuilder();
|
|
|
+
|
|
|
+ String header = StrUtil.format(headerTemplate, el, DateUtil.parse(DateUtil.now()).toString("yyyy-MM-dd HH:mm:ss"));
|
|
|
+ String labelStart = StrUtil.format("<{}>" + CommonStant.LINE_CONSTANT, QNHLEnum.DATA_STAT_TYPE_RealWeather.getCode());
|
|
|
+ String labelEnd = StrUtil.format("</{}>" + CommonStant.LINE_CONSTANT, QNHLEnum.DATA_STAT_TYPE_RealWeather.getCode());
|
|
|
+ content.append(header);
|
|
|
+ content.append(labelStart);
|
|
|
+ String title = "";
|
|
|
+ String template = "";
|
|
|
+ String dataContent = "";
|
|
|
+ BackStatData backStatData = backStatDatas.get(0);
|
|
|
+
|
|
|
+ if (stationType.equals(ElectricFieldTypeEnum.E2.name())) {
|
|
|
+ title = "@" + CommonStant.SPACE1_CONSTANT + "序号" + CommonStant.SPACE4_CONSTANT + "风速" + CommonStant.SPACE4_CONSTANT + "风向"
|
|
|
+ + CommonStant.SPACE4_CONSTANT + "温度" + CommonStant.SPACE4_CONSTANT + "湿度" + CommonStant.SPACE4_CONSTANT + "气压"
|
|
|
+ + CommonStant.LINE_CONSTANT;
|
|
|
+
|
|
|
+ template = "# 1" + CommonStant.SPACE1_CONSTANT + "{}" + CommonStant.SPACE4_CONSTANT + "{}" + CommonStant.SPACE4_CONSTANT
|
|
|
+ + "{}" + CommonStant.SPACE4_CONSTANT + "{}" + CommonStant.SPACE4_CONSTANT + "{}" + CommonStant.SPACE4_CONSTANT
|
|
|
+ + CommonStant.LINE_CONSTANT;
|
|
|
+
|
|
|
+ dataContent = StrUtil.format(template, backStatData.getWs().toString(), backStatData.getWd().toString()
|
|
|
+ , backStatData.getTemperature().toString(), backStatData.getHumidity().toString(), backStatData.getPressure().toString());
|
|
|
+
|
|
|
+ } else {
|
|
|
+ title = "@" + CommonStant.SPACE1_CONSTANT + "序号" + CommonStant.SPACE4_CONSTANT + "总辐照度" + CommonStant.SPACE4_CONSTANT + "直射辐照度"
|
|
|
+ + CommonStant.SPACE4_CONSTANT + "散射辐照度" + CommonStant.SPACE4_CONSTANT + "温度" + CommonStant.SPACE4_CONSTANT + "光伏板温度"
|
|
|
+ + CommonStant.SPACE4_CONSTANT + "湿度" + CommonStant.SPACE4_CONSTANT + "气压" + CommonStant.SPACE4_CONSTANT + "风速" + CommonStant.SPACE4_CONSTANT + "风向"
|
|
|
+ + CommonStant.LINE_CONSTANT;
|
|
|
+
|
|
|
+ template = "# 1" + CommonStant.SPACE1_CONSTANT + "{}" + CommonStant.SPACE4_CONSTANT + "{}" + CommonStant.SPACE4_CONSTANT
|
|
|
+ + "{}" + CommonStant.SPACE4_CONSTANT + "{}" + CommonStant.SPACE4_CONSTANT + "{}" + CommonStant.SPACE4_CONSTANT
|
|
|
+ + "{}" + CommonStant.SPACE4_CONSTANT + "{}" + CommonStant.SPACE4_CONSTANT + "{}" + CommonStant.SPACE4_CONSTANT
|
|
|
+ + "{}" + CommonStant.SPACE4_CONSTANT + CommonStant.LINE_CONSTANT;
|
|
|
+
|
|
|
+ dataContent = StrUtil.format(template, backStatData.getGlobalR().toString(), backStatData.getDirectR().toString()
|
|
|
+ , backStatData.getDiffuseR().toString(), backStatData.getTemperature().toString(), backStatData.getCellT().toString(),
|
|
|
+ backStatData.getHumidity().toString(), backStatData.getPressure().toString(), backStatData.getWs().toString(), backStatData.getWd().toString()
|
|
|
+ );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ content.append(title);
|
|
|
+ content.append(dataContent);
|
|
|
+ content.append(labelEnd);
|
|
|
+
|
|
|
+ requestVo = RequestVo.UPLOAD_STAT(el, content.toString(), signTime);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return requestVo;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成短期上报
|
|
|
+ *
|
|
|
+ * @param el 场站标识
|
|
|
+ * @return RequestVo
|
|
|
+ */
|
|
|
+ public RequestVo genStateForecastPowerReport(String el, long signTime, List<BackStatData> backStatDatas) throws Exception {
|
|
|
+
|
|
|
+ RequestVo requestVo = null;
|
|
|
+
|
|
|
+ if (CollectionUtil.isNotEmpty(backStatDatas) && backStatDatas.get(0).getReportStateForecast() != null) {
|
|
|
+ StringBuilder content = new StringBuilder();
|
|
|
+
|
|
|
+ String header = StrUtil.format(headerTemplate, el, DateUtil.parse(DateUtil.now()).toString("yyyy-MM-dd HH:mm:ss"));
|
|
|
+ String labelStart = StrUtil.format("<{}>" + CommonStant.LINE_CONSTANT, QNHLEnum.DATA_STAT_TYPE_ForecastPowerReport.getCode());
|
|
|
+ String labelEnd = StrUtil.format("</{}>" + CommonStant.LINE_CONSTANT, QNHLEnum.DATA_STAT_TYPE_ForecastPowerReport.getCode());
|
|
|
+ String title = "@" + CommonStant.SPACE1_CONSTANT + "序号" + CommonStant.SPACE2_CONSTANT + "上报" + CommonStant.LINE_CONSTANT;
|
|
|
+ content.append(header);
|
|
|
+ content.append(labelStart);
|
|
|
+ content.append(title);
|
|
|
+
|
|
|
+ String template = "# 1" + CommonStant.SPACE2_CONSTANT + "{}" + CommonStant.LINE_CONSTANT;
|
|
|
+
|
|
|
+ String dataContent = StrUtil.format(template, backStatDatas.get(0).getReportStateForecast().toString());
|
|
|
+
|
|
|
+ content.append(dataContent);
|
|
|
+ content.append(labelEnd);
|
|
|
+
|
|
|
+ requestVo = RequestVo.UPLOAD_STAT(el, content.toString(), signTime);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return requestVo;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成超短期上报
|
|
|
+ *
|
|
|
+ * @param el 场站标识
|
|
|
+ * @return RequestVo
|
|
|
+ */
|
|
|
+ public RequestVo genStateUltraShortTermForecastReport(String el, long signTime, List<BackStatData> backStatDatas) throws Exception {
|
|
|
+
|
|
|
+ RequestVo requestVo = null;
|
|
|
+
|
|
|
+ if (CollectionUtil.isNotEmpty(backStatDatas) && backStatDatas.get(0).getReportStateForecastshort() != null) {
|
|
|
+ StringBuilder content = new StringBuilder();
|
|
|
+
|
|
|
+ String header = StrUtil.format(headerTemplate, el, DateUtil.parse(DateUtil.now()).toString("yyyy-MM-dd HH:mm:ss"));
|
|
|
+ String labelStart = StrUtil.format("<{}>" + CommonStant.LINE_CONSTANT, QNHLEnum.DATA_STAT_TYPE_UltraShortTermForecastReport.getCode());
|
|
|
+ String labelEnd = StrUtil.format("</{}>" + CommonStant.LINE_CONSTANT, QNHLEnum.DATA_STAT_TYPE_UltraShortTermForecastReport.getCode());
|
|
|
+ String title = "@" + CommonStant.SPACE1_CONSTANT + "序号" + CommonStant.SPACE2_CONSTANT + "上报" + CommonStant.LINE_CONSTANT;
|
|
|
+ content.append(header);
|
|
|
+ content.append(labelStart);
|
|
|
+ content.append(title);
|
|
|
+
|
|
|
+ String template = "# 1" + CommonStant.SPACE2_CONSTANT + "{}" + CommonStant.LINE_CONSTANT;
|
|
|
+
|
|
|
+ String dataContent = StrUtil.format(template, backStatDatas.get(0).getReportStateForecastshort().toString());
|
|
|
+
|
|
|
+ content.append(dataContent);
|
|
|
+ content.append(labelEnd);
|
|
|
+
|
|
|
+ requestVo = RequestVo.UPLOAD_STAT(el, content.toString(), signTime);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return requestVo;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public RequestVo genForeUltraShortTermForecast(String el, long signTime, List<BackForeUsForecastData> backForeUsForecastDatas) throws Exception {
|
|
|
+
|
|
|
+ RequestVo requestVo = null;
|
|
|
+
|
|
|
+ if (CollectionUtil.isNotEmpty(backForeUsForecastDatas) && backForeUsForecastDatas.size() < 16) {
|
|
|
+
|
|
|
+ boolean checkDate = true;
|
|
|
+
|
|
|
+ long step = 900000L;
|
|
|
+
|
|
|
+ long startTime = signTime + step;
|
|
|
+
|
|
|
+ long endTime = signTime + step * 15;
|
|
|
+
|
|
|
+ for (long i = startTime; i < endTime; i = i + step) {
|
|
|
+ long finalI = i;
|
|
|
+ List<BackForeUsForecastData> filter = backForeUsForecastDatas.stream().filter(b -> b.getForecastTime().equals(LocalDateTimeUtil.of(finalI))).collect(Collectors.toList());
|
|
|
+ if (CollectionUtil.isEmpty(filter)) {
|
|
|
+ checkDate = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (checkDate) {
|
|
|
+ Collections.sort(backForeUsForecastDatas, Comparator.comparing(BackForeUsForecastData::getForecastTime));
|
|
|
+ StringBuilder content = new StringBuilder();
|
|
|
+ String header = StrUtil.format(headerTemplate, el, DateUtil.parse(DateUtil.now()).toString("yyyy-MM-dd HH:mm:ss"));
|
|
|
+ String labelStart = StrUtil.format("<{}>" + CommonStant.LINE_CONSTANT, QNHLEnum.DATA_STAT_TYPE_UltraShortTermForecastReport.getCode());
|
|
|
+ String labelEnd = StrUtil.format("</{}>" + CommonStant.LINE_CONSTANT, QNHLEnum.DATA_STAT_TYPE_UltraShortTermForecastReport.getCode());
|
|
|
+ String title = "@" + CommonStant.SPACE1_CONSTANT + "序号" + CommonStant.SPACE4_CONSTANT + "时间"
|
|
|
+ + CommonStant.SPACE4_CONSTANT + "功率预测" + CommonStant.SPACE4_CONSTANT + "预计开机容量" + CommonStant.SPACE4_CONSTANT + "风速"
|
|
|
+ + CommonStant.SPACE4_CONSTANT + "风向" + CommonStant.SPACE4_CONSTANT + "温度" + CommonStant.SPACE4_CONSTANT + "湿度" + CommonStant.SPACE4_CONSTANT + "气压"
|
|
|
+ + CommonStant.LINE_CONSTANT;
|
|
|
+ content.append(header);
|
|
|
+ content.append(labelStart);
|
|
|
+ content.append(title);
|
|
|
+
|
|
|
+ String template = "# {}" + CommonStant.SPACE4_CONSTANT + "{}" + CommonStant.SPACE4_CONSTANT + "{}" + CommonStant.SPACE4_CONSTANT + "null" + CommonStant.SPACE4_CONSTANT + "null"
|
|
|
+ + CommonStant.SPACE4_CONSTANT + "null" + CommonStant.SPACE4_CONSTANT + "null" + CommonStant.SPACE4_CONSTANT + "null" + CommonStant.SPACE4_CONSTANT + "null"
|
|
|
+ + CommonStant.LINE_CONSTANT;
|
|
|
+
|
|
|
+ for (int i = 0; i < backForeUsForecastDatas.size(); i++) {
|
|
|
+
|
|
|
+ BackForeUsForecastData b = backForeUsForecastDatas.get(i);
|
|
|
+ String dataContent = String.format(template, i,b.getForecastValue(),b.getForecastOpenCap());
|
|
|
+ content.append(dataContent);
|
|
|
+ }
|
|
|
+
|
|
|
+ content.append(labelEnd);
|
|
|
+
|
|
|
+ requestVo = RequestVo.UPLOAD_FORE(el, content.toString(), signTime);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return requestVo;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|