| | |
| | | package com.lf.server.controller.show; |
| | | |
| | | import com.lf.server.aspect.SysLog; |
| | | import com.lf.server.annotation.SysLog; |
| | | import com.lf.server.controller.all.BaseController; |
| | | import com.lf.server.entity.all.HttpStatus; |
| | | import com.lf.server.entity.all.ResponseMsg; |
| | |
| | | @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, "用户未登录")); |
| | | if (StringHelper.isEmpty(guid)) { |
| | | WebHelper.writeInfo(HttpStatus.BAD_REQUEST, "找不到文件ID", res); |
| | | return; |
| | | } |
| | | |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | DownloadEntity de = downloadService.selectByGuid(guid); |
| | | if (de == null) { |
| | | WebHelper.write2Page(res, WebHelper.getErrJson(HttpStatus.NOT_FOUND, "文件不存在")); |
| | | if (null == de) { |
| | | WebHelper.writeInfo(HttpStatus.NOT_FOUND, "文件不存在", res); |
| | | return; |
| | | } |
| | | |
| | | de.setDcount(de.getDcount() + 1); |
| | | de.setDownloadUser(ue.getId()); |
| | | int rows = downloadService.update(de); |
| | | |
| | | String filePath = exportService.getDownloadFilePath(de); |
| | | String filePath = downloadService.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); |
| | | } |
| | | WebHelper.writeInfo(HttpStatus.ERROR, ex.getMessage(), res); |
| | | } |
| | | } |
| | | } |