From d885c204473cd22c1a745c97f6a5a425506d1276 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期六, 03 十二月 2022 08:29:20 +0800 Subject: [PATCH] 1 --- src/main/java/com/lf/server/controller/data/MetaController.java | 174 +++++++++++++++++++++++++++++++++++++++------------------ 1 files changed, 119 insertions(+), 55 deletions(-) diff --git a/src/main/java/com/lf/server/controller/data/MetaController.java b/src/main/java/com/lf/server/controller/data/MetaController.java index a693ada..8d2e07f 100644 --- a/src/main/java/com/lf/server/controller/data/MetaController.java +++ b/src/main/java/com/lf/server/controller/data/MetaController.java @@ -7,7 +7,9 @@ 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.data.MetaFileEntity; import com.lf.server.entity.sys.UserEntity; +import com.lf.server.helper.Md5Helper; import com.lf.server.helper.StringHelper; import com.lf.server.helper.WebHelper; import com.lf.server.service.data.DownloadService; @@ -19,6 +21,9 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.io.File; +import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; import java.util.List; /** @@ -38,64 +43,29 @@ @Autowired DownloadService downloadService; - @SysLog() - @ApiOperation(value = "鏌ヨ璁板綍鏁�") - @ApiImplicitParams({ - @ApiImplicitParam(name = "name", value = "鍚嶇О", dataType = "String", paramType = "query", required = false, example = "") - }) - @GetMapping({"/selectCount"}) - public ResponseMsg<Integer> selectCount(String name) { - try { - int count = metaService.selectCount(name); - - return success(count); - } catch (Exception ex) { - return fail(ex.getMessage(), -1); - } - } - - @SysLog() - @ApiOperation(value = "鍒嗛〉鏌ヨ") - @ApiImplicitParams({ - @ApiImplicitParam(name = "name", value = "鍚嶇О", dataType = "String", paramType = "query", example = ""), - @ApiImplicitParam(name = "pageSize", value = "姣忛〉鏉℃暟", dataType = "Integer", paramType = "query", example = "10"), - @ApiImplicitParam(name = "pageIndex", value = "鍒嗛〉鏁帮紙浠�1寮�濮嬶級", dataType = "Integer", paramType = "query", example = "1") - }) - @GetMapping(value = "/selectByPage") - public ResponseMsg<List<MetaEntity>> selectByPage(String name, Integer pageSize, Integer pageIndex) { - try { - if (pageSize < 1 || pageIndex < 1) { - return fail("姣忛〉椤垫暟鎴栧垎椤垫暟灏忎簬1", null); - } - - List<MetaEntity> rs = metaService.selectByPage(name, pageSize, pageSize * (pageIndex - 1)); - - return success(rs); - } catch (Exception ex) { - return fail(ex.getMessage(), null); - } - } + private final static String EQ = "="; @SysLog() @ApiOperation(value = "鍒嗛〉鏌ヨ骞惰繑鍥炶褰曟暟") @ApiImplicitParams({ + @ApiImplicitParam(name = "dirid", value = "鐩綍ID", dataType = "Integer", paramType = "query", example = "10"), @ApiImplicitParam(name = "name", value = "鍚嶇О", dataType = "String", paramType = "query", example = ""), @ApiImplicitParam(name = "pageSize", value = "姣忛〉鏉℃暟", dataType = "Integer", paramType = "query", example = "10"), @ApiImplicitParam(name = "pageIndex", value = "鍒嗛〉鏁帮紙浠�1寮�濮嬶級", dataType = "Integer", paramType = "query", example = "1") }) @GetMapping(value = "/selectByPageAndCount") - public ResponseMsg<List<MetaEntity>> selectByPageAndCount(String name, Integer pageSize, Integer pageIndex) { + public ResponseMsg<List<MetaEntity>> selectByPageAndCount(Integer dirid, String name, Integer pageSize, Integer pageIndex) { try { if (pageSize < 1 || pageIndex < 1) { return fail("姣忛〉椤垫暟鎴栧垎椤垫暟灏忎簬1", null); } - int count = metaService.selectCount(name); + int count = metaService.selectCount(dirid, name); if (count == 0) { return success(0, null); } - List<MetaEntity> rs = metaService.selectByPage(name, pageSize, pageSize * (pageIndex - 1)); + List<MetaEntity> rs = metaService.selectByPage(dirid, name, pageSize, pageSize * (pageIndex - 1)); return success(count, rs); } catch (Exception ex) { @@ -185,7 +155,8 @@ @GetMapping(value = "/delete") public ResponseMsg<Integer> delete(int id) { try { - int count = metaService.delete(id); + // int count = metaService.delete(id) + int count = metaService.deleteCascade(String.valueOf(id)); return success(count); } catch (Exception ex) { @@ -205,7 +176,9 @@ return fail("id鏁扮粍涓嶈兘涓虹┖", -1); } - int count = metaService.deletes(ids); + // int count = metaService.deletes(ids) + String idStr = StringHelper.join(ids, ","); + int count = metaService.deleteCascade(idStr); return success(count); } catch (Exception ex) { @@ -260,6 +233,37 @@ } @SysLog() + @ApiOperation(value = "鍒嗛〉鏌ヨ涓嬭浇璁板綍骞惰繑鍥炶褰曟暟") + @ApiImplicitParams({ + @ApiImplicitParam(name = "name", value = "鍚嶇О", dataType = "String", paramType = "query", example = ""), + @ApiImplicitParam(name = "pageSize", value = "姣忛〉鏉℃暟", dataType = "Integer", paramType = "query", example = "10"), + @ApiImplicitParam(name = "pageIndex", value = "鍒嗛〉鏁帮紙浠�1寮�濮嬶級", dataType = "Integer", paramType = "query", example = "1") + }) + @GetMapping(value = "/selectPageCountForDownload") + public ResponseMsg<List<DownloadEntity>> selectPageCountForDownload(String name, Integer pageSize, Integer pageIndex, HttpServletRequest req) { + try { + if (pageSize < 1 || pageIndex < 1) { + return fail("姣忛〉椤垫暟鎴栧垎椤垫暟灏忎簬1", null); + } + + UserEntity ue = tokenService.getCurrentUser(req); + if (ue == null) { + return fail("鐢ㄦ埛鏈櫥褰�", null); + } + + int count = downloadService.selectCountForUser(ue.getCreateUser(), 3, name); + if (count == 0) { + return success(0, null); + } + List<DownloadEntity> rs = downloadService.selectByPageForUser(ue.getCreateUser(), 3, name, pageSize, pageSize * (pageIndex - 1)); + + return success(count, rs); + } catch (Exception ex) { + return fail(ex.getMessage(), null); + } + } + + @SysLog() @ApiOperation(value = "璇锋眰涓嬭浇") @ApiImplicitParams({ @ApiImplicitParam(name = "pwd", value = "瀵嗙爜", dataType = "String", paramType = "body", example = ""), @@ -275,37 +279,97 @@ if (null == reqEntity.getIds() || reqEntity.getIds().isEmpty()) { return fail("璇烽�夋嫨瑕佷笅杞界殑鏂囦欢"); } + if (!downloadService.decryptPwd(reqEntity)) { + return fail("瀵嗙爜瑙e瘑澶辫触", null); + } + if (!StringHelper.checkPwdValid(reqEntity.getPwd())) { + return fail("瀵嗙爜涓嶇鍚堣姹�"); + } - return success(true); + List<MetaFileEntity> list = metaService.selectMetaFiles(reqEntity.getIds()); + if (null == list || list.isEmpty()) { + return fail("娌℃湁鎵惧埌鍏冩暟鎹�"); + } + + UserEntity ue = tokenService.getCurrentUser(req); + String guid = downloadService.zipFiles(ue, list, reqEntity.getPwd()); + + return success(guid); } catch (Exception ex) { return fail(ex.getMessage(), null); } } @SysLog() - @ApiOperation(value = "涓嬭浇鏂囦欢") + @ApiOperation(value = "鏌ヨ涓嬭浇鏂囦欢") @ApiImplicitParams({ - @ApiImplicitParam(name = "guid", value = "鏂囦欢GUID", dataType = "String", paramType = "query") + @ApiImplicitParam(name = "guid", value = "鏂囦欢GUID", dataType = "String", paramType = "query"), + @ApiImplicitParam(name = "pwd", value = "瀵嗙爜", dataType = "String", paramType = "query") }) - @ResponseBody - @RequestMapping(value = "/downloadFile", method = RequestMethod.GET) - public void downloadFile(@RequestBody DownloadReqEntity reqEntity, HttpServletRequest req, HttpServletResponse res) { + @GetMapping(value = "/selectDownloadFile") + public ResponseMsg<Boolean> selectDownloadFile(String guid, String pwd) { try { - if (null == reqEntity || StringHelper.isEmpty(reqEntity.getPwd())) { - WebHelper.writeInfo(HttpStatus.BAD_REQUEST, "瀵嗙爜涓嶈兘涓虹┖", res); + if (StringHelper.isEmpty(guid) || StringHelper.isEmpty(pwd)) { + return fail("鏂囦欢ID鍜屽瘑鐮佷笉鑳戒负绌�", null); } - if (StringHelper.isEmpty(reqEntity.getGuid())) { - WebHelper.writeInfo(HttpStatus.BAD_REQUEST, "鎵句笉鍒版枃浠禝D", res); - return; + if (!pwd.endsWith(EQ)) { + pwd = URLDecoder.decode(pwd, StandardCharsets.UTF_8.name()); } - UserEntity ue = tokenService.getCurrentUser(req); - DownloadEntity de = downloadService.selectByGuid(reqEntity.getGuid()); + String password = downloadService.decryptPwd(pwd); + if (null == password) { + return fail("瀵嗙爜瑙e瘑澶辫触", null); + } + + DownloadEntity de = downloadService.selectByGuid(guid); + if (null == de) { + return fail("鏂囦欢涓嶅瓨鍦�", null); + } + if (!StringHelper.isNull(de.getPwd()) && !Md5Helper.validatePassword(password, de.getPwd())) { + return fail("瀵嗙爜涓嶆纭�", null); + } + + String filePath = downloadService.getDownloadFilePath(de); + File file = new File(filePath); + + return success(file.exists()); + } catch (Exception ex) { + return fail(ex.getMessage(), false); + } + } + + @SysLog() + @ApiOperation(value = "涓嬭浇鏂囦欢") + @ApiImplicitParams({ + @ApiImplicitParam(name = "guid", value = "鏂囦欢GUID", dataType = "String", paramType = "query"), + @ApiImplicitParam(name = "pwd", value = "瀵嗙爜", dataType = "String", paramType = "query") + }) + @ResponseBody + @GetMapping(value = "/downloadFile") + public void downloadFile(String guid, String pwd, HttpServletRequest req, HttpServletResponse res) { + try { + if (StringHelper.isEmpty(guid) || StringHelper.isEmpty(pwd)) { + WebHelper.writeInfo(HttpStatus.BAD_REQUEST, "鏂囦欢ID鍜屽瘑鐮佷笉鑳戒负绌�", res); + } + if (!pwd.endsWith(EQ)) { + pwd = URLDecoder.decode(pwd, StandardCharsets.UTF_8.name()); + } + + String password = downloadService.decryptPwd(pwd); + if (null == password) { + WebHelper.writeInfo(HttpStatus.BAD_REQUEST, "瀵嗙爜瑙e瘑澶辫触", res); + } + + DownloadEntity de = downloadService.selectByGuid(guid); if (null == de) { WebHelper.writeInfo(HttpStatus.NOT_FOUND, "鏂囦欢涓嶅瓨鍦�", res); return; } + if (!StringHelper.isNull(de.getPwd()) && !Md5Helper.validatePassword(password, de.getPwd())) { + WebHelper.writeInfo(HttpStatus.UNAUTHORIZED, "瀵嗙爜涓嶆纭�", res); + } + UserEntity ue = tokenService.getCurrentUser(req); de.setDcount(de.getDcount() + 1); de.setDownloadUser(ue.getId()); int rows = downloadService.update(de); -- Gitblit v1.9.3