Commit 29e4e994 authored by 李健华's avatar 李健华

交易凭证修改

parent 852729b1
......@@ -35,6 +35,9 @@ public class TransactionReceiptRecord {
@Column(name = "order_no")
private String orderNo;
@Column(name = "order_id")
private String orderId;
@Column(name = "batch_no")
private Integer batchNo =0;
......
package cn.quantgroup.customer.rest.vo.transaction;
import lombok.Data;
@Data
public class LoanVO {
/**
* 合同号
*/
private String contractNo;
/**
* 贷字
*/
private String loanNo;
}
......@@ -22,4 +22,9 @@ public class TransactionReceiptVO {
* 物流信息
*/
private ReceiverVO receiver;
/**
* 贷款信息
*/
private List<LoanVO> loanList;
}
......@@ -3,6 +3,7 @@ package cn.quantgroup.customer.service.impl;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ZipUtil;
import cn.quantgroup.customer.entity.TransactionReceiptRecord;
import cn.quantgroup.customer.rest.enums.VoucherExportStatus;
import cn.quantgroup.customer.rest.param.mail.SendMailParam;
import cn.quantgroup.customer.rest.vo.transaction.TransactionReceiptRecordVO;
import cn.quantgroup.customer.repo.TransactionReceiptRecordRepo;
......@@ -236,13 +237,13 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
if(record.getUserId() ==null || record.getUserId() ==0
|| StringUtils.isEmpty(record.getUserName())
|| StringUtils.isEmpty(record.getOrderNo())){
record.setImportStatus(2);
record.setImportStatus(VoucherExportStatus.EXPORT_FAIL.getCode());
//默认导出失败
record.setExportStatus(2);
record.setExportStatus(VoucherExportStatus.EXPORT_FAIL.getCode());
}else{
record.setImportStatus(0);
record.setImportStatus(VoucherExportStatus.INIT.getCode());
//默认导出初始状态
record.setExportStatus(0);
record.setExportStatus(VoucherExportStatus.INIT.getCode());
}
//存储批次号
record.setBatchNo(maxBatchNo.intValue()+1);
......@@ -318,6 +319,8 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
record.setUserName(cellValue);
}else if(c == 4){
record.setOrderNo(cellValue);
} else if (c == 5) {
record.setOrderId(cellValue);
}
}
recordList.add(record);
......@@ -334,7 +337,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
log.info("[TransactionReceiptRecordServiceImpl.exportZipFile begin]");
//查询需要导出的数据-导入成功的数据,但未导出成功的数据
String accessToken = request.getHeader("Access-Token");
List<TransactionReceiptRecord> transactionReceiptRecordList= transactionReceiptRecordRepo.selectRecordsByImportStatusAndExportStatus(1,limit);
List<TransactionReceiptRecord> transactionReceiptRecordList= transactionReceiptRecordRepo.selectRecordsByImportStatusAndExportStatus(VoucherExportStatus.EXPORT_SUCCESS.getCode(), limit);
log.info("[TransactionReceiptRecordServiceImpl.exportZipFile transactionReceiptRecordList] 可导出数据为:",transactionReceiptRecordList.size());
if(CollectionUtils.isEmpty(transactionReceiptRecordList)){
deleteRedis("exportZipFile");
......@@ -342,7 +345,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
throw new RuntimeException("没有可以导出得数据");
}
//查询导入成功数据的导出的最大批次号
Integer maxExportBatchNo = transactionReceiptRecordRepo.findExportMaxBatchNo(1);
Integer maxExportBatchNo = transactionReceiptRecordRepo.findExportMaxBatchNo(VoucherExportStatus.EXPORT_SUCCESS.getCode());
if(maxExportBatchNo == null || maxExportBatchNo ==0 ){
maxExportBatchNo = 1;
}
......@@ -352,12 +355,12 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
SFTPUtil sftpUtil = new SFTPUtil(username,password,host,port);
sftpUtil.login();
log.info("uploadFile | 成功连接ftp");
String url = kdspOperationUrl + "/api/kdsp/op/fa-cui/transaction-proof/query";
for(TransactionReceiptRecord record : transactionReceiptRecordList){
Integer userId = record.getUserId();
String orderNo = record.getOrderNo();
String orderId = record.getOrderId();
//调用kdsp接口获取交易凭证订单信息
String url = kdspOperationUrl + "/api/kdsp/op/fa-cui/transaction-proof/query";
//String url = "http://kdsp-operation-test7.liangkebang.net/api/kdsp/op/fa-cui/transaction-proof/query";
try {
Map<String, String> header = Maps.newHashMap();
header.put("Content-type", "application/json");
......@@ -369,6 +372,9 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
if (StringUtils.isNotBlank(orderNo)) {
param.put("orderNo", orderNo);
}
if (StringUtils.isNotBlank(orderId)) {
param.put("consumeNo", orderId);
}
List<Map> paramList =new ArrayList<>();
paramList.add(param);
//得到json字符串
......@@ -385,7 +391,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
//查询报错
if(!"0000".equals(businessCode)){
//导出失败,跳过
record.setExportStatus(2);
record.setExportStatus(VoucherExportStatus.EXPORT_FAIL.getCode());
transactionReceiptRecordRepo.save(record);
continue;
}
......@@ -394,24 +400,32 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
JSONArray jsonArray = jsonObject.getJSONArray("dataList");
if(jsonArray.isEmpty()){
//导出失败,跳过
record.setExportStatus(2);
record.setExportStatus(VoucherExportStatus.EXPORT_FAIL.getCode());
transactionReceiptRecordRepo.save(record);
continue;
}
List<TransactionReceiptVO> transactionReceiptVOList = jsonArray.toJavaList(TransactionReceiptVO.class);
if(transactionReceiptVOList.isEmpty()){
//导出失败,跳过
record.setExportStatus(2);
record.setExportStatus(VoucherExportStatus.EXPORT_FAIL.getCode());
transactionReceiptRecordRepo.save(record);
continue;
}
TransactionReceiptVO vo = transactionReceiptVOList.get(0);
if(vo.getLogisticsList().size() <= 5) {
// 物流信息异常
record.setExportStatus(VoucherExportStatus.EXPORT_WARN.getCode());
transactionReceiptRecordRepo.save(record);
continue;
}
record.setExportBatchNo(maxExportBatchNo);
//生成pdf
String directory =record.getSerialNo()+record.getUserName();
String pdfFileName = record.getUserId()+"-"+record.getUserName()+"-"+record.getOrderNo()+".pdf";
FileToZip.mkdir(uploadLocalPath+directory);
log.info("导出文件生成pdf begin:"+pdfFileName);
generatePDF(transactionReceiptVOList.get(0),uploadLocalPath+"/"+directory+"/"+pdfFileName);
generatePDF(vo,uploadLocalPath+"/"+directory+"/"+pdfFileName);
log.info("导出文件生成pdf end:"+pdfFileName);
File file1 = new File(uploadLocalPath+"/"+directory+"/"+pdfFileName);
InputStream inputStream = new FileInputStream(file1);
......@@ -444,56 +458,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
throw new RuntimeException("没有签章成功的文件可以发送");
}
//将文件分批放入本地
/* log.info("下载签章完成的文件 begin");
int subListSize = 0;
if(CollectionUtils.isNotEmpty(emailList)){
List<List<Map<String,Object>>> subList= splitList(emailList,mailSize);
subListSize = subList.size();
for(int i =0;i<subList.size();i++){
List<Map<String,Object>>list =subList.get(i);
for(Map<String,Object> map:list){
String filePath = (String) map.get("filePath");
String fileName = (String) map.get("fileName");
SFTPUtil sftpUtil1 = new SFTPUtil(username,password,host,port);
sftpUtil1.login();
byte[] bytes = sftpUtil1.download(filePath,fileName);
String subPath = filePath.substring(0,filePath.length()-1);
int length2 = subPath.lastIndexOf("/");
String directory = subPath.substring(length2+1,subPath.length());
FileToZip.mkdir(downloadLocalPath+"/"+i+"/"+directory);
getFile(bytes,downloadLocalPath+"/"+i+"/"+directory,fileName);
sftpUtil1.logout();
}
}
}
log.info("下载签章完成的文件 end");
log.info("分批发送邮件 begin");
try {
for(int i=0;i<subListSize;i++){
File zipFile = ZipUtil.zip(downloadLocalPath+"\\"+i, downloadLocalPath+"\\"+i+".zip");
FileInputStream is = new FileInputStream(zipFile);
InputStreamResource InputStreamResource =new InputStreamResource(is);
sendCustomerTransactionMail(InputStreamResource);
}
} catch (Exception e) {
deleteRedis("exportZipFile");
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
log.info("邮件发送失败");
throw new RuntimeException("邮件发送失败");
}finally{
//log.info("删除暂存的文件 begin");
//int upload = uploadLocalPath.lastIndexOf("/");
//File deleteFile =new File(uploadLocalPath.substring(0,upload-4));
//deleteDirectory(deleteFile);
//int download = downloadLocalPath.lastIndexOf("/");
//File deleteFile1 =new File(downloadLocalPath.substring(0,download+1));
//deleteDirectory(deleteFile1);
//log.info("删除暂存的文件 end");
deleteRedis("exportZipFile");
log.info("分批发送邮件end");
}
log.info("分批发送邮件成功end");*/
//发送邮件通知已经处理完成
log.info("[TransactionReceiptRecordServiceImpl.sendCustomerTransactionHtmlMail 发送邮件begin]");
sendCustomerTransactionHtmlMail(transactionReceiptRecordList.size(),emailList.size(),transactionReceiptRecordList.size()-emailList.size());
......@@ -664,40 +629,13 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
log.error("TransactionReceiptRecordServiceImpl updateTransactionRecordsStatus 校验更新数据 begin");
//查询所有初始化的数据
List<TransactionReceiptRecord> transactionReceiptRecordList
= transactionReceiptRecordRepo.selectRecordsByImportStatus(0);
= transactionReceiptRecordRepo.selectRecordsByImportStatus(VoucherExportStatus.INIT.getCode());
//没有校验成功的放入一个list
List<TransactionReceiptRecord> failList = new ArrayList<>();
List<TransactionReceiptRecord> successList = new ArrayList<>();
if(CollectionUtils.isNotEmpty(transactionReceiptRecordList)){
for(TransactionReceiptRecord record :transactionReceiptRecordList){
try{
//调用天津自牧用户中心接口
// Map param = Maps.newHashMap();
// param.put("userIds",record.getUserId());
// String userUrl = userSysUrl + "/api/sync/listByUserIds";
// //String userUrl = "http://passportapi-test7.liangkebang.net/api/sync/listByUserIds";
// log.info("TransactionReceiptRecordServiceImpl updateTransactionRecordsStatus 调用用户中心 begin"+param);
// String userResult = httpService.get(userUrl, param);
// log.info("TransactionReceiptRecordServiceImpl userResult ="+userResult);
// if (StringUtils.isEmpty(userResult)) {
// record.setImportStatus(2);
// record.setExportStatus(2);
// failList.add(record);
// continue;
// }
// //对比拿到的
// JSONObject userJsonObject = JSONObject.parseObject(userResult);
// String dataStr = userJsonObject.getString("data");
// JSONArray userArray = JSONArray.parseArray(dataStr);
// if(userArray.size()<=0){
// record.setImportStatus(2);
// record.setExportStatus(2);
// failList.add(record);
// continue;
// }
// JSONObject object= (JSONObject) userArray.get(0);
// String userName = object.getString("name");
// log.info("TransactionReceiptRecordServiceImpl updateTransactionRecordsStatus 调用用户中心 end");
log.info("TransactionReceiptRecordServiceImpl updateTransactionRecordsStatus 调用商城接口 begin");
if(StringUtils.isNotBlank(record.getUserName())){
Map<String, String> header = Maps.newHashMap();
......@@ -727,17 +665,17 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
JSONObject kJsonObject = JSONObject.parseObject(kJsonResult);
List<TransactionReceiptRecord> errorList = (List<TransactionReceiptRecord>) kJsonObject.get("verifyErrorList");
if(errorList.size()>0){
record.setImportStatus(2);
record.setExportStatus(2);
record.setImportStatus(VoucherExportStatus.EXPORT_FAIL.getCode());
record.setExportStatus(VoucherExportStatus.EXPORT_FAIL.getCode());
failList.add(record);
continue;
}
}
record.setImportStatus(1);
record.setImportStatus(VoucherExportStatus.EXPORT_SUCCESS.getCode());
successList.add(record);
}else{
record.setImportStatus(2);
record.setExportStatus(2);
record.setImportStatus(VoucherExportStatus.EXPORT_FAIL.getCode());
record.setExportStatus(VoucherExportStatus.EXPORT_FAIL.getCode());
failList.add(record);
}
}catch(Exception e){
......@@ -747,10 +685,10 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
}
//校验全部通过则更新状态
for(TransactionReceiptRecord record :failList){
transactionReceiptRecordRepo.updateTransactionStatusByImportStatus(2,record.getOrderNo());
transactionReceiptRecordRepo.updateTransactionStatusByImportStatus(VoucherExportStatus.EXPORT_FAIL.getCode(), record.getOrderNo());
}
for(TransactionReceiptRecord record :successList){
transactionReceiptRecordRepo.updateTransactionStatusByImportStatus(1,record.getOrderNo());
transactionReceiptRecordRepo.updateTransactionStatusByImportStatus(VoucherExportStatus.EXPORT_SUCCESS.getCode(), record.getOrderNo());
}
log.error("TransactionReceiptRecordServiceImpl updateTransactionRecordsStatus 校验更新数据 end");
}
......@@ -830,6 +768,8 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
ReceiverVO receiverVO =transactionReceiptVO.getReceiver();
//物流信息
List<LogisticsVO> logisticsVOList = transactionReceiptVO.getLogisticsList();
// 贷款信息
List<LoanVO> loanVOList = transactionReceiptVO.getLoanList();
log.info("generatePDF 开始生成pdf begin",LOG_PRE,filePath);
Document document = new Document(PageSize.A4);
try {
......@@ -896,6 +836,21 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
//展示一个
table=generateMultiParagraph(cell,font,table,logisticsVOList,skuVOList,receiverVO,0);
}
//贷款信息
cell = new PdfPCell(new Phrase(ITextPDFUtil.getUTF8String("贷款信息"), font));
cell.setColspan(6);
cell.setMinimumHeight(18);
table.addCell(cell);
//贷款信息详情
table.addCell(new Phrase(ITextPDFUtil.getUTF8String("合同编号"), font));
cell = new PdfPCell(new Phrase(ITextPDFUtil.getUTF8String("贷字"), font));
cell.setColspan(5);
cell.setMinimumHeight(18);
table.addCell(cell);
for (LoanVO loanVO : loanVOList) {
table.addCell(new PdfPCell(new Phrase(ITextPDFUtil.getUTF8String(StringUtils.isEmpty(loanVO.getContractNo())?"":loanVO.getContractNo()), font))).setMinimumHeight(18);
table.addCell(new PdfPCell(new Phrase(ITextPDFUtil.getUTF8String(StringUtils.isEmpty(loanVO.getLoanNo())?"/":loanVO.getLoanNo()), font))).setMinimumHeight(18);
}
log.info("generatePDF 开始生成pdf end",LOG_PRE,table.getBody());
document.add(table);
document.close();
......
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