Search in sources :

Example 6 with DisplayType

use of com.rebuild.core.metadata.easymeta.DisplayType in project rebuild by getrebuild.

the class MetaFieldController method fieldNew.

@PostMapping("field-new")
public RespBody fieldNew(HttpServletRequest request) {
    JSONObject reqJson = (JSONObject) ServletUtils.getRequestJson(request);
    String entityName = reqJson.getString("entity");
    String label = reqJson.getString("label");
    String type = reqJson.getString("type");
    String comments = reqJson.getString("comments");
    String refEntity = reqJson.getString("refEntity");
    String refClassification = reqJson.getString("refClassification");
    String stateClass = reqJson.getString("stateClass");
    Entity entity = MetadataHelper.getEntity(entityName);
    DisplayType dt = DisplayType.valueOf(type);
    JSON extConfig = null;
    if (dt == DisplayType.CLASSIFICATION) {
        ID dataId = ID.valueOf(refClassification);
        extConfig = JSONUtils.toJSONObject(EasyFieldConfigProps.CLASSIFICATION_USE, dataId);
    } else if (dt == DisplayType.STATE) {
        if (!StateHelper.isStateClass(stateClass)) {
            return RespBody.errorl("无效状态类 (Enum)");
        }
        extConfig = JSONUtils.toJSONObject(EasyFieldConfigProps.STATE_CLASS, stateClass);
    }
    try {
        String fieldName = new Field2Schema().createField(entity, label, dt, comments, refEntity, extConfig);
        return RespBody.ok(fieldName);
    } catch (Exception ex) {
        return RespBody.error(ex.getLocalizedMessage());
    }
}
Also used : EasyEntity(com.rebuild.core.metadata.easymeta.EasyEntity) Entity(cn.devezhao.persist4j.Entity) JSONObject(com.alibaba.fastjson.JSONObject) DisplayType(com.rebuild.core.metadata.easymeta.DisplayType) Field2Schema(com.rebuild.core.metadata.impl.Field2Schema) JSON(com.alibaba.fastjson.JSON) ID(cn.devezhao.persist4j.engine.ID)

Example 7 with DisplayType

use of com.rebuild.core.metadata.easymeta.DisplayType 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)

Example 8 with DisplayType

use of com.rebuild.core.metadata.easymeta.DisplayType in project rebuild by getrebuild.

the class BatchUpdateController method getFields.

@GetMapping("fields")
public List<JSONObject> getFields(@PathVariable String entity) {
    Entity entityMeta = MetadataHelper.getEntity(entity);
    List<JSONObject> updatableFields = new ArrayList<>();
    for (Field field : MetadataSorter.sortFields(entityMeta)) {
        if (!field.isUpdatable())
            continue;
        EasyField easyField = EasyMetaFactory.valueOf(field);
        if (!easyField.isUpdatable())
            continue;
        DisplayType dt = easyField.getDisplayType();
        // 不支持的字段
        if (dt == DisplayType.FILE || dt == DisplayType.IMAGE || dt == DisplayType.AVATAR || dt == DisplayType.BARCODE || dt == DisplayType.SERIES || dt == DisplayType.ANYREFERENCE || dt == DisplayType.LOCATION || dt == DisplayType.SIGN) {
            continue;
        }
        updatableFields.add(buildField(easyField));
    }
    return updatableFields;
}
Also used : Entity(cn.devezhao.persist4j.Entity) EasyField(com.rebuild.core.metadata.easymeta.EasyField) Field(cn.devezhao.persist4j.Field) JSONObject(com.alibaba.fastjson.JSONObject) DisplayType(com.rebuild.core.metadata.easymeta.DisplayType) ArrayList(java.util.ArrayList) EasyField(com.rebuild.core.metadata.easymeta.EasyField)

Example 9 with DisplayType

use of com.rebuild.core.metadata.easymeta.DisplayType in project rebuild by getrebuild.

the class EasyExcelGenerator method buildData.

/**
 * @param record
 * @param varsMap
 * @return
 */
protected Map<String, Object> buildData(Record record, Map<String, String> varsMap) {
    final Entity entity = record.getEntity();
    final String invalidFieldTip = Language.L("[无效字段]");
    final String unsupportFieldTip = Language.L("[暂不支持]");
    final Map<String, Object> data = new HashMap<>();
    // 无效字段填充
    for (Map.Entry<String, String> e : varsMap.entrySet()) {
        if (e.getValue() == null) {
            String varName = e.getKey();
            if (varName.startsWith(TemplateExtractor.NROW_PREFIX)) {
                varName = varName.substring(1);
            }
            data.put(varName, invalidFieldTip);
        }
    }
    for (final String fieldName : varsMap.values()) {
        if (fieldName == null)
            continue;
        EasyField easyField = EasyMetaFactory.valueOf(Objects.requireNonNull(MetadataHelper.getLastJoinField(entity, fieldName)));
        DisplayType dt = easyField.getDisplayType();
        // 替换成变量名
        String varName = fieldName;
        for (Map.Entry<String, String> e : varsMap.entrySet()) {
            if (fieldName.equalsIgnoreCase(e.getValue())) {
                varName = e.getKey();
                break;
            }
        }
        if (varName.startsWith(TemplateExtractor.NROW_PREFIX)) {
            varName = varName.substring(1);
        }
        if (!dt.isExportable()) {
            data.put(varName, unsupportFieldTip);
            continue;
        }
        Object fieldValue = record.getObjectValue(fieldName);
        if (dt == DisplayType.BARCODE) {
            data.put(varName, buildBarcodeData(easyField.getRawMeta(), record.getPrimary()));
        } else if (fieldValue == null) {
            data.put(varName, StringUtils.EMPTY);
        } else {
            if (dt == DisplayType.SIGN) {
                fieldValue = buildSignData((String) fieldValue);
            } else {
                fieldValue = FieldValueHelper.wrapFieldValue(fieldValue, easyField, true);
                if (FieldValueHelper.isUseDesensitized(easyField, this.getUser())) {
                    fieldValue = FieldValueHelper.desensitized(easyField, fieldValue);
                } else if (record.getEntity().getEntityCode() == EntityHelper.RobotApprovalStep && "state".equalsIgnoreCase(fieldName)) {
                    fieldValue = Language.L(ApprovalState.valueOf(ObjectUtils.toInt(fieldValue)));
                }
            }
            data.put(varName, fieldValue);
        }
    }
    return data;
}
Also used : Entity(cn.devezhao.persist4j.Entity) DisplayType(com.rebuild.core.metadata.easymeta.DisplayType) EasyField(com.rebuild.core.metadata.easymeta.EasyField)

Example 10 with DisplayType

use of com.rebuild.core.metadata.easymeta.DisplayType in project rebuild by getrebuild.

the class ParseHelper method useQuickField.

// --
/**
 * 字段是否可用于快速查询
 *
 * @param field
 * @return
 */
public static String useQuickField(Field field) {
    DisplayType dt = EasyMetaFactory.getDisplayType(field);
    // 引用字段要保证其兼容 LIKE 条件的语法要求
    if (dt == DisplayType.REFERENCE) {
        Field nameField = field.getReferenceEntity().getNameField();
        if (nameField.getType() == FieldType.REFERENCE) {
            log.warn("Quick field cannot be circular reference : " + nameField);
            return null;
        }
        String can = useQuickField(nameField);
        return can == null ? null : (QueryCompiler.NAME_FIELD_PREFIX + field.getName());
    } else if (dt == DisplayType.PICKLIST || dt == DisplayType.CLASSIFICATION) {
        return QueryCompiler.NAME_FIELD_PREFIX + field.getName();
    } else if (dt == DisplayType.TEXT || dt == DisplayType.EMAIL || dt == DisplayType.URL || dt == DisplayType.PHONE || dt == DisplayType.SERIES) {
        return field.getName();
    } else {
        return null;
    }
}
Also used : Field(cn.devezhao.persist4j.Field) DisplayType(com.rebuild.core.metadata.easymeta.DisplayType)

Aggregations

DisplayType (com.rebuild.core.metadata.easymeta.DisplayType)25 Field (cn.devezhao.persist4j.Field)13 JSONObject (com.alibaba.fastjson.JSONObject)11 EasyField (com.rebuild.core.metadata.easymeta.EasyField)10 Entity (cn.devezhao.persist4j.Entity)7 JSONArray (com.alibaba.fastjson.JSONArray)5 ID (cn.devezhao.persist4j.engine.ID)4 JSON (com.alibaba.fastjson.JSON)4 Field2Schema (com.rebuild.core.metadata.impl.Field2Schema)3 ArrayList (java.util.ArrayList)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 Record (cn.devezhao.persist4j.Record)2 Department (com.rebuild.core.privileges.bizz.Department)2 StandardRecord (cn.devezhao.persist4j.engine.StandardRecord)1 MetadataException (cn.devezhao.persist4j.metadata.MetadataException)1 MissingMetaExcetion (cn.devezhao.persist4j.metadata.MissingMetaExcetion)1 RebuildException (com.rebuild.core.RebuildException)1 EasyDateTime (com.rebuild.core.metadata.easymeta.EasyDateTime)1 EasyEntity (com.rebuild.core.metadata.easymeta.EasyEntity)1 Entity2Schema (com.rebuild.core.metadata.impl.Entity2Schema)1