21
21
import com .rebuild .core .Application ;
22
22
import com .rebuild .core .configuration .ConfigBean ;
23
23
import com .rebuild .core .configuration .ConfigManager ;
24
+ import com .rebuild .core .metadata .EntityRecordCreator ;
24
25
import com .rebuild .core .metadata .MetadataHelper ;
25
26
import com .rebuild .core .metadata .easymeta .DisplayType ;
26
27
import com .rebuild .core .metadata .easymeta .EasyField ;
38
39
import java .util .ArrayList ;
39
40
import java .util .Collections ;
40
41
import java .util .Date ;
42
+ import java .util .HashMap ;
41
43
import java .util .HashSet ;
42
44
import java .util .Iterator ;
43
45
import java .util .List ;
@@ -58,14 +60,24 @@ public class AutoFillinManager implements ConfigManager {
58
60
59
61
private AutoFillinManager () {}
60
62
63
+ /**
64
+ * @param field
65
+ * @param sourceId
66
+ * @return
67
+ */
68
+ public JSONArray getFillinValue (Field field , ID sourceId ) {
69
+ return getFillinValue (field , sourceId , null );
70
+ }
71
+
61
72
/**
62
73
* 获取回填值
63
74
*
64
75
* @param field
65
76
* @param sourceId
77
+ * @param formData
66
78
* @return
67
79
*/
68
- public JSONArray getFillinValue (Field field , ID sourceId ) {
80
+ public JSONArray getFillinValue (Field field , ID sourceId , JSONObject formData ) {
69
81
final EasyField easyField = EasyMetaFactory .valueOf (field );
70
82
71
83
// 内置字段无配置
@@ -154,7 +166,27 @@ public JSONArray getFillinValue(Field field, ID sourceId) {
154
166
} else {
155
167
targetFieldMeta = targetEntity .getField (targetField );
156
168
}
157
-
169
+
170
+ // v40 使用公式回填
171
+ String sourceFieldFormula40 = e .getString ("sourceFieldFormula" );
172
+ if (StringUtils .isNotBlank (sourceFieldFormula40 )) {
173
+ Map <String , Object > varsInFormula = new HashMap <>();
174
+ if (formData != null ) {
175
+ formData .remove (EntityRecordCreator .META_FIELD );
176
+ JSONObject formDataMain = (JSONObject ) formData .remove ("$$$main" );
177
+ if (formDataMain != null ) {
178
+ formDataMain .remove (EntityRecordCreator .META_FIELD );
179
+ String dtfName = MetadataHelper .getDetailToMainField (field .getOwnEntity ()).getName () + "." ;
180
+ formDataMain .forEach ((k , v ) -> varsInFormula .put (dtfName + k , v ));
181
+ }
182
+ varsInFormula .putAll (formData );
183
+ }
184
+
185
+ Object value = CalcFormulaSupport .evalCalcFormula (targetFieldMeta , varsInFormula , sourceFieldFormula40 );
186
+ if (value == null ) sourceRecord .setNull (sourceField );
187
+ else sourceRecord .setObjectValue (sourceField , value );
188
+ }
189
+
158
190
Object value = null ;
159
191
if (sourceRecord .hasValue (sourceField , false )) {
160
192
value = sourceRecord .getObjectValue (sourceField );
@@ -404,6 +436,9 @@ private List<ConfigBean> getConfig(Field field) {
404
436
.set ("whenUpdate" , extra .getBooleanValue ("whenUpdate" ))
405
437
.set ("fillinForce" , extra .getBooleanValue ("fillinForce" ))
406
438
.set ("fillinBackend" , extra .getBooleanValue ("fillinBackend" ));
439
+ if (extra .getString ("sourceFieldFormula" ) != null ) {
440
+ entry .set ("sourceFieldFormula" , extra .getString ("sourceFieldFormula" ));
441
+ }
407
442
entries .add (entry );
408
443
}
409
444
0 commit comments