공통 수정

This commit is contained in:
2025-06-12 14:18:41 +09:00
parent ab7c6e53fe
commit bef9c41f31
2 changed files with 23 additions and 3 deletions

View File

@@ -16,6 +16,7 @@ public class AdminConstants {
public static final String MONGO_DB_COLLECTION_DATA_INIT_HISTORY = "dataInitHistory";
public static final String MONGO_DB_COLLECTION_API_LOG = "apiLog";
public static final String MONGO_DB_COLLECTION_HISTORY_LOG = "historyLog";
public static final String MONGO_DB_COLLECTION_CURRENCY = "currency";
public static final String MONGO_DB_KEY_LOGTIME = "logTime";
public static final String MONGO_DB_KEY_LOGMONTH = "logMonth";

View File

@@ -1,5 +1,7 @@
package com.caliverse.admin.global.common.utils;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.nio.charset.StandardCharsets;
import java.time.*;
import java.time.format.DateTimeFormatter;
@@ -7,14 +9,15 @@ import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.regex.*;
import com.caliverse.admin.domain.entity.AI.AIRole;
import com.caliverse.admin.domain.entity.DiffStatus;
import com.caliverse.admin.global.common.code.CommonCode;
import com.caliverse.admin.global.common.constants.CommonConstants;
import com.caliverse.admin.global.common.exception.RestApiException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.servlet.http.HttpServletRequest;
import org.apache.commons.math3.dfp.DfpField;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.Authentication;
@@ -323,6 +326,20 @@ public class CommonUtils {
}
}
public static JsonNode stringByJsonNode(String data) {
try {
ObjectMapper objectMapper = new ObjectMapper();
return objectMapper.readTree(data);
} catch (JsonProcessingException e) {
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.JSON_PARSE_ERROR.getMessage());
}
}
public static <T> T nodeByValue(JsonNode node, Class<T> valueType) {
ObjectMapper objectMapper = new ObjectMapper();
return objectMapper.convertValue(node, valueType);
}
public static Integer stringToInt(String string) {
try{
return Integer.parseInt(string);
@@ -393,7 +410,9 @@ public class CommonUtils {
}
}
public static Map<String, String> getAIMessage(AIRole role, String message){
return Map.of("role", role.toString(), "content", message);
public static double mathRoundDouble(double value){
return BigDecimal.valueOf(value)
.setScale(2, RoundingMode.HALF_UP)
.doubleValue();
}
}