enh: 字段匹配支持N级

This commit is contained in:
RB 2024-09-04 12:54:40 +08:00
parent da7b403314
commit ab383aa926
3 changed files with 29 additions and 19 deletions

View file

@ -103,7 +103,7 @@ public class TargetWithMatchFields {
if (MetadataHelper.getLastJoinField(sourceEntity, sourceField) == null) {
throw new MissingMetaExcetion(sourceField, sourceEntity.getName());
}
if (!targetEntity.containsField(targetField)) {
if (MetadataHelper.getLastJoinField(targetEntity, targetField) == null) {
throw new MissingMetaExcetion(targetField, targetEntity.getName());
}
matchFieldsMapping.put(sourceField, targetField);
@ -136,7 +136,7 @@ public class TargetWithMatchFields {
String targetField = e.getValue();
// @see Dimension#getSqlName
EasyField sourceFieldEasy = EasyMetaFactory.valueOf(MetadataHelper.getLastJoinField(sourceEntity, sourceField));
EasyField targetFieldEasy = EasyMetaFactory.valueOf(targetEntity.getField(targetField));
EasyField targetFieldEasy = EasyMetaFactory.valueOf(MetadataHelper.getLastJoinField(targetEntity, targetField));
// fix: 3.7.1
boolean isDateField = sourceFieldEasy.getDisplayType() == DisplayType.DATE

View file

@ -116,8 +116,7 @@ public class FieldWritebackController extends BaseController {
String target = getParameter(request, "target");
Entity targetEntity = StringUtils.isBlank(target) ? null : MetadataHelper.getEntity(target);
// 源字段
// 源实体字段
JSONArray sourceFields = MetaFormatter.buildFieldsWithRefs(sourceEntity, 3, true, field -> {
if (field instanceof EasyField) {
EasyField easyField = (EasyField) field;
@ -126,20 +125,26 @@ public class FieldWritebackController extends BaseController {
}
return false;
});
// ID
sourceFields.fluentAdd(0, EasyMetaFactory.toJSON(sourceEntity.getPrimaryField()));
JSONArray tmp = new JSONArray();
tmp.add(EasyMetaFactory.toJSON(sourceEntity.getPrimaryField()));
tmp.addAll(sourceFields);
sourceFields = tmp;
// 目标字段
// 目标实体字段
JSONArray targetFields = new JSONArray();
JSONArray targetFields4Group = new JSONArray();
if (targetEntity != null) {
targetFields = MetaFormatter.buildFieldsWithRefs(targetEntity, 1, true, field -> {
EasyField easyField = (EasyField) field;
return easyField.getDisplayType() == DisplayType.BARCODE || easyField.isBuiltin();
});
targetFields4Group = MetaFormatter.buildFieldsWithRefs(targetEntity, 2, false, field -> {
if (field instanceof EasyField) {
EasyField easyField = (EasyField) field;
return easyField.getDisplayType() == DisplayType.BARCODE
|| MetaFormatter.isSystemField4Hide(easyField.getRawMeta());
}
return false;
});
}
// 审批流程启用
@ -147,8 +152,8 @@ public class FieldWritebackController extends BaseController {
ObjectUtils.defaultIfNull(targetEntity.getMainEntity(), targetEntity), null) != null;
return JSONUtils.toJSONObject(
new String[]{"source", "target", "hadApproval"},
new Object[]{sourceFields, targetFields, hadApproval});
new String[]{"source", "target", "hadApproval", "target4Group"},
new Object[]{sourceFields, targetFields, hadApproval, targetFields4Group});
}
// 验证公式

View file

@ -78,7 +78,7 @@ class ContentFieldWriteback extends ActionContentSpec {
<label className="col-md-12 col-lg-3 col-form-label text-lg-right"></label>
<div className="col-md-12 col-lg-9">
<h5 className="mt-0 text-bold">{$L('字段匹配规则')}</h5>
<MatchFields targetFields={this.state.targetFields} sourceFields={this.__sourceFieldsCache} ref={(c) => (this._MatchFields = c)} />
<MatchFields targetFields={this.state.targetFields4Group} sourceFields={this.__sourceFieldsCache} ref={(c) => (this._MatchFields = c)} />
</div>
</div>
)}
@ -282,17 +282,22 @@ class ContentFieldWriteback extends ActionContentSpec {
}
$.get(`/admin/robot/trigger/field-writeback-fields?source=${this.props.sourceEntity}&target=${teSplit[1]}`, (res) => {
this.setState({ hasWarning: res.data.hadApproval ? $L('目标实体已启用审批流程可能影响源实体操作 (触发动作)建议启用允许强制更新') : null })
const _data = res.data || {}
this.setState({ hasWarning: _data.hadApproval ? $L('目标实体已启用审批流程可能影响源实体操作 (触发动作)建议启用允许强制更新') : null })
this.__sourceFieldsCache = res.data.source
this.__sourceFieldsCache = _data.source
let fieldsProps = {
targetFields: _data.target,
targetFields4Group: _data.target4Group,
}
if (this.state.targetFields) {
this.setState({ targetFields: res.data.target }, () => {
this.setState({ ...fieldsProps }, () => {
$(this._$targetField).trigger('change')
})
} else {
// init
this.setState({ sourceFields: res.data.source, targetFields: res.data.target }, () => {
this.setState({ sourceFields: _data.source, ...fieldsProps }, () => {
const $s2tf = $(this._$targetField)
.select2({ placeholder: $L('选择目标字段') })
.on('change', () => this._changeTargetField())
@ -326,7 +331,7 @@ class ContentFieldWriteback extends ActionContentSpec {
}
}
this._MatchFields && this._MatchFields.reset({ targetFields: this.state.targetFields, sourceFields: this.__sourceFieldsCache })
this._MatchFields && this._MatchFields.reset({ targetFields: this.state.targetFields4Group, sourceFields: this.__sourceFieldsCache })
})
}