Commit dae5a1a3 authored by LSL's avatar LSL

浙农中际融担协议

parent 71df628e
package com.jqtx.windows.job;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.extra.ssh.Sftp;
import com.jqtx.infrastructure.oss.starter.config.OssUtils;
import com.jqtx.windows.common.config.SftpConfig;
import com.jqtx.windows.component.impl.LoanComponentImpl;
import com.jqtx.windows.component.model.LoanModel;
import com.jqtx.windows.component.model.UploadPdfDetailRequest;
import com.jqtx.windows.component.model.UploadPdfRequest;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
@Component
@Slf4j
public class ContractJob {
/**
* oss的路径
*/
private static final String ossPath = "ZN/contract/";
/**
* sftp的路径
*/
private static final String sftpPath = "/upload/contract/";
/**
* sftp文件后缀
*/
private static final String suffix = "jkfwxy";
@Autowired
private OssUtils ossUtils;
@Autowired
private LoanComponentImpl loanComponent;
@Autowired
private SftpConfig sftpConfig;
@Value("${inf.oss.privateDomain}")
private String privateDomain;
@XxlJob("redeemJob")
public void run() {
String param = XxlJobHelper.getJobParam();
Sftp sftp = new Sftp(sftpConfig.getSshHost(), sftpConfig.getSshPort(), sftpConfig.getSshUser(), sftpConfig.getSshPass(), CharsetUtil.CHARSET_UTF_8);
try {
String date = "";
if (StringUtils.isNotEmpty(param)) {
date = param;
} else {
Calendar cal = Calendar.getInstance();
//获取前面的时间用-负号
cal.setTime(new Date());
cal.add(Calendar.DAY_OF_MONTH, -1);
Date time = cal.getTime();
date = DateUtil.format(time, "yyyyMMdd");
}
String dir = sftpPath + date;
if (sftp.isDir(dir)) {
List<String> list = sftp.lsDirs(dir);
for (String loanNo : list) {
uploadProtocolPdf(loanNo, sftp, dir);
}
}
} catch (Exception e) {
log.info("浙农同步中际融担协议错误:{}", e.getMessage());
} finally {
//关闭sftp连接
sftp.close();
}
}
public void uploadProtocolPdf(String loanNo, Sftp sftp, String dir) {
List<String> list = sftp.lsFiles(dir + "/" + loanNo);
for (String fileName : list) {
//只拿以 jkfwxy.pdf 结尾的文件
if (fileName.indexOf(suffix) != -1) {
String url = getUrl(dir + "/" + fileName, sftp, fileName);
getUploadPdfRequest(url, loanNo);
}
}
}
public String getUrl(String dir, Sftp sftp, String fileName) {
sftp.get(dir, fileName);
ossUtils.ossUpload(ossPath + fileName, FileUtil.file("/" + fileName));
FileUtil.del("/" + fileName);
return privateDomain + ossPath + fileName;
}
public UploadPdfRequest getUploadPdfRequest(String url, String loanNo) {
LoanModel loanModel = loanComponent.getByLoanNo(loanNo);
UploadPdfRequest uploadPdfRequest = new UploadPdfRequest();
uploadPdfRequest.setLoanNo(loanModel.getLoanNo());
uploadPdfRequest.setOrderNo(loanModel.getOrderNo());
UploadPdfDetailRequest uploadPdfDetailRequest = new UploadPdfDetailRequest();
uploadPdfDetailRequest.setUrl(url);
ArrayList<UploadPdfDetailRequest> list = new ArrayList<>();
list.add(uploadPdfDetailRequest);
uploadPdfRequest.setDetailRequestList(list);
return uploadPdfRequest;
}
}
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