【物料】提交报错

This commit is contained in:
tanfengling@x-ri.com 2025-11-17 17:54:13 +08:00
parent 385722ce4a
commit e995ed2280
1 changed files with 179 additions and 33 deletions

View File

@ -3,15 +3,25 @@ package tqq9.lc123.cloud.app.plugin.form.sys;
import kd.bos.bill.AbstractBillPlugIn; import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.dataentity.entity.DynamicObject; import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection; import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.dataentity.entity.LocaleString;
import kd.bos.dataentity.metadata.IDataEntityProperty;
import kd.bos.dataentity.utils.StringUtils; import kd.bos.dataentity.utils.StringUtils;
import kd.bos.entity.datamodel.events.ChangeData; import kd.bos.entity.datamodel.events.ChangeData;
import kd.bos.entity.datamodel.events.PropertyChangedArgs; import kd.bos.entity.datamodel.events.PropertyChangedArgs;
import kd.bos.form.events.AfterDoOperationEventArgs; import kd.bos.form.events.AfterDoOperationEventArgs;
import kd.bos.form.events.BeforeDoOperationEventArgs;
import kd.bos.form.operate.FormOperate;
import kd.bos.orm.query.QCP; import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter; import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper; import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper; import kd.bos.servicehelper.operation.SaveServiceHelper;
import java.math.BigDecimal;
import java.util.Date;
import java.util.EventObject;
import java.util.LinkedHashMap;
import java.util.List;
/** /**
* 物料界面插件 * 物料界面插件
@ -19,42 +29,178 @@ import kd.bos.servicehelper.operation.SaveServiceHelper;
public class MaterialBillPlugin extends AbstractBillPlugIn { public class MaterialBillPlugin extends AbstractBillPlugIn {
// /**
// * 修改时设置变更缘由必填 @Override
// * @param e public void beforeDoOperation(BeforeDoOperationEventArgs args) {
// */ super.beforeDoOperation(args);
// @Override FormOperate source = (FormOperate) args.getSource();
// public void afterBindData(EventObject e) { String operateKey = source.getOperateKey();
// super.afterBindData(e); if("submit".equals(operateKey)){
// OperationStatus status = this.getView().getFormShowParameter().getStatus(); //复制后修改数据在提交时记录修改的内容如果修改内容为空则不记录
// if(OperationStatus.EDIT.getValue() == status.getValue()){ LinkedHashMap changeMap = new LinkedHashMap();
// ComboEdit tqq9_bgyyCtrl = this.getView().getControl("tqq9_bgyy"); DynamicObject dataEntity = this.getModel().getDataEntity(true);
// ComboEdit tqq9_bgyy2Ctrl = this.getView().getControl("tqq9_bgyy2"); String newName = dataEntity.getString("name");
// ComboEdit tqq9_shbgyyCtrl = this.getView().getControl("tqq9_shbgyy"); String srcNumber = null;
// TextEdit tqq9_bgms1Ctrl = this.getView().getControl("tqq9_bgms1"); if(StringUtils.isNotBlank(newName) && newName.contains("_copy")){
// TextEdit tqq9_bgms2Ctrl = this.getView().getControl("tqq9_bgms2"); srcNumber = newName.replace("_copy", "");
// TextEdit tqq9_bgms3Ctrl = this.getView().getControl("tqq9_bgms3"); //查询原单
// QFilter qFilter = new QFilter("number", "=", srcNumber);
// ComboProp tqq9_bgyyProp = (ComboProp) tqq9_bgyyCtrl.getProperty(); DynamicObject[] srcMaterialArr = BusinessDataServiceHelper.load("bd_material", "id", new QFilter[]{qFilter});
// ComboProp tqq9_bgyy2Prop = (ComboProp) tqq9_bgyy2Ctrl.getProperty(); if(srcMaterialArr != null && srcMaterialArr.length > 0){
// ComboProp tqq9_shbgyyProp = (ComboProp) tqq9_shbgyyCtrl.getProperty(); DynamicObject srcMaterial = srcMaterialArr[0];
// TextProp tqq9_bgms1Prop = (TextProp) tqq9_bgms1Ctrl.getProperty(); srcMaterial = BusinessDataServiceHelper.loadSingle(srcMaterial.getPkValue(), "bd_material");
// TextProp tqq9_bgms2Prop = (TextProp) tqq9_bgms2Ctrl.getProperty();
// TextProp tqq9_bgms3Prop = (TextProp) tqq9_bgms3Ctrl.getProperty();
// //获取实体中所有变更的属性
// tqq9_bgyyProp.setMustInput(true); StringBuilder changeContent = new StringBuilder();
// tqq9_bgyy2Prop.setMustInput(true); List<IDataEntityProperty> iDataEntityProperties = dataEntity.getDataEntityState().GetDirtyProperties();
// tqq9_shbgyyProp.setMustInput(true); if(iDataEntityProperties.size()>0){
// tqq9_bgms1Prop.setMustInput(true); for(IDataEntityProperty prop :iDataEntityProperties){
// tqq9_bgms2Prop.setMustInput(true); String name = prop.getName();//字段标识
// tqq9_bgms3Prop.setMustInput(true); String displayName = prop.getDisplayName().get("zh_CN");//字段名称
// String propTypeName = prop.getPropertyType().getName();
//// this.getView().setVisible(true, "tqq9_bgyy","tqq9_bgyy2","tqq9_shbgyy","tqq9_bgms1","tqq9_bgms2","tqq9_bgms3"); if("kd.bos.dataentity.entity.DynamicObject".equals(propTypeName)){
// } DynamicObject dynamicObject = dataEntity.getDynamicObject(name);
// } DynamicObject dynamicObject1 = srcMaterial.getDynamicObject(name);
if(dynamicObject != null){
String newValue = dynamicObject.getString("name");
if(dynamicObject1 != null){
String oldValue = dynamicObject1.getString("name");
if(!oldValue.equals(newValue)){
changeContent.append("字段:"+displayName+"("+name+"),变更前:"+oldValue+",变更后:"+newValue+"");
}
}else{
changeContent.append("字段:"+displayName+"("+name+")变更前null变更后"+newValue+"");
}
}else{
if(dynamicObject1 != null) {
String oldValue = dynamicObject1.getString("name");
changeContent.append("字段:"+displayName+"("+name+"),变更前:"+oldValue+"变更后null");
}
}
}else if("java.util.Date".equals(propTypeName)){
Date newValue = dataEntity.getDate(name);
Date oldValue = srcMaterial.getDate(name);
if(newValue != null){
if(oldValue != null){
if(!oldValue.equals(newValue)){
changeContent.append("字段:"+displayName+"("+name+"),变更前:"+oldValue+",变更后:"+newValue+"");
}
}else{
changeContent.append("字段:"+displayName+"("+name+")变更前null变更后"+newValue+"");
}
}else{
if(oldValue != null){
changeContent.append("字段:"+displayName+"("+name+"),变更前:"+oldValue+"变更后null");
}
}
}else if("java.lang.Integer".equals(propTypeName)){
int newValue = dataEntity.getInt(name);
int oldValue = srcMaterial.getInt(name);
if(newValue != oldValue){
changeContent.append("字段:"+displayName+"("+name+"),变更前:"+oldValue+",变更后:"+newValue+"");
}
}else if("java.lang.Long".equals(propTypeName)){
long newValue = dataEntity.getLong(name);
long oldValue = srcMaterial.getLong(name);
if(newValue != oldValue){
changeContent.append("字段:"+displayName+"("+name+"),变更前:"+oldValue+",变更后:"+newValue+"");
}
}else if("java.math.BigDecimal".equals(propTypeName)){
BigDecimal newValue = dataEntity.getBigDecimal(name);
BigDecimal oldValue = srcMaterial.getBigDecimal(name);
if(newValue != null){
if(oldValue != null){
if(oldValue.compareTo(newValue) != 0){
changeContent.append("字段:"+displayName+"("+name+"),变更前:"+oldValue+",变更后:"+newValue+"");
}
}else{
changeContent.append("字段:"+displayName+"("+name+")变更前null变更后"+newValue+"");
}
}else {
if(oldValue != null){
changeContent.append("字段:"+displayName+"("+name+"),变更前:"+oldValue+"变更后null");
}
}
}else if("boolean".equals(propTypeName)){
boolean newValue = dataEntity.getBoolean(name);
boolean oldValue = srcMaterial.getBoolean(name);
if(newValue != oldValue){
changeContent.append("字段:"+displayName+"("+name+"),变更前:"+oldValue+",变更后:"+newValue+"");
}
}else {
String newValue = dataEntity.getString(name);
String oldValue = srcMaterial.getString(name);
if(StringUtils.isNotBlank(newValue)){
if(StringUtils.isNotBlank(oldValue)){
if(!oldValue.equals(newValue)){
changeContent.append("字段:"+displayName+"("+name+"),变更前:"+oldValue+",变更后:"+newValue+"");
}
}else{
changeContent.append("字段:"+displayName+"("+name+")变更前null变更后"+newValue+"");
}
}else{
if(StringUtils.isNotBlank(oldValue)) {
changeContent.append("字段:"+displayName+"("+name+"),变更前:"+oldValue+"变更后null");
}
}
}
changeMap.put(name,displayName);
}
}
DynamicObjectCollection entryentity = dataEntity.getDynamicObjectCollection("entry_groupstandard");
//获取单据体中已变更的属性
for(int x = 0; x < entryentity.size(); x++){
List<IDataEntityProperty> iDataEntityProperties1 = entryentity.get(x).getDataEntityState().GetDirtyProperties();
for(IDataEntityProperty prop1 :iDataEntityProperties1){
String name = prop1.getName();
String propTypeName = prop1.getPropertyType().getName();
LocaleString displayName1 = prop1.getDisplayName();
changeMap.put("entry_groupstandard-"+(x+1)+":"+name,displayName1);
if("kd.bos.dataentity.entity.DynamicObject".equals(propTypeName)){
DynamicObject dynamicObject = dataEntity.getDynamicObject(name);
}else if("java.util.Date".equals(propTypeName)){
Date date = dataEntity.getDate(name);
}else if("java.lang.Integer".equals(propTypeName)){
int anInt = dataEntity.getInt(name);
}else if("java.lang.Long".equals(propTypeName)){
Long aLong = dataEntity.getLong(name);
}else if("java.math.BigDecimal".equals(propTypeName)){
BigDecimal bigDecimal = dataEntity.getBigDecimal(name);
}else if("boolean".equals(propTypeName)){
boolean aBoolean = dataEntity.getBoolean(name);
}else {
String string = dataEntity.getString(name);
}
}
}
System.out.println("单据已变更的数据是:"+changeMap);
}
}
}
if("copy".equals(operateKey)) {
super.beforeDoOperation(args);
FormOperate operate = (FormOperate) args.getSource();
String operateNo = operate.getOperateKey();
if(operateNo.equalsIgnoreCase("copy")){
DynamicObject bill = this.getModel().getDataEntity();
this.getView().getFormShowParameter().setCustomParam("copySrcBillNo", bill.getString("number"));
}
}
}
@Override @Override
public void afterCopyData(EventObject e) {
super.afterCopyData(e);
String copySrcBillNo = this.getView().getFormShowParameter().getCustomParam("copySrcBillNo");
DynamicObject dataEntity = this.getModel().getDataEntity(true);
dataEntity.set("name", copySrcBillNo + "_copy");
this.getView().invokeOperation("save");
}
public void afterDoOperation(AfterDoOperationEventArgs afterDoOperationEventArgs) { public void afterDoOperation(AfterDoOperationEventArgs afterDoOperationEventArgs) {
super.afterDoOperation(afterDoOperationEventArgs); super.afterDoOperation(afterDoOperationEventArgs);
String operateKey = afterDoOperationEventArgs.getOperateKey(); String operateKey = afterDoOperationEventArgs.getOperateKey();