实际成本优化

This commit is contained in:
xuhaihui 2025-11-26 14:50:02 +08:00
parent 38c396170d
commit 9ace55f142
3 changed files with 111 additions and 65 deletions

View File

@ -0,0 +1,43 @@
package zcgj.zcdev.zcdev.pr.plugin.form;
import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.resource.ResManager;
import kd.bos.dataentity.utils.StringUtils;
import kd.bos.form.field.BasedataEdit;
import kd.bos.form.field.events.BeforeF7SelectEvent;
import kd.bos.form.field.events.BeforeF7SelectListener;
import kd.bos.list.ListShowParameter;
import kd.bos.orm.query.QFilter;
import java.util.EventObject;
public class EcEqCostSplitBillPlugin extends AbstractBillPlugIn implements BeforeF7SelectListener{
@Override
public void registerListener(EventObject e) {
super.registerListener(e);
BasedataEdit procbs = (BasedataEdit) this.getControl("procbs");
procbs.addBeforeF7SelectListener(this);
}
public void beforeF7Select(BeforeF7SelectEvent arg0) {
String name = arg0.getProperty().getName();
if (StringUtils.equals(name, "procbs")) {
//成本分解结构
ListShowParameter parameter = (ListShowParameter) arg0.getFormShowParameter();
arg0.setCancel(true);
DynamicObject project = (DynamicObject) this.getModel().getValue("project");//工程项目
if (project == null) {
this.getView().showMessage(ResManager.loadKDString("请先选择工程项目。", "EntCostSplitEditPlugin_0", "ec-ecco-formplugin", new Object[0]));
arg0.setCancel(true);
return;
}
QFilter qFilter = new QFilter("project", "=", project.getPkValue());
qFilter = qFilter.and(new QFilter("isleaf", "=", true));
parameter.getListFilterParameter().setFilter(qFilter);
parameter.setFormId("bos_listf7");
this.getView().showForm(parameter);
}
}
}

View File

@ -277,39 +277,17 @@ public class EntCostSplitBillPlugin extends AbstractBillPlugIn implements Before
if (costType1 == null) return -1;
if (costType2 == null) return 1;
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);
if (sortValue1 == null && sortValue2 == null) return 0;
if (sortValue1 == null) return -1;
if (sortValue2 == null) return 1;
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);
try {
Double num1 = Double.parseDouble(costType1.toString().replace(".", ""));
Double num2 = Double.parseDouble(costType2.toString().replace(".", ""));
return num1.compareTo(num2);
} catch (NumberFormatException e) {
return costType1.toString().compareTo(costType2.toString());
}
}
// 合并先放 "10." 的条目再放其他
List<DynamicObject> finalEntries = new ArrayList<>();
finalEntries.addAll(firstEntries);
finalEntries.addAll(otherEntries);
});
// 按排序后的顺序添加数据
for (DynamicObject entry : finalEntries) {
for (DynamicObject entry : sortedEntries) {
Object costtype = entry.get("costtype");
if (costtype == null) {
continue;
@ -340,41 +318,18 @@ public class EntCostSplitBillPlugin extends AbstractBillPlugIn implements Before
}
}
private static final Map<String, Integer> COST_TYPE_SORT_MAP = new HashMap<>();
static {
COST_TYPE_SORT_MAP.put("10.", 10);//人工成本
COST_TYPE_SORT_MAP.put("10", 10); // 支持无点的情况
COST_TYPE_SORT_MAP.put("10.0", 10);
COST_TYPE_SORT_MAP.put("10.00", 10);
COST_TYPE_SORT_MAP.put("10. ", 10); // 带空格
COST_TYPE_SORT_MAP.put("10 .", 10);
COST_TYPE_SORT_MAP.put("20.", 20);//材料成本
COST_TYPE_SORT_MAP.put("30.", 30);//机械设备
COST_TYPE_SORT_MAP.put("40.", 40);//分包成本
COST_TYPE_SORT_MAP.put("50.", 50);//劳务成本
COST_TYPE_SORT_MAP.put("60.", 60);//安全支出
COST_TYPE_SORT_MAP.put("70.", 70);//期间费用
COST_TYPE_SORT_MAP.put("80.", 80);//税金及附加
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;
private static Integer getSortValue(String type) {
if ("10.".equals(type)) return 10;
if ("20.".equals(type)) return 20;
if ("30.".equals(type)) return 30;
if ("40.".equals(type)) return 40;
if ("50.".equals(type)) return 50;
if ("60.".equals(type)) return 60;
if ("70.".equals(type)) return 70;
if ("80.".equals(type)) return 80;
if ("90.".equals(type)) return 90;
if ("100.".equals(type)) return 100;
return null;
}
}

View File

@ -0,0 +1,48 @@
package zcgj.zcdev.zcdev.pr.plugin.form;
import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.resource.ResManager;
import kd.bos.dataentity.utils.StringUtils;
import kd.bos.form.field.BasedataEdit;
import kd.bos.form.field.events.BeforeF7SelectEvent;
import kd.bos.form.field.events.BeforeF7SelectListener;
import kd.bos.list.ListShowParameter;
import kd.bos.orm.query.QFilter;
import java.util.EventObject;
/**
* 新增设备表单插件
* 说明1工序过滤
**/
public class EquipmentCardBillPlugin extends AbstractBillPlugIn implements BeforeF7SelectListener {
@Override
public void registerListener(EventObject e) {
super.registerListener(e);
BasedataEdit zcgj_cbs = (BasedataEdit) this.getControl("zcgj_cbs");
zcgj_cbs.addBeforeF7SelectListener(this);
}
public void beforeF7Select(BeforeF7SelectEvent arg0) {
String name = arg0.getProperty().getName();
if (StringUtils.equals(name, "zcgj_cbs")) {
//工序
ListShowParameter parameter = (ListShowParameter) arg0.getFormShowParameter();
arg0.setCancel(true);
DynamicObject project = (DynamicObject) this.getModel().getValue("project");//工程项目
if (project == null) {
this.getView().showMessage(ResManager.loadKDString("请先选择工程项目。", "EntCostSplitEditPlugin_0", "ec-ecco-formplugin", new Object[0]));
arg0.setCancel(true);
return;
}
QFilter qFilter = new QFilter("project", "=", project.getPkValue());
qFilter = qFilter.and(new QFilter("isleaf", "=", true));
parameter.getListFilterParameter().setFilter(qFilter);
parameter.setFormId("bos_listf7");
this.getView().showForm(parameter);
}
}
}