From e0f5d5f5ea200de9eb0847a1f387acd7a08d4cab Mon Sep 17 00:00:00 2001 From: lvleigang <957075182@qq.com> Date: Mon, 7 Apr 2025 11:13:17 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=B8=AD=E5=8F=B0=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base-buildpackage/src/test/java/com/hzya/frame/temButtom.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/base-buildpackage/src/test/java/com/hzya/frame/temButtom.java b/base-buildpackage/src/test/java/com/hzya/frame/temButtom.java index e26d6d1c..a332bb96 100644 --- a/base-buildpackage/src/test/java/com/hzya/frame/temButtom.java +++ b/base-buildpackage/src/test/java/com/hzya/frame/temButtom.java @@ -172,6 +172,9 @@ public class temButtom { JSONObject queryParams = new JSONObject(); queryParams.put("page",1); queryParams.put("size",50); + //queryParams.put("kprqq","2025-04-06"); + //queryParams.put("kprqz","2025-04-06"); + queryParams.put("taxNo","91330110MAC5FPUY2U"); dayabody.put("queryParams",queryParams); Map parametersMap = new HashMap<>(); parametersMap.put("accessKey","6X3B526P5HqE6ums"); From e243a78e22d5f8b203a72c90c2385886257bb85d Mon Sep 17 00:00:00 2001 From: lvleigang <957075182@qq.com> Date: Wed, 9 Apr 2025 15:27:27 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index b252f4db..eb7f9414 100644 --- a/.gitignore +++ b/.gitignore @@ -53,6 +53,7 @@ $RECYCLE.BIN/ # Windows shortcuts *.lnk ./idea/ +/.idea/ /buildpackage/src/main/resources/banner.txt /webapp/target/ /service/target/ @@ -66,3 +67,4 @@ $RECYCLE.BIN/ /base-webapp/target/classes/com/hzya/frame/ /fw-weixin/target/ /E:/yongansystem/log/2024-10-15/ +/D:/ From d748cf982533f176010600e56d4933bf4280df5c Mon Sep 17 00:00:00 2001 From: hecan <1718492867@qq.com> Date: Thu, 10 Apr 2025 12:19:24 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E7=94=B3=E8=AF=B7?= =?UTF-8?q?=E5=8D=95=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application-ht.yml | 8 ++ .../src/main/resources/application.yml | 2 +- .../seeyon/invoice/entity/InvoiceState.java | 44 ++++++ .../service/impl/InvoiceServiceImpl.java | 91 ++++++++++++- .../service/impl/ZxBankServiceImpl.java | 127 +++++++++--------- 5 files changed, 210 insertions(+), 62 deletions(-) create mode 100644 fw-oa/src/main/java/com/hzya/frame/seeyon/invoice/entity/InvoiceState.java diff --git a/base-buildpackage/src/main/resources/application-ht.yml b/base-buildpackage/src/main/resources/application-ht.yml index 85d1b848..e56d9538 100644 --- a/base-buildpackage/src/main/resources/application-ht.yml +++ b/base-buildpackage/src/main/resources/application-ht.yml @@ -40,6 +40,14 @@ OA: data_source_code: yc_oa zt: url: http://127.0.0.1:9999/kangarooDataCenterV3/entranceController/externalCallInterface +file_oa: + url: http://127.0.0.1:9999/kangarooDataCenterV3/entranceController/externalCallInterfacefileUpload +#税务pdf附件下载存放路径 +invoice_pdf: + url: D:\yongansystem\invoice\pdf\ +#税务ofd附件下载存放路径 +invoice_ofd: + url: D:\yongansystem\invoice\ofd\ zx: # 测试用这个 这个是银行给的 privateKey: MIGTAgEAMBMGByqGSM49AgEGCCqBHM9VAYItBHkwdwIBAQQgtzMo2o6THK3yLIm+83Ch/560+02l2hjjBSFGieWY/Z6gCgYIKoEcz1UBgi2hRANCAATKhwZX4P3XI8vYTKeCOLMVbanUNbaXjrIEZynshwdOzRVgzRQSiPNWo6OBBkAPvqE+2RS+5ABpS82DSlKl81z0 diff --git a/base-buildpackage/src/main/resources/application.yml b/base-buildpackage/src/main/resources/application.yml index b87e5bf7..a0bbeaae 100644 --- a/base-buildpackage/src/main/resources/application.yml +++ b/base-buildpackage/src/main/resources/application.yml @@ -1,5 +1,5 @@ server: - port: 10086 + port: 9999 servlet: context-path: /kangarooDataCenterV3 localIP: 127.0.0.1 diff --git a/fw-oa/src/main/java/com/hzya/frame/seeyon/invoice/entity/InvoiceState.java b/fw-oa/src/main/java/com/hzya/frame/seeyon/invoice/entity/InvoiceState.java new file mode 100644 index 00000000..38a119ba --- /dev/null +++ b/fw-oa/src/main/java/com/hzya/frame/seeyon/invoice/entity/InvoiceState.java @@ -0,0 +1,44 @@ +package com.hzya.frame.seeyon.invoice.entity; + +import com.hzya.frame.seeyon.zxbank.entity.PayState; + +public enum InvoiceState { + zero("0","申请单被关闭"), + one("1","申请单开票成功"), + two("2","申请单处理中"), + three("3","申请单开具异常"); + + private String type; + //值 + private String value; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + InvoiceState(String type, String value){ + this.type=type; + this.value=value; + } + + public static String invoiceStateGetValue(String type){ + for (InvoiceState invoiceState : InvoiceState.values()){ + if(invoiceState.getType()==type||invoiceState.getType().equals(type)){ + return invoiceState.getValue().toString(); + } + } + return null; + } +} diff --git a/fw-oa/src/main/java/com/hzya/frame/seeyon/invoice/service/impl/InvoiceServiceImpl.java b/fw-oa/src/main/java/com/hzya/frame/seeyon/invoice/service/impl/InvoiceServiceImpl.java index f27b78c5..d176df54 100644 --- a/fw-oa/src/main/java/com/hzya/frame/seeyon/invoice/service/impl/InvoiceServiceImpl.java +++ b/fw-oa/src/main/java/com/hzya/frame/seeyon/invoice/service/impl/InvoiceServiceImpl.java @@ -10,6 +10,7 @@ import com.hzya.frame.mdm.mdmModuleSource.entity.MdmModuleSourceEntity; import com.hzya.frame.seeyon.invoice.dao.IInvoiceDao; import com.hzya.frame.seeyon.invoice.dao.IInvoiceDetailsDao; import com.hzya.frame.seeyon.invoice.entity.InvoiceEntity; +import com.hzya.frame.seeyon.invoice.entity.InvoiceState; import com.hzya.frame.seeyon.invoice.service.IInvoiceService; import com.hzya.frame.seeyon.util.YzfSignUtil; import com.hzya.frame.seeyon.zxbank.entity.ZxBankEntity; @@ -24,6 +25,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import java.io.File; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.URL; import java.util.*; @Service(value = "InvoiceServiceImpl") @@ -44,6 +50,11 @@ public class InvoiceServiceImpl extends BaseService imple @Value("${zt.url}") private String url; + @Value("${invoice_pdf.url}") + private String invoicePdfUrl; + @Value("${invoice_ofd.url}") + private String invoiceOfdUrl; + @Override public JsonResultEntity queryArchives(JSONObject json) { JSONObject jsonObject = json.getJSONObject("jsonStr"); @@ -108,7 +119,7 @@ public class InvoiceServiceImpl extends BaseService imple parametersMap.put("timestamp",timestamp); String sign = YzfSignUtil.signRequest(parametersMap,"34e5fc32ac894a2ba2ade8c3852c7a0a"); JSONObject jsonObject=new JSONObject(); - jsonObject.put("serialNumber",entity.getBusiness_no()); + jsonObject.put("serialNumber",entity.getId()); jsonObject.put("accessKey","6X3B526P5HqE6ums"); jsonObject.put("sign",sign); jsonObject.put("timestamp",timestamp); @@ -123,6 +134,43 @@ public class InvoiceServiceImpl extends BaseService imple execute(). body(); logger.info("=====调用杭泰税务查询申请单详情的返回参数为:{}===========",result); + JSONObject resultJson = JSONObject.parseObject(result); + if (!resultJson.getBoolean("flag")) { + saveTaskLivingDetails(entity.getId(), entity.getBusiness_no(), jsonObject.toJSONString(), resultJson.toJSONString(), false,""); + } else { + JSONObject attribute = resultJson.getJSONObject("attribute"); + if("0".equals(attribute.getString("code"))){ + JSONObject jsonResult=JSONObject.parseObject(attribute.getString("result")); + if(null !=jsonResult){ + JSONArray jsonArray = jsonResult.getJSONArray("invoiceInfoVOList"); + if(CollectionUtils.isNotEmpty(jsonArray)){ + for (int i = 0; i < jsonArray.size(); i++) { + JSONObject invoiceInfo = jsonArray.getJSONObject(i); + String invoiceCode = invoiceInfo.getString("invoiceCode");//发票代码 + String invoiceNumber = invoiceInfo.getString("invoiceNumber");//发票号码 + String resultStatus = InvoiceState.invoiceStateGetValue(jsonResult.getString("resultStatus"));//开票结果 + String pdfUrl = invoiceInfo.getString("url");//pdf文件 + String ofdUrl = invoiceInfo.getString("ofdUrl");//ofd文件 + String xmlUrl = invoiceInfo.getString("xmlUrl");//xml文件 + //获取pdf文件到本地 并为pdf取名,否则会报无法访问错误 + logger.info("========开始将pdf文件保存到本地========"); + String pdfFileName = generateFileName(pdfUrl,"pdf"); + String pdfSavePath=invoicePdfUrl+pdfFileName; + downloadPdf(pdfUrl,pdfSavePath); + logger.info("========pdf文件保存到本地完成========"); + File filePdf=new File(pdfSavePath); + //获取ofd文件到本地 + logger.info("========开始将ofd文件保存到本地========"); + String ofdFileName = generateFileName(ofdUrl, "ofd"); + String ofdSavePath = ofdUrl + ofdFileName; + downloadPdf(ofdUrl,ofdSavePath); + logger.info("========ofd文件保存到本地完成========"); + File fileOfd=new File(ofdSavePath); + } + } + } + } + } } }catch (Exception e){ @@ -132,6 +180,47 @@ public class InvoiceServiceImpl extends BaseService imple return null; } + private void downloadPdf(String pdfUrl, String savePath) { + try { + URL url = new URL(pdfUrl); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("Post"); + int responseCode = connection.getResponseCode(); + if (responseCode == HttpURLConnection.HTTP_OK) { + InputStream inputStream = connection.getInputStream(); + FileOutputStream outputStream = new FileOutputStream(savePath); + + byte[] buffer = new byte[4096]; + int bytesRead; + while ((bytesRead = inputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, bytesRead); + } + + outputStream.close(); + inputStream.close(); + } else { + logger.info("下载失败,响应码: {}" , responseCode); + } + connection.disconnect(); + }catch (Exception e){ + logger.info("====查询申请单详情获取税务pdf或ofd文件失败:{}========",e.getMessage()); + e.printStackTrace(); + } + } + + private String generateFileName(String url, String extension) { + // 这里简单根据 URL 的参数生成文件名,你可以根据实际需求调整 + String[] parts = url.split("&"); + String fphm = ""; + for (String part : parts) { + if (part.startsWith("fphm=")) { + fphm = part.substring(5); + break; + } + } + return fphm + "." + extension; + } + private List bindingInvoice(JSONObject jsonObject, MdmModuleSourceEntity mdmModuleSourceEntity, String dbCode) { List list = new ArrayList<>(); StringBuffer stringBuffer = new StringBuffer(); diff --git a/fw-oa/src/main/java/com/hzya/frame/seeyon/zxbank/service/impl/ZxBankServiceImpl.java b/fw-oa/src/main/java/com/hzya/frame/seeyon/zxbank/service/impl/ZxBankServiceImpl.java index 6be14686..6646129b 100644 --- a/fw-oa/src/main/java/com/hzya/frame/seeyon/zxbank/service/impl/ZxBankServiceImpl.java +++ b/fw-oa/src/main/java/com/hzya/frame/seeyon/zxbank/service/impl/ZxBankServiceImpl.java @@ -42,6 +42,7 @@ import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; @@ -66,6 +67,7 @@ public class ZxBankServiceImpl extends BaseService impleme @Value("${zt.url}") private String url; + @Value("${zx.privateKey}") private String privateKey; @@ -349,56 +351,57 @@ public class ZxBankServiceImpl extends BaseService impleme } if (sourceFolder.isFile() && sourceFolder.getName().endsWith(".zip")) { - unzipFile(sourceFolder.getAbsolutePath(), destinationFolder); - - //将pdf文件上传OA - File fileOut = new File(sourceFolder.getAbsolutePath()); - if (fileOut.exists()) { - logger.info("=====开始上传中信司库回单到杭泰OA======"); - JSONObject jsonObject = fileUpload(fileOut); - if (jsonObject.getString("fileUrl") != null) { - //表单的附件字段=ctpAttachment的Sub_reference,表单的Summary_id=ctpAttachment的att_reference - String sub_reference = String.valueOf(UUIDLong.longUUID()); - zxBankEntity.setReceipt(sub_reference); - zxBankEntity.setDataSourceCode("HT-OA"); - zxBankDao.updateElecStatusZX(zxBankEntity); - //根据附件id查询附件业务数据 - String file_url = jsonObject.getString("fileUrl"); - CtpAttachmentEntity ctpAttachmentEntity = new CtpAttachmentEntity(); - ctpAttachmentEntity.setFile_url(file_url); - String att_reference = zxBankEntity.getSummaryId();//Summary_id - ctpAttachmentEntity.setSub_reference(sub_reference); - ctpAttachmentEntity.setAtt_reference(att_reference); - ctpAttachmentEntity.setDataSourceCode("HT-OA"); - List ctpAttachmentEntities = ctpAttachmentDao.queryCtpAttachment(ctpAttachmentEntity); - //如果没有查询到数据,就新增附件业务,否则更新 - if (ctpAttachmentEntities.size() == 0) { - String category = jsonObject.getString("category"); - String type = jsonObject.getString("type"); - String filename = jsonObject.getString("filename"); - String mime_type = jsonObject.getString("mimeType"); - String attachment_size = jsonObject.getString("size"); - String id = String.valueOf(UUIDLong.longUUID()); - ctpAttachmentEntity.setCategory(category); - ctpAttachmentEntity.setFilename(filename); - ctpAttachmentEntity.setType(type); - ctpAttachmentEntity.setMime_type(mime_type); - ctpAttachmentEntity.setAttachment_size(attachment_size); - ctpAttachmentEntity.setId(id); - ctpAttachmentEntity.setCategory("66"); - ctpAttachmentEntity.setCreatedate(new Date()); + List files = unzipFile(sourceFolder.getAbsolutePath(), destinationFolder); + // 上传 PDF 文件 + for (File pdfFile : files) { + logger.info("pdf文件名称为:{}",pdfFile.getName()); + if (pdfFile.exists()) { + logger.info("=====开始上传中信司库回单到杭泰OA======"); + JSONObject jsonObject = fileUpload(pdfFile); + if (jsonObject.getString("fileUrl") != null) { + //表单的附件字段=ctpAttachment的Sub_reference,表单的Summary_id=ctpAttachment的att_reference + String sub_reference = String.valueOf(UUIDLong.longUUID()); + zxBankEntity.setReceipt(sub_reference); + zxBankEntity.setDataSourceCode("HT-OA"); + zxBankDao.updateElecStatusZX(zxBankEntity); + //根据附件id查询附件业务数据 + String file_url = jsonObject.getString("fileUrl"); + CtpAttachmentEntity ctpAttachmentEntity = new CtpAttachmentEntity(); + ctpAttachmentEntity.setFile_url(file_url); + String att_reference = zxBankEntity.getSummaryId();//Summary_id + ctpAttachmentEntity.setSub_reference(sub_reference); + ctpAttachmentEntity.setAtt_reference(att_reference); ctpAttachmentEntity.setDataSourceCode("HT-OA"); - ctpAttachmentDao.saveCtpAttachment(ctpAttachmentEntity); - } else { - if (ctpAttachmentEntities.size() > 1) { - throw new BaseSystemException("OA附件业务表中查到多条记录"); + List ctpAttachmentEntities = ctpAttachmentDao.queryCtpAttachment(ctpAttachmentEntity); + //如果没有查询到数据,就新增附件业务,否则更新 + if (ctpAttachmentEntities.size() == 0) { + String category = jsonObject.getString("category"); + String type = jsonObject.getString("type"); + String filename = jsonObject.getString("filename"); + String mime_type = jsonObject.getString("mimeType"); + String attachment_size = jsonObject.getString("size"); + String id = String.valueOf(UUIDLong.longUUID()); + ctpAttachmentEntity.setCategory(category); + ctpAttachmentEntity.setFilename(filename); + ctpAttachmentEntity.setType(type); + ctpAttachmentEntity.setMime_type(mime_type); + ctpAttachmentEntity.setAttachment_size(attachment_size); + ctpAttachmentEntity.setId(id); + ctpAttachmentEntity.setCategory("66"); + ctpAttachmentEntity.setCreatedate(new Date()); + ctpAttachmentEntity.setDataSourceCode("HT-OA"); + ctpAttachmentDao.saveCtpAttachment(ctpAttachmentEntity); + } else { + if (ctpAttachmentEntities.size() > 1) { + throw new BaseSystemException("OA附件业务表中查到多条记录"); + } + //更新数据到OA附件业务表中 + ctpAttachmentDao.updateCtpAttachment(ctpAttachmentEntity); } - //更新数据到OA附件业务表中 - ctpAttachmentDao.updateCtpAttachment(ctpAttachmentEntity); + logger.info("=====电子回单执行完毕======="); } - logger.info("=====电子回单执行完毕======="); + pdfFile.delete(); } - fileOut.delete(); } } } @@ -469,29 +472,33 @@ public class ZxBankServiceImpl extends BaseService impleme return "unknown.zip"; } - private void unzipFile(String zipFilePath, String destinationFolderPath) { - try (FileInputStream fis = new FileInputStream(zipFilePath); - ZipInputStream zis = new ZipInputStream(fis)) { - - ZipEntry zipEntry = zis.getNextEntry(); - while (zipEntry != null) { - if (zipEntry.getName().endsWith(".pdf")) { - String pdfFilePath = destinationFolderPath + zipEntry.getName();//File.separator:文件路径中增加一个斜杠 - try (FileOutputStream fos = new FileOutputStream(pdfFilePath)) { + private List unzipFile(String zipFilePath, String destinationFolderPath) { + List pdfFiles = new ArrayList<>(); + try (ZipFile zipFile = new ZipFile(zipFilePath)) { + Enumeration entries = zipFile.entries(); + while (entries.hasMoreElements()) { + ZipEntry entry = entries.nextElement(); + File outputFile = new File(destinationFolderPath, entry.getName()); + if (entry.isDirectory()) { + outputFile.mkdirs(); + } else { + try (InputStream inputStream = zipFile.getInputStream(entry); + OutputStream outputStream = new FileOutputStream(outputFile)) { byte[] buffer = new byte[4096]; int bytesRead; - while ((bytesRead = zis.read(buffer)) != -1) { - fos.write(buffer, 0, bytesRead); + while ((bytesRead = inputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, bytesRead); } } - logger.info("已提取 PDF 文件:{} " ,pdfFilePath); + if (outputFile.getName().endsWith(".pdf")) { + pdfFiles.add(outputFile); + } } - zis.closeEntry(); - zipEntry = zis.getNextEntry(); } } catch (IOException e) { e.printStackTrace(); } + return pdfFiles; }