package com.zx.test.validation;
import cn.hutool.core.map.BiMap;
import cn.hutool.core.util.StrUtil;
import java.util.HashMap;
/**
* 中国国家民族
* @author zx
*/
public class ChineseNationalityCodeUtil {
/**
* 中国民族-相关码表 chinese nationality code
*/
private static final BiMap<Integer, String> CHINESE_NATIONALITY_CODE = new BiMap<>(new HashMap<>());
static {
//民族代码表 56个民族
// http://www.nbyz.gov.cn/art/2020/9/27/art_1229107563_58678611.html
// http://www.wlht.gov.cn/mcxam/xxgk30/cyzw94/tjxx83/3735536/index.html
CHINESE_NATIONALITY_CODE.put(1, "汉族");
CHINESE_NATIONALITY_CODE.put(2, "壮族");
CHINESE_NATIONALITY_CODE.put(3, "满族");
CHINESE_NATIONALITY_CODE.put(4, "回族");
CHINESE_NATIONALITY_CODE.put(5, "苗族");
CHINESE_NATIONALITY_CODE.put(6, "维吾尔族");
CHINESE_NATIONALITY_CODE.put(7, "土家族");
CHINESE_NATIONALITY_CODE.put(8, "彝族");
CHINESE_NATIONALITY_CODE.put(9, "蒙古族");
CHINESE_NATIONALITY_CODE.put(10, "藏族");
CHINESE_NATIONALITY_CODE.put(11, "布依族");
CHINESE_NATIONALITY_CODE.put(12, "侗族");
CHINESE_NATIONALITY_CODE.put(13, "瑶族");
CHINESE_NATIONALITY_CODE.put(14, "朝鲜族");
CHINESE_NATIONALITY_CODE.put(15, "白族");
CHINESE_NATIONALITY_CODE.put(16, "哈尼族");
CHINESE_NATIONALITY_CODE.put(17, "哈萨克族");
CHINESE_NATIONALITY_CODE.put(18, "黎族");
CHINESE_NATIONALITY_CODE.put(19, "傣族");
CHINESE_NATIONALITY_CODE.put(20, "畲族");
CHINESE_NATIONALITY_CODE.put(21, "傈僳族");
CHINESE_NATIONALITY_CODE.put(22, "仡佬族");
CHINESE_NATIONALITY_CODE.put(23, "东乡族");
CHINESE_NATIONALITY_CODE.put(24, "高山族");
CHINESE_NATIONALITY_CODE.put(25, "拉祜族");
CHINESE_NATIONALITY_CODE.put(26, "水族");
CHINESE_NATIONALITY_CODE.put(27, "佤族");
CHINESE_NATIONALITY_CODE.put(28, "纳西族");
CHINESE_NATIONALITY_CODE.put(29, "羌族");
CHINESE_NATIONALITY_CODE.put(30, "土族");
CHINESE_NATIONALITY_CODE.put(31, "仫佬族");
CHINESE_NATIONALITY_CODE.put(32, "锡伯族");
CHINESE_NATIONALITY_CODE.put(33, "柯尔克孜族");
CHINESE_NATIONALITY_CODE.put(34, "达斡尔族");
CHINESE_NATIONALITY_CODE.put(35, "景颇族");
CHINESE_NATIONALITY_CODE.put(36, "毛南族");
CHINESE_NATIONALITY_CODE.put(37, "撒拉族");
CHINESE_NATIONALITY_CODE.put(38, "布朗族");
CHINESE_NATIONALITY_CODE.put(39, "塔吉克族");
CHINESE_NATIONALITY_CODE.put(40, "阿昌族");
CHINESE_NATIONALITY_CODE.put(41, "普米族");
CHINESE_NATIONALITY_CODE.put(42, "鄂温克族");
CHINESE_NATIONALITY_CODE.put(43, "怒族");
CHINESE_NATIONALITY_CODE.put(44, "京族");
CHINESE_NATIONALITY_CODE.put(45, "基诺族");
CHINESE_NATIONALITY_CODE.put(46, "德昂族");
CHINESE_NATIONALITY_CODE.put(47, "保安族");
CHINESE_NATIONALITY_CODE.put(48, "俄罗斯族");
CHINESE_NATIONALITY_CODE.put(49, "裕固族");
CHINESE_NATIONALITY_CODE.put(50, "乌孜别克族");
CHINESE_NATIONALITY_CODE.put(51, "门巴族");
CHINESE_NATIONALITY_CODE.put(52, "鄂伦春族");
CHINESE_NATIONALITY_CODE.put(53, "独龙族");
CHINESE_NATIONALITY_CODE.put(54, "塔塔尔族");
CHINESE_NATIONALITY_CODE.put(55, "赫哲族");
CHINESE_NATIONALITY_CODE.put(56, "珞巴族");
// 其他 <====> 未定族称人口
CHINESE_NATIONALITY_CODE.put(97, "其他");
// 外国血统 <====> 外国血统中国籍人士 <===> 入籍
CHINESE_NATIONALITY_CODE.put(98, "外国血统");
}
// ----------------------------------------------------------------------------------- 民族 nationality start
/**
* 根据名族代码获取民族名称;
* @param nationalCode 民族代码,取值:1-56、97、98
* @return 民族名称
* @author zx
* @since 5.6.4
*/
public static String getNationalityName(int nationalCode) {
return CHINESE_NATIONALITY_CODE.get(nationalCode);
}
/**
* 根据民族名称 获取编码;
* 民族:可以通过身份证读卡器获取到用户的民族名称,我们通过民族名称反查国家民族代码
* @param nationalName 民族名称,eg: 汉族 或者 汉
* @return 民族编码
* @author zx
* @since 5.6.4
*/
public static Integer getNationalityCode(String nationalName) {
if (nationalName == null || nationalName.length() <= 0) {
return null;
}
Integer code = CHINESE_NATIONALITY_CODE.getKey(nationalName);
// 补偿方案1,存在多种叫法
// 外国血统 <====> 外国血统中国籍人士 <===> 入籍
// 其他 <====> 未定族称人口
if (code == null) {
if ("外国血统中国籍人士".contains(nationalName) || "入籍".equals(nationalName)) {
nationalName = "外国血统";
}
if ("未定族称人口".contains(nationalName)) {
nationalName = "其他";
}
code = CHINESE_NATIONALITY_CODE.getKey(nationalName);
}
// 补偿方案2,如果名族后面没有 加族,我们默认加族
String suffix = "族";
if (code == null) {
if (!nationalName.contains(suffix)) {
nationalName = nationalName + suffix;
code = CHINESE_NATIONALITY_CODE.getKey(nationalName);
}
}
return code;
}
/**
* 根据民族名称 获取编码,编码小于10,如:X---> 0X
* @param nationalName 民族名称
* @return 民族编码
* @author zx
* @since 5.6.4
*/
public static String getNationalityCodeStr(String nationalName) {
Integer code = getNationalityCode(nationalName);
if (code != null) {
return StrUtil.padPre(code.toString(),2,"0");
} else {
return "01";
}
}
}
中国民族工具类
最新推荐文章于 2024-08-18 21:36:31 发布