xiatian před 5 roky
rodič
revize
2e5368c146

+ 43 - 0
src/main/java/cn/com/qmth/examcloud/support/helper/IdentityNumberHelper.java

@@ -0,0 +1,43 @@
+package cn.com.qmth.examcloud.support.helper;
+
+import org.apache.commons.lang3.StringUtils;
+
+import cn.com.qmth.examcloud.commons.exception.StatusException;
+import cn.com.qmth.examcloud.support.Constants;
+import cn.com.qmth.examcloud.support.cache.CacheHelper;
+import cn.com.qmth.examcloud.support.cache.bean.OrgPropertyCacheBean;
+
+public class IdentityNumberHelper {
+
+	public static String conceal(Long rootOrgId,String identityNumber) {
+		if(rootOrgId==null) {
+			throw new StatusException("1001", "rootOrgId不能为空");
+		}
+		if (!identityNumbeConceal(rootOrgId)) {
+			return identityNumber;
+		}
+		if (StringUtils.isBlank(identityNumber)) {
+			return identityNumber;
+		}
+		if (identityNumber.length() < 8) {
+			return identityNumber;
+		}
+		StringBuilder sb = new StringBuilder(identityNumber);
+		sb.replace(identityNumber.length() - 8, identityNumber.length() - 2, "******");
+		return sb.toString();
+	}
+
+	private static boolean identityNumbeConceal(Long rootOrgId) {
+		OrgPropertyCacheBean orgProperty = CacheHelper.getOrgProperty(rootOrgId, Constants.ID_NUMBER_PRIVATE_MODE_KEY);
+		
+		if(orgProperty==null) {
+			return false;
+		}
+
+		if (orgProperty.getHasValue()) {
+			return "1".equals(orgProperty.getValue());
+		}else {
+			return false;
+		}
+	}
+}