Skip to content

Commit

Permalink
feat: 回收站多明细
Browse files Browse the repository at this point in the history
  • Loading branch information
getrebuild committed Nov 30, 2023
1 parent 19c87c5 commit a5e178a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,21 @@ public JSON serialize() {
JSONObject s = (JSONObject) queryed.serialize();

Entity detailEntity = entity.getDetailEntity();
if (detailEntity == null) {
return s;
}
if (detailEntity == null) return s;

// 明细
String detailSql = buildBaseSql(detailEntity)
.append(MetadataHelper.getDetailToMainField(detailEntity).getName())
.append(" = ?")
.toString();
List<Record> detailQueryed = Application.createQueryNoFilter(detailSql).setParameter(1, this.recordId).list();
// v36 多明细
JSONArray detailList = new JSONArray();
for (Record r : detailQueryed) {
detailList.add(r.serialize());
for (Entity de : entity.getDetialEntities()) {
String detailSql = buildBaseSql(de)
.append(MetadataHelper.getDetailToMainField(de).getName())
.append(" = ?")
.toString();
List<Record> detailQueryed = Application.createQueryNoFilter(detailSql).setParameter(1, this.recordId).list();
for (Record r : detailQueryed) {
JSONObject item = (JSONObject) r.serialize();
item.put(RestoreRecordCreator.META_FIELD, de.getName());
detailList.add(item);
}
}
s.put(NAME_DETAILLIST, detailList);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,22 @@ private List<Record> conver2Record(JSONObject content, ID recordId) {
Record record = new RestoreRecordCreator(entity, content).create(true);
records.add(record);

// v36 多明细
Entity detailEntity = entity.getDetailEntity();
if (detailList != null && detailEntity != null) {
for (Object o : detailList) {
Record detail = new RestoreRecordCreator(detailEntity, (JSONObject) o).create(true);
JSONObject item = (JSONObject) o;
Entity de = detailEntity;
if (item.containsKey(RestoreRecordCreator.META_FIELD)) {
String _entity = (String) item.remove(RestoreRecordCreator.META_FIELD);
if (!MetadataHelper.containsEntity(_entity)) {
log.warn("Detail entity not longer exists : {}", _entity);
continue;
}
de = MetadataHelper.getEntity(_entity);
}

Record detail = new RestoreRecordCreator(de, item).create(true);
records.add(detail);
}
}
Expand Down

0 comments on commit a5e178a

Please sign in to comment.