Files
ks/ruoyi-bussiness/src/main/java/com/ruoyi/cms/util/StringUtil.java
2025-11-18 19:29:46 +08:00

100 lines
3.0 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.ruoyi.cms.util;
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 = 1002L;
/**
* 企业用户
*/
public static final String IS_COMPANY_USER = "0";
/**
* 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="http://http://222.80.110.161:11111/kashi/job-portal/detail/:";
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
}
/**
* 脱敏逻辑前4位 + ***+ 后4位
* @param idCard
* @return
*/
public static String desensitizeIdCard(String idCard) {
if (idCard == null || idCard.length() != 18) {
return idCard; // 非标准身份证号不脱敏(或按规则处理)
}
return idCard.substring(0, 4) + "***" + idCard.substring(14);
}
}