Commit 7f9033a8 authored by 吴琼's avatar 吴琼

修改签章

parent 337d76ae
...@@ -25,20 +25,20 @@ public interface TransactionReceiptRecordRepo extends JpaRepository<TransactionR ...@@ -25,20 +25,20 @@ public interface TransactionReceiptRecordRepo extends JpaRepository<TransactionR
@Query(value = "select * from transaction_receipt_record where order_no = ?1 and user_id =?2 and user_name =?3 and import_status != 2 and export_status = 0 ", nativeQuery = true) @Query(value = "select * from transaction_receipt_record where order_no = ?1 and user_id =?2 and user_name =?3 and import_status != 2 and export_status = 0 ", nativeQuery = true)
List<TransactionReceiptRecord> selectRecordsByOrderNo(String orderNo,Integer userId,String userName); List<TransactionReceiptRecord> selectRecordsByOrderNo(String orderNo,Integer userId,String userName);
@Query(value = "select * from transaction_receipt_record where import_status = ?1 and export_status != 1", nativeQuery = true) @Query(value = "select * from transaction_receipt_record where import_status = ?1 and export_status != 1 limit ?2 ", nativeQuery = true)
List<TransactionReceiptRecord> selectRecordsByImportStatusAndExportStatus(Integer status); List<TransactionReceiptRecord> selectRecordsByImportStatusAndExportStatus(Integer status,Integer limit);
@Query(value = "select count(1) from transaction_receipt_record where import_status =?1 ", nativeQuery = true) @Query(value = "select count(1) from transaction_receipt_record where import_status =?1 ", nativeQuery = true)
Long selectCountByImportStatus(Integer status); Long selectCountByImportStatus(Integer status);
@Modifying @Modifying
@Transactional @Transactional
@Query(value = "update transaction_receipt_record set import_status = ?1 where order_no =?2 and import_status = 0 ", nativeQuery = true) @Query(value = "update transaction_receipt_record set import_status = ?1 where import_status = 0 and order_no =?2 ", nativeQuery = true)
int updateTransactionStatusByImportStatus(Integer status,String orderNo); int updateTransactionStatusByImportStatus(Integer status,String orderNo);
@Modifying @Modifying
@Transactional @Transactional
@Query(value = "update transaction_receipt_record set sign_status = ?1,export_status = ?2 where order_no =?3 and import_status = 1 and export_status = 0 ", nativeQuery = true) @Query(value = "update transaction_receipt_record set sign_status =?1 ,export_status =?2 where order_no =?3 and import_status = 1 and export_status = 0 ", nativeQuery = true)
int updatePDFStatusByOrderNo(Integer status,Integer exportStatus,String orderNo); int updatePDFStatusByOrderNo(Integer status,Integer exportStatus,String orderNo);
} }
...@@ -95,17 +95,4 @@ public class TransactionReceiptRecordRest { ...@@ -95,17 +95,4 @@ public class TransactionReceiptRecordRest {
} }
//pdf签章后回调接口更新pdf是否签章成功
@RequestMapping("/orderQuery/updateSignStatus")
@ResponseBody
public JsonResult updateSignStatus(@RequestBody TransactionReceiptRecordQuery query) {
try{
return transactionReceiptRecordService.updatePDFSignStatus(query.getSuccessList(),query.getFailList());
}catch(Exception e){
e.printStackTrace();
return JsonResult.buildErrorStateResult("更新签章状态失败");
}
}
} }
...@@ -22,8 +22,6 @@ public interface ITransactionReceiptRecordService { ...@@ -22,8 +22,6 @@ public interface ITransactionReceiptRecordService {
JsonResult updateTransactionRecordsStatus(); JsonResult updateTransactionRecordsStatus();
JsonResult updatePDFSignStatus(List<String> sucessList, List<String>failList);
void generatePDF(TransactionReceiptVO transactionReceiptVO, String filePath); void generatePDF(TransactionReceiptVO transactionReceiptVO, String filePath);
} }
...@@ -96,6 +96,9 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR ...@@ -96,6 +96,9 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
private String downloadLocalPath; private String downloadLocalPath;
@Value("${customer.transaction.local.file.size}") @Value("${customer.transaction.local.file.size}")
private int fileSize; private int fileSize;
//导出最多条数
@Value("${customer.transaction.local.file.limit}")
private int limit;
@Override @Override
...@@ -160,9 +163,9 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR ...@@ -160,9 +163,9 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
if(CollectionUtils.isEmpty(readList)){ if(CollectionUtils.isEmpty(readList)){
throw new RuntimeException("文件中没有数据"); throw new RuntimeException("文件中没有数据");
} }
/*if(readList !=null && readList.size() > fileSize){ if(readList !=null && readList.size() > fileSize){
throw new RuntimeException("文件太大,最多可以读取"+fileSize+"条数据!"); throw new RuntimeException("文件太大,最多可以读取"+fileSize+"条数据!");
}*/ }
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException("读取数据异常"); throw new RuntimeException("读取数据异常");
} }
...@@ -282,7 +285,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR ...@@ -282,7 +285,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
//调用电商接口获取对应数据 //调用电商接口获取对应数据
log.info("[TransactionReceiptRecordServiceImpl.exportZipFile begin]"); log.info("[TransactionReceiptRecordServiceImpl.exportZipFile begin]");
//查询需要导出的数据-导入成功的数据,但未导出成功的数据 //查询需要导出的数据-导入成功的数据,但未导出成功的数据
List<TransactionReceiptRecord> transactionReceiptRecordList= transactionReceiptRecordRepo.selectRecordsByImportStatusAndExportStatus(1); List<TransactionReceiptRecord> transactionReceiptRecordList= transactionReceiptRecordRepo.selectRecordsByImportStatusAndExportStatus(1,limit);
log.info("[TransactionReceiptRecordServiceImpl.exportZipFile transactionReceiptRecordList]",transactionReceiptRecordList); log.info("[TransactionReceiptRecordServiceImpl.exportZipFile transactionReceiptRecordList]",transactionReceiptRecordList);
if(CollectionUtils.isEmpty(transactionReceiptRecordList)){ if(CollectionUtils.isEmpty(transactionReceiptRecordList)){
return JsonResult.buildErrorStateResult("没有可以导出得数据"); return JsonResult.buildErrorStateResult("没有可以导出得数据");
...@@ -360,7 +363,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR ...@@ -360,7 +363,7 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
//将文件路径和useId放入list,进行签章 //将文件路径和useId放入list,进行签章
Map<String,Object> map =Maps.newHashMap(); Map<String,Object> map =Maps.newHashMap();
map.put("userId",record.getUserId()); map.put("userId",record.getUserId());
map.put("fileAddress",basePath+maxExportBatchNo+"/交易凭证/"+directory+"/"+pdfFileName); map.put("fileAddress",maxExportBatchNo+"/交易凭证/"+directory+"/"+pdfFileName);
filePathList.add(map); filePathList.add(map);
} }
} catch (Exception e) { } catch (Exception e) {
...@@ -369,48 +372,61 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR ...@@ -369,48 +372,61 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
} }
} }
sftpUtil.logout(); sftpUtil.logout();
log.info("uploadFile | 断开ftp");
log.info("[TransactionReceiptRecordServiceImpl.kdspOperationUrl 调用kdsp-op 接口end]",System.currentTimeMillis()); log.info("[TransactionReceiptRecordServiceImpl.kdspOperationUrl 调用kdsp-op 接口end]",System.currentTimeMillis());
//上传文件
//调用签章接口 //调用签章接口
/* String url = contractUrl + "/contract/batch/sign"; log.info("contractUrl /contract/batch/sign 调用签章接口");
String url = contractUrl + "/contract/batch/sign";
Map<String, String> header = Maps.newHashMap(); Map<String, String> header = Maps.newHashMap();
header.put("Content-type", "application/json"); header.put("Content-type", "application/json");
Map param = Maps.newHashMap(); String contractResult = httpService.post(url, header, filePathList);
if (CollectionUtils.isNotEmpty(filePathList)) {
param.put("fileList", filePathList);
}
String contractResult = httpService.post(url, header, param);
JSONObject json = JSONObject.parseObject(contractResult); JSONObject json = JSONObject.parseObject(contractResult);
String jsonResult = json.getString("data"); String jsonResult = json.getString("data");
String businessCode = json.getString("businessCode");*/ String businessCode = json.getString("businessCode");
//下载签章文件 if(!"0000".equals(businessCode)){
throw new RuntimeException("签章失败!");
log.info("downloadFile | 成功连接ftp"); }
for(Map<String,Object> map :filePathList){ JSONObject jsonObject = JSONObject.parseObject(jsonResult);
SFTPUtil sftpUtil1 = new SFTPUtil(username,password,host,port); JSONArray jsonArray = jsonObject.getJSONArray("successList");
sftpUtil1.login(); List<String> updateSuccessList = new ArrayList<>();
String filepath = (String) map.get("fileAddress"); if(jsonArray != null && jsonArray.size()>0){
int totallength =filepath.length(); for(int i= 0;i <jsonArray.size() ;i++){
//byte[] bytes = sftpUtil1.download("/lzshopkf/transaction/交易凭证/1张三/","1498571250795298816.pdf"); String path = (String) jsonArray.get(i);
//getFile(bytes,downloadLocalPath+"交易凭证/1张三","1498571250795298816.pdf");//downloadLocalPath=D:/tmp1/ SFTPUtil sftpUtil1 = new SFTPUtil(username,password,host,port);
int length = filepath.lastIndexOf("/"); sftpUtil1.login();
String fileName =filepath.substring(length+1,totallength); String filepath = basePath + path.substring(1);
filepath =filepath.substring(0,length+1); int totalLength =filepath.length();
byte[] bytes = sftpUtil1.download(filepath,fileName); int length = filepath.lastIndexOf("/");
String subPath = filepath.substring(0,filepath.length()-1); String fileName =filepath.substring(length+1,totalLength);
int length2 = subPath.lastIndexOf("/"); updateSuccessList.add(fileName.substring(0,fileName.indexOf(".")));
String directory = subPath.substring(length2+1,subPath.length()); filepath =filepath.substring(0,length+1);
FileToZip.mkdir(downloadLocalPath+"/"+directory); byte[] bytes = sftpUtil1.download(filepath,fileName);
getFile(bytes,downloadLocalPath+"/"+directory,fileName); String subPath = filepath.substring(0,filepath.length()-1);
sftpUtil1.logout(); int length2 = subPath.lastIndexOf("/");
String directory = subPath.substring(length2+1,subPath.length());
FileToZip.mkdir(downloadLocalPath+"/"+directory);
getFile(bytes,downloadLocalPath+"/"+directory,fileName);
sftpUtil1.logout();
}
}else{
sftpUtil.logout();
throw new RuntimeException("签章失败!");
} }
//byte[] bytes = sftpUtil.download("/lzshopkf/transaction/交易凭证/1张三","",username,password,host,port); //更新数据
//getFile(bytes,"D:/0301/交易凭证/1张三","1498571250795298816.pdf"); JSONArray failList = jsonObject.getJSONArray("failList");
List<String> updateFailList = new ArrayList<>();
if(failList !=null && failList.size()>0){
for(int i= 0;i <jsonArray.size() ;i++){
String path = (String) jsonArray.get(i);
//String path = "/6/jiaoyipingzheng/zhangsan/1496386728293023744.pdf";
int begin = path.lastIndexOf("/")+1;
int end = path.indexOf(".");
path =path.substring(begin,end);
updateFailList.add(path);
//转换成zip包 }
//FileToZip.mkdir("D:/0301/交易凭证"); }
//File file = ZipUtil.zip("D:/0301/交易凭证", "D:/0301/交易凭证"+".zip");//zip 包保存路径 updatePDFSignStatus(updateSuccessList,updateFailList);
//FileToZip.mkdir(downloadLocalPath);
File file = ZipUtil.zip(downloadLocalPath, downloadLocalPath+".zip");//zip 包保存路径 File file = ZipUtil.zip(downloadLocalPath, downloadLocalPath+".zip");//zip 包保存路径
FileInputStream is = null; FileInputStream is = null;
try { try {
...@@ -418,8 +434,10 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR ...@@ -418,8 +434,10 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
byte[] fileData = IOUtils.readNBytes(is, is.available()); byte[] fileData = IOUtils.readNBytes(is, is.available());
Map<String,Object> map = new HashMap<>(); Map<String,Object> map = new HashMap<>();
map.put("base64",Base64.getEncoder().encodeToString(fileData)); map.put("base64",Base64.getEncoder().encodeToString(fileData));
map.put("successCount",100); int successCount = (int) jsonObject.get("successCount");
map.put("failCount",20); int failCount = (int) jsonObject.get("failCount");
map.put("successCount",successCount);
map.put("failCount",failCount);
return JsonResult.buildSuccessResult("ok",map); return JsonResult.buildSuccessResult("ok",map);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("文件转换失败"); throw new RuntimeException("文件转换失败");
...@@ -574,21 +592,26 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR ...@@ -574,21 +592,26 @@ public class TransactionReceiptRecordServiceImpl implements ITransactionReceiptR
return JsonResult.buildSuccessResult("数据导入成功",null); return JsonResult.buildSuccessResult("数据导入成功",null);
} }
@Override /**
public JsonResult updatePDFSignStatus(List<String> sucessList,List<String>failList) { * 更新数据状态
* @param successList
* @param failList
*/
public void updatePDFSignStatus(List<String> successList,List<String>failList) {
//pdf签章成功 //pdf签章成功
if(!sucessList.isEmpty()){ if(!successList.isEmpty()){
for(String orderNo :sucessList){ for(String orderNo :successList){
transactionReceiptRecordRepo.updatePDFStatusByOrderNo(1,1,orderNo); int i = transactionReceiptRecordRepo.updatePDFStatusByOrderNo(1,1,orderNo);
System.out.println(i);
} }
} }
//pdf签章失败 //pdf签章失败
if(!failList.isEmpty()){ if(!failList.isEmpty()){
for(String orderNo :failList){ for(String orderNo :failList){
transactionReceiptRecordRepo.updatePDFStatusByOrderNo(2,2,orderNo); int i = transactionReceiptRecordRepo.updatePDFStatusByOrderNo(2,2,orderNo);
//System.out.println(i);
} }
} }
return JsonResult.buildSuccessResult("pdf签章状态更新失败",null);
} }
/** /**
......
...@@ -71,7 +71,7 @@ public class SFTPUtil { ...@@ -71,7 +71,7 @@ public class SFTPUtil {
// chSftp = (ChannelSftp) channel; // chSftp = (ChannelSftp) channel;
this.sftp = (ChannelSftp)channel; this.sftp = (ChannelSftp)channel;
f.set(sftp, 2); f.set(sftp, 2);
sftp.setFilenameEncoding("GBK"); sftp.setFilenameEncoding("utf-8");
this.logger.info("pwd = [{}]", this.sftp.pwd()); this.logger.info("pwd = [{}]", this.sftp.pwd());
} catch (JSchException var4) { } catch (JSchException var4) {
var4.printStackTrace(); var4.printStackTrace();
......
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