compile error fix

master
yixian 4 years ago
parent 8fe1b1256f
commit f1cf317943

@ -10,13 +10,18 @@ import com.yixsoft.support.mybatis.utils.FieldDescription;
import org.apache.commons.lang3.ClassUtils; import org.apache.commons.lang3.ClassUtils;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.hibernate.validator.constraints.Range; import org.hibernate.validator.constraints.Range;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.AnnotatedElementUtils;
import java.lang.reflect.InvocationTargetException;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@JSONType(naming = PropertyNamingStrategy.SnakeCase) @JSONType(naming = PropertyNamingStrategy.SnakeCase)
public class DefaultClientProfile { public class DefaultClientProfile {
private final Logger logger = LoggerFactory.getLogger(getClass());
@ProfileDesc(value = "周末延迟清算", detail = "周末交易延迟到周二清算") @ProfileDesc(value = "周末延迟清算", detail = "周末交易延迟到周二清算")
private boolean weekendDelay = true; private boolean weekendDelay = true;
@ProfileDesc("手续费包含GST") @ProfileDesc("手续费包含GST")
@ -35,40 +40,46 @@ public class DefaultClientProfile {
return new ClassFieldsDescription<>(getClass()).getFields().stream() return new ClassFieldsDescription<>(getClass()).getFields().stream()
.filter(field -> !"class".equalsIgnoreCase(field.getFieldName())) .filter(field -> !"class".equalsIgnoreCase(field.getFieldName()))
.map(this::convertFieldInfo) .map(this::convertFieldInfo)
.filter(Objects::nonNull)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
private JSONObject convertFieldInfo(FieldDescription field) { private JSONObject convertFieldInfo(FieldDescription field) {
Object value = field.readField(this); try {
String fieldName = CaseFormat.LOWER_CAMEL.converterTo(CaseFormat.LOWER_UNDERSCORE).convert(field.getFieldName()); Object value = field.readField(this);
JSONObject info = new JSONObject(); String fieldName = CaseFormat.LOWER_CAMEL.converterTo(CaseFormat.LOWER_UNDERSCORE).convert(field.getFieldName());
info.put("field", fieldName); JSONObject info = new JSONObject();
info.put("value", value); info.put("field", fieldName);
Class<?> fieldType = field.getMethod().getReturnType(); info.put("value", value);
if (ClassUtils.isPrimitiveOrWrapper(fieldType)) { Class<?> fieldType = field.getMethod().getReturnType();
if (ClassUtils.isPrimitiveWrapper(fieldType)) { if (ClassUtils.isPrimitiveOrWrapper(fieldType)) {
fieldType = ClassUtils.wrapperToPrimitive(fieldType); if (ClassUtils.isPrimitiveWrapper(fieldType)) {
} fieldType = ClassUtils.wrapperToPrimitive(fieldType);
if (fieldType.equals(boolean.class)) { }
info.put("type", "checkbox"); if (fieldType.equals(boolean.class)) {
info.put("type", "checkbox");
} else {
info.put("type", "number");
}
} else { } else {
info.put("type", "number"); info.put("type", "text");
} }
} else {
info.put("type", "text");
}
ProfileDesc getterDesc = AnnotatedElementUtils.findMergedAnnotation(field.getMethod(), ProfileDesc.class); ProfileDesc getterDesc = AnnotatedElementUtils.findMergedAnnotation(field.getMethod(), ProfileDesc.class);
try { try {
ProfileDesc fieldDesc = AnnotatedElementUtils.findMergedAnnotation(getClass().getDeclaredField(field.getFieldName()), ProfileDesc.class); ProfileDesc fieldDesc = AnnotatedElementUtils.findMergedAnnotation(getClass().getDeclaredField(field.getFieldName()), ProfileDesc.class);
ProfileDesc desc = ObjectUtils.defaultIfNull(getterDesc, fieldDesc); ProfileDesc desc = ObjectUtils.defaultIfNull(getterDesc, fieldDesc);
if (desc != null) { if (desc != null) {
info.put("title", desc.value()); info.put("title", desc.value());
info.put("detail", desc.detail()); info.put("detail", desc.detail());
}
} catch (NoSuchFieldException e) {
} }
} catch (NoSuchFieldException e) { return info;
} catch (IllegalAccessException | InvocationTargetException e) {
logger.error("failed to access getter of field {}", field.getFieldName(), e);
return null;
} }
return info;
} }
public void applyToClientConfig(JSONObject client) { public void applyToClientConfig(JSONObject client) {

Loading…
Cancel
Save