| | |
| | | package com.ltkj.framework.config; |
| | | |
| | | import cn.hutool.core.date.DateUtil; |
| | | import com.ltkj.common.utils.StringUtils; |
| | | |
| | | import java.util.Calendar; |
| | | import java.util.Collections; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneId; |
| | | import java.util.*; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | |
| | |
| | | if (matches && idCardBuilder.length() == SECOND_ID_CARD_LENGTH) { |
| | | int index = getIdCardCheckIndex(idCardBuilder); |
| | | // 获取传入身份证的检验码 |
| | | //String check = String.valueOf(idCardBuilder.charAt(idCardBuilder.length() - 1)); |
| | | String check = String.valueOf(idCardBuilder.charAt(idCardBuilder.length() - 1)); |
| | | // 检验码校验 |
| | | //return StringUtils.equalsIgnoreCase(CHECK_INDEX[index], check); |
| | | return StringUtils.equalsIgnoreCase(CHECK_INDEX[index], check); |
| | | } |
| | | return matches; |
| | | } |
| | |
| | | /** |
| | | * @desc 通过身份证获取出生日期 |
| | | */ |
| | | public static String getBirthDayByIdCard(String idCard) { |
| | | public static Date getBirthDayByIdCard(String idCard) throws Exception { |
| | | if (!isIdCard(idCard)) { |
| | | return "idCard error!"; |
| | | throw new Exception("身份证不正确"); |
| | | } |
| | | // 获取身份证的出生年月日串 |
| | | String birth = getIdCardBirthDayStr(idCard); |
| | |
| | | int year = Integer.parseInt(birth.substring(0, 4)); |
| | | int month = Integer.parseInt(birth.substring(4, 6)); |
| | | int day = Integer.parseInt(birth.substring(6, 8)); |
| | | return year + "-" + month + "-" + day; |
| | | String sr= year + "-" + month + "-" + day; |
| | | // 解析为 Date |
| | | Date date = DateUtil.parse(sr, "yyyy-MM-dd"); |
| | | // 转换为 LocalDateTime |
| | | LocalDateTime dateTime = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); |
| | | // 设置固定时分秒 |
| | | dateTime = dateTime.withHour(12).withMinute(34).withSecond(56); |
| | | return Date.from(dateTime.atZone(ZoneId.systemDefault()).toInstant()); |
| | | } |
| | | |
| | | /** |
| | |
| | | /** |
| | | * @desc 计算出校验码所在校验码数组的下标值 |
| | | */ |
| | | private static int getIdCardCheckIndex(StringBuilder idCardBuilder) { |
| | | public static int getIdCardCheckIndex(StringBuilder idCardBuilder) { |
| | | // 判断传入的是17位还是18位身份证号 |
| | | int length = idCardBuilder.length() == SECOND_ID_CARD_LENGTH ? idCardBuilder.length() - 1 : idCardBuilder.length(); |
| | | // 计算出校验码 |
| | |
| | | nativePlace += quxian; |
| | | } |
| | | return nativePlace; |
| | | } |
| | | |
| | | /** |
| | | * 将excel表中科学计数格式的手机号转成字符串形式 |
| | | * @param number |
| | | * @return |
| | | */ |
| | | public static String translateToPlainStr(String number) { |
| | | if (null == number || number.trim().length() == 0) { |
| | | return number; |
| | | } |
| | | String regEx="^([\\+|-]?\\d+(.{0}|.\\d+))[Ee]{1}([\\+|-]?\\d+)$"; |
| | | // 编译正则表达式 |
| | | Pattern pattern = Pattern.compile(regEx); |
| | | // 忽略大小写的写法 |
| | | // Pattern pat = Pattern.compile(regEx, Pattern.CASE_INSENSITIVE); |
| | | Matcher matcher = pattern.matcher(number); |
| | | // 字符串是否与正则表达式相匹配 |
| | | boolean rs = matcher.matches(); |
| | | // 判断是否为字符串的科学计数法 |
| | | if(rs){ |
| | | // 科学计数法转数字 |
| | | BigDecimal originValue = new BigDecimal(number); |
| | | // System.out.println("手机号为 ==> " + originValue.toPlainString()); |
| | | // 数字转字符串 |
| | | return originValue.toPlainString(); |
| | | } |
| | | return number; |
| | | } |
| | | |
| | | private static String getNameString(int code) { |
| | |
| | | } |
| | | return realname; |
| | | } |
| | | |
| | | /** |
| | | * 根据时间段判断上午还是下午 |
| | | * |
| | | * @param timeSlot |
| | | * @return |
| | | */ |
| | | // public static String getMorA(String timeSlot){ |
| | | // String reg=""; |
| | | // switch (timeSlot){ |
| | | // case "1": |
| | | // case "2": |
| | | // case "3": |
| | | // case "4": |
| | | // reg="上午"; |
| | | // break; |
| | | // |
| | | // case "5": |
| | | // case "6": |
| | | // case "7": |
| | | // reg="下午"; |
| | | // break; |
| | | // |
| | | // default:break; |
| | | // } |
| | | // |
| | | // return reg; |
| | | // } |
| | | } |