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; + } + +}