From 0890b7861feae74bdcfd1851e577db6b9f31d484 Mon Sep 17 00:00:00 2001
From: xingjinshuang <xingjs@qq.com>
Date: 星期四, 20 二月 2025 14:40:39 +0800
Subject: [PATCH] @xingjs@20250220@添加处理sww相关接口类

---
 src/main/java/com/se/simu/service/SimuService.java |  134 +++++++++++++++++++++++++++++---------------
 1 files changed, 88 insertions(+), 46 deletions(-)

diff --git a/src/main/java/com/se/simu/service/SimuService.java b/src/main/java/com/se/simu/service/SimuService.java
index 800414f..435d1e5 100644
--- a/src/main/java/com/se/simu/service/SimuService.java
+++ b/src/main/java/com/se/simu/service/SimuService.java
@@ -8,6 +8,8 @@
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.metadata.OrderItem;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.se.simu.config.PropertiesConfig;
+import com.se.simu.domain.dto.GeDb;
 import com.se.simu.domain.po.DataPo;
 import com.se.simu.domain.po.SimuPo;
 import com.se.simu.domain.vo.CreateSimuVo;
@@ -17,41 +19,35 @@
 import com.se.simu.mapper.SimuMapper;
 import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
-import org.springframework.util.StringUtils;
 
 import javax.annotation.Resource;
 import java.io.File;
+import java.sql.Timestamp;
+import java.util.Date;
 import java.util.List;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
-/**
- * 浠跨湡鏈嶅姟绫�
- *
- * @author WWW
- * @date   2024-09-18
- */
 @Slf4j
 @Service
 @SuppressWarnings("ALL")
 public class SimuService {
-    @Value("${sys.path.in}")
-    String inPath;
-
-    @Value("${sys.path.out}")
-    String outPath;
-
     @Resource
     SimuMapper simuMapper;
 
     @Resource
+    PropertiesConfig config;
+
+    @Resource
     GedbService gedbService;
 
-    /**
-     * 鑾峰彇
-     */
+    @Resource
+    UwService uwService;
+
+    @Resource
+    ResultService resultService;
+
     public IPage<SimuPo> get(SimuVo vo) {
         QueryWrapper<SimuPo> wrapper = getPageWrapper(vo);
 
@@ -74,7 +70,7 @@
         if (null != vo.getNum()) {
             wrapper.eq("num", vo.getNum());
         }
-        if (!StringUtils.isEmpty(vo.getName())) {
+        if (!StringHelper.isEmpty(vo.getName())) {
             wrapper.like("lower(name)", vo.getName().trim().toLowerCase());
         }
         if (!CollUtil.isEmpty(vo.getStatus())) {
@@ -84,9 +80,6 @@
         return wrapper;
     }
 
-    /**
-     * 鍒犻櫎
-     */
     public int del(List<Integer> ids) {
         List<SimuPo> list = simuMapper.selectBatchIds(ids);
         if (null != list && list.size() > 0) {
@@ -97,8 +90,9 @@
                     DataPo dp = JSONUtil.toBean(po.getData(), DataPo.class);
                     if (null == dp) continue;
 
-                    delDir(inPath + File.separator + dp.getInPath());
-                    delDir(outPath + File.separator + dp.getOutPath());
+                    delDir(config.getInPath() + File.separator + dp.getInPath());
+                    delDir(config.getOutPath() + File.separator + dp.getOutPath());
+                    FileUtil.del(config.getInPath() + File.separator + dp.getInPath() + ".json");
                 } catch (Exception ex) {
                     log.error(ex.getMessage(), ex);
                 }
@@ -121,12 +115,43 @@
         return simuMapper.selectMaxId();
     }
 
-    public boolean create(CreateSimuVo vo) {
-        DataPo data = BeanUtil.copyProperties(vo, DataPo.class);
-        SimuPo simu = new SimuPo(vo.getNum(), vo.getName(), JSONUtil.toJsonStr(data), 0, vo.getBak());
+    public SimuPo getSimuByPid(Integer pid) {
+        QueryWrapper<SimuPo> wrapper = new QueryWrapper<>();
+        wrapper.eq("id", pid);
+        wrapper.last("limit 1");
 
-        data.setPath(vo.getName(), vo.getName());
+        return simuMapper.selectOne(wrapper);
+    }
+    public SimuPo getSimuById(Integer id) {
+        return simuMapper.selectById(id);
+    }
+
+    public SimuPo getSimuByServiceName(String serviceName) {
+        if (StringHelper.isEmpty(serviceName)) {
+            return null;
+        }
+
+        QueryWrapper<SimuPo> wrapper = new QueryWrapper<>();
+        wrapper.eq("service_name", serviceName);
+        wrapper.last("limit 1");
+
+        return simuMapper.selectOne(wrapper);
+    }
+
+    public boolean create(CreateSimuVo vo) {
+        Date now = new Date();
+        String date = StringHelper.YMDHMS2_FORMAT.format(now);
+        if (StringHelper.isEmpty(vo.getName())) {
+            vo.setName(date);
+        }
+
+        DataPo data = BeanUtil.copyProperties(vo, DataPo.class);
+        data.setPath(date, date);
         initPath(data);
+
+        SimuPo simu = new SimuPo(vo.getNum(), vo.getPid(), vo.getName(), JSONUtil.toJsonStr(data), 0, vo.getBak());
+        simu.setServiceName(date);
+        simu.setCreateTime(new Timestamp(now.getTime()));
 
         int rows = simuMapper.insert(simu);
         if (rows > 0) {
@@ -137,15 +162,16 @@
     }
 
     private void initPath(DataPo data) {
-        createDir(inPath + File.separator + data.getInPath());
-        createDir(outPath + File.separator + data.getOutPath());
+        createDir(config.getInPath() + File.separator + data.getInPath());
+        createDir(config.getOutPath() + File.separator + data.getOutPath());
     }
 
     private void createDir(String path) {
-        File dir = new File(path);
-        if (!dir.exists() || !dir.isDirectory()) {
-            dir.mkdirs();
+        File f = new File(path);
+        if (f.exists() && f.isDirectory()) {
+            FileUtil.del(f);
         }
+        f.mkdirs();
     }
 
     private void asyncCall(SimuPo simu) {
@@ -154,33 +180,49 @@
             @Override
             @SneakyThrows
             public void run() {
-                scope(simu);
+                cope(simu);
             }
         });
         executor.shutdown();
     }
 
-    /**
-     * 澶勭悊锛岀姸鎬侊細0-鍒涘缓浠跨湡锛�1-杩炴帴GEDB搴擄紝2-涓嬭浇绌洪棿鏁版嵁锛�3-涓嬭浇楂樼▼鏁版嵁锛�4-妯℃嫙鍐呮稘浠跨湡锛�5-澶勭悊浠跨湡鏁版嵁锛�10-瀹屾垚锛�-10-鍑洪敊
-     */
-    private void scope(SimuPo simu) {
+    private void cope(SimuPo simu) {
         try {
             DataPo data = JSONUtil.toBean(simu.getData(), DataPo.class);
+
             update(simu, 1, null);
+            String token = gedbService.getToken();
+            GeDb db = gedbService.connectGedb(token, data);
+            simu.setData(JSONUtil.toJsonStr(data));
 
-            //boolean flag = tifService.splitTif(dsd);
-            //update(simu, flag ? 2 : 20, flag ? null : "鍒囧垎鏁版嵁鍑洪敊");
-            //if (!flag) return;
+            update(simu, 2, null);
+            gedbService.copeVectors(token, data, db);
 
-            //flag = aiService.sendRequest(task.getDataType(), dsd.getDataTime());
-            //update(simu, flag ? 3 : 20, flag ? null : "璇嗗埆鏁版嵁鍑洪敊");
-            //if (!flag) return;
+            update(simu, 3, null);
+            gedbService.copeDem(token, data);
 
-            //flag = geoJsonService.processResults(task, dsd);
-            //update(simu, flag ? 10 : 20, flag ? "鎵ц瀹屾垚" : "澶勭悊缁撴灉鍑洪敊");
+            update(simu, 4, null);
+            uwService.createRainFile(data);
+
+            update(simu, 5, null);
+            uwService.createConfig(data);
+
+            update(simu, 6, null);
+            uwService.callExe(data);
+
+            update(simu, 7, null);
+            //uwService.copeWaterFiles();
+
+            update(simu, 8, null);
+            uwService.copeDrainFiles(data);
+
+            update(simu, 9, null);
+            resultService.process(data);
+
+            update(simu, 10, "瀹屾垚");
         } catch (Exception ex) {
             log.error(ex.getMessage(), ex);
-            update(simu, -10, ex.getMessage());
+            update(simu, -simu.getStatus(), ex.getMessage());
         }
     }
 

--
Gitblit v1.9.3