From 9d26a531d6aaad86500e04cc750da15d292e9beb Mon Sep 17 00:00:00 2001
From: wuww <252740454@qq.com>
Date: 星期五, 25 四月 2025 14:18:14 +0800
Subject: [PATCH] 修改controller序号

---
 src/main/java/com/se/nsl/controller/TestController.java |  278 +++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 258 insertions(+), 20 deletions(-)

diff --git a/src/main/java/com/se/nsl/controller/TestController.java b/src/main/java/com/se/nsl/controller/TestController.java
index a5a6fc3..3f4a6c4 100644
--- a/src/main/java/com/se/nsl/controller/TestController.java
+++ b/src/main/java/com/se/nsl/controller/TestController.java
@@ -1,22 +1,41 @@
 package com.se.nsl.controller;
 
+import com.se.nsl.config.PropertiesConfig;
 import com.se.nsl.domain.po.DataPo;
+import com.se.nsl.domain.po.Region;
 import com.se.nsl.domain.vo.R;
+import com.se.nsl.helper.GdalHelper;
 import com.se.nsl.helper.ShpHelper;
 import com.se.nsl.helper.StringHelper;
+import com.se.nsl.mapper.RegionMapper;
 import com.se.nsl.service.*;
+import io.netty.util.internal.StringUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.axis.utils.StringUtils;
+import org.gdal.ogr.*;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
 
-@Api(tags = "Test")
+@Api(tags = "01-Test")
 @Slf4j
 @RestController
 @RequestMapping("/test")
@@ -26,10 +45,13 @@
     UwService uwService;
 
     @Resource
+    TestService testService;
+
+    @Resource
     GedbService gedbService;
 
     @Resource
-    SimuService simuService;
+    SimuPoService simuPoService;
 
     @Resource
     Hdf5Service hdf5Service;
@@ -37,13 +59,229 @@
     @Resource
     ResultService resultService;
 
-    @ApiOperation(value = "褰撳墠鏃堕棿 *")
-    @GetMapping("/getTime")
-    public Object getTime() {
-        return System.currentTimeMillis();
+    @Resource
+    RegionMapper regionMapper;
+
+    @Resource
+    PropertiesConfig config;
+
+    @ApiOperation(value = "01.insertRegion <")
+    @GetMapping("/insertRegion")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "fileName", value = "鏂囦欢鍚�", dataType = "String", paramType = "query", example = "5.beijing.geoJson"),
+            @ApiImplicitParam(name = "type", value = "绫诲瀷", dataType = "Integer", paramType = "query", example = "1")
+    })
+    public R<Object> insertRegion(String fileName, Integer type) {
+        // 瀛欒儭娌焔eometry.json锛�7.nsl_area.geojson锛�4.10000.geoJson锛�5.beijing.geoJson
+        String path = "D:\\terrait\\NslServer\\data\\" + fileName;
+        if (!new File(path).exists()) return fail(path + "锛屾枃浠朵笉瀛樺湪", null);
+
+        org.gdal.ogr.Driver driver = ogr.GetDriverByName("GeoJSON");
+        if (null == driver) return fail("null");
+        DataSource ds = driver.Open(path);
+        if (null == ds) return fail("null");
+
+        List<Region> list = new ArrayList<>();
+        for (int i = 0, c = ds.GetLayerCount(); i < c; i++) {
+            Layer layer = ds.GetLayer(i);
+            for (long j = 0, d = layer.GetFeatureCount(); j <= d; j++) {
+                Feature f = layer.GetFeature(j);
+                if (null == f || null == f.GetGeometryRef()) continue;
+
+                String wkt = f.GetGeometryRef().ExportToWkt().toUpperCase();
+                if (!wkt.contains("POLYGON"))
+                    continue; // g.GetGeometryType() == ogr.wkbPolygon || g.GetGeometryType() == ogr.wkbMultiPolygon
+
+                if (!wkt.contains("MULTIPOLYGON")) wkt = wkt.replace("POLYGON (", "MULTIPOLYGON ((") + ")";
+                list.add(new Region(f.GetFieldAsString("name"), type, wkt)); // type.shortValue()
+                if (path.contains("瀛欒儭娌�")) list.add(new Region(f.GetFieldAsString("name"), 3, wkt));
+            }
+        }
+        ds.delete();
+        driver.delete();
+
+        return success(list.size() > 0 ? regionMapper.inserts(list) : 0);
     }
 
-    @ApiOperation(value = "testCallExe *")
+    @ApiOperation(value = "02.testDepthFiles <")
+    @GetMapping("/testDepthFiles")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "oldPath", value = "杈撳叆璺緞", dataType = "String", paramType = "query", example = "D:\\other\\simu\\uwsolver\\chicago"),
+            @ApiImplicitParam(name = "newPath", value = "寮�濮嬫椂闂�", dataType = "Integer", paramType = "query", example = "D:\\other\\simu\\uwsolver\\chicago\\depth"),
+            @ApiImplicitParam(name = "year", value = "骞�", dataType = "Integer", paramType = "query", example = "2025"),
+            @ApiImplicitParam(name = "month", value = "鏈�", dataType = "Integer", paramType = "query", example = "4"),
+            @ApiImplicitParam(name = "day", value = "鏃�", dataType = "Integer", paramType = "query", example = "21")
+    })
+    public R<Object> testDepthFiles(String oldPath, String newPath, Integer year, Integer month, Integer day) {
+        try {
+            Calendar calendar = Calendar.getInstance();
+            calendar.setTime(new Date(year - 1900, month - 1, day, 0, 0, 0));
+            SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
+
+            for (File file : new File(oldPath).listFiles()) {
+                if (!file.exists() || !file.isDirectory()) continue;
+
+                File tif = new File(oldPath + "\\" + file.getName() + "\\depth.tif");
+                if (!tif.exists() || tif.isDirectory()) continue;
+
+                /*int second = Integer.parseInt(fileName);
+                calendar.set(Calendar.SECOND, 0);
+                calendar.set(Calendar.MINUTE, 0);
+                calendar.set(Calendar.HOUR, 0);
+                calendar.add(Calendar.SECOND, second);*/
+                calendar.add(Calendar.SECOND, 1);
+                String newName = df.format(calendar.getTime());
+                String newFile = newPath + File.separator + newName + ".tif";
+
+                System.out.println(newFile);
+                tif.renameTo(new File(newFile));
+                file.delete();
+            }
+
+            return success("ok");
+        } catch (Exception ex) {
+            return fail(ex, null);
+        }
+    }
+
+    @ApiOperation(value = "03.testTifFiles <")
+    @GetMapping("/testTifFiles")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "oldPath", value = "杈撳叆璺緞", dataType = "String", paramType = "query", example = "D:\\other\\simu\\uwsolver\\chicago\\depth"),
+            @ApiImplicitParam(name = "newPath", value = "寮�濮嬫椂闂�", dataType = "Integer", paramType = "query", example = "D:\\other\\simu\\uwsolver\\chicago\\depth2"),
+            @ApiImplicitParam(name = "step", value = "姝ラ暱", dataType = "Integer", paramType = "query", example = "20")
+    })
+    public R<Object> testTifFiles(String oldPath, String newPath, Integer step) {
+        try {
+            File[] files = new File(oldPath).listFiles();
+            for (int i = 0, c = files.length; i < c; i += step) {
+                File file = files[i];
+                if (!file.exists() || !file.isFile() || !file.getName().endsWith(".tif")) continue;
+
+                String newFile = newPath + File.separator + file.getName();
+
+                System.out.println(newFile);
+                file.renameTo(new File(newFile));
+                //Files.copy(file.toPath(), Paths.get(newFile), StandardCopyOption.REPLACE_EXISTING);
+                file.delete();
+            }
+
+            return success("ok");
+        } catch (Exception ex) {
+            return fail(ex, null);
+        }
+    }
+
+    @ApiOperation(value = "04.testPngList <")
+    @GetMapping("/testPngList")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "path", value = "璺緞", dataType = "String", paramType = "query", example = "D:\\other\\simu\\out\\chicago\\waters"),
+            @ApiImplicitParam(name = "size", value = "灏哄", dataType = "Integer", paramType = "query", example = "1024")
+    })
+    public R<Object> testPngList(String path, Integer size) {
+        try {
+            if (null == size) size = (Integer) 1024;
+            List<String> list = new ArrayList<>();
+            for (File file : new File(path).listFiles()) {
+                if (!file.exists() || file.isFile()) continue;
+
+                File pngFile = new File(file.getPath() + File.separator + size + "_" + size + ".png");
+                if (!pngFile.exists() || pngFile.isDirectory()) continue;
+
+                list.add("file '" + pngFile.getPath().replace("\\", "/") + "'");
+                System.out.println(list.get(list.size() - 1));
+            }
+
+            Path outPath = Paths.get(path + File.separator + "list.txt");
+            try {
+                Files.write(outPath, list, StandardCharsets.UTF_8);
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+
+            return success("ok");
+        } catch (Exception ex) {
+            return fail(ex, null);
+        }
+    }
+
+    @ApiOperation(value = "5.testNsl <")
+    @GetMapping("/testNsl")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "inPath", value = "杈撳叆璺緞", dataType = "String", paramType = "query", example = "20250412"),
+            @ApiImplicitParam(name = "startTime", value = "寮�濮嬫椂闂�", dataType = "Integer", paramType = "query", example = "2025-04-12 00:00:00"),
+            @ApiImplicitParam(name = "epsg", value = "鍧愭爣绯籌D", dataType = "Integer", paramType = "query", example = "4548")
+    })
+    public R<Object> testNsl(String inPath, String startTime, Integer epsg) {
+        try {
+            DataPo data = new DataPo();
+            data.setInPath(inPath);
+            data.setStartTime(StringHelper.YMDHMS_FORMAT.parse(startTime));
+            data.setEpsg(epsg);
+
+            testService.test(data);
+
+            return success("ok");
+        } catch (Exception ex) {
+            return fail(ex, null);
+        }
+    }
+
+    @ApiOperation(value = "09.testCreateNsl <")
+    @GetMapping("/testCreateNsl")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "tifPath", value = "Tif璺緞", dataType = "String", paramType = "query", example = "D:\\other\\simu\\uwsolver\\chicago"),
+            @ApiImplicitParam(name = "inPath", value = "杈撳叆璺緞", dataType = "String", paramType = "query", example = "20250425"),
+            @ApiImplicitParam(name = "startTime", value = "寮�濮嬫椂闂�", dataType = "Integer", paramType = "query", example = "2025-04-25 00:00:00"),
+            @ApiImplicitParam(name = "epsg", value = "鍧愭爣绯籌D", dataType = "Integer", paramType = "query", example = "4548")
+    })
+    public R<Object> testCreateNsl(String tifPath, String inPath, String startTime, Integer epsg) {
+        try {
+            DataPo data = new DataPo();
+            data.setInPath(inPath);
+            data.setStartTime(StringHelper.YMDHMS_FORMAT.parse(startTime));
+            data.setEpsg(epsg);
+
+            procTifs(tifPath, data.getStartTime());
+            testService.test(data);
+
+            return success("ok");
+        } catch (Exception ex) {
+            return fail(ex, null);
+        }
+    }
+
+    private void procTifs(String tifPath, Date startTime) {
+        if (StringUtils.isEmpty(tifPath)) return;
+
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(new Date(startTime.getYear() - 1900, startTime.getMonth() - 1, startTime.getDay(), 0, 0, 0));
+        SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
+        String newPath = config.getInPath() + File.separator + "depth";
+
+        for (File file : new File(tifPath).listFiles()) {
+            if (!file.exists() || !file.isDirectory()) continue;
+
+            File tif = new File(tifPath + "\\" + file.getName() + File.separator + "depth.tif");
+            if (!tif.exists() || tif.isDirectory()) continue;
+
+            calendar.add(Calendar.SECOND, 1);
+            String newName = df.format(calendar.getTime());
+            String newFile = newPath + File.separator + newName + ".tif";
+
+            System.out.println(newFile);
+            tif.renameTo(new File(newFile));
+            file.delete();
+        }
+    }
+
+    @ApiOperation(value = "10.褰撳墠鏃堕棿 *")
+    @GetMapping("/getTime")
+    public Object getTime() {
+        return (Object) System.currentTimeMillis();
+    }
+
+    /*@ApiOperation(value = "12.testCallExe *")
     @ApiImplicitParams({
             @ApiImplicitParam(name = "path", value = "璺緞", dataType = "String", paramType = "query", example = "20241010095328")
     })
@@ -61,7 +299,7 @@
         }
     }
 
-    @ApiOperation(value = "testResuslt *")
+    @ApiOperation(value = "13.testResuslt *")
     @ApiImplicitParams({
             @ApiImplicitParam(name = "path", value = "璺緞", dataType = "String", paramType = "query", example = "20241107092342"),
             @ApiImplicitParam(name = "time", value = "鏃堕棿", dataType = "String", paramType = "query", example = "2024-11-07 09:23:42")
@@ -70,7 +308,7 @@
     public R<Object> testResuslt(String path, String time) {
         try {
             DataPo data = new DataPo();
-            data.setEpsg(4548);
+            data.setEpsg(Integer.valueOf(4548));
             data.setInPath(path);
             data.setStartTime(StringHelper.YMDHMS_FORMAT.parse(time));
 
@@ -82,12 +320,12 @@
         }
     }
 
-    @ApiOperation(value = "testSww2Tif *")
+    @ApiOperation(value = "14.testSww2Tif *")
     @GetMapping("/testSww2Tif")
     public R<Object> testSww2Tif() {
         try {
             DataPo data = new DataPo();
-            data.setEpsg(4548);
+            data.setEpsg(Integer.valueOf(4548));
             data.setInPath("20241010095328");
             data.setStartTime(StringHelper.YMDHMS_FORMAT.parse("2024-09-30 00:00:00"));
 
@@ -99,14 +337,14 @@
         }
     }
 
-    @ApiOperation(value = "testRainfall *")
+    @ApiOperation(value = "15.testRainfall *")
     @GetMapping("/testRainfall")
     public R<Object> testRainfall() {
         try {
             DataPo data = new DataPo();
-            data.setEpsg(4548);
-            data.setTotal(60.0);
-            data.setDuration(60);
+            data.setEpsg(Integer.valueOf(4548));
+            data.setTotal(Double.valueOf(60.0));
+            data.setDuration(Integer.valueOf(60));
             data.setInPath("20241010095328");
             data.setStartTime(StringHelper.YMDHMS_FORMAT.parse("2024-07-01 00:00:00"));
 
@@ -118,7 +356,7 @@
         }
     }
 
-    @ApiOperation(value = "testToken *")
+    @ApiOperation(value = "16.testToken *")
     @GetMapping("/testToken")
     public R<Object> testToken() {
         try {
@@ -130,7 +368,7 @@
         }
     }
 
-    @ApiOperation(value = "testPolygonize *")
+    @ApiOperation(value = "17.testPolygonize *")
     @GetMapping("/testPolygonize")
     public R<Object> testPolygonize() {
         try {
@@ -142,12 +380,12 @@
         }
     }
 
-    @ApiOperation(value = "testH5 *")
+    @ApiOperation(value = "18.testH5 *")
     @GetMapping("/testH5")
     public R<Object> testH5() {
         try {
             DataPo data = new DataPo();
-            data.setEpsg(4548);
+            data.setEpsg(Integer.valueOf(4548));
             data.setInPath("20241010095328");
             data.setStartTime(StringHelper.YMDHMS_FORMAT.parse("2024-09-30 00:00:00"));
 
@@ -157,5 +395,5 @@
         } catch (Exception ex) {
             return fail(ex, null);
         }
-    }
+    }*/
 }

--
Gitblit v1.9.3