| | |
| | | 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; |
| | | |
| | |
| | | |
| | | @Autowired |
| | | PathHelper pathHelper; |
| | | |
| | | @Autowired |
| | | DownloadService downloadService; |
| | | |
| | | @Override |
| | | public Integer selectCount(Integer uid) { |
| | |
| | | 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"); |
| | |
| | | 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) { |
| | |
| | | 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(); |
| | | } |
| | | } |