package com.ruoyi.web.modules.industryservice.support;

/**
 * 身份证校验工具（供经销商/供应商等模块复用）。
 */
public final class PastureValidation
{
    private static final int[] ID_CARD_WEIGHT = { 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 };

    private static final char[] ID_CARD_CHECK = { '1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2' };

    private PastureValidation()
    {
    }

    public static boolean isIdCardChecksumValid(String idCard)
    {
        int sum = 0;
        for (int i = 0; i < 17; i++)
        {
            sum += (idCard.charAt(i) - '0') * ID_CARD_WEIGHT[i];
        }
        char expected = ID_CARD_CHECK[sum % 11];
        char actual = Character.toUpperCase(idCard.charAt(17));
        return expected == actual;
    }
}
