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