use of com.rebuild.core.metadata.easymeta.EasyField in project rebuild by getrebuild.
the class GroupAggregationController method getTargetEntities.
@RequestMapping("group-aggregation-entities")
public JSON getTargetEntities(@EntityParam(name = "source") Entity sourceEntity) {
// 目标实体
List<String[]> entities = new ArrayList<>();
// 任意
for (Entity entity : MetadataSorter.sortEntities(null, false, true)) {
if (entity.equals(sourceEntity))
continue;
entities.add(new String[] { entity.getName(), EasyMetaFactory.getLabel(entity) });
}
// 源-分组字段
List<String[]> sourceGroupFields = new ArrayList<>();
// 源-聚合字段
List<String[]> sourceFields = new ArrayList<>();
for (Field field : MetadataSorter.sortFields(sourceEntity)) {
EasyField easyField = EasyMetaFactory.valueOf(field);
String[] build = buildIfGroupField(easyField);
if (build != null)
sourceGroupFields.add(build);
if (isAllowSourceField(field)) {
sourceFields.add(buildField(field));
}
}
// 明细实体则包括主实体
if (sourceEntity.getMainEntity() != null) {
String prefixName = MetadataHelper.getDetailToMainField(sourceEntity).getName() + ".";
String prefixLabel = EasyMetaFactory.getLabel(sourceEntity.getMainEntity()) + ".";
for (Field field : MetadataSorter.sortFields(sourceEntity.getMainEntity())) {
EasyField easyField = EasyMetaFactory.valueOf(field);
String[] build = buildIfGroupField(easyField);
if (build != null) {
build[0] = prefixName + build[0];
build[1] = prefixLabel + build[1];
sourceGroupFields.add(build);
}
}
}
return JSONUtils.toJSONObject(new String[] { "targetEntities", "sourceGroupFields", "sourceFields" }, new Object[] { entities, sourceGroupFields, sourceFields });
}
use of com.rebuild.core.metadata.easymeta.EasyField in project rebuild by getrebuild.
the class RevisionHistoryController method details.
@RequestMapping("revision-history/details")
public JSON details(@IdParam ID revisionId) {
Object[] rev = Application.createQueryNoFilter("select revisionContent,belongEntity from RevisionHistory where revisionId = ?").setParameter(1, revisionId).unique();
JSONArray contents = JSON.parseArray((String) rev[0]);
// 补充字段名称
if (MetadataHelper.containsEntity((String) rev[1])) {
Entity entity = MetadataHelper.getEntity((String) rev[1]);
for (Iterator<Object> iter = contents.iterator(); iter.hasNext(); ) {
JSONObject item = (JSONObject) iter.next();
String fieldName = item.getString("field");
if (entity.containsField(fieldName)) {
EasyField easyField = EasyMetaFactory.valueOf(entity.getField(fieldName));
// 排除不可查询字段
if (!easyField.isQueryable()) {
iter.remove();
continue;
}
fieldName = easyField.getLabel();
} else {
if ("SHARETO".equalsIgnoreCase(fieldName)) {
fieldName = Language.L("共享用户");
} else {
fieldName = "[" + fieldName.toUpperCase() + "]";
}
}
item.put("field", fieldName);
}
}
return contents;
}
use of com.rebuild.core.metadata.easymeta.EasyField in project rebuild by getrebuild.
the class MetaFieldController method pageEntityField.
@GetMapping("{entity}/field/{field}")
public ModelAndView pageEntityField(@PathVariable String entity, @PathVariable String field, HttpServletRequest request) {
ModelAndView mv = createModelAndView("/admin/metadata/field-edit");
EasyEntity easyEntity = MetaEntityController.setEntityBase(mv, entity);
Field fieldMeta = easyEntity.getRawMeta().getField(field);
EasyField easyField = EasyMetaFactory.valueOf(fieldMeta);
mv.getModel().put("fieldMetaId", easyField.getMetaId());
mv.getModel().put("fieldName", easyField.getName());
mv.getModel().put("fieldLabel", easyField.getLabel());
mv.getModel().put("fieldComments", easyField.getComments());
mv.getModel().put("fieldType", easyField.getDisplayType(false));
mv.getModel().put("fieldTypeLabel", easyField.getDisplayType(true));
mv.getModel().put("fieldNullable", fieldMeta.isNullable());
mv.getModel().put("fieldCreatable", fieldMeta.isCreatable());
mv.getModel().put("fieldUpdatable", fieldMeta.isUpdatable());
mv.getModel().put("fieldRepeatable", fieldMeta.isRepeatable());
mv.getModel().put("fieldQueryable", fieldMeta.isQueryable());
mv.getModel().put("fieldBuildin", easyField.isBuiltin());
mv.getModel().put("fieldDefaultValue", fieldMeta.getDefaultValue());
mv.getModel().put("isSuperAdmin", UserHelper.isSuperAdmin(getRequestUser(request)));
// 明细实体
if (easyEntity.getRawMeta().getMainEntity() != null) {
Field dtmField = MetadataHelper.getDetailToMainField(easyEntity.getRawMeta());
mv.getModel().put("isDetailToMainField", dtmField.equals(fieldMeta));
} else {
mv.getModel().put("isDetailToMainField", false);
}
// 字段类型相关
Type ft = fieldMeta.getType();
if (ft == FieldType.REFERENCE || ft == FieldType.REFERENCE_LIST) {
Entity refEntity = fieldMeta.getReferenceEntity();
mv.getModel().put("fieldRefentity", refEntity.getName());
mv.getModel().put("fieldRefentityLabel", EasyMetaFactory.getLabel(refEntity));
}
// 扩展配置
JSONObject extraAttrs = new JSONObject();
for (Map.Entry<String, Object> e : easyField.getExtraAttrs(true).entrySet()) {
String name = e.getKey();
// 排除私有
if (!name.startsWith("_"))
extraAttrs.put(name, e.getValue());
}
mv.getModel().put("fieldExtConfig", extraAttrs);
return mv;
}
use of com.rebuild.core.metadata.easymeta.EasyField in project rebuild by getrebuild.
the class MetaFieldController method listField.
@RequestMapping("list-field")
public List<Map<String, Object>> listField(@EntityParam Entity entity) {
List<Map<String, Object>> fieldList = new ArrayList<>();
for (Field field : MetadataSorter.sortFields(entity)) {
EasyField easyMeta = EasyMetaFactory.valueOf(field);
Map<String, Object> map = new HashMap<>();
if (easyMeta.getMetaId() != null)
map.put("fieldId", easyMeta.getMetaId());
map.put("fieldName", easyMeta.getName());
map.put("fieldLabel", easyMeta.getLabel());
map.put("comments", easyMeta.getComments());
map.put("displayType", Language.L(easyMeta.getDisplayType()));
map.put("nullable", field.isNullable());
map.put("builtin", easyMeta.isBuiltin());
map.put("creatable", field.isCreatable());
fieldList.add(map);
}
return fieldList;
}
use of com.rebuild.core.metadata.easymeta.EasyField in project rebuild by getrebuild.
the class DataImportController method importFields.
// 可用字段
@RequestMapping("/data-imports/import-fields")
public RespBody importFields(@EntityParam Entity entity) {
List<Map<String, Object>> alist = new ArrayList<>();
for (Field field : MetadataSorter.sortFields(entity)) {
String fieldName = field.getName();
if (EntityHelper.OwningDept.equals(fieldName) || MetadataHelper.isApprovalField(fieldName) || MetadataHelper.isSystemField(fieldName)) {
continue;
}
EasyField easyMeta = EasyMetaFactory.valueOf(field);
DisplayType dt = easyMeta.getDisplayType();
if (!dt.isImportable()) {
continue;
}
Map<String, Object> map = new HashMap<>();
map.put("name", fieldName);
map.put("label", easyMeta.getLabel());
map.put("type", easyMeta.getDisplayType().name());
map.put("nullable", field.isNullable());
String defaultValue = null;
if (EntityHelper.CreatedOn.equals(fieldName) || EntityHelper.ModifiedOn.equals(fieldName)) {
defaultValue = Language.L("当前时间");
} else if (EntityHelper.CreatedBy.equals(fieldName) || EntityHelper.ModifiedBy.equals(fieldName) || EntityHelper.OwningUser.equals(fieldName)) {
defaultValue = Language.L("当前用户");
} else if (easyMeta.getDisplayType() == DisplayType.SERIES) {
defaultValue = Language.L("自动编号");
}
if (defaultValue != null) {
map.put("defaultValue", defaultValue);
}
alist.add(map);
}
return RespBody.ok(alist);
}
Aggregations