Kaynağa Gözat

发电能力分析光伏文件删除与导出

xushili 1 yıl önce
ebeveyn
işleme
34bf85f274

+ 1 - 0
.gitignore

@@ -38,4 +38,5 @@ build/
 /gyee-sample-impala/logs
 /gyee-sample-impala/logs
 /*.log
+**/logs
 /data

+ 13 - 13
gradeevaluation/src/main/resources/application.yml

@@ -6,18 +6,18 @@ server:
 
 spring:
   main:
-    allow-bean-definition-overriding: true #当遇到同样名字的时候,是否允许覆盖注册
-  #redis集群
+    allow-bean-definition-overriding: true #褰撻亣鍒板悓鏍峰悕瀛楃殑鏃跺€欙紝鏄�惁鍏佽�瑕嗙洊娉ㄥ唽
+  #redis闆嗙兢
   redis:
     host: 10.155.32.4
     #    host: 127.0.0.1
     port: 6379
     timeout: 100000
-    #    集群环境打开下面注释,单机不需要打开
+    #    闆嗙兢鐜��鎵撳紑涓嬮潰娉ㄩ噴锛屽崟鏈轰笉闇€瑕佹墦寮€
     #    cluster:
-    #      集群信息
+    #      闆嗙兢淇℃伅
     #      nodes: xxx.xxx.xxx.xxx:xxxx,xxx.xxx.xxx.xxx:xxxx,xxx.xxx.xxx.xxx:xxxx
-    #      #默认值是5 一般当此值设置过大时,容易报:Too many Cluster redirections
+    #      #榛樿�鍊兼槸5 涓€鑸�綋姝ゅ€艰�缃�繃澶ф椂锛屽�鏄撴姤锛歍oo many Cluster redirections
     #      maxRedirects: 3
     password: gdnxfd123
     application:
@@ -34,7 +34,7 @@ spring:
   datasource:
     type: com.alibaba.druid.pool.DruidDataSource
     driver-class-name: oracle.jdbc.OracleDriver
-    #外网
+    #澶栫綉
     url: jdbc:oracle:thin:@192.168.1.105:1521:gdnxfd
     #    url: jdbc:oracle:thin:@172.168.1.14:1521:gdnxfd
     username: nxfdprod
@@ -57,13 +57,13 @@ spring:
       test-on-return: false
   servlet:
     multipart:
-      # 开启 multipart 上传功能
+      # 开启 multipart 上传功能
       enabled: true
-      # 文件写入磁盘的阈值
+      # 文件写入磁盘的阈值
       file-size-threshold: 2KB
-      # 最大文件大小
+      # 最大文件大小
       max-file-size: 200MB
-      # 最大请求大小
+      # 最大请求大小
       max-request-size: 215MB
 
 mybatis-plus:
@@ -73,12 +73,12 @@ mybatis-plus:
     log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
   mapper-locations: classpath*:mapper/**/*Mapper.xml
   global-config:
-    # 逻辑删除配置
+    # 閫昏緫鍒犻櫎閰嶇疆
     db-config:
       id-type: auto
-      # 删除前
+      # 删除前
       logic-not-delete-value: 1
-      # 删除后
+      # 删除后
       logic-delete-value: 0
 logging:
   level:

+ 4 - 0
power-fitting/src/main/java/com/gyee/power/fitting/common/util/FileUtil.java

@@ -204,6 +204,10 @@ public class FileUtil {
         // 判断压缩后的文件存在不,不存在则创建
         if (!zipFile.exists()) {
             try {
+                String fileName = zipFile.getAbsolutePath();
+                fileName = fileName.substring(0, fileName.lastIndexOf("\\"));
+                File file1 = new File(fileName);
+                file1.mkdirs();
                 zipFile.createNewFile();
             } catch (IOException e) {
                 e.printStackTrace();

+ 24 - 5
power-fitting/src/main/java/com/gyee/power/fitting/controller/fj/PhotovoltaicController.java

@@ -1,4 +1,4 @@
-package com.gyee.power.fitting.controller.analyse;
+package com.gyee.power.fitting.controller.fj;
 
 import com.alibaba.fastjson.JSONObject;
 import com.gyee.power.fitting.common.result.JsonResult;
@@ -12,6 +12,7 @@ import com.gyee.power.fitting.service.impl.IvPvCurveFittingService;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletResponse;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -116,10 +117,9 @@ public class PhotovoltaicController {
     //功率-光照-温度曲线
     @PostMapping("/analysis/powerbeam")
     private JSONObject powerBeamTemperature(@RequestBody JSONObject filename) {
-        String fn = filename.getString("filename");
-        String[] split = fn.split(",");
-        if (split.length > 450) return JsonResult.error(ResultCode.PARAM_NOT_VALID);
-        List<PhotovoltaicInfo> infos = curveFittingService.calculatFitting(Arrays.asList(split));
+        List<String> strings = jsonObj2List(filename);
+        if (strings.size() > 450) return JsonResult.error(ResultCode.PARAM_NOT_VALID);
+        List<PhotovoltaicInfo> infos = curveFittingService.calculatFitting(strings);
         List<double[]> b = curveFittingService.oneFileFitting(infos);
         infos = infos.stream().filter(i -> i.getS() > 1).sorted(Comparator.comparing(PhotovoltaicInfo::getS)).collect(Collectors.toList());
 
@@ -142,4 +142,23 @@ public class PhotovoltaicController {
         return JsonResult.successData(ResultCode.SUCCESS, map);
     }
 
+    //文件删除
+    @DeleteMapping("/delete/files")
+    private JSONObject deleteFiles(@RequestBody JSONObject filename) {
+        List<String> strings = jsonObj2List(filename);
+        int i = curveFittingService.deleteFiles(strings);
+        return JsonResult.successData(ResultCode.SUCCESS, "共删除" + i + "个文件,删除失败" + (strings.size() - i) + "个!");
+    }
+
+    private List<String> jsonObj2List(JSONObject filename) {
+        String fn = filename.getString("filename");
+        String[] split = fn.split(",");
+        return Arrays.asList(split);
+    }
+
+    @GetMapping("/export/files")
+    private void exportFiles(HttpServletResponse response, @RequestParam("filename") String filename) {
+        String[] split = filename.split(",");
+        curveFittingService.downFiles(Arrays.asList(split), response);
+    }
 }

+ 27 - 0
power-fitting/src/main/java/com/gyee/power/fitting/service/impl/IvPvCurveFittingService.java

@@ -25,6 +25,7 @@ import org.apache.commons.math3.fitting.WeightedObservedPoints;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletResponse;
 import java.io.File;
 import java.math.BigDecimal;
 import java.util.*;
@@ -531,4 +532,30 @@ public class IvPvCurveFittingService {
         }
         return new HashMap<>();
     }
+
+    public int deleteFiles(List<String> fileList) {
+        String fs = config.getFilePathPrepare() + "gf\\";
+        List<PhotovoltaicInfo> infoList = new ArrayList<>();
+        int count = 0;
+        for (String s : fileList) {
+            File file = new File(fs + s);
+            if (file.delete()) count++;
+        }
+        return count;
+    }
+
+    public void downFiles(List<String> strings, HttpServletResponse response) {
+        List<File> files = path2File(strings);
+        String path = config.getFilePathPrepare() + "zip\\" + System.currentTimeMillis() + ".zip";
+        String s = FileUtil.zipFiles(files, new File(path));
+        FileUtil.download(s, response);
+    }
+
+    private List<File> path2File(List<String> strings) {
+        List<File> files = new ArrayList<>();
+        for (String string : strings) {
+            files.add(new File(config.getFilePathPrepare() + "gf\\" + string));
+        }
+        return files;
+    }
 }