| | |
| | | |
| | | select st_astext(geom) from bd.dlg_25w_hfcl limit 10; |
| | | |
| | | |
| | | |
| | | |
| | | select * from lf.sys_attach where 1=1 limit 1 |
| | | select * from lf.sys_download; |
| | | select * from lf.sys_user; |
| | | |
| | | |
| | | |
| | |
| | | import com.lf.server.entity.all.ResAuthEntity; |
| | | import com.lf.server.entity.bd.DlgAgnpEntity; |
| | | import com.lf.server.helper.AesHelper; |
| | | import com.lf.server.helper.FileHelper; |
| | | import com.lf.server.helper.PathHelper; |
| | | import com.lf.server.mapper.bd.DlgAgnpMapper; |
| | | import com.lf.server.service.all.BaseQueryService; |
| | |
| | | import com.lf.server.entity.all.HttpStatus; |
| | | import com.lf.server.entity.all.ResponseMsg; |
| | | 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.StringHelper; |
| | | import com.lf.server.helper.WebHelper; |
| | | import com.lf.server.service.data.DownloadService; |
| | | import com.lf.server.service.show.MarkService; |
| | | import com.lf.server.service.sys.TokenService; |
| | | import io.swagger.annotations.Api; |
| | |
| | | |
| | | @Autowired |
| | | TokenService tokenService; |
| | | |
| | | @Autowired |
| | | DownloadService downloadService; |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "分页查询并返回记录数") |
| | |
| | | return fail("找不到标绘数据", null); |
| | | } |
| | | |
| | | String str = markService.downloadShp(ue, list, req, res); |
| | | String guid = markService.downloadShp(ue, list, req, res); |
| | | if (StringHelper.isNull(guid)) { |
| | | return fail("生成ShapeFile文件失败", null); |
| | | } |
| | | |
| | | return success(str); |
| | | return success(guid); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | } |
| | | } |
| | | |
| | | public void downloadFile(String guid) { |
| | | @SysLog() |
| | | @ApiOperation(value = "下载文件") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "guid", value = "文件GUID", dataType = "String", paramType = "query") |
| | | }) |
| | | @RequestMapping(value = "/downloadFile", method = RequestMethod.GET) |
| | | public void downloadFile(String guid, HttpServletRequest req, HttpServletResponse res) { |
| | | try { |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | if (ue == null) { |
| | | WebHelper.write2Page(res, WebHelper.getErrJson(HttpStatus.UNAUTHORIZED, "用户未登录")); |
| | | } |
| | | |
| | | DownloadEntity de = downloadService.selectByGuid(guid); |
| | | if (de == null) { |
| | | WebHelper.write2Page(res, WebHelper.getErrJson(HttpStatus.NOT_FOUND, "文件不存在")); |
| | | } |
| | | |
| | | de.setDcount(de.getDcount() + 1); |
| | | de.setDownloadUser(ue.getId()); |
| | | int rows = downloadService.update(de); |
| | | |
| | | String filePath = markService.getDownloadFilePath(de); |
| | | WebHelper.download(filePath, de.getName(), res); |
| | | } catch (Exception ex) { |
| | | try { |
| | | WebHelper.write2Page(res, WebHelper.getErrJson(HttpStatus.UNAUTHORIZED, ex.getMessage())); |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(), e); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | file.delete(); |
| | | } |
| | | |
| | | /** |
| | | * 获取相对路径 |
| | | * |
| | | * @param file 文件 |
| | | * @return 相对路径 |
| | | */ |
| | | public static String getRelativePath(String file) { |
| | | if (StringHelper.isEmpty(file)) { |
| | | return null; |
| | | } |
| | | |
| | | int idx = file.lastIndexOf(File.separator); |
| | | int start = file.lastIndexOf(File.separator, idx - 1); |
| | | |
| | | return file.substring(start + 1); |
| | | } |
| | | } |
| | |
| | | /** |
| | | * 下载文件 |
| | | * |
| | | * @param file 文件 |
| | | * @param res 响应 |
| | | * @param file 文件 |
| | | * @param fileName 文件名 |
| | | * @param res 响应 |
| | | * @throws Exception 异常 |
| | | */ |
| | | public static void download(String file, HttpServletResponse res) throws Exception { |
| | | String fileName = URLEncoder.encode(FileHelper.getFileName(file), "UTF-8"); |
| | | public static void download(String file, String fileName, HttpServletResponse res) throws Exception { |
| | | if (StringHelper.isNull(fileName)) { |
| | | fileName = URLEncoder.encode(FileHelper.getFileName(file), "UTF-8"); |
| | | } |
| | | |
| | | // 设置响应头中文件的下载方式为附件方式,以及设置文件名 |
| | | res.setHeader("Content-Disposition", "attachment; filename=" + fileName); |
| | |
| | | package com.lf.server.mapper.data; |
| | | |
| | | import com.lf.server.entity.data.DownloadEntity; |
| | | import com.lf.server.entity.sys.AttachEntity; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | import org.springframework.stereotype.Repository; |
| | | |
| | |
| | | public DownloadEntity selectById(int id); |
| | | |
| | | /** |
| | | * 根据Guid查询 |
| | | * |
| | | * @param guid |
| | | * @return |
| | | */ |
| | | public DownloadEntity selectByGuid(String guid); |
| | | |
| | | /** |
| | | * 插入一条 |
| | | * |
| | | * @param entity |
| | |
| | | } |
| | | |
| | | String file = pathHelper.getConfig().getUploadPath() + File.separator + entity.getPath(); |
| | | WebHelper.download(file, res); |
| | | WebHelper.download(file, entity.getName(), res); |
| | | } catch (Exception ex) { |
| | | try { |
| | | String msg = JSON.toJSONString(new ResponseMsg<String>(HttpStatus.ERROR, "文件下载出错")); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public DownloadEntity selectByGuid(String guid) { |
| | | return downloadMapper.selectByGuid(guid); |
| | | } |
| | | |
| | | @Override |
| | | public Integer insert(DownloadEntity entity) { |
| | | return downloadMapper.insert(entity); |
| | | } |
| | |
| | | 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(); |
| | | } |
| | | } |
| | |
| | | select * from lf.sys_download where id = #{id} |
| | | </select> |
| | | |
| | | <select id="selectByGuid" resultType="com.lf.server.entity.data.DownloadEntity"> |
| | | select * from lf.sys_download where guid = #{guid} limit 1 |
| | | </select> |
| | | |
| | | <insert id="insert" parameterType="com.lf.server.entity.data.DownloadEntity"> |
| | | insert into lf.sys_download |
| | | (name,type,depid,dcount,pwd,url,descr,guid,create_user,create_time,download_user,download_time,geom,bak) |
| | |
| | | </select> |
| | | |
| | | <select id="selectByGuid" resultType="com.lf.server.entity.sys.AttachEntity"> |
| | | select * from lf.sys_attach where guid = #{guid} |
| | | select * from lf.sys_attach where guid = #{guid} limit 1 |
| | | </select> |
| | | |
| | | <insert id="insert" parameterType="com.lf.server.entity.sys.AttachEntity"> |