zjh
昨天 ad4326adc4ccad14f090fba5acb435deab8260db
ltkj-admin/src/test/java/zjhTest.java
@@ -1,7 +1,9 @@
import cn.hutool.core.io.FileUtil;
import com.ltkj.LtkjApplication;
import com.ltkj.LtkjApplication;import com.ltkj.framework.config.MatchUtils;
import com.ltkj.hosp.domain.TjJcycxm;
import com.ltkj.hosp.idutil.IdUtils;
import jodd.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -30,6 +32,9 @@
import java.io.File;
import java.io.IOException;
/**
 * @Author: 西安路泰科技有限公司/赵佳豪
 * @Date: 2022/12/12 9:05
@@ -66,46 +71,42 @@
    }
    private static final String[] CHECK_INDEX = {"1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"};
        public static void main(String[] args) throws Exception {
            List<String> numbers = Arrays.asList(
                    "25032800283", "25032800284", "25032800285", "25032800286",
                    "25032800287", "25032800288", "25032800289", "25032800290",
                    "25032800291", "25032800292", "25032800293", "25032800294",
                    "25032800295", "25032800296", "25032800297", "25032800298",
                    "25032800299", "25032800300", "25032800301", "25032800302",
                    "25032800303", "25032800304", "25032800305", "25032800306",
                    "25032800307", "25032800308", "25032800309", "25032800310",
                    "25032800311", "25032800312", "25032800313", "25032800314",
                    "25032800315", "25032800316", "25032800317", "25032800318",
                    "25032800319", "25032800320", "25032800321", "25032800322",
                    "25032800323", "25032800324", "25032800325", "25032800326",
                    "25032800327", "25032800328", "25032800329", "25032800330",
                    "25032800331", "25032800332", "25032800333", "25032800334",
                    "25032800335", "25032800336", "25032800337", "25032800338",
                    "25032800339", "25032800340", "25032800341", "25032800342",
                    "25032800343", "25032800344", "25032800345", "25032800346",
                    "25032800347", "25032800348", "25032800349", "25032800350",
                    "25032800351", "25032800352", "25032800353", "25032800354",
                    "25032800355", "25032800356", "25032800357", "25032800358",
                    "25032800359", "25032800360", "25032800361", "25032800362",
                    "25032800363", "25032800364", "25032800365", "25032800366",
                    "25032800367", "25032800368", "25032800369", "25032800370",
                    "25032800371", "25032800372", "25032800373", "25032800374"
            );
            Set<String> uniqueNumbers = new HashSet<>(numbers);
            if (uniqueNumbers.size() == numbers.size()) {
                System.out.println("✅ 没有重复编号!");
            } else {
                System.out.println("❌ 发现重复编号!");
                numbers.stream()
                        .filter(n -> Collections.frequency(numbers, n) > 1)
                        .distinct()
                        .forEach(n -> System.out.println("重复的编号:" + n));
            }
            String s = "62272219650528411X";
            System.out.println(isValidIdCard(s) ? "合法" : "非法");
        }
    public static boolean isValidIdCard(String idCardNumber) {
        // 正则表达式,匹配身份证号码的格式
        String regex = "(^\\d{15}$)|(^\\d{18}$)|(^\\d{17}(\\d|X|x)$)";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(idCardNumber);
        // 判断是否匹配身份证号码的格式
        if (!matcher.matches()) {
            return false;
        }
        // 验证身份证号码中的校验位
        if (idCardNumber.length() == 18) {
            int[] weights = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
            char[] chars = idCardNumber.toCharArray();
            int sum = 0;
            for (int i = 0; i < weights.length; i++) {
                sum += (chars[i] - '0') * weights[i];
            }
            char[] checkCodes = {'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'};
            char checkCode = checkCodes[sum % 11];
            return chars[17] == checkCode || (chars[17] == 'x' && checkCode == 'X');
        }
        return true;
    }
    /**
     * 执行生成