|
|
@ -7,6 +7,7 @@ import com.epmet.commons.tools.page.PageData; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
|
|
import java.lang.reflect.Field; |
|
|
|
import java.util.Arrays; |
|
|
@ -49,11 +50,42 @@ public class MaskProcessor { |
|
|
|
((List)object).forEach(e -> mask(e)); |
|
|
|
return; |
|
|
|
} else if (object instanceof Map) { |
|
|
|
((Map) object).values().forEach(v -> mask(v)); |
|
|
|
maskMap((Map) object); |
|
|
|
return; |
|
|
|
} else if (object.getClass().getName().startsWith(EPMET_PACKAGE_PREFIX)) { |
|
|
|
// 自定义bean,走反射
|
|
|
|
maskEpmetBean(object); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 为map打码,只打value中的码 |
|
|
|
* - 如果value是epmet的dto,那么去反射它 |
|
|
|
* - 如果value是字符串,那么直接给他打码 |
|
|
|
* - 如果value是其他类型,跳过 |
|
|
|
* @param map |
|
|
|
*/ |
|
|
|
private void maskMap(Map<Object, Object> map) { |
|
|
|
if (CollectionUtils.isEmpty(map)) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
for (Map.Entry<Object, Object> entry : map.entrySet()) { |
|
|
|
Object value = entry.getValue(); |
|
|
|
Object key = entry.getKey(); |
|
|
|
if (value != null && value.getClass().getName().startsWith(EPMET_PACKAGE_PREFIX)) { |
|
|
|
// 是epmet的对象
|
|
|
|
maskEpmetBean(value); |
|
|
|
continue; |
|
|
|
} else if (value instanceof String) { |
|
|
|
int index = fieldNames.indexOf(key); |
|
|
|
if (index != -1) { |
|
|
|
String maskResult = maskString((String) value, fieldsMaskType.get(index)); |
|
|
|
entry.setValue(maskResult); |
|
|
|
} |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|