@ -6,7 +6,6 @@ import apelet.common.generator.utils.OrmGenDataSourceUtil;
@@ -6,7 +6,6 @@ import apelet.common.generator.utils.OrmGenDataSourceUtil;
import apelet.common.online.abstractplugin.ExecutePluginParent ;
import apelet.common.online.model.constant.AttributeEnum ;
import com.alibaba.fastjson.JSONObject ;
import org.apache.commons.lang3.StringUtils ;
import java.util.HashMap ;
import java.util.List ;
@ -162,6 +161,8 @@ public class UnitNameChangeFormInitPlugin extends ExecutePluginParent {
@@ -162,6 +161,8 @@ public class UnitNameChangeFormInitPlugin extends ExecutePluginParent {
throw new RuntimeException ( "获取数据库连接失败" ) ;
}
int version = markOldBillsHistory ( ormUtil , objectValue ) ;
ObjectValue newBill = new ObjectValue ( "membership_apply" ) ;
Map values = objectValue . getValues ( ) ;
for ( Object item : values . entrySet ( ) ) {
@ -173,6 +174,7 @@ public class UnitNameChangeFormInitPlugin extends ExecutePluginParent {
@@ -173,6 +174,7 @@ public class UnitNameChangeFormInitPlugin extends ExecutePluginParent {
newBill . put ( getDbFieldKey ( key ) , entry . getValue ( ) ) ;
}
newBill . put ( "history" , "0" ) ;
newBill . put ( "version_number" , version ) ;
ObjectCollection detailEntry = copyEntryForManualSave ( objectValue . getObjectCollection ( CHILD_WIDGET_KEY ) ) ;
if ( detailEntry ! = null & & ! detailEntry . isEmpty ( ) ) {
@ -182,6 +184,64 @@ public class UnitNameChangeFormInitPlugin extends ExecutePluginParent {
@@ -182,6 +184,64 @@ public class UnitNameChangeFormInitPlugin extends ExecutePluginParent {
ormUtil . addNew ( "membership_apply" , newBill ) ;
}
private int markOldBillsHistory ( OrmGenDataSourceUtil ormUtil , ObjectValue objectValue ) throws Exception {
String sourceBillId = getSourceBillId ( objectValue ) ;
if ( sourceBillId = = null | | sourceBillId . trim ( ) . isEmpty ( ) ) {
sourceBillId = objectValue . getString ( PARAM_BILL_ID ) ;
}
if ( sourceBillId = = null | | sourceBillId . trim ( ) . isEmpty ( ) ) {
sourceBillId = objectValue . getString ( PARAM_BILL_ID_ALT ) ;
}
if ( sourceBillId = = null | | sourceBillId . trim ( ) . isEmpty ( ) ) {
return 1 ;
}
apelet . common . orm . impl . Filter sourceFilter = new apelet . common . orm . impl . Filter ( ) ;
sourceFilter . add ( new apelet . common . orm . impl . FilterItem ( "id" , "=" , sourceBillId ) ) ;
ObjectCollection sourceCollection = ormUtil . query ( "membership_apply" , sourceFilter , null ) ;
if ( sourceCollection = = null | | sourceCollection . isEmpty ( ) ) {
return 1 ;
}
ObjectValue sourceBill = sourceCollection . getObject ( 0 ) ;
if ( sourceBill = = null ) {
return 1 ;
}
String number = sourceBill . getString ( "number" ) ;
if ( number = = null | | number . trim ( ) . isEmpty ( ) ) {
return 1 ;
}
apelet . common . orm . impl . Filter sameNumberFilter = new apelet . common . orm . impl . Filter ( ) ;
sameNumberFilter . add ( new apelet . common . orm . impl . FilterItem ( "number" , "=" , number ) ) ;
ObjectCollection sameBills = ormUtil . query ( "membership_apply" , sameNumberFilter , null ) ;
if ( sameBills = = null | | sameBills . isEmpty ( ) ) {
sourceBill . put ( "history" , "1" ) ;
sourceBill . put ( "version_number" , 1 ) ;
ormUtil . update ( "membership_apply" , sourceBill , null ) ;
return 2 ;
}
List < ObjectValue > bills = new java . util . ArrayList < > ( ) ;
for ( int i = 0 ; i < sameBills . size ( ) ; i + + ) {
ObjectValue bill = sameBills . getObject ( i ) ;
if ( bill ! = null ) {
bills . add ( bill ) ;
}
}
bills . sort ( java . util . Comparator . comparingInt ( this : : getVersionNumberSafe ) ) ;
int version = 1 ;
for ( ObjectValue bill : bills ) {
bill . put ( "history" , "1" ) ;
bill . put ( "version_number" , version ) ;
ormUtil . update ( "membership_apply" , bill , null ) ;
version + + ;
}
return version ;
}
private boolean shouldSkipManualSaveField ( String key ) {
return "id" . equals ( key )
| | "eventparams" . equals ( key )
@ -398,21 +458,13 @@ public class UnitNameChangeFormInitPlugin extends ExecutePluginParent {
@@ -398,21 +458,13 @@ public class UnitNameChangeFormInitPlugin extends ExecutePluginParent {
int version = 1 ;
if ( sameBills ! = null & & ! sameBills . isEmpty ( ) ) {
List < ObjectValue > bills = new java . util . ArrayList < > ( ) ;
for ( int i = 0 ; i < sameBills . size ( ) ; i + + ) {
ObjectValue bill = sameBills . getObject ( i ) ;
if ( bill ! = null ) {
bills . add ( bill ) ;
int billVersion = getVersionNumberSafe ( bill ) ;
if ( billVersion > = version ) {
version = billVersion + 1 ;
}
}
bills . sort ( java . util . Comparator . comparingInt ( this : : getVersionNumberSafe ) ) ;
for ( ObjectValue bill : bills ) {
bill . put ( "is_history" , 1 ) ;
bill . put ( "version_number" , version ) ;
ormUtil . update ( "membership_apply" , bill , null ) ;
version + + ;
}
}
objectValue . put ( "is_history" , 0 ) ;