Browse Source

一体化云端:
内蒙东润 上传sftp 模板修改
日志修改

zhangchenglong 3 weeks ago
parent
commit
bb8a8bb2bd

+ 23 - 9
in-cloud/src/main/java/com/jiayue/insu/incloud/pushdata/PushCommon.java

@@ -88,8 +88,11 @@ public class PushCommon {
         String todayStr = today.format(formatter);
 
         // 获取已经下载的预测文件内容
-        List<String> originalContents = getInitFileLines(todayStr,filePath,record,"DQ");
-
+        List<String> originalContents = getInitFileLines(stationCode ,todayStr,filePath,record,"DQ");
+        if (originalContents == null || originalContents.size() == 0) {
+            log.error("场站{}下载的文件为空",stationCode);
+            return false;
+        }
         List<Map<String, Object>> vList = new ArrayList<>();
         String dataTime[];
         // 循环解析原始短期文件
@@ -120,6 +123,14 @@ public class PushCommon {
                 // 将预测时间和预测功率放入list中
                 map.put("forecastTime", dataTime[0] + "_" + dataTime[1]);
                 map.put("fpValue", originalContentArr[3]);
+                String valueString = originalContentArr[3];
+                try {
+                    BigDecimal decimal = new BigDecimal(valueString);
+                    map.put("upper", decimal.multiply(new BigDecimal("1.1")));
+                    map.put("lower", decimal.multiply(new BigDecimal("0.9")));
+                } catch (NumberFormatException e) {
+                    System.err.println("输入字符串格式错误");
+                }
                 vList.add(map);
             }
         }
@@ -156,7 +167,11 @@ public class PushCommon {
         String todayStr = today.toString("yyyyMMdd");
 
         // 获取已经下载的预测文件内容
-        List<String> originalContents = getInitFileLines(todayStr,filePath,record,"NWP");
+        List<String> originalContents = getInitFileLines(stationCode,todayStr,filePath,record,"NWP");
+        if (originalContents == null || originalContents.size() == 0) {
+            log.error("场站{}下载的文件为空",stationCode);
+            return false;
+        }
 
         List<Map<String, Object>> vList = new ArrayList<>();
         for (String originalContent : originalContents) {
@@ -224,7 +239,6 @@ public class PushCommon {
         velocityContext.put("stationCode", station.getStationCode());
         velocityContext.put("stationName", station.getName());
 
-        log.info("******templateName:{}",templateName);
         File newFile;
         // 生成新文件
         try {
@@ -282,34 +296,34 @@ public class PushCommon {
      * 获取已经下载的预测原始文件内容
      * @return
      */
-    public List<String> getInitFileLines(String todayStr,String filePath ,Record record ,String fileType){
+    public List<String> getInitFileLines(String stationCode,String todayStr,String filePath ,Record record ,String fileType){
         List<String> originalContents = new ArrayList<>();
         // 获取指定目录下的短期原始数据(/jiayue/insu/file/init/J00269/)
         File files = new File(filePath);
         String[] fileNames = files.list();
         // 如果文件名列表为空
         if (fileNames == null || fileNames.length == 0) {
-            log.info("指定目录下无文件");
+            log.info("场站:{},指定目录:{} 下无文件",stationCode,filePath);
             record.setState(StatusEnum.FILE_NULL.getSign());
             record.setStateContent(StatusEnum.FILE_NULL.getMsg());
             recordService.save(record);
             return originalContents;
         }
-        // 获取当天日期
 
         // 转为list并根据日期筛选排序
         List<String> fileList = Arrays.stream(fileNames).collect(Collectors.toList());
         List<String> filterFileList = fileList.stream().filter(s -> s.contains(todayStr)).filter(s -> s.contains(fileType)).collect(Collectors.toList());
         // 如果筛选后无文件
         if (filterFileList.size() == 0) {
-            log.info("无当日文件");
+            log.info("场站:{},无当日文件",stationCode);
             record.setState(StatusEnum.FILE_NULL.getSign());
             record.setStateContent(StatusEnum.FILE_NULL.getMsg());
             recordService.save(record);
             return originalContents;
         }
-        filterFileList.sort(Collections.reverseOrder());
 
+        // 根据时间倒序,选择最新的文件
+        filterFileList.sort(Collections.reverseOrder());
         // 获取原始文件
         File originalFile = new File(filterFileList.get(0));
         // 读取文件

+ 6 - 4
in-cloud/src/main/java/com/jiayue/insu/incloud/pushdata/PushDataForBJZYYJY.java

@@ -77,6 +77,7 @@ public class PushDataForBJZYYJY implements IPushInitForecastData {
      */
     @Override
     public Boolean pushDQData(Station station) {
+        boolean pushResult ;
         // 获取场站编号
         String stationCode = station.getStationCode();
         Record record = new Record(CommonStant.RECORD_TYPE_PUSH_INIT_TO_SFTP, CompanyConstant.COMPANY_BJZYYJY, stationCode, null, LocalDateTime.now(), LocalDateTime.now(), null, null);
@@ -163,8 +164,8 @@ public class PushDataForBJZYYJY implements IPushInitForecastData {
         // 文件数据开始时间
         String fileDateStr = DateUtil.format(DateUtil.beginOfDay(DateUtil.tomorrow()), "yyyyMMdd_HH:mm:ss");
 
-        this.pushFileToSftp(record, vList, newFilePath, newFileName, templateName, station, fileType, todayStr, fileDateStr);
-        return true;
+        pushResult = this.pushFileToSftp(record, vList, newFilePath, newFileName, templateName, station, fileType, todayStr, fileDateStr);
+        return pushResult;
     }
 
     @Override
@@ -179,6 +180,7 @@ public class PushDataForBJZYYJY implements IPushInitForecastData {
      * @return
      */
     public Boolean pushRealPowerData(Station station) {
+        boolean pushResult ;
         Record record = new Record(CommonStant.RECORD_TYPE_PUSH_REAL_POWER_TO_SFTP, CompanyConstant.COMPANY_BJZYYJY, station.getStationCode(), null, LocalDateTime.now(), LocalDateTime.now(), null, null);
         // 获取公司信息
         IntegrationCompany integrationCompany = integrationCompanyService.findByCode(CompanyConstant.COMPANY_BJZYYJY);
@@ -227,8 +229,8 @@ public class PushDataForBJZYYJY implements IPushInitForecastData {
         String sftpFilePath = todayStr + File.separatorChar + "real";
         // 文件数据开始时间
         String fileDateStr = DateUtil.format(DateUtil.beginOfDay(DateUtil.yesterday()), "yyyyMMdd_HH:mm:ss");
-        this.pushFileToSftp(record, vList, newFilePath, newFileName, templateName, station, sftpFilePath, todayStr, fileDateStr);
-        return false;
+        pushResult = this.pushFileToSftp(record, vList, newFilePath, newFileName, templateName, station, sftpFilePath, todayStr, fileDateStr);
+        return pushResult;
     }
 
     /**

+ 3 - 3
in-cloud/src/main/java/com/jiayue/insu/incloud/pushdata/PushDataToSftp.java

@@ -52,9 +52,9 @@ public class PushDataToSftp implements IPushInitForecastData {
      */
     @Override
     public Boolean pushDQAndNWPData(Station station) {
-        this.pushDQData(station);
-        this.pushNWPData(station);
-        return null;
+        Boolean dqResult = this.pushDQData(station);
+        Boolean nwpResult = this.pushNWPData(station);
+        return (dqResult && nwpResult)? true:false ;
     }
 
     /**

+ 2 - 1
in-cloud/src/main/java/com/jiayue/insu/incloud/utils/FileUtils.java

@@ -35,12 +35,13 @@ public class FileUtils {
         try {
             boolean res = file.createNewFile();
             if (res) {
+                // 创建文件
                 os = new FileOutputStream(file);
                 // 采用UTF-8字符集
                 os.write(writer.toString().getBytes("UTF-8"));
                 os.flush();
             } else {
-                log.warn(file.getName() + ":文件生成失败");
+                log.warn(file.getName() + ":文件已存在");
             }
         } catch (IOException e) {
             e.printStackTrace();

+ 7 - 2
in-cloud/src/main/java/com/jiayue/insu/incloud/utils/HttpUtils.java

@@ -43,8 +43,13 @@ public class HttpUtils {
         } catch (Exception e) {
             e.printStackTrace();
         }
-        // 将返回结果转为jsonjnn 6 vb
-        result = JSONUtil.parseObj(response);
+        if(JSONUtil.isTypeJSON(response)){
+            // 将返回结果转为jsonjnn 6 vb
+            result = JSONUtil.parseObj(response);
+        }else{
+            log.error("返回结果不是json类型,{}",response);
+        }
+
         return result;
     }
 

+ 3 - 0
in-cloud/src/main/java/com/jiayue/insu/incloud/utils/SFTPUtil.java

@@ -183,6 +183,9 @@ public class SFTPUtil {
                 log.warn("sftp文件路径异常" + e1.toString());
                 return;
             }
+        } catch (Exception e){
+            log.error("*************sftp连接异常,上传sftp失败,错误信息:{}*************",e.toString());
+            return;
         }
         try {
             sftp.put(input, sftpFileName);

+ 3 - 3
in-cloud/src/main/resources/vms/DR_DQ.vm

@@ -1,7 +1,7 @@
 <! Entity=modeloutput time='${date}' !>
-<modeloutput::${stationCode}J001>
+<modeloutput::DRF1623J001>
 times	prepower	upper	lower
 #foreach( $dq in $vList )
-${dq.forecastTime}	${dq.fpValue}	NULL	NULL
+${dq.forecastTime}	${dq.fpValue}	${dq.upper}	${dq.lower}
 #end
-</modeloutput::${stationCode}J001>
+</modeloutput::DRF1623J001>