| | |
| | | import com.lf.server.entity.sys.UserEntity; |
| | | import com.lf.server.helper.*; |
| | | import com.lf.server.service.data.DownloadService; |
| | | import com.lf.server.service.sys.DownlogService; |
| | | import com.lf.server.service.data.PublishService; |
| | | import net.lingala.zip4j.ZipFile; |
| | | import net.lingala.zip4j.model.ZipParameters; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | PathHelper pathHelper; |
| | | |
| | | @Resource |
| | | PublishService publishService; |
| | | |
| | | @Resource |
| | | DownloadService downloadService; |
| | | |
| | | private final static Log log = LogFactory.getLog(InquiryService.class); |
| | | |
| | | /** |
| | | * 读取Shp第一条记录的WKT |
| | |
| | | String dbPwd = Md5Helper.reverse(Md5Helper.generate(dt.getPwd())); |
| | | DownloadEntity de = getDownloadEntity(ue, zipFile, dbPwd); |
| | | int rows = downloadService.insert(de); |
| | | if (de.getId() > 0) { |
| | | insertPubDown(pub, de, ue); |
| | | } |
| | | |
| | | return rows > 0 ? de.getGuid() : null; |
| | | } |
| | |
| | | * 瓦片路径是否存在 |
| | | */ |
| | | private boolean isTilePathExist(PublishEntity pub) { |
| | | String tilePath = pathHelper.getConfig().getTilePath().replace("2d\\tiles", "") + File.separator + pub.getPath(); |
| | | String tilePath = pathHelper.getConfig().getTilePath() + pub.getPath(); |
| | | |
| | | File f = new File(tilePath); |
| | | if (!f.exists() || !f.isDirectory()) { |
| | |
| | | */ |
| | | private List<File> findTiles(DownloadTileEntity dt, PublishEntity pub) { |
| | | List<File> list = new ArrayList<>(); |
| | | |
| | | File view = new File(pub.getPath() + File.separator + "view.htm"); |
| | | if (view.exists() && !view.isDirectory()) { |
| | | list.add(view); |
| | | } |
| | | |
| | | for (int i = 0; i < StaticData.I23; i++) { |
| | | findTilesByZoom(dt, pub, i, list); |
| | | List<File> files = findTilesByZoom(dt, pub, i); |
| | | if (files.size() > 0) { |
| | | list.addAll(files); |
| | | } |
| | | } |
| | | |
| | | return list; |
| | |
| | | /** |
| | | * 根据层次查找瓦片 |
| | | */ |
| | | private void findTilesByZoom(DownloadTileEntity dt, PublishEntity pub, int zoom, List<File> list) { |
| | | private List<File> findTilesByZoom(DownloadTileEntity dt, PublishEntity pub, int zoom) { |
| | | List<File> list = new ArrayList<>(); |
| | | File f = new File(pub.getPath() + File.separator + zoom); |
| | | if (!f.exists() || !f.isDirectory()) { |
| | | return; |
| | | return list; |
| | | } |
| | | |
| | | int x = 0; |
| | | int y = 0; |
| | | // 关键算法 |
| | | int[] leftTop = deg2num(zoom, dt.getXmin(), dt.getYmax()); |
| | | int[] rightBottom = deg2num(zoom, dt.getXmax(), dt.getYmin()); |
| | | |
| | | String pngPath = String.format("%s\\%d\\%d.png", pub.getPath(), x, y); |
| | | File pngFile = new File(pngPath); |
| | | if (pngFile.exists()) { |
| | | list.add(pngFile); |
| | | for (int x = leftTop[0]; x <= rightBottom[0]; x++) { |
| | | for (int y = leftTop[1]; y <= rightBottom[1]; y++) { |
| | | String pngPath = String.format("%s\\%d\\%d\\%d.png", pub.getPath(), zoom, x, y); |
| | | |
| | | File pngFile = new File(pngPath); |
| | | if (pngFile.exists()) { |
| | | list.add(pngFile); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | | * 角度转数值 |
| | | */ |
| | | private int[] deg2num(int zoom, double x, double y) { |
| | | double yRad = Math.toRadians(y); |
| | | double n = Math.pow(2.0, zoom); |
| | | |
| | | int xTile = (int) ((x + 180.0) / 360.0 * n); |
| | | int yTile = (int) ((1.0 - Math.log(Math.tan(yRad) + (1 / Math.cos(yRad))) / Math.PI) / 2.0 * n); |
| | | |
| | | return new int[]{xTile, yTile}; |
| | | } |
| | | |
| | | /** |
| | |
| | | try { |
| | | params.setFileNameInZip(f.getPath().replace(basePath, "")); |
| | | zip.addStream(new FileInputStream(f), params); |
| | | } catch (Exception e) { |
| | | // |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | return de; |
| | | } |
| | | |
| | | /** |
| | | * 插入数据发布-下载表 |
| | | */ |
| | | private void insertPubDown(PublishEntity pub, DownloadEntity de, UserEntity ue) { |
| | | publishService.insertPubDown(pub.getId(), de.getId(), ue.getId()); |
| | | } |
| | | } |