|
@@ -33,7 +33,6 @@ public class DataUtils {
|
|
|
public static final String PASSWORD_KEY = "835a9bdc-4f9f-4614-a0cc-493a12454156";
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 对称加密
|
|
|
*/
|
|
@@ -179,12 +178,12 @@ public class DataUtils {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public static String[] chars = new String[] { "a", "b", "c", "d", "e", "f",
|
|
|
+ public static String[] chars = new String[]{"a", "b", "c", "d", "e", "f",
|
|
|
"g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
|
|
|
"t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5",
|
|
|
"6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I",
|
|
|
"J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V",
|
|
|
- "W", "X", "Y", "Z" };
|
|
|
+ "W", "X", "Y", "Z"};
|
|
|
|
|
|
public static String generateShortUuid() {
|
|
|
StringBuffer shortBuffer = new StringBuffer();
|
|
@@ -197,7 +196,7 @@ public class DataUtils {
|
|
|
return shortBuffer.toString();
|
|
|
}
|
|
|
|
|
|
- public static <T> List<T> objToList(Object obj, Class<T> cla){
|
|
|
+ public static <T> List<T> objToList(Object obj, Class<T> cla) {
|
|
|
List<T> list = new ArrayList<T>();
|
|
|
if (obj instanceof ArrayList<?>) {
|
|
|
for (Object o : (List<?>) obj) {
|
|
@@ -218,7 +217,7 @@ public class DataUtils {
|
|
|
mdTemp = MessageDigest.getInstance("MD5");
|
|
|
mdTemp.update(utfBytes);
|
|
|
byte[] md5Bytes = mdTemp.digest();
|
|
|
- byte[] by = Base64.getEncoder().encode(md5Bytes);
|
|
|
+ byte[] by = Base64.getEncoder().encode(md5Bytes);
|
|
|
|
|
|
encodeStr = Base64Utils.encodeToString(by);
|
|
|
} catch (Exception e) {
|
|
@@ -226,6 +225,7 @@ public class DataUtils {
|
|
|
}
|
|
|
return encodeStr;
|
|
|
}
|
|
|
+
|
|
|
/*
|
|
|
* 计算 HMAC-SHA1
|
|
|
*/
|
|
@@ -236,7 +236,7 @@ public class DataUtils {
|
|
|
Mac mac = Mac.getInstance("HmacSHA1");
|
|
|
mac.init(signingKey);
|
|
|
byte[] rawHmac = mac.doFinal(data.getBytes());
|
|
|
- byte[] by =Base64.getEncoder().encode(rawHmac);
|
|
|
+ byte[] by = Base64.getEncoder().encode(rawHmac);
|
|
|
result = Base64Utils.encodeToString(by);
|
|
|
} catch (Exception e) {
|
|
|
throw new Error("Failed to generate HMAC : " + e.getMessage());
|
|
@@ -256,7 +256,7 @@ public class DataUtils {
|
|
|
return string;
|
|
|
}
|
|
|
|
|
|
- public static String getMarkDownText(String markdownText){
|
|
|
+ public static String getMarkDownText(String markdownText) {
|
|
|
|
|
|
|
|
|
// 配置解析器(支持表格等扩展)
|
|
@@ -276,10 +276,10 @@ public class DataUtils {
|
|
|
// .replaceAll("\\s+", " ") // 合并多余空格
|
|
|
// .trim();
|
|
|
// 输出普通文本
|
|
|
- return html;
|
|
|
+ return html;
|
|
|
}
|
|
|
|
|
|
- public static String getTextBeforeLastSignal(String input,String signal) {
|
|
|
+ public static String getTextBeforeLastSignal(String input, String signal) {
|
|
|
if (input == null || input.isEmpty()) {
|
|
|
return input; // 处理空字符串或null值
|
|
|
}
|
|
@@ -295,6 +295,7 @@ public class DataUtils {
|
|
|
|
|
|
private static final String[] units = {"", "十", "百", "千", "万", "十", "百", "千", "亿"};
|
|
|
private static final String[] digits = {"零", "一", "二", "三", "四", "五", "六", "七", "八", "九"};
|
|
|
+
|
|
|
public static String numberToChinese(int num) {
|
|
|
if (num == 0) {
|
|
|
return "零";
|
|
@@ -326,4 +327,17 @@ public class DataUtils {
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
+
|
|
|
+ public static String aiAnswerThinkRemove(String content) {
|
|
|
+ String regex = "<think>[\\s\\S]*?</think>";
|
|
|
+ content = content.replaceAll(regex, "");
|
|
|
+ content = content.replaceAll("\n{2,}", "\n");
|
|
|
+ content = content.trim();
|
|
|
+ return content;
|
|
|
+ }
|
|
|
+ public static boolean isValidFormat(String regex,String input) {
|
|
|
+ // 定义正则表达式:4位数字-2位数字-2位数字-"会话"
|
|
|
+ // 编译正则模式并匹配整个输入字符串
|
|
|
+ return Pattern.matches(regex, input);
|
|
|
+ }
|
|
|
}
|