Commit ffdba4d4 authored by chenzhao's avatar chenzhao Committed by hezhuozhi

工行代扣回盘下载接口修改

parent 630f3084
......@@ -73,6 +73,9 @@ public class IcbcWithholdDto extends BaseDto {
* 失败原因
*/
private String uploadErrorDesc;
private String receiptFile;
/**
* 失败原因
*/
......
......@@ -257,8 +257,6 @@ public class SFTPUtil {
if (null != output) {
output.close();
}
// 关闭连接
disconnect();
} catch (IOException e) {
logger.error("关闭文件时出错!");
logger.error(e.getMessage());
......@@ -275,14 +273,57 @@ public class SFTPUtil {
* @param localZipPath 本地ZIP文件保存路径
* @return 是否成功
*/
public boolean downloadAndZipFiles(String remotePath, String filenamePattern, String localZipPath) {
// public boolean downloadAndZipFiles(String remotePath, String filenamePattern, String localZipPath) {
// boolean success = false;
// Path tempDir = null;
// try {
// // 创建临时目录
// tempDir = Files.createTempDirectory("sftp_download_temp");
//
// // 列出远程目录中的所有文件`
// Vector<?> filesList = sftp.ls(remotePath);
//
// List<Path> downloadedFiles = new ArrayList<>();
// for (Object obj : filesList) {
// ChannelSftp.LsEntry entry = (ChannelSftp.LsEntry) obj;
// String filename = entry.getFilename();
// if (filename.contains(filenamePattern)) {
// Path localFilePath = tempDir.resolve(filename);
// downloadFile(remotePath, filename, localFilePath.toString());
// downloadedFiles.add(localFilePath);
// }
// }
//
// // 打包下载的文件到ZIP文件
// FileUtils.createZipFile(downloadedFiles, localZipPath);
// success = true;
// logger.info("成功接收文件并打包到ZIP文件: " + localZipPath);
// } catch (Exception e) {
// logger.error("下载或打包文件时发生异常!", e);
// } finally {
// try {
// // 删除临时目录及其内容
// if (tempDir != null) {
// FileUtils.cleanup(tempDir);
// }
// disconnect();
// } catch (IOException e) {
// logger.error("删除临时目录时出错!", e);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// return success;
// }
public boolean downloadAndZipFiles(String remotePath, String filenamePattern, String localZipPath) {
boolean success = false;
Path tempDir = null;
try {
// 创建临时目录
tempDir = Files.createTempDirectory("sftp_download_temp");
// 列出远程目录中的所有文件`
// 列出远程目录中的所有文件
Vector<?> filesList = sftp.ls(remotePath);
List<Path> downloadedFiles = new ArrayList<>();
......@@ -295,13 +336,24 @@ public class SFTPUtil {
downloadedFiles.add(localFilePath);
}
}
disconnect();
// 确保本地ZIP路径的父目录存在
Path localZipFilePath = Paths.get(localZipPath);
Path parentDir = localZipFilePath.getParent();
if (parentDir != null && !Files.exists(parentDir)) {
Files.createDirectories(parentDir);
}
// 打包下载的文件到ZIP文件
FileUtils.createZipFile(downloadedFiles, localZipPath);
FileUtils.createZipFile(downloadedFiles, localZipPath);
success = true;
logger.info("成功接收文件并打包到ZIP文件: " + localZipPath);
} catch (SftpException e) {
logger.error("下载文件时发生异常!", e);
} catch (IOException e) {
logger.error("处理文件或创建目录时发生异常!", e);
} catch (Exception e) {
logger.error("下载或打包文件时发生异常!", e);
logger.error("其他异常!", e);
} finally {
try {
// 删除临时目录及其内容
......@@ -317,8 +369,6 @@ public class SFTPUtil {
}
return success;
}
/**
* 上传文件至远程sftp服务器
*
......
......@@ -180,7 +180,7 @@ public class IcbcWithholdController extends BaseController {
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "GET",value = " 聚富通代扣信息回盘文件获取", notes = " 聚富通代扣信息回盘文件获取")
@GetMapping(value = "/downLoadicbcFile")
public ResponseModel<String> downLoadicbcFile( Long sequenceNbr,String batchNo,HttpServletResponse response ) throws Exception {
public ResponseModel downLoadicbcFile( Long sequenceNbr,String batchNo,HttpServletResponse response ) throws Exception {
icbcWithholdServiceImpl.downLoadicbcFile(batchNo,sequenceNbr,response);
return ResponseHelper.buildResponse(null);
}
......@@ -192,9 +192,9 @@ public class IcbcWithholdController extends BaseController {
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "GET",value = " 聚富通代扣信息回盘文件获取", notes = " 聚富通代扣信息回盘文件获取")
@GetMapping(value = "/updateWithholdStatus")
public ResponseModel updateWithholdStatus( ) throws Exception {
public void updateWithholdStatus( ) throws Exception {
icbcWithholdServiceImpl.updateWithholdStatus();
return CommonResponseNewUtil.success();
}
/**
......
......@@ -328,7 +328,7 @@ public class IcbcWithholdServiceImpl extends BaseService<IcbcWithholdDto,IcbcWit
this.downloadAndSaveZipFile(model.getReceiptFile(),batchNo,"回盘文件",response);
}
String path = new ClassPathResource(file+"secretKey/login-gxjrid_rsa").getPath();
String path = new ClassPathResource(file+"secretKey/登录-gxjrid_rsa").getPath();
SFTPUtil sftp = new SFTPUtil(sftpIp, sftpPort,
sftpUserName,
path, null);
......@@ -340,6 +340,19 @@ public class IcbcWithholdServiceImpl extends BaseService<IcbcWithholdDto,IcbcWit
sftp.priKeyConnect();
Path currentWorkingDir = Paths.get("");
Path dirPath = currentWorkingDir.resolve(batchNo);
try {
if (!Files.exists(dirPath)) {
Files.createDirectories(dirPath);
System.out.println("Directory created: " + dirPath);
} else {
System.out.println("Directory already exists: " + dirPath);
}
} catch (IOException e) {
e.printStackTrace();
System.err.println("Failed to create directory: " + dirPath);
}
System.out.println("Current working directory: " + System.getProperty("user.dir"));
if (sftp.isExist(downLoadPath)) {
sftp.downloadAndZipFiles(downLoadPath,batchNo,dirPath.toString()+"/"+batchNo+".zip");
logger.info("文件下载成功");
......@@ -500,12 +513,11 @@ public class IcbcWithholdServiceImpl extends BaseService<IcbcWithholdDto,IcbcWit
public void upIcbcWithholdRecordWithholdStatus() {
LambdaQueryWrapper<IcbcWithhold> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(IcbcWithhold::getUploadStatus,UploadStatusEnum.成功.getCode());
wrapper.eq(IcbcWithhold::getWithholdStatus,UploadStatusEnum.代扣处理中.getCode());
List<String> batchNos = this.getBaseMapper().selectList(wrapper).stream()
.map(IcbcWithhold::getBatchNo)
.collect(Collectors.toList());;
LambdaQueryWrapper<IcbcWithholdRecord> wrapper = new LambdaQueryWrapper<>();
wrapper.isNull(IcbcWithholdRecord::getWithholdStatus);
Set<String> batchNos = icbcWithholdRecordService.getBaseMapper().selectList(wrapper).stream()
.map(IcbcWithholdRecord::getBatchNo)
.collect(Collectors.toSet());;
String APP_ID = "11000000000000028870";
String MY_PRIVATE_KEY = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDAlcIeANdqipul3/qAIRlknSacHiFCMzLzUJisGcr9ipm3p2rir8WDsac2MxgtUt+f89SGNoWyjv4q0/QAKQQTd5U3KuGAksCJLBGVibuFe7G7YGYVezUksjvocvp8GIinCIkzq67KL2SOpGXAu3s+282rx8AxdTZA/EhXQvbORbWz5+DamyY+wS7Maa8KmIOb6WZPtiXgENZxDHAafrqW8Gt1BnVfJNf5yS5J9Wl+LcR1EPvi5iH8dSIdn1ZMVupoREjV/DvItSogVehsqTRZWuekAo2xH9YEli1UMG/l3deViRn/A4VmPPzdv0xXpn/yO+OTjWez+KmSmJfAZXBvAgMBAAECggEABRYviWFWTz8X+1qeIDI/nHO2KFt3X2tAxkJztd/8h5PYmYw3e4NPATp5Ayp4UgIlW/ExxNW91EiImBL/F939eJIpA8sDJ8U4hqb+U+fOZyksOZnDOIAHmE+I24vl588yFM9Z6F55gGeeDVJ0SZHqIG/nz8i339aLt02yj3N6V1peQugBP6L9arcD+gVu4F70whkqW+lHBK/WzX1OazqEx3Ip175jqzi9/0vO/h/kqnGGXuMi2VeuAPsa+d0a6lf/FScxqCt3t6dCkJ5DPA1MCj81dPi5ZfCM/vE0N8I6LEV+RyC7bb4YVO/PoicFjb2j8vfLvldOUrsvkNH51dZusQKBgQDpMHacOBpIuVzEFfNtS9SgA96cUV6NCSmHoQppJ/p9xKzY4DpcqoOCIBT4WCvVe6PeN5mrjzt8Q5gJWxiq0tVgIF9k8GjLmuiJ2v4Qh8aUmlRwn0T0DYiX/Y7uzX+pRlkpoKrSktlTOT9vmGwZDGDk0h2+H3hZ3YQEucfA6bhHmQKBgQDTbHrbr1WsUR9lrdLaGi/Uphpl3BXLuCnJXav3yIZOktO5V68MfPZXLP7aaNtbK3n0YHD+Uv8wpHBBSWQYjVYlGdvlniA/W1pr73GZJECFfS1BmmFC4GG3E92D5IkmrcPlUuz8XxKrlwHnfW1F0MoDvhp930vS0tS6u+WYTt9dRwKBgCeEQPVkRIACeYf5OFFTQmsDfNv8pgs8fD8xuTPsxHQ/uhLenMVLWBHbIfKb7oG0/CYSQgZitW/vfHpJZ7q7E9HAaqoOW5P1YmbKJ7fhanOQW7LiKqs5B+bJ30j0piendkCpq4kXvaBu2SMuL1NnV5wvRz8K0jhYY6DxYrp8YPAxAoGAZxWTaZ25tgTvvBHeprzx6Ur7wAJpFiU7KpVjjbLV2WW5mbro/LvJGIQ11qQdn/w4wDBtp3MsPblPimWQSnBPOlO7Zd+NdZbDJbFfv/1vACcic8Qj/AmPW0ZyUSaSwKskwqGGLx7j6Yn9QbNkHhBJDz4XiJvhSm/FjS6kKXj7a20CgYEArnEiPmL5g1Ca/qKK9ql8Q6P9gipIfGGpaFu23y0trbcFpVn8Oos/ic0Jgw4Xiz+rqvb6bW2V6lqBJ+9/kdn0i7zlZxKNpYsW2xFgi04OU3d5HkGL16Y1rpqMYYEhjFaOIn7J8P046UYR99yaybgQd18TE6oFrX8OL5uY8M4ge4Y=";
String icbcPulicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCMpjaWjngB4E3ATh+G1DVAmQnIpiPEFAEDqRfNGAVvvH35yDetqewKi0l7OEceTMN1C6NPym3zStvSoQayjYV+eIcZERkx31KhtFu9clZKgRTyPjdKMIth/wBtPKjL/5+PYalLdomM4ONthrPgnkN4x4R0+D4+EBpXo8gNiAFsNwIDAQAB";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment