【物料】提交报错
This commit is contained in:
parent
385722ce4a
commit
e995ed2280
|
|
@ -3,15 +3,25 @@ package tqq9.lc123.cloud.app.plugin.form.sys;
|
|||
import kd.bos.bill.AbstractBillPlugIn;
|
||||
import kd.bos.dataentity.entity.DynamicObject;
|
||||
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.entity.datamodel.events.ChangeData;
|
||||
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
|
||||
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.QFilter;
|
||||
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||
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 {
|
||||
|
||||
|
||||
// /**
|
||||
// * 修改时设置变更缘由必填
|
||||
// * @param e
|
||||
// */
|
||||
// @Override
|
||||
// public void afterBindData(EventObject e) {
|
||||
// super.afterBindData(e);
|
||||
// OperationStatus status = this.getView().getFormShowParameter().getStatus();
|
||||
// if(OperationStatus.EDIT.getValue() == status.getValue()){
|
||||
// ComboEdit tqq9_bgyyCtrl = this.getView().getControl("tqq9_bgyy");
|
||||
// ComboEdit tqq9_bgyy2Ctrl = this.getView().getControl("tqq9_bgyy2");
|
||||
// ComboEdit tqq9_shbgyyCtrl = this.getView().getControl("tqq9_shbgyy");
|
||||
// TextEdit tqq9_bgms1Ctrl = this.getView().getControl("tqq9_bgms1");
|
||||
// TextEdit tqq9_bgms2Ctrl = this.getView().getControl("tqq9_bgms2");
|
||||
// TextEdit tqq9_bgms3Ctrl = this.getView().getControl("tqq9_bgms3");
|
||||
//
|
||||
// ComboProp tqq9_bgyyProp = (ComboProp) tqq9_bgyyCtrl.getProperty();
|
||||
// ComboProp tqq9_bgyy2Prop = (ComboProp) tqq9_bgyy2Ctrl.getProperty();
|
||||
// ComboProp tqq9_shbgyyProp = (ComboProp) tqq9_shbgyyCtrl.getProperty();
|
||||
// TextProp tqq9_bgms1Prop = (TextProp) tqq9_bgms1Ctrl.getProperty();
|
||||
// TextProp tqq9_bgms2Prop = (TextProp) tqq9_bgms2Ctrl.getProperty();
|
||||
// TextProp tqq9_bgms3Prop = (TextProp) tqq9_bgms3Ctrl.getProperty();
|
||||
//
|
||||
// tqq9_bgyyProp.setMustInput(true);
|
||||
// tqq9_bgyy2Prop.setMustInput(true);
|
||||
// tqq9_shbgyyProp.setMustInput(true);
|
||||
// tqq9_bgms1Prop.setMustInput(true);
|
||||
// tqq9_bgms2Prop.setMustInput(true);
|
||||
// tqq9_bgms3Prop.setMustInput(true);
|
||||
//
|
||||
//// this.getView().setVisible(true, "tqq9_bgyy","tqq9_bgyy2","tqq9_shbgyy","tqq9_bgms1","tqq9_bgms2","tqq9_bgms3");
|
||||
// }
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void beforeDoOperation(BeforeDoOperationEventArgs args) {
|
||||
super.beforeDoOperation(args);
|
||||
FormOperate source = (FormOperate) args.getSource();
|
||||
String operateKey = source.getOperateKey();
|
||||
if("submit".equals(operateKey)){
|
||||
//复制后修改数据在提交时记录修改的内容,如果修改内容为空,则不记录
|
||||
LinkedHashMap changeMap = new LinkedHashMap();
|
||||
DynamicObject dataEntity = this.getModel().getDataEntity(true);
|
||||
String newName = dataEntity.getString("name");
|
||||
String srcNumber = null;
|
||||
if(StringUtils.isNotBlank(newName) && newName.contains("_copy")){
|
||||
srcNumber = newName.replace("_copy", "");
|
||||
//查询原单
|
||||
QFilter qFilter = new QFilter("number", "=", srcNumber);
|
||||
DynamicObject[] srcMaterialArr = BusinessDataServiceHelper.load("bd_material", "id", new QFilter[]{qFilter});
|
||||
if(srcMaterialArr != null && srcMaterialArr.length > 0){
|
||||
DynamicObject srcMaterial = srcMaterialArr[0];
|
||||
srcMaterial = BusinessDataServiceHelper.loadSingle(srcMaterial.getPkValue(), "bd_material");
|
||||
|
||||
|
||||
//获取实体中所有变更的属性
|
||||
StringBuilder changeContent = new StringBuilder();
|
||||
List<IDataEntityProperty> iDataEntityProperties = dataEntity.getDataEntityState().GetDirtyProperties();
|
||||
if(iDataEntityProperties.size()>0){
|
||||
for(IDataEntityProperty prop :iDataEntityProperties){
|
||||
String name = prop.getName();//字段标识
|
||||
String displayName = prop.getDisplayName().get("zh_CN");//字段名称
|
||||
String propTypeName = prop.getPropertyType().getName();
|
||||
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
|
||||
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) {
|
||||
super.afterDoOperation(afterDoOperationEventArgs);
|
||||
String operateKey = afterDoOperationEventArgs.getOperateKey();
|
||||
|
|
|
|||
Loading…
Reference in New Issue