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 |    5 +++--
 src/main/java/com/moon/server/helper/FileHelper.java                 |   14 ++++++++++++--
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/main/java/com/moon/server/helper/FileHelper.java b/src/main/java/com/moon/server/helper/FileHelper.java
index 80d9e4b..d33cf02 100644
--- a/src/main/java/com/moon/server/helper/FileHelper.java
+++ b/src/main/java/com/moon/server/helper/FileHelper.java
@@ -6,6 +6,7 @@
 import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 import java.io.*;
 import java.net.URL;
@@ -468,9 +469,9 @@
     }
 
     /**
-     * 鑾峰彇ClassPath
+     * 鑾峰彇ClassPath-jar
      */
-    public static String getClassPath() {
+    public static String getClassPathForJar() {
         URL resource = ClassLoader.getSystemResource("");
         if (null == resource) {
             return null;
@@ -478,4 +479,13 @@
 
         return decode(filter(resource.getPath()));
     }
+
+    /**
+     * 鑾峰彇ClassPath-war
+     */
+    public static String getClassPathForWar() throws IOException {
+        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();
+
+        return context.getResource("").getFile().getAbsolutePath();
+    }
 }
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 a52c0cd..862ebec 100644
--- a/src/main/java/com/moon/server/service/data/SlopeAnalysisService.java
+++ b/src/main/java/com/moon/server/service/data/SlopeAnalysisService.java
@@ -15,6 +15,7 @@
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
 import java.io.File;
+import java.io.IOException;
 import java.util.*;
 
 /**
@@ -37,9 +38,9 @@
     /**
      * 鑾峰彇Excel妯℃澘
      */
-    private String getXlsTemplate() {
+    private String getXlsTemplate() throws IOException {
         if (null == xlsTemplate) {
-            xlsTemplate = FileHelper.getClassPath() + "config/slope.xlsx";
+            xlsTemplate = FileHelper.getClassPathForWar() + File.separator + "config" + File.separator + "slope.xlsx";
         }
 
         return xlsTemplate;

--
Gitblit v1.9.3