From b78b44e8af3d246128ddbcaabe07d74898d1459b Mon Sep 17 00:00:00 2001 From: kk <1910333201@qq.com> Date: Fri, 24 Nov 2023 13:58:34 +0800 Subject: [PATCH] =?UTF-8?q?=E9=93=B6=E8=A1=8C=E8=B4=A6=E5=8F=B7=E3=80=81?= =?UTF-8?q?=E5=90=8D=E7=A7=B0=E6=8B=86=E5=88=86=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../http/invoice/v1/InvoiceController.java | 11 ++- .../jianshui/common/utils/IdcardUtils.java | 35 +++++++ .../AisinoInvoiceRequestAdapterImpl.java | 97 ++++++++++++++----- .../Nuonuo2InvoiceRequestAdapterImpl.java | 8 +- 4 files changed, 126 insertions(+), 25 deletions(-) diff --git a/jianshui-admin/src/main/java/com/jianshui/api/controller/http/invoice/v1/InvoiceController.java b/jianshui-admin/src/main/java/com/jianshui/api/controller/http/invoice/v1/InvoiceController.java index 2d55b66..9202a2d 100644 --- a/jianshui-admin/src/main/java/com/jianshui/api/controller/http/invoice/v1/InvoiceController.java +++ b/jianshui-admin/src/main/java/com/jianshui/api/controller/http/invoice/v1/InvoiceController.java @@ -620,7 +620,16 @@ public class InvoiceController { useAisino = true; } - HXResponse result = preHandleDecryptResult(decryptResult, "batch_print", companyservice); +// HXResponse result = preHandleDecryptResult(decryptResult, "batch_print", companyservice); + PrintDTO billInfo = decryptResult.toJavaObject(PrintDTO.class); + if (billInfo == null) { + throw new JianshuiParamErrorException(ErrorCode.ERROR_PARAMS, companyservice, "invoice"); + } + // 获得请求实例,并且进行扣费 + String serviceKey = serviceManageService.getCompanyServiceSupplier("invoice", companyservice.getCompanyid()); + serviceManageService.companyConsume("invoice", companyservice.getCompanyid()); + IInvoiceApiService invoiceService = invoiceServiceFactory.getService(serviceKey); + HXResponse result = invoiceService.batchPrint(billInfo, companyservice); String responseAdapterKey = serviceManageService.getResponseAdapterKey("invoice", companyservice.getCompanyid()); IInvoiceResponseService invoiceResponseService = null; diff --git a/jianshui-common/src/main/java/com/jianshui/common/utils/IdcardUtils.java b/jianshui-common/src/main/java/com/jianshui/common/utils/IdcardUtils.java index effa1f3..6e53dbd 100644 --- a/jianshui-common/src/main/java/com/jianshui/common/utils/IdcardUtils.java +++ b/jianshui-common/src/main/java/com/jianshui/common/utils/IdcardUtils.java @@ -3,7 +3,11 @@ package com.jianshui.common.utils; import cn.hutool.core.util.ReUtil; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * @Description 身份证工具类 @@ -104,4 +108,35 @@ public class IdcardUtils { return ""; } + /** 解析银行账号-名称*/ + public static Map getBankNoAndName(String input){ + Map resultMap = new HashMap<>(); + + String regex = "(\\p{InCJK_Unified_Ideographs})|(\\d+)"; + + Pattern pattern = Pattern.compile(regex); + Matcher matcher = pattern.matcher(input); + + StringBuilder chineseBuilder = new StringBuilder(); + StringBuilder numberBuilder = new StringBuilder(); + + while (matcher.find()) { + String match = matcher.group(); + if (match.matches("\\p{InCJK_Unified_Ideographs}")) { + chineseBuilder.append(match); + } else { + numberBuilder.append(match); + } + } + + String chinese = chineseBuilder.toString().replaceAll("\\s", ""); + String numbers = numberBuilder.toString().replaceAll("\\s", ""); + + resultMap.put("bankNo", numbers); + resultMap.put("bankName", chinese); + + return resultMap; + } + + } diff --git a/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/adapter/request/AisinoInvoiceRequestAdapterImpl.java b/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/adapter/request/AisinoInvoiceRequestAdapterImpl.java index c53a435..5665e06 100644 --- a/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/adapter/request/AisinoInvoiceRequestAdapterImpl.java +++ b/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/adapter/request/AisinoInvoiceRequestAdapterImpl.java @@ -140,7 +140,7 @@ public class AisinoInvoiceRequestAdapterImpl implements IInvoiceRequestService { // throw new JianshuiParamErrorException(ErrorCode.IDENTITY_NOT_MATCH,"invoice); // } // 红字查询 - if (StringUtils.equals(serviceKey,"find_redinfo")){ + if (StringUtils.equals(serviceKey, "find_redinfo")) { return json; } // 如果是开票或者查询 @@ -149,17 +149,27 @@ public class AisinoInvoiceRequestAdapterImpl implements IInvoiceRequestService { HxBillInfoDTO hxBillInfo = json.toJavaObject(HxBillInfoDTO.class); BillInfo billInfo = new BillInfo(); BeanUtils.copyProperties(hxBillInfo, billInfo); - if(StringUtils.isNotEmpty(hxBillInfo.getEmail())){ + if (StringUtils.isNotEmpty(hxBillInfo.getEmail())) { billInfo.setBuyerEmail(hxBillInfo.getEmail()); } - if (StringUtils.isEmpty(billInfo.getBuyerBank()) && StringUtils.isNotEmpty(billInfo.getBuyerAccount())) { + + // TODO: 2023/11/24 银行处理 + /*if (StringUtils.isEmpty(billInfo.getBuyerBank()) && StringUtils.isNotEmpty(billInfo.getBuyerAccount())) { String bankNo = IdcardUtils.getBankNo(billInfo.getBuyerAccount()); if (StringUtils.isNotEmpty(bankNo)) { String raw = billInfo.getBuyerAccount(); billInfo.setBuyerAccount(bankNo); billInfo.setBuyerBank(raw.replace(bankNo, "")); } + }*/ + // 银行处理 + if (StringUtils.isEmpty(billInfo.getBuyerBank()) && StringUtils.isNotEmpty(billInfo.getBuyerAccount())) { + Map bank = IdcardUtils.getBankNoAndName(billInfo.getBuyerAccount()); + billInfo.setBuyerAccount(bank.getOrDefault("bankNo", "")); + billInfo.setBuyerBank(bank.getOrDefault("bankName", "")); } + + // 处理detail List hxBillDetailList = hxBillInfo.getDetail(); List detailList = new ArrayList<>(); @@ -172,13 +182,19 @@ public class AisinoInvoiceRequestAdapterImpl implements IInvoiceRequestService { billInfo.setBillDetailList(detailList); } - if (StringUtils.isEmpty(billInfo.getBuyerBank()) && StringUtils.isNotEmpty(billInfo.getBuyerAccount())) { + /*if (StringUtils.isEmpty(billInfo.getBuyerBank()) && StringUtils.isNotEmpty(billInfo.getBuyerAccount())) { String bankNo = IdcardUtils.getBankNo(billInfo.getBuyerAccount()); if (StringUtils.isNotEmpty(bankNo)) { String raw = billInfo.getBuyerAccount(); billInfo.setBuyerAccount(bankNo); billInfo.setBuyerBank(raw.replace(bankNo, "")); } + }*/ + // 银行处理 + if (StringUtils.isEmpty(billInfo.getBuyerBank()) && StringUtils.isNotEmpty(billInfo.getBuyerAccount())) { + Map bank = IdcardUtils.getBankNoAndName(billInfo.getBuyerAccount()); + billInfo.setBuyerAccount(bank.getOrDefault("bankNo", "")); + billInfo.setBuyerBank(bank.getOrDefault("bankName", "")); } // 处理销方信息 if (StringUtils.isEmpty(billInfo.getSellerBank()) && StringUtils.isNotEmpty(billInfo.getSellerAccount())) { @@ -193,7 +209,7 @@ public class AisinoInvoiceRequestAdapterImpl implements IInvoiceRequestService { json = (JSONObject) JSONObject.toJSON(billInfo); } - if (StringUtils.equals(serviceKey, "addBatch") ) { + if (StringUtils.equals(serviceKey, "addBatch")) { JSONArray billInfoList = JSONUtil.parseArray(json.get("billInfo")); JSONArray billInfoResult = new JSONArray(); for (Object billInfoTemp : billInfoList) { @@ -203,16 +219,22 @@ public class AisinoInvoiceRequestAdapterImpl implements IInvoiceRequestService { HxBillInfoDTO hxBillInfo = orderJsonTemp.toJavaObject(HxBillInfoDTO.class); BillInfo billInfo = new BillInfo(); BeanUtils.copyProperties(hxBillInfo, billInfo); - if(StringUtils.isNotEmpty(hxBillInfo.getEmail())){ + if (StringUtils.isNotEmpty(hxBillInfo.getEmail())) { billInfo.setBuyerEmail(hxBillInfo.getEmail()); } - if (StringUtils.isEmpty(billInfo.getBuyerBank()) && StringUtils.isNotEmpty(billInfo.getBuyerAccount())) { + /*if (StringUtils.isEmpty(billInfo.getBuyerBank()) && StringUtils.isNotEmpty(billInfo.getBuyerAccount())) { String bankNo = IdcardUtils.getBankNo(billInfo.getBuyerAccount()); if (StringUtils.isNotEmpty(bankNo)) { String raw = billInfo.getBuyerAccount(); billInfo.setBuyerAccount(bankNo); billInfo.setBuyerBank(raw.replace(bankNo, "")); } + }*/ + // 银行处理 + if (StringUtils.isEmpty(billInfo.getBuyerBank()) && StringUtils.isNotEmpty(billInfo.getBuyerAccount())) { + Map bank = IdcardUtils.getBankNoAndName(billInfo.getBuyerAccount()); + billInfo.setBuyerAccount(bank.getOrDefault("bankNo", "")); + billInfo.setBuyerBank(bank.getOrDefault("bankName", "")); } // 处理detail List hxBillDetailList = hxBillInfo.getDetail(); @@ -226,13 +248,19 @@ public class AisinoInvoiceRequestAdapterImpl implements IInvoiceRequestService { billInfo.setBillDetailList(detailList); } - if (StringUtils.isEmpty(billInfo.getBuyerBank()) && StringUtils.isNotEmpty(billInfo.getBuyerAccount())) { + /*if (StringUtils.isEmpty(billInfo.getBuyerBank()) && StringUtils.isNotEmpty(billInfo.getBuyerAccount())) { String bankNo = IdcardUtils.getBankNo(billInfo.getBuyerAccount()); if (StringUtils.isNotEmpty(bankNo)) { String raw = billInfo.getBuyerAccount(); billInfo.setBuyerAccount(bankNo); billInfo.setBuyerBank(raw.replace(bankNo, "")); } + }*/ + // 银行处理 + if (StringUtils.isEmpty(billInfo.getBuyerBank()) && StringUtils.isNotEmpty(billInfo.getBuyerAccount())) { + Map bank = IdcardUtils.getBankNoAndName(billInfo.getBuyerAccount()); + billInfo.setBuyerAccount(bank.getOrDefault("bankNo", "")); + billInfo.setBuyerBank(bank.getOrDefault("bankName", "")); } // 处理销方信息 if (StringUtils.isEmpty(billInfo.getSellerBank()) && StringUtils.isNotEmpty(billInfo.getSellerAccount())) { @@ -249,7 +277,7 @@ public class AisinoInvoiceRequestAdapterImpl implements IInvoiceRequestService { } // 清除数据,重新组装 json.clear(); - json.put("billInfo",billInfoResult); + json.put("billInfo", billInfoResult); } @@ -265,7 +293,7 @@ public class AisinoInvoiceRequestAdapterImpl implements IInvoiceRequestService { List hxBillDetailList = hxBillInfo.getRedinfodetailList(); List detailList = new ArrayList<>(); - if(CollectionUtil.isNotEmpty(hxBillDetailList)){ + if (CollectionUtil.isNotEmpty(hxBillDetailList)) { for (int i = 0; i < hxBillDetailList.size(); i++) { HxRedInfoDetailsDTO detial = hxBillDetailList.get(i); Redinfodetail temp = new Redinfodetail(); @@ -313,10 +341,10 @@ public class AisinoInvoiceRequestAdapterImpl implements IInvoiceRequestService { } @Override - public JSONObject decryptZq(String identity,String order, Companyservice companyservice, String serviceKey) { + public JSONObject decryptZq(String identity, String order, Companyservice companyservice, String serviceKey) { - log.info("【航信转invoice请求适配器】客户请求报文原始数据:{},销方id:{},serviceKey:{},identity={}", order, companyservice.getCompanyid(), serviceKey,identity); + log.info("【航信转invoice请求适配器】客户请求报文原始数据:{},销方id:{},serviceKey:{},identity={}", order, companyservice.getCompanyid(), serviceKey, identity); // 开始解析报文 if (order == null || "".equals(order.trim())) { @@ -356,7 +384,7 @@ public class AisinoInvoiceRequestAdapterImpl implements IInvoiceRequestService { json = orderJson; // 红字查询 - if (StringUtils.equals(serviceKey,"find_redinfo")){ + if (StringUtils.equals(serviceKey, "find_redinfo")) { return json; } // 如果是开票或者查询 @@ -365,16 +393,22 @@ public class AisinoInvoiceRequestAdapterImpl implements IInvoiceRequestService { HxBillInfoDTO hxBillInfo = json.toJavaObject(HxBillInfoDTO.class); BillInfo billInfo = new BillInfo(); BeanUtils.copyProperties(hxBillInfo, billInfo); - if(StringUtils.isNotEmpty(hxBillInfo.getEmail())){ + if (StringUtils.isNotEmpty(hxBillInfo.getEmail())) { billInfo.setBuyerEmail(hxBillInfo.getEmail()); } - if (StringUtils.isEmpty(billInfo.getBuyerBank()) && StringUtils.isNotEmpty(billInfo.getBuyerAccount())) { + /*if (StringUtils.isEmpty(billInfo.getBuyerBank()) && StringUtils.isNotEmpty(billInfo.getBuyerAccount())) { String bankNo = IdcardUtils.getBankNo(billInfo.getBuyerAccount()); if (StringUtils.isNotEmpty(bankNo)) { String raw = billInfo.getBuyerAccount(); billInfo.setBuyerAccount(bankNo); billInfo.setBuyerBank(raw.replace(bankNo, "")); } + }*/ + // 银行处理 + if (StringUtils.isEmpty(billInfo.getBuyerBank()) && StringUtils.isNotEmpty(billInfo.getBuyerAccount())) { + Map bank = IdcardUtils.getBankNoAndName(billInfo.getBuyerAccount()); + billInfo.setBuyerAccount(bank.getOrDefault("bankNo", "")); + billInfo.setBuyerBank(bank.getOrDefault("bankName", "")); } // 处理detail List hxBillDetailList = hxBillInfo.getDetail(); @@ -388,13 +422,19 @@ public class AisinoInvoiceRequestAdapterImpl implements IInvoiceRequestService { billInfo.setBillDetailList(detailList); } - if (StringUtils.isEmpty(billInfo.getBuyerBank()) && StringUtils.isNotEmpty(billInfo.getBuyerAccount())) { + /*if (StringUtils.isEmpty(billInfo.getBuyerBank()) && StringUtils.isNotEmpty(billInfo.getBuyerAccount())) { String bankNo = IdcardUtils.getBankNo(billInfo.getBuyerAccount()); if (StringUtils.isNotEmpty(bankNo)) { String raw = billInfo.getBuyerAccount(); billInfo.setBuyerAccount(bankNo); billInfo.setBuyerBank(raw.replace(bankNo, "")); } + }*/ + // 银行处理 + if (StringUtils.isEmpty(billInfo.getBuyerBank()) && StringUtils.isNotEmpty(billInfo.getBuyerAccount())) { + Map bank = IdcardUtils.getBankNoAndName(billInfo.getBuyerAccount()); + billInfo.setBuyerAccount(bank.getOrDefault("bankNo", "")); + billInfo.setBuyerBank(bank.getOrDefault("bankName", "")); } // 处理销方信息 if (StringUtils.isEmpty(billInfo.getSellerBank()) && StringUtils.isNotEmpty(billInfo.getSellerAccount())) { @@ -409,7 +449,7 @@ public class AisinoInvoiceRequestAdapterImpl implements IInvoiceRequestService { json = (JSONObject) JSONObject.toJSON(billInfo); } - if (StringUtils.equals(serviceKey, "addBatch") ) { + if (StringUtils.equals(serviceKey, "addBatch")) { JSONArray billInfoList = JSONUtil.parseArray(json.get("billInfo")); //开票条数限制 @@ -425,16 +465,22 @@ public class AisinoInvoiceRequestAdapterImpl implements IInvoiceRequestService { HxBillInfoDTO hxBillInfo = orderJsonTemp.toJavaObject(HxBillInfoDTO.class); BillInfo billInfo = new BillInfo(); BeanUtils.copyProperties(hxBillInfo, billInfo); - if(StringUtils.isNotEmpty(hxBillInfo.getEmail())){ + if (StringUtils.isNotEmpty(hxBillInfo.getEmail())) { billInfo.setBuyerEmail(hxBillInfo.getEmail()); } - if (StringUtils.isEmpty(billInfo.getBuyerBank()) && StringUtils.isNotEmpty(billInfo.getBuyerAccount())) { + /*if (StringUtils.isEmpty(billInfo.getBuyerBank()) && StringUtils.isNotEmpty(billInfo.getBuyerAccount())) { String bankNo = IdcardUtils.getBankNo(billInfo.getBuyerAccount()); if (StringUtils.isNotEmpty(bankNo)) { String raw = billInfo.getBuyerAccount(); billInfo.setBuyerAccount(bankNo); billInfo.setBuyerBank(raw.replace(bankNo, "")); } + }*/ + // 银行处理 + if (StringUtils.isEmpty(billInfo.getBuyerBank()) && StringUtils.isNotEmpty(billInfo.getBuyerAccount())) { + Map bank = IdcardUtils.getBankNoAndName(billInfo.getBuyerAccount()); + billInfo.setBuyerAccount(bank.getOrDefault("bankNo", "")); + billInfo.setBuyerBank(bank.getOrDefault("bankName", "")); } // 处理detail List hxBillDetailList = hxBillInfo.getDetail(); @@ -448,13 +494,19 @@ public class AisinoInvoiceRequestAdapterImpl implements IInvoiceRequestService { billInfo.setBillDetailList(detailList); } - if (StringUtils.isEmpty(billInfo.getBuyerBank()) && StringUtils.isNotEmpty(billInfo.getBuyerAccount())) { + /*if (StringUtils.isEmpty(billInfo.getBuyerBank()) && StringUtils.isNotEmpty(billInfo.getBuyerAccount())) { String bankNo = IdcardUtils.getBankNo(billInfo.getBuyerAccount()); if (StringUtils.isNotEmpty(bankNo)) { String raw = billInfo.getBuyerAccount(); billInfo.setBuyerAccount(bankNo); billInfo.setBuyerBank(raw.replace(bankNo, "")); } + }*/ + // 银行处理 + if (StringUtils.isEmpty(billInfo.getBuyerBank()) && StringUtils.isNotEmpty(billInfo.getBuyerAccount())) { + Map bank = IdcardUtils.getBankNoAndName(billInfo.getBuyerAccount()); + billInfo.setBuyerAccount(bank.getOrDefault("bankNo", "")); + billInfo.setBuyerBank(bank.getOrDefault("bankName", "")); } // 处理销方信息 if (StringUtils.isEmpty(billInfo.getSellerBank()) && StringUtils.isNotEmpty(billInfo.getSellerAccount())) { @@ -471,7 +523,7 @@ public class AisinoInvoiceRequestAdapterImpl implements IInvoiceRequestService { } // 清除数据,重新组装 json.clear(); - json.put("billInfo",billInfoResult); + json.put("billInfo", billInfoResult); } @@ -487,7 +539,7 @@ public class AisinoInvoiceRequestAdapterImpl implements IInvoiceRequestService { List hxBillDetailList = hxBillInfo.getRedinfodetailList(); List detailList = new ArrayList<>(); - if(CollectionUtil.isNotEmpty(hxBillDetailList)){ + if (CollectionUtil.isNotEmpty(hxBillDetailList)) { for (int i = 0; i < hxBillDetailList.size(); i++) { HxRedInfoDetailsDTO detial = hxBillDetailList.get(i); Redinfodetail temp = new Redinfodetail(); @@ -535,7 +587,6 @@ public class AisinoInvoiceRequestAdapterImpl implements IInvoiceRequestService { } - @Override public String covertMethodName(String method) { return null; diff --git a/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/adapter/request/Nuonuo2InvoiceRequestAdapterImpl.java b/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/adapter/request/Nuonuo2InvoiceRequestAdapterImpl.java index c14f5d9..cfa3cc0 100644 --- a/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/adapter/request/Nuonuo2InvoiceRequestAdapterImpl.java +++ b/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/adapter/request/Nuonuo2InvoiceRequestAdapterImpl.java @@ -71,13 +71,19 @@ public class Nuonuo2InvoiceRequestAdapterImpl implements IInvoiceRequestService BeanUtils.copyProperties(nuonuo2BillInfoDTO, billInfo); // 处理BillInfo字段 billInfo.setCompanyId(companyservice.getCompanyid()); - if (StringUtils.isEmpty(billInfo.getBuyerBank()) && StringUtils.isNotEmpty(billInfo.getBuyerAccount())) { + /*if (StringUtils.isEmpty(billInfo.getBuyerBank()) && StringUtils.isNotEmpty(billInfo.getBuyerAccount())) { String bankNo = IdcardUtils.getBankNo(billInfo.getBuyerAccount()); if (StringUtils.isNotEmpty(bankNo)) { String raw = billInfo.getBuyerAccount(); billInfo.setBuyerAccount(bankNo); billInfo.setBuyerBank(raw.replace(bankNo, "")); } + }*/ + // 银行处理 + if (StringUtils.isEmpty(billInfo.getBuyerBank()) && StringUtils.isNotEmpty(billInfo.getBuyerAccount())) { + Map bank = IdcardUtils.getBankNoAndName(billInfo.getBuyerAccount()); + billInfo.setBuyerAccount(bank.getOrDefault("bankNo", "")); + billInfo.setBuyerBank(bank.getOrDefault("bankName", "")); } // 处理销方信息 if (StringUtils.isEmpty(billInfo.getSellerBank()) && StringUtils.isNotEmpty(billInfo.getSellerAccount())) {