Search in sources :

Example 11 with EasyField

use of com.rebuild.core.metadata.easymeta.EasyField 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 12 with EasyField

use of com.rebuild.core.metadata.easymeta.EasyField 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 13 with EasyField

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

the class SeriesZeroResetJob method executeJob.

@Scheduled(cron = "0 0 0 * * ?")
protected void executeJob() {
    if (!tryLock())
        return;
    boolean isFirstDayOfYear = false;
    boolean isFirstDayOfMonth = false;
    final Calendar now = CalendarUtils.getInstance();
    if (now.get(Calendar.DAY_OF_MONTH) == 1) {
        isFirstDayOfMonth = true;
        if (now.get(Calendar.MONTH) == Calendar.JANUARY) {
            isFirstDayOfYear = true;
        }
    }
    for (Entity entity : MetadataHelper.getEntities()) {
        for (Field field : entity.getFields()) {
            EasyField easyField = EasyMetaFactory.valueOf(field);
            if (easyField.getDisplayType() == DisplayType.SERIES) {
                String zeroMode = easyField.getExtraAttr(EasyFieldConfigProps.SERIES_ZERO);
                if ("D".equalsIgnoreCase(zeroMode)) {
                    SeriesGeneratorFactory.zero(field);
                    log.info("Zero field by [D] : " + field);
                } else if ("M".equalsIgnoreCase(zeroMode) && isFirstDayOfMonth) {
                    SeriesGeneratorFactory.zero(field);
                    log.info("Zero field by [M] : " + field);
                } else if ("Y".equalsIgnoreCase(zeroMode) && isFirstDayOfYear) {
                    SeriesGeneratorFactory.zero(field);
                    log.info("Zero field by [Y] : " + field);
                }
            }
        }
    }
}
Also used : Entity(cn.devezhao.persist4j.Entity) Field(cn.devezhao.persist4j.Field) EasyField(com.rebuild.core.metadata.easymeta.EasyField) Calendar(java.util.Calendar) EasyField(com.rebuild.core.metadata.easymeta.EasyField) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 14 with EasyField

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

the class Field2Schema method dropField.

/**
 * @param field
 * @param force
 * @return
 */
public boolean dropField(Field field, boolean force) {
    EasyField easyMeta = EasyMetaFactory.valueOf(field);
    ID metaRecordId = easyMeta.getMetaId();
    if (easyMeta.isBuiltin() || metaRecordId == null) {
        throw new MetadataModificationException(Language.L("系统内置,不允许删除"));
    }
    Entity entity = field.getOwnEntity();
    if (entity.getNameField().equals(field)) {
        throw new MetadataModificationException(Language.L("名称字段不允许删除"));
    }
    if (!force) {
        long count;
        if ((count = checkRecordCount(entity)) > 100000) {
            throw new MetadataModificationException(Language.L("实体记录过多 (%d),增加/删除字段可能导致表损坏", count));
        }
    }
    String ddl = String.format("alter table `%s` drop column `%s`", entity.getPhysicalName(), field.getPhysicalName());
    try {
        Application.getSqlExecutor().execute(ddl, 10 * 60);
    } catch (Throwable ex) {
        if (ThrowableUtils.getRootCause(ex).getLocalizedMessage().contains("exists")) {
            log.warn("Column not exists? " + ex.getLocalizedMessage());
        } else {
            log.error("DDL ERROR : \n" + ddl, ex);
            return false;
        }
    }
    Application.getBean(MetaFieldService.class).delete(metaRecordId);
    MetadataHelper.getMetadataFactory().refresh();
    return true;
}
Also used : Entity(cn.devezhao.persist4j.Entity) ID(cn.devezhao.persist4j.engine.ID) EasyField(com.rebuild.core.metadata.easymeta.EasyField)

Example 15 with EasyField

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

the class MetaSchemaGenerator method performField.

private JSON performField(Field field) {
    final JSONObject schemaField = new JSONObject(true);
    final EasyField easyField = EasyMetaFactory.valueOf(field);
    final DisplayType dt = easyField.getDisplayType();
    schemaField.put("field", easyField.getName());
    schemaField.put("fieldLabel", easyField.getLabel());
    schemaField.put("displayType", dt.name());
    if (easyField.getComments() != null) {
        schemaField.put("comments", easyField.getComments());
    }
    schemaField.put("nullable", field.isNullable());
    schemaField.put("updatable", field.isUpdatable());
    schemaField.put("repeatable", field.isRepeatable());
    schemaField.put("queryable", field.isQueryable());
    Object defaultVal = field.getDefaultValue();
    if (defaultVal != null && StringUtils.isNotBlank((String) defaultVal)) {
        schemaField.put("defaultValue", defaultVal);
    }
    if (dt == DisplayType.REFERENCE || dt == DisplayType.N2NREFERENCE) {
        schemaField.put("refEntity", field.getReferenceEntity().getName());
    } else if (dt == DisplayType.PICKLIST || dt == DisplayType.MULTISELECT) {
        schemaField.put("items", performPickList(field));
    }
    JSONObject extConfig = easyField.getExtraAttrs(true);
    if (!extConfig.isEmpty()) {
        schemaField.put("extConfig", extConfig);
    }
    return schemaField;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) DisplayType(com.rebuild.core.metadata.easymeta.DisplayType) JSONObject(com.alibaba.fastjson.JSONObject) EasyField(com.rebuild.core.metadata.easymeta.EasyField)

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