유저생성 정보
로그인 정보 batch 추가
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package com.caliverse.admin.logs.Indicatordomain;
|
||||
|
||||
import com.caliverse.admin.global.common.constants.AdminConstants;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document(collection = AdminConstants.MONGO_DB_COLLECTION_LOG)
|
||||
@Getter
|
||||
@Setter
|
||||
public class UserCreateMongoLog extends MongoLogSearchBase{
|
||||
private String createdTime;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.caliverse.admin.logs.Indicatordomain;
|
||||
|
||||
import com.caliverse.admin.global.common.constants.AdminConstants;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Document(collection = AdminConstants.MONGO_DB_COLLECTION_LOG)
|
||||
@Getter
|
||||
@Setter
|
||||
public class UserLoginMongoLog extends MongoLogSearchBase{
|
||||
private List<Map<String, Object>> sessions;
|
||||
private String firstLoginTime;
|
||||
private String lastLogoutTime;
|
||||
private Integer loginCount;
|
||||
private Double totalPlayTime;
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
||||
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.AggregationOptions;
|
||||
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
|
||||
import org.springframework.data.mongodb.core.query.Criteria;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -119,26 +120,14 @@ public class BusinessLogGenericService extends BusinessLogServiceBase {
|
||||
)
|
||||
);
|
||||
|
||||
Aggregation aggregation = Aggregation.newAggregation(operations);
|
||||
AggregationOptions options = AggregationOptions.builder()
|
||||
.allowDiskUse(true)
|
||||
.build();
|
||||
Aggregation aggregation = Aggregation.newAggregation(operations).withOptions(options);
|
||||
log.info("loadBusinessLogData Generic Query: {}", aggregation);
|
||||
// try {
|
||||
AggregationResults<T> results = getMongoTemplate()
|
||||
.aggregate(aggregation, AdminConstants.MONGO_DB_COLLECTION_LOG, class1);
|
||||
return results.getMappedResults();
|
||||
// }catch(Exception e){
|
||||
// log.error("BusinessLog query error", e);
|
||||
// return null;
|
||||
// }
|
||||
|
||||
|
||||
// AggregationResults<Document> results = getMongoTemplate().aggregate(aggregation, AdminConstants.MONGO_DB_COLLECTION_LOG, Document.class);
|
||||
//
|
||||
// List<Map<String, Object>> logMaps = new ArrayList<>();
|
||||
// for (Document doc : results.getMappedResults()) {
|
||||
// logMaps.add(flattenDocument(doc));
|
||||
// }
|
||||
//
|
||||
// return logMaps;
|
||||
AggregationResults<T> results = getMongoTemplate()
|
||||
.aggregate(aggregation, AdminConstants.MONGO_DB_COLLECTION_LOG, class1);
|
||||
return results.getMappedResults();
|
||||
}
|
||||
|
||||
protected Criteria makeCriteria(String startTime, String endTime) {
|
||||
|
||||
@@ -26,6 +26,38 @@ public class BusinessLogPlayTimeService extends BusinessLogServiceBase {
|
||||
Criteria criteria = makeCriteria(startTime, endTime);
|
||||
List<AggregationOperation> operations = setDefaultOperation(criteria);
|
||||
|
||||
operations.add(context ->
|
||||
new Document("$addFields",
|
||||
new Document(AdminConstants.MONGO_DB_KEY_LOGIN_TIME,
|
||||
new Document("$let",
|
||||
new Document("vars",
|
||||
new Document("found",
|
||||
new Document("$regexFind",
|
||||
new Document("input", "$message")
|
||||
.append("regex", "\"LoginTime\":\"([^\"]+)\"")
|
||||
)
|
||||
)
|
||||
).append("in",
|
||||
new Document("$arrayElemAt", Arrays.asList("$$found.captures", 0))
|
||||
)
|
||||
)
|
||||
).append(AdminConstants.MONGO_DB_KEY_LOGOUT_TIME,
|
||||
new Document("$let",
|
||||
new Document("vars",
|
||||
new Document("found",
|
||||
new Document("$regexFind",
|
||||
new Document("input", "$message")
|
||||
.append("regex", "\"LogoutTime\":\"([^\"]+)\"")
|
||||
)
|
||||
)
|
||||
).append("in",
|
||||
new Document("$arrayElemAt", Arrays.asList("$$found.captures", 0))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
operations.add(Aggregation.match(Criteria.where(AdminConstants.MONGO_DB_KEY_ACCOUNT_ID).ne(null)));
|
||||
|
||||
//3000이라는 값이 들어있는 경우가 있어서 예외처리
|
||||
|
||||
@@ -55,18 +55,6 @@ public abstract class BusinessLogServiceBase implements IBusinessLogService {
|
||||
.append("regex", "\"AccountId\":\"([^\"]+)\"")
|
||||
)
|
||||
)
|
||||
.append(AdminConstants.MONGO_DB_KEY_LOGIN_TIME,
|
||||
new Document("$regexFind",
|
||||
new Document("input", "$message")
|
||||
.append("regex", "\"LoginTime\":\"([^\"]+)\"")
|
||||
)
|
||||
)
|
||||
.append(AdminConstants.MONGO_DB_KEY_LOGOUT_TIME,
|
||||
new Document("$regexFind",
|
||||
new Document("input", "$message")
|
||||
.append("regex", "\"LogoutTime\":\"([^\"]+)\"")
|
||||
)
|
||||
)
|
||||
.append(AdminConstants.MONGO_DB_KEY_TRAN_ID,
|
||||
new Document("$regexFind",
|
||||
new Document("input", "$message")
|
||||
@@ -139,26 +127,6 @@ public abstract class BusinessLogServiceBase implements IBusinessLogService {
|
||||
)
|
||||
)
|
||||
)
|
||||
.append(AdminConstants.MONGO_DB_KEY_LOGIN_TIME,
|
||||
new Document()
|
||||
.append("$ifNull", List.of(
|
||||
new Document("$toString",
|
||||
new Document("$arrayElemAt", List.of("$loginTime.captures", 0))
|
||||
),
|
||||
""
|
||||
)
|
||||
)
|
||||
)
|
||||
.append(AdminConstants.MONGO_DB_KEY_LOGOUT_TIME,
|
||||
new Document()
|
||||
.append("$ifNull", List.of(
|
||||
new Document("$toString",
|
||||
new Document("$arrayElemAt", List.of("$logoutTime.captures", 0))
|
||||
),
|
||||
""
|
||||
)
|
||||
)
|
||||
)
|
||||
.append(AdminConstants.MONGO_DB_KEY_TRAN_ID,
|
||||
new Document()
|
||||
.append("$ifNull", List.of(
|
||||
@@ -229,8 +197,6 @@ public abstract class BusinessLogServiceBase implements IBusinessLogService {
|
||||
.and(AdminConstants.MONGO_DB_KEY_USER_GUID).as(AdminConstants.MONGO_DB_KEY_USER_GUID)
|
||||
.and(AdminConstants.MONGO_DB_KEY_USER_NICKNAME).as(AdminConstants.MONGO_DB_KEY_USER_NICKNAME)
|
||||
.and(AdminConstants.MONGO_DB_KEY_ACCOUNT_ID).as(AdminConstants.MONGO_DB_KEY_ACCOUNT_ID)
|
||||
.and(AdminConstants.MONGO_DB_KEY_LOGIN_TIME).as(AdminConstants.MONGO_DB_KEY_LOGIN_TIME)
|
||||
.and(AdminConstants.MONGO_DB_KEY_LOGOUT_TIME).as(AdminConstants.MONGO_DB_KEY_LOGOUT_TIME)
|
||||
.and(AdminConstants.MONGO_DB_KEY_TRAN_ID).as(AdminConstants.MONGO_DB_KEY_TRAN_ID)
|
||||
.and(AdminConstants.MONGO_DB_KEY_ACTION).as(AdminConstants.MONGO_DB_KEY_ACTION)
|
||||
.and(AdminConstants.MONGO_DB_KEY_DOMAIN).as(AdminConstants.MONGO_DB_KEY_DOMAIN)
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
package com.caliverse.admin.logs.logservice.businesslogservice;
|
||||
|
||||
import com.caliverse.admin.global.common.constants.AdminConstants;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bson.Document;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.data.mongodb.core.aggregation.*;
|
||||
import org.springframework.data.mongodb.core.query.Criteria;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class BusinessLogUserCreateService extends BusinessLogServiceBase {
|
||||
|
||||
|
||||
public BusinessLogUserCreateService(@Qualifier("mongoBusinessLogTemplate") MongoTemplate mongoTemplate) {
|
||||
super(mongoTemplate);
|
||||
}
|
||||
|
||||
|
||||
public <T> List<T> loadBusinessLogData(String startTime, String endTime, Class<T> class1) {
|
||||
|
||||
Criteria criteria = makeCriteria(startTime, endTime);
|
||||
List<AggregationOperation> operations = setDefaultOperation(criteria);
|
||||
|
||||
operations.add(context ->
|
||||
new Document("$addFields",
|
||||
new Document(AdminConstants.MONGO_DB_KEY_CREATE_TIME,
|
||||
new Document("$let",
|
||||
new Document("vars",
|
||||
new Document("found",
|
||||
new Document("$regexFind",
|
||||
new Document("input", "$message")
|
||||
.append("regex", "\"CreatedTime\":\"([^\"]+)\"")
|
||||
)
|
||||
)
|
||||
).append("in",
|
||||
new Document("$arrayElemAt", Arrays.asList("$$found.captures", 0))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
operations.add(context ->
|
||||
new Document("$group",
|
||||
new Document("_id",
|
||||
new Document(AdminConstants.MONGO_DB_KEY_LOGDAY, "$logDay")
|
||||
.append(AdminConstants.MONGO_DB_KEY_ACCOUNT_ID, "$accountId")
|
||||
.append(AdminConstants.MONGO_DB_KEY_TRAN_ID, "$tranId")
|
||||
)
|
||||
.append(AdminConstants.MONGO_DB_KEY_LOGDAY, new Document("$first", "$logDay"))
|
||||
.append(AdminConstants.MONGO_DB_KEY_ACCOUNT_ID, new Document("$first", "$accountId"))
|
||||
.append(AdminConstants.MONGO_DB_KEY_USER_GUID, new Document("$first", "$userGuid"))
|
||||
.append(AdminConstants.MONGO_DB_KEY_USER_NICKNAME, new Document("$max", "$userNickname"))
|
||||
.append(AdminConstants.MONGO_DB_KEY_CREATE_TIME, new Document("$max", "$createdTime"))
|
||||
)
|
||||
);
|
||||
|
||||
// 최종 출력 형식
|
||||
operations.add(context ->
|
||||
new Document("$project",
|
||||
new Document("_id", 0)
|
||||
.append(AdminConstants.MONGO_DB_KEY_LOGDAY, "$_id.logDay")
|
||||
.append(AdminConstants.MONGO_DB_KEY_ACCOUNT_ID, "$_id.accountId")
|
||||
.append(AdminConstants.MONGO_DB_KEY_USER_GUID, "$userGuid")
|
||||
.append(AdminConstants.MONGO_DB_KEY_USER_NICKNAME, "$nickname")
|
||||
.append(AdminConstants.MONGO_DB_KEY_CREATE_TIME, "$createdTime")
|
||||
)
|
||||
);
|
||||
|
||||
Aggregation aggregation = Aggregation.newAggregation(operations);
|
||||
log.info("loadBusinessLogData UserCreate Query: {}", aggregation);
|
||||
AggregationResults<T> results = getMongoTemplate().aggregate(aggregation, AdminConstants.MONGO_DB_COLLECTION_LOG, class1);
|
||||
|
||||
return results.getMappedResults();
|
||||
}
|
||||
|
||||
protected Criteria makeCriteria(String startTime, String endTime) {
|
||||
return new Criteria()
|
||||
.andOperator(
|
||||
Criteria.where(AdminConstants.MONGO_DB_KEY_LOGTIME).gte(startTime)
|
||||
,Criteria.where(AdminConstants.MONGO_DB_KEY_LOGTIME).lt(endTime)
|
||||
, new Criteria()
|
||||
.orOperator(
|
||||
Criteria.where(AdminConstants.MONGO_DB_KEY_MESSAGE).regex(AdminConstants.REGEX_MSG_CHARACTER_CREATE)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,263 @@
|
||||
package com.caliverse.admin.logs.logservice.businesslogservice;
|
||||
|
||||
import com.caliverse.admin.global.common.constants.AdminConstants;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bson.Document;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.data.mongodb.core.aggregation.*;
|
||||
import org.springframework.data.mongodb.core.query.Criteria;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class BusinessLogUserLoginMultiService extends BusinessLogServiceBase {
|
||||
|
||||
|
||||
public BusinessLogUserLoginMultiService(@Qualifier("mongoBusinessLogTemplate") MongoTemplate mongoTemplate) {
|
||||
super(mongoTemplate);
|
||||
}
|
||||
|
||||
|
||||
public <T> List<T> loadBusinessLogData(String startTime, String endTime, Class<T> class1) {
|
||||
|
||||
Criteria criteria = makeCriteria(startTime, endTime);
|
||||
List<AggregationOperation> operations = setDefaultOperation(criteria);
|
||||
|
||||
operations.add(context ->
|
||||
new Document("$addFields",
|
||||
new Document(AdminConstants.MONGO_DB_KEY_LOGIN_TIME,
|
||||
new Document("$let",
|
||||
new Document("vars",
|
||||
new Document("found",
|
||||
new Document("$regexFind",
|
||||
new Document("input", "$message")
|
||||
.append("regex", "\"LoginTime\":\"([^\"]+)\"")
|
||||
)
|
||||
)
|
||||
).append("in",
|
||||
new Document("$arrayElemAt", Arrays.asList("$$found.captures", 0))
|
||||
)
|
||||
)
|
||||
).append(AdminConstants.MONGO_DB_KEY_LOGOUT_TIME,
|
||||
new Document("$let",
|
||||
new Document("vars",
|
||||
new Document("found",
|
||||
new Document("$regexFind",
|
||||
new Document("input", "$message")
|
||||
.append("regex", "\"LogoutTime\":\"([^\"]+)\"")
|
||||
)
|
||||
)
|
||||
).append("in",
|
||||
new Document("$arrayElemAt", Arrays.asList("$$found.captures", 0))
|
||||
)
|
||||
)
|
||||
).append(AdminConstants.MONGO_DB_KEY_IP,
|
||||
new Document("$let",
|
||||
new Document("vars",
|
||||
new Document("found",
|
||||
new Document("$regexFind",
|
||||
new Document("input", "$message")
|
||||
.append("regex", "\"Ip\":\"([^\"]+)\"")
|
||||
)
|
||||
)
|
||||
).append("in",
|
||||
new Document("$arrayElemAt", Arrays.asList("$$found.captures", 0))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
operations.add(context ->
|
||||
new Document("$match",
|
||||
new Document("$expr",
|
||||
new Document("$and", Arrays.asList(
|
||||
new Document("$not",
|
||||
new Document("$regexMatch",
|
||||
new Document("input", new Document("$toString", "$loginTime"))
|
||||
.append("regex", "^(0001|1970|3000)")
|
||||
)
|
||||
),
|
||||
new Document("$not",
|
||||
new Document("$regexMatch",
|
||||
new Document("input", new Document("$toString", "$serverType"))
|
||||
.append("regex", "^Login")
|
||||
)
|
||||
)
|
||||
))
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
SortOperation sortOperation = Aggregation.sort(
|
||||
Sort.by(
|
||||
Sort.Order.asc(AdminConstants.MONGO_DB_KEY_ACCOUNT_ID),
|
||||
Sort.Order.asc(AdminConstants.MONGO_DB_KEY_LOGTIME)
|
||||
)
|
||||
);
|
||||
operations.add(sortOperation);
|
||||
|
||||
operations.add(context ->
|
||||
new Document("$group",
|
||||
new Document("_id",
|
||||
new Document(AdminConstants.MONGO_DB_KEY_ACCOUNT_ID, "$accountId")
|
||||
.append(AdminConstants.MONGO_DB_KEY_LOGDAY, "$logDay")
|
||||
)
|
||||
.append(AdminConstants.MONGO_DB_KEY_LOGDAY, new Document("$first", "$logDay"))
|
||||
.append(AdminConstants.MONGO_DB_KEY_ACCOUNT_ID, new Document("$first", "$accountId"))
|
||||
.append(AdminConstants.MONGO_DB_KEY_USER_GUID, new Document("$first", "$userGuid"))
|
||||
.append(AdminConstants.MONGO_DB_KEY_USER_NICKNAME, new Document("$max", "$userNickname"))
|
||||
.append("actions", new Document("$push",
|
||||
new Document(AdminConstants.MONGO_DB_KEY_ACTION, "$action")
|
||||
.append(AdminConstants.MONGO_DB_KEY_SERVER_TYPE, "$serverType")
|
||||
.append(AdminConstants.MONGO_DB_KEY_LOGTIME, "$logTime")
|
||||
.append(AdminConstants.MONGO_DB_KEY_LOGIN_TIME, "$loginTime")
|
||||
.append(AdminConstants.MONGO_DB_KEY_LOGOUT_TIME, "$logoutTime")
|
||||
.append(AdminConstants.MONGO_DB_KEY_IP, "$ip")
|
||||
.append(AdminConstants.MONGO_DB_KEY_LANGUAGE_TYPE, "$languageType")
|
||||
))
|
||||
)
|
||||
);
|
||||
|
||||
operations.add(context ->
|
||||
new Document("$addFields",
|
||||
new Document("sessions",
|
||||
new Document("$reduce",
|
||||
new Document("input", "$actions")
|
||||
.append("initialValue",
|
||||
new Document("sessions", Arrays.asList())
|
||||
.append("currentLogin", null)
|
||||
.append("isProcessing", false)
|
||||
)
|
||||
.append("in",
|
||||
new Document("$let",
|
||||
new Document("vars",
|
||||
new Document("currentAction", "$$this")
|
||||
.append("state", "$$value")
|
||||
)
|
||||
.append("in",
|
||||
new Document("$cond", Arrays.asList(
|
||||
new Document("$eq", Arrays.asList("$$currentAction.action", "LoginToGame")),
|
||||
new Document("sessions", "$$state.sessions")
|
||||
.append("currentLogin", "$$currentAction")
|
||||
.append("isProcessing", true),
|
||||
new Document("$cond", Arrays.asList(
|
||||
"$$state.isProcessing",
|
||||
new Document("sessions",
|
||||
new Document("$concatArrays", Arrays.asList(
|
||||
"$$state.sessions",
|
||||
Arrays.asList(
|
||||
new Document(AdminConstants.MONGO_DB_KEY_LOGIN_TIME, "$$state.currentLogin.loginTime")
|
||||
.append(AdminConstants.MONGO_DB_KEY_LOGOUT_TIME, "$$currentAction.logoutTime")
|
||||
.append(AdminConstants.MONGO_DB_KEY_SERVER_TYPE, "$$state.currentLogin.serverType")
|
||||
.append(AdminConstants.MONGO_DB_KEY_IP, "$$state.currentLogin.ip")
|
||||
.append(AdminConstants.MONGO_DB_KEY_LANGUAGE_TYPE, "$$state.currentLogin.languageType")
|
||||
.append(AdminConstants.MONGO_DB_COLLECTION_PLAYTIME,
|
||||
new Document("$divide", Arrays.asList(
|
||||
new Document("$subtract", Arrays.asList(
|
||||
new Document("$toDate", "$$currentAction.logoutTime"),
|
||||
new Document("$toDate", "$$state.currentLogin.loginTime")
|
||||
)),
|
||||
1000
|
||||
))
|
||||
)
|
||||
)
|
||||
))
|
||||
)
|
||||
.append("currentLogin", null)
|
||||
.append("isProcessing", false),
|
||||
new Document("sessions",
|
||||
new Document("$concatArrays", Arrays.asList(
|
||||
"$$state.sessions",
|
||||
Arrays.asList(
|
||||
new Document(AdminConstants.MONGO_DB_KEY_LOGIN_TIME, "$$currentAction.loginTime")
|
||||
.append(AdminConstants.MONGO_DB_KEY_LOGOUT_TIME, "$$currentAction.logoutTime")
|
||||
.append(AdminConstants.MONGO_DB_KEY_SERVER_TYPE, "$$currentAction.serverType")
|
||||
.append(AdminConstants.MONGO_DB_KEY_IP, "$$currentAction.ip")
|
||||
.append(AdminConstants.MONGO_DB_KEY_LANGUAGE_TYPE, "$$currentAction.languageType")
|
||||
.append(AdminConstants.MONGO_DB_COLLECTION_PLAYTIME,
|
||||
new Document("$divide", Arrays.asList(
|
||||
new Document("$subtract", Arrays.asList(
|
||||
new Document("$toDate", "$$currentAction.logoutTime"),
|
||||
new Document("$toDate", "$$currentAction.loginTime")
|
||||
)),
|
||||
1000
|
||||
))
|
||||
)
|
||||
)
|
||||
))
|
||||
)
|
||||
.append("currentLogin", null)
|
||||
.append("isProcessing", false)
|
||||
))
|
||||
))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
));
|
||||
|
||||
operations.add(context ->
|
||||
new Document("$addFields",
|
||||
new Document("sessions", "$sessions.sessions")
|
||||
.append("totalPlayTime", new Document("$sum", "$sessions.sessions.playtime"))
|
||||
.append("firstLoginTime", new Document("$min", "$sessions.sessions.loginTime"))
|
||||
.append("lastLogoutTime", new Document("$max", "$sessions.sessions.logoutTime"))
|
||||
.append("loginCount", new Document("$size", "$sessions.sessions"))
|
||||
)
|
||||
);
|
||||
|
||||
operations.add(context ->
|
||||
new Document("$match",
|
||||
new Document("$expr",
|
||||
new Document("$gt", Arrays.asList(
|
||||
new Document("$size", "$sessions"), 0
|
||||
))
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// 최종 출력 형식
|
||||
operations.add(context ->
|
||||
new Document("$project",
|
||||
new Document(AdminConstants.MONGO_DB_KEY_LOGDAY, "$logDay")
|
||||
.append(AdminConstants.MONGO_DB_KEY_ACCOUNT_ID, "$accountId")
|
||||
.append(AdminConstants.MONGO_DB_KEY_USER_GUID, 1)
|
||||
.append(AdminConstants.MONGO_DB_KEY_USER_NICKNAME, 1)
|
||||
.append("sessions", 1)
|
||||
.append("firstLoginTime", 1)
|
||||
.append("lastLogoutTime", 1)
|
||||
.append("loginCount", 1)
|
||||
.append("totalPlayTime", 1)
|
||||
.append("_id", 0)
|
||||
)
|
||||
);
|
||||
|
||||
Aggregation aggregation = Aggregation.newAggregation(operations);
|
||||
log.info("loadBusinessLogData UserLoginMulti Query: {}", aggregation);
|
||||
AggregationResults<T> results = getMongoTemplate().aggregate(aggregation, AdminConstants.MONGO_DB_COLLECTION_LOG, class1);
|
||||
|
||||
return results.getMappedResults();
|
||||
}
|
||||
|
||||
protected Criteria makeCriteria(String startTime, String endTime) {
|
||||
return new Criteria()
|
||||
.andOperator(
|
||||
Criteria.where(AdminConstants.MONGO_DB_KEY_LOGTIME).gte(startTime)
|
||||
,Criteria.where(AdminConstants.MONGO_DB_KEY_LOGTIME).lt(endTime)
|
||||
, new Criteria()
|
||||
.orOperator(
|
||||
Criteria.where(AdminConstants.MONGO_DB_KEY_MESSAGE).regex(AdminConstants.REGEX_MSG_USER_LOGOUT)
|
||||
,Criteria.where(AdminConstants.MONGO_DB_KEY_MESSAGE).regex(AdminConstants.REGEX_MSG_LOGIN_TO_GAME)
|
||||
)
|
||||
// AccountId가 빈값인 경우 제외
|
||||
, Criteria.where(AdminConstants.MONGO_DB_KEY_MESSAGE).not().regex("\"AccountId\"\\s*:\\s*\"\"")
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
package com.caliverse.admin.logs.logservice.businesslogservice;
|
||||
|
||||
import com.caliverse.admin.global.common.constants.AdminConstants;
|
||||
import com.mongodb.BasicDBObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bson.Document;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.data.mongodb.core.aggregation.*;
|
||||
import org.springframework.data.mongodb.core.query.Criteria;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class BusinessLogUserLoginService extends BusinessLogServiceBase {
|
||||
|
||||
|
||||
public BusinessLogUserLoginService(@Qualifier("mongoBusinessLogTemplate") MongoTemplate mongoTemplate) {
|
||||
super(mongoTemplate);
|
||||
}
|
||||
|
||||
|
||||
public <T> List<T> loadBusinessLogData(String startTime, String endTime, Class<T> class1) {
|
||||
|
||||
Criteria criteria = makeCriteria(startTime, endTime);
|
||||
List<AggregationOperation> operations = setDefaultOperation(criteria);
|
||||
|
||||
operations.add(context ->
|
||||
new Document("$addFields",
|
||||
new Document(AdminConstants.MONGO_DB_KEY_LOGIN_TIME,
|
||||
new Document("$let",
|
||||
new Document("vars",
|
||||
new Document("found",
|
||||
new Document("$regexFind",
|
||||
new Document("input", "$message")
|
||||
.append("regex", "\"LoginTime\":\"([^\"]+)\"")
|
||||
)
|
||||
)
|
||||
).append("in",
|
||||
new Document("$arrayElemAt", Arrays.asList("$$found.captures", 0))
|
||||
)
|
||||
)
|
||||
).append(AdminConstants.MONGO_DB_KEY_LOGOUT_TIME,
|
||||
new Document("$let",
|
||||
new Document("vars",
|
||||
new Document("found",
|
||||
new Document("$regexFind",
|
||||
new Document("input", "$message")
|
||||
.append("regex", "\"LogoutTime\":\"([^\"]+)\"")
|
||||
)
|
||||
)
|
||||
).append("in",
|
||||
new Document("$arrayElemAt", Arrays.asList("$$found.captures", 0))
|
||||
)
|
||||
)
|
||||
).append(AdminConstants.MONGO_DB_KEY_IP,
|
||||
new Document("$let",
|
||||
new Document("vars",
|
||||
new Document("found",
|
||||
new Document("$regexFind",
|
||||
new Document("input", "$message")
|
||||
.append("regex", "\"Ip\":\"([^\"]+)\"")
|
||||
)
|
||||
)
|
||||
).append("in",
|
||||
new Document("$arrayElemAt", Arrays.asList("$$found.captures", 0))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
operations.add(context ->
|
||||
new Document("$match",
|
||||
new Document("$expr",
|
||||
new Document("$and", Arrays.asList(
|
||||
new Document("$not",
|
||||
new Document("$regexMatch",
|
||||
new Document("input", new Document("$toString", "$loginTime"))
|
||||
.append("regex", "^(0001|1970|3000)")
|
||||
)
|
||||
),
|
||||
new Document("$not",
|
||||
new Document("$regexMatch",
|
||||
new Document("input", new Document("$toString", "$serverType"))
|
||||
.append("regex", "^Login")
|
||||
)
|
||||
)
|
||||
))
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
operations.add(context ->
|
||||
new Document("$addFields",
|
||||
new Document("loginTimeDate",
|
||||
new Document("$dateFromString",
|
||||
new Document("dateString",
|
||||
new Document("$substr", Arrays.asList("$loginTime", 0, 19))
|
||||
).append("format", "%Y-%m-%dT%H:%M:%S")
|
||||
)
|
||||
).append("logoutTimeDate",
|
||||
new Document("$dateFromString",
|
||||
new Document("dateString",
|
||||
new Document("$substr", Arrays.asList("$logoutTime", 0, 19))
|
||||
).append("format", "%Y-%m-%dT%H:%M:%S")
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
operations.add(context ->
|
||||
new Document("$addFields",
|
||||
new Document("playTimeInSeconds",
|
||||
new Document("$divide", Arrays.asList(
|
||||
new Document("$subtract", Arrays.asList(
|
||||
new Document("$toDate", "$logoutTimeDate"),
|
||||
new Document("$toDate", "$loginTimeDate")
|
||||
))
|
||||
, 1000
|
||||
))
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
SortOperation sortOperation = Aggregation.sort(
|
||||
Sort.by(
|
||||
Sort.Order.asc(AdminConstants.MONGO_DB_KEY_ACCOUNT_ID),
|
||||
Sort.Order.asc(AdminConstants.MONGO_DB_KEY_LOGTIME)
|
||||
)
|
||||
);
|
||||
operations.add(sortOperation);
|
||||
|
||||
operations.add(context ->
|
||||
new Document("$group",
|
||||
new Document("_id",
|
||||
new Document(AdminConstants.MONGO_DB_KEY_LOGDAY, "$logDay")
|
||||
.append(AdminConstants.MONGO_DB_KEY_ACCOUNT_ID, "$accountId")
|
||||
)
|
||||
.append(AdminConstants.MONGO_DB_KEY_LOGDAY, new Document("$first", "$logDay"))
|
||||
.append(AdminConstants.MONGO_DB_KEY_ACCOUNT_ID, new Document("$first", "$accountId"))
|
||||
.append(AdminConstants.MONGO_DB_KEY_USER_GUID, new Document("$first", "$userGuid"))
|
||||
.append(AdminConstants.MONGO_DB_KEY_USER_NICKNAME, new Document("$max", "$userNickname"))
|
||||
.append("sessions", new Document("$push",
|
||||
new Document(AdminConstants.MONGO_DB_KEY_ACTION, "$action")
|
||||
.append(AdminConstants.MONGO_DB_KEY_SERVER_TYPE, "$serverType")
|
||||
.append(AdminConstants.MONGO_DB_KEY_LOGIN_TIME, "$loginTimeDate")
|
||||
.append(AdminConstants.MONGO_DB_KEY_LOGOUT_TIME, "$logoutTimeDate")
|
||||
.append(AdminConstants.MONGO_DB_COLLECTION_PLAYTIME, "$playTimeInSeconds")
|
||||
.append(AdminConstants.MONGO_DB_KEY_IP, "$ip")
|
||||
.append(AdminConstants.MONGO_DB_KEY_LANGUAGE_TYPE, "$languageType")
|
||||
))
|
||||
.append("firstLoginTime", new Document("$min", "$loginTimeDate"))
|
||||
.append("lastLogoutTime", new Document("$max", "$logoutTimeDate"))
|
||||
.append("loginCount", new Document("$sum", 1))
|
||||
.append("totalPlayTime", new Document("$sum", "$playTimeInSeconds"))
|
||||
)
|
||||
);
|
||||
|
||||
// 최종 출력 형식
|
||||
operations.add(context ->
|
||||
new Document("$project",
|
||||
new Document(AdminConstants.MONGO_DB_KEY_LOGDAY, "$logDay")
|
||||
.append(AdminConstants.MONGO_DB_KEY_ACCOUNT_ID, "$accountId")
|
||||
.append(AdminConstants.MONGO_DB_KEY_USER_GUID, 1)
|
||||
.append(AdminConstants.MONGO_DB_KEY_USER_NICKNAME, 1)
|
||||
.append("sessions", 1)
|
||||
.append("firstLoginTime", 1)
|
||||
.append("lastLogoutTime", 1)
|
||||
.append("loginCount", 1)
|
||||
.append("totalPlayTime", 1)
|
||||
.append("_id", 0)
|
||||
)
|
||||
);
|
||||
|
||||
Aggregation aggregation = Aggregation.newAggregation(operations);
|
||||
log.info("loadBusinessLogData UserLogin Query: {}", aggregation);
|
||||
AggregationResults<T> results = getMongoTemplate().aggregate(aggregation, AdminConstants.MONGO_DB_COLLECTION_LOG, class1);
|
||||
|
||||
return results.getMappedResults();
|
||||
}
|
||||
|
||||
protected Criteria makeCriteria(String startTime, String endTime) {
|
||||
return new Criteria()
|
||||
.andOperator(
|
||||
Criteria.where(AdminConstants.MONGO_DB_KEY_LOGTIME).gte(startTime)
|
||||
,Criteria.where(AdminConstants.MONGO_DB_KEY_LOGTIME).lt(endTime)
|
||||
, new Criteria()
|
||||
.orOperator(
|
||||
Criteria.where(AdminConstants.MONGO_DB_KEY_MESSAGE).regex(AdminConstants.REGEX_MSG_USER_LOGOUT)
|
||||
)
|
||||
// AccountId가 빈값인 경우 제외
|
||||
, Criteria.where(AdminConstants.MONGO_DB_KEY_MESSAGE).not().regex("\"AccountId\"\\s*:\\s*\"\"")
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.caliverse.admin.logs.logservice.indicators;
|
||||
|
||||
import com.caliverse.admin.Indicators.Indicatordomain.IndicatorsLog;
|
||||
import com.caliverse.admin.Indicators.entity.UserCreateLogInfo;
|
||||
import com.caliverse.admin.Indicators.indicatorrepository.IndicatorUserCreateRepository;
|
||||
import com.caliverse.admin.logs.Indicatordomain.UserCreateMongoLog;
|
||||
import com.caliverse.admin.logs.logservice.businesslogservice.BusinessLogUserCreateService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class IndicatorsUserCreateService {
|
||||
|
||||
@Autowired private IndicatorUserCreateRepository indicatorUserCreateRepository;
|
||||
@Autowired private BusinessLogUserCreateService userCreateService;
|
||||
|
||||
public void collectUserCreate(String startTime, String endTime){
|
||||
String logTimeStr = startTime.substring(0, 10);
|
||||
List<UserCreateMongoLog> indicatorsLog = userCreateService.loadBusinessLogData(startTime, endTime, UserCreateMongoLog.class);
|
||||
|
||||
if (indicatorsLog == null || indicatorsLog.isEmpty()) {
|
||||
log.info("collectUserCreate indicatorsLog Log logDay: {} null", logTimeStr);
|
||||
return;
|
||||
}
|
||||
|
||||
for(UserCreateMongoLog mongo_log : indicatorsLog){
|
||||
String logDay = mongo_log.getLogDay();
|
||||
|
||||
UserCreateLogInfo userCreateLog = new UserCreateLogInfo(logDay, mongo_log.getAccountId(), mongo_log.getUserGuid(), mongo_log.getUserNickname(), mongo_log.getCreatedTime());
|
||||
log.info("collectUserCreate UserCreate Log Save logDay: {}, userGuid: {}, createTime: {}", logDay, userCreateLog.getUserGuid(), userCreateLog.getCreatedTime());
|
||||
saveStatLogData(userCreateLog);
|
||||
}
|
||||
}
|
||||
|
||||
public void saveStatLogData(IndicatorsLog indicatorsLog) {
|
||||
|
||||
if (indicatorsLog instanceof UserCreateLogInfo logInfo) {
|
||||
try {
|
||||
indicatorUserCreateRepository.save(logInfo);
|
||||
} catch (Exception e) {
|
||||
log.error("Error Repository Write UserCreateLogInfo: {}, Message: {}", logInfo, e.getMessage());
|
||||
}
|
||||
} else {
|
||||
log.error("Not instanceof UserCreateLogInfo");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.caliverse.admin.logs.logservice.indicators;
|
||||
|
||||
import com.caliverse.admin.Indicators.Indicatordomain.IndicatorsLog;
|
||||
import com.caliverse.admin.Indicators.entity.UserLoginLogInfo;
|
||||
import com.caliverse.admin.Indicators.indicatorrepository.IndicatorUserLoginRepository;
|
||||
import com.caliverse.admin.logs.Indicatordomain.UserLoginMongoLog;
|
||||
import com.caliverse.admin.logs.logservice.businesslogservice.BusinessLogUserLoginMultiService;
|
||||
import com.caliverse.admin.logs.logservice.businesslogservice.BusinessLogUserLoginService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class IndicatorsUserLoginService {
|
||||
|
||||
@Autowired private IndicatorUserLoginRepository indicatorUserLoginRepository;
|
||||
@Autowired private BusinessLogUserLoginService userLoginService;
|
||||
@Autowired private BusinessLogUserLoginMultiService userLoginMultiService;
|
||||
|
||||
public void collectUserLogin(String startTime, String endTime){
|
||||
String logTimeStr = startTime.substring(0, 10);
|
||||
|
||||
List<UserLoginMongoLog> indicatorsLog = null;
|
||||
if(startTime.startsWith("2024")){
|
||||
indicatorsLog = userLoginMultiService.loadBusinessLogData(startTime, endTime, UserLoginMongoLog.class);
|
||||
}else{
|
||||
indicatorsLog = userLoginService.loadBusinessLogData(startTime, endTime, UserLoginMongoLog.class);
|
||||
}
|
||||
|
||||
if (indicatorsLog == null || indicatorsLog.isEmpty()) {
|
||||
log.info("collectUserLogin indicatorsLog Log logDay: {} null", logTimeStr);
|
||||
return;
|
||||
}
|
||||
|
||||
for(UserLoginMongoLog mongo_log : indicatorsLog){
|
||||
String logDay = mongo_log.getLogDay();
|
||||
|
||||
UserLoginLogInfo userCreateLog = new UserLoginLogInfo(logDay,
|
||||
mongo_log.getAccountId(),
|
||||
mongo_log.getUserGuid(),
|
||||
mongo_log.getUserNickname(),
|
||||
mongo_log.getSessions(),
|
||||
mongo_log.getFirstLoginTime(),
|
||||
mongo_log.getLastLogoutTime(),
|
||||
mongo_log.getLoginCount(),
|
||||
mongo_log.getTotalPlayTime()
|
||||
);
|
||||
log.info("collectUserLogin UserLogin Log Save logDay: {}, info: {}", logDay, userCreateLog);
|
||||
saveStatLogData(userCreateLog);
|
||||
}
|
||||
}
|
||||
|
||||
public void saveStatLogData(IndicatorsLog indicatorsLog) {
|
||||
|
||||
if (indicatorsLog instanceof UserLoginLogInfo logInfo) {
|
||||
try {
|
||||
indicatorUserLoginRepository.save(logInfo);
|
||||
} catch (Exception e) {
|
||||
log.error("Error Repository Write UserLoginLogInfo: {}, Message: {}", logInfo, e.getMessage());
|
||||
}
|
||||
} else {
|
||||
log.error("Not instanceof UserLoginLogInfo");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user