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

Loading…
Cancel
Save