出库单生产成本工序分摊校验插件

This commit is contained in:
zhangzhiguo 2025-10-14 14:08:49 +08:00
parent 039cddb9e1
commit 38287d9cda
2 changed files with 260 additions and 0 deletions

View File

@ -0,0 +1,195 @@
package zcgj.zcdev.zcdev.pr.plugin.form;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.utils.StringUtils;
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
import kd.bos.entity.property.BasedataProp;
import kd.bos.form.field.BasedataEdit;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.ec.basedata.common.enums.CostControlModelEnum;
import kd.ec.basedata.common.enums.StatusEnum;
import kd.ec.basedata.common.utils.EcProjectHelper;
import kd.ec.material.formplugin.MaterialOutCostMustInputEditPlugin;
import java.math.BigDecimal;
import java.util.EventObject;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class MaterialOutCostMustInputEditPluginExt extends AbstractFormPlugin {
private static final List<String> cbsKeyList = (List) Stream.of("procbs", "cbs").collect(Collectors.toList());
private static final List<String> caKeyList = (List)Stream.of("ca", "costaccount").collect(Collectors.toList());
private static final List<String> boqKeyList = (List)Stream.of("proboq", "boq").collect(Collectors.toList());
public void afterBindData(EventObject e) {
//因次方法需要调用父级的逻辑所以需要重写当前插件
super.afterBindData(e);
this.controlCostMustInput();
DynamicObject transtype = (DynamicObject)this.getModel().getValue("transtype");
boolean impactcost = transtype == null ? false : (Boolean)transtype.get("impactcost");
String billStatus = (String)this.getModel().getValue("billstatus");
if (impactcost && StatusEnum.Checked.getValue().equalsIgnoreCase(billStatus)) {
this.getView().setVisible(true, new String[]{"splitamount", "iscompleted"});
} else {
this.getView().setVisible(false, new String[]{"splitamount", "iscompleted"});
}
}
public void propertyChanged(PropertyChangedArgs e) {
super.propertyChanged(e);
String name = e.getProperty().getName();
if (!StringUtils.equals("project", name) && !StringUtils.equals("warehouse", name)) {
if (StringUtils.equals("transtype", name)) {
this.controlCostMustInput();
this.showSplitAmount();
} else if (StringUtils.equals("costtype", name)) {
this.controlCostMustInput();
} else if (StringUtils.equals("amount", name)) {
this.onAmountChanged(e);
}
} else {
this.controlCostMustInput();
}
}
private void onAmountChanged(PropertyChangedArgs e) {
BigDecimal amount = (BigDecimal)e.getChangeSet()[0].getNewValue();
int rowIndex = e.getChangeSet()[0].getRowIndex();
DynamicObject transType = this.getModel().getDataEntity().getDynamicObject("transtype");
if (transType != null) {
boolean impactcost = transType.getBoolean("impactcost");
if (impactcost) {
this.getModel().setValue("splitamount", amount, rowIndex);
}
}
}
private void showSplitAmount() {
DynamicObject transType = this.getModel().getDataEntity().getDynamicObject("transtype");
if (transType != null) {
boolean impactcost = transType.getBoolean("impactcost");
if (impactcost) {
int rowCount = this.getModel().getEntryRowCount("entryentity");
for(int i = 0; i < rowCount; ++i) {
BigDecimal amount = (BigDecimal)this.getModel().getValue("amount", i);
this.getModel().setValue("splitamount", amount, i);
}
} else {
int rowCount = this.getModel().getEntryRowCount("entryentity");
for(int i = 0; i < rowCount; ++i) {
this.getModel().setValue("splitamount", (Object)null, i);
}
}
}
}
private void controlCostMustInput() {
this.clearMustInpt();
DynamicObject transType = this.getModel().getDataEntity().getDynamicObject("transtype");
if (transType != null) {
boolean impactcost = transType.getBoolean("impactcost");
if (impactcost) {
String costType = (String)this.getModel().getValue("costtype");
if (!StringUtils.equals("b", costType)) {
DynamicObject project = this.getModel().getDataEntity().getDynamicObject("project");
if (project != null) {
List<String> modelList = EcProjectHelper.getCostControlModelList(project.getLong("id"));
BasedataEdit basedataEdit = null;
BasedataProp basedataProp = null;
for(String string : modelList) {
if (StringUtils.equals(string, CostControlModelEnum.CBS.getValue())) {
/*for(String cbsKey : cbsKeyList) { //移除必录
basedataEdit = (BasedataEdit)this.getControl(cbsKey);
basedataProp = (BasedataProp)this.getModel().getDataEntityType().findProperty(cbsKey);
if (basedataEdit != null) {
basedataEdit.setMustInput(true);
}
if (basedataProp != null) {
basedataProp.setMustInput(true);
}
}*/
} else if (StringUtils.equals(string, CostControlModelEnum.CA.getValue())) {
for(String caKey : caKeyList) {
basedataEdit = (BasedataEdit)this.getControl(caKey);
basedataProp = (BasedataProp)this.getModel().getDataEntityType().findProperty(caKey);
if (basedataEdit != null) {
basedataEdit.setMustInput(true);
}
if (basedataProp != null) {
basedataProp.setMustInput(true);
}
}
} else if (StringUtils.equals(string, CostControlModelEnum.BOQ.getValue())) {
for(String boqKey : boqKeyList) {
basedataEdit = (BasedataEdit)this.getControl(boqKey);
basedataProp = (BasedataProp)this.getModel().getDataEntityType().findProperty(boqKey);
if (basedataEdit != null) {
basedataEdit.setMustInput(true);
}
if (basedataProp != null) {
basedataProp.setMustInput(true);
}
}
}
}
}
}
}
}
}
private void clearMustInpt() {
BasedataEdit dBasedataEdit = null;
BasedataProp dBasedataProp = null;
for(String cbsKey : cbsKeyList) {
dBasedataEdit = (BasedataEdit)this.getControl(cbsKey);
if (dBasedataEdit != null) {
dBasedataEdit.setMustInput(false);
}
dBasedataProp = (BasedataProp)this.getModel().getDataEntityType().findProperty(cbsKey);
if (dBasedataProp != null) {
dBasedataProp.setMustInput(false);
}
}
for(String boqKey : boqKeyList) {
dBasedataEdit = (BasedataEdit)this.getControl(boqKey);
if (dBasedataEdit != null) {
dBasedataEdit.setMustInput(false);
}
dBasedataProp = (BasedataProp)this.getModel().getDataEntityType().findProperty(boqKey);
if (dBasedataProp != null) {
dBasedataProp.setMustInput(false);
}
}
for(String caKey : caKeyList) {
dBasedataEdit = (BasedataEdit)this.getControl(caKey);
if (dBasedataEdit != null) {
dBasedataEdit.setMustInput(false);
}
dBasedataProp = (BasedataProp)this.getModel().getDataEntityType().findProperty(caKey);
if (dBasedataProp != null) {
dBasedataProp.setMustInput(false);
}
}
}
}

View File

@ -0,0 +1,65 @@
package zcgj.zcdev.zcdev.pr.plugin.operate;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.ExtendedDataEntity;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.AddValidatorsEventArgs;
import kd.bos.entity.plugin.PreparePropertysEventArgs;
import kd.bos.entity.validate.AbstractValidator;
import java.util.HashSet;
import java.util.Set;
/**
* 出库单生产成本工序分摊校验插件
*/
public class MaterialoutbillProcbsCkOp extends AbstractOperationServicePlugIn {
public void onPreparePropertys(PreparePropertysEventArgs e) {
super.onPreparePropertys(e);
e.getFieldKeys().add("entryentity");
e.getFieldKeys().add("entryentity.procbs");
e.getFieldKeys().add("entryentity.zcgj_accounttype");
}
@Override
public void onAddValidators(AddValidatorsEventArgs e) {
super.onAddValidators(e);
e.getValidators().add(new ValidatorExt());
}
class ValidatorExt extends AbstractValidator {
@Override
public void validate() {
Set<String> key = new HashSet<String>();
key.add("FL001");
key.add("FL012");
key.add("FL013");
key.add("FL017");
key.add("FL018");
key.add("FL019");
ExtendedDataEntity[] extendedDataEntities = this.getDataEntities();
for (ExtendedDataEntity extendedDataEntity : extendedDataEntities) {
DynamicObject dataEntity = extendedDataEntity.getDataEntity();
DynamicObjectCollection dynamicObjectCollection = dataEntity.getDynamicObjectCollection("entryentity");
int i=0;
for (DynamicObject dynamicObject : dynamicObjectCollection) {
i++;
DynamicObject accounttype = dynamicObject.getDynamicObject("zcgj_accounttype");
if(accounttype!=null){
String number = accounttype.getString("number");
if(key.contains(number)){
DynamicObject procbs = dynamicObject.getDynamicObject("procbs");
if(procbs==null){
this.addFatalErrorMessage(extendedDataEntity, String.format("出库单明细第%d行需要填写工序分摊",i));
}
}
}
}
}
}
}
}