From 11a0fd72629862b9a9823109fb77919a993b3476 Mon Sep 17 00:00:00 2001 From: dongxiaoke <1910333201@qq.com> Date: Thu, 11 Jul 2024 10:08:51 +0800 Subject: [PATCH] =?UTF-8?q?feature:=20=E7=BB=93=E6=9E=9C=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E4=B8=8D=E8=BF=94=E5=9B=9E=E7=89=88=E5=BC=8F=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../invoice/mapper/InvoiceMapper.java | 1 + .../impl/ElephantInvoiceServiceImpl.java | 2 +- ...noConsoleInvoiceApiZhongQiServiceImpl.java | 6 +- .../api/ElephantInvoiceApiServiceImpl.java | 3 +- ...ephantInvoiceApiV6ByInspurServiceImpl.java | 12 +- .../api/ElephantInvoiceApiV6ServiceImpl.java | 465 +++++++++--------- .../invoice/task/AddInvoiceBatchTask.java | 4 +- .../invoice/task/InvoiceBackTask.java | 425 +++++++++++----- .../invoice/task/QueryInvoiceTask.java | 2 +- .../invoice/task/RedInvoiceBackTask.java | 2 +- .../mapper/invoice/InvoiceMapper.xml | 8 + 11 files changed, 563 insertions(+), 367 deletions(-) diff --git a/jianshui-invoice/src/main/java/com/jianshui/invoice/mapper/InvoiceMapper.java b/jianshui-invoice/src/main/java/com/jianshui/invoice/mapper/InvoiceMapper.java index 804844c..3b083d6 100644 --- a/jianshui-invoice/src/main/java/com/jianshui/invoice/mapper/InvoiceMapper.java +++ b/jianshui-invoice/src/main/java/com/jianshui/invoice/mapper/InvoiceMapper.java @@ -102,6 +102,7 @@ public interface InvoiceMapper extends BaseMapper { public Invoice selectByOutTradeOrderno(@Param(("companyId")) Long companyId, @Param("out_trade_orderno") String systemOrderNo,@Param("update_by") String updateBy); public Invoice selectByOutTradeOrdernoNoUpdateBy(@Param(("companyId")) Long companyId, @Param("out_trade_orderno") String systemOrderNo); public List selectByOutTradeOrdernoList(@Param(("companyId")) Long companyId, @Param("out_trade_orderno") String systemOrderNo,@Param("update_by") String updateBy); + public List selectByOutTradeOrdernoListNoUpdateBy(@Param(("companyId")) Long companyId, @Param("out_trade_orderno") String systemOrderNo); /** diff --git a/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/ElephantInvoiceServiceImpl.java b/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/ElephantInvoiceServiceImpl.java index 5f338e9..18abd8e 100644 --- a/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/ElephantInvoiceServiceImpl.java +++ b/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/ElephantInvoiceServiceImpl.java @@ -502,7 +502,7 @@ public class ElephantInvoiceServiceImpl implements ElephantInvoiceService { invoiceBack.setIdentity(companyservice.getIdentity()); invoiceBack.setBackMsg(""); invoiceBack.setBackUrl(""); - invoiceBack.setSystemOrderno(invoice.getOutTradeOrderno()); + invoiceBack.setSystemOrderno(invoice.getFpqqlsh()); invoiceBack.setStatus("0"); invoiceBack.setCreateTime(new Date()); invoiceBackMapper.insertInvoiceBack(invoiceBack); diff --git a/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/AisinoConsoleInvoiceApiZhongQiServiceImpl.java b/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/AisinoConsoleInvoiceApiZhongQiServiceImpl.java index aa493c9..8e45b17 100644 --- a/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/AisinoConsoleInvoiceApiZhongQiServiceImpl.java +++ b/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/AisinoConsoleInvoiceApiZhongQiServiceImpl.java @@ -133,7 +133,7 @@ public class AisinoConsoleInvoiceApiZhongQiServiceImpl implements IInvoiceApiSer invoiceBackVali.setBackUrl(""); invoiceBackVali.setStatus("0"); invoiceBackVali.setCreateTime(new Date()); - invoiceBackVali.setSystemOrderno(invoice.getOutTradeOrderno()); + invoiceBackVali.setSystemOrderno(invoice.getFpqqlsh()); invoiceBackVali.setBackMsg(""); invoiceBackVali.setResultCode("0000"); invoiceBackVali.setResultMsg("开票成功!"); @@ -426,7 +426,7 @@ public class AisinoConsoleInvoiceApiZhongQiServiceImpl implements IInvoiceApiSer queryInvoiceBack.setBackUrl(callBackUrl); queryInvoiceBack.setStatus("0"); queryInvoiceBack.setCreateTime(new Date()); - queryInvoiceBack.setSystemOrderno(billInfo.getOutTradeOrderno()); + queryInvoiceBack.setSystemOrderno(billInfo.getFpqqlsh()); queryInvoiceBack.setBackMsg(""); queryInvoiceBack.setResultCode("0000"); queryInvoiceBack.setResultMsg("开票成功!"); @@ -541,7 +541,7 @@ public class AisinoConsoleInvoiceApiZhongQiServiceImpl implements IInvoiceApiSer queryInvoiceBack.setBackUrl(callBackUrl); queryInvoiceBack.setStatus("0"); queryInvoiceBack.setCreateTime(new Date()); - queryInvoiceBack.setSystemOrderno(billInfo.getOutTradeOrderno()); + queryInvoiceBack.setSystemOrderno(billInfo.getFpqqlsh()); queryInvoiceBack.setBackMsg(""); queryInvoiceBack.setResultCode("0000"); queryInvoiceBack.setResultMsg("开票成功!"); diff --git a/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiServiceImpl.java b/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiServiceImpl.java index f055167..4b5579d 100644 --- a/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiServiceImpl.java +++ b/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiServiceImpl.java @@ -234,6 +234,7 @@ public class ElephantInvoiceApiServiceImpl implements IInvoiceApiService { queryBody.put("DDQQPCH", billInfo.getSystemOrderno()); queryBody.put("FPLXDM", fplxdm); queryBody.put("SFFHSBSJ", "0"); + queryBody.put("BSWJ", "1"); // queryResult = ElephantUtils.sendRequest(ElephantConstants.ADD_INVOICE_RESULT, JSONUtil.parse(queryBody)); try { queryResult = ElephantUtils.sendRequestWithoutToken(ElephantConstants.ADD_INVOICE_RESULT_LOCALHOST, ElephantConstants.ADD_INVOICE_RESULT_METHOD, JSONUtil.parse(queryBody), companyservice); @@ -359,7 +360,7 @@ public class ElephantInvoiceApiServiceImpl implements IInvoiceApiService { JSONObject queryBody = new JSONObject(); queryBody.put("NSRSBH", companyservice.getSellertax()); queryBody.put("DDQQLSH", originBillInfo.getSystemOrderno()); - queryBody.put("BSWJ", "0"); + queryBody.put("BSWJ", "1"); debugLog("断点4", uuid, timestamp); // AjaxResult queryResult = ElephantUtils.sendRequest(ElephantConstants.QUERY_INVOICE, JSONUtil.parse(queryBody)); diff --git a/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiV6ByInspurServiceImpl.java b/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiV6ByInspurServiceImpl.java index 2b89a48..80e1425 100644 --- a/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiV6ByInspurServiceImpl.java +++ b/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiV6ByInspurServiceImpl.java @@ -327,7 +327,7 @@ public class ElephantInvoiceApiV6ByInspurServiceImpl implements IInvoiceApiServi // TODO: 2023/10/8 数电 // TODO kk:2024/7/8 寿仙谷定制 去掉文件流 -// queryBody.put("BSWJ", "1"); + queryBody.put("BSWJ", "1"); // 订单请求流水号 @@ -474,7 +474,7 @@ public class ElephantInvoiceApiV6ByInspurServiceImpl implements IInvoiceApiServi JSONObject queryBody = new JSONObject(); queryBody.put("NSRSBH", companyservice.getSellertax()); queryBody.put("DDQQLSH", originBillInfo.getSystemOrderno()); - queryBody.put("BSWJ", "0"); + queryBody.put("BSWJ", "1"); // TODO kk:2024/7/8 寿仙谷定制 不需要文件流 // queryBody.put("BSWJ", "1"); debugLog("断点4", uuid, timestamp); @@ -3137,7 +3137,7 @@ public class ElephantInvoiceApiV6ByInspurServiceImpl implements IInvoiceApiServi invoiceBackVali.setBackUrl(""); invoiceBackVali.setStatus("0"); invoiceBackVali.setCreateTime(new Date()); - invoiceBackVali.setSystemOrderno(invoice.getOutTradeOrderno()); + invoiceBackVali.setSystemOrderno(invoice.getFpqqlsh()); invoiceBackVali.setBackMsg(""); invoiceBackVali.setResultCode("0000"); invoiceBackVali.setResultMsg("开票成功!"); @@ -3324,8 +3324,8 @@ public class ElephantInvoiceApiV6ByInspurServiceImpl implements IInvoiceApiServi // 订单请求流水号 queryBody.put("DDQQLSH", billInfo.getSystemOrderno()); - - + + queryBody.put("BSWJ", "1"); /*// 提取码 queryBody.put("TQM", "0"); // 订单号 @@ -3401,7 +3401,7 @@ public class ElephantInvoiceApiV6ByInspurServiceImpl implements IInvoiceApiServi queryInvoiceBack.setBackUrl(callBackUrl); queryInvoiceBack.setStatus(InvoiceBackStatusEnum.IN_PROCESS.getCode()); queryInvoiceBack.setCreateTime(new Date()); - queryInvoiceBack.setSystemOrderno(billInfo.getOutTradeOrderno()); + queryInvoiceBack.setSystemOrderno(billInfo.getFpqqlsh()); queryInvoiceBack.setBackMsg(""); queryInvoiceBack.setResultCode("0000"); queryInvoiceBack.setResultMsg("开票中,进入队列"); diff --git a/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiV6ServiceImpl.java b/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiV6ServiceImpl.java index 869faea..ee60eac 100644 --- a/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiV6ServiceImpl.java +++ b/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiV6ServiceImpl.java @@ -149,6 +149,7 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { /** * 发票开具 * v6 + * * @param billInfo * @return */ @@ -158,18 +159,18 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { /** 查找权限ID */ String entId = ""; CompanyserviceProp companyservicePropEntId = companyservicePropMapper.selectPropByKey(companyservice.getCompanyid(), "ent_id"); - if(companyservicePropEntId != null && StrUtil.isNotEmpty(companyservicePropEntId.getValue()) ){ + if (companyservicePropEntId != null && StrUtil.isNotEmpty(companyservicePropEntId.getValue())) { entId = companyservicePropEntId.getValue(); - }else{ + } else { log.info("权限id未配置,需配置key名 ent_id,实现权限管理"); } - String clerk = billInfo.getClerk() != null ? billInfo.getClerk():""; - if(StrUtil.isNotEmpty(clerk)) { + String clerk = billInfo.getClerk() != null ? billInfo.getClerk() : ""; + if (StrUtil.isNotEmpty(clerk)) { CompanyserviceProp companyservicePropClerk = companyservicePropMapper.selectPropByKey(companyservice.getCompanyid(), clerk); - if(companyservicePropClerk != null && StrUtil.isNotEmpty(companyservicePropClerk.getValue()) ){ + if (companyservicePropClerk != null && StrUtil.isNotEmpty(companyservicePropClerk.getValue())) { entId = companyservicePropClerk.getValue(); - }else{ + } else { log.info("权限id未配置,需配置key名 clerk,实现权限管理"); } } @@ -195,7 +196,7 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { log.error("【销项】【大象发票】开票接口校验异常", e); return new HXResponse("格式校验失败,请检查报文"); } - log.info("billInfo信息:{}",JSONObject.toJSONString(billInfo)); + log.info("billInfo信息:{}", JSONObject.toJSONString(billInfo)); // 订单头信息 DDTXX ddtxx = new DDTXX(billInfo); @@ -251,7 +252,7 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { // 权限id赋值 ddpcxx.setENTID(entId); - if ("001".equals(fplxdm)||"002".equals(fplxdm)){ + if ("001".equals(fplxdm) || "002".equals(fplxdm)) { CompanyserviceProp companyserviceProp = companyservicePropMapper.selectPropByKey(companyservice.getCompanyid(), "account_show"); if (companyserviceProp != null && "1".equals(companyserviceProp.getValue())) { @@ -270,18 +271,18 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { qdtxx.setFJYSLIST(billInfo.getFjyslist());// 附加要素列表 qdtxx.setHWYSLIST(billInfo.getHwysList()); // 货物运输 - if(billInfo.getBdcxsxxList() != null && !billInfo.getBdcxsxxList().isEmpty()){ + if (billInfo.getBdcxsxxList() != null && !billInfo.getBdcxsxxList().isEmpty()) { qdtxx.setBDCXSXX(billInfo.getBdcxsxxList().get(0)); // 不动产销售信息 } - if(billInfo.getJzfwList() != null && !billInfo.getJzfwList().isEmpty()){ + if (billInfo.getJzfwList() != null && !billInfo.getJzfwList().isEmpty()) { qdtxx.setJZFWXX(billInfo.getJzfwList().get(0));// 建筑服务信息 } - if(billInfo.getBdczlxxList() != null && !billInfo.getBdczlxxList().isEmpty()){ + if (billInfo.getBdczlxxList() != null && !billInfo.getBdczlxxList().isEmpty()) { qdtxx.setBDCZLXX(billInfo.getBdczlxxList().get(0));// 不动产租赁信息 } - if(billInfo.getJDCXX() != null ){ - qdtxx.setJDCXX(billInfo.getJDCXX() );// 机动车信息 + if (billInfo.getJDCXX() != null) { + qdtxx.setJDCXX(billInfo.getJDCXX());// 机动车信息 } // qdtxx.setBDCZLXX(billInfo.getBdczlxxList()); //不动产租赁信息 @@ -299,14 +300,14 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { } else if (BeanUtil.isNotEmpty(qdtxx.getBDCZLXX())) { // GenerateQdBdczlInvoice 不动产租赁信息 url = ElephantConstantsV6.GENERATE_QD_BDXZL_INVOICE; - }else if( BeanUtil.isNotEmpty(qdtxx.getJDCXX()) ){ + } else if (BeanUtil.isNotEmpty(qdtxx.getJDCXX())) { // GenerateQdjdcxsInvoice 数电机动车销售统一发票 url = ElephantConstantsV6.GENERATE_QD_JDCXS_INVOICE; } // 机动车专票适配 - String jdcbz = billInfo.getJdcbz() != null ? billInfo.getJdcbz():""; - if("1".equals(jdcbz)){ + String jdcbz = billInfo.getJdcbz() != null ? billInfo.getJdcbz() : ""; + if ("1".equals(jdcbz)) { billInfo.setTdys("14"); // (数电机动车专票)发票开具/冲红接口 url = ElephantConstantsV6.GENERATE_QD_JDCZP_INVOICE; @@ -385,6 +386,7 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { queryBody.put("DDRQQ", "0"); // 订单日期止 queryBody.put("DDRQZ", "0");*/ + queryBody.put("BSWJ", "1"); // queryResult = ElephantUtils.sendRequest(ElephantConstantsV6.ADD_INVOICE_RESULT, JSONUtil.parse(queryBody)); try { queryResult = ElephantUtils.sendRequestWithoutTokenV6New(ElephantConstantsV6.ADD_INVOICE_RESULT_LOCALHOST, ElephantConstantsV6.ADD_INVOICE_RESULT_METHOD, JSONUtil.parse(queryBody), companyservice); @@ -405,7 +407,7 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { if (contentJson != null) { String ztdm = contentJson.getString("ZTDM"); // 021002 020111 - if (!StringUtils.equalsAny(ztdm, "020111", "020000", "010000","000000")) { + if (!StringUtils.equalsAny(ztdm, "020111", "020000", "010000", "000000")) { // 开票失败 if (StringUtils.equals("020002", ztdm)) { billInfo.setState(22); @@ -414,10 +416,10 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { // kk: 2023/12/5 判断人脸识别的状态 String DDFPZXX = contentJson.getString("DDFPZXX") != null ? contentJson.getString("DDFPZXX") : ""; - if(StrUtil.isNotEmpty(DDFPZXX)){ - DDFPZXX ddfpzxx = BeanUtil.copyProperties(DDFPZXX,DDFPZXX.class); - if(ddfpzxx != null && ddfpzxx.getDDFPXX() != null && "03200".equals(ddfpzxx.getDDFPXX().getDDZT())){ - return new HXResponse("E004",ddfpzxx.getDDFPXX().getDDZTXX() != null ? ddfpzxx.getDDFPXX().getDDZTXX():"发票开具失败,请确认是否人脸识别超期!"); + if (StrUtil.isNotEmpty(DDFPZXX)) { + DDFPZXX ddfpzxx = BeanUtil.copyProperties(DDFPZXX, DDFPZXX.class); + if (ddfpzxx != null && ddfpzxx.getDDFPXX() != null && "03200".equals(ddfpzxx.getDDFPXX().getDDZT())) { + return new HXResponse("E004", ddfpzxx.getDDFPXX().getDDZTXX() != null ? ddfpzxx.getDDFPXX().getDDZTXX() : "发票开具失败,请确认是否人脸识别超期!"); } } @@ -432,7 +434,7 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { } // 定时拉取保存发票, TODO 处理开票中的问题 - AsyncManager.me().execute(new QueryInvoiceTask(billInfo, companyservice, this,invoiceBackMapper)); + AsyncManager.me().execute(new QueryInvoiceTask(billInfo, companyservice, this, invoiceBackMapper)); // 数电的加入金财表 InvoiceAllApiLog allApiLog = new InvoiceAllApiLog(); @@ -471,6 +473,7 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { /** * 单个发票查询接口 * V6 + * * @param billInfo * @return */ @@ -515,7 +518,7 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { JSONObject queryBody = new JSONObject(); queryBody.put("NSRSBH", companyservice.getSellertax()); queryBody.put("DDQQLSH", originBillInfo.getSystemOrderno()); - queryBody.put("BSWJ", "0"); + queryBody.put("BSWJ", "1"); debugLog("断点4", uuid, timestamp); AjaxResult queryResult = null; @@ -669,27 +672,27 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { String fileId = IdUtils.randomUUID(); String fileName = invoice.getFphm(); - if(ddfpxx.getPDFZJL() != null && StrUtil.isNotEmpty(ddfpxx.getPDFZJL())){ + if (ddfpxx.getPDFZJL() != null && StrUtil.isNotEmpty(ddfpxx.getPDFZJL())) { String fphm = ddfpxx.getFPHM(); - if(StrUtil.isNotEmpty(fphm)){ + if (StrUtil.isNotEmpty(fphm)) { Environment environment = SpringUtils.getBean(Environment.class); String type = environment.getProperty(Constants.INVOICE_FILE_SAVE_TYPE); //配置文件存储类型0为数据库存储 - if (Constants.STRING_0.equals(type)){ - saveFileUseDb(invoice, fileId, fileName,companyservice, ddfpxx); - //配置文件存储类型1为oss存储 - }else if (Constants.STRING_1.equals(type)){ - saveFileUseOss(defaultStorage,invoice,ddfpxx); - //配置文件存储类型2为本地存储 - }else if (Constants.STRING_2.equals(type)){ - saveFileUseLocal(invoice,ddfpxx); + if (Constants.STRING_0.equals(type)) { + saveFileUseDb(invoice, fileId, fileName, companyservice, ddfpxx); + //配置文件存储类型1为oss存储 + } else if (Constants.STRING_1.equals(type)) { + saveFileUseOss(defaultStorage, invoice, ddfpxx); + //配置文件存储类型2为本地存储 + } else if (Constants.STRING_2.equals(type)) { + saveFileUseLocal(invoice, ddfpxx); } } } // end - + debugLog("断点13", uuid, timestamp); if (invoice.getId() != null) { @@ -782,12 +785,12 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { return response; } - private void saveFileUseLocal(Invoice invoice,DDFPXX ddfpxx) { + private void saveFileUseLocal(Invoice invoice, DDFPXX ddfpxx) { try { byte[] pdfBytes = Base64.decode(ddfpxx.getPDFZJL()); String key = IdUtils.fastSimpleUUID(); - String fileName = key + "."+ddfpxx.getZJLLX().toLowerCase(); + String fileName = key + "." + ddfpxx.getZJLLX().toLowerCase(); String fileDir = JianshuiConfig.getDownloadPath() + "/storage/"; // 判断fileDir是否存在,不存在则创建 File fileDirInst = new File(fileDir); @@ -833,13 +836,13 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { if (StringUtils.equals(ddfpxx.getZJLLX(), Constants.OFD_UPCASE)) { invoice.setcOfdUrl(realPath); } - }catch (Exception e){ - log.error("文件保存异常",e); + } catch (Exception e) { + log.error("文件保存异常", e); } } - private void saveFileUseOss(String defaultStorage,Invoice invoice,DDFPXX ddfpxx) { + private void saveFileUseOss(String defaultStorage, Invoice invoice, DDFPXX ddfpxx) { if (StringUtils.isNotEmpty(defaultStorage) && StringUtils.isEmpty(invoice.getInvoicePdfUrl())) { try { IStorageService service = storageFactory.getStorageInstance(defaultStorage); @@ -870,11 +873,11 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { } } - private void saveFileUseDb(Invoice invoice,String fileId,String fileName,Companyservice companyservice,DDFPXX ddfpxx) { + private void saveFileUseDb(Invoice invoice, String fileId, String fileName, Companyservice companyservice, DDFPXX ddfpxx) { InvoiceFile invoiceFile = new InvoiceFile(); invoiceFile.setFphm(ddfpxx.getFPHM()); List invoiceFileList = invoiceFileMapper.selectInvoiceFileList(invoiceFile); - if(invoiceFileList != null && invoiceFileList.size() > 0){ + if (invoiceFileList != null && invoiceFileList.size() > 0) { invoiceFile = invoiceFileList.get(0); invoiceFile.setFileContent(ddfpxx.getPDFZJL()); invoiceFile.setFileName(fileName); @@ -884,7 +887,7 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { fileId = invoiceFile.getFileId(); fileName = invoiceFile.getFileName(); invoiceFileMapper.updateInvoiceFile(invoiceFile); - }else{ + } else { invoiceFile.setId(fileId); invoiceFile.setFileContent(ddfpxx.getPDFZJL()); invoiceFile.setFileId(fileId); @@ -1105,12 +1108,14 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { return null; } - /** 获取人脸识别结果*/ + /** + * 获取人脸识别结果 + */ @Override public HXResponse qrcodeResult(JSONObject decryptResult, Companyservice companyservice) { - InvoiceAllQycodeResultDTO qycodeResultDTO = BeanUtil.copyProperties(decryptResult,InvoiceAllQycodeResultDTO.class); - if(BeanUtil.isEmpty(qycodeResultDTO)){ + InvoiceAllQycodeResultDTO qycodeResultDTO = BeanUtil.copyProperties(decryptResult, InvoiceAllQycodeResultDTO.class); + if (BeanUtil.isEmpty(qycodeResultDTO)) { return new HXResponse("参数为空!"); } @@ -1134,19 +1139,20 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { // 返回结果处理 HXResponse hxResponseT = parseResult(dxhyInterfaceResponse); - if("000000".equals(hxResponseT.get("code")) && hxResponseT.get("data") != null && !"".equals(hxResponseT.get("data"))){ - InvoiceAllQycodeResultElEVO qycodeResultVO = BeanUtil.copyProperties(JSONUtil.parse(hxResponseT.get("data")),InvoiceAllQycodeResultElEVO.class); + if ("000000".equals(hxResponseT.get("code")) && hxResponseT.get("data") != null && !"".equals(hxResponseT.get("data"))) { + InvoiceAllQycodeResultElEVO qycodeResultVO = BeanUtil.copyProperties(JSONUtil.parse(hxResponseT.get("data")), InvoiceAllQycodeResultElEVO.class); HXResponse response = new HXResponse("0000", "请求成功", qycodeResultVO); return response; } else { - return new HXResponse(hxResponseT.getMessage() != null ? hxResponseT.getMessage():""); + return new HXResponse(hxResponseT.getMessage() != null ? hxResponseT.getMessage() : ""); } } - - /** 邮箱交付 */ + /** + * 邮箱交付 + */ @Override public HXResponse mailDelivery(InvoiceMailDeliveryDTO mailDeliveryDTO, Companyservice companyservice) { @@ -1172,7 +1178,7 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { public HXResponse fastRedInvoice(JSONObject decryptResult, Companyservice companyservice) { decryptResult = JsonKeyCase.JsonKeyCase(decryptResult); - log.info("调用大象V6接口报文key转大写后的报文为{}",decryptResult); + log.info("调用大象V6接口报文key转大写后的报文为{}", decryptResult); DxhyInterfaceResponse dxhyInterfaceResponse = null; try { dxhyInterfaceResponse = ElephantUtils.sendRequestWithoutTokenV6(ElephantConstantsV6.ORDER_TO_FAST_RED_INVOICE_LOCALHOST, ElephantConstantsV6.ORDER_TO_FAST_RED_INVOICE_METHOD, JSONUtil.parse(decryptResult), companyservice); @@ -1189,7 +1195,7 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { @Override public HXResponse QueryFastRedInvoiceResult(JSONObject decryptResult, Companyservice companyservice) { decryptResult = JsonKeyCase.JsonKeyCase(decryptResult); - log.info("调用大象V6接口报文key转大写后的报文为{}",decryptResult); + log.info("调用大象V6接口报文key转大写后的报文为{}", decryptResult); DxhyInterfaceResponse dxhyInterfaceResponse = null; try { dxhyInterfaceResponse = ElephantUtils.sendRequestWithoutTokenV6(ElephantConstantsV6.QUERY_FAST_RED_INVOICE_RESULT_LOCALHOST, @@ -1207,7 +1213,7 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { @Override public HXResponse QuerySdInvoiceFile(JSONObject decryptResult, Companyservice companyservice) { decryptResult = JsonKeyCase.JsonKeyCase(decryptResult); - log.info("调用大象V6接口报文key转大写后的报文为{}",decryptResult); + log.info("调用大象V6接口报文key转大写后的报文为{}", decryptResult); DxhyInterfaceResponse dxhyInterfaceResponse = null; try { dxhyInterfaceResponse = ElephantUtils.sendRequestWithoutTokenV6(ElephantConstantsV6.QUERY_INVOICE_FILE_LOCALHOST, @@ -1239,7 +1245,7 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { public HXResponse queryRedConfirmationList(JSONObject decryptResult, Companyservice companyservice) { decryptResult = JsonKeyCase.JsonKeyCase(decryptResult); - log.info("调用大象V6接口报文key转大写后的报文为{}",decryptResult); + log.info("调用大象V6接口报文key转大写后的报文为{}", decryptResult); DxhyInterfaceResponse dxhyInterfaceResponse = null; try { dxhyInterfaceResponse = ElephantUtils.sendRequestWithoutTokenV6(ElephantConstantsV6.QUERY_RED_CONFIRMATION_LIST_LOCALHOST, ElephantConstantsV6.QUERY_RED_CONFIRMATION_LIST_METHOD, JSONUtil.parse(decryptResult), companyservice); @@ -1264,7 +1270,7 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { public HXResponse queryRedConfirmationItemList(JSONObject decryptResult, Companyservice companyservice) { decryptResult = JsonKeyCase.JsonKeyCase(decryptResult); - log.info("调用大象V6接口报文key转大写后的报文为{}",decryptResult); + log.info("调用大象V6接口报文key转大写后的报文为{}", decryptResult); DxhyInterfaceResponse dxhyInterfaceResponse = null; try { dxhyInterfaceResponse = ElephantUtils.sendRequestWithoutTokenV6(ElephantConstantsV6.QUERY_RED_CONFIRMATION_ITEM_LIST_LOCALHOST, ElephantConstantsV6.QUERY_RED_CONFIRMATION_ITEM_LIST_METHOD, JSONUtil.parse(decryptResult), companyservice); @@ -1290,16 +1296,16 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { String fpdm = decryptResult.getString("lzfppzdm"); decryptResult.put("lzfppzdm", InvoiceType.getEleCode(fpdm)); // TODO kk:2024/1/8 红字申请表申请用的是01 02 - String lzfpdm = decryptResult.get("lzfppzdm") != null ? decryptResult.get("lzfppzdm").toString():""; - if("001".equals(lzfpdm)){ + String lzfpdm = decryptResult.get("lzfppzdm") != null ? decryptResult.get("lzfppzdm").toString() : ""; + if ("001".equals(lzfpdm)) { lzfpdm = "01"; - }else if("002".equals(lzfpdm)){ + } else if ("002".equals(lzfpdm)) { lzfpdm = "02"; } decryptResult.put("lzfppzdm", lzfpdm); decryptResult = JsonKeyCase.JsonKeyCase(decryptResult); - log.info("调用大象V6接口报文key转大写后的报文为{}",decryptResult); + log.info("调用大象V6接口报文key转大写后的报文为{}", decryptResult); DxhyInterfaceResponse dxhyInterfaceResponse = null; try { dxhyInterfaceResponse = ElephantUtils.sendRequestWithoutTokenV6(ElephantConstantsV6.RED_CONFIRMATION_LOCALHOST, ElephantConstantsV6.RED_CONFIRMATION_METHOD, JSONUtil.parse(decryptResult), companyservice); @@ -1310,10 +1316,10 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { } HXResponse hxResponse = parseResult(dxhyInterfaceResponse); - if("000000".equals(hxResponse.get("code"))){ + if ("000000".equals(hxResponse.get("code"))) { cn.hutool.json.JSONObject data = JSONUtil.parseObj(hxResponse.getData()); - String bh = data.get("hzfpxxqrdbh") != null ? data.get("hzfpxxqrdbh").toString() : ""; - if(StrUtil.isNotEmpty(bh)){ + String bh = data.get("hzfpxxqrdbh") != null ? data.get("hzfpxxqrdbh").toString() : ""; + if (StrUtil.isNotEmpty(bh)) { InvoiceAllApiLog allApiLog = new InvoiceAllApiLog(); allApiLog.setUrl(WebServiceConstant.ADD_RED_INVOICE_QRD); allApiLog.setSendMsg(JSONUtil.toJsonStr(decryptResult)); @@ -1342,7 +1348,7 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { public HXResponse redConfirmationConfirm(JSONObject decryptResult, Companyservice companyservice) { decryptResult = JsonKeyCase.JsonKeyCase(decryptResult); - log.info("调用大象V6接口报文key转大写后的报文为{}",decryptResult); + log.info("调用大象V6接口报文key转大写后的报文为{}", decryptResult); DxhyInterfaceResponse dxhyInterfaceResponse = null; try { dxhyInterfaceResponse = ElephantUtils.sendRequestWithoutTokenV6(ElephantConstantsV6.RED_CONFIRMATION_CONFIRM_LOCALHOST, ElephantConstantsV6.RED_CONFIRMATION_CONFIRM_METHOD, JSONUtil.parse(decryptResult), companyservice); @@ -1366,7 +1372,7 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { public HXResponse rpaLogin(JSONObject decryptResult, Companyservice companyservice) { decryptResult = JsonKeyCase.JsonKeyCase(decryptResult); - log.info("调用大象V6接口报文key转大写后的报文为{}",decryptResult); + log.info("调用大象V6接口报文key转大写后的报文为{}", decryptResult); DxhyInterfaceResponse dxhyInterfaceResponse = null; try { dxhyInterfaceResponse = ElephantUtils.sendRequestWithoutTokenV6(ElephantConstantsV6.RPA_LOGIN_LOCALHOST, ElephantConstantsV6.RPA_LOGIN_METHOD, JSONUtil.parse(decryptResult), companyservice); @@ -1472,7 +1478,6 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { } - /** * 申请/上传 红字发票 * @@ -1647,7 +1652,7 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { } // 存入金四关联日志表 - if("0000".equals(ztxx) && StrUtil.isNotEmpty(queryId)){ + if ("0000".equals(ztxx) && StrUtil.isNotEmpty(queryId)) { InvoiceAllApiLog allApiLog = new InvoiceAllApiLog(); allApiLog.setUrl(WebServiceConstant.SQHZFPXXQRD); allApiLog.setSendMsg(""); @@ -1663,7 +1668,7 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { HXResponse response = new HXResponse("0000", "申请成功"); response.put("queryid", queryId); return response; - }else{ + } else { return new HXResponse(ztxx); } @@ -2090,7 +2095,7 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { e.printStackTrace(); throw new JianshuiServiceException("系统异常!"); } - log.info("【销项发票】【大象发票】发票专用章图片生成请求结果{}", StrUtil.sub(queryResult.toString(),0,50)); + log.info("【销项发票】【大象发票】发票专用章图片生成请求结果{}", StrUtil.sub(queryResult.toString(), 0, 50)); // 判断外层报文是否成功 @@ -2316,7 +2321,7 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { decryptResult = JsonKeyCase.JsonKeyCase(decryptResult); - log.info("调用大象V6接口报文key转大写后的报文为{}",decryptResult); + log.info("调用大象V6接口报文key转大写后的报文为{}", decryptResult); DxhyInterfaceResponse dxhyInterfaceResponse = null; try { dxhyInterfaceResponse = ElephantUtils.sendRequestWithoutTokenV6(ElephantConstantsV6.GET_RPA_QY_CODE_LOCALHOST, ElephantConstantsV6.GET_RPA_QY_CODE_METHOD, JSONUtil.parse(decryptResult), companyservice); @@ -2361,15 +2366,15 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { } /** - * @author kk + * @author kk * 通用查询接口 - */ + */ @Override public HXResponse queryResultInfo(InvoiceAllQueryTWODTO invoiceAllYhdjDTO, Companyservice companyservice) { //存入金财的调用接口表里去 String requestId = invoiceAllYhdjDTO.getRequestId() != null ? invoiceAllYhdjDTO.getRequestId() : ""; - if(StrUtil.isEmpty(requestId)){ + if (StrUtil.isEmpty(requestId)) { return new HXResponse("requestId不能为空!"); } @@ -2403,22 +2408,22 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { response.put("data", invoice); return response; - }else if (WebServiceConstant.QRCODE.equals(finalServiceId)) { + } else if (WebServiceConstant.QRCODE.equals(finalServiceId)) { // 获取人脸二维码 //获取税局用户名称 JSONObject param = new JSONObject(); - param.put(ElephantConstants.NSRSBH,companyservice.getSellertax()); + param.put(ElephantConstants.NSRSBH, companyservice.getSellertax()); HXResponse hxResponse = queryRpaTaxAccount(param, companyservice); - if (!StringUtils.equals("000000",hxResponse.getCode())){ + if (!StringUtils.equals("000000", hxResponse.getCode())) { return hxResponse; } JSONObject resp = JSONObject.parseObject(JSON.toJSONString(hxResponse.getData())); - param.put(ElephantConstants.YHM,resp.getString(ElephantConstants.YHM)); + param.put(ElephantConstants.YHM, resp.getString(ElephantConstants.YHM)); HXResponse rpaAuthStatus = qrcode(param, companyservice); - log.info("获取人脸二维码大象返回报文封装后:{}",JSONUtil.toJsonStr(hxResponse)); + log.info("获取人脸二维码大象返回报文封装后:{}", JSONUtil.toJsonStr(hxResponse)); // if (StringUtils.equals("000000",rpaAuthStatus.getCode())){ // rpaAuthStatus.setCode("200"); @@ -2429,18 +2434,18 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { // } return rpaAuthStatus; - }else if (WebServiceConstant.SQHZFPXXQRD.equals(finalServiceId)) { + } else if (WebServiceConstant.SQHZFPXXQRD.equals(finalServiceId)) { // 申请红字信息表 //查询红字信息表入库信息 LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(Redinfo::getFpqqlsh,requestId); + queryWrapper.eq(Redinfo::getFpqqlsh, requestId); Redinfo redinfo = redinfoMapper.selectOne(queryWrapper); - HXResponse hxResponse = queryRedInfoByElepant(redinfo,companyservice,allApiLog); + HXResponse hxResponse = queryRedInfoByElepant(redinfo, companyservice, allApiLog); return hxResponse; - }else if (WebServiceConstant.ADD_RED_INVOICE.equals(finalServiceId)) { + } else if (WebServiceConstant.ADD_RED_INVOICE.equals(finalServiceId)) { // 红字发票开具 //调用大象接口获取数据入库 @@ -2448,26 +2453,26 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { queryBillInfoDTO.setFpqqlsh(requestId); HXResponse hxResponse = queryInvoice(queryBillInfoDTO, companyservice); - if(StringUtils.equals("0000",hxResponse.getCode())){ + if (StringUtils.equals("0000", hxResponse.getCode())) { return hxResponse; } //查询数据库信息并返回 LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(Invoice::getFpqqlsh,requestId); + queryWrapper.eq(Invoice::getFpqqlsh, requestId); queryWrapper.orderByDesc(Invoice::getId).last("limit 1"); Invoice invoice = invoiceMapper.selectOne(queryWrapper); - response.put("data",invoice); + response.put("data", invoice); return response; - }else if (WebServiceConstant.ADD_RED_INVOICE_QRD.equals(finalServiceId)) { + } else if (WebServiceConstant.ADD_RED_INVOICE_QRD.equals(finalServiceId)) { // 红字发票开具-确认单编号方式 // TODO kk:2024/2/26 调用订单查询接口-不入库 JSONObject jsonObject = new JSONObject(); - jsonObject.put("HZQRDBH",requestId); - jsonObject.put("NSRSBH",allApiLog.getCompany()); + jsonObject.put("HZQRDBH", requestId); + jsonObject.put("NSRSBH", allApiLog.getCompany()); DxhyInterfaceResponse dxhyInterfaceResponse = null; try { @@ -2480,32 +2485,32 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { } HXResponse hxResponse = parseResult(dxhyInterfaceResponse); - hxResponse = parseDxhyRes(hxResponse,companyservice); + hxResponse = parseDxhyRes(hxResponse, companyservice); return hxResponse; - }else if (WebServiceConstant.CXHZFPXXQRD.equals(finalServiceId)) { + } else if (WebServiceConstant.CXHZFPXXQRD.equals(finalServiceId)) { // 查询红字信息表 CxhzJsonDataTwoDTO cxhzJsonDataTwoDTO = null; try { String sendMsg = allApiLog.getSendMsg(); - cxhzJsonDataTwoDTO= JSONObject.parseObject(sendMsg, CxhzTwoDTO.class).getJsonData(); + cxhzJsonDataTwoDTO = JSONObject.parseObject(sendMsg, CxhzTwoDTO.class).getJsonData(); - }catch (Exception e){ - log.error("反序列化失败异常",e); + } catch (Exception e) { + log.error("反序列化失败异常", e); throw new JianshuiServiceException("起始日期反序列化失败"); } JSONObject param = new JSONObject(); - param.put(ElephantConstants.YHJSLX,ElephantConstants.STRING_0); - param.put(ElephantConstants.XSFNSRSBH,companyservice.getSellertax()); - param.put(ElephantConstants.XSFMC,companyservice.getSellername()); - param.put(ElephantConstants.LRFSF,ElephantConstants.STRING_0); - param.put(ElephantConstants.LRRQQ,cxhzJsonDataTwoDTO.getKprqq()); - param.put(ElephantConstants.LRRQZ,cxhzJsonDataTwoDTO.getKprqz()); + param.put(ElephantConstants.YHJSLX, ElephantConstants.STRING_0); + param.put(ElephantConstants.XSFNSRSBH, companyservice.getSellertax()); + param.put(ElephantConstants.XSFMC, companyservice.getSellername()); + param.put(ElephantConstants.LRFSF, ElephantConstants.STRING_0); + param.put(ElephantConstants.LRRQQ, cxhzJsonDataTwoDTO.getKprqq()); + param.put(ElephantConstants.LRRQZ, cxhzJsonDataTwoDTO.getKprqz()); HXResponse hxResponse = queryRedConfirmationList(param, companyservice); - log.info(" 查询红字信息表大象返回报文封装后:{}",JSONUtil.toJsonStr(hxResponse)); + log.info(" 查询红字信息表大象返回报文封装后:{}", JSONUtil.toJsonStr(hxResponse)); HZXXLIST hzxxlist = JSONObject.parseObject(JSONObject.toJSONString(hxResponse.getData()), HZXXLIST.class); @@ -2514,24 +2519,24 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { } else if (WebServiceConstant.SHHZFPXXQRD.equals(finalServiceId)) { // 审核红字信息表 LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(Redinfo::getFpqqlsh,requestId); + queryWrapper.eq(Redinfo::getFpqqlsh, requestId); queryWrapper.orderByDesc(Redinfo::getId).last("limit 1"); Redinfo redinfo = redinfoMapper.selectOne(queryWrapper); - return auditRedInfoResult(allApiLog.getResultMsg(),redinfo,companyservice); + return auditRedInfoResult(allApiLog.getResultMsg(), redinfo, companyservice); } else if (WebServiceConstant.FPEWMXZ.equals(finalServiceId)) { // 获取发票下载地址 - } else if (WebServiceConstant.KSHC.equals(finalServiceId)) { + } else if (WebServiceConstant.KSHC.equals(finalServiceId)) { // 快速红冲 } else if (WebServiceConstant.QDFPWJHQ.equals(finalServiceId)) { // 全电发票文件获取 - } else{ + } else { return new HXResponse("功能升级中~请稍等~"); } @@ -2540,8 +2545,10 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { } - /** 转换大象返回报文为简税报文 */ - private HXResponse parseDxhyRes(HXResponse hxResponse,Companyservice companyservice) { + /** + * 转换大象返回报文为简税报文 + */ + private HXResponse parseDxhyRes(HXResponse hxResponse, Companyservice companyservice) { // 判断外层报文是否成功 if (!hxResponse.getCode().equals("000000")) { @@ -2653,13 +2660,13 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { String fileId = IdUtils.randomUUID(); String fileName = invoice.getFphm(); - if(ddfpxx.getPDFZJL() != null && StrUtil.isNotEmpty(ddfpxx.getPDFZJL())){ + if (ddfpxx.getPDFZJL() != null && StrUtil.isNotEmpty(ddfpxx.getPDFZJL())) { String fphm = ddfpxx.getFPHM(); - if(StrUtil.isNotEmpty(fphm)){ + if (StrUtil.isNotEmpty(fphm)) { InvoiceFile invoiceFile = new InvoiceFile(); invoiceFile.setFphm(ddfpxx.getFPHM()); List invoiceFileList = invoiceFileMapper.selectInvoiceFileList(invoiceFile); - if(invoiceFileList != null && invoiceFileList.size() > 0){ + if (invoiceFileList != null && invoiceFileList.size() > 0) { invoiceFile = invoiceFileList.get(0); invoiceFile.setFileContent(ddfpxx.getPDFZJL()); invoiceFile.setFileName(fileName); @@ -2669,7 +2676,7 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { fileId = invoiceFile.getFileId(); fileName = invoiceFile.getFileName(); invoiceFileMapper.updateInvoiceFile(invoiceFile); - }else{ + } else { invoiceFile.setId(fileId); invoiceFile.setFileContent(ddfpxx.getPDFZJL()); invoiceFile.setFileId(fileId); @@ -2745,12 +2752,12 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { for (HZXXDATA hzxxdata : list) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(Redinfo::getRedInfoNo,hzxxdata.getHZFPXXQRDBH()); + queryWrapper.eq(Redinfo::getRedInfoNo, hzxxdata.getHZFPXXQRDBH()); queryWrapper.orderByDesc(Redinfo::getId).last("limit 1"); //根据红字信息表编号查询红字信息 Redinfo redinfo = redinfoMapper.selectOne(queryWrapper); //不存在就创建对象 - if (ObjectUtils.isEmpty(redinfo)){ + if (ObjectUtils.isEmpty(redinfo)) { redinfo = new Redinfo(); } redinfo.setRedInfoNo(hzxxdata.getHZFPXXQRDBH()); @@ -2764,7 +2771,7 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { redinfo.setReqnsrsbh(hzxxdata.getXSFNSRSBH()); redinfos.add(redinfo); //判断是否存在红字信息,存在执行更新 - if (ObjectUtils.isEmpty(redinfo.getId())){ + if (ObjectUtils.isEmpty(redinfo.getId())) { //处理发票表和红字信息表 redInfoAndInvoiceUpdate(hzxxdata, redinfo); } @@ -2799,7 +2806,7 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { } - return new HXResponse("200","查询成功",hzxxList,true); + return new HXResponse("200", "查询成功", hzxxList, true); } @Async @@ -2823,33 +2830,33 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { invoiceMapper.insertInvoice(invoice); } - private HXResponse auditRedInfoResult(String uuid,Redinfo redinfo, Companyservice companyservice) { - if (ObjectUtils.isEmpty(companyservice)){ + private HXResponse auditRedInfoResult(String uuid, Redinfo redinfo, Companyservice companyservice) { + if (ObjectUtils.isEmpty(companyservice)) { log.info("请求日志为空或者企业服务为空"); - return new HXResponse("9998","请求日志为空或者企业服务为空"); + return new HXResponse("9998", "请求日志为空或者企业服务为空"); } - if (ObjectUtils.isEmpty(redinfo)){ + if (ObjectUtils.isEmpty(redinfo)) { log.info("不存在该红字信息"); - return new HXResponse("9998","不存在该红字信息"); + return new HXResponse("9998", "不存在该红字信息"); } - if (StringUtils.isBlank(uuid)){ + if (StringUtils.isBlank(uuid)) { log.info("红字确认单UUID不能为空"); - return new HXResponse("9998","红字确认单UUID不能为空"); + return new HXResponse("9998", "红字确认单UUID不能为空"); } JSONObject param = new JSONObject(); - param.put(ElephantConstants.NSRSBH,companyservice.getSellertax()); - param.put(ElephantConstants.UUID,uuid); - param.put(ElephantConstants.HZQRDBH,redinfo.getRedInfoNo()); - param.put(ElephantConstants.QRLX,ElephantConstants.QRLX_Y); + param.put(ElephantConstants.NSRSBH, companyservice.getSellertax()); + param.put(ElephantConstants.UUID, uuid); + param.put(ElephantConstants.HZQRDBH, redinfo.getRedInfoNo()); + param.put(ElephantConstants.QRLX, ElephantConstants.QRLX_Y); //调用大象接口获取确认日期 AjaxResult queryResult = null; try { queryResult = ElephantUtils.sendRequestWithoutTokenV6New(ElephantConstantsV6.QUERY_INVOICE_LOCALHOST, ElephantConstantsV6.QUERY_INVOICE_METHOD, JSONUtil.parse(param), companyservice); - log.info("大象返回报文封装后:{}",JSONUtil.toJsonStr(queryResult)); + log.info("大象返回报文封装后:{}", JSONUtil.toJsonStr(queryResult)); } catch (UnsupportedEncodingException | InvalidKeyException | NoSuchAlgorithmException e) { log.error("【销项发票】【大象接口】【发票开具】发票请求异常,请求报文{},销方信息{}", param.toJSONString(), JSONObject.toJSONString(companyservice)); e.printStackTrace(); @@ -2859,17 +2866,17 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { JSONObject data = queryResult.getJsonData(); String qrrq = data.getString(ElephantConstants.QRRQ); data.clear(); - data.put(ElephantConstants.CASE_QRRQ,qrrq); + data.put(ElephantConstants.CASE_QRRQ, qrrq); - return new HXResponse(String.valueOf(queryResult.getCode()),queryResult.getMsg(),data,true); + return new HXResponse(String.valueOf(queryResult.getCode()), queryResult.getMsg(), data, true); } // @Transactional(rollbackFor = Exception.class) - public HXResponse queryRedInfoByElepant(Redinfo redinfo, Companyservice companyservice,InvoiceAllApiLog apiLog) { + public HXResponse queryRedInfoByElepant(Redinfo redinfo, Companyservice companyservice, InvoiceAllApiLog apiLog) { //返回信息 - if (ObjectUtils.isEmpty(redinfo)){ - return new HXResponse("9998","红字信息未查询到"); + if (ObjectUtils.isEmpty(redinfo)) { + return new HXResponse("9998", "红字信息未查询到"); } //日志uuid @@ -2877,16 +2884,16 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { //封装请求参数 JSONObject param = new JSONObject(); - param.put(ElephantConstants.NSRSBH,companyservice.getSellertax()); - param.put(ElephantConstants.UUID,apiLog.getResultMsg()); - param.put(ElephantConstants.XSFNSRSBH,companyservice.getSellertax()); + param.put(ElephantConstants.NSRSBH, companyservice.getSellertax()); + param.put(ElephantConstants.UUID, apiLog.getResultMsg()); + param.put(ElephantConstants.XSFNSRSBH, companyservice.getSellertax()); - debugLog("红字信息表申请查询断点1",uuid,System.currentTimeMillis()); + debugLog("红字信息表申请查询断点1", uuid, System.currentTimeMillis()); //调用大象接口查询红字信息表明细 AjaxResult queryResult = null; try { queryResult = ElephantUtils.sendRequestWithoutTokenV6New(ElephantConstantsV6.QUERY_RED_CONFIRMATION_ITEM_LIST_LOCALHOST, ElephantConstantsV6.QUERY_RED_CONFIRMATION_ITEM_LIST_METHOD, JSONUtil.parse(param), companyservice); - log.info(" 红字信息表申请大象返回报文封装后:{}",JSONUtil.toJsonStr(queryResult)); + log.info(" 红字信息表申请大象返回报文封装后:{}", JSONUtil.toJsonStr(queryResult)); } catch (UnsupportedEncodingException | InvalidKeyException | NoSuchAlgorithmException e) { log.error("【销项发票】【大象接口】【红字信息表申请】发票请求异常,请求报文{},销方信息{}", JSONUtil.parse(param).toString(), JSONObject.toJSONString(companyservice)); e.printStackTrace(); @@ -2945,8 +2952,8 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { int i = redinfoMapper.updateRedinfo(redinfo); debugLog("断点9", uuid, System.currentTimeMillis()); - if (i<1){ - debugLog("红字订单更新主表信息失败",uuid,System.currentTimeMillis()); + if (i < 1) { + debugLog("红字订单更新主表信息失败", uuid, System.currentTimeMillis()); throw new JianshuiServiceException("红字订单更新主表信息失败"); } @@ -2991,7 +2998,7 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { List detailList = new ArrayList<>(); for (ElephantRedInfoDetail elephantRedInfoDetail : elephantRedInfo.getHZQRXXMXLIST()) { - ElephantRedInfoDetailCase detail = new ElephantRedInfoDetailCase(); + ElephantRedInfoDetailCase detail = new ElephantRedInfoDetailCase(); detail.setDw(elephantRedInfoDetail.getDW()); detail.setJe(elephantRedInfoDetail.getJE()); detail.setSe(elephantRedInfoDetail.getSE()); @@ -3051,22 +3058,22 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { // } - return new HXResponse("0000","查询成功",addRedInfoInvoiceTWO,true); + return new HXResponse("0000", "查询成功", addRedInfoInvoiceTWO, true); } - - - /** 批量开票接口 */ + /** + * 批量开票接口 + */ @Override public HXResponse addInvoiceBeatch(BillInfo billInfo, Companyservice companyservice) throws IllegalAccessException, InstantiationException { - return submitAddInvoice(billInfo,companyservice); + return submitAddInvoice(billInfo, companyservice); } @Override - public void callBackAisino(InvoiceBack invoiceBack, String callBackUrl, String identity,Long id) { + public void callBackAisino(InvoiceBack invoiceBack, String callBackUrl, String identity, Long id) { if (id == null) { log.info("【控制台】发票回调,id为空"); @@ -3096,14 +3103,14 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { try { /** 开票成功处理 */ - if("0000".equals(invoiceBack.getResultCode())){ + if ("0000".equals(invoiceBack.getResultCode())) { invoice.setUpdateBy("0"); invoiceMapper.updateInvoice(invoice); } // 重汽国际不判断null值,给特殊处理下 - if(StrUtil.isEmpty(invoice.getInvoiceResultMsg())){ - invoice.setInvoiceResultMsg(""); + if (StrUtil.isEmpty(invoice.getInvoiceResultMsg())) { + invoice.setInvoiceResultMsg(""); } log.info("【控制台】发票回调接口,发送数据开始,id={},callBackUrl={},param={}", id, callBackUrl, JSONUtil.toJsonStr(invoice)); @@ -3133,7 +3140,7 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { } } } catch (Exception e) { - log.info("【控制台】发票回调接口,发送数据异常,id={},e={}", id,e); + log.info("【控制台】发票回调接口,发送数据异常,id={},e={}", id, e); invoiceBack.setStatus("2"); invoiceBack.setBackMsg("发送数据异常!"); invoiceBackMapper.updateInvoiceBack(invoiceBack); @@ -3141,18 +3148,18 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { } - - /** - * @author kk - * @date 2024/4/8 14:55 - * @param: [billInfo, companyservice] - * @return: 提交开票 - */ + /** + * @author kk + * @date 2024/4/8 14:55 + * @param: [billInfo, companyservice] + * @return: 提交开票 + */ public HXResponse submitAddInvoice(BillInfo billInfo, Companyservice companyservice) throws IllegalAccessException, InstantiationException { // 1.订单唯一校验。新增历史订单部分(删除)。 // 订单号唯一校验 start String outNO = billInfo.getOutTradeOrderno() != null ? billInfo.getOutTradeOrderno() : ""; + String fpqqlsh = billInfo.getFpqqlsh() != null ? billInfo.getFpqqlsh() : ""; if (StrUtil.isEmpty(outNO)) { return new HXResponse("批量开票:订单号为空,请检查报文!"); } @@ -3161,65 +3168,90 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { /** 查找权限ID */ String entId = ""; CompanyserviceProp companyservicePropEntId = companyservicePropMapper.selectPropByKey(companyservice.getCompanyid(), "ent_id"); - if(companyservicePropEntId != null && StrUtil.isNotEmpty(companyservicePropEntId.getValue()) ){ + if (companyservicePropEntId != null && StrUtil.isNotEmpty(companyservicePropEntId.getValue())) { entId = companyservicePropEntId.getValue(); - }else{ + } else { log.info("权限id未配置,需配置key名 ent_id,实现权限管理"); } - String clerk = billInfo.getClerk() != null ? billInfo.getClerk():""; - if(StrUtil.isNotEmpty(clerk)) { + String clerk = billInfo.getClerk() != null ? billInfo.getClerk() : ""; + if (StrUtil.isNotEmpty(clerk)) { CompanyserviceProp companyservicePropClerk = companyservicePropMapper.selectPropByKey(companyservice.getCompanyid(), clerk); - if(companyservicePropClerk != null && StrUtil.isNotEmpty(companyservicePropClerk.getValue()) ){ + if (companyservicePropClerk != null && StrUtil.isNotEmpty(companyservicePropClerk.getValue())) { entId = companyservicePropClerk.getValue(); - }else{ + } else { log.info("权限id未配置,需配置key名 clerk,实现权限管理"); } } - Invoice invoiceValidateTemp = new Invoice(); - List invoicesValidate = invoiceMapper.selectByOutTradeOrdernoList(companyservice.getCompanyid(), outNO, "0"); + Invoice invoice = invoiceMapper.selectBySystemOrderNo(companyservice.getCompanyid(), fpqqlsh); // 开票回调失败防重复处理 start - if (!org.springframework.util.CollectionUtils.isEmpty(invoicesValidate)) { - for (Invoice invoice : invoicesValidate) { - QueryWrapper invoiceBackQueryWrapper = new QueryWrapper<>(); - invoiceBackQueryWrapper.eq("system_orderno", invoice.getOutTradeOrderno()); - InvoiceBack invoiceBackVali = invoiceBackMapper.selectOne(invoiceBackQueryWrapper); - - if (BeanUtil.isEmpty(invoiceBackVali)) { - invoiceBackVali = new InvoiceBack(); - invoiceBackVali.setSystemOrderno(invoice.getOutTradeOrderno()); - invoiceBackVali.setCreateTime(new Date()); - - invoiceBackVali.setId(IdUtils.randomUUID()); - invoiceBackVali.setIdentity(companyservice.getIdentity()); - invoiceBackVali.setBackUrl(""); - invoiceBackVali.setStatus("0"); - invoiceBackVali.setCreateTime(new Date()); - invoiceBackVali.setSystemOrderno(invoice.getOutTradeOrderno()); - invoiceBackVali.setBackMsg(""); - invoiceBackVali.setResultCode("0000"); - invoiceBackVali.setResultMsg("开票成功!"); - invoiceBackVali.setUpdateTime(new Date()); - invoiceBackMapper.insertInvoiceBack(invoiceBackVali); + if(invoice != null){ + boolean con = true; + QueryWrapper invoiceBackQueryWrapper = new QueryWrapper<>(); + invoiceBackQueryWrapper.eq("system_orderno", invoice.getOutTradeOrderno()); + InvoiceBack invoiceBackVali = invoiceBackMapper.selectOne(invoiceBackQueryWrapper); + if (BeanUtil.isEmpty(invoiceBackVali)) { + invoiceBackVali = new InvoiceBack(); + invoiceBackVali.setSystemOrderno(invoice.getFpqqlsh()); + invoiceBackVali.setCreateTime(new Date()); + invoiceBackVali.setId(IdUtils.randomUUID()); + invoiceBackVali.setIdentity(companyservice.getIdentity()); + invoiceBackVali.setBackUrl(""); + invoiceBackVali.setStatus("3"); + invoiceBackVali.setBackMsg("k:数据为空,初始化数据"); + invoiceBackVali.setUpdateTime(new Date()); + invoiceBackMapper.insertInvoiceBack(invoiceBackVali); + } - } else { - invoiceBackVali.setResultCode("0000"); - invoiceBackVali.setResultMsg("开票成功!"); - invoiceBackVali.setStatus("0"); + Integer state = invoice.getState(); + if (state == 20) { + // 开票中 + BillInfo billInfoQuery = new BillInfo(); + billInfoQuery.setFpqqlsh("[\"" + billInfo.getFpqqlsh() + "\"]"); + billInfoQuery.setOutTradeOrderno(billInfo.getOutTradeOrderno()); + log.info("发票回调getOutTradeOrderno()={},invoice.getFpqqlsh()={}", billInfoQuery.getOutTradeOrderno(), billInfoQuery.getFpqqlsh()); + HXResponse resultDxhy = batchQueryInvoices(billInfoQuery, "fpqqlsh", companyservice); + + invoice = invoiceMapper.selectBySystemOrderNo(companyservice.getCompanyid(), fpqqlsh); + if (invoice == null) { + log.info("查询到Invoice信息,回调后还是未查询到Invoice"); + invoiceBackVali.setStatus(InvoiceBackStatusEnum.MULTIPLE_FAILURES.getCode()); + invoiceBackVali.setBackMsg("k:回调后还是未查询到Invoice"); invoiceBackVali.setUpdateTime(new Date()); invoiceBackMapper.updateInvoiceBack(invoiceBackVali); + return new HXResponse("9999", "已开票,开具状态不存在!"); } + } else if (state == 22) { + // 开票失败 + invoiceBackVali.setResultCode("9999"); + invoiceBackVali.setResultMsg("开票失败!"); + invoiceBackVali.setStatus("0"); + invoiceBackVali.setUpdateTime(new Date()); + con = false; + } else if (state == 2) { + // 开票成功 + invoiceBackVali.setResultCode("0000"); + invoiceBackVali.setResultMsg("开票成功!"); + invoiceBackVali.setStatus("0"); + invoiceBackVali.setUpdateTime(new Date()); + } else { + log.info("未识别状态state={}", state); + return new HXResponse("9999", "开票:未识别状态!"); + } + invoiceBackMapper.updateInvoiceBack(invoiceBackVali); - // 再次推送 + // 再次推送 + if(con){ try { callBackAisino(invoiceBackVali, "", companyservice.getIdentity(), invoice.getId()); } catch (Exception e) { log.info("【批量开票】发票回调失败!invoiceId={}", invoice.getId()); } + return new HXResponse("0000", "开票:发票已开具!"); } - return new HXResponse("0000", "批量开票:重复订单已推送!"); + } // end @@ -3236,10 +3268,10 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { // 订单头信息 DDTXX ddtxx = new DDTXX(billInfo); CompanyserviceProp companyserviceProp = companyservicePropMapper.selectPropByKey(companyservice.getCompanyid(), "account_show"); - if (companyserviceProp != null && "1".equals(companyserviceProp.getValue())){ + if (companyserviceProp != null && "1".equals(companyserviceProp.getValue())) { StringBuilder bz = new StringBuilder(); - if (StringUtils.isNotBlank(ddtxx.getBZ())){ + if (StringUtils.isNotBlank(ddtxx.getBZ())) { bz.append(ddtxx.getBZ()).append("\n"); } @@ -3291,17 +3323,17 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { qdtxx.setFJYSLIST(billInfo.getFjyslist());// 附加要素列表 qdtxx.setHWYSLIST(billInfo.getHwysList()); // 货物运输 - if(billInfo.getBdcxsxxList() != null && !billInfo.getBdcxsxxList().isEmpty()){ + if (billInfo.getBdcxsxxList() != null && !billInfo.getBdcxsxxList().isEmpty()) { qdtxx.setBDCXSXX(billInfo.getBdcxsxxList().get(0)); // 不动产销售信息 } - if(billInfo.getJzfwList() != null && !billInfo.getJzfwList().isEmpty()){ + if (billInfo.getJzfwList() != null && !billInfo.getJzfwList().isEmpty()) { qdtxx.setJZFWXX(billInfo.getJzfwList().get(0));// 建筑服务信息 } - if(billInfo.getBdczlxxList() != null && !billInfo.getBdczlxxList().isEmpty()){ + if (billInfo.getBdczlxxList() != null && !billInfo.getBdczlxxList().isEmpty()) { qdtxx.setBDCZLXX(billInfo.getBdczlxxList().get(0));// 不动产租赁信息 } - if(billInfo.getJDCXX() != null ){ - qdtxx.setJDCXX(billInfo.getJDCXX() );// 机动车信息 + if (billInfo.getJDCXX() != null) { + qdtxx.setJDCXX(billInfo.getJDCXX());// 机动车信息 } // qdtxx.setBDCZLXX(billInfo.getBdczlxxList()); //不动产租赁信息 @@ -3319,14 +3351,14 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { } else if (BeanUtil.isNotEmpty(qdtxx.getBDCZLXX())) { // GenerateQdBdczlInvoice 不动产租赁信息 url = ElephantConstantsV6.GENERATE_QD_BDXZL_INVOICE; - }else if( BeanUtil.isNotEmpty(qdtxx.getJDCXX()) ){ + } else if (BeanUtil.isNotEmpty(qdtxx.getJDCXX())) { // GenerateQdjdcxsInvoice 数电机动车销售统一发票 url = ElephantConstantsV6.GENERATE_QD_JDCXS_INVOICE; } // 机动车专票适配 - String jdcbz = billInfo.getJdcbz() != null ? billInfo.getJdcbz():""; - if("1".equals(jdcbz)){ + String jdcbz = billInfo.getJdcbz() != null ? billInfo.getJdcbz() : ""; + if ("1".equals(jdcbz)) { billInfo.setTdys("14"); // (数电机动车专票)发票开具/冲红接口 url = ElephantConstantsV6.GENERATE_QD_JDCZP_INVOICE; @@ -3343,7 +3375,6 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { } - // 开始封装请求报文 ElephantInvoiceAddDTO elephantInvoiceAddDTO = new ElephantInvoiceAddDTO(); elephantInvoiceAddDTO.setDDPCXX(ddpcxx); @@ -3357,7 +3388,6 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { elephantInvoiceAddDTO.setDDZXX(ddzxxes); - AjaxResult queryResult = null; try { queryResult = ElephantUtils.sendRequestWithoutTokenV6New(url, "", JSONUtil.parse(elephantInvoiceAddDTO), companyservice); @@ -3408,6 +3438,7 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { queryBody.put("DDRQQ", "0"); // 订单日期止 queryBody.put("DDRQZ", "0");*/ + queryBody.put("BSWJ", "1"); // queryResult = ElephantUtils.sendRequest(ElephantConstantsV6.ADD_INVOICE_RESULT, JSONUtil.parse(queryBody)); try { queryResult = ElephantUtils.sendRequestWithoutTokenV6New(ElephantConstantsV6.ADD_INVOICE_RESULT_LOCALHOST, ElephantConstantsV6.ADD_INVOICE_RESULT_METHOD, JSONUtil.parse(queryBody), companyservice); @@ -3427,7 +3458,7 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { if (contentJson != null) { String ztdm = contentJson.getString("ZTDM"); // 021002 020111 - if (!StringUtils.equalsAny(ztdm, "020111", "020000", "010000","000000")) { + if (!StringUtils.equalsAny(ztdm, "020111", "020000", "010000", "000000")) { // 开票失败 if (StringUtils.equals("020002", ztdm)) { billInfo.setState(22); @@ -3436,10 +3467,10 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { // kk: 2023/12/5 判断人脸识别的状态 String DDFPZXX = contentJson.getString("DDFPZXX") != null ? contentJson.getString("DDFPZXX") : ""; - if(StrUtil.isNotEmpty(DDFPZXX)){ - DDFPZXX ddfpzxx = BeanUtil.copyProperties(DDFPZXX,DDFPZXX.class); - if(ddfpzxx != null && ddfpzxx.getDDFPXX() != null && "03200".equals(ddfpzxx.getDDFPXX().getDDZT())){ - return new HXResponse("E004",ddfpzxx.getDDFPXX().getDDZTXX() != null ? ddfpzxx.getDDFPXX().getDDZTXX():"发票开具失败,请确认是否人脸识别超期!"); + if (StrUtil.isNotEmpty(DDFPZXX)) { + DDFPZXX ddfpzxx = BeanUtil.copyProperties(DDFPZXX, DDFPZXX.class); + if (ddfpzxx != null && ddfpzxx.getDDFPXX() != null && "03200".equals(ddfpzxx.getDDFPXX().getDDZT())) { + return new HXResponse("E004", ddfpzxx.getDDFPXX().getDDZTXX() != null ? ddfpzxx.getDDFPXX().getDDZTXX() : "发票开具失败,请确认是否人脸识别超期!"); } } @@ -3471,7 +3502,7 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { queryInvoiceBack.setBackUrl(callBackUrl); queryInvoiceBack.setStatus(InvoiceBackStatusEnum.IN_PROCESS.getCode()); queryInvoiceBack.setCreateTime(new Date()); - queryInvoiceBack.setSystemOrderno(billInfo.getOutTradeOrderno()); + queryInvoiceBack.setSystemOrderno(billInfo.getFpqqlsh()); queryInvoiceBack.setBackMsg(""); queryInvoiceBack.setResultCode("0000"); queryInvoiceBack.setResultMsg("开票中,进入队列"); @@ -3480,7 +3511,7 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { } } // 定时拉取保存发票 - AsyncManager.me().execute(new QueryInvoiceTask(billInfo, companyservice, this,invoiceBackMapper)); + AsyncManager.me().execute(new QueryInvoiceTask(billInfo, companyservice, this, invoiceBackMapper)); // 数电的加入金财表 InvoiceAllApiLog allApiLog = new InvoiceAllApiLog(); @@ -3502,18 +3533,4 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { } - - - - - - - - - - - - - - } diff --git a/jianshui-invoice/src/main/java/com/jianshui/invoice/task/AddInvoiceBatchTask.java b/jianshui-invoice/src/main/java/com/jianshui/invoice/task/AddInvoiceBatchTask.java index 72aa9aa..78dd311 100644 --- a/jianshui-invoice/src/main/java/com/jianshui/invoice/task/AddInvoiceBatchTask.java +++ b/jianshui-invoice/src/main/java/com/jianshui/invoice/task/AddInvoiceBatchTask.java @@ -189,7 +189,7 @@ public class AddInvoiceBatchTask extends TimerTask { } else { invoiceBack.setResultCode("9999"); invoiceBack.setResultMsg(resultHx.getMessage()); - invoiceBack.setSystemOrderno(billInfo.getOutTradeOrderno()); + invoiceBack.setSystemOrderno(billInfo.getFpqqlsh()); invoiceBack.setStatus("0"); invoiceBack.setCreateTime(new Date()); invoiceBackMapper.insertInvoiceBack(invoiceBack); @@ -216,7 +216,7 @@ public class AddInvoiceBatchTask extends TimerTask { } else { invoiceBack.setResultCode("9999"); invoiceBack.setResultMsg("开票失败!"); - invoiceBack.setSystemOrderno(billInfo.getOutTradeOrderno()); + invoiceBack.setSystemOrderno(billInfo.getFpqqlsh()); invoiceBack.setStatus("0"); invoiceBack.setCreateTime(new Date()); invoiceBackMapper.insertInvoiceBack(invoiceBack); diff --git a/jianshui-invoice/src/main/java/com/jianshui/invoice/task/InvoiceBackTask.java b/jianshui-invoice/src/main/java/com/jianshui/invoice/task/InvoiceBackTask.java index 20ccc8c..5a063ef 100644 --- a/jianshui-invoice/src/main/java/com/jianshui/invoice/task/InvoiceBackTask.java +++ b/jianshui-invoice/src/main/java/com/jianshui/invoice/task/InvoiceBackTask.java @@ -9,14 +9,13 @@ import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.jianshui.common.core.domain.entity.Companyservice; -import com.jianshui.common.utils.StringUtils; import com.jianshui.common.utils.spring.SpringUtils; import com.jianshui.invoice.constant.aisino.console.AisinoConsoleConstants; import com.jianshui.invoice.domain.*; import com.jianshui.invoice.domain.dto.ExportVehicleDTO; import com.jianshui.invoice.domain.dto.HXResponse; +import com.jianshui.invoice.enums.InvoiceBackStatusEnum; import com.jianshui.invoice.factory.IInvoiceServiceFactory; import com.jianshui.invoice.mapper.BillInfoMapper; import com.jianshui.invoice.mapper.InvoiceBackMapper; @@ -61,15 +60,16 @@ public class InvoiceBackTask { private final String ZQ_BACK_DXHY = "【重汽回调(开票中单据)】"; + private final String ZQ_BACK = "【重汽回调】"; - /** + /* *//** * @author kk * @date 9:03 * @param: [params] * @return: 开票回调 - */ + *//* public void bkParams(String params) { // TODO: 2023/11/9 回调次数处理 // 默认1次 定时任务控制,补偿机制 @@ -172,7 +172,7 @@ public class InvoiceBackTask { } log.info("[重汽回调定时任务执行结束]---"); } - +*/ /** * @author kk @@ -221,113 +221,133 @@ public class InvoiceBackTask { public void sdBackInvoice() { // 发票回调补偿机制。 - log.info("[重汽回调定时任务开始执行]"); - + log.info("================================[重汽回调定时任务开始执行]============================="); + log.info("{}:查询回调表信息,查询条件为:status=0,2,3", ZQ_BACK); QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("status", "0").or().eq("status", "2").or().eq("status", "3"); List invoiceBackList = invoiceBackMapper.selectList(queryWrapper); - log.info("【重汽回调】查询到{}条带回调订单", invoiceBackList.size()); + log.info("{}:查询到{}条带回调订单", ZQ_BACK, invoiceBackList.size()); for (InvoiceBack invoiceBack : invoiceBackList) { String id = invoiceBack.getSystemOrderno(); String identity = invoiceBack.getIdentity(); + log.info("{}:开始处理回调订单,identity={},id={},", ZQ_BACK, identity, id); if (StrUtil.isEmpty(id)) { - log.info("【控制台】发票回调,id为空"); - invoiceBack.setStatus("3"); - invoiceBack.setBackMsg("id为空"); + log.info("{}:发票回调,回调id为空", ZQ_BACK); + invoiceBack.setStatus(InvoiceBackStatusEnum.MULTIPLE_FAILURES.getCode()); + invoiceBack.setBackMsg("运维排查:传入id为空"); invoiceBack.setUpdateTime(new Date()); invoiceBackMapper.updateInvoiceBack(invoiceBack); continue; } - - log.info("【重汽回调】订单号{},开始回调", id); + log.info("{}:订单号{},开始回调", ZQ_BACK, id); ICompanyservicePropService companyserviceProp = SpringUtils.getBean(ICompanyservicePropService.class); CompanyserviceProp secretIdProp = companyserviceProp.selectPropByKey(Long.valueOf(identity), "aisino_callback_url"); if (secretIdProp == null || secretIdProp.getValue() == null || "".equals(secretIdProp.getValue())) { - log.info("【重汽回调】发票回调,未配置回调地址{}",identity); - invoiceBack.setStatus("3"); - invoiceBack.setBackMsg("未配置回调地址"); + log.info("{}发票回调,未配置回调地址{}", ZQ_BACK, identity); + invoiceBack.setStatus(InvoiceBackStatusEnum.MULTIPLE_FAILURES.getCode()); + invoiceBack.setBackMsg("运维排查:未配置回调地址"); invoiceBack.setUpdateTime(new Date()); invoiceBackMapper.updateInvoiceBack(invoiceBack); continue; } String callBackUrl = secretIdProp.getValue(); - log.info("【重汽回调】发票回调,订单号{},回调地址{}",id, callBackUrl); + log.info("{}:发票回调,订单号{},回调地址{}", ZQ_BACK, id, callBackUrl); + + Invoice invoice = invoiceMapper.selectBySystemOrderNo(Long.valueOf(identity), id); - Invoice invoice = invoiceMapper.selectByOutTradeOrderno(Long.valueOf(identity), id, "0"); if (invoice == null) { - log.info("【重汽回调】发票信息未查询到,id={}", id); - invoice = new Invoice(); - invoice.setOutTradeOrderno(invoiceBack.getSystemOrderno()); - invoice.setState(22); - invoice.setMessage( (invoiceBack.getResultMsg() != null && invoiceBack.getResultMsg().length() > 200) ? invoiceBack.getResultMsg().substring(0, 200) : invoiceBack.getResultMsg() ); - } + log.info("{}:当前发票未查询到Invoice信息,开始请求大象接口获取", ZQ_BACK); + log.info("通过billInfo组装,id为:{}", id); + BillInfo billInfo = billInfoMapper.selectBySystemOrderNo(Long.valueOf(identity), id); + if (BeanUtil.isEmpty(billInfo)) { + log.info("{}:billInfo中不存咋,id为:{}", ZQ_BACK, id); + } - if(invoice != null){ - // 明细重插 - List invoiceDetailList = invoiceMapper.selectInvoiceIdForInvoiceDetailList(invoice.getId()); - if(!invoiceDetailList.isEmpty()){ - invoice.setInvoiceDetailList(invoiceDetailList); + // 发票查询 + String messageQhery = getInvoiceQuery(invoiceBack, billInfo); + + invoice = invoiceMapper.selectBySystemOrderNo(Long.valueOf(identity), id); + log.info("{}:调用回调接口拉取后,Invoice存在状态为{},回调查询发票结果为:{}", ZQ_BACK, invoice != null, messageQhery); + if (invoice == null) { + log.info("{}:查询到Invoice信息,回调后还是未查询到Invoice", ZQ_BACK); + invoiceBack.setStatus(InvoiceBackStatusEnum.MULTIPLE_FAILURES.getCode()); + invoiceBack.setBackMsg("k:回调后还是未查询到Invoice"); + invoiceBack.setUpdateTime(new Date()); + invoiceBackMapper.updateInvoiceBack(invoiceBack); + continue; } - } - try { + } - log.info("【重汽回调】发票回调接口,发送数据开始,id={},orderno={},callBackUrl={},param={}", id, invoice.getOutTradeOrderno(), callBackUrl, JSONUtil.toJsonStr(invoice)); - String result = HttpUtil.post(callBackUrl, JSONUtil.toJsonStr(invoice)); - log.info("【重汽回调】发票回调接口,发送数据结束,id={},接口返回信息={}", id, result); - JSONObject jsonObject = JSONUtil.parseObj(result); - if (jsonObject != null) { - String status = jsonObject.get("status") != null ? jsonObject.get("status").toString() : ""; - String message = jsonObject.get("message") != null ? jsonObject.get("message").toString() : ""; - - if ("0000".equals(status)) { - invoiceBack.setStatus("1"); - invoiceBack.setBackMsg(message != null ? message.substring(0, Math.min(message.length(), 200)) : ""); - invoiceBack.setUpdateTime(new Date()); - invoiceBackMapper.updateInvoiceBack(invoiceBack); - } else if ("9999".equals(status)) { - invoiceBack.setStatus("3"); - invoiceBack.setBackMsg(message != null ? message.substring(0, Math.min(message.length(), 200)) : ""); - invoiceBack.setUpdateTime(new Date()); - invoiceBackMapper.updateInvoiceBack(invoiceBack); - } else { - invoiceBack.setStatus("3"); - invoiceBack.setBackMsg(status + message != null ? message.substring(0, Math.min(message.length(), 200)) : ""); - invoiceBack.setUpdateTime(new Date()); - invoiceBackMapper.updateInvoiceBack(invoiceBack); - } + Integer stateInvoice = invoice.getState(); + String fpqqlsh = invoice.getFpqqlsh(); + String ddh = invoice.getOutTradeOrderno(); + log.info("{}:查询到Invoice信息,发票状态为:{}", ZQ_BACK, stateInvoice); + if (stateInvoice == 20) { + // 开票中 + log.info("{}:开具中,调用查询,fpqqlsh={},ddh={}", ZQ_BACK, fpqqlsh, ddh); + BillInfo billInfo = new BillInfo(); + billInfo.setFpqqlsh(invoice.getFpqqlsh()); + billInfo.setOutTradeOrderno(invoice.getOutTradeOrderno()); + // 发票查询 + String messageQhery = getInvoiceQuery(invoiceBack, billInfo); + + invoice = invoiceMapper.selectBySystemOrderNo(Long.valueOf(identity), id); + log.info("{}:调用回调接口拉取后,Invoice存在状态为{},回调查询发票结果为:{}", ZQ_BACK, invoice != null, messageQhery); + if (invoice == null) { + log.info("{}:查询到Invoice信息,回调后还是未查询到Invoice", ZQ_BACK); + invoiceBack.setStatus(InvoiceBackStatusEnum.MULTIPLE_FAILURES.getCode()); + invoiceBack.setBackMsg("k:回调后还是未查询到Invoice"); + invoiceBack.setUpdateTime(new Date()); + invoiceBackMapper.updateInvoiceBack(invoiceBack); continue; } - } catch (Exception e) { - log.info("【重汽回调】发票回调接口,发送数据异常,id={},e={}", id,e.toString()); - invoiceBack.setStatus("2"); - invoiceBack.setBackMsg("发送数据异常"); + + } else if (stateInvoice == 22) { + // 开票失败 + log.info("{}:开具失败,递交回调,fpqqlsh={},ddh={}", ZQ_BACK, fpqqlsh, ddh); + } else if (stateInvoice == 2) { + // 开票成功 + log.info("{}:开具成功,递交回调,fpqqlsh={},ddh={}", ZQ_BACK, fpqqlsh, ddh); + } else { + // 未解析状态 + log.info("{}:查询到Invoice信息,发票状态为:{},未解析状态", ZQ_BACK, stateInvoice); + invoiceBack.setStatus(InvoiceBackStatusEnum.CALLBACK_FAILED.getCode()); + invoiceBack.setBackMsg("发票状态为" + stateInvoice + ",未解析状态"); invoiceBack.setUpdateTime(new Date()); invoiceBackMapper.updateInvoiceBack(invoiceBack); + continue; } - } - log.info("[重汽回调定时任务执行结束]---"); - } + // 明细重插 + List invoiceDetailList = invoiceMapper.selectInvoiceIdForInvoiceDetailList(invoice.getId()); + if (!invoiceDetailList.isEmpty()) { + invoice.setInvoiceDetailList(invoiceDetailList); + } + // 回调重汽 + backZq(id, invoice, callBackUrl, invoiceBack); + } + log.info("=======================[重汽回调定时任务执行结束]================================="); + } /** - * @author kk - * @date 16:12 - * @param: [] - * @return: 开票中发票 查询发票状态并回推 -重汽 - */ + * @author kk + * @date 16:12 + * @param: [] + * @return: 开票中发票 查询发票状态并回推 -重汽 + */ public void sdBackInvoiceQueryDxhy() { // 发票回调补偿机制。 - log.info(ZQ_BACK_DXHY + "开始执行]"); + log.info("============================{}:开始执行,查询条件-5===================================", ZQ_BACK_DXHY); QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("status", "5"); @@ -347,8 +367,8 @@ public class InvoiceBackTask { long minutesBetween = DateUtil.between(now, halfAnHourAgo, DateUnit.MINUTE); // 如果差值大于或等于30分钟,则认为当前时间在半个小时之前 boolean isHalfAnHourAgo = minutesBetween >= 30; - if(!isHalfAnHourAgo){ - log.info(ZQ_BACK_DXHY + "只查询半个小时之前的单据"); + if (!isHalfAnHourAgo) { + log.info("{}只查询半个小时之前的单据,之前的交给系统队列,当前单据号:{}暂不回调", ZQ_BACK_DXHY, invoiceBack.getSystemOrderno()); continue; } @@ -356,7 +376,7 @@ public class InvoiceBackTask { String identity = invoiceBack.getIdentity(); if (StrUtil.isEmpty(id)) { - log.info(ZQ_BACK_DXHY + "发票回调,id为空"); + log.info("{}:发票回调,id为空", ZQ_BACK_DXHY); invoiceBack.setStatus("3"); invoiceBack.setBackMsg("id为空"); invoiceBack.setUpdateTime(new Date()); @@ -364,13 +384,13 @@ public class InvoiceBackTask { continue; } - log.info(ZQ_BACK_DXHY + "订单号{}", id); + log.info("{}:订单号{}", ZQ_BACK_DXHY, id); ICompanyservicePropService companyserviceProp = SpringUtils.getBean(ICompanyservicePropService.class); CompanyserviceProp secretIdProp = companyserviceProp.selectPropByKey(Long.valueOf(identity), "aisino_callback_url"); if (secretIdProp == null || secretIdProp.getValue() == null || "".equals(secretIdProp.getValue())) { - log.info(ZQ_BACK_DXHY + "发票回调,未配置回调地址{}",identity); + log.info("{}:发票回调,未配置回调地址{}", ZQ_BACK_DXHY, identity); invoiceBack.setStatus("3"); invoiceBack.setBackMsg("未配置回调地址"); invoiceBack.setUpdateTime(new Date()); @@ -379,28 +399,22 @@ public class InvoiceBackTask { } String callBackUrl = secretIdProp.getValue(); - log.info(ZQ_BACK_DXHY + "发票回调,订单号{},回调地址{}",id, callBackUrl); + log.info(ZQ_BACK_DXHY + "发票回调,订单号{},回调地址{}", id, callBackUrl); - Invoice invoice = invoiceMapper.selectByOutTradeOrdernoNoUpdateBy(Long.valueOf(identity), id); + Invoice invoice = invoiceMapper.selectBySystemOrderNo(Long.valueOf(identity), id); if (invoice != null) { - log.info("通过Invoice组装,id为:{}",id); -// log.info(ZQ_BACK_DXHY + "发票信息未查询到,id={}", id); -// invoice = new Invoice(); -// invoice.setOutTradeOrderno(invoiceBack.getSystemOrderno()); -// invoice.setState(22); -// invoice.setMessage( (invoiceBack.getResultMsg() != null && invoiceBack.getResultMsg().length() > 200) ? invoiceBack.getResultMsg().substring(0, 200) : invoiceBack.getResultMsg() ); - + log.info("通过Invoice组装,id为:{}", id); // 明细重插 List invoiceDetailList = invoiceMapper.selectInvoiceIdForInvoiceDetailList(invoice.getId()); - if(!invoiceDetailList.isEmpty()){ + if (!invoiceDetailList.isEmpty()) { invoice.setInvoiceDetailList(invoiceDetailList); } - }else { - log.info("通过billInfo组装,id为:{}",id); - BillInfo billInfo = billInfoMapper.selectByOutTradeOrderno(Long.valueOf(identity), id); - if(BeanUtil.isEmpty(billInfo)){ - log.info("billInfo中不存咋,id为:{}",id); + } else { + log.info("通过billInfo组装,id为:{}", id); + BillInfo billInfo = billInfoMapper.selectBySystemOrderNo(Long.valueOf(identity), id); + if (BeanUtil.isEmpty(billInfo)) { + log.info("billInfo中不存咋,id为:{}", id); } Invoice invoice1 = new Invoice(); invoice1.setFpqqlsh(billInfo.getFpqqlsh()); @@ -408,9 +422,9 @@ public class InvoiceBackTask { invoice1.setOutTradeOrderno(billInfo.getOutTradeOrderno()); } - Integer state = invoice.getState() != null ? invoice.getState() :1; - log.info(ZQ_BACK_DXHY + "id={},state={}",id,state); - log.info(ZQ_BACK_DXHY + "请求大象接口更新发票状态,id={},state={}",id,state); + Integer state = invoice.getState() != null ? invoice.getState() : 1; + log.info(ZQ_BACK_DXHY + "id={},state={}", id, state); + log.info(ZQ_BACK_DXHY + "请求大象接口更新发票状态,id={},state={}", id, state); IInvoiceApiService invoiceService = invoiceServiceFactory.getService("elephantV6_invoice"); Companyservice companyservice = new Companyservice(); @@ -419,66 +433,221 @@ public class InvoiceBackTask { BillInfo billInfo = new BillInfo(); billInfo.setFpqqlsh("[\"" + invoice.getFpqqlsh() + "\"]"); billInfo.setOutTradeOrderno(invoice.getOutTradeOrderno()); - log.info("发票回调invoice.id={},getOutTradeOrderno()={},invoice.getFpqqlsh()={}",id,invoice.getOutTradeOrderno(),invoice.getFpqqlsh()); + log.info("发票回调invoice.id={},getOutTradeOrderno()={},invoice.getFpqqlsh()={}", id, invoice.getOutTradeOrderno(), invoice.getFpqqlsh()); HXResponse resultDxhy = invoiceService.batchQueryInvoices(billInfo, "fpqqlsh", companyservice); - log.info("发票回调id={}",id); - invoice = invoiceMapper.selectByOutTradeOrdernoNoUpdateBy(Long.valueOf(identity), id); + log.info("发票回调id={}", id); + invoice = invoiceMapper.selectBySystemOrderNo(Long.valueOf(identity), id); if (invoice == null) { log.info(ZQ_BACK_DXHY + "重新拉取结果后,发票信息未查询到,id={}", id); invoice = new Invoice(); invoice.setOutTradeOrderno(invoiceBack.getSystemOrderno()); invoice.setState(22); - invoice.setMessage( (invoiceBack.getResultMsg() != null && invoiceBack.getResultMsg().length() > 200) ? invoiceBack.getResultMsg().substring(0, 200) : invoiceBack.getResultMsg() ); + invoice.setMessage((invoiceBack.getResultMsg() != null && invoiceBack.getResultMsg().length() > 200) ? invoiceBack.getResultMsg().substring(0, 200) : invoiceBack.getResultMsg()); continue; } state = invoice.getState(); - log.info(ZQ_BACK_DXHY + "拉去后查询状态为,id={},state={}",id,state); + log.info(ZQ_BACK_DXHY + "拉去后查询状态为,id={},state={}", id, state); - if( state == 20 ){ - log.info(ZQ_BACK_DXHY + "20为开票中,不回调,id={},state={}",id,state); + if (state == 20) { + log.info(ZQ_BACK_DXHY + "20为开票中,不回调,id={},state={}", id, state); continue; } - try { + // 回调重汽 + backZq(id, invoice, callBackUrl, invoiceBack); - log.info(ZQ_BACK_DXHY + "发票回调接口,发送数据开始,id={},orderno={},callBackUrl={},param={}", id, invoice.getOutTradeOrderno(), callBackUrl, JSONUtil.toJsonStr(invoice)); - String result = HttpUtil.post(callBackUrl, JSONUtil.toJsonStr(invoice)); - log.info(ZQ_BACK_DXHY + "发票回调接口,发送数据结束,id={},接口返回信息={}", id, result); - JSONObject jsonObject = JSONUtil.parseObj(result); - if (jsonObject != null) { - String status = jsonObject.get("status") != null ? jsonObject.get("status").toString() : ""; - String message = jsonObject.get("message") != null ? jsonObject.get("message").toString() : ""; - - if ("0000".equals(status)) { - invoiceBack.setStatus("1"); - invoiceBack.setBackMsg(message != null ? message.substring(0, Math.min(message.length(), 200)) : ""); - invoiceBack.setUpdateTime(new Date()); - invoiceBackMapper.updateInvoiceBack(invoiceBack); - } else if ("9999".equals(status)) { - invoiceBack.setStatus("3"); - invoiceBack.setBackMsg(message != null ? message.substring(0, Math.min(message.length(), 200)) : ""); - invoiceBack.setUpdateTime(new Date()); - invoiceBackMapper.updateInvoiceBack(invoiceBack); - } else { - invoiceBack.setStatus("3"); - invoiceBack.setBackMsg(status + message != null ? message.substring(0, Math.min(message.length(), 200)) : ""); - invoiceBack.setUpdateTime(new Date()); - invoiceBackMapper.updateInvoiceBack(invoiceBack); - } + } + log.info(ZQ_BACK_DXHY + "定时任务执行结束---"); + } + + + + /** 回调重汽 */ + public void backZq(String id, Invoice invoice, String callBackUrl, InvoiceBack invoiceBack) { + try { + log.info("【重汽回调】发票回调接口,发送数据开始,id={},orderno={},callBackUrl={},param={}", id, invoice.getOutTradeOrderno(), callBackUrl, JSONUtil.toJsonStr(invoice)); + String result = HttpUtil.post(callBackUrl, JSONUtil.toJsonStr(invoice)); + log.info("【重汽回调】发票回调接口,发送数据结束,id={},接口返回信息={}", id, result); + JSONObject jsonObject = JSONUtil.parseObj(result); + String status = jsonObject.get("status") != null ? jsonObject.get("status").toString() : ""; + String message = jsonObject.get("message") != null ? jsonObject.get("message").toString() : ""; + + if (message.length() > 200) { + message = message.substring(0, Math.min(message.length(), 200)); + } + invoiceBack.setBackMsg("zq:" + message); + + if ("0000".equals(status)) { + invoiceBack.setStatus("1"); + } else if ("9999".equals(status)) { + invoiceBack.setStatus("3"); + } else { + invoiceBack.setStatus("3"); + invoiceBack.setResultMsg("k:客户系统回调异常,status=" + status); + } + invoiceBack.setUpdateTime(new Date()); + invoiceBackMapper.updateInvoiceBack(invoiceBack); + + } catch (Exception e) { + log.info("{}:发票回调接口,发送数据异常,id={},e={}", ZQ_BACK, id, e.toString()); + invoiceBack.setStatus(InvoiceBackStatusEnum.MULTIPLE_FAILURES.getCode()); + invoiceBack.setBackMsg("运维:发送数据异常"); + invoiceBack.setUpdateTime(new Date()); + invoiceBackMapper.updateInvoiceBack(invoiceBack); + } + } + + + + /** + * 查询发票查询 + */ + private String getInvoiceQuery(InvoiceBack invoiceBack, BillInfo billInfo) { + IInvoiceApiService invoiceService = invoiceServiceFactory.getService("elephantV6_invoice"); + Companyservice companyservice = new Companyservice(); + companyservice.setCompanyid(Long.valueOf(invoiceBack.getIdentity())); + companyservice.setSellertax(billInfo.getSellerTaxnum()); + + BillInfo billInfoQuery = new BillInfo(); + billInfoQuery.setFpqqlsh("[\"" + billInfo.getFpqqlsh() + "\"]"); + billInfoQuery.setOutTradeOrderno(billInfo.getOutTradeOrderno()); + + log.info("发票回调getOutTradeOrderno()={},invoice.getFpqqlsh()={}", billInfoQuery.getOutTradeOrderno(), billInfoQuery.getFpqqlsh()); + HXResponse resultDxhy = invoiceService.batchQueryInvoices(billInfoQuery, "fpqqlsh", companyservice); + return resultDxhy.getMessage(); + } + + + + /** + * @author kk + * @date 2024/4/10 20:32 + * @param: [] + * @return: 重汽数电回推补偿机制。 + */ + public void sdBackInvoiceJiuBan() { + + // 发票回调补偿机制。 + log.info("================================[重汽回调定时任务开始执行]============================="); + log.info("{}:查询回调表信息,查询条件为:status=7", ZQ_BACK); + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("status", "7"); + List invoiceBackList = invoiceBackMapper.selectList(queryWrapper); + + log.info("{}:查询到{}条带回调订单", ZQ_BACK, invoiceBackList.size()); + for (InvoiceBack invoiceBack : invoiceBackList) { + + String id = invoiceBack.getSystemOrderno(); + String identity = invoiceBack.getIdentity(); + + log.info("{}:开始处理回调订单,identity={},id={},", ZQ_BACK, identity, id); + if (StrUtil.isEmpty(id)) { + log.info("{}:发票回调,回调id为空", ZQ_BACK); + invoiceBack.setStatus(InvoiceBackStatusEnum.MULTIPLE_FAILURES.getCode()); + invoiceBack.setBackMsg("运维排查:传入id为空"); + invoiceBack.setUpdateTime(new Date()); + invoiceBackMapper.updateInvoiceBack(invoiceBack); + continue; + } + log.info("{}:订单号{},开始回调", ZQ_BACK, id); + + ICompanyservicePropService companyserviceProp = SpringUtils.getBean(ICompanyservicePropService.class); + CompanyserviceProp secretIdProp = companyserviceProp.selectPropByKey(Long.valueOf(identity), "aisino_callback_url"); + + if (secretIdProp == null || secretIdProp.getValue() == null || "".equals(secretIdProp.getValue())) { + log.info("{}发票回调,未配置回调地址{}", ZQ_BACK, identity); + invoiceBack.setStatus(InvoiceBackStatusEnum.MULTIPLE_FAILURES.getCode()); + invoiceBack.setBackMsg("运维排查:未配置回调地址"); + invoiceBack.setUpdateTime(new Date()); + invoiceBackMapper.updateInvoiceBack(invoiceBack); + continue; + } + + String callBackUrl = secretIdProp.getValue(); + log.info("{}:发票回调,订单号{},回调地址{}", ZQ_BACK, id, callBackUrl); + + Invoice invoice = invoiceMapper.selectByOutTradeOrdernoNoUpdateBy(Long.valueOf(identity), id); + + if (invoice == null) { + log.info("{}:当前发票未查询到Invoice信息,开始请求大象接口获取", ZQ_BACK); + log.info("通过billInfo组装,id为:{}", id); + BillInfo billInfo = billInfoMapper.selectByOutTradeOrderno(Long.valueOf(identity), id); + if (BeanUtil.isEmpty(billInfo)) { + log.info("{}:billInfo中不存咋,id为:{}", ZQ_BACK, id); + } + + // 发票查询 + String messageQhery = getInvoiceQuery(invoiceBack, billInfo); + + invoice = invoiceMapper.selectByOutTradeOrdernoNoUpdateBy(Long.valueOf(identity), id); + log.info("{}:调用回调接口拉取后,Invoice存在状态为{},回调查询发票结果为:{}", ZQ_BACK, invoice != null, messageQhery); + if (invoice == null) { + log.info("{}:查询到Invoice信息,回调后还是未查询到Invoice", ZQ_BACK); + invoiceBack.setStatus(InvoiceBackStatusEnum.MULTIPLE_FAILURES.getCode()); + invoiceBack.setBackMsg("k:回调后还是未查询到Invoice"); + invoiceBack.setUpdateTime(new Date()); + invoiceBackMapper.updateInvoiceBack(invoiceBack); continue; } - } catch (Exception e) { - log.info(ZQ_BACK_DXHY + "发票回调接口,发送数据异常,id={},e={}", id,e.toString()); - invoiceBack.setStatus("2"); - invoiceBack.setBackMsg("发送数据异常"); + + } + + Integer stateInvoice = invoice.getState(); + String fpqqlsh = invoice.getFpqqlsh(); + String ddh = invoice.getOutTradeOrderno(); + log.info("{}:查询到Invoice信息,发票状态为:{}", ZQ_BACK, stateInvoice); + if (stateInvoice == 20) { + // 开票中 + log.info("{}:开具中,调用查询,fpqqlsh={},ddh={}", ZQ_BACK, fpqqlsh, ddh); + BillInfo billInfo = new BillInfo(); + billInfo.setFpqqlsh(invoice.getFpqqlsh()); + billInfo.setOutTradeOrderno(invoice.getOutTradeOrderno()); + // 发票查询 + String messageQhery = getInvoiceQuery(invoiceBack, billInfo); + + invoice = invoiceMapper.selectByOutTradeOrdernoNoUpdateBy(Long.valueOf(identity), id); + log.info("{}:调用回调接口拉取后,Invoice存在状态为{},回调查询发票结果为:{}", ZQ_BACK, invoice != null, messageQhery); + if (invoice == null) { + log.info("{}:查询到Invoice信息,回调后还是未查询到Invoice", ZQ_BACK); + invoiceBack.setStatus(InvoiceBackStatusEnum.MULTIPLE_FAILURES.getCode()); + invoiceBack.setBackMsg("k:回调后还是未查询到Invoice"); + invoiceBack.setUpdateTime(new Date()); + invoiceBackMapper.updateInvoiceBack(invoiceBack); + continue; + } + + } else if (stateInvoice == 22) { + // 开票失败 + log.info("{}:开具失败,递交回调,fpqqlsh={},ddh={}", ZQ_BACK, fpqqlsh, ddh); + } else if (stateInvoice == 2) { + // 开票成功 + log.info("{}:开具成功,递交回调,fpqqlsh={},ddh={}", ZQ_BACK, fpqqlsh, ddh); + } else { + // 未解析状态 + log.info("{}:查询到Invoice信息,发票状态为:{},未解析状态", ZQ_BACK, stateInvoice); + invoiceBack.setStatus(InvoiceBackStatusEnum.CALLBACK_FAILED.getCode()); + invoiceBack.setBackMsg("发票状态为" + stateInvoice + ",未解析状态"); invoiceBack.setUpdateTime(new Date()); invoiceBackMapper.updateInvoiceBack(invoiceBack); + continue; + } + + // 明细重插 + List invoiceDetailList = invoiceMapper.selectInvoiceIdForInvoiceDetailList(invoice.getId()); + if (!invoiceDetailList.isEmpty()) { + invoice.setInvoiceDetailList(invoiceDetailList); } + + // 回调重汽 + backZq(id, invoice, callBackUrl, invoiceBack); } - log.info(ZQ_BACK_DXHY + "定时任务执行结束---"); + log.info("=======================[重汽回调定时任务执行结束]================================="); } } + + + diff --git a/jianshui-invoice/src/main/java/com/jianshui/invoice/task/QueryInvoiceTask.java b/jianshui-invoice/src/main/java/com/jianshui/invoice/task/QueryInvoiceTask.java index 01ef10e..d711bc9 100644 --- a/jianshui-invoice/src/main/java/com/jianshui/invoice/task/QueryInvoiceTask.java +++ b/jianshui-invoice/src/main/java/com/jianshui/invoice/task/QueryInvoiceTask.java @@ -112,7 +112,7 @@ public class QueryInvoiceTask extends TimerTask { invoiceBackVali.setBackUrl(""); invoiceBackVali.setStatus("0"); invoiceBackVali.setCreateTime(new Date()); - invoiceBackVali.setSystemOrderno(invoice.getOutTradeOrderno()); + invoiceBackVali.setSystemOrderno(invoice.getFpqqlsh()); invoiceBackVali.setBackMsg(""); invoiceBackVali.setResultCode(kpStatus); invoiceBackVali.setResultMsg(kpMsg); diff --git a/jianshui-invoice/src/main/java/com/jianshui/invoice/task/RedInvoiceBackTask.java b/jianshui-invoice/src/main/java/com/jianshui/invoice/task/RedInvoiceBackTask.java index 1136c7e..16b000c 100644 --- a/jianshui-invoice/src/main/java/com/jianshui/invoice/task/RedInvoiceBackTask.java +++ b/jianshui-invoice/src/main/java/com/jianshui/invoice/task/RedInvoiceBackTask.java @@ -118,7 +118,7 @@ public class RedInvoiceBackTask { //处理返回结果 InvoiceBack invoiceBack = new InvoiceBack(); invoiceBack.setId(IdUtil.randomUUID()); - invoiceBack.setSystemOrderno(invoice.getOutTradeOrderno()); + invoiceBack.setSystemOrderno(invoice.getFpqqlsh()); invoiceBack.setBackUrl(secretIdProp.getValue()); invoiceBack.setIdentity(String.valueOf(companyserviceProp.getCompanyid())); invoiceBack.setCreateTime(new Date()); diff --git a/jianshui-invoice/src/main/resources/mapper/invoice/InvoiceMapper.xml b/jianshui-invoice/src/main/resources/mapper/invoice/InvoiceMapper.xml index d67615c..6220631 100644 --- a/jianshui-invoice/src/main/resources/mapper/invoice/InvoiceMapper.xml +++ b/jianshui-invoice/src/main/resources/mapper/invoice/InvoiceMapper.xml @@ -260,6 +260,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where a.company_id = #{companyId} and a.out_trade_orderno = #{out_trade_orderno} and a.update_by = #{update_by} order by a.id desc + +