From 4393d934ba300601a91084763616ea80379b550e Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期二, 28 十一月 2023 18:44:49 +0800
Subject: [PATCH] 修改 获取Excel模板 方法

---
 src/main/java/com/moon/server/service/data/SlopeAnalysisService.java |   39 +++++++++++++++++++++++++++++++--------
 1 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/src/main/java/com/moon/server/service/data/SlopeAnalysisService.java b/src/main/java/com/moon/server/service/data/SlopeAnalysisService.java
index dfaecbd..862ebec 100644
--- a/src/main/java/com/moon/server/service/data/SlopeAnalysisService.java
+++ b/src/main/java/com/moon/server/service/data/SlopeAnalysisService.java
@@ -2,7 +2,7 @@
 
 import com.moon.server.entity.all.StaticData;
 import com.moon.server.entity.data.PointEntity;
-import com.moon.server.helper.FileHelper;
+import com.moon.server.helper.*;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.gdal.gdal.Dataset;
@@ -12,11 +12,11 @@
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
 import java.io.File;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
+import java.io.IOException;
+import java.util.*;
 
 /**
  * 鏍呮牸鍒嗘瀽鏈嶅姟
@@ -28,6 +28,9 @@
     @Value("${sys.path.slopFile}")
     private String filePath;
 
+    @Resource
+    protected PathHelper pathHelper;
+
     private String xlsTemplate;
 
     private final static Log log = LogFactory.getLog(SlopeAnalysisService.class);
@@ -35,9 +38,9 @@
     /**
      * 鑾峰彇Excel妯℃澘
      */
-    private String getXlsTemplate() {
+    private String getXlsTemplate() throws IOException {
         if (null == xlsTemplate) {
-            xlsTemplate = FileHelper.getClassPath() + File.separator + "config" + File.separator + "slop.xlsx";
+            xlsTemplate = FileHelper.getClassPathForWar() + File.separator + "config" + File.separator + "slope.xlsx";
         }
 
         return xlsTemplate;
@@ -59,7 +62,13 @@
                 throw new Exception("鍒嗘瀽缁撴灉涓虹┖锛堟煡璇㈣寖鍥存棤鏁堬級");
             }
 
-            //
+            String xlsFile = createXls(list, getXlsTemplate());
+            if (null == xlsFile || !new File(xlsFile).exists()) {
+                throw new Exception("鍒涘缓鍧″害鍒嗘瀽Excel澶辫触");
+            }
+
+            String fileName = FileHelper.getFileName(xlsFile);
+            WebHelper.download(xlsFile, fileName, res);
         } finally {
             if (null != ds) {
                 ds.delete();
@@ -97,11 +106,25 @@
 
                 ds.GetRasterBand(StaticData.I1).ReadRaster(x, y, 1, 1, values);
                 if (!Double.isNaN(values[0])) {
-                    list.add(new PointEntity(point.GetY(), point.GetX(), values[0]));
+                    list.add(new PointEntity(point.GetX(), point.GetY(), values[0]));
                 }
             }
         }
 
         return list;
     }
+
+    /**
+     * 鍒涘缓Excel
+     */
+    public String createXls(List<PointEntity> list, String template) {
+        String target = pathHelper.getTempPath() + File.separator + "slope_" + StringHelper.YMD2_FORMAT.format(new Date()) + ".xlsx";
+
+        Map<String, List<PointEntity>> map = new HashMap<>(1);
+        map.put("data", list);
+
+        ExcelHelper.writeToTemplate(template, target, map);
+
+        return target;
+    }
 }

--
Gitblit v1.9.3