xm
2024-06-14 722af26bc6fec32bb289b1df51a9016a4935610f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.dl.common.enums;
 
import cn.hutool.core.util.DesensitizedUtil;
import lombok.AllArgsConstructor;
 
import java.util.function.Function;
 
/**
 * 脱敏策略
 *
 * @author Yjoioooo
 * @version 3.6.0
 */
@AllArgsConstructor
public enum SensitiveStrategy {
 
    /**
     * 身份证脱敏
     */
    ID_CARD(s -> DesensitizedUtil.idCardNum(s, 3, 4)),
 
    /**
     * 手机号脱敏
     */
    PHONE(DesensitizedUtil::mobilePhone),
 
    /**
     * 地址脱敏
     */
    ADDRESS(s -> DesensitizedUtil.address(s, 8)),
 
    /**
     * 邮箱脱敏
     */
    EMAIL(DesensitizedUtil::email),
 
    /**
     * 银行卡
     */
    BANK_CARD(DesensitizedUtil::bankCard);
 
    //可自行添加其他脱敏策略
 
    private final Function<String, String> desensitizer;
 
    public Function<String, String> desensitizer() {
        return desensitizer;
    }
}