비즈니스로그 header, body 처리 수정
This commit is contained in:
@@ -1,36 +1,16 @@
|
||||
package com.caliverse.admin.domain.service;
|
||||
|
||||
import com.caliverse.admin.Indicators.Indicatorsservice.aggregationservice.*;
|
||||
import com.caliverse.admin.Indicators.entity.*;
|
||||
import com.caliverse.admin.domain.entity.Currencys;
|
||||
import com.caliverse.admin.domain.entity.LandInfo;
|
||||
import com.caliverse.admin.domain.entity.ROUTE;
|
||||
import com.caliverse.admin.domain.request.LogGenericRequest;
|
||||
import com.caliverse.admin.domain.response.IndicatorsResponse;
|
||||
import com.caliverse.admin.domain.response.LandResponse;
|
||||
import com.caliverse.admin.domain.response.LogResponse;
|
||||
import com.caliverse.admin.global.common.code.CommonCode;
|
||||
import com.caliverse.admin.global.common.code.ErrorCode;
|
||||
import com.caliverse.admin.global.common.exception.RestApiException;
|
||||
import com.caliverse.admin.global.common.utils.CommonUtils;
|
||||
import com.caliverse.admin.global.common.utils.ExcelUtils;
|
||||
import com.caliverse.admin.logs.Indicatordomain.GenericMongoLog;
|
||||
import com.caliverse.admin.logs.logservice.businesslogservice.BusinessLogGenericService;
|
||||
import com.caliverse.admin.logs.logservice.indicators.IndicatorsDauService;
|
||||
import com.caliverse.admin.logs.logservice.indicators.IndicatorsMcuService;
|
||||
import com.caliverse.admin.logs.logservice.indicators.IndicatorsNruService;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.mongodb.MongoCommandException;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.mongodb.UncategorizedMongoDbException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -72,6 +52,19 @@ public class LogService {
|
||||
log.error("businessLog error", e);
|
||||
}
|
||||
|
||||
logList = logList.stream().map(logData -> {
|
||||
try {
|
||||
var header = logData.getMessage().get("Header");
|
||||
var body = logData.getMessage().get("Body");
|
||||
logData.setHeader((Map<String, Object>) header);
|
||||
logData.setBody((Map<String, Object>) body);
|
||||
return logData;
|
||||
} catch (Exception e) {
|
||||
log.error("Error parsing JSON from message field", e);
|
||||
return logData;
|
||||
}
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
int totalItems = logList.size();
|
||||
|
||||
return LogResponse.builder()
|
||||
|
||||
@@ -47,6 +47,7 @@ public class MongoBusinessLogConfig {
|
||||
String auth = username.isEmpty() ? "" : String.format("%s:%s@",username, encodePassword);
|
||||
String connection;
|
||||
if(activeProfile.equals("local") || activeProfile.equals("dev")) {
|
||||
// connection = String.format("mongodb+srv://%s%s/%s?retryWrites=true&w=majority", auth, businessLogHost, businessLogdb);
|
||||
connection = String.format("mongodb://%s%s/?authSource=%s", auth, businessLogHost, businessLogdb);
|
||||
}else{
|
||||
connection = String.format("mongodb+srv://%s%s/%s?retryWrites=true&w=majority&appName=backoffice-%s", auth, businessLogHost, businessLogdb, activeProfile);
|
||||
|
||||
@@ -1,17 +1,27 @@
|
||||
package com.caliverse.admin.logs.Indicatordomain;
|
||||
|
||||
import com.caliverse.admin.global.common.constants.AdminConstants;
|
||||
import com.caliverse.admin.global.common.utils.CommonUtils;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Document(collection = AdminConstants.MONGO_DB_COLLECTION_LOG)
|
||||
@Getter
|
||||
@Setter
|
||||
public class GenericMongoLog extends MongoLogSearchBase{
|
||||
// private Map<String, Object> parseMessage;
|
||||
private Map<String, Object> header;
|
||||
private Map<String, Object> body;
|
||||
private String message;
|
||||
|
||||
public Map getMessage() {
|
||||
if (message == null || message.isEmpty()) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
return CommonUtils.stringByObject(message, Map.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -58,41 +58,6 @@ public class BusinessLogGenericService extends BusinessLogServiceBase {
|
||||
Criteria criteria = makeCriteria(startTime, endTime);
|
||||
List<AggregationOperation> operations = setDefaultOperation(criteria);
|
||||
|
||||
if(activeProfile.equals("local") || activeProfile.equals("dev")) {
|
||||
//message json parsing
|
||||
operations.add(context ->
|
||||
new Document("$addFields",
|
||||
new Document("parseMessage",
|
||||
new Document("$function",
|
||||
new Document("body", "function(jsonString) { try { return JSON.parse(jsonString); } catch(e) { return {}; } }")
|
||||
.append("args", Arrays.asList("$message"))
|
||||
.append("lang", "js")
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}else {
|
||||
|
||||
operations.add(context ->
|
||||
new Document("$addFields",
|
||||
new Document("parseMessage",
|
||||
new Document("$convert",
|
||||
new Document("input", "$message")
|
||||
.append("to", "object")
|
||||
.append("onError", new Document())
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
operations.add(context ->
|
||||
new Document("$addFields",
|
||||
new Document("header","$parseMessage.Header")
|
||||
.append("body","$parseMessage.Body")
|
||||
)
|
||||
);
|
||||
|
||||
if(logAction != null && !logAction.equals(LogAction.None)) {
|
||||
operations.add(context ->
|
||||
new Document("$match",
|
||||
|
||||
Reference in New Issue
Block a user