31 changed files with 1718 additions and 19 deletions
@ -0,0 +1,22 @@ |
|||
package com.bnyer.common.core.annotation; |
|||
|
|||
|
|||
import com.bnyer.common.core.enums.SensitiveTypeEnum; |
|||
|
|||
import java.lang.annotation.*; |
|||
|
|||
/** |
|||
* 敏感字段脱敏注解 |
|||
* @author wuhao |
|||
* @date 2021/01/11 15:17 |
|||
*/ |
|||
@Target({ElementType.FIELD, ElementType.METHOD}) |
|||
@Retention(RetentionPolicy.RUNTIME) |
|||
@Inherited |
|||
@Documented |
|||
public @interface Desensitized { |
|||
/*脱敏类型(规则)*/ |
|||
SensitiveTypeEnum type(); |
|||
/*判断注解是否生效的方法*/ |
|||
String isEffictiveMethod() default ""; |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
package com.bnyer.common.core.enums; |
|||
|
|||
/** |
|||
* @author chengkun |
|||
* @date 2021/01/11 15:18 |
|||
*/ |
|||
public enum SensitiveTypeEnum { |
|||
/** 中文名 */ |
|||
CHINESE_NAME, |
|||
/** 身份证号 */ |
|||
ID_CARD, |
|||
/** 座机号 */ |
|||
FIXED_PHONE, |
|||
/** 手机号 */ |
|||
MOBILE_PHONE, |
|||
/** 地址 */ |
|||
ADDRESS, |
|||
/** 电子邮件 */ |
|||
EMAIL, |
|||
/** 银行卡 */ |
|||
BANK_CARD, |
|||
/** 密码 */ |
|||
PASSWORD, |
|||
/** 长文本 **/ |
|||
LONG_CONTENT; |
|||
} |
|||
@ -0,0 +1,639 @@ |
|||
package com.bnyer.common.core.utils; |
|||
|
|||
import com.alibaba.fastjson.JSON; |
|||
import com.alibaba.fastjson.serializer.SerializerFeature; |
|||
import com.bnyer.common.core.annotation.Desensitized; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
|
|||
import java.lang.reflect.Array; |
|||
import java.lang.reflect.Field; |
|||
import java.lang.reflect.InvocationTargetException; |
|||
import java.lang.reflect.Method; |
|||
import java.util.*; |
|||
|
|||
/** |
|||
* 敏感数据脱敏打印工具类 |
|||
* @author chengkun |
|||
* @date 2021/01/11 15:18 |
|||
*/ |
|||
public class DesensitizedUtils { |
|||
/** |
|||
* 获取脱敏json串(递归引用会导致java.lang.StackOverflowError) |
|||
* |
|||
* @param javaBean |
|||
* @return |
|||
*/ |
|||
public static String getJson(Object javaBean) { |
|||
String json = null; |
|||
if (null != javaBean) { |
|||
try { |
|||
if (javaBean.getClass().isInterface()){ return json;} |
|||
/* 克隆出一个实体进行字段修改,避免修改原实体 */ |
|||
//Object clone =ObjectUtils.deepCloneObject(javaBean);
|
|||
//Object clone =ObjectUtils.deepCloneByFastJson(javaBean);
|
|||
Object clone = ObjectUtils.deepClone(javaBean); |
|||
|
|||
/* 定义一个计数器,用于避免重复循环自定义对象类型的字段 */ |
|||
Set<Integer> referenceCounter = new HashSet<Integer>(); |
|||
|
|||
/* 对克隆实体进行脱敏操作 */ |
|||
DesensitizedUtils.replace(ObjectUtils.getAllFields(clone), clone, referenceCounter); |
|||
|
|||
/* 利用fastjson对脱敏后的克隆对象进行序列化 */ |
|||
json = JSON.toJSONString(clone, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullListAsEmpty); |
|||
|
|||
/* 清空计数器 */ |
|||
referenceCounter.clear(); |
|||
referenceCounter = null; |
|||
} catch (Throwable e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
return json; |
|||
} |
|||
|
|||
/** |
|||
* 获取广发定制化化脱敏json串(递归引用会导致java.lang.StackOverflowError) |
|||
* |
|||
* @param javaBean |
|||
* @return |
|||
*/ |
|||
public static String getGuangFaJson(Object javaBean) { |
|||
String json = null; |
|||
if (null != javaBean) { |
|||
try { |
|||
if (javaBean.getClass().isInterface()){ return json;} |
|||
/* 克隆出一个实体进行字段修改,避免修改原实体 */ |
|||
//Object clone =ObjectUtils.deepCloneObject(javaBean);
|
|||
//Object clone =ObjectUtils.deepCloneByFastJson(javaBean);
|
|||
Object clone = ObjectUtils.deepClone(javaBean); |
|||
|
|||
/* 定义一个计数器,用于避免重复循环自定义对象类型的字段 */ |
|||
Set<Integer> referenceCounter = new HashSet<Integer>(); |
|||
|
|||
/* 对克隆实体进行脱敏操作 */ |
|||
DesensitizedUtils.guangFaReplace(ObjectUtils.getAllFields(clone), clone, referenceCounter); |
|||
|
|||
/* 利用fastjson对脱敏后的克隆对象进行序列化 */ |
|||
json = JSON.toJSONString(clone, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullListAsEmpty); |
|||
|
|||
/* 清空计数器 */ |
|||
referenceCounter.clear(); |
|||
referenceCounter = null; |
|||
} catch (Throwable e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
return json; |
|||
} |
|||
|
|||
/** |
|||
* 获取脱敏json串(递归引用会导致java.lang.StackOverflowError) |
|||
* |
|||
* @param javaBean |
|||
* @return |
|||
*/ |
|||
public static String getJsonNoCopy(Object javaBean) { |
|||
String json = null; |
|||
if (null != javaBean) { |
|||
try { |
|||
if (javaBean.getClass().isInterface()){ return json;} |
|||
|
|||
/* 定义一个计数器,用于避免重复循环自定义对象类型的字段 */ |
|||
Set<Integer> referenceCounter = new HashSet<Integer>(); |
|||
|
|||
/* 对克隆实体进行脱敏操作 */ |
|||
DesensitizedUtils.replace(ObjectUtils.getAllFields(javaBean), javaBean, referenceCounter); |
|||
|
|||
/* 利用fastjson对脱敏后的克隆对象进行序列化 */ |
|||
json = JSON.toJSONString(javaBean, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullListAsEmpty); |
|||
|
|||
/* 清空计数器 */ |
|||
referenceCounter.clear(); |
|||
referenceCounter = null; |
|||
} catch (Throwable e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
return json; |
|||
} |
|||
|
|||
/** |
|||
* 获取广发定制化脱敏json串(递归引用会导致java.lang.StackOverflowError) |
|||
* |
|||
* @param javaBean |
|||
* @return |
|||
*/ |
|||
public static String getGuangFaJsonNoCopy(Object javaBean) { |
|||
String json = null; |
|||
if (null != javaBean) { |
|||
try { |
|||
if (javaBean.getClass().isInterface()){ return json;} |
|||
|
|||
/* 定义一个计数器,用于避免重复循环自定义对象类型的字段 */ |
|||
Set<Integer> referenceCounter = new HashSet<Integer>(); |
|||
|
|||
/* 对克隆实体进行脱敏操作 */ |
|||
DesensitizedUtils.guangFaReplace(ObjectUtils.getAllFields(javaBean), javaBean, referenceCounter); |
|||
|
|||
/* 利用fastjson对脱敏后的克隆对象进行序列化 */ |
|||
json = JSON.toJSONString(javaBean, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullListAsEmpty); |
|||
|
|||
/* 清空计数器 */ |
|||
referenceCounter.clear(); |
|||
referenceCounter = null; |
|||
} catch (Throwable e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
return json; |
|||
} |
|||
|
|||
/** |
|||
* 对需要脱敏的字段进行转化 |
|||
* |
|||
* @param fields |
|||
* @param javaBean |
|||
* @param referenceCounter |
|||
* @throws IllegalArgumentException |
|||
* @throws IllegalAccessException |
|||
*/ |
|||
private static void replace(Field[] fields, Object javaBean, Set<Integer> referenceCounter) throws IllegalArgumentException, IllegalAccessException { |
|||
if (null != fields && fields.length > 0) { |
|||
for (Field field : fields) { |
|||
field.setAccessible(true); |
|||
if (null != field && null != javaBean) { |
|||
Object value = field.get(javaBean); |
|||
if (null != value) { |
|||
Class<?> type = value.getClass(); |
|||
//处理子属性,包括集合中的
|
|||
if (type.isArray()) {//对数组类型的字段进行递归过滤
|
|||
int len = Array.getLength(value); |
|||
for (int i = 0; i < len; i++) { |
|||
Object arrayObject = Array.get(value, i); |
|||
if (isNotGeneralType(arrayObject.getClass(), arrayObject, referenceCounter)) { |
|||
replace(ObjectUtils.getAllFields(arrayObject), arrayObject, referenceCounter); |
|||
} |
|||
} |
|||
} else if (value instanceof Collection<?>) {//对集合类型的字段进行递归过滤
|
|||
Collection<?> c = (Collection<?>) value; |
|||
Iterator<?> it = c.iterator(); |
|||
while (it.hasNext()) {// TODO: 待优化
|
|||
Object collectionObj = it.next(); |
|||
if (isNotGeneralType(collectionObj.getClass(), collectionObj, referenceCounter)) { |
|||
replace(ObjectUtils.getAllFields(collectionObj), collectionObj, referenceCounter); |
|||
} |
|||
} |
|||
} else if (value instanceof Map<?, ?>) {//对Map类型的字段进行递归过滤
|
|||
Map<?, ?> m = (Map<?, ?>) value; |
|||
Set<?> set = m.entrySet(); |
|||
for (Object o : set) { |
|||
Map.Entry<?, ?> entry = (Map.Entry<?, ?>) o; |
|||
Object mapVal = entry.getValue(); |
|||
if (isNotGeneralType(mapVal.getClass(), mapVal, referenceCounter)) { |
|||
replace(ObjectUtils.getAllFields(mapVal), mapVal, referenceCounter); |
|||
} |
|||
} |
|||
} else if (value instanceof Enum<?>) { |
|||
continue; |
|||
} |
|||
|
|||
/*除基础类型、jdk类型的字段之外,对其他类型的字段进行递归过滤*/ |
|||
else { |
|||
if (!type.isPrimitive() |
|||
&& type.getPackage() != null |
|||
&& !StringUtils.startsWith(type.getPackage().getName(), "javax.") |
|||
&& !StringUtils.startsWith(type.getPackage().getName(), "java.") |
|||
&& !StringUtils.startsWith(field.getType().getName(), "javax.") |
|||
&& !StringUtils.startsWith(field.getName(), "java.") |
|||
&& referenceCounter.add(value.hashCode())) { |
|||
replace(ObjectUtils.getAllFields(value), value, referenceCounter); |
|||
} |
|||
} |
|||
} |
|||
|
|||
//脱敏操作
|
|||
setNewValueForField(javaBean, field, value); |
|||
|
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 对广发财富功能进行定制化脱敏的字段进行转化 |
|||
* |
|||
* @param fields |
|||
* @param javaBean |
|||
* @param referenceCounter |
|||
* @throws IllegalArgumentException |
|||
* @throws IllegalAccessException |
|||
*/ |
|||
private static void guangFaReplace(Field[] fields, Object javaBean, Set<Integer> referenceCounter) throws IllegalArgumentException, IllegalAccessException { |
|||
if (null != fields && fields.length > 0) { |
|||
for (Field field : fields) { |
|||
field.setAccessible(true); |
|||
if (null != field && null != javaBean) { |
|||
Object value = field.get(javaBean); |
|||
if (null != value) { |
|||
Class<?> type = value.getClass(); |
|||
//处理子属性,包括集合中的
|
|||
if (type.isArray()) {//对数组类型的字段进行递归过滤
|
|||
int len = Array.getLength(value); |
|||
for (int i = 0; i < len; i++) { |
|||
Object arrayObject = Array.get(value, i); |
|||
if (isNotGeneralType(arrayObject.getClass(), arrayObject, referenceCounter)) { |
|||
guangFaReplace(ObjectUtils.getAllFields(arrayObject), arrayObject, referenceCounter); |
|||
} |
|||
} |
|||
} else if (value instanceof Collection<?>) {//对集合类型的字段进行递归过滤
|
|||
Collection<?> c = (Collection<?>) value; |
|||
Iterator<?> it = c.iterator(); |
|||
while (it.hasNext()) {// TODO: 待优化
|
|||
Object collectionObj = it.next(); |
|||
if (isNotGeneralType(collectionObj.getClass(), collectionObj, referenceCounter)) { |
|||
guangFaReplace(ObjectUtils.getAllFields(collectionObj), collectionObj, referenceCounter); |
|||
} |
|||
} |
|||
} else if (value instanceof Map<?, ?>) {//对Map类型的字段进行递归过滤
|
|||
Map<?, ?> m = (Map<?, ?>) value; |
|||
Set<?> set = m.entrySet(); |
|||
for (Object o : set) { |
|||
Map.Entry<?, ?> entry = (Map.Entry<?, ?>) o; |
|||
Object mapVal = entry.getValue(); |
|||
if (isNotGeneralType(mapVal.getClass(), mapVal, referenceCounter)) { |
|||
guangFaReplace(ObjectUtils.getAllFields(mapVal), mapVal, referenceCounter); |
|||
} |
|||
} |
|||
} else if (value instanceof Enum<?>) { |
|||
continue; |
|||
} |
|||
|
|||
/*除基础类型、jdk类型的字段之外,对其他类型的字段进行递归过滤*/ |
|||
else { |
|||
if (!type.isPrimitive() |
|||
&& type.getPackage() != null |
|||
&& !StringUtils.startsWith(type.getPackage().getName(), "javax.") |
|||
&& !StringUtils.startsWith(type.getPackage().getName(), "java.") |
|||
&& !StringUtils.startsWith(field.getType().getName(), "javax.") |
|||
&& !StringUtils.startsWith(field.getName(), "java.") |
|||
&& referenceCounter.add(value.hashCode())) { |
|||
guangFaReplace(ObjectUtils.getAllFields(value), value, referenceCounter); |
|||
} |
|||
} |
|||
} |
|||
|
|||
//脱敏操作
|
|||
setGuangFaNewValueForField(javaBean, field, value); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 排除基础类型、jdk类型、枚举类型的字段 |
|||
* |
|||
* @param clazz |
|||
* @param value |
|||
* @param referenceCounter |
|||
* @return |
|||
*/ |
|||
private static boolean isNotGeneralType(Class<?> clazz, Object value, Set<Integer> referenceCounter) { |
|||
return !clazz.isPrimitive() |
|||
&& clazz.getPackage() != null |
|||
&& !clazz.isEnum() |
|||
&& !StringUtils.startsWith(clazz.getPackage().getName(), "javax.") |
|||
&& !StringUtils.startsWith(clazz.getPackage().getName(), "java.") |
|||
&& !StringUtils.startsWith(clazz.getName(), "javax.") |
|||
&& !StringUtils.startsWith(clazz.getName(), "java.") |
|||
&& referenceCounter.add(value.hashCode()); |
|||
} |
|||
|
|||
/** |
|||
* 脱敏操作(按照规则转化需要脱敏的字段并设置新值) |
|||
* 目前只支持String类型的字段,如需要其他类型如BigDecimal、Date等类型,可以添加 |
|||
* |
|||
* @param javaBean |
|||
* @param field |
|||
* @param value |
|||
* @throws IllegalAccessException |
|||
*/ |
|||
public static void setNewValueForField(Object javaBean, Field field, Object value) throws IllegalAccessException { |
|||
//处理自身的属性
|
|||
Desensitized annotation = field.getAnnotation(Desensitized.class); |
|||
if (field.getType().equals(String.class) && null != annotation && executeIsEffictiveMethod(javaBean, annotation)) { |
|||
String valueStr = (String) value; |
|||
if (StringUtils.isNotBlank(valueStr)) { |
|||
switch (annotation.type()) { |
|||
case CHINESE_NAME: { |
|||
field.set(javaBean, DesensitizedUtils.chineseName(valueStr)); |
|||
break; |
|||
} |
|||
case ID_CARD: { |
|||
field.set(javaBean, DesensitizedUtils.idCardNum(valueStr)); |
|||
break; |
|||
} |
|||
case FIXED_PHONE: { |
|||
field.set(javaBean, DesensitizedUtils.fixedPhone(valueStr)); |
|||
break; |
|||
} |
|||
case MOBILE_PHONE: { |
|||
field.set(javaBean, DesensitizedUtils.mobilePhone(valueStr)); |
|||
break; |
|||
} |
|||
case ADDRESS: { |
|||
field.set(javaBean, DesensitizedUtils.address(valueStr, 8)); |
|||
break; |
|||
} |
|||
case EMAIL: { |
|||
field.set(javaBean, DesensitizedUtils.email(valueStr)); |
|||
break; |
|||
} |
|||
case BANK_CARD: { |
|||
field.set(javaBean, DesensitizedUtils.bankCard(valueStr)); |
|||
break; |
|||
} |
|||
case PASSWORD: { |
|||
field.set(javaBean, DesensitizedUtils.password(valueStr)); |
|||
break; |
|||
} |
|||
case LONG_CONTENT:{ |
|||
field.set(javaBean, DesensitizedUtils.longContent(valueStr)); |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 脱敏操作(根据广发规则要求转化需要脱敏的字段并设置新值) |
|||
* 目前只支持String类型的字段,如需要其他类型如BigDecimal、Date等类型,可以添加 |
|||
* |
|||
* @param javaBean |
|||
* @param field |
|||
* @param value |
|||
* @throws IllegalAccessException |
|||
*/ |
|||
public static void setGuangFaNewValueForField(Object javaBean, Field field, Object value) throws IllegalAccessException { |
|||
//处理自身的属性
|
|||
Desensitized annotation = field.getAnnotation(Desensitized.class); |
|||
if (field.getType().equals(String.class) && null != annotation && executeIsEffictiveMethod(javaBean, annotation)) { |
|||
String valueStr = (String) value; |
|||
if (StringUtils.isNotBlank(valueStr)) { |
|||
switch (annotation.type()) { |
|||
case CHINESE_NAME: { |
|||
field.set(javaBean, DesensitizedUtils.guangFaChineseName(valueStr)); |
|||
break; |
|||
} |
|||
case ID_CARD: { |
|||
field.set(javaBean, DesensitizedUtils.guangFaIdCardNum(valueStr)); |
|||
break; |
|||
} |
|||
case FIXED_PHONE: { |
|||
field.set(javaBean, DesensitizedUtils.fixedPhone(valueStr)); |
|||
break; |
|||
} |
|||
case MOBILE_PHONE: { |
|||
field.set(javaBean, DesensitizedUtils.guangFaMobilePhone(valueStr)); |
|||
break; |
|||
} |
|||
case ADDRESS: { |
|||
field.set(javaBean, DesensitizedUtils.address(valueStr, 8)); |
|||
break; |
|||
} |
|||
case EMAIL: { |
|||
field.set(javaBean, DesensitizedUtils.email(valueStr)); |
|||
break; |
|||
} |
|||
case BANK_CARD: { |
|||
field.set(javaBean, DesensitizedUtils.bankCard(valueStr)); |
|||
break; |
|||
} |
|||
case PASSWORD: { |
|||
field.set(javaBean, DesensitizedUtils.password(valueStr)); |
|||
break; |
|||
} |
|||
case LONG_CONTENT:{ |
|||
field.set(javaBean, DesensitizedUtils.longContent(valueStr)); |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 执行某个对象中指定的方法 |
|||
* |
|||
* @param javaBean 对象 |
|||
* @param desensitized |
|||
* @return |
|||
*/ |
|||
private static boolean executeIsEffictiveMethod(Object javaBean, Desensitized desensitized) { |
|||
boolean isAnnotationEffictive = true;//注解默认生效
|
|||
if (desensitized != null) { |
|||
String isEffictiveMethod = desensitized.isEffictiveMethod(); |
|||
if (isNotEmpty(isEffictiveMethod)) { |
|||
try { |
|||
Method method = javaBean.getClass().getMethod(isEffictiveMethod); |
|||
method.setAccessible(true); |
|||
isAnnotationEffictive = (Boolean) method.invoke(javaBean); |
|||
} catch (NoSuchMethodException e) { |
|||
e.printStackTrace(); |
|||
} catch (IllegalAccessException e) { |
|||
e.printStackTrace(); |
|||
} catch (InvocationTargetException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
} |
|||
return isAnnotationEffictive; |
|||
} |
|||
|
|||
private static boolean isNotEmpty(String str) { |
|||
return str != null && !"".equals(str); |
|||
} |
|||
|
|||
private static boolean isEmpty(String str) { |
|||
return !isNotEmpty(str); |
|||
} |
|||
|
|||
/** |
|||
* 【中文姓名】只显示第一个汉字,其他隐藏为2个星号,比如:李** |
|||
* |
|||
* @param fullName |
|||
* @return |
|||
*/ |
|||
public static String chineseName(String fullName) { |
|||
if (StringUtils.isBlank(fullName)) { |
|||
return ""; |
|||
} |
|||
String name = StringUtils.left(fullName, 1); |
|||
return StringUtils.rightPad(name, StringUtils.length(fullName), "*"); |
|||
} |
|||
|
|||
/** |
|||
* 【中文姓名】只最后一个汉字脱敏,隐藏为1个星号,比如:李舒*,其余正常显示 |
|||
* |
|||
* @param fullName |
|||
* @return |
|||
*/ |
|||
public static String guangFaChineseName(String fullName) { |
|||
if (StringUtils.isBlank(fullName)) { |
|||
return ""; |
|||
} |
|||
StringBuilder sb = new StringBuilder(fullName); |
|||
return sb.replace(sb.length() - 1, sb.length(), "*").toString(); |
|||
} |
|||
|
|||
/** |
|||
* 【身份证号】显示最后四位,其他隐藏。共计18位或者15位,比如:*************1234 |
|||
* |
|||
* @param id |
|||
* @return |
|||
*/ |
|||
public static String idCardNum(String id) { |
|||
if (StringUtils.isBlank(id)) { |
|||
return ""; |
|||
} |
|||
String num = StringUtils.right(id, 4); |
|||
return StringUtils.leftPad(num, StringUtils.length(id), "*"); |
|||
} |
|||
|
|||
/** |
|||
* 【身份证号】显示最后三位和前四位,其他隐藏。共计18位或者15位,比如:5101***********82X |
|||
* |
|||
* @param id |
|||
* @return |
|||
*/ |
|||
public static String guangFaIdCardNum(String id) { |
|||
if (StringUtils.isBlank(id)) { |
|||
return ""; |
|||
} |
|||
// StringBuilder sb = new StringBuilder(id);
|
|||
// if(id.length() == 18){
|
|||
// return sb.replace(4,16,"*").toString();
|
|||
// }else{
|
|||
// return sb.replace(4,12,"*").toString();
|
|||
// }
|
|||
return StringUtils.left(id, 4).concat(StringUtils.removeStart(StringUtils.leftPad(StringUtils.right(id, 3), StringUtils.length(id), "*"), "***")); |
|||
} |
|||
|
|||
/** |
|||
* 【固定电话 后四位,其他隐藏,比如1234 |
|||
* |
|||
* @param num |
|||
* @return |
|||
*/ |
|||
public static String fixedPhone(String num) { |
|||
if (StringUtils.isBlank(num)) { |
|||
return ""; |
|||
} |
|||
return StringUtils.leftPad(StringUtils.right(num, 4), StringUtils.length(num), "*"); |
|||
} |
|||
|
|||
/** |
|||
* 【手机号码】前三位,后四位,其他隐藏,比如135****6810 |
|||
* |
|||
* @param num |
|||
* @return |
|||
*/ |
|||
public static String mobilePhone(String num) { |
|||
if (StringUtils.isBlank(num)) { |
|||
return ""; |
|||
} |
|||
return StringUtils.left(num, 3).concat(StringUtils.removeStart(StringUtils.leftPad(StringUtils.right(num, 4), StringUtils.length(num), "*"), "***")); |
|||
} |
|||
|
|||
/** |
|||
* 【手机号码】前五位脱敏,其他正常显示,比如*****186810 |
|||
* |
|||
* @param number |
|||
* @return |
|||
*/ |
|||
public static String guangFaMobilePhone(String number) { |
|||
if (StringUtils.isBlank(number)) { |
|||
return ""; |
|||
} |
|||
String num = StringUtils.right(number, 6); |
|||
return StringUtils.leftPad(num, StringUtils.length(number), "*"); |
|||
} |
|||
|
|||
/** |
|||
* 【地址】只显示到地区,不显示详细地址,比如:北京市海淀区**** |
|||
* |
|||
* @param address |
|||
* @param sensitiveSize 敏感信息长度 |
|||
* @return |
|||
*/ |
|||
public static String address(String address, int sensitiveSize) { |
|||
if (StringUtils.isBlank(address)) { |
|||
return ""; |
|||
} |
|||
int length = StringUtils.length(address); |
|||
return StringUtils.rightPad(StringUtils.left(address, length - sensitiveSize), length, "*"); |
|||
} |
|||
|
|||
/** |
|||
* 【电子邮箱 邮箱前缀仅显示第一个字母,前缀其他隐藏,用星号代替,@及后面的地址显示,比如:d**@126.com> |
|||
* |
|||
* @param email |
|||
* @return |
|||
*/ |
|||
public static String email(String email) { |
|||
if (StringUtils.isBlank(email)) { |
|||
return ""; |
|||
} |
|||
int index = StringUtils.indexOf(email, "@"); |
|||
if (index <= 1) { |
|||
return email; |
|||
} |
|||
else { |
|||
return StringUtils.rightPad(StringUtils.left(email, 1), index, "*").concat(StringUtils.mid(email, index, StringUtils.length(email))); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 【银行卡号】前六位,后四位,其他用星号隐藏每位1个星号,比如:6222600**********1234> |
|||
* |
|||
* @param cardNum |
|||
* @return |
|||
*/ |
|||
public static String bankCard(String cardNum) { |
|||
if (StringUtils.isBlank(cardNum)) { |
|||
return ""; |
|||
} |
|||
return StringUtils.left(cardNum, 6).concat(StringUtils.removeStart(StringUtils.leftPad(StringUtils.right(cardNum, 4), StringUtils.length(cardNum), "*"), "******")); |
|||
} |
|||
|
|||
/** |
|||
* 【密码】密码的全部字符都用*代替,比如:****** |
|||
* |
|||
* @param password |
|||
* @return |
|||
*/ |
|||
public static String password(String password) { |
|||
if (StringUtils.isBlank(password)) { |
|||
return ""; |
|||
} |
|||
String pwd = StringUtils.left(password, 0); |
|||
return StringUtils.rightPad(pwd, StringUtils.length(password), "*"); |
|||
} |
|||
|
|||
/** |
|||
* 长文本内容 精简 避免日志文件爆炸 |
|||
* |
|||
* @param content |
|||
* @return |
|||
*/ |
|||
public static String longContent(String content) { |
|||
if (StringUtils.isBlank(content)) { |
|||
return ""; |
|||
} |
|||
if (content.length()>100) { |
|||
return StringUtils.left(content, 100)+"【太长截省略】"; |
|||
} |
|||
return content; |
|||
} |
|||
} |
|||
@ -0,0 +1,278 @@ |
|||
package com.bnyer.common.core.utils; |
|||
|
|||
import com.alibaba.fastjson.JSON; |
|||
import org.springframework.util.StringUtils; |
|||
|
|||
import java.lang.reflect.Array; |
|||
import java.lang.reflect.Field; |
|||
import java.lang.reflect.InvocationTargetException; |
|||
import java.lang.reflect.Modifier; |
|||
import java.util.*; |
|||
|
|||
/** |
|||
* OBJECT工具类 |
|||
* |
|||
* @author chengkun |
|||
* @date 2020/05/30 11:20 |
|||
*/ |
|||
public class ObjectUtils { |
|||
/** |
|||
* Object转Map |
|||
* |
|||
* @param obj |
|||
* @return |
|||
* @throws IllegalAccessException |
|||
*/ |
|||
public static Map<String, Object> getObjectToMap(Object obj) throws IllegalAccessException { |
|||
Map<String, Object> map = new LinkedHashMap<>(); |
|||
Class<?> clazz = obj.getClass(); |
|||
List<Field> fields = new ArrayList<>(); |
|||
while (clazz != null) { |
|||
fields.addAll(Arrays.asList(clazz.getDeclaredFields())); |
|||
clazz = clazz.getSuperclass(); |
|||
} |
|||
for (Field field : fields) { |
|||
field.setAccessible(true); |
|||
String fieldName = field.getName(); |
|||
Object value = field.get(obj); |
|||
if (value == null) { |
|||
value = ""; |
|||
} |
|||
map.put(fieldName, value); |
|||
} |
|||
return map; |
|||
} |
|||
|
|||
/** |
|||
* Map转Object |
|||
*/ |
|||
public static Object mapToObject(Map<Object, Object> map, Class<?> beanClass) throws Exception { |
|||
if (map == null) { |
|||
return null; |
|||
} |
|||
Object obj = beanClass.newInstance(); |
|||
Field[] fields = obj.getClass().getDeclaredFields(); |
|||
for (Field field : fields) { |
|||
int mod = field.getModifiers(); |
|||
if (Modifier.isStatic(mod) || Modifier.isFinal(mod)) { |
|||
continue; |
|||
} |
|||
field.setAccessible(true); |
|||
if (map.containsKey(field.getName())) { |
|||
field.set(obj, map.get(field.getName())); |
|||
} |
|||
} |
|||
return obj; |
|||
} |
|||
|
|||
|
|||
|
|||
/** |
|||
* 用序列化-反序列化的方式实现深克隆 |
|||
* 缺点:1、当实体中存在接口类型的参数,并且这个接口指向的实例为枚举类型时,会报错"com.alibaba.fastjson.JSONException: syntax error, expect {, actual string, pos 171, fieldName iLimitKey" |
|||
* |
|||
* @param objSource |
|||
* @return |
|||
*/ |
|||
public static Object deepCloneByFastJson(Object objSource) { |
|||
String tempJson = JSON.toJSONString(objSource); |
|||
Object clone = JSON.parseObject(tempJson, objSource.getClass()); |
|||
return clone; |
|||
} |
|||
|
|||
/** |
|||
* 深度克隆对象 |
|||
* |
|||
* @throws IllegalAccessException |
|||
* @throws InstantiationException |
|||
*/ |
|||
public static Object deepClone(Object objSource) throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { |
|||
if (null == objSource) {return null;} |
|||
//是否jdk类型、基础类型、枚举类型
|
|||
if (isJDKType(objSource.getClass()) |
|||
|| objSource.getClass().isPrimitive() |
|||
|| objSource instanceof Enum<?>) { |
|||
if ("java.lang.String".equals(objSource.getClass().getName())) {//目前只支持String类型深复制
|
|||
return new String((String) objSource); |
|||
} else { |
|||
return objSource; |
|||
} |
|||
} |
|||
// 获取源对象类型
|
|||
Class<?> clazz = objSource.getClass(); |
|||
Object objDes = clazz.newInstance(); |
|||
// 获得源对象所有属性
|
|||
Field[] fields = getAllFields(objSource); |
|||
// 循环遍历字段,获取字段对应的属性值
|
|||
for (Field field : fields) { |
|||
field.setAccessible(true); |
|||
if (null == field) {continue;}; |
|||
Object value = field.get(objSource); |
|||
if (null == value) {continue;}; |
|||
Class<?> type = value.getClass(); |
|||
if (isStaticFinal(field)) { |
|||
continue; |
|||
} |
|||
try { |
|||
|
|||
//遍历集合属性
|
|||
if (type.isArray()) {//对数组类型的字段进行递归过滤
|
|||
int len = Array.getLength(value); |
|||
if (len < 1) {continue;} |
|||
Class<?> c = value.getClass().getComponentType(); |
|||
Array newArray = (Array) Array.newInstance(c, len); |
|||
for (int i = 0; i < len; i++) { |
|||
Object arrayObject = Array.get(value, i); |
|||
Array.set(newArray, i, deepClone(arrayObject)); |
|||
} |
|||
} else if (value instanceof Collection<?>) { |
|||
Collection newCollection = (Collection) value.getClass().newInstance(); |
|||
Collection<?> c = (Collection<?>) value; |
|||
Iterator<?> it = c.iterator(); |
|||
while (it.hasNext()) { |
|||
Object collectionObj = it.next(); |
|||
newCollection.add(deepClone(collectionObj)); |
|||
} |
|||
field.set(objDes, newCollection); |
|||
continue; |
|||
} else if (value instanceof Map<?, ?>) { |
|||
Map newMap = (Map) value.getClass().newInstance(); |
|||
Map<?, ?> m = (Map<?, ?>) value; |
|||
Set<?> set = m.entrySet(); |
|||
for (Object o : set) { |
|||
Map.Entry<?, ?> entry = (Map.Entry<?, ?>) o; |
|||
Object mapVal = entry.getValue(); |
|||
newMap.put(entry.getKey(), deepClone(mapVal)); |
|||
} |
|||
field.set(objDes, newMap); |
|||
continue; |
|||
} |
|||
|
|||
//是否jdk类型或基础类型
|
|||
if (isJDKType(field.get(objSource).getClass()) |
|||
|| field.getClass().isPrimitive() |
|||
|| isStaticType(field) |
|||
|| value instanceof Enum<?>) { |
|||
if ("java.lang.String".equals(value.getClass().getName())) {//目前只支持String类型深复制
|
|||
field.set(objDes, new String((String) value)); |
|||
} else { |
|||
field.set(objDes, field.get(objSource)); |
|||
} |
|||
continue; |
|||
} |
|||
|
|||
//是否枚举
|
|||
if (value.getClass().isEnum()) { |
|||
field.set(objDes, field.get(objSource)); |
|||
continue; |
|||
} |
|||
|
|||
//是否自定义类
|
|||
if (isUserDefinedType(value.getClass())) { |
|||
field.set(objDes, deepClone(value)); |
|||
continue; |
|||
} |
|||
|
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
return objDes; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 是否静态变量 |
|||
* |
|||
* @param field |
|||
* @return |
|||
*/ |
|||
private static boolean isStaticType(Field field) { |
|||
return field.getModifiers() == 8 ? true : false; |
|||
} |
|||
|
|||
private static boolean isStaticFinal(Field field) { |
|||
return Modifier.isFinal(field.getModifiers()) && Modifier.isStatic(field.getModifiers()); |
|||
} |
|||
|
|||
/** |
|||
* 是否jdk类型变量 |
|||
* |
|||
* @param clazz |
|||
* @return |
|||
* @throws IllegalAccessException |
|||
*/ |
|||
private static boolean isJDKType(Class clazz) throws IllegalAccessException { |
|||
//Class clazz = field.get(objSource).getClass();
|
|||
return StringUtils.startsWithIgnoreCase(clazz.getPackage().getName(), "javax.") |
|||
|| StringUtils.startsWithIgnoreCase(clazz.getPackage().getName(), "java.") |
|||
|| StringUtils.startsWithIgnoreCase(clazz.getName(), "javax.") |
|||
|| StringUtils.startsWithIgnoreCase(clazz.getName(), "java."); |
|||
} |
|||
|
|||
/** |
|||
* 是否用户自定义类型 |
|||
* |
|||
* @param clazz |
|||
* @return |
|||
*/ |
|||
private static boolean isUserDefinedType(Class<?> clazz) { |
|||
return |
|||
clazz.getPackage() != null |
|||
&& !StringUtils.startsWithIgnoreCase(clazz.getPackage().getName(), "javax.") |
|||
&& !StringUtils.startsWithIgnoreCase(clazz.getPackage().getName(), "java.") |
|||
&& !StringUtils.startsWithIgnoreCase(clazz.getName(), "javax.") |
|||
&& !StringUtils.startsWithIgnoreCase(clazz.getName(), "java."); |
|||
} |
|||
|
|||
/** |
|||
* 获取包括父类所有的属性 |
|||
* |
|||
* @param objSource |
|||
* @return |
|||
*/ |
|||
public static Field[] getAllFields(Object objSource) { |
|||
/*获得当前类的所有属性(private、protected、public)*/ |
|||
List<Field> fieldList = new ArrayList<Field>(); |
|||
Class tempClass = objSource.getClass(); |
|||
while (tempClass != null && !tempClass.getName().toLowerCase().equals("java.lang.object")) {//当父类为null的时候说明到达了最上层的父类(Object类).
|
|||
fieldList.addAll(Arrays.asList(tempClass.getDeclaredFields())); |
|||
tempClass = tempClass.getSuperclass(); //得到父类,然后赋给自己
|
|||
} |
|||
Field[] fields = new Field[fieldList.size()]; |
|||
fieldList.toArray(fields); |
|||
return fields; |
|||
} |
|||
|
|||
/** |
|||
* 深度克隆对象 |
|||
* |
|||
* @throws IllegalAccessException |
|||
* @throws InstantiationException |
|||
*/ |
|||
@Deprecated |
|||
public static Object copy(Object objSource) throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { |
|||
|
|||
if (null == objSource) {return null;} |
|||
// 获取源对象类型
|
|||
Class<?> clazz = objSource.getClass(); |
|||
Object objDes = clazz.newInstance(); |
|||
// 获得源对象所有属性
|
|||
Field[] fields = getAllFields(objSource); |
|||
// 循环遍历字段,获取字段对应的属性值
|
|||
for (Field field : fields) { |
|||
field.setAccessible(true); |
|||
// 如果该字段是 static + final 修饰
|
|||
if (field.getModifiers() >= 24) { |
|||
continue; |
|||
} |
|||
try { |
|||
// 设置字段可见,即可用get方法获取属性值。
|
|||
field.set(objDes, field.get(objSource)); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
return objDes; |
|||
} |
|||
} |
|||
@ -0,0 +1,81 @@ |
|||
package com.bnyer.img.controller; |
|||
|
|||
import com.alibaba.fastjson.JSON; |
|||
import com.bnyer.common.core.utils.DesensitizedUtils; |
|||
import com.bnyer.common.core.web.controller.BaseController; |
|||
import com.bnyer.common.core.web.domain.AjaxResult; |
|||
import com.bnyer.common.core.web.page.TableDataInfo; |
|||
import com.bnyer.img.domain.CreatorAccount; |
|||
import com.bnyer.img.dto.CreatorAccountDto; |
|||
import com.bnyer.img.dto.CreatorAccountPageDto; |
|||
import com.bnyer.img.dto.StatusDto; |
|||
import com.bnyer.img.service.CreatorAccountService; |
|||
import com.github.pagehelper.PageHelper; |
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import io.swagger.annotations.ApiParam; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.validation.annotation.Validated; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import java.util.List; |
|||
|
|||
@Api(value = "img-creatorAccount-【后端】艺术家账户接口",tags = "img-creatorAccount-【后端】艺术家账户接口") |
|||
@RestController |
|||
@RequestMapping("/img/creatorAccount") |
|||
@Slf4j |
|||
public class CreatorAccountController extends BaseController { |
|||
|
|||
@Autowired |
|||
private CreatorAccountService creatorAccountService; |
|||
|
|||
//@RequiresPermissions("system:config:list")
|
|||
@ApiOperation(value="查询creatorAccount分页") |
|||
@PostMapping("/page") |
|||
public TableDataInfo pageCreatorAccount(@RequestBody @ApiParam("分页对象") CreatorAccountPageDto dto){ |
|||
PageHelper.startPage(dto.getPageNum(), dto.getPageSize()); |
|||
List<CreatorAccount> creatorAccounts = creatorAccountService.queryPage(dto); |
|||
return getDataTable(creatorAccounts); |
|||
} |
|||
|
|||
//@RequiresPermissions("system:config:list")
|
|||
@ApiOperation(value="新增creatorAccount") |
|||
@PostMapping(value = "/insert") |
|||
public AjaxResult insertCreatorAccount(@Validated @RequestBody @ApiParam("creatorAccount对象")CreatorAccountDto dto){ |
|||
log.debug("新增creatorAccount参数为:{}", DesensitizedUtils.getJson(dto)); |
|||
return AjaxResult.success(creatorAccountService.insert(dto.extractParam())); |
|||
} |
|||
|
|||
//@RequiresPermissions("system:config:list")
|
|||
@ApiOperation(value="修改creatorAccount") |
|||
@PostMapping(value = "/update") |
|||
public AjaxResult updateCreatorAccount(@Validated @RequestBody @ApiParam("creatorAccount对象")CreatorAccountDto dto){ |
|||
log.debug("修改creatorAccount参数为:{}", JSON.toJSONString(dto)); |
|||
return AjaxResult.success(creatorAccountService.update(dto.extractParam())); |
|||
} |
|||
|
|||
//@RequiresPermissions("system:config:list")
|
|||
@ApiOperation(value="删除creatorAccount") |
|||
@DeleteMapping(value = "/delete/{ids}") |
|||
public AjaxResult deleteCreatorAccount(@PathVariable @ApiParam("主键ids") List<Long> ids){ |
|||
log.debug("删除creatorAccount参数为:{}", JSON.toJSONString(ids)); |
|||
return AjaxResult.success(creatorAccountService.delete(ids)); |
|||
} |
|||
|
|||
//@RequiresPermissions("system:config:list")
|
|||
@ApiOperation(value="查询creatorAccount详情") |
|||
@GetMapping(value = "/details/{id}") |
|||
public AjaxResult detailsCreatorAccount(@PathVariable @ApiParam("主键id") Long id){ |
|||
log.debug("查询creatorAccount详情参数为:{}", id); |
|||
return AjaxResult.success(creatorAccountService.queryDetails(id)); |
|||
} |
|||
|
|||
//@RequiresPermissions("system:config:list")
|
|||
@ApiOperation(value="变更type显示状态") |
|||
@PostMapping(value = "/changeStatus") |
|||
public AjaxResult changeStatus(@Validated @RequestBody @ApiParam("type状态对象") StatusDto dto){ |
|||
log.debug("变更type参数为:{}", JSON.toJSONString(dto)); |
|||
return AjaxResult.success(creatorAccountService.changeStatus(dto.getId(),dto.getStatus())); |
|||
} |
|||
} |
|||
@ -0,0 +1,46 @@ |
|||
package com.bnyer.img.controller; |
|||
|
|||
import com.bnyer.common.core.web.controller.BaseController; |
|||
import com.bnyer.common.core.web.domain.AjaxResult; |
|||
import com.bnyer.common.core.web.page.TableDataInfo; |
|||
import com.bnyer.img.domain.InviteLog; |
|||
import com.bnyer.img.domain.VerifyLog; |
|||
import com.bnyer.img.dto.InviteLogPageDto; |
|||
import com.bnyer.img.dto.VerifyPageDto; |
|||
import com.bnyer.img.service.InviteLogService; |
|||
import com.github.pagehelper.PageHelper; |
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import io.swagger.annotations.ApiParam; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import java.util.List; |
|||
|
|||
@Api(value = "img-inviteLog-【后端】邀请记录接口",tags = "img-inviteLog-【后端】邀请记录接口") |
|||
@RestController |
|||
@RequestMapping("/img/inviteLog") |
|||
@Slf4j |
|||
public class InviteLogController extends BaseController { |
|||
|
|||
@Autowired |
|||
private InviteLogService inviteLogService; |
|||
|
|||
//@RequiresPermissions("system:config:list")
|
|||
@ApiOperation(value="查询邀请记录分页") |
|||
@PostMapping("/page") |
|||
public TableDataInfo pageInviteLog(@RequestBody @ApiParam("分页对象") InviteLogPageDto dto){ |
|||
PageHelper.startPage(dto.getPageNum(), dto.getPageSize()); |
|||
List<InviteLog> inviteLogs = inviteLogService.queryPage(dto); |
|||
return getDataTable(inviteLogs); |
|||
} |
|||
|
|||
//@RequiresPermissions("system:config:list")
|
|||
@ApiOperation(value="删除邀请记录") |
|||
@DeleteMapping(value = "/delete/{ids}") |
|||
public AjaxResult deleteVerifyLog(@PathVariable @ApiParam("主键ids") List<Long> ids){ |
|||
log.debug("删除邀请记录参数为:{}", ids); |
|||
return AjaxResult.success(inviteLogService.delete(ids)); |
|||
} |
|||
} |
|||
@ -0,0 +1,57 @@ |
|||
package com.bnyer.img.dto; |
|||
|
|||
import com.bnyer.common.core.annotation.Desensitized; |
|||
import com.bnyer.common.core.enums.SensitiveTypeEnum; |
|||
import com.bnyer.common.core.utils.Sm4Util; |
|||
import com.bnyer.img.domain.CreatorAccount; |
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
import java.io.Serializable; |
|||
|
|||
|
|||
@Getter |
|||
@Setter |
|||
@ApiModel("艺术家账户接收类") |
|||
public class CreatorAccountDto implements Serializable { |
|||
|
|||
@ApiModelProperty(value="主键id") |
|||
private Long id; |
|||
|
|||
@ApiModelProperty(value="艺术家id") |
|||
private Long creatorId; |
|||
|
|||
@NotBlank(message = "姓名不能为空!") |
|||
@Desensitized(type = SensitiveTypeEnum.CHINESE_NAME) |
|||
@ApiModelProperty(value="姓名(加密)") |
|||
private String name; |
|||
|
|||
@NotBlank(message = "身份证不能为空!") |
|||
@Desensitized(type = SensitiveTypeEnum.ID_CARD) |
|||
@ApiModelProperty(value="身份证(加密)") |
|||
private String idNo; |
|||
|
|||
@NotBlank(message = "银行卡不能为空!") |
|||
@Desensitized(type = SensitiveTypeEnum.BANK_CARD) |
|||
@ApiModelProperty(value="银行卡(加密)") |
|||
private String bankNo; |
|||
|
|||
@NotBlank(message = "联系电话不能为空!") |
|||
@Desensitized(type = SensitiveTypeEnum.MOBILE_PHONE) |
|||
@ApiModelProperty(value="联系电话") |
|||
private String phone; |
|||
|
|||
public CreatorAccount extractParam(){ |
|||
CreatorAccount creatorAccount = new CreatorAccount(); |
|||
creatorAccount.setId(this.getId()); |
|||
creatorAccount.setCreatorId(this.getCreatorId()); |
|||
creatorAccount.setBankNo(Sm4Util.sm4Encryption(this.getBankNo())); |
|||
creatorAccount.setName(this.getName()); |
|||
creatorAccount.setPhone(Sm4Util.sm4Encryption(this.getPhone())); |
|||
creatorAccount.setIdNo(Sm4Util.sm4Encryption(this.getIdNo())); |
|||
return creatorAccount; |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
package com.bnyer.img.dto; |
|||
|
|||
import com.bnyer.common.core.annotation.Desensitized; |
|||
import com.bnyer.common.core.enums.SensitiveTypeEnum; |
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
|
|||
@Getter |
|||
@Setter |
|||
@ApiModel("艺术家账户分页接收类") |
|||
public class CreatorAccountPageDto extends BasePageDto { |
|||
|
|||
@Desensitized(type = SensitiveTypeEnum.ID_CARD) |
|||
@ApiModelProperty(value="身份证(加密)") |
|||
private String idNo; |
|||
|
|||
@Desensitized(type = SensitiveTypeEnum.BANK_CARD) |
|||
@ApiModelProperty(value="银行卡(加密)") |
|||
private String bankNo; |
|||
|
|||
@Desensitized(type = SensitiveTypeEnum.MOBILE_PHONE) |
|||
@ApiModelProperty(value="联系电话") |
|||
private String phone; |
|||
|
|||
@Desensitized(type = SensitiveTypeEnum.CHINESE_NAME) |
|||
@ApiModelProperty(value="姓名(加密)") |
|||
private String name; |
|||
|
|||
@ApiModelProperty(value="是否显示") |
|||
private String isShow; |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
package com.bnyer.img.dto; |
|||
|
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
|
|||
|
|||
@Getter |
|||
@Setter |
|||
@ApiModel("邀请记录分页接收类") |
|||
public class InviteLogPageDto extends BasePageDto { |
|||
|
|||
@ApiModelProperty(value="邀请码") |
|||
private String inviteCode; |
|||
|
|||
@ApiModelProperty(value="是否显示 (0->隐藏;1->显示)") |
|||
private String isShow; |
|||
} |
|||
@ -0,0 +1,63 @@ |
|||
package com.bnyer.img.service; |
|||
|
|||
import com.bnyer.img.domain.CreatorAccount; |
|||
import com.bnyer.img.dto.BannerPageDto; |
|||
import com.bnyer.img.dto.CreatorAccountPageDto; |
|||
import com.bnyer.img.vo.BannerVo; |
|||
import com.bnyer.img.vo.CreatorAccountVo; |
|||
|
|||
import java.util.List; |
|||
|
|||
public interface CreatorAccountService { |
|||
|
|||
/** |
|||
* 新增艺术家账户 |
|||
* @param creatorAccount - |
|||
* @return - |
|||
*/ |
|||
int insert(CreatorAccount creatorAccount); |
|||
|
|||
/** |
|||
* 修改艺术家账户 |
|||
* @param creatorAccount - |
|||
* @return - |
|||
*/ |
|||
int update(CreatorAccount creatorAccount); |
|||
|
|||
/** |
|||
* 批量删除艺术家账户 |
|||
* @param ids ids |
|||
* @return - |
|||
*/ |
|||
int delete(List<Long> ids); |
|||
|
|||
/** |
|||
* 查询艺术家账户分页 |
|||
* @param dto 分页对象 |
|||
* @return - |
|||
*/ |
|||
List<CreatorAccount> queryPage(CreatorAccountPageDto dto); |
|||
|
|||
/** |
|||
* 查询艺术家账户详情 |
|||
* @param id 主键id |
|||
* @return - |
|||
*/ |
|||
CreatorAccount queryDetails(Long id); |
|||
|
|||
/** |
|||
* 查询小程序艺术家账户列表 |
|||
* @param creatorId 艺术家id |
|||
* @return - |
|||
*/ |
|||
List<CreatorAccountVo> queryList(Long creatorId); |
|||
|
|||
/** |
|||
* 变更显示状态 |
|||
* @param id 主键id |
|||
* @param status 状态 |
|||
* @return - |
|||
*/ |
|||
int changeStatus(Long id,String status); |
|||
|
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
package com.bnyer.img.service; |
|||
|
|||
import com.bnyer.img.domain.InviteLog; |
|||
import com.bnyer.img.domain.VerifyLog; |
|||
import com.bnyer.img.dto.InviteLogPageDto; |
|||
import com.bnyer.img.dto.VerifyPageDto; |
|||
import com.bnyer.img.vo.InviteLogVo; |
|||
import com.bnyer.img.vo.VerifyLogVo; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @author chengkun |
|||
* @date 2022/5/31 10:37 |
|||
*/ |
|||
public interface InviteLogService { |
|||
|
|||
/** |
|||
* 查询邀请记录分页 |
|||
* @param params 分页参数 |
|||
* @return - |
|||
*/ |
|||
List<InviteLog> queryPage(InviteLogPageDto params); |
|||
|
|||
/** |
|||
* 删除记录 |
|||
* @param ids 主键ids |
|||
* @return - |
|||
*/ |
|||
int delete(List<Long> ids); |
|||
|
|||
/** |
|||
* 小程序查询指定艺术家邀请记录 |
|||
* @param creatorId 艺术家id |
|||
* @return - |
|||
*/ |
|||
List<InviteLogVo> queryFrontList(Long creatorId); |
|||
} |
|||
@ -0,0 +1,107 @@ |
|||
package com.bnyer.img.service.impl; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|||
import com.bnyer.common.core.utils.DesensitizedUtils; |
|||
import com.bnyer.common.core.utils.Sm4Util; |
|||
import com.bnyer.common.core.utils.StringUtils; |
|||
import com.bnyer.img.domain.CreatorAccount; |
|||
import com.bnyer.img.dto.CreatorAccountPageDto; |
|||
import com.bnyer.img.mapper.CreatorAccountMapper; |
|||
import com.bnyer.img.service.CreatorAccountService; |
|||
import com.bnyer.img.vo.CreatorAccountVo; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
|
|||
import java.util.Date; |
|||
import java.util.List; |
|||
|
|||
@Service |
|||
@Slf4j |
|||
public class CreatorAccountServiceImpl implements CreatorAccountService { |
|||
|
|||
@Autowired |
|||
private CreatorAccountMapper creatorAccountMapper; |
|||
|
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public int insert(CreatorAccount creatorAccount) { |
|||
creatorAccount.setCreateTime(new Date()); |
|||
creatorAccount.setUpdateTime(new Date()); |
|||
return creatorAccountMapper.insert(creatorAccount); |
|||
} |
|||
|
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public int update(CreatorAccount creatorAccount) { |
|||
creatorAccount.setUpdateTime(new Date()); |
|||
return creatorAccountMapper.updateById(creatorAccount); |
|||
} |
|||
|
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public int delete(List<Long> ids) { |
|||
return creatorAccountMapper.deleteBatchIds(ids); |
|||
} |
|||
|
|||
@Override |
|||
public List<CreatorAccount> queryPage(CreatorAccountPageDto dto) { |
|||
LambdaQueryWrapper<CreatorAccount> wrapper = new LambdaQueryWrapper<>(); |
|||
if(StringUtils.isNotBlank(dto.getName())){ |
|||
wrapper.like(CreatorAccount::getName, dto.getName()); |
|||
} |
|||
if(StringUtils.isNotBlank(dto.getBankNo())){ |
|||
wrapper.eq(CreatorAccount::getBankNo, Sm4Util.sm4Encryption(dto.getBankNo())); |
|||
} |
|||
if(StringUtils.isNotBlank(dto.getIdNo())){ |
|||
wrapper.eq(CreatorAccount::getIdNo, Sm4Util.sm4Encryption(dto.getIdNo())); |
|||
} |
|||
if(StringUtils.isNotBlank(dto.getPhone())){ |
|||
wrapper.eq(CreatorAccount::getPhone, Sm4Util.sm4Encryption(dto.getPhone())); |
|||
} |
|||
if(StringUtils.isNotBlank(dto.getIsShow())){ |
|||
wrapper.eq(CreatorAccount::getIsShow, dto.getIsShow()); |
|||
} |
|||
wrapper.orderByDesc(CreatorAccount::getSort); |
|||
List<CreatorAccount> creatorAccounts = creatorAccountMapper.selectList(wrapper); |
|||
for (CreatorAccount creatorAccount : creatorAccounts) { |
|||
creatorAccount.setIdNo(DesensitizedUtils.getJsonNoCopy(Sm4Util.sm4Decrypt(creatorAccount.getIdNo()))); |
|||
creatorAccount.setPhone(DesensitizedUtils.getJsonNoCopy(Sm4Util.sm4Decrypt(creatorAccount.getPhone()))); |
|||
creatorAccount.setName(DesensitizedUtils.getJsonNoCopy(creatorAccount.getName())); |
|||
creatorAccount.setBankNo(DesensitizedUtils.getJsonNoCopy(Sm4Util.sm4Decrypt(creatorAccount.getBankNo()))); |
|||
} |
|||
return creatorAccounts; |
|||
} |
|||
|
|||
@Override |
|||
public CreatorAccount queryDetails(Long id) { |
|||
CreatorAccount creatorAccount = creatorAccountMapper.selectById(id); |
|||
creatorAccount.setIdNo(DesensitizedUtils.getJson(Sm4Util.sm4Decrypt(creatorAccount.getIdNo()))); |
|||
creatorAccount.setPhone(DesensitizedUtils.getJson(Sm4Util.sm4Decrypt(creatorAccount.getPhone()))); |
|||
creatorAccount.setName(DesensitizedUtils.getJson(Sm4Util.sm4Decrypt(creatorAccount.getName()))); |
|||
creatorAccount.setBankNo(DesensitizedUtils.getJson(Sm4Util.sm4Decrypt(creatorAccount.getBankNo()))); |
|||
return creatorAccount; |
|||
} |
|||
|
|||
@Override |
|||
public List<CreatorAccountVo> queryList(Long creatorId) { |
|||
List<CreatorAccountVo> creatorAccountVos = creatorAccountMapper.queryFrontList(creatorId); |
|||
for (CreatorAccountVo creatorAccountVo : creatorAccountVos) { |
|||
creatorAccountVo.setName(DesensitizedUtils.getJson(Sm4Util.sm4Decrypt(creatorAccountVo.getName()))); |
|||
creatorAccountVo.setBankNo(DesensitizedUtils.getJson(Sm4Util.sm4Decrypt(creatorAccountVo.getBankNo()))); |
|||
} |
|||
return creatorAccountVos; |
|||
} |
|||
|
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public int changeStatus(Long id, String status) { |
|||
LambdaUpdateWrapper<CreatorAccount> wrapper = new LambdaUpdateWrapper<>(); |
|||
wrapper.eq(CreatorAccount::getId, id); |
|||
CreatorAccount creatorAccount = new CreatorAccount(); |
|||
creatorAccount.setIsShow(status); |
|||
return creatorAccountMapper.update(creatorAccount,wrapper); |
|||
} |
|||
} |
|||
@ -0,0 +1,52 @@ |
|||
package com.bnyer.img.service.impl; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|||
import com.bnyer.common.core.utils.StringUtils; |
|||
import com.bnyer.img.domain.InviteLog; |
|||
import com.bnyer.img.dto.InviteLogPageDto; |
|||
import com.bnyer.img.dto.VerifyPageDto; |
|||
import com.bnyer.img.mapper.InviteLogMapper; |
|||
import com.bnyer.img.service.InviteLogService; |
|||
import com.bnyer.img.service.VerifyLogService; |
|||
import com.bnyer.img.vo.InviteLogVo; |
|||
import com.bnyer.img.vo.VerifyLogVo; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @author chengkun |
|||
* @date 2022/5/30 16:46 |
|||
*/ |
|||
@Service |
|||
@Slf4j |
|||
public class InviteLogServiceImpl implements InviteLogService { |
|||
|
|||
@Autowired |
|||
private InviteLogMapper inviteLogMapper; |
|||
|
|||
|
|||
@Override |
|||
public List<InviteLog> queryPage(InviteLogPageDto params) { |
|||
LambdaQueryWrapper<InviteLog> wrapper = new LambdaQueryWrapper<>(); |
|||
wrapper.eq(StringUtils.isNotBlank(params.getIsShow()),InviteLog::getIsShow,params.getIsShow()); |
|||
wrapper.eq(StringUtils.isNotBlank(params.getInviteCode()),InviteLog::getInviteCode,params.getInviteCode()); |
|||
return inviteLogMapper.selectList(wrapper); |
|||
} |
|||
|
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public int delete(List<Long> ids) { |
|||
return inviteLogMapper.deleteBatchIds(ids); |
|||
} |
|||
|
|||
@Override |
|||
public List<InviteLogVo> queryFrontList(Long creatorId) { |
|||
return inviteLogMapper.queryFrontList(creatorId); |
|||
} |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
package com.bnyer.img.vo; |
|||
|
|||
import com.bnyer.common.core.annotation.Desensitized; |
|||
import com.bnyer.common.core.enums.SensitiveTypeEnum; |
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
|
|||
@Getter |
|||
@Setter |
|||
@ApiModel("艺术家账户响应体") |
|||
public class CreatorAccountVo implements Serializable { |
|||
@ApiModelProperty(value="主键id") |
|||
private Long id; |
|||
|
|||
@ApiModelProperty(value="艺术家id") |
|||
private Long creatorId; |
|||
|
|||
@Desensitized(type = SensitiveTypeEnum.CHINESE_NAME) |
|||
@ApiModelProperty(value="姓名(加密)") |
|||
private String name; |
|||
|
|||
@Desensitized(type = SensitiveTypeEnum.BANK_CARD) |
|||
@ApiModelProperty(value="银行卡(加密)") |
|||
private String bankNo; |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
} |
|||
@ -0,0 +1,36 @@ |
|||
package com.bnyer.img.vo; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
|
|||
@Getter |
|||
@Setter |
|||
@ApiModel("邀请记录响应体") |
|||
public class InviteLogVo implements Serializable { |
|||
@ApiModelProperty(value="id") |
|||
private Long id; |
|||
|
|||
@ApiModelProperty(value="邀请者id") |
|||
private Long creatorId; |
|||
|
|||
@ApiModelProperty(value="邀请码") |
|||
private String inviteCode; |
|||
|
|||
@ApiModelProperty(value="被邀请者id") |
|||
private Long invitedCreatorId; |
|||
|
|||
@ApiModelProperty(value="被邀请者搜索码") |
|||
private String invitedScanCode; |
|||
|
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
|||
@ApiModelProperty(value="邀请时间") |
|||
private String createTime; |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
} |
|||
Loading…
Reference in new issue