@ -117,6 +117,110 @@ public class UnitNameChangeFormInitPlugin extends ExecutePluginParent {
@@ -117,6 +117,110 @@ public class UnitNameChangeFormInitPlugin extends ExecutePluginParent {
this . setWidgetAttribute ( "table-btn primary" , AttributeEnum . SHOW , false ) ;
}
@Override
public void buttonTriggered ( String widgetVariableName , ObjectValue objectValue ) {
super . buttonTriggered ( widgetVariableName , objectValue ) ;
if ( ! "保存" . equals ( widgetVariableName ) ) {
return ;
}
if ( ! isChangeBill ( objectValue ) ) {
return ;
}
try {
saveChangeBillManually ( objectValue ) ;
this . cancelOperate ( ) ;
this . showMessage ( "保存成功" ) ;
} catch ( Exception e ) {
this . cancelOperate ( ) ;
this . showErrorMessage ( "保存失败:" + e . getMessage ( ) ) ;
}
}
private boolean isChangeBill ( ObjectValue objectValue ) {
if ( objectValue = = null ) {
return false ;
}
String sourceBillId = getSourceBillId ( objectValue ) ;
if ( sourceBillId = = null | | sourceBillId . trim ( ) . isEmpty ( ) ) {
sourceBillId = objectValue . getString ( PARAM_BILL_ID_ALT ) ;
}
return sourceBillId ! = null & & ! sourceBillId . trim ( ) . isEmpty ( ) ;
}
private void saveChangeBillManually ( ObjectValue objectValue ) throws Exception {
OrmGenDataSourceUtil ormUtil = ( OrmGenDataSourceUtil ) ormGenDataSourceUtil ( ) ;
if ( ormUtil = = null ) {
throw new RuntimeException ( "获取数据库连接失败" ) ;
}
ObjectValue newBill = new ObjectValue ( "membership_apply" ) ;
Map values = objectValue . getValues ( ) ;
for ( Object item : values . entrySet ( ) ) {
Map . Entry entry = ( Map . Entry ) item ;
String key = entry . getKey ( ) . toString ( ) ;
if ( shouldSkipManualSaveField ( key ) ) {
continue ;
}
newBill . put ( getDbFieldKey ( key ) , entry . getValue ( ) ) ;
}
ObjectCollection detailEntry = copyEntryForManualSave ( objectValue . getObjectCollection ( CHILD_WIDGET_KEY ) ) ;
if ( detailEntry ! = null & & ! detailEntry . isEmpty ( ) ) {
newBill . put ( CHILD_TABLE_NAME , detailEntry ) ;
}
ormUtil . addNew ( "membership_apply" , newBill ) ;
}
private boolean shouldSkipManualSaveField ( String key ) {
return "id" . equals ( key )
| | "eventparams" . equals ( key )
| | PARAM_BILL_ID . equals ( key )
| | PARAM_BILL_ID_ALT . equals ( key )
| | PARAM_BILL_NUMBER . equals ( key )
| | CHILD_TABLE_NAME . equals ( key )
| | CHILD_WIDGET_KEY . equals ( key ) ;
}
private String getDbFieldKey ( String widgetKey ) {
for ( Map . Entry < String , String > entry : FIELD_WIDGET_MAPPING . entrySet ( ) ) {
if ( entry . getValue ( ) . equals ( widgetKey ) ) {
return entry . getKey ( ) ;
}
}
return widgetKey ;
}
private ObjectCollection copyEntryForManualSave ( ObjectCollection sourceEntry ) {
if ( sourceEntry = = null | | sourceEntry . isEmpty ( ) ) {
return null ;
}
ObjectCollection targetEntry = new ObjectCollection ( ) ;
for ( int i = 0 ; i < sourceEntry . size ( ) ; i + + ) {
ObjectValue sourceRow = sourceEntry . getObject ( i ) ;
if ( sourceRow = = null ) {
continue ;
}
ObjectValue targetRow = new ObjectValue ( CHILD_TABLE_NAME ) ;
Map rowValues = sourceRow . getValues ( ) ;
for ( Object item : rowValues . entrySet ( ) ) {
Map . Entry entry = ( Map . Entry ) item ;
String key = entry . getKey ( ) . toString ( ) ;
if ( "id" . equals ( key ) | | CHILD_PARENT_FIELD . equals ( key ) ) {
continue ;
}
targetRow . put ( key , entry . getValue ( ) ) ;
}
targetEntry . addObject ( targetRow ) ;
}
return targetEntry ;
}
/ * *
* 从ObjectValue中获取源单据ID
* 从 eventparams 中获取
@ -246,6 +350,7 @@ public class UnitNameChangeFormInitPlugin extends ExecutePluginParent {
@@ -246,6 +350,7 @@ public class UnitNameChangeFormInitPlugin extends ExecutePluginParent {
// 设置字段值到表单控件
try {
this . setWidgetAttribute ( "id" , AttributeEnum . VALUE_CHANGE , null ) ;
this . setWidgetAttribute ( widgetKey , AttributeEnum . VALUE_CHANGE , value ) ;
} catch ( Exception e ) {
// 字段可能不存在,忽略异常