재화 로그 액션, 재화종류, 증감유형 조건 추가

재화 로그 잔량 필드 추가
재화 지표 export 추가
This commit is contained in:
2025-06-16 15:40:04 +09:00
parent 2f9ea432f4
commit b1fbd556e2
9 changed files with 217 additions and 18 deletions

View File

@@ -1,12 +1,9 @@
package com.caliverse.admin.Indicators.entity;
import com.caliverse.admin.logs.Indicatordomain.CurrencyMongoLog;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.List;
@Getter
@Setter
@Document(collection = "currency")
@@ -22,6 +19,7 @@ public class CurrencyDetailLogInfo extends LogInfoBase{
private String currencyType;
private String amountDeltaType;
private Double deltaAmount;
private Double currencyAmount;
public CurrencyDetailLogInfo(String id,
String logDay,
@@ -33,7 +31,8 @@ public class CurrencyDetailLogInfo extends LogInfoBase{
String logTime,
String currencyType,
String amountDeltaType,
Double deltaAmount
Double deltaAmount,
Double currencyAmount
) {
super(StatisticsType.CURRENCY);
@@ -48,6 +47,7 @@ public class CurrencyDetailLogInfo extends LogInfoBase{
this.currencyType = currencyType;
this.amountDeltaType = amountDeltaType;
this.deltaAmount = deltaAmount;
this.currencyAmount = currencyAmount;
}
}

View File

@@ -54,4 +54,10 @@ public class LogController {
@RequestBody LogGameRequest logGameRequest){
logService.currencyDetailExcelExport(response, logGameRequest);
}
@PostMapping("/currency/excel-export")
public void currencyExcelExport(HttpServletResponse response,
@RequestBody LogGameRequest logGameRequest){
logService.currencyExcelExport(response, logGameRequest);
}
}

View File

@@ -1,6 +1,8 @@
package com.caliverse.admin.domain.request;
import com.caliverse.admin.domain.entity.common.SearchUserType;
import com.caliverse.admin.dynamodb.entity.EAmountDeltaType;
import com.caliverse.admin.dynamodb.entity.ECurrencyType;
import com.caliverse.admin.logs.entity.LogAction;
import com.caliverse.admin.logs.entity.LogDomain;
import com.fasterxml.jackson.annotation.JsonProperty;
@@ -26,6 +28,10 @@ public class LogGameRequest {
private LogDomain logDomain;
@JsonProperty("tran_id")
private String tranId;
@JsonProperty("currency_type")
private ECurrencyType currencyType;
@JsonProperty("amount_delta_type")
private EAmountDeltaType amountDeltaType;
@JsonProperty("start_dt")
private LocalDateTime startDt;
@JsonProperty("end_dt")

View File

@@ -303,9 +303,12 @@ public class LogService {
}
public LogResponse getCurrencyLogList(Map<String, String> requestParams){
String startDt = requestParams.get("start_dt");
String endDt = requestParams.get("end_dt");
List<CurrencyLogInfo> currencyLogList = indicatorsCurrencyService.getIndicatorsLogData(startDt, endDt, CurrencyLogInfo.class);
LocalDateTime startDt = DateUtils.stringISOToLocalDateTime(requestParams.get("start_dt"));
LocalDateTime endDt = DateUtils.stringISOToLocalDateTime(requestParams.get("end_dt"));
List<CurrencyLogInfo> currencyLogList = indicatorsCurrencyService.getIndicatorsLogData(
startDt.toString().substring(0, 10),
endDt.toString().substring(0, 10),
CurrencyLogInfo.class);
List<LogResponse.currencyLog> currencyList = new ArrayList<>();
for (CurrencyLogInfo info : currencyLogList){
@@ -343,10 +346,90 @@ public class LogService {
.build();
}
public void currencyExcelExport(HttpServletResponse response, LogGameRequest logGameRequest){
String taskId = logGameRequest.getTaskId();
LocalDateTime startDt = logGameRequest.getStartDt().plusHours(9);
LocalDateTime endDt = logGameRequest.getEndDt().plusHours(9).plusDays(1);
logGameRequest.setStartDt(startDt);
logGameRequest.setEndDt(endDt);
logGameRequest.setPageNo(null);
logGameRequest.setPageSize(null);
progressTracker.updateProgress(taskId, 5, 100, "엑셀 생성 준비 중...");
List<CurrencyLogInfo> result = null;
try{
result = indicatorsCurrencyService.getIndicatorsLogData(
startDt.toString().substring(0, 10),
endDt.toString().substring(0, 10),
CurrencyLogInfo.class
);
progressTracker.updateProgress(taskId, 20, 100, "데이터 생성완료");
}catch(UncategorizedMongoDbException e){
if (e.getMessage().contains("Sort exceeded memory limit")) {
log.error("MongoDB Query memory limit error: {}", e.getMessage());
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.ERROR_LOG_MEMORY_LIMIT.toString());
} else if (e.getMessage().contains("time limit")) {
log.error("MongoDB Query operation exceeded time limit: {}", e.getMessage());
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.ERROR_LOG_MEMORY_LIMIT.toString());
}else {
log.error("MongoDB Query error", e);
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.ERROR_MONGODB_QUERY.toString());
}
}catch (Exception e){
log.error("currencyExcelExport ExcelExport Data Search Error", e);
}
List<LogResponse.currencyLog> currencyList = new ArrayList<>();
for (CurrencyLogInfo info : result){
LogResponse.currencyLog build = LogResponse.currencyLog.builder()
.logDay(info.getLogDay())
.accountId(info.getAccountId())
.userGuid(info.getUserGuid())
.userNickname(info.getUserNickname())
.goldAcquired(info.getGoldAcquired())
.goldConsumed(info.getGoldConsumed())
.goldNet(info.getGoldNet())
.sapphireAcquired(info.getSapphireAcquired())
.sapphireConsumed(info.getSapphireConsumed())
.sapphireNet(info.getSapphireNet())
.beamAcquired(info.getBeamAcquired())
.beamConsumed(info.getBeamConsumed())
.beamNet(info.getBeamNet())
.caliumAcquired(info.getCaliumAcquired())
.caliumConsumed(info.getCaliumConsumed())
.caliumNet(info.getCaliumNet())
.rubyAcquired(info.getRubyAcquired())
.rubyConsumed(info.getRubyConsumed())
.rubyNet(info.getRubyNet())
.totalCurrencies(info.getTotalCurrencies())
.build();
currencyList.add(build);
}
progressTracker.updateProgress(taskId, 30, 100, "데이터 파싱 완료...");
try{
excelService.generateExcelToResponse(
response,
currencyList,
"재화 지표 데이터",
"sheet1",
taskId
);
}catch (Exception e){
log.error("currencyExcelExport Excel Export Create Error", e);
throw new RestApiException(CommonCode.ERROR.getHttpStatus(), ErrorCode.ERROR_EXCEL_DOWN.toString());
}
}
public LogResponse getCurrencyDetailLogList(Map<String, String> requestParams){
String searchType = requestParams.get("search_type");
String searchData = requestParams.get("search_data");
String tranId = requestParams.get("tran_id");
String logAction = requestParams.get("log_action");
String currencyType = requestParams.get("currency_type");
String amountDeltaType = requestParams.get("amount_delta_type");
LocalDateTime startDt = DateUtils.stringISOToLocalDateTime(requestParams.get("start_dt"));
LocalDateTime endDt = DateUtils.stringISOToLocalDateTime(requestParams.get("end_dt"));
String orderBy = requestParams.get("orderby");
@@ -356,6 +439,9 @@ public class LogService {
searchType,
searchData,
tranId,
logAction,
currencyType,
amountDeltaType,
startDt.toString().substring(0, 10),
endDt.toString().substring(0, 10),
orderBy,
@@ -389,13 +475,15 @@ public class LogService {
logGameRequest.setPageSize(null);
progressTracker.updateProgress(taskId, 5, 100, "엑셀 생성 준비 중...");
MongoPageResult<CurrencyDetailLogInfo> result = null;
try{
result = indicatorsCurrencyService.getCurrencyDetailLogData(
logGameRequest.getSearchType().toString(),
logGameRequest.getSearchData(),
logGameRequest.getTranId(),
logGameRequest.getLogAction().name(),
logGameRequest.getCurrencyType().name(),
logGameRequest.getAmountDeltaType().name(),
startDt.toString().substring(0, 10),
endDt.toString().substring(0, 10),
logGameRequest.getOrderBy(),

View File

@@ -2,6 +2,7 @@ package com.caliverse.admin.dynamodb.entity;
import com.caliverse.admin.domain.entity.common.ValueEnum;
import com.fasterxml.jackson.annotation.JsonCreator;
public enum EAmountDeltaType implements ValueEnum {
None(0),
@@ -20,4 +21,24 @@ public enum EAmountDeltaType implements ValueEnum {
public int getValue() {
return value;
}
@JsonCreator
public static EAmountDeltaType fromValue(Object value) {
if (value instanceof Number) {
int intValue = ((Number) value).intValue();
for (EAmountDeltaType type : values()) {
if (type.value == intValue) {
return type;
}
}
} else if (value instanceof String) {
String stringValue = (String) value;
for (EAmountDeltaType type : values()) {
if (type.name().equalsIgnoreCase(stringValue)) {
return type;
}
}
}
throw new IllegalArgumentException("Invalid EAmountDeltaType value: " + value);
}
}

View File

@@ -2,6 +2,7 @@ package com.caliverse.admin.dynamodb.entity;
import com.caliverse.admin.domain.entity.common.ValueEnum;
import com.fasterxml.jackson.annotation.JsonCreator;
public enum ECurrencyType implements ValueEnum {
None(0),
@@ -22,4 +23,25 @@ public enum ECurrencyType implements ValueEnum {
public int getValue() {
return value;
}
@JsonCreator
public static ECurrencyType fromValue(Object value) {
if (value instanceof Number) {
int intValue = ((Number) value).intValue();
for (ECurrencyType type : values()) {
if (type.value == intValue) {
return type;
}
}
} else if (value instanceof String) {
String stringValue = (String) value;
for (ECurrencyType type : values()) {
if (type.name().equalsIgnoreCase(stringValue)) {
return type;
}
}
}
throw new IllegalArgumentException("Invalid ECurrencyType value: " + value);
}
}

View File

@@ -40,5 +40,6 @@ public class CurrencyMongoLog extends MongoLogSearchBase{
private String currencyType;
private String amountDeltaType;
private Double deltaAmount;
private Double currencyAmount;
}
}

View File

@@ -133,6 +133,25 @@ public class BusinessLogCurrencyService extends BusinessLogServiceBase {
)
)
)
.append("currencyAmount",
new Document("$let",
new Document("vars",
new Document("found",
new Document("$regexFind",
new Document("input", "$$doc.message")
.append("regex", "\"CurrencyAmount\":([^,}]+)")
)
)
)
.append("in",
new Document("$toDouble",
new Document("$arrayElemAt",
Arrays.asList("$$found.captures", 0)
)
)
)
)
)
)
)
)
@@ -345,6 +364,7 @@ public class BusinessLogCurrencyService extends BusinessLogServiceBase {
.append("currencyType", "$currencyInfo.currencyType")
.append("amountDeltaType", "$currencyInfo.amountDeltaType")
.append("deltaAmount", "$currencyInfo.deltaAmount")
.append("currencyAmount", "$currencyInfo.currencyAmount")
)
)
)
@@ -406,7 +426,11 @@ public class BusinessLogCurrencyService extends BusinessLogServiceBase {
Aggregation aggregation = Aggregation.newAggregation(operations);
log.info("loadBusinessLogData Currency Query: {}", aggregation);
AggregationResults<T> results = getMongoTemplate().aggregate(aggregation, AdminConstants.MONGO_DB_COLLECTION_LOG, class1);
AggregationResults<T> results = getMongoTemplate().aggregate(
aggregation.withOptions(AggregationOptions.builder().allowDiskUse(true).build())
, AdminConstants.MONGO_DB_COLLECTION_LOG
, class1
);
return results.getMappedResults();
}

View File

@@ -124,13 +124,20 @@ public class IndicatorsCurrencyService extends IndicatorsLogLoadServiceBase {
Aggregation aggregation = Aggregation.newAggregation(operations);
return mongoTemplate.aggregate(aggregation, AdminConstants.MONGO_DB_COLLECTION_CURRENCY, clazz).getMappedResults();
return mongoTemplate.aggregate(
aggregation.withOptions(AggregationOptions.builder().allowDiskUse(true).build())
, AdminConstants.MONGO_DB_COLLECTION_CURRENCY
, clazz
).getMappedResults();
}
public <T extends IndicatorsLog> MongoPageResult<T> getCurrencyDetailLogData(
String searchType,
String searchData,
String tranId,
String logAction,
String currencyType,
String amountDeltaType,
String startTime,
String endTime,
String orderBy,
@@ -174,14 +181,32 @@ public class IndicatorsCurrencyService extends IndicatorsLogLoadServiceBase {
.and("currencies.action").as("action")
.and("currencies.currencyType").as("currencyType")
.and("currencies.amountDeltaType").as("amountDeltaType")
.and("currencies.deltaAmount").as("deltaAmount");
.and("currencies.deltaAmount").as("deltaAmount")
.and("currencies.currencyAmount").as("currencyAmount");
List<AggregationOperation> baseOperations = List.of(
List<AggregationOperation> baseOperations = new ArrayList<>(List.of(
Aggregation.match(criteria),
unwindOperation,
projection,
Aggregation.sort(orderBy.equals("ASC") ? Sort.Direction.ASC : Sort.Direction.DESC, AdminConstants.MONGO_DB_KEY_LOGDAY)
);
Aggregation.sort(orderBy.equals("DESC") ? Sort.Direction.DESC : Sort.Direction.ASC, AdminConstants.MONGO_DB_KEY_LOGTIME)
));
Criteria postUnwindCriteria = new Criteria();
if(logAction != null && !logAction.isEmpty() && !logAction.equals("None")){
postUnwindCriteria.and("action").is(logAction);
}
if(currencyType != null && !currencyType.isEmpty() && !currencyType.equals("None")){
postUnwindCriteria.and("currencyType").is(currencyType);
}
if(amountDeltaType != null && !amountDeltaType.isEmpty() && !amountDeltaType.equals("None")){
postUnwindCriteria.and("amountDeltaType").is(amountDeltaType);
}
if (!postUnwindCriteria.getCriteriaObject().isEmpty()) {
baseOperations.add(Aggregation.match(postUnwindCriteria));
}
int totalCount = 0;
if(page != null && page != 0) {
@@ -189,8 +214,11 @@ public class IndicatorsCurrencyService extends IndicatorsLogLoadServiceBase {
countOperations.add(Aggregation.count().as("total"));
Aggregation countAggregation = Aggregation.newAggregation(countOperations);
Document countResult = mongoTemplate.aggregate(countAggregation, AdminConstants.MONGO_DB_COLLECTION_CURRENCY, Document.class)
.getUniqueMappedResult();
Document countResult = mongoTemplate.aggregate(
countAggregation.withOptions(AggregationOptions.builder().allowDiskUse(true).build()),
AdminConstants.MONGO_DB_COLLECTION_CURRENCY,
Document.class
).getUniqueMappedResult();
totalCount = countResult != null ? countResult.getInteger("total") : 0;
}
@@ -202,8 +230,11 @@ public class IndicatorsCurrencyService extends IndicatorsLogLoadServiceBase {
}
Aggregation aggregation = Aggregation.newAggregation(dataOperations);
List<T> items = mongoTemplate.aggregate(aggregation, AdminConstants.MONGO_DB_COLLECTION_CURRENCY, clazz)
.getMappedResults();
List<T> items = mongoTemplate.aggregate(
aggregation.withOptions(AggregationOptions.builder().allowDiskUse(true).build()),
AdminConstants.MONGO_DB_COLLECTION_CURRENCY,
clazz
).getMappedResults();
return new MongoPageResult<>(items, totalCount);
}