master
zhang chengzhi 2024-08-26 01:13:30 +08:00
parent e982e31572
commit b64875c107
5 changed files with 408 additions and 2 deletions

View File

@ -0,0 +1,271 @@
package com.muyu.rule.common.utils;
import com.muyu.common.core.utils.StringUtils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
*
*/
public class Desensitization {
/**
*
*
* @param idCard
* @return
*/
public static String idCardDesensitization(String idCard) {
if (StringUtils.isNotEmpty(idCard)) {
// 身份证号脱敏规则一:保留前六后三
if (idCard.length() == 15) {
idCard = idCard.replaceAll("(\\w{6})\\w*(\\w{3})", "$1******$2");
} else if (idCard.length() == 18) {
idCard = idCard.replaceAll("(\\w{6})\\w*(\\w{3})", "$1*********$2");
}
// 身份证号脱敏规则二:保留前三后四
// idCard = idCard.replaceAll("(?<=\\w{3})\\w(?=\\w{4})", "*");
}
return idCard;
}
/**
*
* @param mobilePhone
* @return
*/
public static String mobilePhoneDesensitization(String mobilePhone) {
// 手机号码保留前三后四
if (StringUtils.isNotEmpty(mobilePhone)) {
mobilePhone = mobilePhone.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
}
return mobilePhone;
}
/**
*
*
* @param email
* @return
*/
public static String emailDesensitization(String email) {
// 电子邮箱隐藏@前面的3个字符
if (StringUtils.isEmpty(email)) {
return email;
}
String encrypt = email.replaceAll("(\\w+)\\w{3}@(\\w+)", "$1***@$2");
if (email.equalsIgnoreCase(encrypt)) {
encrypt = email.replaceAll("(\\w*)\\w{1}@(\\w+)", "$1*@$2");
}
return encrypt;
}
/**
*
*
* @param acctNo
* @return
*/
public static String acctNoDesensitization(String acctNo) {
// 银行账号保留前六后四
if (StringUtils.isNotEmpty(acctNo)) {
String regex = "(\\w{6})(.*)(\\w{4})";
Matcher m = Pattern.compile(regex).matcher(acctNo);
if (m.find()) {
String rep = m.group(2);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < rep.length(); i++) {
sb.append("*");
}
acctNo = acctNo.replaceAll(rep, sb.toString());
}
}
return acctNo;
}
/**
*
*
* @param custName
* @return
*/
public static String custNameDesensitization(String custName) {
// 规则说明:
// 姓名字符长度小于5位企业名称字符长度大于等于5位。
// 姓名规则
// 规则一1个字则不脱敏如"张"-->"张"
// 规则二2个字则脱敏第二个字如"张三"-->"张*"
// 规则三3个字则脱敏第二个字如"张三丰"-->"张*丰"
// 规则四4个字则脱敏中间两个字如"易烊千玺"-->"易**玺"
// 企业名称规则:
// 从第4位开始隐藏最多隐藏6位。
if (StringUtils.isNotEmpty(custName)) {
char[] chars = custName.toCharArray();
if (chars.length < 5) {// 表示姓名
if (chars.length > 1) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < chars.length - 2; i++) {
sb.append("*");
}
custName = custName.replaceAll(custName.substring(1, chars.length - 1), sb.toString());
}
} else {// 企业名称
int start = 4;
// 第一部分
String str1 = custName.substring(0, start);
// 第二部分
String str2 = "";
if (chars.length == 5) {
str2 = "*";
} else if (chars.length == 6) {
str2 = "**";
} else if (chars.length == 7) {
str2 = "***";
} else if (chars.length == 8) {
str2 = "****";
} else if (chars.length == 9) {
str2 = "*****";
} else {
str2 = "******";
}
// 通过计算得到第三部分需要从第几个字符截取
int subIndex = start + str2.length();
// 第三部分
String str3 = custName.substring(subIndex);
StringBuffer sb = new StringBuffer();
sb.append(str1);
sb.append(str2);
sb.append(str3);
custName = sb.toString();
}
}
return custName;
}
/**
*
*
* @param address
* @return
*/
public static String addressDesensitization(String address) {
// 规则说明从第4位开始隐藏隐藏8位。
if (StringUtils.isNotEmpty(address)) {
char[] chars = address.toCharArray();
if (chars.length > 11) {// 由于需要从第4位开始隐藏8位因此数据长度必须大于11位
// 获取第一部分内容
String str1 = address.substring(0, 4);
// 获取第二部分
String str2 = "********";
// 获取第三部分
String str3 = address.substring(12);
StringBuffer sb = new StringBuffer();
sb.append(str1);
sb.append(str2);
sb.append(str3);
address = sb.toString();
}
}
return address;
}
//下面代码是从别人博客看到的。
/**
*
*/
public static final int ONE = 1;
public static final int TWO = 2;
/**
*
*
* @param realName
* @return
*/
public static String desensitizedName(String realName) {
if (realName == null) {
return null;
}
if (realName.length() == ONE) {
return realName;
} else if (realName.length() == TWO) {
return realName.substring(0, 1) +"*";
} else {
Integer length = realName.length();
StringBuffer middle = new StringBuffer();
for (int i = 0; i < realName.substring(1, length - 1).length(); i++) {
middle.append("*");
}
return realName.substring(0, 1) + middle + realName.substring(length - 1, length);
}
}
/**
*
*
* @param address
* @return
*/
public static String desensitizedAddress(String address){
//江西省宜春市丰城市剑南街道人才教育小区41号丰城住总运营有限公司-->江西省宜春市丰城市剑南街道人才教育小区*************
if (StringUtils.isNotEmpty(address)) {
int length = address.length();
int indes = address.indexOf("区");
if (indes == -1) {
indes = address.indexOf("市");
}
address = address.substring(0, indes + 1);
StringBuffer middle = new StringBuffer();
for (int i = 0; i < length - indes; i++) {
middle.append("*");
}
return address + middle;
}
return address;
}
/**
*
*
* @param origin
* @param prefixNoMaskLen
* @param suffixNoMaskLen
* @param maskStr , '*'
* @return
*/
public static String desValue(String origin, int prefixNoMaskLen, int suffixNoMaskLen, String maskStr) {
if (origin == null) {
return null;
}
StringBuilder sb = new StringBuilder();
for (int i = 0, n = origin.length(); i < n; i++) {
if (i < prefixNoMaskLen) {
sb.append(origin.charAt(i));
continue;
}
if (i > (n - suffixNoMaskLen - 1)) {
sb.append(origin.charAt(i));
continue;
}
sb.append(maskStr);
}
return sb.toString();
}
/**
* **
*
* @param fullName
* @return
*/
public static String chineseName(String fullName) {
if (fullName == null) {
return null;
}
return desValue(fullName, 0, 1, "*");
}
}

View File

@ -27,7 +27,8 @@ public class SourceCodeComplier extends ClassLoader {
* @param path
*/
public static void javaCompilerPath(String path){
public static void
javaCompilerPath(String path){
File[] files = JavaCodeScan.javaSourceScanByPath(path);
javaCampiler(files);

View File

@ -1,5 +1,6 @@
package com.muyu.rule.server.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.muyu.common.core.domain.Result;
import com.muyu.rule.common.domain.RuleEngine;
@ -104,6 +105,7 @@ public class EtlRuleController {
@PostMapping("/findAllRuleRegion")
@Operation(summary = "规则作用域列表", description = "查询所有作用域的信息")
public Result<List<RuleRegion>> findAllRuleRegion(){
@ -119,6 +121,7 @@ public class EtlRuleController {
@PostMapping("/selectRuleAndVersionById/{id}")
@Operation(summary = "规则引擎的维护", description = "通过Id查询规则引擎和规则引擎的版本")
public Result<EtlRuleResp> selectRuleAndVersionById(@PathVariable("id") Long id){
EtlRuleResp etlRuleResp = etlRuleService.selectRuleAndVersionById(id);
@ -126,8 +129,63 @@ public class EtlRuleController {
return Result.success(etlRuleResp);
}
/**
*
* @param id
* @return
*/
@PostMapping("/openEngine/{id}")
@Operation(summary = "规则引擎的开启", description = "通过Id开启规则引擎")
public Result openEngine(@PathVariable("id") Long id){
etlRuleService.openEngine(id);
return Result.success();
}
/**
*
*/
@PostMapping("/closeEngine/{id}")
@Operation(summary = "规则引擎的关闭", description = "通过Id关闭规则引擎")
public Result closeEngine(@PathVariable("id") Long id){
etlRuleService.closeEngine(id);
return Result.success();
}
/**
*
* @param id
* @return
*/
@PostMapping("/activate/{id}")
@Operation(summary = "规则引擎的激活", description = "通过Id激活规则引擎")
public Result activate(@PathVariable("id") Long id){
etlRuleService.activate(id);
return Result.success();
}
/**
*
*/
@PostMapping("/disable/{id}")
@Operation(summary = "规则引擎的取消", description = "通过Id取消规则引擎")
public Result disable(@PathVariable("id") Long id){
etlRuleService.disable(id);
return Result.success();
}

View File

@ -58,4 +58,20 @@ public interface EtlRuleService extends IService<RuleEngine> {
EtlRuleResp selectRuleAndVersionById(Long id);
/**
*
* @param id
*/
void openEngine(Long id);
/**
*
* @param id
*/
void closeEngine(Long id);
void activate(Long id);
void disable(Long id);
}

View File

@ -1,8 +1,11 @@
package com.muyu.rule.server.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.common.core.enums.SystemYesNo;
import com.muyu.common.core.utils.StringUtils;
import com.muyu.common.system.domain.SysDept;
import com.muyu.rule.common.domain.RuleEngine;
import com.muyu.rule.common.domain.RuleRegion;
import com.muyu.rule.common.domain.req.EtlRuleListReq;
@ -93,7 +96,7 @@ public class EtlRuleServiceImpl extends ServiceImpl<EtlRuleMapper, RuleEngine>
}
@Override
public EtlRuleResp selectRuleAndVersionById(Long id) {
public EtlRuleResp selectRuleAndVersionById(Long id) {
RuleEngine ruleEngine = etlRuleMapper.selectById(id);
@ -106,5 +109,62 @@ public class EtlRuleServiceImpl extends ServiceImpl<EtlRuleMapper, RuleEngine>
return etlRuleResp;
}
@Override
public void openEngine(Long id) {
this.updateStatus(id,"0");
}
@Override
public void closeEngine(Long id) {
this.updateStatus(id,"1");
}
@Override
public void activate(Long id) {
this.updateOpen(id,SystemYesNo.YES.getCode());
}
@Override
public void disable(Long id) {
this.updateOpen(id,SystemYesNo.NO.getCode());
}
/**
*
* @param id
* @param status
*/
public void updateStatus(Long id, String status){
UpdateWrapper<RuleEngine> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("id",id).set("status",status);
this.update(updateWrapper);
}
/**
*
* @param id
* @param open
*/
public void updateOpen(Long id, String open){
UpdateWrapper<RuleEngine> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("id",id).set("open",open);
this.update(updateWrapper);
}
}