Browse Source

增加服务器系统适配(windows/linux),主要解决文件路径问题

wanger 3 months ago
parent
commit
3a3eafca04

+ 13 - 4
onemap-common/onemap-common-core/src/main/java/com/onemap/common/core/utils/StringUtils.java

@@ -610,9 +610,13 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
      * @param filename
      * @return
      */
-    public static String getFileStaticPath(String filename) {
+    public static String getFileStaticPath(String filename, String platform) {
         filename = filename.replaceAll("\\\\", "/");
-//        return filename.replace("/home/onemapfile/", "/file/statics/");
+        if ("windows".equals(platform)) {
+            return filename.replace("D:/onemapfile/", "/file/statics/");
+        } else if ("linux".equals(platform)) {
+            return filename.replace("/home/onemapfile/", "/file/statics/");
+        }
         return filename.replace("D:/onemapfile/", "/file/statics/");
     }
 
@@ -622,9 +626,13 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
      * @param filename
      * @return
      */
-    public static String getFileAbsolutePath(String filename) {
+    public static String getFileAbsolutePath(String filename, String platform) {
         filename = filename.replaceAll("\\\\", "/");
-//        return filename.replace("/file/statics/", "/home/onemapfile/");
+        if ("windows".equals(platform)) {
+            return filename.replace("/file/statics/", "D:\\onemapfile\\");
+        } else if ("linux".equals(platform)) {
+            return filename.replace("/file/statics/", "/home/onemapfile/");
+        }
         return filename.replace("/file/statics/", "D:\\onemapfile\\");
     }
 
@@ -653,6 +661,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
 
     /**
      * 获取纯英文字符串
+     *
      * @return
      */
     public static String getStrUUID(Integer num) {

+ 4 - 2
onemap-modules/onemap-analyse/src/main/java/com/onemap/analyse/service/impl/ChscServiceImpl.java

@@ -48,6 +48,8 @@ public class ChscServiceImpl implements IChscService {
     private FxfwDictDTO fxfwDictDTO = new FxfwDictDTO();
     @Value("${Hgxfx.temp}")
     private String temp;
+    @Value("${platform}")
+    private String platform;
 
     @Override
     public R<?> authorize(String appid, HttpServletRequest request, HttpServletResponse response) {
@@ -75,7 +77,7 @@ public class ChscServiceImpl implements IChscService {
             if (xzlbDTO.getHgxfx() == chsc.getXzlb()) {
                 HgxfxDTO hgxfx = hgxfxMapper.selectOne(new QueryWrapper<HgxfxDTO>().eq("bsm", bsm));
                 if (hgxfx != null) {
-                    DownloadUtils.download(response, hgxfx.getFxbg().replace(".docx", ".pdf"), "选址报告");
+                    DownloadUtils.download(response, hgxfx.getFxbg().replace(".docx", ".pdf"), "选址报告", platform);
                     return null;
                 } else {
                     return WebResult.error("查询报告为空");
@@ -83,7 +85,7 @@ public class ChscServiceImpl implements IChscService {
             } else if (xzlbDTO.getXmxz() == chsc.getXzlb()) {
                 FzxzDTO fzxz = fzxzMapper.selectOne(new QueryWrapper<FzxzDTO>().eq("bsm", bsm));
                 if (fzxz != null) {
-                    DownloadUtils.download(response, fzxz.getFxbg(), "选址报告");
+                    DownloadUtils.download(response, fzxz.getFxbg(), "选址报告", platform);
                     return null;
                 } else {
                     return WebResult.error("查询报告为空");

+ 6 - 4
onemap-modules/onemap-analyse/src/main/java/com/onemap/analyse/task/FzxzSchedule.java

@@ -58,6 +58,8 @@ public class FzxzSchedule {
     private String fzxzShp;
     @Value("${Hgxfx.temp}")
     private String temp;
+    @Value("${platform}")
+    private String platform;
     /**
      * Scheduled 定时器参数
      * cron表达式:指定任务在特定时间执行
@@ -175,10 +177,10 @@ public class FzxzSchedule {
                     , rootPath + File.separator + reportPath
                     , rootPath + File.separator + simplePath);
             //生成返回结果
-            fzxzReport.setRootPath(StringUtils.getFileStaticPath(rootPath));
-            fzxzReport.setReportfile(StringUtils.getFileStaticPath(rootPath + File.separator + reportPath));
-            fzxzReport.setSimplefile(StringUtils.getFileStaticPath(rootPath + File.separator + simplePath));
-            fzxzReport.setZipfile(StringUtils.getFileStaticPath(rootPath + File.separator + zipPath));
+            fzxzReport.setRootPath(StringUtils.getFileStaticPath(rootPath, platform));
+            fzxzReport.setReportfile(StringUtils.getFileStaticPath(rootPath + File.separator + reportPath, platform));
+            fzxzReport.setSimplefile(StringUtils.getFileStaticPath(rootPath + File.separator + simplePath, platform));
+            fzxzReport.setZipfile(StringUtils.getFileStaticPath(rootPath + File.separator + zipPath, platform));
             fzxzReport.setBsm(bsm);
             fzxzReport.setFxbg(fzxzReport.getReportfile());
             fzxzReport.setJsdw(res.getJsdw());

+ 3 - 1
onemap-modules/onemap-analyse/src/main/java/com/onemap/analyse/task/HgxfxSchedule.java

@@ -51,6 +51,8 @@ public class HgxfxSchedule {
     private String temp;
     @Value("${Hgxfx.ftpOut}")
     private String ftpOut;
+    @Value("${platform}")
+    private String platform;
     private static final Logger log = LoggerFactory.getLogger(HgxfxSchedule.class);
     /**
      * Scheduled 定时器参数
@@ -216,7 +218,7 @@ public class HgxfxSchedule {
         String reportPath = rootPath
                 + File.separator + res.getXmmc() + "(合规性检查报告)_" + timeStamp + ".docx";
         //解析文件路径为web路径
-        String webFilePath = StringUtils.getFileStaticPath(reportPath);
+        String webFilePath = StringUtils.getFileStaticPath(reportPath, platform);
         double mj = 0;
         if (res != null) {
             XWPFDocument document = null;

+ 3 - 2
onemap-modules/onemap-analyse/src/main/java/com/onemap/analyse/utils/DownloadUtils.java

@@ -1,15 +1,16 @@
 package com.onemap.analyse.utils;
 
 import com.onemap.common.core.utils.StringUtils;
+import lombok.Value;
 
 import javax.servlet.http.HttpServletResponse;
 import java.io.*;
 import java.nio.file.Files;
 
 public class DownloadUtils {
-    public static void download(HttpServletResponse response, String filepath, String name){
+    public static void download(HttpServletResponse response, String filepath, String name, String platform){
         try{
-            filepath = StringUtils.getFileAbsolutePath(filepath);
+            filepath = StringUtils.getFileAbsolutePath(filepath, platform);
             File file = new File(filepath);
             // 取得文件名。
             String filename = file.getName();

+ 4 - 1
onemap-modules/onemap-apply/src/main/java/com/onemap/apply/controller/yzt/ZttKController.java

@@ -12,6 +12,7 @@ import com.onemap.common.core.web.controller.BaseController;
 import com.onemap.common.core.web.domain.RequestResult;
 import com.onemap.common.core.web.page.RecordTableDataInfo;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletResponse;
@@ -33,6 +34,8 @@ public class ZttKController extends BaseController
     IZttKService zttkService;
     @Autowired
     ZttKMapper zttKMapper;
+    @Value("${platform}")
+    private String platform;
 
     /**
      * 获取专题图模板
@@ -116,7 +119,7 @@ public class ZttKController extends BaseController
     {
         try
         {
-            String  filepath = StringUtils.getFileAbsolutePath(zttwj);
+            String  filepath = StringUtils.getFileAbsolutePath(zttwj, platform);
 
             File file = new File(filepath);
             // 取得文件名。

+ 4 - 3
onemap-modules/onemap-apply/src/main/java/com/onemap/apply/service/impl/cggl/CgglServiceImpl.java

@@ -67,7 +67,8 @@ public class CgglServiceImpl implements CgglService {
     @Autowired
     private XzczghcgsbMapper xzczghcgsbMapper;
 
-
+    @Value("${platform}")
+    private static String platform;
     @Value("${Cggl.temp}")
     private String temp;
     @Value("${Cggl.appid}")
@@ -854,7 +855,7 @@ public class CgglServiceImpl implements CgglService {
             data.setId(map.get(file.getAbsolutePath()));
             data.setPid(map.get(file.getParent()));
             data.setName(file.getName());
-            data.setFilepath(StringUtils.getFileStaticPath(file.getAbsolutePath()));
+            data.setFilepath(StringUtils.getFileStaticPath(file.getAbsolutePath(), platform));
             data.setIsparent(true);
             if (file.getName().toLowerCase().indexOf(".gdb") > 0) {
                 data.setFilepath(file.getAbsolutePath());
@@ -887,7 +888,7 @@ public class CgglServiceImpl implements CgglService {
                 data.setId(map.get(file.getAbsolutePath()));
                 data.setPid(map.get(file.getParent()));
                 data.setName(file.getName());
-                data.setFilepath(StringUtils.getFileStaticPath(file.getAbsolutePath()));
+                data.setFilepath(StringUtils.getFileStaticPath(file.getAbsolutePath(), platform));
                 data.setIsparent(false);
                 allFile.add(data);
             }