发票信息传输BIP新增发票类型+发票号码拼接

This commit is contained in:
李贵强 2025-07-16 13:23:53 +08:00
parent 9cca6ddc84
commit 8c4261311f
1 changed files with 74 additions and 0 deletions

View File

@ -25,6 +25,10 @@ import okhttp3.*;
import shkd.utils.DobeDWUtils;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
/**
@ -661,6 +665,8 @@ public class YongyouBIPOperation extends AbstractOperationServicePlugIn implemen
Long commonTaxRateId = null;
boolean hasDifferentTaxRates = false;
// 新增用于存储发票类型和号码的映射关系
Map<String, Set<String>> invoiceTypeToNumbersMap = new LinkedHashMap<>();
// 遍历发票
for (DynamicObject invoiceObj : invoiceEntry) {
@ -676,6 +682,14 @@ public class YongyouBIPOperation extends AbstractOperationServicePlugIn implemen
DynamicObject invoice = invoiceBill.getDynamicObject("invoice");
if (invoice != null) {
String invoiceName = invoice.getString("name");
String invoiceNo = invoiceBill.getString("invoiceno");
// 新增收集发票类型和号码信息
if (invoiceName != null && invoiceNo != null) {
// 专票在前处理如果包含"专用"则放在前面否则放在后面
String typeKey = invoiceName.contains("专用") ? "1_" + invoiceName : "2_" + invoiceName;
invoiceTypeToNumbersMap.computeIfAbsent(typeKey, k -> new LinkedHashSet<>()).add(invoiceNo);
}
if (invoiceName != null && invoiceName.contains("专用")) {
// 发票登记-发票明细只有一行
DynamicObjectCollection invoiceDetails = invoiceBill.getDynamicObjectCollection("invoiceentry");
@ -741,6 +755,30 @@ public class YongyouBIPOperation extends AbstractOperationServicePlugIn implemen
items.put("taxcodeid", "CN07");
}
// 新增构建发票类型和号码的拼接字符串
if (!invoiceTypeToNumbersMap.isEmpty()) {
StringBuilder def4Builder = new StringBuilder();
// 按照排序处理专票在前
invoiceTypeToNumbersMap.entrySet().stream()
.sorted(Map.Entry.comparingByKey())
.forEach(entry -> {
String typeName = entry.getKey().substring(2); // 去掉排序前缀
Set<String> numbers = entry.getValue();
if (def4Builder.length() > 0) {
def4Builder.append(",");
}
def4Builder.append(typeName).append(":").append(String.join(",", numbers));
});
// 截取200字符
String def4Value = def4Builder.toString();
if (def4Value.length() > 200) {
def4Value = def4Value.substring(0, 200);
}
items.put("def4", def4Value);
}
if("unaudit".equals(eventName)){
//如果此时是反审核则需要将金额置为负数
@ -782,6 +820,9 @@ public class YongyouBIPOperation extends AbstractOperationServicePlugIn implemen
Long commonTaxRateId = null;
boolean hasDifferentTaxRates = false;
// 新增用于存储发票类型和号码的映射关系
Map<String, Set<String>> invoiceTypeToNumbersMap = new LinkedHashMap<>();
// 遍历发票
for (DynamicObject invoiceObj : invoiceEntry) {
DynamicObject invoiceBillF7 = invoiceObj.getDynamicObject("inventry_invoicebill");
@ -795,6 +836,13 @@ public class YongyouBIPOperation extends AbstractOperationServicePlugIn implemen
DynamicObject invoice = invoiceBill.getDynamicObject("invoice");
if (invoice != null) {
String invoiceName = invoice.getString("name");
String invoiceNo = invoiceBill.getString("invoiceno");
// 新增收集发票类型和号码信息
if (invoiceName != null && invoiceNo != null) {
// 专票在前处理如果包含"专用"则放在前面否则放在后面
String typeKey = invoiceName.contains("专用") ? "1_" + invoiceName : "2_" + invoiceName;
invoiceTypeToNumbersMap.computeIfAbsent(typeKey, k -> new LinkedHashSet<>()).add(invoiceNo);
}
if (invoiceName != null && invoiceName.contains("专用")) {
// 发票登记-发票明细只有一行
DynamicObjectCollection invoiceDetails = invoiceBill.getDynamicObjectCollection("invoiceentry");
@ -860,6 +908,32 @@ public class YongyouBIPOperation extends AbstractOperationServicePlugIn implemen
items.put("taxcodeid", "CN07");
}
// 新增构建发票类型和号码的拼接字符串
if (!invoiceTypeToNumbersMap.isEmpty()) {
StringBuilder def4Builder = new StringBuilder();
// 按照排序处理专票在前
invoiceTypeToNumbersMap.entrySet().stream()
.sorted(Map.Entry.comparingByKey())
.forEach(entry -> {
String typeName = entry.getKey().substring(2); // 去掉排序前缀
Set<String> numbers = entry.getValue();
if (def4Builder.length() > 0) {
def4Builder.append(",");
}
def4Builder.append(typeName).append(":").append(String.join(",", numbers));
});
// 截取200字符
String def4Value = def4Builder.toString();
if (def4Value.length() > 200) {
def4Value = def4Value.substring(0, 200);
}
items.put("def4", def4Value);
}
if("unaudit".equals(eventName)){
//如果此时是反审核则需要将金额置为负数
items.put("local_tax_de","-"+items.getString("local_tax_de"));