| | |
| | | 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; |
| | |
| | | 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.*; |
| | | |
| | |
| | | @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("请选择要下载的文件"); |
| | | } |
| | | |
| | |
| | | @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 (null == reqEntity || StringHelper.isEmpty(reqEntity.getPwd())) { |
| | | WebHelper.writeInfo(HttpStatus.BAD_REQUEST, "密码不能为空", res); |
| | | } |
| | | if (StringHelper.isEmpty(reqEntity.getGuid())) { |
| | | WebHelper.writeInfo(HttpStatus.BAD_REQUEST, "找不到文件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; |
| | | } |
| | | |
| | |
| | | de.setDownloadUser(ue.getId()); |
| | | int rows = downloadService.update(de); |
| | | |
| | | //String filePath = exportService.getDownloadFilePath(de); |
| | | //WebHelper.download(filePath, de.getName(), res); |
| | | String filePath = downloadService.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); |
| | | } |
| | | } |
| | | } |