From d064421d278ca1fa68ffd662dccaa5d2cfcc3fba Mon Sep 17 00:00:00 2001 From: cuibaocheng Date: Thu, 23 Sep 2021 14:06:37 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E4=BF=AE=E6=94=B9=E4=BA=86=E6=8F=90?= =?UTF-8?q?=E7=8E=B0=E8=AE=B0=E5=BD=95=E5=88=97=E8=A1=A8=E7=9A=84Bug=202.?= =?UTF-8?q?=20=E4=BF=AE=E6=94=B9=E4=BA=86=E5=8A=A8=E6=80=81=E8=A1=A8?= =?UTF-8?q?=E5=8D=95=E5=9B=A0=E4=B8=BA=E5=BC=80=E5=90=AFcache=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E5=AF=BC=E8=87=B4=E6=95=B0=E6=8D=AE=E4=B8=8D=E5=85=A8?= =?UTF-8?q?=E4=B8=8D=E6=9B=B4=E6=96=B0=E7=9A=84Bug(=E4=B8=8D=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E7=BC=93=E5=AD=98)=203.=20=E8=B0=83=E8=AF=95=E6=8E=A7?= =?UTF-8?q?=E5=88=B6=E5=8F=B0=E5=A2=9E=E5=8A=A0=E4=BA=86=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E7=9A=84=E9=85=8D=E7=BD=AE=204.=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=BA=86=E4=BC=81=E4=B8=9A=E8=AE=A4=E8=AF=81=E7=9A=84?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../systemcard/enums/AuditTypeEnum.java | 30 +++++++ .../filter/AuditServiceLocator.java | 54 +++++++++++++ .../util/BusinessLicenseCheckUtil.java | 79 +++++++++++++++++++ 3 files changed, 163 insertions(+) create mode 100644 src/main/java/cn/com/tenlion/systemcard/enums/AuditTypeEnum.java create mode 100644 src/main/java/cn/com/tenlion/systemcard/filter/AuditServiceLocator.java create mode 100644 src/main/java/cn/com/tenlion/systemcard/util/BusinessLicenseCheckUtil.java diff --git a/src/main/java/cn/com/tenlion/systemcard/enums/AuditTypeEnum.java b/src/main/java/cn/com/tenlion/systemcard/enums/AuditTypeEnum.java new file mode 100644 index 0000000..30db78e --- /dev/null +++ b/src/main/java/cn/com/tenlion/systemcard/enums/AuditTypeEnum.java @@ -0,0 +1,30 @@ +package cn.com.tenlion.systemcard.enums; + +/** + * 2021年9月22日16:07:40 + * 审核日志表类型枚举 + */ +public enum AuditTypeEnum { + + CERTIFICATION("shopCertificationServiceImpl", "企业认证"); + + private String type; + + private String typeName; + + AuditTypeEnum(String type, String typeName) { + this.type = type; + this.typeName = typeName; + } + public String getType() { + return type; + } + + public String getTypeName() { + return typeName; + } + +// public static ArrayList> getType() { +// return type; +// } +} diff --git a/src/main/java/cn/com/tenlion/systemcard/filter/AuditServiceLocator.java b/src/main/java/cn/com/tenlion/systemcard/filter/AuditServiceLocator.java new file mode 100644 index 0000000..c9bc098 --- /dev/null +++ b/src/main/java/cn/com/tenlion/systemcard/filter/AuditServiceLocator.java @@ -0,0 +1,54 @@ +package cn.com.tenlion.systemcard.filter; + +import cn.com.tenlion.systemcard.enums.AuditTypeEnum; +import cn.com.tenlion.systemcard.service.shopauditlog.IShopAuditLogUpdateService; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.Map; + +/** + * explain:获取应用上下文并获取所有的审核记录实现类 + * @author yang + * @date 2021/1/5 + */ +@Component +public class AuditServiceLocator implements ApplicationContextAware { + + /** + * 用于保存接口实现类名及对应的类 + */ + private Map map = new HashMap(); + + /** + * 获取应用上下文并获取相应的接口实现类 + * @param applicationContext + * @throws BeansException + */ + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + //根据接口类型返回相应的所有bean + map = applicationContext.getBeansOfType(IShopAuditLogUpdateService.class); + } + + /** + * 获取所有实现集合 + * @return + */ + public Map getMap() { + return map; + } + + /** + * 获取对应服务 + * @param key + * @return + */ + public IShopAuditLogUpdateService getService(String key) { + return map.get(key); + } + +} diff --git a/src/main/java/cn/com/tenlion/systemcard/util/BusinessLicenseCheckUtil.java b/src/main/java/cn/com/tenlion/systemcard/util/BusinessLicenseCheckUtil.java new file mode 100644 index 0000000..a702ecd --- /dev/null +++ b/src/main/java/cn/com/tenlion/systemcard/util/BusinessLicenseCheckUtil.java @@ -0,0 +1,79 @@ +package cn.com.tenlion.systemcard.util; + +import org.apache.commons.collections4.BidiMap; +import org.apache.commons.collections4.bidimap.TreeBidiMap; + +import javax.xml.bind.ValidationException; +import java.util.Map; + +public class BusinessLicenseCheckUtil { + + static String baseCode = "0123456789ABCDEFGHJKLMNPQRTUWXY"; + static char[] baseCodeArray = baseCode.toCharArray(); + static int[] wi = {1, 3, 9, 27, 19, 26, 16, 17, 20, 29, 25, 13, 8, 24, 10, 30, 28}; + + public static void main(String[] args) { + System.out.println(validateUnifiedCreditCode("91140100095819667W")); + System.out.println(validateUnifiedCreditCode("612727199303151514")); + System.out.println(validateUnifiedCreditCode("ces ")); + System.out.println(validateUnifiedCreditCode("CEE")); + System.out.println(validateUnifiedCreditCode("测试")); + System.out.println(validateUnifiedCreditCode("测试彻底的的35465465qqq")); + } + + /** + * 生成供较验使用的 Code Map + * + * @return BidiMap + */ + static BidiMap generateCodes() { + BidiMap codes = new TreeBidiMap<>(); + for (int i = 0; i < baseCode.length(); i++) { + codes.put(baseCodeArray[i], i); + } + return codes; + } + + /** + * 较验社会统一信用代码 + * + * @param unifiedCreditCode 统一社会信息代码 + * @return 符合: true + */ + public static boolean validateUnifiedCreditCode(String unifiedCreditCode) { + if ((unifiedCreditCode.equals("")) || unifiedCreditCode.length() != 18) { + return false; + } + Map codes = generateCodes(); + int parityBit; + try { + parityBit = getParityBit(unifiedCreditCode, codes); + } catch (Exception e) { + return false; + } + return parityBit == codes.get(unifiedCreditCode.charAt(unifiedCreditCode.length() - 1)); + } + + /** + * 获取较验码 + * + * @param unifiedCreditCode 统一社会信息代码 + * @param codes 带有映射关系的国家代码 + * @return 获取较验位的值 + */ + static int getParityBit(String unifiedCreditCode, Map codes) throws Exception { + char[] businessCodeArray = unifiedCreditCode.toCharArray(); + + int sum = 0; + for (int i = 0; i < 17; i++) { + char key = businessCodeArray[i]; + if (baseCode.indexOf(key) == -1) { + throw new Exception("第" + String.valueOf(i + 1) + "位传入了非法的字符" + key); + } + sum += (codes.get(key) * wi[i]); + } + int result = 31 - sum % 31; + return result == 31 ? 0 : result; + } + +}