public MessageInfo watermarkUpload(CommonsMultipartFile[] files)throws BusinessException{
MessageInfo msgInfo = new MessageInfo();
String finalPath = "";
String backupsPath = "";
try {
finalPath = new PropertiesLoader("destinationPath.properties").getProperty("GSPO001Path");
File file1 = new File(finalPath);
if (file1.exists()) {
file1.mkdirs();
}
backupsPath = new PropertiesLoader("destinationPath.properties").getProperty("GSPO001PathBackups");
File file2 = new File(finalPath);
if (file2.exists()) {
file2.mkdirs();
}
String[] fileNameArr = null;
String filePreName = "";//文件名前缀,文件名
String fileSufName = "";//文件名后缀,格式名
//循环做数据提取
for(int i = 0;i<files.length;i++){
String fileDir="";
String file ="";
fileNameArr = files[i].getOriginalFilename().split("\\.");
if(fileNameArr==null||fileNameArr.length!=2){
logger.error("机能:{},上传文件名有异常:文件名为{}:", JobIds.GSPT008,files[i].getOriginalFilename());
throw new BusinessException(MsgIds.GSPPDBSQLE002,"文件异常");
}
filePreName = fileNameArr[0].toUpperCase();
fileSufName =fileNameArr[1];
file = filePreName+"."+fileSufName;
fileDir = backupsPath+File.separator+file;
files[i].transferTo(new File(fileDir));//上传到指定路径
//删除原文件
// deleteFile(fileDir);
}
msgInfo = PropertiesUtil.loadSuccessMsg(MsgIds.COMMENTADD002, JobIds.GSPT008);
} catch (BusinessException be) {
logger.error("机能:{},业务异常,追加操作出现异常:",JobIds.GSPT008);
logger.error(be.getMsgInfo().getMessageContent());
throw be;
} catch (IOException e) {
logger.error("机能:{},非业务异常,追加操作出现异常:",JobIds.GSPT008);
logger.error(e.getMessage());
//捕捉未定义的异常,SQL错误到处异常信息
throw new BusinessException(MsgIds.CME03019);// 数据库异常
} catch (Exception e) {
if(e.getCause().toString().contains("ORA-00001")){
//主键重复
msgInfo =PropertiesUtil.loadMsg(MsgIds.GSPT008UP, JobIds.GSPT008);
return msgInfo;
}
logger.error("机能:{},非业务异常,追加操作出现异常:",JobIds.GSPT008);
logger.error(e.getMessage());
throw new BusinessException(MsgIds.CME03019);// 数据库异常
}
return msgInfo;
}
上传文件到服务器或指定路径
最新推荐文章于 2023-07-04 14:09:19 发布