字段数据脱敏
# 说明
数据脱敏一般用于接口响应时,对姓名,手机号,身份证号码,银行卡号,电子邮箱,地址信息,IP地址
进行掩码处理
框架增加了一个注解@Masked
有一个参数
type:数据类型,0=姓名,1=手机号,2=身份证号码,3=银行卡号,4=电子邮箱,5=地址信息,6=IP地址
请使用MaskedType枚举类
注:使用jackson序列化完成
注:通过扩展MaskedType枚举类
和MyUtil.masked
进行对更多类型的数据进行脱敏
# 使用例程
package cn.daenx.myadmin.test.domain.po;
import cn.daenx.myadmin.common.annotation.Dict;
import cn.daenx.myadmin.common.annotation.DictDetail;
import cn.daenx.myadmin.common.annotation.Masked;
import cn.daenx.myadmin.common.constant.enums.MaskedType;
import cn.daenx.myadmin.common.vo.BaseEntity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* 测试数据
*/
@Data
@EqualsAndHashCode(callSuper = true)
@AllArgsConstructor
@NoArgsConstructor
@TableName(value = "test_data")
public class TestData extends BaseEntity implements Serializable {
@TableId(value = "id", type = IdType.ASSIGN_UUID)
private String id;
@TableField(value = "title")
private String title;
@TableField(value = "content")
//字段脱敏
@Masked(type = MaskedType.NAME)
private String content;
/**
* 类型,0=民生,1=科技
*/
@TableField(value = "type")
//使用自定义字典进行翻译,意思是直接写死在代码里的
@Dict(custom = {@DictDetail(value = "0", label = "民生"), @DictDetail(value = "1", label = "科技"), @DictDetail(value = "2", label = "农业"), @DictDetail(value = "3", label = "其他")})
// @Dict(dictCode = "test_data_type", custom = {})
private String type;
/**
* 备注
*/
@TableField(value = "remark")
private String remark;
/**
* 状态,0=正常,1=禁用
*/
@TableField(value = "`status`")
// @Dict(custom = {@DictDetail(value = "0", label = "正常"), @DictDetail(value = "1", label = "禁用")})
//使用系统字典表里的翻译数据,推荐
@Dict(dictCode = "sys_normal_disable", custom = {})
private String status;
}
# 效果
{
"code": 200,
"success": true,
"msg": "操作成功",
"data": {
"createId": "1",
"createTime": "2023-06-03 10:56:21",
"updateId": "1",
"updateTime": "2023-06-03 10:58:26",
"isDelete": 0,
"createName": null,
"updateName": null,
"createDept": null,
"id": "8f05e1af476e3537e796c966ff4b7b53",
"title": "阿萨德",
//这里就是效果
"content": "阿**",
"type": "0",
"typeDict": {
"label": "民生",
"value": "0"
},
"remark": "4",
"status": "0",
"statusDict": {
"listClass": "primary",
"cssClass": null,
"remark": "正常状态",
"label": "正常",
"value": "0",
"status": "0"
}
},
"timestamp": 1686886734758
}
# 更多效果
String name="刘萌萌";
String phone="18588855555";
String idCard="130423198505051055";
String bankCard="1234567890123456";
String email="1330166565@qq.com";
String address="北京市朝阳区某某街道123号";
String ip="127.0.0.1";
刘**
185****5555
1304**********1055
1234 **** **** 3456
1****@qq.com
北*************
127.0.*.*
# 导入导出
就是在导出xlsx时,自动将字段进行脱敏处理
注意,需要在@ExcelProperty
注解中指定转换器
为ExcelConverter
@ExcelProperty(value = "学生姓名", converter = ExcelConverter.class)
注:导入和导出使用了阿里巴巴的easyexcel
# 使用例程
package cn.daenx.test.domain.vo;
import cn.daenx.framework.dictMasked.enums.MaskedType;
import cn.daenx.framework.excel.ExcelConverter;
import cn.daenx.framework.dictMasked.annotation.Dict;
import cn.daenx.framework.dictMasked.annotation.DictDetail;
import cn.daenx.framework.dictMasked.annotation.Masked;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
@Data
//导出时忽略没有@ExcelProperty的字段
@ExcelIgnoreUnannotated
public class TestSheetBVo {
private Integer line;
@ExcelProperty(value = "学生姓名", converter = ExcelConverter.class)
@Masked(type = MaskedType.NAME)
private String studentName;
@ExcelProperty(value = "学生年龄")
private String studentAge;
@ExcelProperty(value = "类型", converter = ExcelConverter.class)
//使用自定义字典进行翻译,意思是直接写死在代码里的
@Dict(custom = {@DictDetail(value = "0", label = "民生"), @DictDetail(value = "1", label = "科技"), @DictDetail(value = "2", label = "农业"), @DictDetail(value = "3", label = "其他")})
// @Dict(dictCode = "test_data_type", custom = {})
private String type;
@ExcelProperty(value = "备注")
private String remark;
}
上次更新: 2024/09/20, 15:24:20