| | |
| | | return newFileName; |
| | | } |
| | | |
| | | /** |
| | | * 上传公共文件,如合同、计划等 |
| | | * myUploadProcessor#uploadCommonFile |
| | | * @param file |
| | | * @param parameter |
| | | * @return |
| | | */ |
| | | @FileResolver |
| | | public String uploadCommonFile(UploadFile file, Map<String, Object> parameter) { |
| | | |
| | | String fileId = null; |
| | | try { |
| | | |
| | | String oldFileName = (String)parameter.get("name"); |
| | | if(oldFileName == null){ |
| | | //上传失败:附件名称为空。 |
| | | return "10"; |
| | | } |
| | | //判断oldFileName后缀名是否为pdf |
| | | if(!oldFileName.endsWith(".pdf")) { |
| | | //上传失败:附件不是pdf文件。 |
| | | return "20"; |
| | | } |
| | | String basePath = fileService.getCommonFilePath(null); |
| | | |
| | | fileId = ContextUtil.getTimeId(1000) |
| | | + file.getFileName().substring( |
| | | file.getFileName().lastIndexOf(".")); |
| | | |
| | | file.transferTo(new File(basePath + fileId)); |
| | | |
| | | } catch (IllegalStateException e) { |
| | | e.printStackTrace(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | return fileId; |
| | | } |
| | | |
| | | } |