| | |
| | | package com.lf.server.service.show; |
| | | |
| | | import com.lf.server.config.PropertiesConfig; |
| | | import com.lf.server.entity.all.StaticData; |
| | | import com.lf.server.entity.ctrl.DownloadTileEntity; |
| | | import com.lf.server.entity.ctrl.ShpRecordEntity; |
| | | import com.lf.server.entity.data.MetaFileEntity; |
| | | import com.lf.server.entity.data.PublishEntity; |
| | | import com.lf.server.entity.sys.UserEntity; |
| | | import com.lf.server.helper.FileHelper; |
| | | import com.lf.server.helper.ShpHelper; |
| | | import com.lf.server.helper.StringHelper; |
| | | import com.lf.server.helper.*; |
| | | import net.lingala.zip4j.ZipFile; |
| | | import net.lingala.zip4j.model.ZipParameters; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | @Service |
| | | public class InquiryService { |
| | | @Resource |
| | | PropertiesConfig config; |
| | | PathHelper pathHelper; |
| | | |
| | | /** |
| | | * 读取Shp第一条记录的WKT |
| | |
| | | * 打包瓦片 |
| | | */ |
| | | public String zipTiles(DownloadTileEntity dt, PublishEntity pub, UserEntity ue) { |
| | | if (!TilePathExist(pub)) { |
| | | if (!isTilePathExist(pub)) { |
| | | return null; |
| | | } |
| | | |
| | | List<String> list = findTiles(dt, pub); |
| | | List<File> list = findTiles(dt, pub); |
| | | if (list.isEmpty()) { |
| | | return null; |
| | | } |
| | | |
| | | String tempName = StringHelper.YMDHMS2_FORMAT.format(new Date()); |
| | | String zipFile = pathHelper.getDownloadFullPath() + File.separator + tempName + ".zip"; |
| | | |
| | | ZipFile zip = Zip4jHelper.createZipFile(zipFile, dt.getPwd()); |
| | | ZipParameters params = Zip4jHelper.getZipParams(true); |
| | | addFiles(zip, params, list, pub.getPath() + File.separator); |
| | | |
| | | return "aaa"; |
| | | } |
| | |
| | | /** |
| | | * 瓦片路径是否存在 |
| | | */ |
| | | private boolean TilePathExist(PublishEntity pub) { |
| | | String tilePath = config.getTilePath().replace("2d\\tiles", "") + File.separator + pub.getPath(); |
| | | private boolean isTilePathExist(PublishEntity pub) { |
| | | String tilePath = pathHelper.getConfig().getTilePath().replace("2d\\tiles", "") + File.separator + pub.getPath(); |
| | | |
| | | File f = new File(tilePath); |
| | | if (!f.exists() || !f.isDirectory()) { |
| | |
| | | /** |
| | | * 查找瓦片 |
| | | */ |
| | | private List<String> findTiles(DownloadTileEntity dt, PublishEntity pub) { |
| | | List<String> list = new ArrayList<>(); |
| | | private List<File> findTiles(DownloadTileEntity dt, PublishEntity pub) { |
| | | List<File> list = new ArrayList<>(); |
| | | for (int i = 0; i < StaticData.I23; i++) { |
| | | findTilesByZoom(dt, pub, i, list); |
| | | } |
| | |
| | | /** |
| | | * 根据层次查找瓦片 |
| | | */ |
| | | private void findTilesByZoom(DownloadTileEntity dt, PublishEntity pub, int zoom, List<String> list) { |
| | | private void findTilesByZoom(DownloadTileEntity dt, PublishEntity pub, int zoom, List<File> list) { |
| | | File f = new File(pub.getPath() + File.separator + zoom); |
| | | if (!f.exists() || !f.isDirectory()) { |
| | | return; |
| | | } |
| | | |
| | | // |
| | | int x = 0; |
| | | int y = 0; |
| | | // 关键算法 |
| | | |
| | | String pngPath = String.format("%s\\%d\\%d.png", pub.getPath(), x, y); |
| | | File pngFile = new File(pngPath); |
| | | if (pngFile.exists()) { |
| | | list.add(pngFile); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 添加文件至压缩包 |
| | | */ |
| | | private void addFiles(ZipFile zip, ZipParameters params, List<File> list, String basePath) { |
| | | for (File f : list) { |
| | | try { |
| | | params.setFileNameInZip(f.getPath().replace(basePath, "")); |
| | | zip.addStream(new FileInputStream(f), params); |
| | | } catch (Exception e) { |
| | | // |
| | | } |
| | | } |
| | | } |
| | | } |