-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* task-num show * feat: 审批可修改字段明细支持 * trigger job cron * entity-truncate
- Loading branch information
1 parent
88986b5
commit e03c733
Showing
24 changed files
with
404 additions
and
105 deletions.
There are no files selected for viewing
Submodule @rbv
updated
from 3e4b5e to fd2547
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
src/main/java/com/rebuild/core/service/approval/EditableFields.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/*! | ||
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.approval; | ||
|
||
import cn.devezhao.persist4j.Entity; | ||
import cn.devezhao.persist4j.engine.ID; | ||
import com.alibaba.fastjson.JSONArray; | ||
import com.alibaba.fastjson.JSONObject; | ||
import com.rebuild.core.configuration.general.LiteFormBuilder; | ||
import com.rebuild.core.metadata.MetadataHelper; | ||
import com.rebuild.core.metadata.easymeta.EasyMetaFactory; | ||
import com.rebuild.core.service.query.QueryHelper; | ||
import com.rebuild.utils.JSONUtils; | ||
import org.apache.commons.collections4.CollectionUtils; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* 可编辑字段 | ||
* | ||
* @author ZiXin | ||
* @since 2015/1/15 | ||
*/ | ||
public class EditableFields { | ||
|
||
private final JSONArray editableFields; | ||
|
||
public EditableFields(JSONArray editableFields) { | ||
this.editableFields = editableFields; | ||
} | ||
|
||
/** | ||
* @param recordId | ||
* @param user | ||
* @return | ||
*/ | ||
public JSONObject buildForms(ID recordId, ID user) { | ||
final Entity entity = MetadataHelper.getEntity(recordId.getEntityCode()); | ||
|
||
Map<String, JSONArray> fieldsByEntity = getEditableFieldsByEntity(entity.getName()); | ||
JSONObject aforms = new JSONObject(); | ||
|
||
JSONArray mFields = fieldsByEntity.remove(entity.getName()); | ||
if (CollectionUtils.isNotEmpty(mFields)) { | ||
JSONArray aform = new LiteFormBuilder(recordId, user).build(mFields); | ||
if (CollectionUtils.isNotEmpty(aform)) { | ||
aforms.put("aform", aform); | ||
aforms.put("aentity", entity.getName()); | ||
} | ||
} | ||
|
||
List<JSONObject> detailsByEntity = new ArrayList<>(); | ||
for (Map.Entry<String, JSONArray> e : fieldsByEntity.entrySet()) { | ||
Entity dEntity = MetadataHelper.getEntity(e.getKey()); | ||
JSONArray dFields = e.getValue(); | ||
|
||
JSONArray dForms = new JSONArray(); | ||
for (ID did : QueryHelper.detailIdsNoFilter(recordId, dEntity)) { | ||
JSONArray aform = new LiteFormBuilder(did, user).build(dFields); | ||
if (CollectionUtils.isNotEmpty(aform)) { | ||
aform.add(did); // Last is ID | ||
dForms.add(aform); | ||
} | ||
} | ||
|
||
if (!dForms.isEmpty()) { | ||
JSONObject d = JSONUtils.toJSONObject( | ||
new String[]{"aentity", "aentityLabel", "aforms"}, | ||
new Object[]{dEntity.getName(), EasyMetaFactory.getLabel(dEntity), dForms}); | ||
detailsByEntity.add(d); | ||
} | ||
} | ||
|
||
if (!detailsByEntity.isEmpty()) { | ||
aforms.put("aform_details", detailsByEntity); | ||
} | ||
|
||
return aforms; | ||
} | ||
|
||
private Map<String, JSONArray> getEditableFieldsByEntity(String entityName) { | ||
Map<String, JSONArray> fieldsByEntity = new HashMap<>(); | ||
for (Object o : editableFields) { | ||
JSONObject item = (JSONObject) o; | ||
String fieldName = item.getString("field"); | ||
String[] ef; | ||
if (fieldName.contains(".")) ef = fieldName.split("\\."); | ||
else ef = new String[]{entityName, fieldName}; | ||
|
||
JSONArray fields = fieldsByEntity.computeIfAbsent(ef[0], k -> new JSONArray()); | ||
item.put("field", ef[1]); | ||
fields.add(item); | ||
} | ||
return fieldsByEntity; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.