| | |
| | | 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.RsaHelper; |
| | | import com.lf.server.helper.StringHelper; |
| | | import com.lf.server.helper.WebHelper; |
| | | import com.lf.server.service.data.DownloadService; |
| | |
| | | |
| | | 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; |
| | | |
| | | /** |
| | |
| | | |
| | | @Autowired |
| | | DownloadService downloadService; |
| | | |
| | | private final static String EQ = "="; |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "分页查询并返回记录数") |
| | |
| | | @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) { |
| | |
| | | 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) { |
| | |
| | | if (null == reqEntity.getIds() || reqEntity.getIds().isEmpty()) { |
| | | return fail("请选择要下载的文件"); |
| | | } |
| | | if (!downloadService.validatePwd(reqEntity)) { |
| | | if (!downloadService.decryptPwd(reqEntity)) { |
| | | return fail("密码解密失败", null); |
| | | } |
| | | if (!StringHelper.checkPwdValid(reqEntity.getPwd())) { |
| | | return fail("密码不符合要求"); |
| | | } |
| | | |
| | | List<MetaFileEntity> list = metaService.selectMetaFiles(reqEntity.getIds()); |
| | | if (null == list || list.isEmpty()) { |
| | | return fail("没有找到元数据"); |
| | | } |
| | | |
| | | return success(true); |
| | | 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, "找不到文件ID", res); |
| | | return; |
| | | if (!pwd.endsWith(EQ)) { |
| | | pwd = URLDecoder.decode(pwd, StandardCharsets.UTF_8.name()); |
| | | } |
| | | |
| | | DownloadEntity de = downloadService.selectByGuid(reqEntity.getGuid()); |
| | | String password = downloadService.decryptPwd(pwd); |
| | | if (null == password) { |
| | | return fail("密码解密失败", 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, "密码解密失败", res); |
| | | } |
| | | |
| | | DownloadEntity de = downloadService.selectByGuid(guid); |
| | | if (null == de) { |
| | | WebHelper.writeInfo(HttpStatus.NOT_FOUND, "文件不存在", res); |
| | | return; |
| | | } |
| | | if (!StringHelper.isNull(de.getPwd()) && !Md5Helper.validatePassword(reqEntity.getPwd(), de.getPwd())) { |
| | | if (!StringHelper.isNull(de.getPwd()) && !Md5Helper.validatePassword(password, de.getPwd())) { |
| | | WebHelper.writeInfo(HttpStatus.UNAUTHORIZED, "密码不正确", res); |
| | | } |
| | | |