233 lines
6.6 KiB
Java
233 lines
6.6 KiB
Java
package com.ruoyi.cms.util;
|
||
|
||
import com.ruoyi.common.utils.StringUtils;
|
||
|
||
import javax.servlet.http.HttpServletRequest;
|
||
import java.util.ArrayList;
|
||
import java.util.Arrays;
|
||
import java.util.List;
|
||
import java.util.Objects;
|
||
import java.util.stream.Collectors;
|
||
|
||
public class StringUtil {
|
||
|
||
/*1101(求职者)、1102(招聘者)、1103(网格员)、1104(内部工作者)*/
|
||
public static final Long COMPANY_ADMIN_ROLE_KEY = 1102L;
|
||
|
||
/************************移动端角色开始***************************/
|
||
/**
|
||
* 移动端-企业用户
|
||
*/
|
||
public static final String IS_COMPANY_USER = "0";
|
||
/**
|
||
* 移动端-求职者
|
||
*/
|
||
public static final String IS_JOB_REQUEST_USER = "1";
|
||
/**
|
||
* 移动端-网格员
|
||
*/
|
||
public static final String IS_GRID_USER = "2";
|
||
/**
|
||
* 移动端-内部工作者
|
||
*/
|
||
public static final String IS_INTERNAL_USER = "3";
|
||
/************************移动端角色结束***************************/
|
||
/**
|
||
* pc端-求职者
|
||
*/
|
||
public static final String SYS_QZZ = "1101";
|
||
/**
|
||
* pc端-企业
|
||
*/
|
||
public static final String SYS_QY = "1102";
|
||
|
||
/**
|
||
* 互联网用户头
|
||
*/
|
||
public static final String USER_KEY="hlw_";
|
||
|
||
/**
|
||
* 岗位互联网
|
||
*/
|
||
public static final String BASE_WW_GW="https://www.xjksly.cn/kashi/job-portal/detail/";
|
||
|
||
/**
|
||
*录用
|
||
*/
|
||
public static final String HIRE_LY="0";
|
||
|
||
/**
|
||
*录用-系统
|
||
*/
|
||
public static final String HIRE_SOURCE_SYSTEM="0";
|
||
/**
|
||
*录用-招聘会
|
||
*/
|
||
public static final String HIRE_SOURCE_ZPH="1";
|
||
/**
|
||
* 标记
|
||
*/
|
||
public static final boolean PATH_TEST_ENV = true;
|
||
/**
|
||
* 测试环境附件地址
|
||
*/
|
||
public static final String PATH_DEV = "http://ks.zhaopinzao8dian.com/file/";
|
||
/**
|
||
* 正式环境环境地址
|
||
*/
|
||
public static final String PATH_PROXY_37 = "http://10.98.80.37/file/";
|
||
/**
|
||
* 互联网
|
||
*/
|
||
public static final String PATH_PROXY_50="https://www.xjksly.cn/file/";
|
||
/**
|
||
* 经办端
|
||
*/
|
||
public static final String PATH_PROXY_146="http://10.98.80.146/file/";
|
||
|
||
/**
|
||
* 身份证规则
|
||
*/
|
||
public static final String SFZ_VALID_REGEX="^[1-9]\\d{5}(18|19|20)\\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$";
|
||
|
||
public static Boolean isEmptyOrNull(String s){
|
||
if(Objects.isNull(s)){return true;}
|
||
return s.isEmpty();
|
||
}
|
||
/**
|
||
* 将逗号分隔的数字字符串转换为List<Integer>
|
||
*/
|
||
public static List<Integer> convertStringToIntegerList(String input) {
|
||
if (isEmptyOrNull(input)) {
|
||
return new ArrayList<>();
|
||
}
|
||
|
||
return Arrays.stream(input.split(",")) // 按逗号分割字符串
|
||
.map(String::trim) // 去除每个部分的前后空格
|
||
.map(Integer::parseInt) // 将字符串转换为Integer
|
||
.collect(Collectors.toList()); // 收集为List
|
||
}
|
||
/**
|
||
* 将逗号分隔的数字字符串转换为List<Integer>
|
||
*/
|
||
public static List<Long> convertStringToLongList(String input) {
|
||
List<Integer> longs = convertStringToIntegerList(input);
|
||
return longs.stream().map(Long::valueOf).collect(Collectors.toList());
|
||
}
|
||
/**
|
||
* 找到List<Integer>中的最大值
|
||
*/
|
||
public static Integer findMaxValue(String input) {
|
||
List<Integer> numbers = convertStringToIntegerList(input);
|
||
if (numbers == null || numbers.isEmpty()) {
|
||
return null;
|
||
}
|
||
|
||
return numbers.stream()
|
||
.mapToInt(Integer::intValue) // 将Integer转换为int
|
||
.max() // 找到最大值
|
||
.orElseThrow(() -> new RuntimeException("列表为空,无法找到最大值")); // 如果列表为空,抛出异常
|
||
}
|
||
|
||
|
||
public static List<String> convertStringToStringList(String input) {
|
||
if (isEmptyOrNull(input)) {
|
||
return new ArrayList<>();
|
||
}
|
||
|
||
return Arrays.stream(input.split(",")) // 按逗号分割字符串
|
||
.map(String::trim) // 去除每个部分的前后空格
|
||
.collect(Collectors.toList()); // 收集为List
|
||
}
|
||
|
||
/**
|
||
* 获取附件地址
|
||
* @return
|
||
*/
|
||
public static String getFilePath(HttpServletRequest request){
|
||
String proxyServer = getProxyServer(request);
|
||
if ("proxy-50".equals(proxyServer)) {
|
||
return PATH_PROXY_50;
|
||
} else if ("proxy-146".equals(proxyServer)) {
|
||
return PATH_PROXY_146;
|
||
}
|
||
return !PATH_TEST_ENV ? PATH_PROXY_37 : PATH_DEV;
|
||
}
|
||
|
||
/**
|
||
* 原方法-不传request
|
||
* @return
|
||
*/
|
||
public static String getFilePath(){
|
||
return !PATH_TEST_ENV ? PATH_PROXY_37 : PATH_DEV;
|
||
}
|
||
|
||
/**
|
||
* 获取nginx地址
|
||
* @param request
|
||
* @return
|
||
*/
|
||
private static String getProxyServer(HttpServletRequest request) {
|
||
if (request == null) {
|
||
return null;
|
||
}
|
||
return request.getHeader("X-Proxy-Server");
|
||
}
|
||
|
||
/**
|
||
* 手机号脱敏
|
||
* @param phone
|
||
* @return
|
||
*/
|
||
public static String desensitizePhone(String phone) {
|
||
if (StringUtils.isEmpty(phone) || phone.length() != 11) {
|
||
return phone;
|
||
}
|
||
return phone.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
|
||
}
|
||
|
||
/**
|
||
* 脱敏逻辑:前4位 + ***+ 后4位
|
||
* @param idCard
|
||
* @return
|
||
*/
|
||
public static String desensitizeIdCard(String idCard) {
|
||
if (StringUtils.isEmpty(idCard)) {
|
||
return null;
|
||
}
|
||
// 处理18位身份证(支持末尾X/x)
|
||
if (idCard.matches("\\d{17}[\\dXx]")) {
|
||
return idCard.replaceAll("(\\d{6})\\d{8}([\\dXx]{4})", "$1********$2");
|
||
}
|
||
// 处理15位身份证
|
||
else if (idCard.matches("\\d{15}")) {
|
||
return idCard.replaceAll("(\\d{6})\\d{6}(\\d{3})", "$1******$2");
|
||
}
|
||
// 非标准格式(如16位、含特殊字符):返回部分脱敏(前4位+****+后2位),避免明文暴露
|
||
else {
|
||
int len = idCard.length();
|
||
if (len >= 6) {
|
||
return idCard.substring(0, 4) + "****" + idCard.substring(len - 2);
|
||
}
|
||
// 长度过短(<6位):直接返回***,避免明文
|
||
return "***";
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 转大写
|
||
* @param str
|
||
* @return
|
||
*/
|
||
public static String toUpperCaseIgnoreBlank(String str) {
|
||
if (str == null) {
|
||
return null;
|
||
}
|
||
String trimmedStr = str.trim();
|
||
if (trimmedStr.isEmpty()) {
|
||
return str;
|
||
}
|
||
return str.toUpperCase();
|
||
}
|
||
}
|