src/main/java/com/lf/server/controller/data/MetaController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/lf/server/controller/show/ExportController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/lf/server/entity/ctrl/DownloadReqEntity.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/lf/server/helper/StringHelper.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/lf/server/helper/WebHelper.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/main/java/com/lf/server/controller/data/MetaController.java
@@ -4,6 +4,7 @@ import com.lf.server.controller.all.BaseController; import com.lf.server.entity.all.HttpStatus; import com.lf.server.entity.all.ResponseMsg; import com.lf.server.entity.ctrl.DownloadReqEntity; import com.lf.server.entity.data.DownloadEntity; import com.lf.server.entity.data.MetaEntity; import com.lf.server.entity.sys.UserEntity; @@ -12,10 +13,7 @@ import com.lf.server.service.data.DownloadService; import com.lf.server.service.data.MetaService; import com.lf.server.service.sys.TokenService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -267,13 +265,14 @@ @ApiImplicitParam(name = "pwd", value = "å¯ç ", dataType = "String", paramType = "body", example = ""), @ApiImplicitParam(name = "ids", value = "IDæ°ç»", dataType = "Integer", paramType = "body", example = "1,2") }) @ResponseBody @PostMapping(value = "/downloadReq") public ResponseMsg<Object> downloadReq(@RequestParam String pwd, @RequestParam List<Integer> ids, HttpServletRequest req, HttpServletResponse res) { public ResponseMsg<Object> downloadReq(@RequestBody DownloadReqEntity reqEntity, HttpServletRequest req, HttpServletResponse res) { try { if (StringHelper.isEmpty(pwd)) { if (null == reqEntity || StringHelper.isEmpty(reqEntity.getPwd())) { return fail("å¯ç ä¸è½ä¸ºç©º"); } if (null == ids || ids.isEmpty()) { if (null == reqEntity.getIds() || reqEntity.getIds().isEmpty()) { return fail("è¯·éæ©è¦ä¸è½½çæä»¶"); } @@ -288,18 +287,19 @@ @ApiImplicitParams({ @ApiImplicitParam(name = "guid", value = "æä»¶GUID", dataType = "String", paramType = "query") }) @ResponseBody @RequestMapping(value = "/downloadFile", method = RequestMethod.GET) public void downloadFile(String guid, HttpServletRequest req, HttpServletResponse res) { public void downloadFile(@RequestBody DownloadReqEntity reqEntity, HttpServletRequest req, HttpServletResponse res) { try { UserEntity ue = tokenService.getCurrentUser(req); if (ue == null) { writeInfo(HttpStatus.UNAUTHORIZED, "ç¨æ·æªç»å½", res); if (StringHelper.isEmpty(reqEntity.getGuid())) { WebHelper.writeInfo(HttpStatus.UNAUTHORIZED, "æ¾ä¸å°æä»¶ID", res); return; } DownloadEntity de = downloadService.selectByGuid(guid); if (de == null) { writeInfo(HttpStatus.NOT_FOUND, "æä»¶ä¸åå¨", res); UserEntity ue = tokenService.getCurrentUser(req); DownloadEntity de = downloadService.selectByGuid(reqEntity.getGuid()); if (null == de) { WebHelper.writeInfo(HttpStatus.NOT_FOUND, "æä»¶ä¸åå¨", res); return; } @@ -310,15 +310,7 @@ //String filePath = exportService.getDownloadFilePath(de); //WebHelper.download(filePath, de.getName(), res); } catch (Exception ex) { writeInfo(HttpStatus.ERROR, ex.getMessage(), res); } } private void writeInfo(HttpStatus status, String info, HttpServletResponse res) { try { WebHelper.write2Page(res, WebHelper.getErrJson(status, info)); } catch (Exception e) { log.error(e.getMessage(), e); WebHelper.writeInfo(HttpStatus.ERROR, ex.getMessage(), res); } } } src/main/java/com/lf/server/controller/show/ExportController.java
@@ -112,15 +112,15 @@ @RequestMapping(value = "/downloadFile", method = RequestMethod.GET) public void downloadFile(String guid, HttpServletRequest req, HttpServletResponse res) { try { UserEntity ue = tokenService.getCurrentUser(req); if (ue == null) { writeInfo(HttpStatus.UNAUTHORIZED, "ç¨æ·æªç»å½", res); if (StringHelper.isEmpty(guid)) { WebHelper.writeInfo(HttpStatus.UNAUTHORIZED, "æ¾ä¸å°æä»¶ID", res); return; } UserEntity ue = tokenService.getCurrentUser(req); DownloadEntity de = downloadService.selectByGuid(guid); if (de == null) { writeInfo(HttpStatus.NOT_FOUND, "æä»¶ä¸åå¨", res); if (null == de) { WebHelper.writeInfo(HttpStatus.NOT_FOUND, "æä»¶ä¸åå¨", res); return; } @@ -131,15 +131,7 @@ String filePath = exportService.getDownloadFilePath(de); WebHelper.download(filePath, de.getName(), res); } catch (Exception ex) { writeInfo(HttpStatus.ERROR, ex.getMessage(), res); } } private void writeInfo(HttpStatus status, String info, HttpServletResponse res) { try { WebHelper.write2Page(res, WebHelper.getErrJson(status, info)); } catch (Exception e) { log.error(e.getMessage(), e); WebHelper.writeInfo(HttpStatus.ERROR, ex.getMessage(), res); } } } src/main/java/com/lf/server/entity/ctrl/DownloadReqEntity.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,45 @@ package com.lf.server.entity.ctrl; import java.io.Serializable; import java.util.List; /** * 请æ±ä¸è½½å®ä½ç±» * @author WWW */ public class DownloadReqEntity implements Serializable { private static final long serialVersionUID = -8624235184539814997L; private String pwd; private String guid; private List<Integer> ids; public DownloadReqEntity() { } public String getPwd() { return pwd; } public void setPwd(String pwd) { this.pwd = pwd; } public String getGuid() { return guid; } public void setGuid(String guid) { this.guid = guid; } public List<Integer> getIds() { return ids; } public void setIds(List<Integer> ids) { this.ids = ids; } } src/main/java/com/lf/server/helper/StringHelper.java
@@ -110,7 +110,7 @@ * å符串,æ¯å¦ä¸ºç©ºnullåç©ºæ ¼ */ public static boolean isEmpty(String str) { return str == null || "".equals(str.trim()); return null == str || "".equals(str.trim()); } /** src/main/java/com/lf/server/helper/WebHelper.java
@@ -277,6 +277,17 @@ } /** * åååºä¿¡æ¯ */ public static void writeInfo(HttpStatus status, String info, HttpServletResponse res) { try { WebHelper.write2Page(res, WebHelper.getErrJson(status, info)); } catch (Exception e) { // } } /** * è·åéæºæ´æ° */ public static int getRandomInt(int min, int max) {