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

修改签章

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