yuanhao 2 năm trước cách đây
mục cha
commit
b51abdc564

+ 81 - 0
in-client-qn/src/main/java/com/jiayue/insu/inclientqn/constant/TemplateStant.java

@@ -0,0 +1,81 @@
+package com.jiayue.insu.inclientqn.constant;
+
+import cn.hutool.core.util.StrUtil;
+
+public interface TemplateStant {
+
+    String BACK_FORE_US_FORECAST_TITLE_E2 = "@" + 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;
+
+    String BACK_FORE_US_FORECAST_TEMPLATE_E2 = "# {}" + CommonStant.SPACE4_CONSTANT + "{}" + 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.LINE_CONSTANT;
+
+
+    String BACK_FORE_US_FORECAST_TITLE_E1 = "@" + 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.SPACE4_CONSTANT + "风速"+ CommonStant.SPACE4_CONSTANT + "风向"
+            + CommonStant.LINE_CONSTANT;
+
+
+    String BACK_FORE_US_FORECAST_TEMPLATE_E1 = "# {}" + CommonStant.SPACE4_CONSTANT + "{}" + 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.SPACE4_CONSTANT + "null" + CommonStant.SPACE4_CONSTANT + "null"
+            + CommonStant.LINE_CONSTANT;
+
+
+    String BACK_FORE_US_FORECAST_TITLE_REPORT = "@" + CommonStant.SPACE1_CONSTANT + "序号" + CommonStant.SPACE2_CONSTANT + "上报" + CommonStant.LINE_CONSTANT;
+    String BACK_FORE_US_FORECAST_TITLE_TEMPLATE = "# 1" + CommonStant.SPACE2_CONSTANT + "{}" + CommonStant.LINE_CONSTANT;
+
+
+
+
+    String BACK_FORE_FORECAST_TITLE =  "@" + CommonStant.SPACE1_CONSTANT + "序号" + CommonStant.SPACE4_CONSTANT + "时间"
+            + CommonStant.SPACE4_CONSTANT + "功率预测" + CommonStant.SPACE4_CONSTANT + "预计开机容量"
+            + CommonStant.LINE_CONSTANT;
+
+    String BACK_FORE_FORECAST_TEMPLATE = "# {}" + CommonStant.SPACE4_CONSTANT + "{}" + CommonStant.SPACE4_CONSTANT + "{}" + CommonStant.SPACE4_CONSTANT + "{}"
+            + CommonStant.LINE_CONSTANT;
+
+    String BACK_FORE_FORECAST_TITLE_REPORT = "@" + CommonStant.SPACE1_CONSTANT + "序号" + CommonStant.SPACE2_CONSTANT + "上报" + CommonStant.LINE_CONSTANT;
+    String BACK_FORE_FORECAST_TEMPLATE_REPORT = "# 1" + CommonStant.SPACE2_CONSTANT + "{}" + CommonStant.LINE_CONSTANT;
+
+    String BACK_STAT_REAL_WEATHER_TITLE_E2  ="@" + CommonStant.SPACE1_CONSTANT + "序号" + CommonStant.SPACE4_CONSTANT + "风速" + CommonStant.SPACE4_CONSTANT + "风向"
+            + CommonStant.SPACE4_CONSTANT + "温度" + CommonStant.SPACE4_CONSTANT + "湿度" + CommonStant.SPACE4_CONSTANT + "气压"
+            + CommonStant.LINE_CONSTANT;
+
+    String BACK_STAT_REAL_WEATHER_TEMPLATE_E2 = "# 1" + CommonStant.SPACE1_CONSTANT + "{}" + CommonStant.SPACE4_CONSTANT + "{}" + CommonStant.SPACE4_CONSTANT
+            + "{}" + CommonStant.SPACE4_CONSTANT + "{}" + CommonStant.SPACE4_CONSTANT + "{}" + CommonStant.SPACE4_CONSTANT
+            + CommonStant.LINE_CONSTANT;
+
+
+    String BACK_STAT_REAL_WEATHER_TITLE_E1 = "@" + 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;
+
+    String BACK_STAT_REAL_WEATHER_TEMPLATE_E1 = "# 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;
+
+
+
+    String BACK_STAT_REAL_POWER_TITLE= "@" + CommonStant.SPACE1_CONSTANT + "序号" + CommonStant.SPACE2_CONSTANT + "实发功率值" + CommonStant.LINE_CONSTANT;
+
+    String BACK_STAT_REAL_POWER_TEMPLATE= "# 1" + CommonStant.SPACE2_CONSTANT + "{}" + CommonStant.LINE_CONSTANT;
+
+
+    String HEADER_TEMPLATE = "<! Entity={}  time='{}' !>" + CommonStant.LINE_CONSTANT;
+
+
+    static String GEN_LABELSTART(String code){
+        return StrUtil.format("<{}>" + CommonStant.LINE_CONSTANT,code);
+    }
+    static String GEN_LABELEND(String code){
+        return StrUtil.format("</{}>" + CommonStant.LINE_CONSTANT, code);
+    }
+}

+ 3 - 3
in-client-qn/src/main/java/com/jiayue/insu/inclientqn/job/BackDataForecastPowerJob.java

@@ -32,10 +32,10 @@ public class BackDataForecastPowerJob implements Job {
 
     @Override
     public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
+        //生成请求时间
         long time = DateTimeUtils.get15min(DateUtil.date().getTime());
-        LocalDateTime localDateTime = LocalDateTimeUtil.of(time);
-
-        LocalDateTime beginDay = LocalDateTimeUtil.beginOfDay(localDateTime);
+        //查询记录时间
+        LocalDateTime beginDay = LocalDateTimeUtil.beginOfDay(LocalDateTime.now());
 
         Record record = recordService.findTimeAndTypeAndContentAndState(beginDay, CommonStant.RECORD_TYPE_BACK_DATA, QNHLEnum.DATA_FORE_TYPE_UltraShortTermForecast.getCode(), StatusEnum.SUCCESS.getSign());
 

+ 43 - 0
in-client-qn/src/main/java/com/jiayue/insu/inclientqn/job/BackForeDataJob.java

@@ -0,0 +1,43 @@
+package com.jiayue.insu.inclientqn.job;
+
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.date.LocalDateTimeUtil;
+import com.jiayue.insu.inclientqn.constant.CommonStant;
+import com.jiayue.insu.inclientqn.entity.Record;
+import com.jiayue.insu.inclientqn.inenum.StatusEnum;
+import com.jiayue.insu.inclientqn.service.RecordService;
+import com.jiayue.insu.inclientqn.service.client.RequestDataService;
+import com.jiayue.insu.inclientqn.util.DateTimeUtils;
+import org.quartz.Job;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.time.LocalDateTime;
+
+/**
+ * @description: 回传预测数据定时任务
+ * @author: yuanhao
+ * @createDate: 2022/6/17
+ * @version: 1.0
+ */
+public class BackForeDataJob implements Job {
+
+
+    @Autowired
+    private RequestDataService requestDataService;
+    @Autowired
+    private RecordService recordService;
+
+    @Override
+    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
+        long time = DateTimeUtils.get15min(DateUtil.date().getTime());
+        LocalDateTime localDateTime = LocalDateTimeUtil.of(time);
+        Record record = recordService.findTimeAndTypeAndContentAndState(localDateTime, CommonStant.RECORD_TYPE_BACK_DATA, "BACK_FORE_ALL", StatusEnum.SUCCESS.getSign());
+
+        if (record == null) {
+            requestDataService.requestBackFore(time);
+        }
+
+    }
+}

+ 44 - 0
in-client-qn/src/main/java/com/jiayue/insu/inclientqn/job/BackStatDataJob.java

@@ -0,0 +1,44 @@
+package com.jiayue.insu.inclientqn.job;
+
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.date.LocalDateTimeUtil;
+import com.jiayue.insu.inclientqn.constant.CommonStant;
+import com.jiayue.insu.inclientqn.entity.Record;
+import com.jiayue.insu.inclientqn.inenum.QNHLEnum;
+import com.jiayue.insu.inclientqn.inenum.StatusEnum;
+import com.jiayue.insu.inclientqn.service.RecordService;
+import com.jiayue.insu.inclientqn.service.client.RequestDataService;
+import com.jiayue.insu.inclientqn.util.DateTimeUtils;
+import org.quartz.Job;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.time.LocalDateTime;
+
+/**
+ * @description: 回传统计数据定时任务
+ * @author: yuanhao
+ * @createDate: 2022/6/17
+ * @version: 1.0
+ */
+public class BackStatDataJob implements Job {
+
+
+    @Autowired
+    private RequestDataService requestDataService;
+    @Autowired
+    private RecordService recordService;
+
+    @Override
+    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
+        long time = DateTimeUtils.get15min(DateUtil.date().getTime());
+        LocalDateTime localDateTime = LocalDateTimeUtil.of(time);
+        Record record = recordService.findTimeAndTypeAndContentAndState(localDateTime, CommonStant.RECORD_TYPE_BACK_DATA, "BACK_STAT_ALL", StatusEnum.SUCCESS.getSign());
+
+        if (record == null) {
+            requestDataService.requestBackStat(time);
+        }
+
+    }
+}

+ 245 - 0
in-client-qn/src/main/java/com/jiayue/insu/inclientqn/service/client/BackDataGenBodyService.java

@@ -0,0 +1,245 @@
+package com.jiayue.insu.inclientqn.service.client;
+
+import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.date.DatePattern;
+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.constant.TemplateStant;
+import com.jiayue.insu.inclientqn.entity.BackForeForecastData;
+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 lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
+import org.springframework.stereotype.Service;
+
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+
+/**
+ * @description: 回传数据请求生成
+ * @author: yuanhao
+ * @createDate: 2022/6/17
+ * @version: 1.0
+ */
+@Service
+@Slf4j
+@RequiredArgsConstructor
+@RefreshScope
+public class BackDataGenBodyService {
+
+    /**
+     * 生成回传实际功率
+     *
+     * @param backStatDatas 数据集
+     * @return RequestVo
+     */
+    public StringBuilder genStateRealPowerData(List<BackStatData> backStatDatas) {
+
+        StringBuilder content = new StringBuilder();
+
+        String labelStart = TemplateStant.GEN_LABELSTART(QNHLEnum.DATA_STAT_TYPE_RealPower.getCode());
+        String labelEnd = TemplateStant.GEN_LABELEND(QNHLEnum.DATA_STAT_TYPE_RealPower.getCode());
+        String title = TemplateStant.BACK_STAT_REAL_POWER_TITLE;
+
+        content.append(labelStart);
+        content.append(title);
+
+        String dataContent = StrUtil.format(TemplateStant.BACK_STAT_REAL_POWER_TEMPLATE, backStatDatas.get(0).getRealPower().toString());
+
+        content.append(dataContent);
+        content.append(labelEnd);
+
+        return content;
+    }
+
+
+    /**
+     * 生成回传实际气象
+     *
+     * @param stationType   场站类型
+     * @param backStatDatas 数据集
+     * @return RequestVo
+     */
+    public StringBuilder genStateRealWeatherData(String stationType, List<BackStatData> backStatDatas) {
+
+        StringBuilder content = new StringBuilder();
+
+        String labelStart = TemplateStant.GEN_LABELSTART(QNHLEnum.DATA_STAT_TYPE_RealWeather.getCode());
+        String labelEnd = TemplateStant.GEN_LABELEND(QNHLEnum.DATA_STAT_TYPE_RealWeather.getCode());
+
+        content.append(labelStart);
+        String title = "";
+        String dataContent = "";
+        BackStatData backStatData = backStatDatas.get(0);
+
+        if (stationType.equals(ElectricFieldTypeEnum.E2.name())) {
+
+            title = TemplateStant.BACK_STAT_REAL_WEATHER_TITLE_E2;
+            dataContent = StrUtil.format(TemplateStant.BACK_STAT_REAL_WEATHER_TEMPLATE_E2, backStatData.getWs().toString(), backStatData.getWd().toString()
+                    , backStatData.getTemperature().toString(), backStatData.getHumidity().toString(), backStatData.getPressure().toString());
+
+        } else {
+
+            title = TemplateStant.BACK_STAT_REAL_WEATHER_TITLE_E1;
+            dataContent = StrUtil.format(TemplateStant.BACK_STAT_REAL_WEATHER_TEMPLATE_E1, 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);
+
+
+        return content;
+    }
+
+
+    /**
+     * 生成短期上报
+     *
+     * @param backStatDatas 结果集
+     * @return RequestVo
+     */
+    public StringBuilder genStateForecastPowerReport(List<BackStatData> backStatDatas) {
+
+        StringBuilder content = new StringBuilder();
+
+
+        String labelStart = TemplateStant.GEN_LABELSTART(QNHLEnum.DATA_STAT_TYPE_ForecastPowerReport.getCode());
+        String labelEnd = TemplateStant.GEN_LABELEND(QNHLEnum.DATA_STAT_TYPE_ForecastPowerReport.getCode());
+        String title = TemplateStant.BACK_FORE_FORECAST_TITLE_REPORT;
+
+
+        content.append(labelStart);
+        content.append(title);
+
+        String dataContent = StrUtil.format(TemplateStant.BACK_FORE_FORECAST_TEMPLATE_REPORT, backStatDatas.get(0).getReportStateForecast().toString());
+
+        content.append(dataContent);
+        content.append(labelEnd);
+
+
+        return content;
+    }
+
+
+    /**
+     * 生成超短期上报
+     *
+     * @param backStatDatas 数据集
+     * @return RequestVo
+     */
+    public StringBuilder genStateUltraShortTermForecastReport(List<BackStatData> backStatDatas) {
+
+
+        StringBuilder content = new StringBuilder();
+        if (CollectionUtil.isNotEmpty(backStatDatas) && backStatDatas.get(0).getReportStateForecastshort() != null) {
+
+
+            String labelStart = TemplateStant.GEN_LABELSTART(QNHLEnum.DATA_STAT_TYPE_UltraShortTermForecastReport.getCode());
+            String labelEnd = TemplateStant.GEN_LABELEND(QNHLEnum.DATA_STAT_TYPE_UltraShortTermForecastReport.getCode());
+            String title = TemplateStant.BACK_FORE_US_FORECAST_TITLE_REPORT;
+
+            content.append(labelStart);
+            content.append(title);
+
+
+            String dataContent = StrUtil.format(TemplateStant.BACK_FORE_US_FORECAST_TITLE_TEMPLATE, backStatDatas.get(0).getReportStateForecastshort().toString());
+
+            content.append(dataContent);
+            content.append(labelEnd);
+
+
+        }
+
+
+        return content;
+    }
+
+
+    public StringBuilder genForeUltraShortTermForecast(String stationType, List<BackForeUsForecastData> backForeUsForecastDatas) {
+
+
+        StringBuilder content = new StringBuilder();
+
+        Collections.sort(backForeUsForecastDatas, Comparator.comparing(BackForeUsForecastData::getForecastTime));
+
+        String labelStart = TemplateStant.GEN_LABELSTART(QNHLEnum.DATA_FORE_TYPE_UltraShortTermForecast.getCode());
+        String labelEnd = TemplateStant.GEN_LABELEND(QNHLEnum.DATA_FORE_TYPE_UltraShortTermForecast.getCode());
+
+        String title = "";
+        String template = "";
+
+        content.append(labelStart);
+
+
+        if (stationType.equals(ElectricFieldTypeEnum.E2.name())) {
+            title = TemplateStant.BACK_FORE_US_FORECAST_TITLE_E2;
+            template = TemplateStant.BACK_FORE_US_FORECAST_TEMPLATE_E2;
+
+        } else {
+            title = TemplateStant.BACK_FORE_US_FORECAST_TITLE_E1;
+            template = TemplateStant.BACK_FORE_US_FORECAST_TEMPLATE_E1;
+
+        }
+
+        content.append(title);
+
+        for (int i = 0; i < backForeUsForecastDatas.size(); i++) {
+
+            BackForeUsForecastData b = backForeUsForecastDatas.get(i);
+            String format = LocalDateTimeUtil.format(b.getForecastTime(), DatePattern.PURE_DATETIME_PATTERN);
+            String dataContent = StrUtil.format(template, i, format, b.getForecastValue(), b.getForecastOpenCap());
+            content.append(dataContent);
+        }
+
+        content.append(labelEnd);
+
+
+        return content;
+    }
+
+
+    public StringBuilder genForeForecast(List<BackForeForecastData> backForeForecastDatas) {
+
+
+        StringBuilder content = new StringBuilder();
+
+        Collections.sort(backForeForecastDatas, Comparator.comparing(BackForeForecastData::getForecastTime));
+
+        String labelStart = TemplateStant.GEN_LABELSTART(QNHLEnum.DATA_FORE_TYPE_ForecastPower.getCode());
+        String labelEnd = TemplateStant.GEN_LABELEND(QNHLEnum.DATA_FORE_TYPE_ForecastPower.getCode());
+
+        String title = TemplateStant.BACK_FORE_FORECAST_TITLE;
+
+        content.append(labelStart);
+        content.append(title);
+
+        for (int i = 0; i < backForeForecastDatas.size(); i++) {
+
+            BackForeForecastData b = backForeForecastDatas.get(i);
+            String format = LocalDateTimeUtil.format(b.getForecastTime(), DatePattern.PURE_DATETIME_PATTERN);
+            String dataContent = StrUtil.format( TemplateStant.BACK_FORE_FORECAST_TEMPLATE, i+1, format, b.getForecastValue(), b.getForecastOpenCap());
+            content.append(dataContent);
+        }
+
+        content.append(labelEnd);
+
+
+        return content;
+    }
+
+
+}

+ 51 - 63
in-client-qn/src/main/java/com/jiayue/insu/inclientqn/service/client/BackDataGenService.java

@@ -6,23 +6,21 @@ 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.constant.TemplateStant;
 import com.jiayue.insu.inclientqn.entity.BackForeForecastData;
 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;
 
 
 /**
@@ -37,11 +35,6 @@ import java.util.stream.Collectors;
 @RefreshScope
 public class BackDataGenService {
 
-    private String headerTemplate = "<! Entity={}  time='{}' !>" + CommonStant.LINE_CONSTANT;
-
-    private final BackStatDataService backStatDataService;
-
-
     /**
      * 生成回传实际功率
      *
@@ -55,15 +48,15 @@ public class BackDataGenService {
         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;
+            String header = StrUtil.format(TemplateStant.HEADER_TEMPLATE, el, DateUtil.parse(DateUtil.now()).toString("yyyy-MM-dd HH:mm:ss"));
+            String labelStart = TemplateStant.GEN_LABELSTART( QNHLEnum.DATA_STAT_TYPE_RealPower.getCode());
+            String labelEnd = TemplateStant.GEN_LABELEND( QNHLEnum.DATA_STAT_TYPE_RealPower.getCode());
+            String title = TemplateStant.BACK_STAT_REAL_POWER_TITLE;
             content.append(header);
             content.append(labelStart);
             content.append(title);
 
-            String template = "# 1" + CommonStant.SPACE2_CONSTANT + "{}" + CommonStant.LINE_CONSTANT;
+            String template = TemplateStant.BACK_STAT_REAL_POWER_TEMPLATE;
 
             String dataContent = StrUtil.format(template, backStatDatas.get(0).getRealPower().toString());
 
@@ -92,9 +85,9 @@ public class BackDataGenService {
         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());
+            String header = StrUtil.format(TemplateStant.HEADER_TEMPLATE, el, DateUtil.parse(DateUtil.now()).toString("yyyy-MM-dd HH:mm:ss"));
+            String labelStart = TemplateStant.GEN_LABELSTART( QNHLEnum.DATA_STAT_TYPE_RealWeather.getCode());
+            String labelEnd = TemplateStant.GEN_LABELEND( QNHLEnum.DATA_STAT_TYPE_RealWeather.getCode());
             content.append(header);
             content.append(labelStart);
             String title = "";
@@ -103,28 +96,16 @@ public class BackDataGenService {
             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;
 
+                title = TemplateStant.BACK_STAT_REAL_WEATHER_TITLE_E2;
+                template = TemplateStant.BACK_STAT_REAL_WEATHER_TEMPLATE_E2;
                 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;
 
+                title = TemplateStant.BACK_STAT_REAL_WEATHER_TITLE_E1;
+                template = TemplateStant.BACK_STAT_REAL_WEATHER_TEMPLATE_E1;
                 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()
@@ -158,15 +139,16 @@ public class BackDataGenService {
         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;
+            String header = StrUtil.format(TemplateStant.HEADER_TEMPLATE, el, DateUtil.parse(DateUtil.now()).toString("yyyy-MM-dd HH:mm:ss"));
+            String labelStart = TemplateStant.GEN_LABELSTART( QNHLEnum.DATA_STAT_TYPE_ForecastPowerReport.getCode());
+            String labelEnd = TemplateStant.GEN_LABELEND( QNHLEnum.DATA_STAT_TYPE_ForecastPowerReport.getCode());
+            String title = TemplateStant.BACK_FORE_FORECAST_TITLE_REPORT;
+
             content.append(header);
             content.append(labelStart);
             content.append(title);
 
-            String template = "# 1" + CommonStant.SPACE2_CONSTANT + "{}" + CommonStant.LINE_CONSTANT;
+            String template = TemplateStant.BACK_FORE_FORECAST_TEMPLATE_REPORT;
 
             String dataContent = StrUtil.format(template, backStatDatas.get(0).getReportStateForecast().toString());
 
@@ -194,15 +176,16 @@ public class BackDataGenService {
         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;
+            String header = StrUtil.format(TemplateStant.HEADER_TEMPLATE, el, DateUtil.parse(DateUtil.now()).toString("yyyy-MM-dd HH:mm:ss"));
+            String labelStart = TemplateStant.GEN_LABELSTART( QNHLEnum.DATA_STAT_TYPE_UltraShortTermForecastReport.getCode());
+            String labelEnd = TemplateStant.GEN_LABELEND( QNHLEnum.DATA_STAT_TYPE_UltraShortTermForecastReport.getCode());
+            String title = TemplateStant.BACK_FORE_US_FORECAST_TITLE_REPORT;
+
             content.append(header);
             content.append(labelStart);
             content.append(title);
 
-            String template = "# 1" + CommonStant.SPACE2_CONSTANT + "{}" + CommonStant.LINE_CONSTANT;
+            String template = TemplateStant.BACK_FORE_US_FORECAST_TITLE_TEMPLATE;
 
             String dataContent = StrUtil.format(template, backStatDatas.get(0).getReportStateForecastshort().toString());
 
@@ -217,7 +200,7 @@ public class BackDataGenService {
     }
 
 
-    public RequestVo genForeUltraShortTermForecast(String el, long signTime, List<BackForeUsForecastData> backForeUsForecastDatas) throws Exception {
+    public RequestVo genForeUltraShortTermForecast(String el, String stationType, long signTime, List<BackForeUsForecastData> backForeUsForecastDatas) throws Exception {
 
         RequestVo requestVo = null;
 
@@ -225,20 +208,28 @@ public class BackDataGenService {
 
             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;
+            String header = StrUtil.format(TemplateStant.HEADER_TEMPLATE, el, DateUtil.parse(DateUtil.now()).toString("yyyy-MM-dd HH:mm:ss"));
+            String labelStart = TemplateStant.GEN_LABELSTART( QNHLEnum.DATA_FORE_TYPE_UltraShortTermForecast.getCode());
+            String labelEnd = TemplateStant.GEN_LABELEND( QNHLEnum.DATA_FORE_TYPE_UltraShortTermForecast.getCode());
+
+            String title = "";
+            String template = "";
+
             content.append(header);
             content.append(labelStart);
-            content.append(title);
 
-            String template = "# {}" + CommonStant.SPACE4_CONSTANT + "{}" + 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.LINE_CONSTANT;
+
+            if (stationType.equals(ElectricFieldTypeEnum.E2.name())) {
+                title = TemplateStant.BACK_FORE_US_FORECAST_TITLE_E2;
+                template = TemplateStant.BACK_FORE_US_FORECAST_TEMPLATE_E2;
+
+            } else {
+                title = TemplateStant.BACK_FORE_US_FORECAST_TITLE_E1;
+                template = TemplateStant.BACK_FORE_US_FORECAST_TEMPLATE_E1;
+
+            }
+
+            content.append(title);
 
             for (int i = 0; i < backForeUsForecastDatas.size(); i++) {
 
@@ -271,18 +262,16 @@ public class BackDataGenService {
             if (checkDate) {
                 Collections.sort(backForeForecastDatas, Comparator.comparing(BackForeForecastData::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.LINE_CONSTANT;
+                String header = StrUtil.format(TemplateStant.HEADER_TEMPLATE, el, DateUtil.parse(DateUtil.now()).toString("yyyy-MM-dd HH:mm:ss"));
+                String labelStart = TemplateStant.GEN_LABELSTART( QNHLEnum.DATA_FORE_TYPE_ForecastPower.getCode());
+                String labelEnd = TemplateStant.GEN_LABELEND( QNHLEnum.DATA_FORE_TYPE_ForecastPower.getCode());
+
+                String title = TemplateStant.BACK_FORE_FORECAST_TITLE;
                 content.append(header);
                 content.append(labelStart);
                 content.append(title);
 
-                String template = "# {}" + CommonStant.SPACE4_CONSTANT + "{}" + CommonStant.SPACE4_CONSTANT + "{}" + CommonStant.SPACE4_CONSTANT + "{}"
-                        + CommonStant.LINE_CONSTANT;
+                String template = TemplateStant.BACK_FORE_FORECAST_TEMPLATE;
 
                 for (int i = 0; i < backForeForecastDatas.size(); i++) {
 
@@ -298,7 +287,6 @@ public class BackDataGenService {
             }
         }
 
-
         return requestVo;
     }
 

+ 182 - 6
in-client-qn/src/main/java/com/jiayue/insu/inclientqn/service/client/RequestDataService.java

@@ -1,10 +1,13 @@
 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 cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
 import com.jiayue.insu.inclientqn.constant.CommonStant;
+import com.jiayue.insu.inclientqn.constant.TemplateStant;
 import com.jiayue.insu.inclientqn.entity.*;
 import com.jiayue.insu.inclientqn.inenum.QNHLEnum;
 import com.jiayue.insu.inclientqn.inenum.StatusEnum;
@@ -40,6 +43,8 @@ public class RequestDataService {
 
     private final BackDataGenService backDataGenService;
 
+    private final BackDataGenBodyService backDataGenBodyService;
+
     private final StationService stationService;
 
     private final ComPermisson comPermisson;
@@ -48,9 +53,162 @@ public class RequestDataService {
 
     private final BackStatDataService backStatDataService;
 
+
     private final BackForeUsForecastDataService backForeUsForecastDataService;
+
     private final BackForeForecastDataService backForeForecastDataService;
 
+
+    public void requestBackStat(long signTime) {
+        LocalDateTime localDateTime = LocalDateTimeUtil.of(signTime);
+
+        Record record = new Record();
+        record.setType(CommonStant.RECORD_TYPE_BACK_DATA);
+        record.setTime(localDateTime);
+        record.setCreateTime(LocalDateTime.now());
+        record.setContent("BACK_STAT_ALL");
+
+        Station station = stationService.findThis();
+        StringBuilder stringBuilder = new StringBuilder();
+        List<BackStatData> backStatDatas = backStatDataService.findBySignTime(localDateTime);
+        if (CollectionUtil.isNotEmpty(backStatDatas)) {
+            String header = StrUtil.format(TemplateStant.HEADER_TEMPLATE, station.getSignCode(), DateUtil.parse(DateUtil.now()).toString("yyyy-MM-dd HH:mm:ss"));
+            stringBuilder.append(header);
+
+            stringBuilder.append(backDataGenBodyService.genStateRealPowerData(backStatDatas));
+            stringBuilder.append(backDataGenBodyService.genStateRealWeatherData(station.getType(), backStatDatas));
+            stringBuilder.append(backDataGenBodyService.genStateForecastPowerReport(backStatDatas));
+            stringBuilder.append(backDataGenBodyService.genStateUltraShortTermForecastReport(backStatDatas));
+
+            RequestVo requestVo = RequestVo.UPLOAD_STAT(station.getSignCode(), stringBuilder.toString(), signTime);
+
+            //校验请求数据是否为null  和  token是否有效
+            if (requestVo != null && comPermisson.isToken(station)) {
+                JSONObject json = JSONUtil.parseObj(requestVo, true);
+                String body = json.toString();
+                System.out.println("----------------------------------------------------------------------");
+                System.out.println(body);
+                System.out.println("----------------------------------------------------------------------");
+                String response = RequestUtils.post(station.getBackurl(), body, station.getComKey());
+
+                if (RequestUtils.checkResponse(response, record)) {
+
+                    ResponseVo responseVo = JSONUtil.toBean(response, ResponseVo.class);
+                    String code = responseVo.getRetCode();
+
+                    if (code.equals(QNHLEnum.REQUEST_SUCCESS.getCode())) {
+
+                        record.setState(StatusEnum.SUCCESS.getSign());
+                        record.setStateContent(responseVo.getRetMsg());
+
+                        BackStatData backStatData = backStatDatas.get(0);
+
+                        backStatData.setBackTime(LocalDateTime.now());
+
+                        try {
+                            backStatDataService.saveOrUpdate(backStatData);
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                        }
+
+                    } else {
+                        record.setState(code);
+                        record.setStateContent(responseVo.getRetMsg());
+                    }
+                }
+
+            } else {
+                record.setState(StatusEnum.BACK_DATA_GEN_FAIL.getSign());
+                record.setStateContent("token失效或请求体为null");
+            }
+
+
+        }
+
+        recordService.save(record);
+    }
+
+
+    public void requestBackFore(long signTime) {
+        LocalDateTime localDateTime = LocalDateTimeUtil.of(signTime);
+        LocalDateTime beginDay = LocalDateTimeUtil.beginOfDay(localDateTime);
+
+        Record record = new Record();
+        record.setType(CommonStant.RECORD_TYPE_BACK_DATA);
+        record.setTime(localDateTime);
+        record.setCreateTime(LocalDateTime.now());
+        record.setContent("BACK_FORE_ALL");
+
+        Station station = stationService.findThis();
+        StringBuilder stringBuilder = new StringBuilder();
+        String header = StrUtil.format(TemplateStant.HEADER_TEMPLATE, station.getSignCode(), DateUtil.parse(DateUtil.now()).toString("yyyy-MM-dd HH:mm:ss"));
+        stringBuilder.append(header);
+
+        List<BackForeUsForecastData> uList = backForeUsForecastDataService.findBySignTime(localDateTime);
+
+        List<BackForeForecastData> list = backForeForecastDataService.findBySignTime(beginDay);
+
+        if (CollectionUtil.isNotEmpty(uList)) {
+            stringBuilder.append(backDataGenBodyService.genForeUltraShortTermForecast(station.getType(),uList));
+
+            uList.forEach(u->u.setBackTime(LocalDateTime.now()));
+        }
+
+        if (CollectionUtil.isNotEmpty(list)) {
+            stringBuilder.append(backDataGenBodyService.genForeForecast(list));
+
+            list.forEach(u->u.setBackTime(LocalDateTime.now()));
+        }
+
+        RequestVo requestVo = RequestVo.UPLOAD_FORE(station.getSignCode(), stringBuilder.toString(), signTime);
+        //校验请求数据是否为null  和  token是否有效
+        if (stringBuilder != null && comPermisson.isToken(station)) {
+            JSONObject json = JSONUtil.parseObj(requestVo, true);
+            String body = json.toString();
+            System.out.println("----------------------------------------------------------------------");
+            System.out.println(body);
+            System.out.println("----------------------------------------------------------------------");
+            String response = RequestUtils.post(station.getBackurl(), body, station.getComKey());
+
+            if (RequestUtils.checkResponse(response, record)) {
+
+                ResponseVo responseVo = JSONUtil.toBean(response, ResponseVo.class);
+                String code = responseVo.getRetCode();
+
+                if (code.equals(QNHLEnum.REQUEST_SUCCESS.getCode())) {
+
+                    record.setState(StatusEnum.SUCCESS.getSign());
+                    record.setStateContent(responseVo.getRetMsg());
+
+
+
+                    try {
+                        backForeUsForecastDataService.saveOrUpdateBatch(uList);
+                        backForeForecastDataService.saveOrUpdateBatch(list);
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+
+                } else {
+                    record.setState(code);
+                    record.setStateContent(responseVo.getRetMsg());
+                }
+            }
+
+        } else {
+            record.setState(StatusEnum.BACK_DATA_GEN_FAIL.getSign());
+            record.setStateContent("token失效或请求体为null");
+        }
+
+        recordService.save(record);
+    }
+
+    /**
+     * 回传统计数据
+     *
+     * @param qnhlEnum 类型
+     * @param signTime 标记时间
+     */
     public void requestBackStatData(QNHLEnum qnhlEnum, long signTime) {
 
         LocalDateTime localDateTime = LocalDateTimeUtil.of(signTime);
@@ -94,6 +252,9 @@ public class RequestDataService {
         if (requestVo != null && comPermisson.isToken(station)) {
             JSONObject json = JSONUtil.parseObj(requestVo, true);
             String body = json.toString();
+            System.out.println("----------------------------------------------------------------------");
+            System.out.println(body);
+            System.out.println("----------------------------------------------------------------------");
             String response = RequestUtils.post(station.getBackurl(), body, station.getComKey());
 
             if (RequestUtils.checkResponse(response, record)) {
@@ -125,7 +286,7 @@ public class RequestDataService {
                     }
 
                     try {
-                        backStatDataService.save(backStatData);
+                        backStatDataService.saveOrUpdate(backStatData);
                     } catch (Exception e) {
                         e.printStackTrace();
                     }
@@ -145,7 +306,12 @@ public class RequestDataService {
         recordService.save(record);
     }
 
-
+    /**
+     * 回传超短期数据
+     *
+     * @param qnhlEnum 类型
+     * @param signTime 标记时间
+     */
     public void requestBackForeUsData(QNHLEnum qnhlEnum, long signTime) {
 
         LocalDateTime localDateTime = LocalDateTimeUtil.of(signTime);
@@ -163,7 +329,7 @@ public class RequestDataService {
 
         RequestVo requestVo = null;
         try {
-            requestVo = backDataGenService.genForeUltraShortTermForecast(station.getSignCode(), signTime, list);
+            requestVo = backDataGenService.genForeUltraShortTermForecast(station.getSignCode(), station.getType(), signTime, list);
 
         } catch (Exception e) {
             e.printStackTrace();
@@ -173,6 +339,9 @@ public class RequestDataService {
         if (requestVo != null && comPermisson.isToken(station)) {
             JSONObject json = JSONUtil.parseObj(requestVo, true);
             String body = json.toString();
+            System.out.println("----------------------------------------------------------------------");
+            System.out.println(body);
+            System.out.println("----------------------------------------------------------------------");
             String response = RequestUtils.post(station.getBackurl(), body, station.getComKey());
 
             if (RequestUtils.checkResponse(response, record)) {
@@ -208,8 +377,12 @@ public class RequestDataService {
     }
 
 
-
-
+    /**
+     * 回传短期数据
+     *
+     * @param qnhlEnum 类型
+     * @param signTime 标记时间
+     */
 
     public void requestBackForeData(QNHLEnum qnhlEnum, long signTime) {
 
@@ -238,6 +411,9 @@ public class RequestDataService {
         if (requestVo != null && comPermisson.isToken(station)) {
             JSONObject json = JSONUtil.parseObj(requestVo, true);
             String body = json.toString();
+            System.out.println("----------------------------------------------------------------------");
+            System.out.println(body);
+            System.out.println("----------------------------------------------------------------------");
             String response = RequestUtils.post(station.getBackurl(), body, station.getComKey());
 
             if (RequestUtils.checkResponse(response, record)) {
@@ -252,7 +428,7 @@ public class RequestDataService {
                     list.forEach(f -> f.setBackTime(LocalDateTime.now()));
 
                     try {
-                        backForeForecastDataService.saveBatch(list);
+                        backForeForecastDataService.saveOrUpdateBatch(list);
                     } catch (Exception e) {
                         e.printStackTrace();
                     }

+ 14 - 1
in-client-qn/src/main/java/com/jiayue/insu/inclientqn/util/RequestUtils.java

@@ -7,7 +7,13 @@ import com.jiayue.insu.inclientqn.entity.Record;
 import com.jiayue.insu.inclientqn.inenum.StatusEnum;
 
 public class RequestUtils {
-
+    /**
+     * 回传数据post请求
+     * @param url 请求路径
+     * @param body 请求体
+     * @param token token
+     * @return 结果
+     */
     public static String post(String url,String body,String token){
         String response = "";
 
@@ -28,6 +34,13 @@ public class RequestUtils {
 
     }
 
+    /**
+     *
+     * @param response  返回数据
+     * @param record 记录
+     * @return 是否返回数据正常
+     */
+
     public static boolean checkResponse(String response,Record record){
         boolean result = false;
         if (StrUtil.isNotEmpty(response)) {

+ 27 - 1
in-client-qn/src/test/java/com/jiayue/insu/inclientqn/service/BackDataGenServiceTest.java

@@ -5,6 +5,7 @@ import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.date.LocalDateTimeUtil;
 import cn.hutool.core.util.RandomUtil;
 import com.jiayue.insu.inclientqn.BaseTest;
+import com.jiayue.insu.inclientqn.entity.BackForeForecastData;
 import com.jiayue.insu.inclientqn.entity.BackForeUsForecastData;
 import com.jiayue.insu.inclientqn.inenum.QNHLEnum;
 import com.jiayue.insu.inclientqn.service.client.BackDataGenService;
@@ -25,7 +26,8 @@ public class BackDataGenServiceTest extends BaseTest {
     private RequestDataService requestDataService;
     @Autowired
     private BackForeUsForecastDataService backForeUsForecastDataService;
-
+    @Autowired
+    private BackForeForecastDataService backForeForecastDataService;
     @Test
     void test() {
         try {
@@ -81,4 +83,28 @@ public class BackDataGenServiceTest extends BaseTest {
     }
 
 
+    @Test
+    void test4() {
+        try {
+
+            LocalDateTime beginOfDay = LocalDateTimeUtil.beginOfDay(LocalDateTime.now());
+            LocalDateTime forecastTime = beginOfDay.plusDays(1);
+            List<BackForeForecastData> list = new ArrayList<>();
+            for (int i = 0; i < 288; i++) {
+                BackForeForecastData backForeForecastData = new BackForeForecastData();
+                backForeForecastData.setSignTime(beginOfDay);
+                backForeForecastData.setForecastTime(forecastTime.plusMinutes(15 * i));
+                backForeForecastData.setForecastValue(RandomUtil.randomBigDecimal(new BigDecimal(50)));
+                backForeForecastData.setForecastOpenCap(new BigDecimal("50"));
+                list.add(backForeForecastData);
+            }
+
+            backForeForecastDataService.saveBatch(list);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+    }
+
+
 }