/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  org.apache.commons.lang.StringUtils
 */
package com.hst.common.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang.StringUtils;

public class IDCardUtil {
    public static boolean checkIdCardNo(String idCardNo) throws Exception {
        block6: {
            String verify;
            String front_17;
            block7: {
                block5: {
                    if (!StringUtils.isBlank((String)idCardNo)) break block5;
                    return false;
                }
                int length = idCardNo.length();
                if (length == 15) {
                    Pattern p = Pattern.compile("^[0-9]*$");
                    Matcher m = p.matcher(idCardNo);
                    return m.matches();
                }
                if (length != 18) break block6;
                front_17 = idCardNo.substring(0, idCardNo.length() - 1);
                verify = idCardNo.substring(17, 18);
                Pattern p = Pattern.compile("^[0-9]*$");
                Matcher m = p.matcher(front_17);
                if (m.matches()) break block7;
                return false;
            }
            IDCardUtil.checkVerify(front_17, verify);
        }
        return false;
    }

    public static boolean checkVerify(String front_17, String verify) throws Exception {
        int[] wi = new int[]{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1};
        String[] vi = new String[]{"1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"};
        int s = 0;
        int i = 0;
        while (i < front_17.length()) {
            int ai = Integer.parseInt(String.valueOf(front_17.charAt(i)));
            s += wi[i] * ai;
            ++i;
        }
        int y = s % 11;
        String v = vi[y];
        return verify.toUpperCase().equals(v);
    }

    public static String getGenderByIdCard(String idCardNo) {
        String sCardNum;
        String sGender = "\u672a\u77e5";
        int length = idCardNo.length();
        sGender = length == 15 ? (Integer.parseInt(sCardNum = idCardNo.substring(14, 15)) % 2 != 0 ? "1" : "2") : (Integer.parseInt(sCardNum = idCardNo.substring(16, 17)) % 2 != 0 ? "1" : "2");
        return sGender;
    }
}
