| | |
| | | /** |
| | | * 将 30*1000 转为 30000 |
| | | * 不能出现小数点等 |
| | | * |
| | | * @param val |
| | | * @return |
| | | */ |
| | | public static int multiplicativeStringToInteger(String val){ |
| | | public static int multiplicativeStringToInteger(String val) { |
| | | try { |
| | | if (StringUtils.isEmpty(val)) { |
| | | return 0; |
| | |
| | | if (val.contains("*")) { |
| | | String[] vals = val.split("\\*"); |
| | | int value = 1; |
| | | for(int vIndex = 0 ; vIndex < vals.length;vIndex++){ |
| | | if(!NumberUtils.isNumber(vals[vIndex])){ |
| | | for (int vIndex = 0; vIndex < vals.length; vIndex++) { |
| | | if (!NumberUtils.isNumber(vals[vIndex])) { |
| | | throw new ClassCastException("配置的数据有问题,必须配置为30*1000格式"); |
| | | } |
| | | value *= Integer.parseInt(vals[vIndex]); |
| | | } |
| | | return value; |
| | | } |
| | | if(NumberUtils.isNumber(val)){ |
| | | if (NumberUtils.isNumber(val)) { |
| | | return Integer.parseInt(val); |
| | | } |
| | | }catch (Exception e){ |
| | | logger.error("---------------[CommonUtil.multiplicativeStringToInteger]----------------类型转换失败",e); |
| | | } catch (Exception e) { |
| | | logger.error("---------------[CommonUtil.multiplicativeStringToInteger]----------------类型转换失败", e); |
| | | return 0; |
| | | } |
| | | return 0; |
| | |
| | | |
| | | /** |
| | | * 生成六位验证码 |
| | | * |
| | | * @return |
| | | */ |
| | | public static String generateVerificationCode(){ |
| | | public static String generateVerificationCode() { |
| | | Random random = new Random(); |
| | | |
| | | String result=""; |
| | | for(int i=0;i<6;i++){ |
| | | result+=random.nextInt(10); |
| | | String result = ""; |
| | | for (int i = 0; i < 6; i++) { |
| | | result += random.nextInt(10); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | // 手机号码前三后四脱敏 |
| | | public static String mobileEncrypt(String mobile) { |
| | | if (StringUtils.isEmpty(mobile) || (mobile.length() != 11)) { |
| | | return mobile; |
| | | } |
| | | return mobile.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2"); |
| | | } |
| | | |
| | | //身份证前三后四脱敏 |
| | | public static String idEncrypt(String id) { |
| | | if (StringUtils.isEmpty(id) || (id.length() < 8)) { |
| | | return id; |
| | | } |
| | | return id.replaceAll("(?<=\\w{3})\\w(?=\\w{4})", "*"); |
| | | } |
| | | |
| | | |
| | | //效验 |
| | | public static boolean sqlValidate(String str) { |