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/controller/show/MarkController.java | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/lf/server/controller/show/MarkController.java b/src/main/java/com/lf/server/controller/show/MarkController.java index ec1bf6e..0094e8e 100644 --- a/src/main/java/com/lf/server/controller/show/MarkController.java +++ b/src/main/java/com/lf/server/controller/show/MarkController.java @@ -5,9 +5,12 @@ 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; @@ -34,6 +37,9 @@ @Autowired TokenService tokenService; + + @Autowired + DownloadService downloadService; @SysLog() @ApiOperation(value = "鍒嗛〉鏌ヨ骞惰繑鍥炶褰曟暟") @@ -238,15 +244,47 @@ 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); + } + } } } -- Gitblit v1.9.3