Skip to content

Commit

Permalink
OK
Browse files Browse the repository at this point in the history
  • Loading branch information
getrebuild committed Nov 14, 2024
1 parent 9e72a92 commit 6731c23
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 13 deletions.
9 changes: 9 additions & 0 deletions src/main/java/com/rebuild/core/metadata/DeleteRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import cn.devezhao.persist4j.engine.ID;
import cn.devezhao.persist4j.engine.StandardRecord;
import lombok.Getter;

/**
* 删除专用
Expand All @@ -19,8 +20,16 @@
public class DeleteRecord extends StandardRecord {
private static final long serialVersionUID = -7098132591224439549L;

@Getter
private boolean quietly;

public DeleteRecord(ID primaryid, ID editor) {
this(primaryid, editor, false);
}

public DeleteRecord(ID primaryid, ID editor, boolean quietly) {
super(MetadataHelper.getEntity(primaryid.getEntityCode()), editor);
this.setID(getEntity().getPrimaryField().getName(), primaryid);
this.quietly = quietly;
}
}
4 changes: 4 additions & 0 deletions src/main/java/com/rebuild/core/metadata/EntityHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ public static Record parse(JSONObject data, ID user, boolean safetyUrl, boolean
String id = metadata.getString("id");
return new DeleteRecord(ID.valueOf(id), user);
}
if (metadata.getBooleanValue("deleteQuietly")) {
String id = metadata.getString("id");
return new DeleteRecord(ID.valueOf(id), user, true);
}

Record record = new EntityRecordCreator(MetadataHelper.getEntity(entityName), data, user, safetyUrl)
.create(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,13 @@ record = record.getPrimary() == null ? create(record) : update(record);
for (int i = 0; i < details.size(); i++) {
Record d = details.get(i);
if (d instanceof DeleteRecord) {
des.delete(d.getPrimary());
detaileds.put(i, d.getPrimary());
// 安静删除,不触发任何系统逻辑
if (((DeleteRecord) d).isQuietly()) {
Application.getCommonsService().delete(d.getPrimary(), false);
} else {
des.delete(d.getPrimary());
detaileds.put(i, d.getPrimary());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected ID saveRecord(Record record, List<Record> detailsList) {
if (hasDetailsConf != null && !hasDetailsConf.isEmpty()) {
List<ID> detailIds = QueryHelper.detailIdsNoFilter(targetRecordId);
if (!detailIds.isEmpty()) {
Application.getCommonsService().delete(detailIds.toArray(new ID[0]), true);
Application.getCommonsService().delete(detailIds.toArray(new ID[0]), false);
}
}

Expand Down Expand Up @@ -126,7 +126,7 @@ public JSON preview(ID sourceRecordId, ID specMainId, ID targetRecordId) {

// 有明细
ID fakeMainId = EntityHelper.newUnsavedId(sourceEntity.getEntityCode());
Map<String, JSONArray> formModelDetailsMap = new HashMap<>();
Map<String, Object> formModelDetailsMap = new HashMap<>();
for (Object o : fieldsMappingDetails) {
JSONObject fmd = (JSONObject) o;
Entity[] fmdEntity = checkEntity(fmd);
Expand Down Expand Up @@ -157,6 +157,14 @@ public JSON preview(ID sourceRecordId, ID specMainId, ID targetRecordId) {
} finally {
FormsBuilderContextHolder.getMainIdOfDetail(true);
}

// 删除已有的
if (targetRecordId != null) {
List<ID> detailIds = QueryHelper.detailIdsNoFilter(targetRecordId);
if (!detailIds.isEmpty()) {
formModelDetailsMap.put(dTargetEntity.getName() + "$DELETED", detailIds);
}
}
}

((JSONObject) formModel).put(GeneralEntityService.HAS_DETAILS, formModelDetailsMap);
Expand All @@ -175,5 +183,7 @@ private void merge2ExistsTarget(Record targetRecord) {
targetRecord.removeValue(EntityHelper.OwningUser);
targetRecord.removeValue(EntityHelper.OwningDept);
}

// FIXME 有空值问题,例如源纪录的A字段无值,对应目标字段有值,此时会出现问题(空值应更新到目标中)
}
}
3 changes: 3 additions & 0 deletions src/main/resources/web/assets/js/general/rb-assignshare.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,9 @@ class DlgTransform extends RbModalHandler {
return RbHighbar.createl('请选择主记录')
}
}
if (_post.sourceRecord === _post.existsRecord) {
return RbHighbar.createl('已有记录不能是当前记录')
}

const $btn = $(this._$btn).find('.btn').button('loading')
$.post('/app/entity/extras/transform39', JSON.stringify(_post), (res) => {
Expand Down
8 changes: 6 additions & 2 deletions src/main/resources/web/assets/js/general/rb-forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,19 +329,21 @@ class RbForm extends React.Component {

// v3.7 ND
const detailImports = this.props.rawModel.detailImports
// v3.9 记录转换
const transDetails = this.props.rawModel.$DETAILS$

this._ProTables = {}

return (
<RF>
{this.props.rawModel.detailMetas.map((item, idx) => {
return <RF key={idx}>{this.renderDetailsForm(item, detailImports)}</RF>
return <RF key={idx}>{this.renderDetailsForm(item, detailImports, transDetails)}</RF>
})}
</RF>
)
}

renderDetailsForm(detailMeta, detailImports) {
renderDetailsForm(detailMeta, detailImports, transDetails) {
let _ProTable
if (window._CustomizedForms) {
_ProTable = window._CustomizedForms.useProTable(detailMeta.entity, this)
Expand Down Expand Up @@ -453,6 +455,8 @@ class RbForm extends React.Component {
this._ProTable = c // comp:v3.8
}}
$$$main={this}
transDetails={transDetails ? transDetails[detailMeta.entity] : null}
transDetailsDelete={transDetails ? transDetails[detailMeta.entity + '$DELETED'] : null}
/>
)
} else {
Expand Down
28 changes: 21 additions & 7 deletions src/main/resources/web/assets/js/general/rb-forms.protable.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,13 @@ class ProTable extends React.Component {
$(this._$scroller).find('thead .tipping').tooltip()
})

// 记录转换
if (this.props.transDetails) {
this.setLines(this.props.transDetails)
this._deletesQuietly = this.props.transDetailsDelete
}
// 正常编辑
if (this.props.mainid) {
else if (this.props.mainid) {
$.get(`/app/${entity.entity}/detail-models?mainid=${this.props.mainid}`, (res) => {
if (res.error_code === 0) this.setLines(res.data)
else RbHighbar.error($L('明细加载失败,请稍后重试'))
Expand Down Expand Up @@ -370,19 +375,28 @@ class ProTable extends React.Component {
return null
}

// 删除
if (this._deletes) {
// 删除的
this._deletes &&
this._deletes.forEach((item) => {
const d = {
datas.push({
metadata: {
entity: this.props.entity.entity,
id: item,
delete: true,
},
}
datas.push(d)
})
})
// 记录转换删除的
this._deletesQuietly &&
this._deletesQuietly.forEach((item) => {
datas.push({
metadata: {
entity: this.props.entity.entity,
id: item,
deleteQuietly: true,
},
})
})
}

return datas
}
Expand Down

0 comments on commit 6731c23

Please sign in to comment.