package com.ld.igds.file; import java.io.File; import java.io.IOException; import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import com.bstek.dorado.uploader.UploadFile; import com.bstek.dorado.uploader.annotation.FileResolver; import com.ld.igds.util.ContextUtil; /** * dorado7附件上传 * * @author: andy.jia * @description: * @version: * @data:2020年6月24日 * */ @Component public class MyUploadProcessor { @Autowired private CoreFileService fileService; /** * * myUploadProcessor#tempProcess * 上传附件到临时目录,名称自动调整生成,并返回 * * @param file * @param parameter * @return */ @FileResolver public String tempProcess(UploadFile file, Map parameter) { String newFileName = null; try { String basePath = fileService.getTempFilePath(); newFileName = ContextUtil.getUUID() + file.getFileName().substring( file.getFileName().lastIndexOf(".")); file.transferTo(new File(basePath + newFileName)); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return newFileName; } /** * 上传公共文件,如合同、计划等 * myUploadProcessor#uploadCommonFile * @param file * @param parameter * @return */ @FileResolver public String uploadCommonFile(UploadFile file, Map 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; } }