yuanhao 2 年之前
父节点
当前提交
899fd74c50
共有 20 个文件被更改,包括 1364 次插入346 次删除
  1. 11 0
      in-client-qn/pom.xml
  2. 6 0
      in-client-qn/src/main/java/com/jiayue/insu/inclientqn/constant/CommonStant.java
  3. 2 1
      in-client-qn/src/main/java/com/jiayue/insu/inclientqn/controller/StationController.java
  4. 1 1
      in-client-qn/src/main/java/com/jiayue/insu/inclientqn/job/CorrforeDataJob.java
  5. 23 0
      in-client-qn/src/main/java/com/jiayue/insu/inclientqn/job/CorrforeFileJob.java
  6. 114 125
      in-client-qn/src/main/java/com/jiayue/insu/inclientqn/service/CorrforeService.java
  7. 5 0
      in-client-qn/src/main/resources/vms/DQ.vm
  8. 4 4
      in-cloud/pom.xml
  9. 34 0
      in-cloud/src/main/java/com/jiayue/insu/incloud/config/MinioConfig.java
  10. 1 1
      in-cloud/src/main/java/com/jiayue/insu/incloud/config/SaTokenConfigure.java
  11. 23 0
      in-cloud/src/main/java/com/jiayue/insu/incloud/controller/FileController.java
  12. 185 214
      in-cloud/src/main/java/com/jiayue/insu/incloud/pulldata/PullCorrectDataForQNHL.java
  13. 45 0
      in-cloud/src/main/java/com/jiayue/insu/incloud/service/FileService.java
  14. 396 0
      in-cloud/src/main/java/com/jiayue/insu/incloud/utils/MinioUtils.java
  15. 5 0
      in-cloud/src/main/resources/vms/DQ.vm
  16. 28 0
      in-common/in-common-minio/pom.xml
  17. 32 0
      in-common/in-common-minio/src/main/java/com/jiayue/insu/minio/config/MinioConfig.java
  18. 443 0
      in-common/in-common-minio/src/main/java/com/jiayue/insu/minio/util/MinioUtilService.java
  19. 5 0
      in-common/in-common-minio/src/main/resources/META-INF/spring.factories
  20. 1 0
      in-common/pom.xml

+ 11 - 0
in-client-qn/pom.xml

@@ -109,5 +109,16 @@
             <version>1.7</version>
         </dependency>
 
+        <dependency>
+            <groupId>io.minio</groupId>
+            <artifactId>minio</artifactId>
+            <version>8.2.1</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.jiayue</groupId>
+            <artifactId>in-common-minio</artifactId>
+            <version>1.0-SNAPSHOT</version>
+        </dependency>
     </dependencies>
 </project>

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

@@ -25,6 +25,12 @@ public interface CommonStant {
      */
     String RECORD_TYPE_PULL_CORRECT = "PULL_CORRECT";
 
+
+    /**
+     * 日志类型:下拉修正数据
+     */
+    String RECORD_TYPE_PULL_CORRECT_JY = "PULL_CORRECT_JY";
+
     /**
      * 日志类型:交互权限
      */

+ 2 - 1
in-client-qn/src/main/java/com/jiayue/insu/inclientqn/controller/StationController.java

@@ -1,5 +1,7 @@
 package com.jiayue.insu.inclientqn.controller;
 
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.http.HttpUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.jiayue.insu.common.core.util.R;
@@ -41,7 +43,6 @@ public class StationController {
         if(station.getName()!=null){
             lambdaQueryWrapper.like(Station::getName,station.getName());
         }
-
         return R.ok(stationService.page(page, lambdaQueryWrapper));
     }
 

+ 1 - 1
in-client-qn/src/main/java/com/jiayue/insu/inclientqn/job/CorrforeStJob.java → in-client-qn/src/main/java/com/jiayue/insu/inclientqn/job/CorrforeDataJob.java

@@ -9,7 +9,7 @@ import org.quartz.JobExecutionContext;
 import org.quartz.JobExecutionException;
 import org.springframework.beans.factory.annotation.Autowired;
 
-public class CorrforeStJob implements Job {
+public class CorrforeDataJob implements Job {
     @Autowired
     private CorrforeService corrforeService;
     @Autowired

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

@@ -0,0 +1,23 @@
+package com.jiayue.insu.inclientqn.job;
+
+import com.jiayue.insu.inclientqn.entity.Station;
+import com.jiayue.insu.inclientqn.service.CorrforeService;
+import com.jiayue.insu.inclientqn.service.StationService;
+import org.quartz.Job;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+import org.springframework.beans.factory.annotation.Autowired;
+
+public class CorrforeFileJob implements Job {
+    @Autowired
+    private CorrforeService corrforeService;
+    @Autowired
+    private StationService stationService;
+    @Override
+    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
+
+        Station station = stationService.findThis();
+
+        corrforeService.downLoadCorrforeFile(station);
+    }
+}

+ 114 - 125
in-client-qn/src/main/java/com/jiayue/insu/inclientqn/service/CorrforeService.java

@@ -19,11 +19,13 @@ import com.jiayue.insu.inclientqn.model.RequestVo;
 import com.jiayue.insu.inclientqn.model.ResponseVo;
 import com.jiayue.insu.inclientqn.permisson.com.ComPermisson;
 import com.jiayue.insu.inclientqn.util.SystermUtils;
+import com.jiayue.insu.minio.util.MinioUtilService;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.velocity.Template;
 import org.apache.velocity.VelocityContext;
 import org.apache.velocity.app.VelocityEngine;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import java.io.File;
@@ -58,13 +60,59 @@ public class CorrforeService extends ServiceImpl<CorrforeStMapper, CorrforeSt> {
 
     private final ComPermisson comPermisson;
 
+    private final MinioUtilService minioUtilService;
 
+    @Value("${minio.bucketname}")
+    private String bucketName;
 
     /**
-     * 下载修正预测数据
+     * 下载修正文件,从嘉越云上
      *
      * @param station
+     * @return
+     */
+    public boolean downLoadCorrforeFile(Station station) {
+
+        Record record = new Record();
+        record.setType(CommonStant.RECORD_TYPE_PULL_CORRECT_JY);
+        LocalDateTime localDateTime = LocalDateTimeUtil.beginOfDay(LocalDateTime.now());
+        record.setTime(localDateTime);
+        record.setCreateTime(LocalDateTime.now());
+
+        boolean isUpload = false;
 
+        try {
+            List<String> names = minioUtilService.listObjects(bucketName, station.getStationCode(), true);
+            boolean isFile = false;
+            String downfileName = "";
+            String fileName = station.getStationCode() + "/DQ_" + DateUtil.format(DateUtil.beginOfDay(new Date()), "yyyyMMdd");
+            for (String name : names) {
+                if (name.contains(fileName)) {
+                    isFile = true;
+                    downfileName = name;
+                    break;
+                }
+            }
+
+            if (isFile) {
+                minioUtilService.downloadObject(bucketName, downfileName, station.getLocalFilePath() + File.separatorChar + downfileName.split("/")[1]);
+            }
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            record.setState(StatusEnum.DOWNLOAD_FILE_ERROR.getSign());
+            record.setStateContent(StatusEnum.DOWNLOAD_FILE_ERROR.getMsg());
+        }
+
+
+        recordService.save(record);
+        return isUpload;
+    }
+
+    /**
+     * 下载修正预测数据,从一体化上
+     *
+     * @param station
      * @return
      */
     public boolean downLoadCorrforeData(Station station) {
@@ -139,18 +187,18 @@ public class CorrforeService extends ServiceImpl<CorrforeStMapper, CorrforeSt> {
                                 BigDecimal one = new BigDecimal("1");
                                 BigDecimal checkCount = new BigDecimal(station.getDays().toString()).add(one).multiply(new BigDecimal("96")).add(one);
 
-                                if(list.size()>0){
+                                if (list.size() > 0) {
                                     if (list.size() < checkCount.intValue()) {
                                         log.warn("========== 请求短期修正数据缺数: {}", list.size());
                                     }
                                     corrforeStService.updateBetweenForecastTime(list.get(0).getTimeFormat(), list.get(list.size() - 1).getTimeFormat(), list);
 
-                                    genFile(station,list);
+                                    genFile(station, list);
 
                                     result = true;
 
 
-                                }else{
+                                } else {
                                     record.setState(StatusEnum.CONNECT_RESPONSE_CONTENT_NULL.getCode());
                                     record.setStateContent(StatusEnum.CONNECT_RESPONSE_CONTENT_NULL.getMsg());
                                 }
@@ -160,20 +208,22 @@ public class CorrforeService extends ServiceImpl<CorrforeStMapper, CorrforeSt> {
 
                             } catch (Exception e) {
                                 record.setState(StatusEnum.CONNECT_RESPONSE_FORMAT_ERROR.getSign());
-                                record.setStateContent("解析失败");
+                                record.setStateContent("解析短期或生成文件失败");
                                 log.error("========== 解析短期或生成文件失败 ");
                             }
 
 
                             if (result) {
                                 log.info("========== 拉取短期修正数据成功! ==========");
-                                record.setState(QNHLEnum.REQUEST_SUCCESS.getSign());
-                                record.setStateContent(QNHLEnum.REQUEST_SUCCESS.getMsg());
+                                record.setState(StatusEnum.SUCCESS.getSign());
+                                record.setStateContent(String.valueOf(list.size()));
 
                             }
 
                         } else {
-
+                            record.setState(StatusEnum.RESPONSE_FAIL.getSign());
+                            record.setStateContent(StatusEnum.RESPONSE_FAIL.getMsg());
+                            log.error("========== 拉取短期修正数据失败 响应码异常 ");
                         }
                     } else {
                         record.setState(StatusEnum.CONNECT_RESPONSE_FORMAT_ERROR.getSign());
@@ -209,71 +259,39 @@ public class CorrforeService extends ServiceImpl<CorrforeStMapper, CorrforeSt> {
     public List<CorrforeSt> correctPhotovoltaicData(String data) throws Exception {
         List<CorrforeSt> list = new ArrayList<>();
 
-        try {
-            String[] content = data.split("\n");
-
-            for (int i = 3; i < content.length - 1; i++) {
-
-                CorrforeSt corrforeSt = new CorrforeSt();
-                String column = content[i];
-                String[] datas = column.split(CommonStant.SPACE1_CONSTANT);
-                corrforeSt.setForecastTime(DateUtil.parse(datas[2], "yyyyMMddHHmmss").getTime());
-                corrforeSt.setTimeFormat(DateUtil.parse(datas[2], "yyyyMMddHHmmss").toTimestamp().toLocalDateTime());
-
-                if(column.contains("NULL") || column.contains("null")){
-
-                    BigDecimal defaultValue =new BigDecimal("-99");
-
-                    corrforeSt.setFpValue(defaultValue);
+        String[] content = data.split("\n");
 
-                    corrforeSt.setGlobalR(defaultValue);
+        for (int i = 3; i < content.length - 1; i++) {
 
-                    corrforeSt.setDirectR(defaultValue);
+            CorrforeSt corrforeSt = new CorrforeSt();
+            String column = content[i];
+            String[] datas = column.split(CommonStant.SPACE1_CONSTANT);
+            corrforeSt.setForecastTime(DateUtil.parse(datas[2], "yyyyMMddHHmmss").getTime());
+            corrforeSt.setTimeFormat(DateUtil.parse(datas[2], "yyyyMMddHHmmss").toTimestamp().toLocalDateTime());
 
-                    corrforeSt.setDiffuseR(defaultValue);
+            corrforeSt.setFpValue(isNumberOrNull(datas[3]));
 
-                    corrforeSt.setT(defaultValue);
+            corrforeSt.setGlobalR(isNumberOrNull(datas[4]));
 
-                    corrforeSt.setRh(defaultValue);
+            corrforeSt.setDirectR(isNumberOrNull(datas[5]));
 
-                    corrforeSt.setP(defaultValue);
+            corrforeSt.setDiffuseR(isNumberOrNull(datas[6]));
 
-                    corrforeSt.setWs(defaultValue);
+            corrforeSt.setT(isNumberOrNull(datas[7]));
 
-                    corrforeSt.setWd(defaultValue);
+            corrforeSt.setRh(isNumberOrNull(datas[8]));
 
-                    corrforeSt.setCorrectTime(LocalDateTime.now());
+            corrforeSt.setP(isNumberOrNull(datas[9]));
 
-                }else{
+            corrforeSt.setWs(isNumberOrNull(datas[10]));
 
-                    corrforeSt.setFpValue(isNumber(datas[3]));
+            corrforeSt.setWd(isNumberOrNull(datas[11]));
 
-                    corrforeSt.setGlobalR(isNumber(datas[4]));
+            corrforeSt.setCorrectTime(LocalDateTime.now());
 
-                    corrforeSt.setDirectR(isNumber(datas[5]));
+            Collections.sort(list, Comparator.comparing(CorrforeSt::getForecastTime));
 
-                    corrforeSt.setDiffuseR(isNumber(datas[6]));
-
-                    corrforeSt.setT(isNumber(datas[7]));
-
-                    corrforeSt.setRh(isNumber(datas[8]));
-
-                    corrforeSt.setP(isNumber(datas[9]));
-
-                    corrforeSt.setWs(isNumber(datas[10]));
-
-                    corrforeSt.setWd(isNumber(datas[11]));
-
-                    corrforeSt.setCorrectTime(LocalDateTime.now());
-                }
-
-                Collections.sort(list, Comparator.comparing(CorrforeSt::getForecastTime));
-                list.add(corrforeSt);
-            }
-
-        }catch (Exception e){
-            e.printStackTrace();
-            log.error("解析一体化修正短期内容异常");
+            list.add(corrforeSt);
         }
 
         return list;
@@ -290,85 +308,64 @@ public class CorrforeService extends ServiceImpl<CorrforeStMapper, CorrforeSt> {
     public List<CorrforeSt> correctWindData(String data) throws Exception {
 
         List<CorrforeSt> list = new ArrayList<>();
-        try {
-            String[] content = data.split("\n");
-
-            if (content[1].contains("CorrectForecast")) {
-
-                for (int i = 3; i < content.length - 1; i++) {
 
-                    CorrforeSt corrforeSt = new CorrforeSt();
-                    String column = content[i];
-                    String[] datas = column.split(CommonStant.SPACE1_CONSTANT);
-                    corrforeSt.setForecastTime(DateUtil.parse(datas[2], "yyyyMMddHHmmss").getTime());
-                    corrforeSt.setTimeFormat(DateUtil.parse(datas[2], "yyyyMMddHHmmss").toTimestamp().toLocalDateTime());
+        String[] content = data.split("\n");
 
-                    if(column.contains("NULL") || column.contains("null")){
-                        BigDecimal defaultValue = new BigDecimal("-99");
 
-                        corrforeSt.setFpValue(defaultValue);
+        for (int i = 3; i < content.length - 1; i++) {
 
-                        corrforeSt.setWs(defaultValue);
+            CorrforeSt corrforeSt = new CorrforeSt();
+            String column = content[i];
+            String[] datas = column.split(CommonStant.SPACE1_CONSTANT);
+            corrforeSt.setForecastTime(DateUtil.parse(datas[2], "yyyyMMddHHmmss").getTime());
+            corrforeSt.setTimeFormat(DateUtil.parse(datas[2], "yyyyMMddHHmmss").toTimestamp().toLocalDateTime());
 
-                        corrforeSt.setWd(defaultValue);
+            corrforeSt.setFpValue(isNumberOrNull(datas[3]));
 
-                        corrforeSt.setT(defaultValue);
+            corrforeSt.setWs(isNumberOrNull(datas[4]));
 
-                        corrforeSt.setRh(defaultValue);
+            corrforeSt.setWd(isNumberOrNull(datas[5]));
 
-                        corrforeSt.setP(defaultValue);
+            corrforeSt.setT(isNumberOrNull(datas[6]));
 
-                        corrforeSt.setCorrectTime(LocalDateTime.now());
-                    }else{
+            corrforeSt.setRh(isNumberOrNull(datas[7]));
 
-                        corrforeSt.setFpValue(isNumber(datas[3]));
+            corrforeSt.setP(isNumberOrNull(datas[8]));
 
-                        corrforeSt.setWs(isNumber(datas[4]));
+            corrforeSt.setCorrectTime(LocalDateTime.now());
 
-                        corrforeSt.setWd(isNumber(datas[5]));
+            Collections.sort(list, Comparator.comparing(CorrforeSt::getForecastTime));
 
-                        corrforeSt.setT(isNumber(datas[6]));
-
-                        corrforeSt.setRh(isNumber(datas[7]));
-
-                        corrforeSt.setP(isNumber(datas[8]));
-
-                        corrforeSt.setCorrectTime(LocalDateTime.now());
-                    }
-                    Collections.sort(list, Comparator.comparing(CorrforeSt::getForecastTime));
-                    list.add(corrforeSt);
-                }
-            } else {
-                log.error("解析一体化修正短期异常,标识错误不为<CorrectForecast>");
-
-            }
-        }catch (Exception e){
-            e.printStackTrace();
-            log.error("解析一体化修正短期内容异常");
+            list.add(corrforeSt);
         }
 
+
         return list;
 
     }
 
+
     /**
-     * 判断是否是数值
+     * 判断是否是NULL 和是否是数值
      *
      * @param data
      * @return
      */
-    public BigDecimal isNumber(String data) {
-        BigDecimal bigDecimal = null;
-        Pattern pattern = Pattern.compile("-[0-9]+(.[0-9]+)?|[0-9]+(.[0-9]+)?");
-        Matcher isNum = pattern.matcher(data);
-        try {
-            if (isNum.matches()) {
-                bigDecimal = new BigDecimal(data).setScale(2, BigDecimal.ROUND_DOWN);
+    public BigDecimal isNumberOrNull(String data) {
+        BigDecimal bigDecimal = new BigDecimal("-99");
+        if (!data.contains("null") && !data.contains("NULL")) {
+
+            Pattern pattern = Pattern.compile("-[0-9]+(.[0-9]+)?|[0-9]+(.[0-9]+)?");
+            Matcher isNum = pattern.matcher(data);
+            try {
+                if (isNum.matches()) {
+                    bigDecimal = new BigDecimal(data).setScale(2, BigDecimal.ROUND_DOWN);
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
             }
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
 
+        }
 
         return bigDecimal;
     }
@@ -379,7 +376,7 @@ public class CorrforeService extends ServiceImpl<CorrforeStMapper, CorrforeSt> {
      *
      * @return
      */
-    public File genFile(Station station,List<CorrforeSt> list) {
+    public File genFile(Station station, List<CorrforeSt> list) {
 
         String vmsPath = SystermUtils.getResourceBasePath() + "/vms/DQAMEND.vm";
         File file = null;
@@ -394,24 +391,16 @@ public class CorrforeService extends ServiceImpl<CorrforeStMapper, CorrforeSt> {
             for (CorrforeSt a : list) {
                 Map<String, Object> map = new HashMap<>();
                 map.put("id", a.getId());
-                map.put("forecastTime", DateUtil.format(a.getTimeFormat(), "yyyyMMddHHmmss"));
+                map.put("stationName", station.getName());
+                map.put("forecastTime", DateUtil.format(new Date(a.getForecastTime()), "yyyy-MM-dd HH:mm:ss"));
                 map.put("fpValue", a.getFpValue() == null ? "-99" : a.getFpValue());
-                map.put("swr", a.getGlobalR() == null ? "-99" : a.getGlobalR());
-                map.put("directRadiation", a.getDirectR() == null ? "-99" : a.getDirectR());
-                map.put("diffuseRadiation", a.getDiffuseR() == null ? "-99" : a.getDiffuseR());
-                map.put("windspeed", a.getWs() == null ? "-99" : a.getWs());
-                map.put("windDir", a.getWd() == null ? "-99" : a.getWd());
-                map.put("temperature", a.getT() == null ? "-99" : a.getT());
-                map.put("humidity", a.getRh() == null ? "-99" : a.getRh());
-                map.put("pressure", a.getP() == null ? "-99" : a.getP());
                 vList.add(map);
 
             }
 
             velocityContext = new VelocityContext();
-            velocityContext.put("sign", station.getStationCode());
-
-            velocityContext.put("uploadTime", DateUtil.format(new Date(), "yyyy-MM-dd"));
+            velocityContext.put("stationName", station.getName());
+            velocityContext.put("date", DateUtil.format(new Date(), "yyyy-MM-dd"));
             velocityContext.put("vList", vList);
 
             writer = new StringWriter();

+ 5 - 0
in-client-qn/src/main/resources/vms/DQ.vm

@@ -0,0 +1,5 @@
+<功率预测::${stationName} date='${date}'>
+@@顺序 	 场站名称	 时刻 	 预测功率
+#foreach( $dq in $vList )
+#${velocityCount}   ${dq.stationName}  ${dq.forecastTime} ${dq.fpValue}
+#end

+ 4 - 4
in-cloud/pom.xml

@@ -106,13 +106,13 @@
             <scope>test</scope>
         </dependency>
 
+
         <dependency>
-            <groupId>io.minio</groupId>
-            <artifactId>minio</artifactId>
-            <version>${minio.version}</version>
+            <groupId>com.jiayue</groupId>
+            <artifactId>in-common-minio</artifactId>
+            <version>1.0-SNAPSHOT</version>
         </dependency>
 
-
         <!--<dependency>
 
             <groupId>org.springframework.boot</groupId>

+ 34 - 0
in-cloud/src/main/java/com/jiayue/insu/incloud/config/MinioConfig.java

@@ -0,0 +1,34 @@
+package com.jiayue.insu.incloud.config;
+
+import io.minio.MinioClient;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+@Slf4j
+public class MinioConfig {
+
+    @Value("${minio.endpoint.http}")
+    private String endpoint;
+    @Value("${minio.endpoint.accessKey}")
+    private String accessKey;
+    @Value("${minio.endpoint.secretKey}")
+    private String secretKey;
+
+    /**
+     * 注入minio 客户端
+     * @return
+     */
+    @Bean
+    public MinioClient minioClient() {
+        log.info("minioClient加载成功!");
+        return MinioClient.builder()
+                .endpoint(endpoint)
+                .credentials(accessKey, secretKey)
+                .build();
+
+    }
+}

+ 1 - 1
in-cloud/src/main/java/com/jiayue/insu/incloud/config/SaTokenConfigure.java

@@ -25,7 +25,7 @@ public class SaTokenConfigure implements WebMvcConfigurer {
         // 注册Sa-Token的路由拦截器
         registry.addInterceptor(new SaRouteInterceptor())
                 .addPathPatterns("/**")
-                .excludePathPatterns("/login/doLogin","/index");
+                .excludePathPatterns("/login/doLogin","/file/**");
     }
 
 

+ 23 - 0
in-cloud/src/main/java/com/jiayue/insu/incloud/controller/FileController.java

@@ -0,0 +1,23 @@
+package com.jiayue.insu.incloud.controller;
+
+import com.jiayue.insu.incloud.service.FileService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletResponse;
+
+@RestController
+@RequestMapping("/file")
+public class FileController {
+    @Autowired
+    private FileService fileService;
+
+    @GetMapping("getFile/{code}")
+    public void downloadFile(@PathVariable("code") String stationCode, HttpServletResponse response){
+       fileService.download(stationCode, response);
+    }
+
+}

+ 185 - 214
in-cloud/src/main/java/com/jiayue/insu/incloud/pulldata/PullCorrectDataForQNHL.java

@@ -25,9 +25,10 @@ import com.jiayue.insu.incloud.service.ForecastDataService;
 import com.jiayue.insu.incloud.service.IntegrationCompanyService;
 import com.jiayue.insu.incloud.service.RecordService;
 import com.jiayue.insu.incloud.service.StationService;
+import com.jiayue.insu.incloud.utils.MinioUtils;
 import com.jiayue.insu.incloud.utils.SystermUtils;
+import com.jiayue.insu.minio.util.MinioUtilService;
 import io.minio.MinioClient;
-import io.minio.PutObjectOptions;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
 import org.apache.velocity.Template;
@@ -35,18 +36,17 @@ import org.apache.velocity.VelocityContext;
 import org.apache.velocity.app.VelocityEngine;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
 import org.springframework.stereotype.Component;
 
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.StringWriter;
+import java.io.*;
 import java.math.BigDecimal;
 import java.time.LocalDateTime;
 import java.util.*;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
+
 /**
  * 清能互联 拉取修正数据业务
  *
@@ -56,7 +56,8 @@ import java.util.stream.Collectors;
  */
 @Component
 @Slf4j
-public class PullCorrectDataForQNHL implements IPullInitCorrectData{
+@RefreshScope
+public class PullCorrectDataForQNHL implements IPullInitCorrectData {
 
     @Autowired
     private ForecastDataService forecastDataService;
@@ -70,25 +71,19 @@ public class PullCorrectDataForQNHL implements IPullInitCorrectData{
     @Autowired
     private RecordService recordService;
     @Autowired
-    private  VelocityEngine velocityEngine;
+    private VelocityEngine velocityEngine;
+    @Autowired
+    private MinioUtilService minioUtilService;
 
     @Value("${minio.fileurl}")
     String fileurl;
 
-    @Value("${minio.logurl}")
-    private String logurl;
-
-    @Value("${minio.host}")
-    private String minloHost;
-
-    @Value("${minio.user}")
-    private String minloUser;
-
-    @Value("${minio.pwd}")
-    private String minloPwd;
+    @Value("${minio.bucketname}")
+    private String bucketName;
 
     /**
      * 拉取修正预测数据并生成文件上送minio服务器
+     *
      * @param station 场站信息
      * @return 是否成功
      */
@@ -104,29 +99,28 @@ public class PullCorrectDataForQNHL implements IPullInitCorrectData{
         record.setCreateTime(LocalDateTime.now());
 
         Station st = stationService.findByStationCode(station.getStationCode());
-        String token  = st.getComKey();
-        LocalDateTime tokenTime  = st.getKeyTime();
+        String token = st.getComKey();
+        LocalDateTime tokenTime = st.getKeyTime();
 
         IntegrationCompany integrationCompany = integrationCompanyService.findByCode(CompanyConstant.COMPANY_QNHL);
         String dataPullUrl = integrationCompany.getPullUrl();
 
 
-
-        boolean result =false;
+        boolean result = false;
         boolean isUpload = false;
         String response;
         RequestVo requestVo;
         List<ForecastData> list = new ArrayList<>();
 
-        if (StrUtil.isEmpty(token)  || LocalDateTime.now().isAfter(tokenTime)) {
-            if(qNHLComPermisson.generateKey(station)){
+        if (StrUtil.isEmpty(token) || LocalDateTime.now().isAfter(tokenTime)) {
+            if (qNHLComPermisson.generateKey(station)) {
                 st = stationService.findByStationCode(station.getStationCode());
-                token  = st.getComKey();
-                tokenTime  = st.getKeyTime();
+                token = st.getComKey();
+                tokenTime = st.getKeyTime();
             }
         }
 
-        if (StrUtil.isNotEmpty(token) &&  LocalDateTime.now().isBefore(tokenTime)) {
+        if (StrUtil.isNotEmpty(token) && LocalDateTime.now().isBefore(tokenTime)) {
             try {
 
                 DateTime dateTime = DateUtil.parse(DateUtil.today());
@@ -161,96 +155,100 @@ public class PullCorrectDataForQNHL implements IPullInitCorrectData{
                             log.info(station.getStationCode() + " 请求短期修正数据返回内容:{}", response);
 
                             String dataContent = responseVo.getData();
-                            if (!dataContent.contains("NULL") && !dataContent.contains("null")) {
 
-                                try {
+                            try {
 
-                                    if (CommonStant.ET_PHOTOVOLTAIC.equals(st.getType())) {
-                                        list = correctPhotovoltaicData(responseVo.getData());
+                                if (CommonStant.ET_PHOTOVOLTAIC.equals(st.getType())) {
+                                    list = correctPhotovoltaicData(responseVo.getData());
 
-                                    } else {
-                                        list = correctWindData(responseVo.getData());
-                                    }
+                                } else {
+                                    list = correctWindData(responseVo.getData());
+                                }
 
-                                    /**************检测解析数据完整性*******************/
-                                    BigDecimal one = new BigDecimal("1");
-                                    BigDecimal checkCount = new BigDecimal( st.getDays().toString()).add(one).multiply(new BigDecimal("96")).add(one);
-                                    if (list.size() < checkCount.intValue()) {
-                                        record.setState(StatusEnum.DATA_DEFICIENCY.getCode());
-                                        record.setStateContent(StatusEnum.DATA_DEFICIENCY.getMsg());
-                                        log.warn( "========== {}:{} ==> 请求短期修正数据缺数: {}" ,integrationCompany.getName(),st.getStationCode(),list.size());
-                                    } else {
-                                        result = true;
-                                        for (ForecastData a : aList) {
-                                            List<ForecastData> collect = list.stream().filter(n -> n.getForecastTime().longValue() == a.getForecastTime().longValue()).collect(Collectors.toList());
-                                            if (CollectionUtil.isNotEmpty(collect)) {
-                                                ForecastData correct = collect.get(0);
-                                                a.setCorrectTime(LocalDateTime.now());
-                                                a.setFpValueCorrect(correct.getFpValueCorrect());
-                                                a.setSwrCorrect(correct.getSwrCorrect());
-                                                a.setDirectRadiationCorrect(correct.getDirectRadiationCorrect());
-                                                a.setDiffuseRadiationCorrect(correct.getDiffuseRadiationCorrect());
-                                                a.setWindSpeedCorrect(correct.getWindSpeedCorrect());
-                                                a.setWindDirCorrect(correct.getWindDirCorrect());
-                                                a.setTemperatureCorrect(correct.getTemperatureCorrect());
-                                                a.setHumidityCorrect(correct.getHumidityCorrect());
-                                                a.setPressureCorrect(correct.getPressureCorrect());
-
-                                            } else {
-                                                record.setState(StatusEnum.DATA_DEFICIENCY.getCode());
-                                                record.setStateContent(StatusEnum.DATA_DEFICIENCY.getMsg());
-                                                log.warn( "========== {}:{} ==> 请求短期修正数据缺数: {}" ,integrationCompany.getName(),st.getStationCode(),list.size());
-                                                break;
-                                            }
+                                /**************检测解析数据完整性*******************/
+                                BigDecimal one = new BigDecimal("1");
+                                BigDecimal checkCount = new BigDecimal(st.getDays().toString()).add(one).multiply(new BigDecimal("96")).add(one);
+                                if (list.size() < checkCount.intValue()) {
+                                    record.setState(StatusEnum.DATA_DEFICIENCY.getCode());
+                                    record.setStateContent(StatusEnum.DATA_DEFICIENCY.getMsg());
+                                    log.warn("========== {}:{} ==> 请求短期修正数据缺数: {}", integrationCompany.getName(), st.getStationCode(), list.size());
+                                } else {
+                                    result = true;
+                                    for (ForecastData a : aList) {
+                                        List<ForecastData> collect = list.stream().filter(n -> n.getForecastTime().longValue() == a.getForecastTime().longValue()).collect(Collectors.toList());
+                                        if (CollectionUtil.isNotEmpty(collect)) {
+                                            ForecastData correct = collect.get(0);
+                                            a.setCorrectTime(LocalDateTime.now());
+                                            a.setFpValueCorrect(correct.getFpValueCorrect());
+                                            a.setSwrCorrect(correct.getSwrCorrect());
+                                            a.setDirectRadiationCorrect(correct.getDirectRadiationCorrect());
+                                            a.setDiffuseRadiationCorrect(correct.getDiffuseRadiationCorrect());
+                                            a.setWindSpeedCorrect(correct.getWindSpeedCorrect());
+                                            a.setWindDirCorrect(correct.getWindDirCorrect());
+                                            a.setTemperatureCorrect(correct.getTemperatureCorrect());
+                                            a.setHumidityCorrect(correct.getHumidityCorrect());
+                                            a.setPressureCorrect(correct.getPressureCorrect());
+
+                                        } else {
+                                            record.setState(StatusEnum.DATA_DEFICIENCY.getCode());
+                                            record.setStateContent(StatusEnum.DATA_DEFICIENCY.getMsg());
+                                            log.warn("========== {}:{} ==> 请求短期修正数据缺数: {}", integrationCompany.getName(), st.getStationCode(), list.size());
+                                            break;
                                         }
-
                                     }
-                                    /**************检测解析数据完整性*******************/
 
-                                } catch (Exception e) {
-                                    record.setState(StatusEnum.CONNECT_RESPONSE_FORMAT_ERROR.getSign());
-                                    record.setStateContent("解析失败");
-                                    log.error("=========={}:{} ==> 解析短期修正数据失败 " ,integrationCompany.getName(),st.getStationCode());
                                 }
-                            } else {
+                                /**************检测解析数据完整性*******************/
+
+                            } catch (Exception e) {
                                 record.setState(StatusEnum.CONNECT_RESPONSE_FORMAT_ERROR.getSign());
-                                record.setStateContent(StatusEnum.CONNECT_RESPONSE_FORMAT_ERROR.getMsg());
-                                log.error("=========={}:{} ==>拉取短期修正数据失败  返回响应存在NULL ==========" ,integrationCompany.getName(),st.getStationCode());
+                                record.setStateContent("解析短期修正数据失败");
+                                log.error("=========={}:{} ==> 解析短期修正数据失败 ", integrationCompany.getName(), st.getStationCode());
                             }
 
 
                             if (result) {
-                                log.info("=========={}:{} ==> 拉取短期修正数据成功! ==========" ,integrationCompany.getName(),st.getStationCode());
-                                record.setState(QNHLEnum.REQUEST_SUCCESS.getSign());
-                                record.setStateContent(QNHLEnum.REQUEST_SUCCESS.getMsg());
+                                log.info("=========={}:{} ==> 拉取短期修正数据成功! ==========", integrationCompany.getName(), st.getStationCode());
+                                record.setState(StatusEnum.SUCCESS.getSign());
+                                record.setStateContent(String.valueOf(list.size()));
                                 boolean b = forecastDataService.saveOrUpdateBatch(aList);
-                                if(b){
+                                if (b) {
                                     File file = genFile(station);
-                                    if(file!=null){
-                                        isUpload = uploadFile(station.getStationCode() + "/" + file.getName(), file, station.getStationCode());
+                                    if (file != null) {
+
+                                        boolean flag = minioUtilService.bucketExists(bucketName);
+                                        if (flag) {
+                                            InputStream in = new FileInputStream(file);
+                                            //String fileName = "/" + station.getStationCode() + "/" + "DQ_" + DateUtil.format(DateUtil.beginOfDay(new Date()), "yyyyMMddHHmmss") + "0.RB";
+                                            String fileName = "/" + station.getStationCode() + "/" + file.getName();
+                                            minioUtilService.putObject(bucketName, fileName, in);
+                                        }
+
                                     }
                                 }
 
                             }
 
                         } else {
-
+                            record.setState(StatusEnum.RESPONSE_FAIL.getSign());
+                            record.setStateContent(StatusEnum.RESPONSE_FAIL.getMsg());
+                            log.error("=========={}:{} ==>拉取短期修正数据失败 响应码异常 ", integrationCompany.getName(), st.getStationCode());
                         }
                     } else {
                         record.setState(StatusEnum.CONNECT_RESPONSE_FORMAT_ERROR.getSign());
                         record.setStateContent(StatusEnum.CONNECT_RESPONSE_FORMAT_ERROR.getMsg());
-                        log.error("=========={}:{} ==>拉取短期修正数据失败 接收响应字符串非json格式 " ,integrationCompany.getName(),st.getStationCode());
+                        log.error("=========={}:{} ==>拉取短期修正数据失败 接收响应字符串非json格式 ", integrationCompany.getName(), st.getStationCode());
                     }
                 } else {
                     record.setState(StatusEnum.CONNECT_RESPONSE_CONTENT_NULL.getSign());
                     record.setStateContent(StatusEnum.CONNECT_RESPONSE_CONTENT_NULL.getMsg());
-                    log.error("=========={}:{} ==> 拉取短期修正数据失败  返回响应内容为空 ==========" ,integrationCompany.getName(),st.getStationCode());
+                    log.error("=========={}:{} ==> 拉取短期修正数据失败  返回响应内容为空 ==========", integrationCompany.getName(), st.getStationCode());
                 }
 
             } catch (Exception e) {
                 record.setState(StatusEnum.CONNECT_ERROR.getSign());
                 record.setStateContent(StatusEnum.CONNECT_ERROR.getMsg());
-                log.error("=========={}:{} ==>请求短期修正数据失败 连接断开或请求超时 ==========",integrationCompany.getName(),st.getStationCode());
+                log.error("=========={}:{} ==>请求短期修正数据失败 连接断开或请求超时 ==========", integrationCompany.getName(), st.getStationCode());
                 e.printStackTrace();
 
             }
@@ -260,16 +258,6 @@ public class PullCorrectDataForQNHL implements IPullInitCorrectData{
 
     }
 
-    @Override
-    public Boolean pullDQData(Station station) {
-        return null;
-    }
-
-    @Override
-    public Boolean pullNWPData(Station station) {
-        return null;
-    }
-
 
     /**
      * 生成文件
@@ -278,7 +266,7 @@ public class PullCorrectDataForQNHL implements IPullInitCorrectData{
      */
     public File genFile(Station station) {
 
-        String vmsPath = SystermUtils.getResourceBasePath() + "/vms/DQAMEND.vm";
+        String vmsPath = SystermUtils.getResourceBasePath() + "/vms/DQ.vm";
         File file = null;
         Template template = this.velocityEngine.getTemplate(vmsPath);
         if (template != null) {
@@ -288,40 +276,24 @@ public class PullCorrectDataForQNHL implements IPullInitCorrectData{
             long startTime = DateUtil.beginOfDay(new Date()).getTime();
             long endTime = DateUtil.offsetDay(DateUtil.beginOfDay(DateUtil.tomorrow()), station.getDays()).getTime();
             List<ForecastData> aList = new ArrayList<>();
-            aList = forecastDataService.findTimeByStation( station.getStationCode(), startTime, endTime);
+            aList = forecastDataService.findTimeByStation(station.getStationCode(), startTime, endTime);
             aList.sort(Comparator.comparing(ForecastData::getForecastTime));
             List<Map<String, Object>> vList = new ArrayList<>();
 
             for (ForecastData a : aList) {
                 Map<String, Object> map = new HashMap<>();
                 map.put("id", a.getId());
-                map.put("forecastTime", DateUtil.format(new Date(a.getForecastTime()), "yyyyMMddHHmmss"));
+                map.put("stationName", station.getName());
+                map.put("forecastTime", DateUtil.format(new Date(a.getForecastTime()), "yyyy-MM-dd HH:mm:ss"));
                 map.put("fpValue", a.getFpValue() == null ? "-99" : a.getFpValue());
-                map.put("fpValueAmend", a.getFpValueCorrect() == null ? "-99" : a.getFpValueCorrect());
-                map.put("swr", a.getSwr() == null ? "-99" : a.getSwr());
-                map.put("swrAmend", a.getSwrCorrect() == null ? "-99" : a.getSwrCorrect());
-                map.put("directRadiation", a.getDirectRadiation() == null ? "-99" : a.getDirectRadiation());
-                map.put("directRadiationAmend", a.getDirectRadiationCorrect() == null ? "-99" : a.getDirectRadiationCorrect());
-                map.put("diffuseRadiation", a.getDiffuseRadiation() == null ? "-99" : a.getDiffuseRadiation());
-                map.put("diffuseRadiationAmend", a.getDiffuseRadiationCorrect() == null ? "-99" : a.getDiffuseRadiationCorrect());
-                map.put("windspeed", a.getWindSpeed() == null ? "-99" : a.getWindSpeed());
-                map.put("windspeedAmend", a.getWindSpeedCorrect() == null ? "-99" : a.getWindSpeedCorrect());
-                map.put("windDir", a.getWindDir() == null ? "-99" : a.getWindDir());
-                map.put("windDirAmend", a.getWindDirCorrect() == null ? "-99" : a.getWindDirCorrect());
-                map.put("temperature", a.getTemperature() == null ? "-99" : a.getTemperature());
-                map.put("temperatureAmend", a.getTemperatureCorrect() == null ? "-99" : a.getTemperatureCorrect());
-                map.put("humidity", a.getHumidity() == null ? "-99" : a.getHumidity());
-                map.put("humidityAmend", a.getHumidityCorrect() == null ? "-99" : a.getHumidityCorrect());
-                map.put("pressure", a.getPressure() == null ? "-99" : a.getPressure());
-                map.put("pressureAmend", a.getPressureCorrect() == null ? "-99" : a.getPressureCorrect());
                 vList.add(map);
 
             }
 
             velocityContext = new VelocityContext();
-            velocityContext.put("sign", "signCode");
+            velocityContext.put("stationName", station.getName());
 
-            velocityContext.put("uploadTime", DateUtil.format(new Date(), "yyyy-MM-dd"));
+            velocityContext.put("date", DateUtil.format(new Date(), "yyyy-MM-dd"));
             velocityContext.put("vList", vList);
 
             writer = new StringWriter();
@@ -334,7 +306,7 @@ public class PullCorrectDataForQNHL implements IPullInitCorrectData{
                 fileUrl.mkdirs();
             }
 
-            String fileName = "AMENDFORECAST_" + DateUtil.format(new Date(), "yyyyMMddHHmm") + ".RB";
+            String fileName = "DQ_" + DateUtil.format(DateUtil.beginOfDay(new Date()), "yyyyMMddHHmmss") + "0.RB";
 
             file = new File(fUrl + File.separatorChar + fileName);
 
@@ -349,11 +321,11 @@ public class PullCorrectDataForQNHL implements IPullInitCorrectData{
                     os.write(writer.toString().getBytes("UTF-8"));
                     os.flush();
                 } else {
-                    log.warn(station.getStationCode() + " 生成minlo文件失败");
+                    log.warn(station.getStationCode() + " 生成DQ文件失败");
                 }
             } catch (IOException e) {
                 e.printStackTrace();
-                log.warn(station.getStationCode() + " 创建minlo文件失败");
+                log.warn(station.getStationCode() + " 创建DQ文件失败");
             } finally {
                 if (os != null) {
                     try {
@@ -369,57 +341,6 @@ public class PullCorrectDataForQNHL implements IPullInitCorrectData{
         return file;
     }
 
-    /**
-     * 上传文件
-     *
-     * @return
-     */
-    public boolean uploadFile(String filePath, File file, String stationCode) {
-        boolean status = false;
-        try {
-            MinioClient minioClient = new MinioClient(minloHost, minloUser, minloPwd, false);
-
-            // 检查存储桶是否已经存在
-            boolean isExist = minioClient.bucketExists("forcast");
-            if (!isExist) {
-                // 创建一个名为asiatrip的存储桶,用于存储照片的zip文件。
-                minioClient.makeBucket("forcast");
-            }
-
-            // 使用putObject上传一个文件到存储桶中。
-            minioClient.putObject("forcast", filePath, FileUtil.getInputStream(file), new PutObjectOptions(file.length(), -1));
-
-            Map<String, Object> parmer = new HashMap<>();
-            parmer.put("stationCode", stationCode);
-            parmer.put("fileName", file.getName());
-            String s = JSONUtil.toJsonStr(parmer);
-            String response = "";
-
-            response = HttpUtil.post(logurl, parmer);
-            if (StringUtils.isNotEmpty(response)) {
-                boolean isJson = JSONUtil.isJsonObj(response);
-                if (isJson) {
-                    JSONObject jsonObject = JSONUtil.parseObj(response);
-                    String code = jsonObject.getStr("code");
-                    if (code.equals("0")) {
-                        status = true;
-                    } else {
-                        log.warn(stationCode + " minlo上送日志响应不为0");
-                    }
-                } else {
-                    log.warn(stationCode + " minlo上送日志响应格式不对");
-                }
-
-            }
-
-        } catch (Exception e) {
-            e.printStackTrace();
-            log.error("文件上传存储服务器失败" + filePath, e);
-        }
-
-        return status;
-    }
-
 
     /**
      * 光伏数据解析
@@ -432,41 +353,37 @@ public class PullCorrectDataForQNHL implements IPullInitCorrectData{
 
         String[] content = data.split("\n");
 
-
-        String dateStr = content[0].split("'")[1];
-
         List<ForecastData> list = new ArrayList<>();
 
-
         for (int i = 3; i < content.length - 1; i++) {
 
             ForecastData inForecastPowerShortTerm = new ForecastData();
             String column = content[i];
-
             String[] datas = column.split(CommonStant.SPACE1_CONSTANT);
-
             inForecastPowerShortTerm.setForecastTime(DateUtil.parse(datas[2], "yyyyMMddHHmmss").getTime());
 
-            inForecastPowerShortTerm.setFpValueCorrect(isNumber(datas[3]));
 
-            inForecastPowerShortTerm.setSwrCorrect(isNumber(datas[4]));
+            inForecastPowerShortTerm.setFpValueCorrect(isNumberOrNull(datas[3]));
+
+            inForecastPowerShortTerm.setSwrCorrect(isNumberOrNull(datas[4]));
 
-            inForecastPowerShortTerm.setDirectRadiationCorrect(isNumber(datas[5]));
+            inForecastPowerShortTerm.setDirectRadiationCorrect(isNumberOrNull(datas[5]));
 
-            inForecastPowerShortTerm.setDiffuseRadiationCorrect(isNumber(datas[6]));
+            inForecastPowerShortTerm.setDiffuseRadiationCorrect(isNumberOrNull(datas[6]));
 
-            inForecastPowerShortTerm.setTemperatureCorrect(isNumber(datas[7]));
+            inForecastPowerShortTerm.setTemperatureCorrect(isNumberOrNull(datas[7]));
 
-            inForecastPowerShortTerm.setHumidityCorrect(isNumber(datas[8]));
+            inForecastPowerShortTerm.setHumidityCorrect(isNumberOrNull(datas[8]));
 
-            inForecastPowerShortTerm.setPressureCorrect(isNumber(datas[9]));
+            inForecastPowerShortTerm.setPressureCorrect(isNumberOrNull(datas[9]));
 
-            inForecastPowerShortTerm.setWindSpeedCorrect(isNumber(datas[10]));
+            inForecastPowerShortTerm.setWindSpeedCorrect(isNumberOrNull(datas[10]));
 
-            inForecastPowerShortTerm.setWindDirCorrect(isNumber(datas[11]));
+            inForecastPowerShortTerm.setWindDirCorrect(isNumberOrNull(datas[11]));
 
             inForecastPowerShortTerm.setCorrectTime(LocalDateTime.now());
 
+
             list.add(inForecastPowerShortTerm);
         }
 
@@ -485,71 +402,125 @@ public class PullCorrectDataForQNHL implements IPullInitCorrectData{
 
         String[] content = data.split("\n");
 
+        List<ForecastData> list = new ArrayList<>();
 
-        String dateStr = content[0].split("'")[1];
+        for (int i = 3; i < content.length - 1; i++) {
 
-        List<ForecastData> list = new ArrayList<>();
+            ForecastData inForecastPowerShortTerm = new ForecastData();
+            String column = content[i];
 
+            String[] datas = column.split(CommonStant.SPACE1_CONSTANT);
 
-        if (content[1].contains("CorrectForecast")) {
+            inForecastPowerShortTerm.setForecastTime(DateUtil.parse(datas[2], "yyyyMMddHHmmss").getTime());
 
+            inForecastPowerShortTerm.setFpValueCorrect(isNumberOrNull(datas[3]));
 
-            for (int i = 3; i < content.length - 1; i++) {
+            inForecastPowerShortTerm.setWindSpeedCorrect(isNumberOrNull(datas[4]));
 
-                ForecastData inForecastPowerShortTerm = new ForecastData();
-                String column = content[i];
+            inForecastPowerShortTerm.setWindDirCorrect(isNumberOrNull(datas[5]));
 
-                String[] datas = column.split(CommonStant.SPACE1_CONSTANT);
+            inForecastPowerShortTerm.setTemperatureCorrect(isNumberOrNull(datas[6]));
 
-                inForecastPowerShortTerm.setForecastTime(DateUtil.parse(datas[2], "yyyyMMddHHmmss").getTime());
+            inForecastPowerShortTerm.setHumidityCorrect(isNumberOrNull(datas[7]));
 
-                inForecastPowerShortTerm.setFpValueCorrect(isNumber(datas[3]));
+            inForecastPowerShortTerm.setPressureCorrect(isNumberOrNull(datas[8]));
 
-                inForecastPowerShortTerm.setWindSpeedCorrect(isNumber(datas[4]));
+            inForecastPowerShortTerm.setCorrectTime(LocalDateTime.now());
 
-                inForecastPowerShortTerm.setWindDirCorrect(isNumber(datas[5]));
+            list.add(inForecastPowerShortTerm);
+        }
 
-                inForecastPowerShortTerm.setTemperatureCorrect(isNumber(datas[6]));
 
-                inForecastPowerShortTerm.setHumidityCorrect(isNumber(datas[7]));
+        return list;
 
-                inForecastPowerShortTerm.setPressureCorrect(isNumber(datas[8]));
+    }
 
-                inForecastPowerShortTerm.setCorrectTime(LocalDateTime.now());
+    /**
+     * 判断是否是NULL 和是否是数值
+     *
+     * @param data
+     * @return
+     */
+    public BigDecimal isNumberOrNull(String data) {
+        BigDecimal bigDecimal = new BigDecimal("-99");
+        if (!data.contains("null") && !data.contains("NULL")) {
 
-                list.add(inForecastPowerShortTerm);
+            Pattern pattern = Pattern.compile("-[0-9]+(.[0-9]+)?|[0-9]+(.[0-9]+)?");
+            Matcher isNum = pattern.matcher(data);
+            try {
+                if (isNum.matches()) {
+                    bigDecimal = new BigDecimal(data).setScale(2, BigDecimal.ROUND_DOWN);
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
             }
-        } else {
-            log.error("解析一体化修正短期异常:{}", "标识错误不为<CorrectForecast>");
 
         }
 
+        return bigDecimal;
+    }
 
-        return list;
 
+    @Override
+    public Boolean pullDQData(Station station) {
+        return null;
+    }
+
+    @Override
+    public Boolean pullNWPData(Station station) {
+        return null;
     }
 
     /**
-     * 判断是否是数值
+     * 上传文件
      *
-     * @param data
      * @return
      */
-    public BigDecimal isNumber(String data) {
-        BigDecimal bigDecimal = null;
-        Pattern pattern = Pattern.compile("-[0-9]+(.[0-9]+)?|[0-9]+(.[0-9]+)?");
-        Matcher isNum = pattern.matcher(data);
+   /* public boolean uploadFile(String filePath, File file, String stationCode) {
+        boolean status = false;
         try {
-            if (isNum.matches()) {
-                bigDecimal = new BigDecimal(data).setScale(2, BigDecimal.ROUND_DOWN);
+            MinioClient minioClient = new MinioClient(minloHost, minloUser, minloPwd, false);
+
+            // 检查存储桶是否已经存在
+            boolean isExist = minioClient.bucketExists("forcast");
+            if (!isExist) {
+                // 创建一个名为asiatrip的存储桶,用于存储照片的zip文件。
+                minioClient.makeBucket("forcast");
+            }
+
+            // 使用putObject上传一个文件到存储桶中。
+            minioClient.putObject("forcast", filePath, FileUtil.getInputStream(file), new PutObjectOptions(file.length(), -1));
+
+            Map<String, Object> parmer = new HashMap<>();
+            parmer.put("stationCode", stationCode);
+            parmer.put("fileName", file.getName());
+            String s = JSONUtil.toJsonStr(parmer);
+            String response = "";
+
+            response = HttpUtil.post(logurl, parmer);
+            if (StringUtils.isNotEmpty(response)) {
+                boolean isJson = JSONUtil.isJsonObj(response);
+                if (isJson) {
+                    JSONObject jsonObject = JSONUtil.parseObj(response);
+                    String code = jsonObject.getStr("code");
+                    if (code.equals("0")) {
+                        status = true;
+                    } else {
+                        log.warn(stationCode + " minlo上送日志响应不为0");
+                    }
+                } else {
+                    log.warn(stationCode + " minlo上送日志响应格式不对");
+                }
+
             }
+
         } catch (Exception e) {
             e.printStackTrace();
+            log.error("文件上传存储服务器失败" + filePath, e);
         }
 
-
-        return bigDecimal;
-    }
+        return status;
+    }*/
 
 
 }

+ 45 - 0
in-cloud/src/main/java/com/jiayue/insu/incloud/service/FileService.java

@@ -0,0 +1,45 @@
+package com.jiayue.insu.incloud.service;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.*;
+
+@Service
+public class FileService {
+
+    @Value("${download.fileurl}")
+    private String fileurl;
+
+    public void download(String stationCode, HttpServletResponse response) {
+        try {
+            String filepath = fileurl + File.separatorChar+ stationCode + File.separatorChar+"AMENDFORECAST_202206161001.RB";
+            // path是指欲下载的文件的路径。
+            File file = new File(filepath);
+            // 取得文件名。
+            String filename = file.getName();
+            // 取得文件的后缀名。
+            String ext = filename.substring(filename.lastIndexOf(".") + 1).toUpperCase();
+
+            // 以流的形式下载文件。
+            InputStream fis = new BufferedInputStream(new FileInputStream(filepath));
+            byte[] buffer = new byte[fis.available()];
+            fis.read(buffer);
+            fis.close();
+            // 清空response
+            response.reset();
+            // 设置response的Header
+            response.addHeader("Content-Disposition", "attachment;filename=" + new String(filename.getBytes()));
+            response.addHeader("Content-Length", "" + file.length());
+            OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
+            response.setContentType("application/octet-stream");
+            toClient.write(buffer);
+            toClient.flush();
+            toClient.close();
+        } catch (IOException ex) {
+            ex.printStackTrace();
+        }
+
+    }
+}

+ 396 - 0
in-cloud/src/main/java/com/jiayue/insu/incloud/utils/MinioUtils.java

@@ -0,0 +1,396 @@
+package com.jiayue.insu.incloud.utils;
+
+import cn.hutool.core.util.ObjectUtil;
+import io.minio.*;
+import io.minio.http.Method;
+import io.minio.messages.Bucket;
+import io.minio.messages.DeleteError;
+import io.minio.messages.DeleteObject;
+import io.minio.messages.Item;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.io.InputStream;
+import java.time.LocalDate;
+import java.util.ArrayList;
+import java.util.List;
+
+@Component
+public class MinioUtils {
+    @Autowired
+    MinioClient minioClient;
+
+    private static final int DEFAULT_EXPIRY_TIME = 7 * 24 * 3600;
+
+    public MinioClient  client(){
+        return minioClient;
+    }
+
+    /**
+     * 检查存储桶是否存在
+     *
+     * @param bucketName 存储桶名称
+     * @return
+     */
+    public boolean bucketExists(String bucketName) throws Exception {
+        boolean flag = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
+        if (flag) {
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * 创建存储桶
+     *
+     * @param bucketName 存储桶名称
+     */
+    public boolean makeBucket(String bucketName)
+            throws Exception {
+        boolean flag = bucketExists(bucketName);
+        if (!flag) {
+            minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * 列出所有存储桶名称
+     *
+     * @return
+     */
+    public List<String> listBucketNames() throws Exception {
+        List<Bucket> bucketList = listBuckets();
+        List<String> bucketListName = new ArrayList<>();
+        for (Bucket bucket : bucketList) {
+            bucketListName.add(bucket.name());
+        }
+        return bucketListName;
+    }
+
+    /**
+     * 列出所有存储桶
+     *
+     * @return
+     */
+    public List<Bucket> listBuckets() throws Exception {
+        return minioClient.listBuckets();
+    }
+
+    /**
+     * 删除存储桶
+     *
+     * @param bucketName 存储桶名称
+     * @return
+     */
+    public boolean removeBucket(String bucketName) throws Exception {
+        boolean flag = bucketExists(bucketName);
+        if (flag) {
+            Iterable<Result<Item>> myObjects = listObjects(bucketName);
+            for (Result<Item> result : myObjects) {
+                Item item = result.get();
+                // 有对象文件,则删除失败
+                if (item.size() > 0) {
+                    return false;
+                }
+            }
+            // 删除存储桶,注意,只有存储桶为空时才能删除成功。
+            minioClient.removeBucket(RemoveBucketArgs.builder().bucket(bucketName).build());
+            flag = bucketExists(bucketName);
+            if (!flag) {
+                return true;
+            }
+
+        }
+        return false;
+    }
+
+    /**
+     * 列出存储桶中的所有对象名称
+     *
+     * @param bucketName 存储桶名称
+     * @return
+     */
+    public List<String> listObjectNames(String bucketName) throws Exception {
+        List<String> listObjectNames = new ArrayList<>();
+        boolean flag = bucketExists(bucketName);
+        if (flag) {
+            Iterable<Result<Item>> myObjects = listObjects(bucketName);
+            for (Result<Item> result : myObjects) {
+                Item item = result.get();
+                listObjectNames.add(item.objectName());
+            }
+        }
+        return listObjectNames;
+    }
+
+    /**
+     * 列出存储桶中的所有对象
+     *
+     * @param bucketName 存储桶名称
+     * @return
+     */
+    public Iterable<Result<Item>> listObjects(String bucketName) throws Exception {
+        boolean flag = bucketExists(bucketName);
+        if (flag) {
+            return minioClient.listObjects(ListObjectsArgs.builder().bucket(bucketName).build());
+        }
+        return null;
+    }
+
+
+    /**
+     * 获取年月日[2020, 09, 01]
+     *
+     * @return
+     */
+    protected static String[] getDateFolder() {
+        String[] retVal = new String[3];
+
+        LocalDate localDate = LocalDate.now();
+        retVal[0] = localDate.getYear() + "";
+
+        int month = localDate.getMonthValue();
+        retVal[1] = month < 10 ? "0" + month : month + "";
+
+        int day = localDate.getDayOfMonth();
+        retVal[2] = day < 10 ? "0" + day : day + "";
+
+        return retVal;
+    }
+
+    /**
+     * 上传文件
+     *
+     * @param bucketName bucket名称
+     * @param in         文件流
+     * @throws Exception https://docs.minio.io/cn/java-client-api-reference.html#putObject
+     */
+    public String putObject(String bucketName, String objectName, InputStream in) throws Exception {
+        makeBucket(bucketName);
+        ObjectWriteResponse objectWriteResponse = minioClient.putObject(PutObjectArgs.builder()
+                .bucket(bucketName)
+                .object(objectName)
+                .stream(in, in.available(), -1)
+                .build()
+        );
+        return this.getObjectUrl(bucketName, objectName);
+    }
+
+
+    /**
+     * 以流的形式获取一个文件对象
+     *
+     * @param bucketName 存储桶名称
+     * @param objectName 存储桶里的对象名称
+     * @return
+     */
+    public InputStream getObject(String bucketName, String objectName)
+            throws Exception {
+        boolean flag = bucketExists(bucketName);
+        if (flag) {
+            StatObjectResponse statObject = statObject(bucketName, objectName);
+            if (statObject != null && statObject.size() > 0) {
+                InputStream stream = minioClient.getObject(GetObjectArgs.builder()
+                        .bucket(bucketName)
+                        .object(objectName)
+                        .build());
+                return stream;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * 以流的形式获取一个文件对象(断点下载)
+     *
+     * @param bucketName 存储桶名称
+     * @param objectName 存储桶里的对象名称
+     * @param offset     起始字节的位置
+     * @param length     要读取的长度 (可选,如果无值则代表读到文件结尾)
+     * @return
+     */
+    public InputStream getObject(String bucketName, String objectName, long offset, Long length)
+            throws Exception {
+        boolean flag = bucketExists(bucketName);
+        if (flag) {
+            StatObjectResponse statObject = statObject(bucketName, objectName);
+            if (statObject != null && statObject.size() > 0) {
+                InputStream stream = minioClient.getObject(GetObjectArgs.builder()
+                        .bucket(bucketName)
+                        .object(objectName)
+                        .offset(offset)
+                        .length(length)
+                        .build());
+                return stream;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * 下载并将文件保存到本地
+     *
+     * @param bucketName 存储桶名称
+     * @param objectName 存储桶里的对象名称
+     *                   //     * @param fileName   File name
+     * @return
+     */
+    public boolean getObjectFile(String bucketName, String objectName)
+            throws Exception {
+        boolean flag = bucketExists(bucketName);
+        if (flag) {
+            StatObjectResponse statObject = statObject(bucketName, objectName);
+            if (statObject != null && statObject.size() > 0) {
+                GetObjectResponse getObjectResponse = minioClient.getObject(GetObjectArgs.builder()
+                        .bucket(bucketName)
+                        .object(objectName)
+                        .build());
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * 删除一个对象
+     *
+     * @param bucketName 存储桶名称
+     * @param objectName 存储桶里的对象名称
+     */
+    public boolean removeObject(String bucketName, String objectName)
+            throws Exception {
+        boolean flag = bucketExists(bucketName);
+        if (flag) {
+            minioClient.removeObject(RemoveObjectArgs.builder().bucket(bucketName).object(objectName).build());
+            return true;
+        }
+        return false;
+
+    }
+
+    /**
+     * 删除指定桶的多个文件对象,返回删除错误的对象列表,全部删除成功,返回空列表
+     *
+     * @param bucketName  存储桶名称
+     * @param objectNames 含有要删除的多个object名称的迭代器对象
+     * @return
+     */
+    public List<String> removeObject(String bucketName, List<String> objectNames)
+            throws Exception {
+        List<String> deleteErrorNames = new ArrayList<>();
+        boolean flag = bucketExists(bucketName);
+        if (flag) {
+            List<DeleteObject> deleteObjectList = new ArrayList<>();
+            if (ObjectUtil.isNotEmpty(objectNames)) {
+                for (String objectName : objectNames) {
+                    deleteObjectList.add(new DeleteObject(objectName));
+                }
+            }
+            Iterable<Result<DeleteError>> results = minioClient.removeObjects(
+                    RemoveObjectsArgs.builder()
+                            .bucket(bucketName)
+                            .objects(deleteObjectList)
+                            .build()
+            );
+            for (Result<DeleteError> result : results) {
+                DeleteError error = result.get();
+                deleteErrorNames.add(error.objectName());
+            }
+        }
+        return deleteErrorNames;
+    }
+
+
+    /**
+     * 生成一个给HTTP GET请求用的presigned URL。
+     * 浏览器/移动端的客户端可以用这个URL进行下载,即使其所在的存储桶是私有的。这个presigned URL可以设置一个失效时间,默认值是7天。
+     *
+     * @param bucketName 存储桶名称
+     * @param objectName 存储桶里的对象名称
+     * @param expires    失效时间(以秒为单位),默认是7天,不得大于七天
+     * @return
+     */
+    public String presignedGetObject(String bucketName, String objectName, Integer expires)
+            throws Exception {
+        boolean flag = bucketExists(bucketName);
+        String url = "";
+        if (flag) {
+            if (expires < 1 || expires > DEFAULT_EXPIRY_TIME) {
+                throw new RuntimeException(expires +
+                        ":expires must be in range of 1 to " + DEFAULT_EXPIRY_TIME);
+            }
+            url = minioClient.getPresignedObjectUrl(
+                    GetPresignedObjectUrlArgs.builder()
+                            .bucket(bucketName)
+                            .object(objectName)
+                            .expiry(expires)
+                            .build());
+        }
+        return url;
+    }
+
+//    /**
+//     * 生成一个给HTTP PUT请求用的presigned URL。
+//     * 浏览器/移动端的客户端可以用这个URL进行上传,即使其所在的存储桶是私有的。这个presigned URL可以设置一个失效时间,默认值是7天。
+//     *
+//     * @param bucketName 存储桶名称
+//     * @param objectName 存储桶里的对象名称
+//     * @param expires    失效时间(以秒为单位),默认是7天,不得大于七天
+//     * @return
+//     */
+//    public String presignedPutObject(String bucketName, String objectName, Integer expires)
+//            throws Exception {
+//        boolean flag = bucketExists(bucketName);
+//        String url = "";
+//        if (flag) {
+//            if (expires < 1 || expires > DEFAULT_EXPIRY_TIME) {
+//                throw new RuntimeException(expires+
+//                        ":expires must be in range of 1 to " + DEFAULT_EXPIRY_TIME);
+//            }
+//            url = minioClient.presignedPutObject(bucketName, objectName, expires);
+//        }
+//        return url;
+//    }
+
+    /**
+     * 获取对象的元数据
+     *
+     * @param bucketName 存储桶名称
+     * @param objectName 存储桶里的对象名称
+     * @return
+     */
+    public StatObjectResponse statObject(String bucketName, String objectName)
+            throws Exception {
+        boolean flag = bucketExists(bucketName);
+        if (flag) {
+            StatObjectResponse statObject = minioClient.statObject(StatObjectArgs.builder().bucket(bucketName).object(objectName).build());
+            return statObject;
+        }
+        return null;
+    }
+
+    /**
+     * 文件访问路径
+     *
+     * @param bucketName 存储桶名称
+     * @param objectName 存储桶里的对象名称
+     * @return
+     */
+    public String getObjectUrl(String bucketName, String objectName) throws Exception {
+        boolean flag = bucketExists(bucketName);
+        String url = "";
+        if (flag) {
+            url = minioClient.getPresignedObjectUrl(
+                    GetPresignedObjectUrlArgs.builder()
+                            .method(Method.GET)
+                            .bucket(bucketName)
+                            .object(objectName)
+                            .build()
+            );
+        }
+        return url;
+    }
+}

+ 5 - 0
in-cloud/src/main/resources/vms/DQ.vm

@@ -0,0 +1,5 @@
+<功率预测::${stationName} date='${date}'>
+@@顺序 	 场站名称	 时刻 	 预测功率
+#foreach( $dq in $vList )
+#${velocityCount}   ${dq.stationName}  ${dq.forecastTime} ${dq.fpValue}
+#end

+ 28 - 0
in-common/in-common-minio/pom.xml

@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>in-common</artifactId>
+        <groupId>com.jiayue</groupId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>in-common-minio</artifactId>
+    <packaging>jar</packaging>
+    <properties>
+        <maven.compiler.source>8</maven.compiler.source>
+        <maven.compiler.target>8</maven.compiler.target>
+    </properties>
+
+
+    <dependencies>
+        <dependency>
+            <groupId>io.minio</groupId>
+            <artifactId>minio</artifactId>
+            <version>8.2.1</version>
+        </dependency>
+    </dependencies>
+
+</project>

+ 32 - 0
in-common/in-common-minio/src/main/java/com/jiayue/insu/minio/config/MinioConfig.java

@@ -0,0 +1,32 @@
+package com.jiayue.insu.minio.config;
+
+import io.minio.MinioClient;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+@Slf4j
+public class MinioConfig {
+
+    @Value("${minio.endpoint.http}")
+    private String endpoint;
+    @Value("${minio.endpoint.accessKey}")
+    private String accessKey;
+    @Value("${minio.endpoint.secretKey}")
+    private String secretKey;
+
+    /**
+     * 注入minio 客户端
+     * @return
+     */
+    @Bean
+    public MinioClient minioClient(){
+        log.info("minioClient加载成功!");
+        return MinioClient.builder()
+                .endpoint(endpoint)
+                .credentials(accessKey, secretKey)
+                .build();
+    }
+}

+ 443 - 0
in-common/in-common-minio/src/main/java/com/jiayue/insu/minio/util/MinioUtilService.java

@@ -0,0 +1,443 @@
+package com.jiayue.insu.minio.util;
+
+import cn.hutool.core.util.ObjectUtil;
+import io.minio.*;
+import io.minio.errors.*;
+import io.minio.http.Method;
+import io.minio.messages.Bucket;
+import io.minio.messages.DeleteError;
+import io.minio.messages.DeleteObject;
+import io.minio.messages.Item;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.stereotype.Service;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.time.LocalDate;
+import java.util.ArrayList;
+import java.util.List;
+
+@Service
+@ConditionalOnBean(name = "minioClient")
+public class MinioUtilService {
+    /**
+     * url分隔符
+     */
+    public static final String URI_DELIMITER = "/";
+
+    @Autowired
+    private MinioClient minioClient;
+
+    private static final int DEFAULT_EXPIRY_TIME = 7 * 24 * 3600;
+
+    /**
+     * 检查存储桶是否存在
+     *
+     * @param bucketName 存储桶名称
+     * @return
+     */
+    public boolean bucketExists(String bucketName) throws Exception {
+        boolean flag = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
+        if (flag) {
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * 创建存储桶
+     *
+     * @param bucketName 存储桶名称
+     */
+    public boolean makeBucket(String bucketName)
+            throws Exception {
+        boolean flag = bucketExists(bucketName);
+        if (!flag) {
+            minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * 列出所有存储桶名称
+     *
+     * @return
+     */
+    public List<String> listBucketNames() throws Exception {
+        List<Bucket> bucketList = listBuckets();
+        List<String> bucketListName = new ArrayList<>();
+        for (Bucket bucket : bucketList) {
+            bucketListName.add(bucket.name());
+        }
+        return bucketListName;
+    }
+
+    /**
+     * 列出所有存储桶
+     *
+     * @return
+     */
+    public List<Bucket> listBuckets() throws Exception {
+        return minioClient.listBuckets();
+    }
+
+    /**
+     * 删除存储桶
+     *
+     * @param bucketName 存储桶名称
+     * @return
+     */
+    public boolean removeBucket(String bucketName) throws Exception {
+        boolean flag = bucketExists(bucketName);
+        if (flag) {
+            Iterable<Result<Item>> myObjects = listObjects(bucketName);
+            for (Result<Item> result : myObjects) {
+                Item item = result.get();
+                // 有对象文件,则删除失败
+                if (item.size() > 0) {
+                    return false;
+                }
+            }
+            // 删除存储桶,注意,只有存储桶为空时才能删除成功。
+            minioClient.removeBucket(RemoveBucketArgs.builder().bucket(bucketName).build());
+            flag = bucketExists(bucketName);
+            if (!flag) {
+                return true;
+            }
+
+        }
+        return false;
+    }
+
+    /**
+     * 列出存储桶中的所有对象名称
+     *
+     * @param bucketName 存储桶名称
+     * @return
+     */
+    public List<String> listObjectNames(String bucketName) throws Exception {
+        List<String> listObjectNames = new ArrayList<>();
+        boolean flag = bucketExists(bucketName);
+        if (flag) {
+            Iterable<Result<Item>> myObjects = listObjects(bucketName);
+            for (Result<Item> result : myObjects) {
+                Item item = result.get();
+                listObjectNames.add(item.objectName());
+            }
+        }
+        return listObjectNames;
+    }
+
+
+
+    /**
+     * 列出存储桶文件夹下对象名称列表,
+     *
+     * @param bucketName 存储桶名称
+     * @param fileDir 文件夹名称
+     * @param recursive 文件夹名称
+     * @return
+     */
+    public List<String> listObjects(String bucketName,String fileDir,boolean recursive) throws Exception {
+        List<String> listObjectNames = new ArrayList<>();
+        boolean flag = bucketExists(bucketName);
+        if (flag) {
+            Iterable<Result<Item>> results = minioClient.listObjects(ListObjectsArgs.builder().bucket(bucketName).recursive(recursive).prefix(fileDir).build());
+            for (Result<Item> result : results) {
+                Item item = result.get();
+                listObjectNames.add(item.objectName());
+            }
+        }
+        return listObjectNames;
+    }
+
+    /**
+     * 列出存储桶中的所有对象
+     *
+     * @param bucketName 存储桶名称
+     * @return
+     */
+    public Iterable<Result<Item>> listObjects(String bucketName) throws Exception {
+        boolean flag = bucketExists(bucketName);
+        if (flag) {
+            return minioClient.listObjects(ListObjectsArgs.builder().bucket(bucketName).build());
+        }
+        return null;
+    }
+
+    /**
+     *
+     * @param bucketName 桶名
+     * @param downfileName 桶中文件
+     * @param path 下载到本地的路径+文件名
+     * @throws Exception 异常
+     */
+    public void downloadObject(String bucketName,String downfileName,String path) throws Exception {
+        minioClient.downloadObject(
+                DownloadObjectArgs.builder()
+                        .bucket(bucketName)
+                        .object(downfileName)
+                        .filename(path)
+                        .build());
+    }
+
+    /**
+     * 获取年月日[2020, 09, 01]
+     *
+     * @return
+     */
+    protected static String[] getDateFolder() {
+        String[] retVal = new String[3];
+
+        LocalDate localDate = LocalDate.now();
+        retVal[0] = localDate.getYear() + "";
+
+        int month = localDate.getMonthValue();
+        retVal[1] = month < 10 ? "0" + month : month + "";
+
+        int day = localDate.getDayOfMonth();
+        retVal[2] = day < 10 ? "0" + day : day + "";
+
+        return retVal;
+    }
+
+        /**
+         * 上传文件
+         *
+         * @param bucketName bucket名称
+         * @param in         文件流
+         * @throws Exception https://docs.minio.io/cn/java-client-api-reference.html#putObject
+         */
+        public String putObject(String bucketName, String objectName, InputStream in) throws Exception {
+            makeBucket(bucketName);
+            ObjectWriteResponse objectWriteResponse = minioClient.putObject(PutObjectArgs.builder()
+                    .bucket(bucketName)
+                    .object(objectName)
+                    .stream(in, in.available(), -1)
+                    .build()
+            );
+            return this.getObjectUrl(bucketName, objectName);
+        }
+
+
+    /**
+     * 以流的形式获取一个文件对象
+     *
+     * @param bucketName 存储桶名称
+     * @param objectName 存储桶里的对象名称
+     * @return
+     */
+    public InputStream getObject(String bucketName, String objectName)
+            throws Exception {
+        boolean flag = bucketExists(bucketName);
+        if (flag) {
+            StatObjectResponse statObject = statObject(bucketName, objectName);
+            if (statObject != null && statObject.size() > 0) {
+                InputStream stream = minioClient.getObject(GetObjectArgs.builder()
+                        .bucket(bucketName)
+                        .object(objectName)
+                        .build());
+                return stream;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * 以流的形式获取一个文件对象(断点下载)
+     *
+     * @param bucketName 存储桶名称
+     * @param objectName 存储桶里的对象名称
+     * @param offset     起始字节的位置
+     * @param length     要读取的长度 (可选,如果无值则代表读到文件结尾)
+     * @return
+     */
+    public InputStream getObject(String bucketName, String objectName, long offset, Long length)
+            throws Exception {
+        boolean flag = bucketExists(bucketName);
+        if (flag) {
+            StatObjectResponse statObject = statObject(bucketName, objectName);
+            if (statObject != null && statObject.size() > 0) {
+                InputStream stream = minioClient.getObject(GetObjectArgs.builder()
+                        .bucket(bucketName)
+                        .object(objectName)
+                        .offset(offset)
+                        .length(length)
+                        .build());
+                return stream;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * 下载并将文件保存到本地
+     *
+     * @param bucketName 存储桶名称
+     * @param objectName 存储桶里的对象名称
+     *                   //     * @param fileName   File name
+     * @return
+     */
+    public boolean getObjectFile(String bucketName, String objectName)
+            throws Exception {
+        boolean flag = bucketExists(bucketName);
+        if (flag) {
+            StatObjectResponse statObject = statObject(bucketName, objectName);
+            if (statObject != null && statObject.size() > 0) {
+                GetObjectResponse getObjectResponse = minioClient.getObject(GetObjectArgs.builder()
+                        .bucket(bucketName)
+                        .object(objectName)
+                        .build());
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * 删除一个对象
+     *
+     * @param bucketName 存储桶名称
+     * @param objectName 存储桶里的对象名称
+     */
+    public boolean removeObject(String bucketName, String objectName)
+            throws Exception {
+        boolean flag = bucketExists(bucketName);
+        if (flag) {
+            minioClient.removeObject(RemoveObjectArgs.builder().bucket(bucketName).object(objectName).build());
+            return true;
+        }
+        return false;
+
+    }
+
+    /**
+     * 删除指定桶的多个文件对象,返回删除错误的对象列表,全部删除成功,返回空列表
+     *
+     * @param bucketName  存储桶名称
+     * @param objectNames 含有要删除的多个object名称的迭代器对象
+     * @return
+     */
+    public List<String> removeObject(String bucketName, List<String> objectNames)
+            throws Exception {
+        List<String> deleteErrorNames = new ArrayList<>();
+        boolean flag = bucketExists(bucketName);
+        if (flag) {
+            List<DeleteObject> deleteObjectList = new ArrayList<>();
+            if (ObjectUtil.isNotEmpty(objectNames)) {
+                for (String objectName : objectNames) {
+                    deleteObjectList.add(new DeleteObject(objectName));
+                }
+            }
+            Iterable<Result<DeleteError>> results = minioClient.removeObjects(
+                    RemoveObjectsArgs.builder()
+                            .bucket(bucketName)
+                            .objects(deleteObjectList)
+                            .build()
+            );
+            for (Result<DeleteError> result : results) {
+                DeleteError error = result.get();
+                deleteErrorNames.add(error.objectName());
+            }
+        }
+        return deleteErrorNames;
+    }
+
+
+    /**
+     * 生成一个给HTTP GET请求用的presigned URL。
+     * 浏览器/移动端的客户端可以用这个URL进行下载,即使其所在的存储桶是私有的。这个presigned URL可以设置一个失效时间,默认值是7天。
+     *
+     * @param bucketName 存储桶名称
+     * @param objectName 存储桶里的对象名称
+     * @param expires    失效时间(以秒为单位),默认是7天,不得大于七天
+     * @return
+     */
+    public String presignedGetObject(String bucketName, String objectName, Integer expires)
+            throws Exception {
+        boolean flag = bucketExists(bucketName);
+        String url = "";
+        if (flag) {
+            if (expires < 1 || expires > DEFAULT_EXPIRY_TIME) {
+                throw new RuntimeException(expires +
+                        ":expires must be in range of 1 to " + DEFAULT_EXPIRY_TIME);
+            }
+            url = minioClient.getPresignedObjectUrl(
+                    GetPresignedObjectUrlArgs.builder()
+                            .bucket(bucketName)
+                            .object(objectName)
+                            .expiry(expires)
+                            .build());
+        }
+        return url;
+    }
+
+//    /**
+//     * 生成一个给HTTP PUT请求用的presigned URL。
+//     * 浏览器/移动端的客户端可以用这个URL进行上传,即使其所在的存储桶是私有的。这个presigned URL可以设置一个失效时间,默认值是7天。
+//     *
+//     * @param bucketName 存储桶名称
+//     * @param objectName 存储桶里的对象名称
+//     * @param expires    失效时间(以秒为单位),默认是7天,不得大于七天
+//     * @return
+//     */
+//    public String presignedPutObject(String bucketName, String objectName, Integer expires)
+//            throws Exception {
+//        boolean flag = bucketExists(bucketName);
+//        String url = "";
+//        if (flag) {
+//            if (expires < 1 || expires > DEFAULT_EXPIRY_TIME) {
+//                throw new RuntimeException(expires+
+//                        ":expires must be in range of 1 to " + DEFAULT_EXPIRY_TIME);
+//            }
+//            url = minioClient.presignedPutObject(bucketName, objectName, expires);
+//        }
+//        return url;
+//    }
+
+    /**
+     * 获取对象的元数据
+     *
+     * @param bucketName 存储桶名称
+     * @param objectName 存储桶里的对象名称
+     * @return
+     */
+    public StatObjectResponse statObject(String bucketName, String objectName)
+            throws Exception {
+        boolean flag = bucketExists(bucketName);
+        if (flag) {
+            StatObjectResponse statObject = minioClient.statObject(StatObjectArgs.builder().bucket(bucketName).object(objectName).build());
+            return statObject;
+        }
+        return null;
+    }
+
+    /**
+     * 文件访问路径
+     *
+     * @param bucketName 存储桶名称
+     * @param objectName 存储桶里的对象名称
+     * @return
+     */
+    public String getObjectUrl(String bucketName, String objectName) throws Exception {
+        boolean flag = bucketExists(bucketName);
+        String url = "";
+        if (flag) {
+            url = minioClient.getPresignedObjectUrl(
+                    GetPresignedObjectUrlArgs.builder()
+                            .method(Method.GET)
+                            .bucket(bucketName)
+                            .object(objectName)
+                            .build()
+            );
+        }
+        return url;
+    }
+
+}

+ 5 - 0
in-common/in-common-minio/src/main/resources/META-INF/spring.factories

@@ -0,0 +1,5 @@
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
+  com.jiayue.insu.minio.config.MinioConfig,\
+  com.jiayue.insu.minio.util.MinioUtilService
+  
+

+ 1 - 0
in-common/pom.xml

@@ -13,6 +13,7 @@
     <packaging>pom</packaging>
     <modules>
         <module>in-common-core</module>
+        <module>in-common-minio</module>
     </modules>
     <properties>
         <maven.compiler.source>8</maven.compiler.source>