|
|
|
@ -103,7 +103,7 @@ public class BotpService { |
|
|
|
} |
|
|
|
} |
|
|
|
ConvertMappingPlan plan = buildMappingPlan(convertFieldmappingEntryList, srcFormHead, destFormHead); |
|
|
|
ConvertMappingPlan plan = buildMappingPlan(convertFieldmappingEntryList, srcFormHead, destFormHead); |
|
|
|
List<ObjectValue> sourceBills = loadSourceBills(plan, srcFormHead, srcBillIds); |
|
|
|
List<ObjectValue> sourceBills = loadSourceBills(plan, srcFormHead, srcBillIds); |
|
|
|
Map<String, List<ConvertSourceRowGroup>> entryGroups = buildEntryGroups(plan, sourceBills, convertRule); |
|
|
|
Map<String, List<ConvertSourceRowGroup>> entryGroups = buildEntryGroups(plan, sourceBills); |
|
|
|
BtpTransformResult result = initDestBillData(plan, sourceBills, convertRule, entryGroups); |
|
|
|
BtpTransformResult result = initDestBillData(plan, sourceBills, convertRule, entryGroups); |
|
|
|
ObjectValue destBillData = result.getBillDataList().getObject(0); |
|
|
|
ObjectValue destBillData = result.getBillDataList().getObject(0); |
|
|
|
applyMappings(plan, destBillData, sourceBills, convertRule, entryGroups); |
|
|
|
applyMappings(plan, destBillData, sourceBills, convertRule, entryGroups); |
|
|
|
@ -358,59 +358,52 @@ public class BotpService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 为每个目标分录表预计算归并结果,供建骨架与逐列映射共用(避免算两遍)。 |
|
|
|
* 为每个目标分录表预计算源行分组,供建骨架与逐列映射共用(避免算两遍)。 |
|
|
|
* |
|
|
|
* |
|
|
|
* @param plan 映射计划。 |
|
|
|
* @param plan 映射计划。 |
|
|
|
* @param sourceBills 源单数据。 |
|
|
|
* @param sourceBills 源单数据。 |
|
|
|
* @param convertRule 转换规则(提供行键字段)。 |
|
|
|
* @return 目标分录表名 → 源行组。 |
|
|
|
* @return 目标分录表名 → 归并后的源行组。 |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private Map<String, List<ConvertSourceRowGroup>> buildEntryGroups(ConvertMappingPlan plan, List<ObjectValue> sourceBills, ConvertRule convertRule) { |
|
|
|
private Map<String, List<ConvertSourceRowGroup>> buildEntryGroups(ConvertMappingPlan plan, List<ObjectValue> sourceBills) { |
|
|
|
Map<String, List<ConvertSourceRowGroup>> entryGroups = new LinkedHashMap<>(); |
|
|
|
Map<String, List<ConvertSourceRowGroup>> entryGroups = new LinkedHashMap<>(); |
|
|
|
for (String destEntryTable : plan.getDestEntryColumns().keySet()) { |
|
|
|
for (String destEntryTable : plan.getDestEntryColumns().keySet()) { |
|
|
|
entryGroups.put(destEntryTable, groupSourceRows(plan, sourceBills, destEntryTable, convertRule.getGroupByField())); |
|
|
|
entryGroups.put(destEntryTable, groupSourceRows(plan, sourceBills, destEntryTable)); |
|
|
|
} |
|
|
|
} |
|
|
|
return entryGroups; |
|
|
|
return entryGroups; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 把批次内所有源单的某张源分录表摊平后按行键归并。 |
|
|
|
* 把批次内所有源单的某张源分录表摊平成「一行源行一组」。 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* <p><b>为什么分录不再按 {@code group_by_field} 归并</b>:分单字段是<b>源单表头</b>级的, |
|
|
|
|
|
|
|
* 只用来决定「生成几张目标单」(见 {@code ConvertOrchestrator#splitByGroup})。 |
|
|
|
|
|
|
|
* 分录表上没有这一列,拿它当行键会让每一行都取到 null、全部塌进同一个分组, |
|
|
|
|
|
|
|
* 最终一张目标单只剩一条明细——即使它合并了多张源单的全部源行。</p> |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* <p>保持「每条源分录行 → 一条目标分录行」:按分组合并时,每张目标单保留该组内 |
|
|
|
|
|
|
|
* 全部源单的全部明细行,不丢行、不互相覆盖。同一目标行的多值折算仍由 |
|
|
|
|
|
|
|
* {@code merge_method} 在映射阶段决定(当前每条目标行只对应一条源行,故按「直接取」处理)。</p> |
|
|
|
* |
|
|
|
* |
|
|
|
* @param plan 映射计划。 |
|
|
|
* @param plan 映射计划。 |
|
|
|
* @param sourceBills 源单数据。 |
|
|
|
* @param sourceBills 源单数据。 |
|
|
|
* @param destEntryTable 目标分录表名。 |
|
|
|
* @param destEntryTable 目标分录表名。 |
|
|
|
* @param mergeKeyField 行键字段,空表示不合并。 |
|
|
|
|
|
|
|
* @return 分组结果,每组对应一条目标分录行。 |
|
|
|
* @return 分组结果,每组对应一条目标分录行。 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private List<ConvertSourceRowGroup> groupSourceRows(ConvertMappingPlan plan, List<ObjectValue> sourceBills, |
|
|
|
private List<ConvertSourceRowGroup> groupSourceRows(ConvertMappingPlan plan, List<ObjectValue> sourceBills, |
|
|
|
String destEntryTable, String mergeKeyField) { |
|
|
|
String destEntryTable) { |
|
|
|
String srcEntryTable = resolveSourceEntryTable(plan, destEntryTable); |
|
|
|
String srcEntryTable = resolveSourceEntryTable(plan, destEntryTable); |
|
|
|
List<ConvertSourceRow> flatRows = new ArrayList<>(); |
|
|
|
List<ConvertSourceRowGroup> groups = new ArrayList<>(); |
|
|
|
for (ObjectValue bill : sourceBills) { |
|
|
|
for (ObjectValue bill : sourceBills) { |
|
|
|
ObjectCollection rows = bill.getObjectCollection(srcEntryTable); |
|
|
|
ObjectCollection rows = bill.getObjectCollection(srcEntryTable); |
|
|
|
if (rows == null) { |
|
|
|
if (rows == null) { |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
for (int i = 0; i < rows.size(); i++) { |
|
|
|
for (int i = 0; i < rows.size(); i++) { |
|
|
|
flatRows.add(new ConvertSourceRow(bill, rows.getObject(i))); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
List<ConvertSourceRowGroup> groups = new ArrayList<>(); |
|
|
|
|
|
|
|
if (StringUtils.isBlank(mergeKeyField)) { |
|
|
|
|
|
|
|
for (ConvertSourceRow flat : flatRows) { |
|
|
|
|
|
|
|
ConvertSourceRowGroup group = new ConvertSourceRowGroup(); |
|
|
|
ConvertSourceRowGroup group = new ConvertSourceRowGroup(); |
|
|
|
group.add(flat.getBill(), flat.getRow()); |
|
|
|
group.add(bill, rows.getObject(i)); |
|
|
|
groups.add(group); |
|
|
|
groups.add(group); |
|
|
|
} |
|
|
|
} |
|
|
|
return groups; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Map<String, ConvertSourceRowGroup> grouped = new LinkedHashMap<>(); |
|
|
|
|
|
|
|
for (ConvertSourceRow flat : flatRows) { |
|
|
|
|
|
|
|
Object key = flat.getRow().get(mergeKeyField); |
|
|
|
|
|
|
|
grouped.computeIfAbsent(key == null ? "" : String.valueOf(key), k -> new ConvertSourceRowGroup()) |
|
|
|
|
|
|
|
.add(flat.getBill(), flat.getRow()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
groups.addAll(grouped.values()); |
|
|
|
|
|
|
|
return groups; |
|
|
|
return groups; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|