优化企业成本核算

This commit is contained in:
xuhaihui 2025-11-26 11:18:42 +08:00
parent c260c57ac7
commit 38c396170d
1 changed files with 38 additions and 4 deletions

View File

@ -277,8 +277,8 @@ public class EntCostSplitBillPlugin extends AbstractBillPlugIn implements Before
if (costType1 == null) return -1;
if (costType2 == null) return 1;
String str1 = costType1.toString().trim();
String str2 = costType2.toString().trim();
String str1 = cleanCostType(costType1.toString().trim());
String str2 = cleanCostType(costType2.toString().trim());
Integer sortValue1 = COST_TYPE_SORT_MAP.get(str1);
Integer sortValue2 = COST_TYPE_SORT_MAP.get(str2);
@ -289,14 +289,31 @@ public class EntCostSplitBillPlugin extends AbstractBillPlugIn implements Before
return sortValue1.compareTo(sortValue2);
});
// 手动将 "10." 的条目移到最前面
List<DynamicObject> firstEntries = new ArrayList<>();
List<DynamicObject> otherEntries = new ArrayList<>();
// 按排序后的顺序添加数据且跳过成本项为空的分录行
for (DynamicObject entry : sortedEntries) {
Object costtype = entry.get("costtype");
String cleaned = cleanCostType(costtype != null ? costtype.toString() : "");
if ("10.".equals(cleaned)) {
firstEntries.add(entry);
} else {
otherEntries.add(entry);
}
}
// 合并先放 "10." 的条目再放其他
List<DynamicObject> finalEntries = new ArrayList<>();
finalEntries.addAll(firstEntries);
finalEntries.addAll(otherEntries);
// 按排序后的顺序添加数据
for (DynamicObject entry : finalEntries) {
Object costtype = entry.get("costtype");
if (costtype == null) {
continue;
}
entry.set("comment", costtype);
entryCollection.add(entry);
}
@ -343,4 +360,21 @@ public class EntCostSplitBillPlugin extends AbstractBillPlugIn implements Before
COST_TYPE_SORT_MAP.put("90.", 90);//财务费用
COST_TYPE_SORT_MAP.put("100.", 100);//研发支出
}
private static String cleanCostType(String type) {
if (type == null || type.isEmpty()) return "";
// 去除前后空格
type = type.trim();
// 如果是 "10.0""10.00" 转换为 "10."
if (type.matches("^\\d+\\.\\d+$")) {
String[] parts = type.split("\\.");
return parts[0] + ".";
}
// 如果是纯数字加个点
if (type.matches("^\\d+$")) {
return type + ".";
}
// 其他情况保持原样
return type;
}
}