데이터 초기화 히스토리 추가
This commit is contained in:
@@ -0,0 +1,36 @@
|
|||||||
|
package com.caliverse.admin.history.domain;
|
||||||
|
|
||||||
|
import com.caliverse.admin.domain.entity.EInitDataType;
|
||||||
|
import com.caliverse.admin.history.entity.DBType;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class DataInitializeHistoryBase implements historyLog {
|
||||||
|
|
||||||
|
private DBType dbType;
|
||||||
|
private String timestamp;
|
||||||
|
private EInitDataType initDataType;
|
||||||
|
private String tableName;
|
||||||
|
private String tranId;
|
||||||
|
private boolean isSuccess;
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
public DataInitializeHistoryBase(DBType dbType,
|
||||||
|
String timestamp,
|
||||||
|
EInitDataType initDataType,
|
||||||
|
String tableName,
|
||||||
|
String tranId,
|
||||||
|
boolean isSuccess,
|
||||||
|
String message
|
||||||
|
) {
|
||||||
|
this.dbType = dbType;
|
||||||
|
this.timestamp = timestamp;
|
||||||
|
this.initDataType = initDataType;
|
||||||
|
this.tableName = tableName;
|
||||||
|
this.tranId = tranId;
|
||||||
|
this.isSuccess = isSuccess;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.caliverse.admin.history.domain;
|
||||||
|
|
||||||
|
import com.caliverse.admin.domain.entity.EInitDataType;
|
||||||
|
import com.caliverse.admin.dynamodb.domain.doc.DynamoDBDocBase;
|
||||||
|
import com.caliverse.admin.global.common.utils.DateUtils;
|
||||||
|
import com.caliverse.admin.history.entity.DBType;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.springframework.data.mongodb.core.mapping.Document;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Document(collection = "dataInitHistory")
|
||||||
|
public class DynamodbDataInitializeHistory extends DataInitializeHistoryBase {
|
||||||
|
|
||||||
|
private DynamoDBDocBase data;
|
||||||
|
private String key;
|
||||||
|
|
||||||
|
public DynamodbDataInitializeHistory(EInitDataType initDataType,
|
||||||
|
String tableName,
|
||||||
|
String tranId,
|
||||||
|
boolean isSuccess,
|
||||||
|
String message,
|
||||||
|
DynamoDBDocBase data,
|
||||||
|
String key) {
|
||||||
|
super(DBType.DYNAMODB, DateUtils.nowDateTime(), initDataType, tableName, tranId, isSuccess, message);
|
||||||
|
|
||||||
|
this.data = data;
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.caliverse.admin.history.domain;
|
||||||
|
|
||||||
|
import com.caliverse.admin.domain.entity.EInitDataType;
|
||||||
|
import com.caliverse.admin.global.common.utils.DateUtils;
|
||||||
|
import com.caliverse.admin.history.entity.DBType;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.springframework.data.mongodb.core.mapping.Document;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Document(collection = "dataInitHistory")
|
||||||
|
public class MysqlDataInitializeHistory extends DataInitializeHistoryBase {
|
||||||
|
|
||||||
|
private Object data;
|
||||||
|
|
||||||
|
public MysqlDataInitializeHistory(EInitDataType initDataType,
|
||||||
|
String tableName,
|
||||||
|
String TranId,
|
||||||
|
boolean isSuccess,
|
||||||
|
String message,
|
||||||
|
Object data) {
|
||||||
|
super(DBType.MYSQL, DateUtils.nowDateTime(), initDataType, tableName, TranId, isSuccess, message);
|
||||||
|
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,9 @@ import com.caliverse.admin.domain.entity.HISTORYTYPE;
|
|||||||
import com.caliverse.admin.global.common.utils.DateUtils;
|
import com.caliverse.admin.global.common.utils.DateUtils;
|
||||||
import com.caliverse.admin.history.entity.DBType;
|
import com.caliverse.admin.history.entity.DBType;
|
||||||
import com.caliverse.admin.history.entity.EDBOperationType;
|
import com.caliverse.admin.history.entity.EDBOperationType;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.apache.poi.ss.formula.functions.T;
|
import org.apache.poi.ss.formula.functions.T;
|
||||||
@@ -23,5 +26,21 @@ public class MysqlHistoryLogInfo extends HistoryLogInfoBase {
|
|||||||
super(DBType.MYSQL, DateUtils.nowDateTime(), operationType, historytype, tableName, message, tranId, changed, userId, userIP);
|
super(DBType.MYSQL, DateUtils.nowDateTime(), operationType, historytype, tableName, message, tranId, changed, userId, userIP);
|
||||||
|
|
||||||
this.data = data;
|
this.data = data;
|
||||||
|
// this.data = deepCopy(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// private Object deepCopy(Object source) {
|
||||||
|
// try {
|
||||||
|
// if (source == null) return null;
|
||||||
|
//
|
||||||
|
// ObjectMapper mapper = new ObjectMapper()
|
||||||
|
// .setSerializationInclusion(JsonInclude.Include.NON_NULL)
|
||||||
|
// .registerModule(new JavaTimeModule());
|
||||||
|
//
|
||||||
|
// String json = mapper.writeValueAsString(source);
|
||||||
|
// return mapper.readValue(json, Object.class);
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// return source;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.caliverse.admin.history.repository;
|
||||||
|
|
||||||
|
import com.caliverse.admin.history.domain.DynamodbDataInitializeHistory;
|
||||||
|
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||||
|
|
||||||
|
public interface DynamodbDataInitializeHistoryRepository extends MongoRepository<DynamodbDataInitializeHistory, String> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.caliverse.admin.history.repository;
|
||||||
|
|
||||||
|
import com.caliverse.admin.history.domain.MysqlDataInitializeHistory;
|
||||||
|
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||||
|
|
||||||
|
public interface MysqlDataInitializeHistoryRepository extends MongoRepository<MysqlDataInitializeHistory, String> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,135 @@
|
|||||||
|
package com.caliverse.admin.history.service;
|
||||||
|
|
||||||
|
import com.caliverse.admin.domain.entity.EInitDataType;
|
||||||
|
import com.caliverse.admin.domain.request.LogGenericRequest;
|
||||||
|
import com.caliverse.admin.dynamodb.domain.doc.DynamoDBDocBase;
|
||||||
|
import com.caliverse.admin.global.common.constants.AdminConstants;
|
||||||
|
import com.caliverse.admin.history.domain.DynamodbDataInitializeHistory;
|
||||||
|
import com.caliverse.admin.history.domain.MysqlDataInitializeHistory;
|
||||||
|
import com.caliverse.admin.history.repository.DynamodbDataInitializeHistoryRepository;
|
||||||
|
import com.caliverse.admin.history.repository.MysqlDataInitializeHistoryRepository;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.bson.Document;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||||
|
import org.springframework.data.mongodb.core.aggregation.Aggregation;
|
||||||
|
import org.springframework.data.mongodb.core.aggregation.AggregationOperation;
|
||||||
|
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
|
||||||
|
import org.springframework.data.mongodb.core.query.Criteria;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Slf4j
|
||||||
|
public class DataInitializeHistoryService {
|
||||||
|
|
||||||
|
private final MysqlDataInitializeHistoryRepository mysqlDataInitializeHistoryRepository;
|
||||||
|
private final DynamodbDataInitializeHistoryRepository dynamodbDataInitializeHistoryRepository;
|
||||||
|
private final ObjectMapper objectMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
@Qualifier("mongoAdminTemplate")
|
||||||
|
private MongoTemplate mongoTemplate;
|
||||||
|
|
||||||
|
@Value("${amazon.dynamodb.metaTable}")
|
||||||
|
private String dynamodbTableName;
|
||||||
|
|
||||||
|
public <T> List<T> loadHistoryData(LogGenericRequest logGenericRequest, Class<T> class1) {
|
||||||
|
String startTime = logGenericRequest.getStartDt().toString().substring(0, 10);
|
||||||
|
String endTime = logGenericRequest.getEndDt().toString().substring(0, 10);
|
||||||
|
String tranId = logGenericRequest.getTranId();
|
||||||
|
|
||||||
|
Criteria criteria = makeCriteria(startTime, endTime);
|
||||||
|
List<AggregationOperation> operations = new ArrayList<>();
|
||||||
|
|
||||||
|
operations.add(Aggregation.match(criteria));
|
||||||
|
|
||||||
|
if(tranId != null && !tranId.isEmpty()) {
|
||||||
|
operations.add(context ->
|
||||||
|
new Document("$match",
|
||||||
|
new Document(AdminConstants.MONGO_DB_KEY_TRAN_ID, tranId)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 최종 출력 형식
|
||||||
|
operations.add(context ->
|
||||||
|
new Document("$sort",
|
||||||
|
new Document(AdminConstants.MONGO_DB_KEY_TIMESTAMP, -1)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
Aggregation aggregation = Aggregation.newAggregation(operations);
|
||||||
|
log.info("loadHistoryData Query: {}", aggregation);
|
||||||
|
|
||||||
|
AggregationResults<T> results = mongoTemplate.aggregate(aggregation, AdminConstants.MONGO_DB_COLLECTION_DATA_INIT_HISTORY, class1);
|
||||||
|
return results.getMappedResults();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Criteria makeCriteria(String startTime, String endTime) {
|
||||||
|
return new Criteria()
|
||||||
|
.andOperator(
|
||||||
|
Criteria.where(AdminConstants.MONGO_DB_KEY_TIMESTAMP).gte(startTime).lt(endTime)
|
||||||
|
,Criteria.where(AdminConstants.MONGO_DB_KEY_DB_TYPE).is("DYNAMODB")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> void mysqlDataInitHistory(EInitDataType dataType,
|
||||||
|
String tableName,
|
||||||
|
String tranId,
|
||||||
|
boolean isSuccess,
|
||||||
|
String message,
|
||||||
|
T data
|
||||||
|
){
|
||||||
|
|
||||||
|
try {
|
||||||
|
MysqlDataInitializeHistory history = new MysqlDataInitializeHistory(
|
||||||
|
dataType,
|
||||||
|
tableName,
|
||||||
|
tranId,
|
||||||
|
isSuccess,
|
||||||
|
message,
|
||||||
|
data
|
||||||
|
);
|
||||||
|
|
||||||
|
mysqlDataInitializeHistoryRepository.save(history);
|
||||||
|
|
||||||
|
}catch(Exception e){
|
||||||
|
log.error("dataInit history Save Error", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> void dynamodbDataInitHistory(EInitDataType dataType,
|
||||||
|
String tranId,
|
||||||
|
boolean isSuccess,
|
||||||
|
String message,
|
||||||
|
DynamoDBDocBase data,
|
||||||
|
Object key
|
||||||
|
){
|
||||||
|
|
||||||
|
try {
|
||||||
|
DynamodbDataInitializeHistory history = new DynamodbDataInitializeHistory(
|
||||||
|
dataType,
|
||||||
|
dynamodbTableName,
|
||||||
|
tranId,
|
||||||
|
isSuccess,
|
||||||
|
message,
|
||||||
|
data,
|
||||||
|
objectMapper.writeValueAsString(key)
|
||||||
|
);
|
||||||
|
|
||||||
|
dynamodbDataInitializeHistoryRepository.save(history);
|
||||||
|
|
||||||
|
}catch(Exception e){
|
||||||
|
log.error("dataInit history Save Error", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user