需求:用户隐私配置,打开则把相关界面展示的手机号码中间四位用*替换,关闭则不隐藏
如针对A、B、C接口后置处理
1.自定义注解
/**
* 号码隐藏注解
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface MaskPhone {
}
2.aop后置处理
@Aspect
@Component
@Slf4j
public class CallMaskPhoneAspect {
@AfterReturning(pointcut = "@annotation(maskPhone)", returning = "result")
public Object afterReturningAdvice(MaskPhone maskPhone, Object result) {
// GlobalConfig globalConfig = globalConfigService.getGlobalConfig(UserInfoContext.getSid());
// if (globalConfig != null && globalConfig.getHide()==1) {
// }
// 对返回结果进行加工处理
if (result instanceof PageInfoDTO) {
PageInfoDTO pageInfoDTO = (PageInfoDTO) result;
List<Object> data = pageInfoDTO.getData();
for (Object o : data) {
// 假设需要处理 phone 字段
if (o instanceof CallOutRecord) {
CallOutRecord callOutRecord = (CallOutRecord) o;
String calleeNumber = callOutRecord.getCalleeNumber();
if (StringUtils.isNotBlank(calleeNumber)) {
String maskedPhone = maskPhone(callOutRecord.getCalleeNumber());
callOutRecord.setCalleeNumber(maskedPhone);
}
String callerNumber = callOutRecord.getCallerNumber();
if (StringUtils.isNotBlank(callerNumber)) {
String maskedPhone = maskPhone(callOutRecord.getCallerNumber());
callOutRecord.setCallerNumber(maskedPhone);
}
}else if (o instanceof CallPlan) {
CallPlan callPlan = (CallPlan) o;
String customerPhone = callPlan.getCustomerPhone();
if (StringUtils.isNotBlank(customerPhone)) {
String maskedPhone = maskPhone(customerPhone);
callPlan.setCustomerPhone(maskedPhone);
}
}else if (o instanceof CallTaskCustomer) {
CallTaskCustomer callTaskCustomer = (CallTaskCustomer) o;
String customerPhone = callTaskCustomer.getCustomerPhone();
if (StringUtils.isNotBlank(customerPhone)) {
String maskedPhone = maskPhone(customerPhone);
callTaskCustomer.setCustomerPhone(maskedPhone);
}
}
}
return pageInfoDTO; // 返回处理后的对象
}else if (result instanceof Result) {
Result ans = (Result) result;
Object data = ans.getData();
if (data instanceof CallOutRecord) {
CallOutRecord callOutRecord = (CallOutRecord)ans.getData();
String calleeNumber = callOutRecord.getCalleeNumber();
if (StringUtils.isNotBlank(calleeNumber)) {
String maskedPhone = maskPhone(callOutRecord.getCalleeNumber());
callOutRecord.setCalleeNumber(maskedPhone);
}
String callerNumber = callOutRecord.getCallerNumber();
if (StringUtils.isNotBlank(callerNumber)) {
String maskedPhone = maskPhone(callOutRecord.getCallerNumber());
callOutRecord.setCallerNumber(maskedPhone);
}
}else if (data instanceof List){
List<MyCallTask> list = (List<MyCallTask>) data;
for (MyCallTask myCallTask : list) {
List<CallTaskCustomer> customerList = myCallTask.getCustomerList();
if (CollectionUtil.isNotEmpty(customerList)){
customerList.forEach(c->{
String maskedPhone = maskPhone(c.getCustomerPhone());
c.setCustomerPhone(maskedPhone);
});
}
}
}
return ans;
}
return result; // 返回原始结果
}
private String maskPhone(String phone) {
if (phone.length() < 7) {
return phone; // 如果长度小于7,返回原始号码
}
return phone.substring(0, 3) + "****" + phone.substring(7);
}
}
3.在需要校验的接口加上注解

641






