Search in sources :

Example 6 with EasyField

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 });
}
Also used : Entity(cn.devezhao.persist4j.Entity) FieldAggregationController.isAllowSourceField(com.rebuild.web.robot.trigger.FieldAggregationController.isAllowSourceField) Field(cn.devezhao.persist4j.Field) FieldAggregationController.buildField(com.rebuild.web.robot.trigger.FieldAggregationController.buildField) EasyField(com.rebuild.core.metadata.easymeta.EasyField) ArrayList(java.util.ArrayList) EasyField(com.rebuild.core.metadata.easymeta.EasyField) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with EasyField

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;
}
Also used : Entity(cn.devezhao.persist4j.Entity) JSONObject(com.alibaba.fastjson.JSONObject) JSONArray(com.alibaba.fastjson.JSONArray) JSONObject(com.alibaba.fastjson.JSONObject) EasyField(com.rebuild.core.metadata.easymeta.EasyField) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with EasyField

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;
}
Also used : EasyEntity(com.rebuild.core.metadata.easymeta.EasyEntity) EasyField(com.rebuild.core.metadata.easymeta.EasyField) Field(cn.devezhao.persist4j.Field) EasyEntity(com.rebuild.core.metadata.easymeta.EasyEntity) Entity(cn.devezhao.persist4j.Entity) DisplayType(com.rebuild.core.metadata.easymeta.DisplayType) FieldType(cn.devezhao.persist4j.dialect.FieldType) Type(cn.devezhao.persist4j.dialect.Type) JSONObject(com.alibaba.fastjson.JSONObject) ModelAndView(org.springframework.web.servlet.ModelAndView) JSONObject(com.alibaba.fastjson.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map) EasyField(com.rebuild.core.metadata.easymeta.EasyField)

Example 9 with EasyField

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;
}
Also used : EasyField(com.rebuild.core.metadata.easymeta.EasyField) Field(cn.devezhao.persist4j.Field) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JSONObject(com.alibaba.fastjson.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map) EasyField(com.rebuild.core.metadata.easymeta.EasyField)

Example 10 with EasyField

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);
}
Also used : EasyField(com.rebuild.core.metadata.easymeta.EasyField) Field(cn.devezhao.persist4j.Field) DisplayType(com.rebuild.core.metadata.easymeta.DisplayType) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JSONObject(com.alibaba.fastjson.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map) EasyField(com.rebuild.core.metadata.easymeta.EasyField) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

EasyField (com.rebuild.core.metadata.easymeta.EasyField)27 Field (cn.devezhao.persist4j.Field)16 JSONObject (com.alibaba.fastjson.JSONObject)15 DisplayType (com.rebuild.core.metadata.easymeta.DisplayType)11 Entity (cn.devezhao.persist4j.Entity)10 ArrayList (java.util.ArrayList)7 JSONArray (com.alibaba.fastjson.JSONArray)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 Record (cn.devezhao.persist4j.Record)4 ID (cn.devezhao.persist4j.engine.ID)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 MissingMetaExcetion (cn.devezhao.persist4j.metadata.MissingMetaExcetion)2 FieldAggregationController.buildField (com.rebuild.web.robot.trigger.FieldAggregationController.buildField)2 FieldAggregationController.isAllowSourceField (com.rebuild.web.robot.trigger.FieldAggregationController.isAllowSourceField)2 FieldType (cn.devezhao.persist4j.dialect.FieldType)1 Type (cn.devezhao.persist4j.dialect.Type)1 StandardRecord (cn.devezhao.persist4j.engine.StandardRecord)1 JSON (com.alibaba.fastjson.JSON)1 LayoutConfigService (com.rebuild.core.configuration.general.LayoutConfigService)1