From b1bdad2ff512e73a2dd9049f2ccbddd4634969f7 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期二, 01 十一月 2022 15:51:58 +0800 Subject: [PATCH] 1 --- src/main/java/com/lf/server/service/show/MarkService.java | 75 ++++++++++++++++++++++++++++++++----- 1 files changed, 64 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/lf/server/service/show/MarkService.java b/src/main/java/com/lf/server/service/show/MarkService.java index b1cb186..4fa6894 100644 --- a/src/main/java/com/lf/server/service/show/MarkService.java +++ b/src/main/java/com/lf/server/service/show/MarkService.java @@ -1,10 +1,12 @@ package com.lf.server.service.show; import com.lf.server.entity.ctrl.MarkJsonEntity; +import com.lf.server.entity.data.DownloadEntity; import com.lf.server.entity.show.MarkEntity; import com.lf.server.entity.sys.UserEntity; import com.lf.server.helper.*; import com.lf.server.mapper.show.MarkMapper; +import com.lf.server.service.data.DownloadService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -25,6 +27,9 @@ @Autowired PathHelper pathHelper; + + @Autowired + DownloadService downloadService; @Override public Integer selectCount(Integer uid) { @@ -76,8 +81,42 @@ return markMapper.updates(list); } + /** + * 涓嬭浇ShapeFile鏂囦欢 + * + * @param ue 鐢ㄦ埛瀹炰綋 + * @param list 鏍囩粯JSON瀹炰綋绫婚泦鍚� + * @param req 璇锋眰 + * @param res 鍝嶅簲 + * @return GUID + * @throws Exception 寮傚父 + */ public String downloadShp(UserEntity ue, List<MarkJsonEntity> list, HttpServletRequest req, HttpServletResponse res) throws Exception { String parent = pathHelper.getTempPath(ue.getId()); + + String path = createShapeFiles(ue, list, parent); + File[] files = new File(path).listFiles(); + if (files == null || files.length == 0) { + return null; + } + + String zip = getZip(); + ZipHelper.zip(zip, parent); + FileHelper.deleteDir(parent); + + String guid = FileHelper.getFileMd5(zip); + DownloadEntity entity = downloadService.selectByGuid(guid); + if (entity != null) { + return entity.getGuid(); + } + + DownloadEntity de = getDownloadEntity(ue, zip); + int rows = downloadService.insert(de); + + return rows > 0 ? de.getGuid() : null; + } + + private String createShapeFiles(UserEntity ue, List<MarkJsonEntity> list, String parent) { String path = getShpDir(ue, parent); List<MarkJsonEntity> points = getMarkByType(list, "POINT"); @@ -93,17 +132,7 @@ String polygonFile = GdalHelper.createShp(polygons, path, "POLYGON"); } - File[] files = new File(path).listFiles(); - if (files == null || files.length == 0) { - return "Shp鏂囦欢鐢熸垚澶辫触"; - } - - String zip = getZip(); - ZipHelper.zip(zip, parent); - //download(res, zip); - FileHelper.deleteDir(parent); - - return ""; + return path; } private String getShpDir(UserEntity ue, String parent) { @@ -142,5 +171,29 @@ return path; } + private DownloadEntity getDownloadEntity(UserEntity ue, String file) throws Exception { + DownloadEntity de = new DownloadEntity(); + de.setName(FileHelper.getFileName(file)); + de.setType(1); + de.setDepid(ue.getDepid()); + de.setDcount(0); + // de.setPwd(null) + de.setUrl(FileHelper.getRelativePath(file)); + de.setDescr("涓嬭浇ShapeFile鏂囦欢"); + de.setGuid(FileHelper.getFileMd5(file)); + de.setCreateUser(ue.getId()); + // de.setGeom(null) + return de; + } + + /** + * 鑾峰彇涓嬭浇鏂囦欢璺緞 + * + * @param de 涓嬭浇瀹炰綋绫� + * @return 涓嬭浇鏂囦欢璺緞 + */ + public String getDownloadFilePath(DownloadEntity de) { + return pathHelper.getConfig().getDownloadPath() + File.separator + de.getUrl(); + } } -- Gitblit v1.9.3