From ec7d18cc112f4e5c694e5de837658db243ead5c1 Mon Sep 17 00:00:00 2001
From: 张洋洋 <10611411+yang-yang-z@user.noreply.gitee.com>
Date: 星期四, 20 二月 2025 16:29:56 +0800
Subject: [PATCH] [add]服务发布

---
 src/main/java/com/se/simu/controller/SimuController.java |  121 +++++++++++++++++++++++++++++++---------
 1 files changed, 93 insertions(+), 28 deletions(-)

diff --git a/src/main/java/com/se/simu/controller/SimuController.java b/src/main/java/com/se/simu/controller/SimuController.java
index c9b8452..8f611fe 100644
--- a/src/main/java/com/se/simu/controller/SimuController.java
+++ b/src/main/java/com/se/simu/controller/SimuController.java
@@ -1,5 +1,7 @@
 package com.se.simu.controller;
 
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.json.JSONUtil;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -12,6 +14,10 @@
 import com.se.simu.domain.po.SimuPo;
 import com.se.simu.domain.vo.*;
 import com.se.simu.enums.RadioEnums;
+import com.se.simu.enums.SemErrorEnums;
+import com.se.simu.helper.StringHelper;
+import com.se.simu.helper.WebHelper;
+import com.se.simu.mapper.SimuMapper;
 import com.se.simu.service.*;
 import com.se.simu.utils.*;
 import io.swagger.annotations.*;
@@ -30,6 +36,7 @@
 import java.net.URL;
 import java.net.URLEncoder;
 import java.nio.charset.StandardCharsets;
+import java.sql.Timestamp;
 import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
@@ -58,6 +65,9 @@
 
     @Resource
     PropertiesConfig config;
+
+    @Resource
+    SimuMapper simuMapper;
 
     @Value("${simu-app.filePath}")
     private String uploadedFolder;
@@ -395,13 +405,35 @@
             JSONObject link = getModule("layerQueryParams.json");
             String linkUrl = assemble(vo.getLinkName(), link.getString("layerid"), bbox, token);
             vo.setLinkName(linkUrl);
-            asyncCall(tableName, dtos, vo, token);
+            SimuPo simu = saveSimu(vo);
+            //鐢熸垚sem鏂囦欢
+            asyncCall(tableName, dtos, vo, token, simu);
+
             // 寮�濮嬫ā鎷熻绠�
-            boolean flag = simuFilesService.createByfiles(vo,token);
-            return success(flag, flag ? "鎴愬姛" : "澶辫触");
+            //boolean flag = simuFilesService.createByfiles(vo, token);
+            return success(simu.getId() != null ? "鎴愬姛" : "澶辫触");
         } catch (Exception ex) {
             return fail(ex, null);
         }
+    }
+
+    public SimuPo saveSimu(CreateFilesSimuVo 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);
+        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()));
+        simu.setSemUrl(vo.getSemUrl());
+        simu.setPointUrl(vo.getPointName());
+        simu.setLinkUrl(vo.getLinkName());
+        simu.setSemUrl(inPath + "\\" + vo.getSemUrl());
+        int rows = simuMapper.insert(simu);
+        return simu;
     }
 
     @ApiOperation(value = "鑾峰彇鐐硅矾寰�")
@@ -426,44 +458,77 @@
         return success(null);
     }
 
-    private void asyncCall(String tableName, List<GridDto> dtos, CreateFilesSimuVo vo, String token) {
+    private void asyncCall(String tableName, List<GridDto> dtos, CreateFilesSimuVo vo, String token, SimuPo simu) {
         ExecutorService executor = Executors.newSingleThreadExecutor();
         executor.execute(new Runnable() {
             @Override
             @SneakyThrows
             public void run() {
-                createSem(tableName, dtos, vo, token);
+                createSem(tableName, dtos, vo, token, simu);
             }
         });
         executor.shutdown();
     }
 
-    public void createSem(String tableName, List<GridDto> dtos, CreateFilesSimuVo vo, String token) throws Exception {
-        vo.setSemUrl(inPath + "\\" + vo.getSemUrl());
-        boolean ends = vo.getSemUrl().endsWith("\\");
-        if (!ends) {
-            vo.setSemUrl(vo.getSemUrl() + "\\");
+    public void createSem(String tableName, List<GridDto> dtos, CreateFilesSimuVo vo, String token, SimuPo simu) throws Exception {
+        int code=1;
+        try {
+            vo.setSemUrl(inPath + "\\" + vo.getSemUrl());
+            boolean ends = vo.getSemUrl().endsWith("\\");
+            if (!ends) {
+                vo.setSemUrl(vo.getSemUrl() + "\\");
+            }
+            File file = new File(vo.getSemUrl());
+            if (!file.exists()) {
+                file.mkdirs();
+            }
+            //鍒濆鍖�
+            update(simu, code, null);
+            code+=1;
+            //闄嶉洦鏂囦欢鐢熸垚
+            saveZarr(tableName, vo.getSemUrl());
+            update(simu, code, null);
+            code+=1;
+            //绠$偣鐢熸垚
+            pointTosem(dtos, token, vo.getSemUrl());
+            update(simu, code, null);
+            code+=1;
+            //绠$嚎鐢熸垚
+            lineToSem(dtos, token, vo.getSemUrl());
+            update(simu, code, null);
+            code+=1;
+            //鑼冨洿鐢熸垚
+            gridToCityJson(dtos, vo.getSemUrl());
+            update(simu, code, null);
+            code+=1;
+            //娌虫祦鐢熸垚
+            riverToSem(vo.getSemUrl());
+            update(simu, code, null);
+            code+=1;
+            //鍦熷湴鍒╃敤鐢熸垚
+            landuseToSem(vo.getSemUrl());
+            update(simu, code, null);
+            code+=1;
+            //鍦板舰鐢熸垚
+            terrainToSem(dtos, vo.getSemUrl());
+            update(simu, code, null);
+            code+=1;
+            //9=璋冪敤姹傝В/10=姹傝В鍒嗘瀽
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            update(simu, -simu.getStatus(), SemErrorEnums.of(code));
         }
-        File file = new File(vo.getSemUrl());
-        if (!file.exists()) {
-            file.mkdirs();
-        }
-        //闄嶉洦鏂囦欢鐢熸垚
-        saveZarr(tableName, vo.getSemUrl());
-        //绠$偣鐢熸垚
-        pointTosem(dtos, token, vo.getSemUrl());
-        //绠$嚎鐢熸垚
-        lineToSem(dtos, token, vo.getSemUrl());
-        //鑼冨洿鐢熸垚
-        gridToCityJson(dtos, vo.getSemUrl());
-        //娌虫祦鐢熸垚
-        riverToSem(vo.getSemUrl());
-        //鍦熷湴鍒╃敤鐢熸垚
-        landuseToSem(vo.getSemUrl());
-        //鍦板舰鐢熸垚
-        terrainToSem(dtos, vo.getSemUrl());
+
+
     }
 
+    private void update(SimuPo simu, int status, String rs) {
+        simu.setStatus(status);
+        if (null != rs) simu.setResult(rs);
+        simu.setUpdateTime(WebHelper.getCurrentTimestamp());
+
+        simuMapper.updateById(simu);
+    }
 
     public String assemble(String name, String layerid, String bbox, String token) throws Exception {
         JSONObject jsonObject = EntityLibraryUtils.createAssemble(name, token);

--
Gitblit v1.9.3