Search in sources :

Example 1 with EchoVO

use of top.tangyh.basic.interfaces.echo.EchoVO in project lamp-util by zuihou.

the class EchoServiceImpl method iterationWrite.

private void iterationWrite(Object obj, Map<LoadKey, Map<Serializable, Object>> typeMap, int depth, String... ignoreFields) {
    // 解析方法上的注解,计算出obj对象中所有需要查询的数据
    List<Field> fields = ClassManager.getFields(obj.getClass());
    for (Field field : fields) {
        FieldParam fieldParam = getFieldParam(obj, field, typeMap, innerTypeMap -> write(ReflectUtil.getFieldValue(obj, field), innerTypeMap, depth + 1, ignoreFields), ignoreFields);
        if (fieldParam == null) {
            continue;
        }
        Echo inField = fieldParam.getEcho();
        Object actualValue = fieldParam.getActualValue();
        Object originalValue = fieldParam.getOriginalValue();
        String fieldName = fieldParam.getFieldName();
        String ref = inField.ref();
        LoadKey loadKey = fieldParam.getLoadKey();
        Object echoValue = getEchoValue(inField, actualValue, originalValue, loadKey, typeMap);
        if (echoValue == null) {
            continue;
        }
        if (echoValue instanceof Map && ((Map<?, ?>) echoValue).isEmpty()) {
            continue;
        }
        // feign 接口序列化 丢失类型
        if (echoValue instanceof Map && !Object.class.equals(inField.beanClass())) {
            echoValue = JsonUtil.parse(JsonUtil.toJson(echoValue), inField.beanClass());
        }
        if (StrUtil.isNotEmpty(ref)) {
            ReflectUtil.setFieldValue(obj, ref, echoValue);
        }
        // 将新的值 反射 到指定字段
        if (obj instanceof EchoVO) {
            EchoVO vo = (EchoVO) obj;
            vo.getEchoMap().put(fieldName, echoValue);
        } else {
            ReflectUtil.setFieldValue(obj, field, echoValue);
        }
    }
}
Also used : LoadKey(top.tangyh.basic.echo.manager.LoadKey) Field(java.lang.reflect.Field) FieldParam(top.tangyh.basic.echo.manager.FieldParam) Echo(top.tangyh.basic.annotation.echo.Echo) EchoVO(top.tangyh.basic.interfaces.echo.EchoVO) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

Field (java.lang.reflect.Field)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Echo (top.tangyh.basic.annotation.echo.Echo)1 FieldParam (top.tangyh.basic.echo.manager.FieldParam)1 LoadKey (top.tangyh.basic.echo.manager.LoadKey)1 EchoVO (top.tangyh.basic.interfaces.echo.EchoVO)1