Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion @rbv
Submodule @rbv updated from 385ec3 to e44942
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>com.rebuild</groupId>
<artifactId>rebuild</artifactId>
<version>4.2.3</version>
<version>4.3.0-dev</version>
<name>rebuild</name>
<description>Building your business-systems freely!</description>
<url>https://getrebuild.com/</url>
Expand Down
32 changes: 28 additions & 4 deletions src/main/java/com/rebuild/core/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.rebuild.core.privileges.PrivilegesManager;
import com.rebuild.core.privileges.RecordOwningCache;
import com.rebuild.core.privileges.UserStore;
import com.rebuild.core.service.BaseService;
import com.rebuild.core.service.CommonsService;
import com.rebuild.core.service.ServiceSpec;
import com.rebuild.core.service.SqlExecutor;
Expand Down Expand Up @@ -76,11 +77,11 @@ public class Application implements ApplicationListener<ApplicationStartedEvent>
/**
* Rebuild Version
*/
public static final String VER = "4.2.3";
public static final String VER = "4.3.0-dev";
/**
* Rebuild Build [MAJOR]{1}[MINOR]{2}[PATCH]{2}[BUILD]{2}
*/
public static final int BUILD = 4020308;
public static final int BUILD = 4030000;

static {
// Driver for DB
Expand Down Expand Up @@ -351,7 +352,9 @@ public static SqlExecutor getSqlExecutor() {

/**
* 非业务实体使用
* @see #getCommonsService()
*
* @param entityCode
* @return
*/
public static ServiceSpec getService(int entityCode) {
if (_ESS != null && _ESS.containsKey(entityCode)) {
Expand All @@ -369,7 +372,9 @@ public static ServiceSpec getService(int entityCode) {

/**
* 业务实体使用
* @see #getGeneralEntityService()
*
* @param entityCode
* @return
*/
public static EntityService getEntityService(int entityCode) {
ServiceSpec es = null;
Expand All @@ -388,14 +393,33 @@ public static EntityService getEntityService(int entityCode) {
throw new RebuildException("Non EntityService implements : " + entityCode);
}

/**
* 业务实体使用
*
* @return
*/
public static GeneralEntityService getGeneralEntityService() {
return (GeneralEntityService) getContext().getBean("rbGeneralEntityService");
}

/**
* 纯增删改操作 *无*业务规则 *无*字段值处理
*
* @return
* @see #getBaseService()
*/
public static CommonsService getCommonsService() {
return (CommonsService) getContext().getBean("rbCommonsService");
}

/**
* 纯增删改操作 *无*业务规则 *有*字段值处理
* @return
*/
public static BaseService getBaseService() {
return getCommonsService().getBaseService();
}

/**
* @param entity
* @return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ public EntityRecordCreator(Entity entity, JSONObject source, ID editor, boolean
@Override
public boolean setFieldValue(Field field, String value, Record record) {
value = setValueByLiteralBefore(field, value, record, true);
if (value == null) return false;

return super.setFieldValue(field, value, record);
}

Expand Down Expand Up @@ -308,9 +306,7 @@ protected static String setValueByLiteralBefore(Field field, String value, Recor
* @see RecordVisitor#setValueByLiteral(Field, String, Record)
*/
public static void setValueByLiteral(Field field, String value, Record record, boolean checkPattern) {
value = setValueByLiteralBefore(field, value, record, checkPattern);
if (value == null) return;

value = value == null ? null : setValueByLiteralBefore(field, value, record, checkPattern);
RecordVisitor.setValueByLiteral(field, value, record);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
import com.rebuild.core.metadata.EntityHelper;
import com.rebuild.core.metadata.EntityRecordCreator;
import com.rebuild.core.metadata.MetadataHelper;
import com.rebuild.core.metadata.easymeta.DisplayType;
import com.rebuild.core.metadata.easymeta.EasyField;
import com.rebuild.core.metadata.easymeta.EasyMetaFactory;
import com.rebuild.core.metadata.easymeta.EasyTag;
import com.rebuild.core.privileges.UserService;
import com.rebuild.core.service.general.GeneralEntityService;
import com.rebuild.core.service.general.GeneralEntityServiceContextHolder;
Expand Down Expand Up @@ -56,10 +58,10 @@ public class RecordTransfomer extends SetUser {
private static final ThreadLocal<ID> FILLBACK2_ONCE414 = new NamedThreadLocal<>("FallbackMode=2 Trigger Once");

final protected Entity targetEntity;
final protected JSONObject transConfig;
final protected boolean skipGuard;

final private ID transid;
final protected JSONObject transConfig;
final protected ID transid;

/**
* @param transid
Expand Down Expand Up @@ -213,28 +215,42 @@ record = Application.getBestService(targetEntity).createOrUpdate(record);
* @return
*/
protected boolean fillback(ID sourceRecordId, ID newId) {
return fillback(sourceRecordId, new ID[]{newId});
}

/**
* @param sourceRecordId
* @param newIds
* @return
*/
protected boolean fillback(ID sourceRecordId, ID[] newIds) {
final Entity sourceEntity = MetadataHelper.getEntity(sourceRecordId.getEntityCode());
String fillbackField = transConfig.getString("fillbackField");
if (fillbackField == null || !MetadataHelper.checkAndWarnField(sourceEntity, fillbackField)) {
return false;
}

Record updateSource = EntityHelper.forUpdate(sourceRecordId, UserService.SYSTEM_USER, false);
updateSource.setID(fillbackField, newId);
// 更新源纪录
Record s = EntityHelper.forUpdate(sourceRecordId, UserService.SYSTEM_USER, false);
if (EasyMetaFactory.getDisplayType(s.getEntity().getField(fillbackField)) == DisplayType.N2NREFERENCE) {
s.setIDArray(fillbackField, newIds);
} else {
s.setID(fillbackField, newIds[0]);
}

// 4.1.4 (LAB) 配置开放
int fillbackMode = transConfig.getIntValue("fillbackMode");
if (fillbackMode == 2 && !EntityHelper.isUnsavedId(newId) && FILLBACK2_ONCE414.get() == null) {
GeneralEntityServiceContextHolder.setAllowForceUpdate(updateSource.getPrimary());
FILLBACK2_ONCE414.set(newId);
if (fillbackMode == 2 && !EntityHelper.isUnsavedId(newIds) && FILLBACK2_ONCE414.get() == null) {
GeneralEntityServiceContextHolder.setAllowForceUpdate(s.getPrimary());
FILLBACK2_ONCE414.set(newIds[0]);
try {
Application.getEntityService(sourceEntity.getEntityCode()).update(updateSource);
Application.getEntityService(sourceEntity.getEntityCode()).update(s);
} finally {
GeneralEntityServiceContextHolder.isAllowForceUpdateOnce();
}
} else {
// 无传播更新
Application.getCommonsService().update(updateSource, false);
Application.getBaseService().update(s);
}
return true;
}
Expand Down Expand Up @@ -293,6 +309,11 @@ protected Record transformRecord(

if (sourceAny instanceof JSONArray) {
Object sourceValue = ((JSONArray) sourceAny).get(0);
// fix:4.3
if (targetFieldEasy.getDisplayType() == DisplayType.TAG) {
sourceValue = sourceValue.toString().replace(", ", EasyTag.VALUE_SPLIT);
}

EntityRecordCreator.setValueByLiteral(
targetFieldEasy.getRawMeta(), sourceValue.toString(), targetRecord, false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,23 @@
@Slf4j
public class RecordTransfomer39 extends RecordTransfomer37 {

private ID transid;
// 转换到已存在记录
private ID targetExistsRecordId;
// 预览时生成的 Record
volatile private List<Record> previewRecords;

public RecordTransfomer39(ID transid) {
super(transid);
this.transid = transid;
}

@Override
public ID transform(ID sourceRecordId) {
return this.transform(sourceRecordId, null, null);
return transform(sourceRecordId, null, null);
}

@Override
public ID transform(ID sourceRecordId, ID specMainId) {
return this.transform(sourceRecordId, specMainId, null);
return transform(sourceRecordId, specMainId, null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*!
Copyright (c) REBUILD <https://getrebuild.com/> and/or its owners. All rights reserved.

rebuild is dual-licensed under commercial and open source licenses (GPLv3).
See LICENSE and COMMERCIAL in the project root for license information.
*/

package com.rebuild.core.service.general.transform;

import cn.devezhao.commons.ObjectUtils;
import cn.devezhao.persist4j.Record;
import cn.devezhao.persist4j.engine.ID;
import com.alibaba.fastjson.JSONArray;
import com.rebuild.core.configuration.general.MultiSelectManager;
import com.rebuild.core.metadata.MetadataHelper;
import com.rebuild.core.metadata.easymeta.DisplayType;
import com.rebuild.core.metadata.easymeta.EasyField;
import com.rebuild.core.metadata.easymeta.EasyMetaFactory;
import com.rebuild.core.service.query.QueryHelper;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
* v4.3 支持 `one2n` 模式
*
* @author Zixin
* @since 2025/11/23
*/
public class RecordTransfomer43 extends RecordTransfomer39 {

private ID sourceRecordId;
private String one2nModeField;

private ID[] fillbackReadyIds = null;

public RecordTransfomer43(ID transid) {
super(transid);
}

@Override
public ID transform(ID sourceRecordId, ID specMainId, ID targetExistsRecordId) {
boolean one2nMode = transConfig.getBooleanValue("one2nMode");
this.one2nModeField = one2nMode ? transConfig.getString("one2nModeField") : null;
this.sourceRecordId = sourceRecordId;

return super.transform(sourceRecordId, specMainId, targetExistsRecordId);
}

@Override
protected ID saveRecord(Record record, List<Record> detailsList) {
if (StringUtils.isBlank(one2nModeField)) {
return super.saveRecord(record, detailsList);
}

// 需要保存为多条
// TODO 如果多条主记录,明细(如有)都会带着

Object multiValue = QueryHelper.queryFieldValue(sourceRecordId, one2nModeField);
if (multiValue == null) {
return super.saveRecord(record, detailsList);
}

List<Object> multiValueSplit = new ArrayList<>();
// TAG, N2NREF
if (multiValue instanceof Object[]) {
Collections.addAll(multiValueSplit, (Object[]) multiValue);
} else if (multiValue instanceof Number) {
// MULTISELECT
EasyField one2nModeFieldEasy = EasyMetaFactory.valueOf(
MetadataHelper.getEntity(sourceRecordId.getEntityCode()).getField(one2nModeField));
if (one2nModeFieldEasy.getDisplayType() == DisplayType.MULTISELECT) {
multiValue = MultiSelectManager.instance.getLabels((Long) multiValue, one2nModeFieldEasy.getRawMeta());
Collections.addAll(multiValueSplit, (Object[]) multiValue);
}
// NUMBER
else {
for (int i = 0; i < ObjectUtils.toInt(multiValue); i++) {
multiValueSplit.add(1);
}
}
}

if (multiValueSplit.size() <= 1) {
return super.saveRecord(record, detailsList);
}

// `转换依据字段` 未映射则不保存此字段值
Object hm = transConfig.getJSONObject("fieldsMapping").get(one2nModeField);
DisplayType hasMappingTargetType = null;
if (hm != null) {
if (hm instanceof JSONArray) {
// 使用固定值
} else {
hasMappingTargetType = EasyMetaFactory.getDisplayType(record.getEntity().getField(hm.toString()));
}
}

List<ID> theNewId = new ArrayList<>();
for (Object value : multiValueSplit) {
Record clone = record.clone();
if (hasMappingTargetType != null) {
if (hasMappingTargetType == DisplayType.N2NREFERENCE) {
clone.setObjectValue(one2nModeField, new ID[]{(ID) value});
} else {
clone.setObjectValue(one2nModeField, value);
}
}

theNewId.add(super.saveRecord(clone, detailsList));
}

// 回填
fillbackReadyIds = theNewId.toArray(new ID[0]);

// 返回最先那条
return fillbackReadyIds[0];
}

@Override
protected boolean fillback(ID sourceRecordId, ID newId) {
if (fillbackReadyIds == null) return true;
return super.fillback(sourceRecordId, fillbackReadyIds);
}

// --

/**
* @param transid
* @return
*/
public static RecordTransfomer39 create(ID transid) {
return new RecordTransfomer43(transid);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.rebuild.core.metadata.easymeta.EasyDateTime;
import com.rebuild.core.metadata.easymeta.EasyField;
import com.rebuild.core.metadata.easymeta.EasyMetaFactory;
import com.rebuild.core.metadata.easymeta.EasyTag;
import com.rebuild.core.metadata.easymeta.MultiValue;
import com.rebuild.core.metadata.easymeta.PatternValue;
import com.rebuild.core.privileges.UserService;
Expand Down Expand Up @@ -428,6 +429,11 @@ protected Record buildTargetRecordData(OperatingContext operatingContext, ID tar

// 固定值
else if ("VFIXED".equalsIgnoreCase(updateMode)) {
// fix:4.3
if (targetFieldEasy.getDisplayType() == DisplayType.TAG) {
sourceAny = sourceAny.replace(", ", EasyTag.VALUE_SPLIT);
}

EntityRecordCreator.setValueByLiteral(
targetFieldEasy.getRawMeta(), sourceAny, targetRecord, false);
}
Expand Down
Loading
Loading