From 0818e493d3d9c8511ec6afe432a77d7af775d60a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=B3=89=E4=BD=B3?= <1107186916@qq.com> Date: Wed, 4 Nov 2026 01:28:52 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E4=BF=AE=E5=A4=8D=E5=BC=80=E7=A5=A8?= =?UTF-8?q?=E7=94=B3=E8=AF=B7A303-4=E9=A2=84=E6=A3=80=E5=91=BD=E4=B8=AD?= =?UTF-8?q?=E5=8D=B3=E6=95=B4=E5=8D=95=E8=BF=94=E5=9B=9E=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E5=A4=9A=E5=BC=A0=E5=8F=91=E7=A5=A8=E5=BC=A0=E6=AC=A1=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E6=96=AD=E7=82=B9=E7=BB=AD=E6=8E=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/InvoiceApplicationServiceImpl.java | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/InvoiceApplicationServiceImpl.java b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/InvoiceApplicationServiceImpl.java index 33ed3b10..2438e690 100644 --- a/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/InvoiceApplicationServiceImpl.java +++ b/blade-service/blade-transport/src/main/java/org/springblade/transport/service/impl/InvoiceApplicationServiceImpl.java @@ -782,31 +782,40 @@ public class InvoiceApplicationServiceImpl extends BaseServiceImpl sheetBillNos = sheets.stream().map(sheet -> this.sheetBillNo(entity, sheet, sheets.size())).toList(); // A303-4 幂等预检:按全部候选 billno 查询金蝶是否已生成开票申请单(防上次推送成功但本地回滚的断链重推), - // 已生成的张次幂等跳过,未生成的张次重新推送 + // 实测返回 billno 与推送值完全一致,按 billno 精确匹配;部分张次已生成时不可整单提前返回,须断点续推剩余张次 BfiInvoiceApplyQueryDTO idempotentQuery = new BfiInvoiceApplyQueryDTO(); idempotentQuery.setPageNo(1); idempotentQuery.setPageSize(Math.max(sheets.size(), 10)); idempotentQuery.setBillno(sheetBillNos); - Set existSheetBillNos = new LinkedHashSet<>(); + Map existApplyByBillNo = new LinkedHashMap<>(); BfiPageVO existPage = bfiService.queryInvoiceApply(idempotentQuery); if (existPage != null && Func.isNotEmpty(existPage.getRows())) { for (BfiInvoiceApplyVO existApply : existPage.getRows()) { if (existApply != null && Func.isNotBlank(existApply.getBillno()) && sheetBillNos.contains(existApply.getBillno())) { - existSheetBillNos.add(existApply.getBillno()); - // 金蝶已生成:直接回填视为同步成功(勾稽纠偏),星瀚内码一并回填(A902 附件上传定位用) - log.info("开票申请[{}]经 A303-4 查得金蝶开票申请单已生成(单据编号[{}],星瀚内码[{}]),跳过重复推送直接回填", + existApplyByBillNo.put(existApply.getBillno(), existApply); + log.info("开票申请[{}]经 A303-4 查得金蝶开票申请单已生成(单据编号[{}],星瀚内码[{}]),幂等跳过推送", entity.getApplicationNo(), existApply.getBillno(), existApply.getId()); - entity.setKingdeeBillNo(existApply.getBillno()); - entity.setKingdeeBillId(existApply.getId() == null ? null : String.valueOf(existApply.getId())); - entity.setKingdeeStatus(KingdeeBfiConstant.KINGDEE_STATUS_SYNCED); - entity.setSyncedTime(LocalDateTime.now()); - updateById(entity); - record(entity.getId(), "sync", "同步金蝶(勾稽回填)", TransportBusiConstant.APPROVED, TransportBusiConstant.APPROVED, null, existApply.getBillno()); - return existApply.getBillno(); } } } + // 全部张次金蝶均已生成:直接勾稽回填视为同步成功(星瀚内码一并回填,A902 附件上传定位用) + if (!existApplyByBillNo.isEmpty() && existApplyByBillNo.keySet().containsAll(sheetBillNos)) { + entity.setKingdeeBillNo(String.join(",", existApplyByBillNo.keySet())); + entity.setKingdeeBillId(existApplyByBillNo.values().stream() + .map(BfiInvoiceApplyVO::getId).filter(Objects::nonNull).findFirst().map(String::valueOf).orElse(null)); + entity.setKingdeeStatus(KingdeeBfiConstant.KINGDEE_STATUS_SYNCED); + entity.setSyncedTime(LocalDateTime.now()); + updateById(entity); + record(entity.getId(), "sync", "同步金蝶(勾稽回填)", TransportBusiConstant.APPROVED, TransportBusiConstant.APPROVED, null, entity.getKingdeeBillNo()); + return entity.getKingdeeBillNo(); + } + // 部分张次已生成:先回填星瀚内码,已生成张次在下方逐张循环幂等跳过,未生成张次继续推送 + Set existSheetBillNos = existApplyByBillNo.keySet(); + if (Func.isBlank(entity.getKingdeeBillId())) { + entity.setKingdeeBillId(existApplyByBillNo.values().stream() + .map(BfiInvoiceApplyVO::getId).filter(Objects::nonNull).findFirst().map(String::valueOf).orElse(null)); + } // 组装 A303-1 开票申请单(字段映射见设计文档 6.3/6.4) if (Func.isBlank(entity.getIssuerName())) { throw new ServiceException("推送金蝶开票申请失败:开票单位(销方)为空");