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;
}
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;
}
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);
}
}
}
}
}
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;
}
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;
}
Aggregations