From a6415c0c5116172db31fd353032fdfd11ac91544 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期五, 01 十一月 2024 20:53:04 +0800
Subject: [PATCH] 1

---
 src/main/java/com/se/simu/service/ResultService.java      |    3 +
 src/main/java/com/se/simu/controller/WaterController.java |   57 ++++++++++++++++++----------
 src/main/java/com/se/simu/service/WaterService.java       |   29 +-------------
 3 files changed, 43 insertions(+), 46 deletions(-)

diff --git a/src/main/java/com/se/simu/controller/WaterController.java b/src/main/java/com/se/simu/controller/WaterController.java
index d0f2df3..fdeba3f 100644
--- a/src/main/java/com/se/simu/controller/WaterController.java
+++ b/src/main/java/com/se/simu/controller/WaterController.java
@@ -42,15 +42,49 @@
 
     private final static long Y2000 = 949334400000L;
 
-    @ApiOperation(value = "鑾峰彇鍏冩暟鎹俊鎭�")
+    @ApiOperation(value = "鑾峰彇鍏冩暟鎹甁SON")
     @GetMapping("/{serviceName}/layer.json")
-    public void getLayer(@PathVariable String serviceName, HttpServletResponse res) {
+    public void getLayerJson(@PathVariable String serviceName, HttpServletResponse res) {
         try {
             if (!validate(serviceName, res)) {
                 return;
             }
 
-            byte[] bytes = waterService.getLayerJson(serviceName);
+            byte[] bytes = waterService.getson(serviceName, "layer.json");
+
+            WebHelper.writeBytes(bytes, res);
+        } catch (Exception ex) {
+            log.error(ex.getMessage(), ex);
+            WebHelper.writeStr2Page(res, HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
+        }
+    }
+
+    @ApiOperation(value = "鑾峰彇闄嶆按鏇茬嚎JSON")
+    @GetMapping("/{serviceName}/rainfall.json")
+    public void getRainfallJson(@PathVariable String serviceName, HttpServletResponse res) {
+        try {
+            if (!validate(serviceName, res)) {
+                return;
+            }
+
+            byte[] bytes = waterService.getson(serviceName, "rainfall.json");
+
+            WebHelper.writeBytes(bytes, res);
+        } catch (Exception ex) {
+            log.error(ex.getMessage(), ex);
+            WebHelper.writeStr2Page(res, HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
+        }
+    }
+
+    @ApiOperation(value = "鑾峰彇寤虹瓚鐗╂秹姘碕SON")
+    @GetMapping("/{serviceName}/building.json")
+    public void getBuildingJson(@PathVariable String serviceName, HttpServletResponse res) {
+        try {
+            if (!validate(serviceName, res)) {
+                return;
+            }
+
+            byte[] bytes = waterService.getson(serviceName, "building.json");
 
             WebHelper.writeBytes(bytes, res);
         } catch (Exception ex) {
@@ -104,23 +138,6 @@
             String file = waterService.getFlowMap(serviceName, width, height, timestamp);
 
             WebHelper.writePng(file, res);
-        } catch (Exception ex) {
-            log.error(ex.getMessage(), ex);
-            WebHelper.writeStr2Page(res, HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
-        }
-    }
-
-    @ApiOperation(value = "鑾峰彇闄嶆按鏇茬嚎鏂囦欢鏇茬嚎鍥�")
-    @GetMapping("/{serviceName}/rainfall.json")
-    public void getRainfall(@PathVariable String serviceName, HttpServletResponse res) {
-        try {
-            if (!validate(serviceName, res)) {
-                return;
-            }
-
-            byte[] bytes = waterService.getRainfall(serviceName);
-
-            WebHelper.writeBytes(bytes, res);
         } catch (Exception ex) {
             log.error(ex.getMessage(), ex);
             WebHelper.writeStr2Page(res, HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
diff --git a/src/main/java/com/se/simu/service/ResultService.java b/src/main/java/com/se/simu/service/ResultService.java
index b7bd2dd..40b1634 100644
--- a/src/main/java/com/se/simu/service/ResultService.java
+++ b/src/main/java/com/se/simu/service/ResultService.java
@@ -18,6 +18,7 @@
 import org.gdal.gdalconst.gdalconst;
 import org.gdal.ogr.*;
 import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
 
 import javax.annotation.Resource;
 import javax.imageio.ImageIO;
@@ -565,6 +566,8 @@
     }
 
     private void copeBuildingDepthJson(ResultDto dto, List<BuildingDepthVo> list) throws IOException {
+        if (CollectionUtils.isEmpty(list)) return;
+
         String json = JSON.toJSONString(list);
         String filePath = dto.getOutPath() + File.separator + "building.json";
 
diff --git a/src/main/java/com/se/simu/service/WaterService.java b/src/main/java/com/se/simu/service/WaterService.java
index 07beea4..7d6061a 100644
--- a/src/main/java/com/se/simu/service/WaterService.java
+++ b/src/main/java/com/se/simu/service/WaterService.java
@@ -37,9 +37,9 @@
     /**
      * 鑾峰彇鍏冩暟鎹俊鎭�
      */
-    public byte[] getLayerJson(String serviceName) {
+    public byte[] getson(String serviceName, String json) {
         try {
-            String filePath = config.getOutPath() + File.separator + serviceName + File.separator + "layer.json";
+            String filePath = config.getOutPath() + File.separator + serviceName + File.separator + json;
 
             File dat = new File(filePath);
             if (!dat.exists()) {
@@ -54,6 +54,7 @@
 
             return bytes;
         } catch (Exception ex) {
+            log.error(ex.getMessage(), ex);
             return null;
         }
     }
@@ -101,30 +102,6 @@
         layer.setWaters(new Water(data));
 
         return layer;
-    }
-
-    /**
-     * 鑾峰彇闄嶆按鏇茬嚎鏂囦欢鏇茬嚎鍥�
-     */
-    public byte[] getRainfall(String serviceName) {
-        try {
-            String filePath = config.getOutPath() + File.separator + serviceName + File.separator + "rainfall.json";
-
-            File rainfall = new File(filePath);
-            if (!rainfall.exists()) {
-                return null;
-            }
-
-            byte[] bytes = new byte[(int) rainfall.length()];
-
-            FileInputStream fs = new FileInputStream(filePath);
-            fs.read(bytes);
-            fs.close();
-
-            return bytes;
-        } catch (Exception ex) {
-            return null;
-        }
     }
 
     /**

--
Gitblit v1.9.3