|
@@ -0,0 +1,226 @@
|
|
|
+package com.jiayue.insu.inclientqn.service;
|
|
|
+
|
|
|
+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.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.util.DateTimeUtils;
|
|
|
+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.List;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * @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) throws Exception{
|
|
|
+
|
|
|
+ RequestVo requestVo = null;
|
|
|
+
|
|
|
+ long time = DateTimeUtils.get15min(DateUtil.date().getTime());
|
|
|
+ LocalDateTime queryTime = LocalDateTimeUtil.of(time);
|
|
|
+ List<BackStatData> backStatDatas = backStatDataService.findBySignTime(queryTime);
|
|
|
+
|
|
|
+ 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_FORE(el,content.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return requestVo;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成回传实际气象
|
|
|
+ * @param el 场站标识
|
|
|
+ * @param stationType 场站类型
|
|
|
+ * @return RequestVo
|
|
|
+ */
|
|
|
+ public RequestVo genStateRealWeatherData(String el,String stationType)throws Exception {
|
|
|
+
|
|
|
+ RequestVo requestVo = null;
|
|
|
+
|
|
|
+ long time = DateTimeUtils.get15min(DateUtil.date().getTime());
|
|
|
+ LocalDateTime queryTime = LocalDateTimeUtil.of(time);
|
|
|
+ List<BackStatData> backStatDatas = backStatDataService.findBySignTime(queryTime);
|
|
|
+
|
|
|
+ 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_FORE(el,content.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return requestVo;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成短期上报
|
|
|
+ * @param el 场站标识
|
|
|
+ * @return RequestVo
|
|
|
+ */
|
|
|
+ public RequestVo genStateForecastPowerReport(String el) throws Exception {
|
|
|
+
|
|
|
+ RequestVo requestVo = null;
|
|
|
+
|
|
|
+ long time = DateTimeUtils.get15min(DateUtil.date().getTime());
|
|
|
+ LocalDateTime queryTime = LocalDateTimeUtil.of(time);
|
|
|
+ List<BackStatData> backStatDatas = backStatDataService.findBySignTime(queryTime);
|
|
|
+
|
|
|
+ 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_FORE(el,content.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return requestVo;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成超短期上报
|
|
|
+ * @param el 场站标识
|
|
|
+ * @return RequestVo
|
|
|
+ */
|
|
|
+ public RequestVo genStateUltraShortTermForecastReport(String el) throws Exception{
|
|
|
+
|
|
|
+ RequestVo requestVo = null;
|
|
|
+
|
|
|
+ long time = DateTimeUtils.get15min(DateUtil.date().getTime());
|
|
|
+ LocalDateTime queryTime = LocalDateTimeUtil.of(time);
|
|
|
+ List<BackStatData> backStatDatas = backStatDataService.findBySignTime(queryTime);
|
|
|
+
|
|
|
+ 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_FORE(el,content.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return requestVo;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|