|
@@ -53,19 +53,22 @@ public class FtpUploadTransactionService extends BaseUploadFileService {
|
|
//明日凌晨
|
|
//明日凌晨
|
|
logger.info("准备上报:" + srcPath);
|
|
logger.info("准备上报:" + srcPath);
|
|
try {
|
|
try {
|
|
- InputStreamReader isr = null;
|
|
|
|
- InputStream uploadFileIs = null;
|
|
|
|
|
|
+ String str = "";
|
|
|
|
+ try (
|
|
|
|
+ InputStreamReader isr = new InputStreamReader(new FileInputStream(srcPath), StandardCharsets.UTF_8);){
|
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
|
+ int len1;
|
|
|
|
+ while ((len1 = isr.read()) != -1) {
|
|
|
|
+ sb.append((char) len1);
|
|
|
|
+ }
|
|
|
|
+ str = sb.toString();
|
|
|
|
+ }
|
|
|
|
+ catch (Exception e){
|
|
|
|
+ logger.error("读取文件失败", e);
|
|
|
|
+ }
|
|
if (ftp != null) {
|
|
if (ftp != null) {
|
|
- try {
|
|
|
|
- isr = new InputStreamReader(new FileInputStream(srcPath), StandardCharsets.UTF_8);
|
|
|
|
- StringBuilder sb = new StringBuilder();
|
|
|
|
- int len1;
|
|
|
|
- while ((len1 = isr.read()) != -1) {
|
|
|
|
- sb.append((char) len1);
|
|
|
|
- }
|
|
|
|
- isr.close();
|
|
|
|
- String str = sb.toString();
|
|
|
|
- uploadFileIs = new ByteArrayInputStream(str.getBytes(uploadObject.getUploadFileCharSetEnum().getMessage()));
|
|
|
|
|
|
+ try (
|
|
|
|
+ InputStream uploadFileIs = new ByteArrayInputStream(str.getBytes(uploadObject.getUploadFileCharSetEnum().getMessage()));){
|
|
String uploadFileName = new String(new File(srcPath).getName().getBytes(StandardCharsets.UTF_8), uploadObject.getUploadFileCharSetEnum().getMessage());
|
|
String uploadFileName = new String(new File(srcPath).getName().getBytes(StandardCharsets.UTF_8), uploadObject.getUploadFileCharSetEnum().getMessage());
|
|
// 是否每个文件类型一个路径
|
|
// 是否每个文件类型一个路径
|
|
if (StrUtil.hasBlank(uploadFileChannel.getBackupC()) || "0".equals(uploadFileChannel.getBackupC())) {
|
|
if (StrUtil.hasBlank(uploadFileChannel.getBackupC()) || "0".equals(uploadFileChannel.getBackupC())) {
|
|
@@ -76,28 +79,13 @@ public class FtpUploadTransactionService extends BaseUploadFileService {
|
|
UploadURL uploadURL = uploadURLList.stream().filter(c -> c.getFileTypeEnum().name().equals(keys[1])).collect(Collectors.toList()).get(0);
|
|
UploadURL uploadURL = uploadURLList.stream().filter(c -> c.getFileTypeEnum().name().equals(keys[1])).collect(Collectors.toList()).get(0);
|
|
isSuccess = ftp.upload(uploadURL.getUploadURL(), uploadFileName, uploadFileIs);
|
|
isSuccess = ftp.upload(uploadURL.getUploadURL(), uploadFileName, uploadFileIs);
|
|
}
|
|
}
|
|
- } catch (Exception e) {
|
|
|
|
- logger.error("ftp上传失败", e);
|
|
|
|
- throw e;
|
|
|
|
- } finally {
|
|
|
|
- if (isr != null) {
|
|
|
|
- isr.close();
|
|
|
|
- }
|
|
|
|
- if (uploadFileIs != null) {
|
|
|
|
- uploadFileIs.close();
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
+ catch (Exception e){
|
|
|
|
+ logger.error("读取文件失败", e);
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- try {
|
|
|
|
- isr = new InputStreamReader(new FileInputStream(srcPath), StandardCharsets.UTF_8);
|
|
|
|
- StringBuilder sb = new StringBuilder();
|
|
|
|
- int len1;
|
|
|
|
- while ((len1 = isr.read()) != -1) {
|
|
|
|
- sb.append((char) len1);
|
|
|
|
- }
|
|
|
|
- isr.close();
|
|
|
|
- String str = sb.toString();
|
|
|
|
- uploadFileIs = new ByteArrayInputStream(str.getBytes(uploadObject.getUploadFileCharSetEnum().getMessage()));
|
|
|
|
|
|
+ try (
|
|
|
|
+ InputStream uploadFileIs = new ByteArrayInputStream(str.getBytes(uploadObject.getUploadFileCharSetEnum().getMessage()));){
|
|
String uploadFileName = new String(new File(srcPath).getName().getBytes(StandardCharsets.UTF_8), uploadObject.getUploadFileCharSetEnum().getMessage());
|
|
String uploadFileName = new String(new File(srcPath).getName().getBytes(StandardCharsets.UTF_8), uploadObject.getUploadFileCharSetEnum().getMessage());
|
|
|
|
|
|
if (StrUtil.hasBlank(uploadFileChannel.getBackupC()) || "0".equals(uploadFileChannel.getBackupC())) {
|
|
if (StrUtil.hasBlank(uploadFileChannel.getBackupC()) || "0".equals(uploadFileChannel.getBackupC())) {
|
|
@@ -108,23 +96,17 @@ public class FtpUploadTransactionService extends BaseUploadFileService {
|
|
UploadURL uploadURL = uploadURLList.stream().filter(c -> c.getFileTypeEnum().name().equals(keys[1])).collect(Collectors.toList()).get(0);
|
|
UploadURL uploadURL = uploadURLList.stream().filter(c -> c.getFileTypeEnum().name().equals(keys[1])).collect(Collectors.toList()).get(0);
|
|
sftp.getClient().put(uploadFileIs, uploadURL.getUploadURL() + "/" + uploadFileName);
|
|
sftp.getClient().put(uploadFileIs, uploadURL.getUploadURL() + "/" + uploadFileName);
|
|
}
|
|
}
|
|
-
|
|
|
|
logger.info("上传远端put结束:" + keys[2]);
|
|
logger.info("上传远端put结束:" + keys[2]);
|
|
isSuccess = true;
|
|
isSuccess = true;
|
|
- } finally {
|
|
|
|
- if (isr != null) {
|
|
|
|
- isr.close();
|
|
|
|
- }
|
|
|
|
- if (uploadFileIs != null) {
|
|
|
|
- uploadFileIs.close();
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
+ catch (Exception e){
|
|
|
|
+ logger.error("读取文件失败", e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
isSuccess = false;
|
|
isSuccess = false;
|
|
logger.error("上报通道:" + uploadFileChannel.getChannelName() + "," + keys[2] + "上报失败", e);
|
|
logger.error("上报通道:" + uploadFileChannel.getChannelName() + "," + keys[2] + "上报失败", e);
|
|
Integer id = FileConstant.fileShouldMomentMap.get(entry.getKey());
|
|
Integer id = FileConstant.fileShouldMomentMap.get(entry.getKey());
|
|
-
|
|
|
|
Optional<UploadFileLog> optional = uploadFileLogRepository.findById(id);
|
|
Optional<UploadFileLog> optional = uploadFileLogRepository.findById(id);
|
|
UploadFileLog uploadFileLog = new UploadFileLog();
|
|
UploadFileLog uploadFileLog = new UploadFileLog();
|
|
if (optional.isPresent()) {
|
|
if (optional.isPresent()) {
|