| | |
| | | import com.product.core.entity.RequestParameterEntity; |
| | | import com.product.core.exception.BaseException; |
| | | import com.product.core.spring.context.SpringMVCContextHolder; |
| | | import com.product.file.config.CmnConst; |
| | | import com.product.file.config.FileCode; |
| | | import com.product.file.service.FileManagerService; |
| | | import com.product.module.sys.version.ApiVersion; |
| | |
| | | @Autowired |
| | | public FileManagerService fileManagerService; |
| | | |
| | | |
| | | /** |
| | | * @param uuid |
| | | * @param response |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 文件记录-新增 |
| | | * |
| | | * @param request 请求 |
| | | * @return 结果 |
| | | */ |
| | | @RequestMapping(value = "/add-file-record-plan/{version}", method = RequestMethod.POST) |
| | | @ApiVersion(1) |
| | | public String addFileRecordPlan(HttpServletRequest request) { |
| | | try { |
| | | FieldSetEntity fse = null; |
| | | Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); |
| | | RequestParameterEntity rpe = (RequestParameterEntity) bean; |
| | | if (null != rpe && null != rpe.getFormData()) { |
| | | fse = rpe.getFormData(); |
| | | } |
| | | if (fse == null) { |
| | | SpringMVCContextHolder.getSystemLogger().error(FileCode.FORM_NODATA.getValue(), FileCode.FORM_NODATA.getText()); |
| | | return this.error(FileCode.FORM_NODATA.getValue(), FileCode.FORM_NODATA.getText()); |
| | | } |
| | | FieldSetEntity fs = fileManagerService.addFileRecordPlan(fse); |
| | | return fs != null ? this.OK_List(fs) : this.error(FileCode.ADD_FILE_RECORD_FAIL.getValue(), FileCode.ADD_FILE_RECORD_FAIL.getText()); |
| | | } catch (BaseException e) { |
| | | SpringMVCContextHolder.getSystemLogger().error(e); |
| | | return this.error(e.getCode(), e.getMessageInfo()); |
| | | } catch (Exception e) { |
| | | SpringMVCContextHolder.getSystemLogger().error(e); |
| | | e.printStackTrace(); |
| | | return error(FileCode.ADD_FILE_RECORD_FAIL.getValue(), FileCode.ADD_FILE_RECORD_FAIL.getText()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 文件记录-文件新增结果回调 |
| | | * |
| | | * @param request 请求 |
| | | * @return 结果 |
| | | */ |
| | | @RequestMapping(value = "/add-file-callback/{version}", method = RequestMethod.POST) |
| | | @ApiVersion(1) |
| | | public String addFileCallback(HttpServletRequest request) { |
| | | try { |
| | | FieldSetEntity fse = null; |
| | | Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); |
| | | RequestParameterEntity rpe = (RequestParameterEntity) bean; |
| | | if (null != rpe && null != rpe.getFormData()) { |
| | | fse = rpe.getFormData(); |
| | | } |
| | | if (fse == null) { |
| | | SpringMVCContextHolder.getSystemLogger().error(FileCode.FORM_NODATA.getValue(), FileCode.FORM_NODATA.getText()); |
| | | return this.error(FileCode.FORM_NODATA.getValue(), FileCode.FORM_NODATA.getText()); |
| | | } |
| | | JSONObject data = fileManagerService.addFileCallback(fse); |
| | | JSONObject result = new JSONObject(); |
| | | result.put("data", data); |
| | | result.put("msg", FileCode.SUCCESS.getText()); |
| | | result.put("code", "200"); |
| | | result.put("status", "success"); |
| | | return result.toString(); |
| | | } catch (BaseException e) { |
| | | SpringMVCContextHolder.getSystemLogger().error(e); |
| | | return this.error(e.getCode(), e.getMessageInfo()); |
| | | } catch (Exception e) { |
| | | SpringMVCContextHolder.getSystemLogger().error(e); |
| | | e.printStackTrace(); |
| | | return error(FileCode.ADD_FILE_CALLBACK_FAIL.getValue(), FileCode.ADD_FILE_CALLBACK_FAIL.getText()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 文件记录-删除准备(状态修改) |
| | | * |
| | | * @param request 请求 |
| | | * @return 结果 |
| | | */ |
| | | @RequestMapping(value = "/del-file-record-plan/{version}", method = RequestMethod.POST) |
| | | @ApiVersion(1) |
| | | public String delFileRecordPlan(HttpServletRequest request) { |
| | | try { |
| | | FieldSetEntity fse = null; |
| | | Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); |
| | | RequestParameterEntity rpe = (RequestParameterEntity) bean; |
| | | if (null != rpe && null != rpe.getFormData()) { |
| | | fse = rpe.getFormData(); |
| | | } |
| | | if (fse == null) { |
| | | SpringMVCContextHolder.getSystemLogger().error(FileCode.FORM_NODATA.getValue(), FileCode.FORM_NODATA.getText()); |
| | | return this.error(FileCode.FORM_NODATA.getValue(), FileCode.FORM_NODATA.getText()); |
| | | } |
| | | FieldSetEntity fs = fileManagerService.delFileRecordPlan(fse); |
| | | |
| | | return fs != null ? this.OK_List(fs) : this.error(FileCode.DELETE_FILE_PLAN_FIAL.getValue(), FileCode.DELETE_FILE_PLAN_FIAL.getText()); |
| | | } catch (BaseException e) { |
| | | SpringMVCContextHolder.getSystemLogger().error(e); |
| | | return this.error(e.getCode(), e.getMessageInfo()); |
| | | } catch (Exception e) { |
| | | SpringMVCContextHolder.getSystemLogger().error(e); |
| | | e.printStackTrace(); |
| | | return error(FileCode.DELETE_FILE_PLAN_FIAL.getValue(), FileCode.DELETE_FILE_PLAN_FIAL.getText()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 文件记录-文件新增结果回调 |
| | | * |
| | | * @param request 请求 |
| | | * @return 结果 |
| | | */ |
| | | @RequestMapping(value = "/del-file-callback/{version}", method = RequestMethod.POST) |
| | | @ApiVersion(1) |
| | | public String delFileCallback(HttpServletRequest request) { |
| | | try { |
| | | FieldSetEntity fse = null; |
| | | Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); |
| | | RequestParameterEntity rpe = (RequestParameterEntity) bean; |
| | | if (null != rpe && null != rpe.getFormData()) { |
| | | fse = rpe.getFormData(); |
| | | } |
| | | if (fse == null) { |
| | | SpringMVCContextHolder.getSystemLogger().error(FileCode.FORM_NODATA.getValue(), FileCode.FORM_NODATA.getText()); |
| | | return this.error(FileCode.FORM_NODATA.getValue(), FileCode.FORM_NODATA.getText()); |
| | | } |
| | | JSONObject data = fileManagerService.delFileCallback(fse); |
| | | JSONObject result = new JSONObject(); |
| | | result.put("data", data); |
| | | result.put("msg", FileCode.SUCCESS.getText()); |
| | | result.put("code", "200"); |
| | | result.put("status", "success"); |
| | | return result.toString(); |
| | | } catch (BaseException e) { |
| | | SpringMVCContextHolder.getSystemLogger().error(e); |
| | | return this.error(e.getCode(), e.getMessageInfo()); |
| | | } catch (Exception e) { |
| | | SpringMVCContextHolder.getSystemLogger().error(e); |
| | | e.printStackTrace(); |
| | | return error(FileCode.DELETE_FILE_CALLBACK_FIAL.getValue(), FileCode.DELETE_FILE_CALLBACK_FIAL.getText()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取客户上传的文件总大小 |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取文件记录信息 |
| | | * |
| | | * @return 结果 |
| | | */ |
| | | @RequestMapping(value = "/get-file-info/{version}", method = RequestMethod.POST) |
| | | @ApiVersion(1) |
| | | public String getFileInfo(HttpServletRequest request) { |
| | | try { |
| | | FieldSetEntity fse = null; |
| | | Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); |
| | | RequestParameterEntity rpe = (RequestParameterEntity) bean; |
| | | if (null != rpe && null != rpe.getFormData()) { |
| | | fse = rpe.getFormData(); |
| | | } |
| | | if (fse == null) { |
| | | SpringMVCContextHolder.getSystemLogger().error(FileCode.FORM_NODATA.getValue(), FileCode.FORM_NODATA.getText()); |
| | | return this.error(FileCode.FORM_NODATA.getValue(), FileCode.FORM_NODATA.getText()); |
| | | } |
| | | return BaseUtil.success(fileManagerService.getFileInfo(fse), null); |
| | | } catch (Exception e) { |
| | | SpringMVCContextHolder.getSystemLogger().error(e); |
| | | e.printStackTrace(); |
| | | return error(FileCode.CLEAR_NO_USED_DATA_FAIL.getValue(), FileCode.CLEAR_NO_USED_DATA_FAIL.getText()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 文件刪除 |
| | |
| | | return error(FileCode.UPLOAD_FILE_FAIL.getValue(), FileCode.UPLOAD_FILE_FAIL.getText()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 下载文件或者在线预览 |
| | | * |
| | | * @return 结果 |
| | | */ |
| | | @RequestMapping(value = "/get-file-content/{version}", method = RequestMethod.GET) |
| | | @ApiVersion(1) |
| | | public String getFileContents(HttpServletRequest request, HttpServletResponse response) { |
| | | try { |
| | | FieldSetEntity fse = null; |
| | | String uuid = request.getParameter(CoreConst.UUID); |
| | | String onlineView = request.getParameter(CmnConst.NEED_ONLINE_VIEW); |
| | | |
| | | if (StringUtils.isEmpty(uuid)) { |
| | | SpringMVCContextHolder.getSystemLogger().error(FileCode.FORM_NODATA.getValue(), FileCode.FORM_NODATA.getText()); |
| | | return this.error(FileCode.FORM_NODATA.getValue(), FileCode.FORM_NODATA.getText()); |
| | | } |
| | | fse=new FieldSetEntity(); |
| | | fse.setTableName(CmnConst.PRODUCT_SYS_ATTACHMENTS); |
| | | fse.setValue(CoreConst.UUID, uuid); |
| | | fse.setValue(CmnConst.NEED_ONLINE_VIEW, onlineView); |
| | | SpringMVCContextHolder.getSystemLogger().info("通过GET请求获取附件内容"); |
| | | // 正式代码 |
| | | fileManagerService.getFileContent(fse, response); |
| | | return OK(); |
| | | } catch (Exception e) { |
| | | SpringMVCContextHolder.getSystemLogger().error(e); |
| | | e.printStackTrace(); |
| | | return error(FileCode.GET_FILE_CONTENT_FAIL.getValue(), FileCode.GET_FILE_CONTENT_FAIL.getText()); |
| | | } |
| | | } |
| | | /** |
| | | * 下载文件或者在线预览 |
| | | * |