From b64875c1073a2946870f370c8426040a70191c2c Mon Sep 17 00:00:00 2001 From: zhang chengzhi <3144712872@qq.com> Date: Mon, 26 Aug 2024 01:13:30 +0800 Subject: [PATCH] 11111 --- .../rule/common/utils/Desensitization.java | 271 ++++++++++++++++++ .../server/complie/SourceCodeComplier.java | 3 +- .../server/controller/EtlRuleController.java | 58 ++++ .../rule/server/service/EtlRuleService.java | 16 ++ .../service/impl/EtlRuleServiceImpl.java | 62 +++- 5 files changed, 408 insertions(+), 2 deletions(-) create mode 100644 cloud-rule-common/src/main/java/com/muyu/rule/common/utils/Desensitization.java diff --git a/cloud-rule-common/src/main/java/com/muyu/rule/common/utils/Desensitization.java b/cloud-rule-common/src/main/java/com/muyu/rule/common/utils/Desensitization.java new file mode 100644 index 0000000..77124ef --- /dev/null +++ b/cloud-rule-common/src/main/java/com/muyu/rule/common/utils/Desensitization.java @@ -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, "*"); + } +} diff --git a/cloud-rule-server/src/main/java/com/muyu/rule/server/complie/SourceCodeComplier.java b/cloud-rule-server/src/main/java/com/muyu/rule/server/complie/SourceCodeComplier.java index b2a8ffc..7b4454e 100644 --- a/cloud-rule-server/src/main/java/com/muyu/rule/server/complie/SourceCodeComplier.java +++ b/cloud-rule-server/src/main/java/com/muyu/rule/server/complie/SourceCodeComplier.java @@ -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); diff --git a/cloud-rule-server/src/main/java/com/muyu/rule/server/controller/EtlRuleController.java b/cloud-rule-server/src/main/java/com/muyu/rule/server/controller/EtlRuleController.java index 37a9cd8..122feba 100644 --- a/cloud-rule-server/src/main/java/com/muyu/rule/server/controller/EtlRuleController.java +++ b/cloud-rule-server/src/main/java/com/muyu/rule/server/controller/EtlRuleController.java @@ -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> findAllRuleRegion(){ @@ -119,6 +121,7 @@ public class EtlRuleController { @PostMapping("/selectRuleAndVersionById/{id}") +@Operation(summary = "规则引擎的维护", description = "通过Id查询规则引擎和规则引擎的版本") public Result 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(); + } diff --git a/cloud-rule-server/src/main/java/com/muyu/rule/server/service/EtlRuleService.java b/cloud-rule-server/src/main/java/com/muyu/rule/server/service/EtlRuleService.java index 7244067..d842c72 100644 --- a/cloud-rule-server/src/main/java/com/muyu/rule/server/service/EtlRuleService.java +++ b/cloud-rule-server/src/main/java/com/muyu/rule/server/service/EtlRuleService.java @@ -58,4 +58,20 @@ public interface EtlRuleService extends IService { EtlRuleResp selectRuleAndVersionById(Long id); + /** + * 开启状态接口 + * @param id + */ + + void openEngine(Long id); + + /** + * 关闭状态的接口 + * @param id + */ + void closeEngine(Long id); + + void activate(Long id); + + void disable(Long id); } diff --git a/cloud-rule-server/src/main/java/com/muyu/rule/server/service/impl/EtlRuleServiceImpl.java b/cloud-rule-server/src/main/java/com/muyu/rule/server/service/impl/EtlRuleServiceImpl.java index 724837c..4c4b404 100644 --- a/cloud-rule-server/src/main/java/com/muyu/rule/server/service/impl/EtlRuleServiceImpl.java +++ b/cloud-rule-server/src/main/java/com/muyu/rule/server/service/impl/EtlRuleServiceImpl.java @@ -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 } @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 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 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 updateWrapper = new UpdateWrapper<>(); + + updateWrapper.eq("id",id).set("open",open); + + this.update(updateWrapper); + + } }