src/main/java/com/lf/server/config/PropertiesConfig.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/lf/server/helper/FileHelper.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/lf/server/helper/PathHelper.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/lf/server/service/show/MarkService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/resources/application.yml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
说明.txt | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/main/java/com/lf/server/config/PropertiesConfig.java
@@ -9,8 +9,8 @@ */ @Configuration public class PropertiesConfig { @Value("${sys.path.import}") private String importPath; @Value("${sys.path.download}") private String downloadPath; @Value("${sys.path.export}") private String exportPath; @@ -46,12 +46,12 @@ this.druidPwd = druidPwd; } public String getImportPath() { return importPath; public String getDownloadPath() { return downloadPath; } public void setImportPath(String importPath) { this.importPath = importPath; public void setDownloadPath(String downloadPath) { this.downloadPath = downloadPath; } public String getExportPath() { src/main/java/com/lf/server/helper/FileHelper.java
@@ -26,6 +26,20 @@ private final static Log log = LogFactory.getLog(FileHelper.class); /** * è·åæä»¶å * @param file * @return */ public static String getFileName(String file) { int idx = file.lastIndexOf(File.separator); if (idx > -1) { return file.substring(idx + 1); } return ""; } /** * è·åæä»¶æ©å±å */ public static String getExtension(File file) { src/main/java/com/lf/server/helper/PathHelper.java
@@ -19,7 +19,7 @@ @Autowired private PropertiesConfig config; private static int importPath = 1; private static int downloadPath = 1; private static int exportPath = 1; @@ -35,8 +35,8 @@ return config; } public static int getImportPath() { return importPath; public static int getDownloadPath() { return downloadPath; } public static int getExportPath() { @@ -55,7 +55,7 @@ * åå§å */ public void init() { importPath = getSubPath(config.getImportPath(), importPath); downloadPath = getSubPath(config.getDownloadPath(), downloadPath); exportPath = getSubPath(config.getExportPath(), exportPath); uploadPath = getSubPath(config.getUploadPath(), uploadPath); sharePath = getSubPath(config.getSharePath(), sharePath); @@ -84,9 +84,9 @@ * è·åå¯¼å ¥ç®å½ */ public String getImportFullPath() { importPath = getSubPath(config.getImportPath(), importPath); downloadPath = getSubPath(config.getDownloadPath(), downloadPath); return config.getImportPath() + File.separator + importPath; return config.getDownloadPath() + File.separator + downloadPath; } /** src/main/java/com/lf/server/service/show/MarkService.java
@@ -1,12 +1,10 @@ package com.lf.server.service.show; import com.lf.server.entity.all.HttpStatus; import com.lf.server.entity.ctrl.MarkJsonEntity; import com.lf.server.entity.show.MarkEntity; import com.lf.server.entity.sys.UserEntity; import com.lf.server.helper.GdalHelper; import com.lf.server.helper.PathHelper; import com.lf.server.helper.StringHelper; import com.lf.server.helper.WebHelper; import com.lf.server.helper.*; import com.lf.server.mapper.show.MarkMapper; import com.lf.server.service.data.UploaderService; import org.apache.commons.logging.Log; @@ -15,9 +13,12 @@ import org.springframework.stereotype.Service; import org.springframework.web.bind.annotation.RequestBody; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.FileInputStream; import java.net.URLEncoder; import java.util.ArrayList; import java.util.List; import java.util.Random; @@ -84,8 +85,9 @@ return markMapper.updates(list); } public void downloadShp(UserEntity ue, List<MarkJsonEntity> list, HttpServletRequest req, HttpServletResponse res) { String path = getShpDir(ue); public void downloadShp(UserEntity ue, List<MarkJsonEntity> list, HttpServletRequest req, HttpServletResponse res) throws Exception { String parent = pathHelper.getTempPath(ue.getId()); String path = getShpDir(ue, parent); List<MarkJsonEntity> points = getMarkByType(list, "POINT"); if (points.size() > 0) { @@ -100,11 +102,19 @@ String polygonFile = GdalHelper.createShp(polygons, path, "POLYGON"); } // File[] files = new File(path).listFiles(); if (files == null || files.length == 0) { WebHelper.write2Page(res, WebHelper.getErrJson(HttpStatus.BAD_REQUEST, "Shpæä»¶çæå¤±è´¥")); return; } String zip = getZip(parent); ZipHelper.zip(zip, parent); download(res, zip); } private String getShpDir(UserEntity ue) { String path = pathHelper.getTempPath(ue.getId()) + File.separator + WebHelper.getRandomInt(100000, 1000000); private String getShpDir(UserEntity ue, String parent) { String path = parent + File.separator + WebHelper.getRandomInt(100000, 1000000); File file = new File(path); if (!file.exists() && !file.isDirectory()) { @@ -127,4 +137,46 @@ return rs; } private String getZip(String parent) { String path = parent + File.separator + WebHelper.getRandomInt(100000, 1000000) + ".zip"; File file = new File(path); if (file.exists() && !file.isDirectory()) { file.delete(); } return path; } private void download(HttpServletResponse res, String file) throws Exception { String fileName = URLEncoder.encode(FileHelper.getFileName(file), "UTF-8"); // 设置ååºå¤´ä¸æä»¶çä¸è½½æ¹å¼ä¸ºéä»¶æ¹å¼ï¼ä»¥å设置æä»¶å res.setHeader("Content-Disposition", "attachment; filename=" + fileName); // 设置ååºå¤´çç¼ç æ ¼å¼ä¸ºUTF-8 res.setCharacterEncoding("UTF-8"); // éè¿response对象设置ååºæ°æ®æ ¼å¼(å¦ï¼"text/plain; charset=utf-8") String ext = FileHelper.getExtension(file); String mime = FileHelper.getMime(ext); res.setContentType(mime); // éè¿response对象ï¼è·åå°è¾åºæµ ServletOutputStream outputStream = res.getOutputStream(); // å®ä¹è¾å ¥æµï¼éè¿è¾å ¥æµè¯»åæä»¶å 容 FileInputStream fileInputStream = new FileInputStream(file); int len = 0; byte[] bytes = new byte[1024]; while ((len = fileInputStream.read(bytes)) != -1) { // éè¿è¾å ¥æµè¯»åæä»¶æ°æ®ï¼ç¶åéè¿ä¸è¿°çè¾åºæµååæµè§å¨ outputStream.write(bytes, 0, len); outputStream.flush(); } // å ³éèµæº outputStream.close(); fileInputStream.close(); } } src/main/resources/application.yml
@@ -140,13 +140,13 @@ # ç³»ç»é ç½® sys: path: # å¯¼å ¥ç®å½ import: D:\LF\import # åºå¾ç®å½ # ä¸è½½ç®å½ï¼ä¸è½½æä»¶ï¼ download: D:\LF\download # åºå¾ç®å½ï¼ä¸é¢å¾åºå¾ï¼ export: D:\LF\export # ä¸ä¼ ç®å½ # ä¸ä¼ ç®å½ï¼å¤§æ°æ®ä¸ä¼ ï¼ upload: D:\LF\upload # å ±äº«ç®å½ # å ±äº«ç®å½ï¼æ°æ®åå¸ï¼ share: D:\LF\share # 临æ¶ç®å½ # 临æ¶ç®å½ï¼ä¸´æ¶ä¸ä¼ æä»¶ï¼ temp: D:\LF\temp ˵Ã÷.txt
@@ -24,19 +24,24 @@ 23.ä¿®æ¹é»åæ°æ®ä¸è½½å·¥å ·ï¼æ´æ°æ°å¢å段ç屿§ 24.èº«ä»½è®¤è¯æ¦æªå¨æ·»å é»ç½å忣æ¥åè½ 25.å¼åèªå¨çæMybtis Plus代ç å°å·¥å · 26.æ¹éçæåºç¡æ°æ®è¡¨çå®ä½ç±»åMapperç±» < 27. 28. 26.æ¹éçæåºç¡æ°æ®è¡¨çå®ä½ç±»åMapperç±» 27.ä¿®æ¹ææçæ¹éæ°å¢ãå é¤ãä¿®æ¹æ¥å£ 28.å¼å大æä»¶ä¸ä¼ æ¥å£ï¼commons-fileuploadï¼ < 29. 30. ----------------------------------------------- .æ·»å æ¹éä¿®æ¹ç¨æ·å¯ç æ¥å£ .ä¿®æ¹ææçæ¹éæ°å¢ãå é¤ãä¿®æ¹æ¥å£ .å¼å大æä»¶ä¸ä¼ æ¥å£ï¼commons-fileuploadï¼ .ä¿®æ¹ç¨æ·å¯ç æ¥å£ .GDAL读åshpåå é¤ä¸ä¼ æä»¶ .å¯¹ç¨æ·ãèåãè§è²ãèµæºè¿è¡ææ .æ·»å æ¥è¯¢è§è²ãèåãèµæºæéæ¥å£ .å¼åæ ¹æ®å®ä½åç§°å¨ææ¥è¯¢è¡¨çè®°å½æ° .å¼åæ ¹æ®å®ä½åç§°è¿è¡å¨æå页æ¥è¯¢ .å¼åæ ¹æ®å®ä½åç§°æ¥è¯¢ç©ºé´è¡¨çWKTè®°å½ .å¼åæ ¹æ®å®ä½åç§°+åæ®µ+弿¨¡ç³æç´¢å10æ¡è®°å½ .å¼åæ ¹æ®åç§°æ¨¡ç³æç´¢ç¨æ·ãåä½çå10æ¡è®°å½ .å¼åæ ¹æ®æ ç»JSONæ°æ®çæshpæä»¶å¹¶ä¸è½½ .å¼åä¸ä¼ shpæä»¶è½¬æ¢ä¸ºJSONæ°æ®æ¥å£ ---------------------------------------------------------------------------------------------------- java è°ç¨gdal读ågdbæ°æ®ï¼linuxä¸javaè°ç¨gdalï¼