Browse Source

Merge branch 'master' of http://124.70.43.205:3000/xieshengjie/sis-background

# Conflicts:
#	power-fitting/src/main/java/com/gyee/power/fitting/controller/gf/PhotovoltaicController.java
chenminghua 1 year ago
parent
commit
1a3e5cb821

+ 1 - 0
.gitignore

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

+ 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 - 4
power-fitting/src/main/java/com/gyee/power/fitting/controller/gf/PhotovoltaicController.java

@@ -1,3 +1,4 @@
+package com.gyee.power.fitting.controller.fj;
 package com.gyee.power.fitting.controller.gf;
 
 import com.alibaba.fastjson.JSONObject;
@@ -12,6 +13,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 +118,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 +143,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;
+    }
 }