Commit 7581c5e3 authored by alex yao's avatar alex yao

style: 时间范围计算

parent cd765570
package cn.com.poc.data_analyze.constants; package cn.com.poc.data_analyze.constants;
import cn.com.poc.common.utils.Assert;
import cn.com.poc.common.utils.DateUtils;
import cn.com.poc.data_analyze.domain.DataAnalyzeTimeRange;
import cn.com.poc.data_analyze.domain.TimeRange;
import cn.com.yict.framemax.core.i18n.I18nMessageException; import cn.com.yict.framemax.core.i18n.I18nMessageException;
import java.util.Date;
/** /**
* 应用数据分析-时间范围枚举 * 应用数据分析-时间范围枚举
* *
...@@ -38,4 +44,44 @@ public enum DataAnalyzeTimeRangeEnum { ...@@ -38,4 +44,44 @@ public enum DataAnalyzeTimeRangeEnum {
throw new I18nMessageException("data-analyze/not.support.rang.type"); throw new I18nMessageException("data-analyze/not.support.rang.type");
} }
public static TimeRange calculateTimeRange(DataAnalyzeTimeRange dataAnalyzeTimeRange) {
String startTime;
String endTime;
Date startDate;
Date endDate;
String rangType = dataAnalyzeTimeRange.getRangType();
switch (DataAnalyzeTimeRangeEnum.getByType(rangType)) {
case today:
endDate = DateUtils.getTodayEnd();
startDate = DateUtils.getDayStartTime(endDate);
startTime = DateUtils.formatDate(startDate, DateUtils.yyyy_MM_dd);
endTime = DateUtils.formatDate(endDate, DateUtils.yyyy_MM_dd_HH_mm_ss);
break;
case week:
endDate = DateUtils.getTodayEnd();
startDate = DateUtils.getDayStartTime(DateUtils.addDays(endDate, -6));
startTime = DateUtils.formatDate(startDate, DateUtils.yyyy_MM_dd);
endTime = DateUtils.formatDate(endDate, DateUtils.yyyy_MM_dd_HH_mm_ss);
break;
case month:
endDate = DateUtils.getTodayEnd();
startDate = DateUtils.getDayStartTime(DateUtils.addMonth(endDate, -1));
startTime = DateUtils.formatDate(startDate, DateUtils.yyyy_MM_dd);
endTime = DateUtils.formatDate(endDate, DateUtils.yyyy_MM_dd_HH_mm_ss);
break;
case customize:
Assert.notBlank(dataAnalyzeTimeRange.getStartTime());
Assert.notBlank(dataAnalyzeTimeRange.getEndTime());
startTime = dataAnalyzeTimeRange.getStartTime();
endDate = DateUtils.getDayEnd(DateUtils.stringToDateShort(dataAnalyzeTimeRange.getEndTime()));
endTime = DateUtils.formatDate(endDate, DateUtils.yyyy_MM_dd_HH_mm_ss);
break;
default:
throw new I18nMessageException("data-analyze/not.support.rang.type");
}
TimeRange timeRange = new TimeRange();
timeRange.setStartTime(startTime);
timeRange.setEndTime(endTime);
return timeRange;
}
} }
package cn.com.poc.data_analyze.domain;
/**
* @author alex.yao
* @date 2024/12/24
*/
public class TimeRange {
private String startTime;
private String endTime;
public String getStartTime() {
return startTime;
}
public void setStartTime(String startTime) {
this.startTime = startTime;
}
public String getEndTime() {
return endTime;
}
public void setEndTime(String endTime) {
this.endTime = endTime;
}
}
package cn.com.poc.expose.aggregate.impl; package cn.com.poc.expose.aggregate.impl;
import cn.com.poc.agent_application.aggregate.AgentApplicationInfoService;
import cn.com.poc.common.utils.Assert;
import cn.com.poc.common.utils.BlContext;
import cn.com.poc.common.utils.DateUtils; import cn.com.poc.common.utils.DateUtils;
import cn.com.poc.data_analyze.constants.DataAnalyzeChannelEnum; import cn.com.poc.data_analyze.constants.DataAnalyzeChannelEnum;
import cn.com.poc.data_analyze.constants.DataAnalyzeTimeDimensionEnum; import cn.com.poc.data_analyze.constants.DataAnalyzeTimeDimensionEnum;
import cn.com.poc.data_analyze.constants.DataAnalyzeTimeRangeEnum; import cn.com.poc.data_analyze.constants.DataAnalyzeTimeRangeEnum;
import cn.com.poc.data_analyze.domain.ChannelDataCount; import cn.com.poc.data_analyze.domain.*;
import cn.com.poc.data_analyze.domain.DataAnalyze;
import cn.com.poc.data_analyze.domain.DataAnalyzeInfo;
import cn.com.poc.data_analyze.domain.DataAnalyzeTimeRange;
import cn.com.poc.data_analyze.entity.*; import cn.com.poc.data_analyze.entity.*;
import cn.com.poc.data_analyze.query.*; import cn.com.poc.data_analyze.query.*;
import cn.com.poc.data_analyze.service.BizDataAnalyzeDialogueRecordService; import cn.com.poc.data_analyze.service.BizDataAnalyzeDialogueRecordService;
import cn.com.poc.data_analyze.service.BizDataAnalyzePointRecordService; import cn.com.poc.data_analyze.service.BizDataAnalyzePointRecordService;
import cn.com.poc.expose.aggregate.AgentDataAnalyzeService; import cn.com.poc.expose.aggregate.AgentDataAnalyzeService;
import cn.com.yict.framemax.core.i18n.I18nMessageException;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -115,35 +108,9 @@ public class AgentDataAnalyzeServiceImpl implements AgentDataAnalyzeService { ...@@ -115,35 +108,9 @@ public class AgentDataAnalyzeServiceImpl implements AgentDataAnalyzeService {
@Override @Override
public List<AgentDataAnalyzeTrendEntity> getAgentDataTrend(String agentId, List<String> channel, DataAnalyzeTimeRange timeRange) { public List<AgentDataAnalyzeTrendEntity> getAgentDataTrend(String agentId, List<String> channel, DataAnalyzeTimeRange timeRange) {
String rangType = timeRange.getRangType(); TimeRange timeRangeResult = DataAnalyzeTimeRangeEnum.calculateTimeRange(timeRange);
String startTime = ""; String endTime = timeRangeResult.getEndTime();
String endTime = ""; String startTime = timeRangeResult.getStartTime();
Date endDate;
Date startDate;
switch (DataAnalyzeTimeRangeEnum.getByType(rangType)) {
case week:
endDate = DateUtils.getTodayEnd();
startDate = DateUtils.getDayStartTime(DateUtils.addDays(endDate, -6));
startTime = DateUtils.formatDate(startDate, DateUtils.yyyy_MM_dd);
endTime = DateUtils.formatDate(endDate, DateUtils.yyyy_MM_dd_HH_mm_ss);
break;
case month:
endDate = DateUtils.getTodayEnd();
startDate = DateUtils.getDayStartTime(DateUtils.addMonth(endDate, -1));
startTime = DateUtils.formatDate(startDate, DateUtils.yyyy_MM_dd);
endTime = DateUtils.formatDate(endDate, DateUtils.yyyy_MM_dd_HH_mm_ss);
break;
case customize:
Assert.notBlank(timeRange.getStartTime());
Assert.notBlank(timeRange.getEndTime());
startTime = timeRange.getStartTime();
endDate = DateUtils.getDayEnd(DateUtils.stringToDateShort(timeRange.getEndTime()));
endTime = DateUtils.formatDate(endDate, DateUtils.yyyy_MM_dd_HH_mm_ss);
break;
default:
throw new I18nMessageException("data-analyze/not.support.rang.type");
}
AgentDataTrendQueryCondition agentDataTrendQueryCondition = new AgentDataTrendQueryCondition(); AgentDataTrendQueryCondition agentDataTrendQueryCondition = new AgentDataTrendQueryCondition();
agentDataTrendQueryCondition.setStartDate(startTime); agentDataTrendQueryCondition.setStartDate(startTime);
agentDataTrendQueryCondition.setEndDate(endTime); agentDataTrendQueryCondition.setEndDate(endTime);
...@@ -167,40 +134,9 @@ public class AgentDataAnalyzeServiceImpl implements AgentDataAnalyzeService { ...@@ -167,40 +134,9 @@ public class AgentDataAnalyzeServiceImpl implements AgentDataAnalyzeService {
@Override @Override
public List<AgentDataAnalyzeApiChannelEntity> getAgentApiChannelPointCount(String agentId, DataAnalyzeTimeRange timeRange) { public List<AgentDataAnalyzeApiChannelEntity> getAgentApiChannelPointCount(String agentId, DataAnalyzeTimeRange timeRange) {
String rangType = timeRange.getRangType(); TimeRange timeRangeResult = DataAnalyzeTimeRangeEnum.calculateTimeRange(timeRange);
String startTime = ""; String endTime = timeRangeResult.getEndTime();
String endTime = ""; String startTime = timeRangeResult.getStartTime();
Date endDate;
Date startDate;
switch (DataAnalyzeTimeRangeEnum.getByType(rangType)) {
case today:
endDate = DateUtils.getTodayEnd();
startDate = DateUtils.getDayStartTime(endDate);
startTime = DateUtils.formatDate(startDate, DateUtils.yyyy_MM_dd);
endTime = DateUtils.formatDate(endDate, DateUtils.yyyy_MM_dd_HH_mm_ss);
break;
case week:
endDate = DateUtils.getTodayEnd();
startDate = DateUtils.getDayStartTime(DateUtils.addDays(endDate, -6));
startTime = DateUtils.formatDate(startDate, DateUtils.yyyy_MM_dd);
endTime = DateUtils.formatDate(endDate, DateUtils.yyyy_MM_dd_HH_mm_ss);
break;
case month:
endDate = DateUtils.getTodayEnd();
startDate = DateUtils.getDayStartTime(DateUtils.addMonth(endDate, -1));
startTime = DateUtils.formatDate(startDate, DateUtils.yyyy_MM_dd);
endTime = DateUtils.formatDate(endDate, DateUtils.yyyy_MM_dd_HH_mm_ss);
break;
case customize:
Assert.notBlank(timeRange.getStartTime());
Assert.notBlank(timeRange.getEndTime());
startTime = timeRange.getStartTime();
endDate = DateUtils.getDayEnd(DateUtils.stringToDateShort(timeRange.getEndTime()));
endTime = DateUtils.formatDate(endDate, DateUtils.yyyy_MM_dd_HH_mm_ss);
break;
default:
throw new I18nMessageException("data-analyze/not.support.rang.type");
}
List<String> channels = new ArrayList<String>() {{ List<String> channels = new ArrayList<String>() {{
add(DataAnalyzeChannelEnum.api.getChannel()); add(DataAnalyzeChannelEnum.api.getChannel());
}}; }};
...@@ -222,8 +158,7 @@ public class AgentDataAnalyzeServiceImpl implements AgentDataAnalyzeService { ...@@ -222,8 +158,7 @@ public class AgentDataAnalyzeServiceImpl implements AgentDataAnalyzeService {
return result; return result;
} }
private static void buildGeneralData(DataAnalyzeTimeDimensionEnum private static void buildGeneralData(DataAnalyzeTimeDimensionEnum dataAnalyzeTimeDimensionEnum, List<PointsUsageQueryItem> pointsUsageQueryItems, List<AgentUsageQueryItem> agentUsageQueryItems, List<AgentDataAnalyzeGeneralEntity> result) {
dataAnalyzeTimeDimensionEnum, List<PointsUsageQueryItem> pointsUsageQueryItems, List<AgentUsageQueryItem> agentUsageQueryItems, List<AgentDataAnalyzeGeneralEntity> result) {
DataAnalyzeInfo dataAnalyzeInfo = new DataAnalyzeInfo(); DataAnalyzeInfo dataAnalyzeInfo = new DataAnalyzeInfo();
//积分 //积分
DataAnalyze pointsCount = new DataAnalyze(); DataAnalyze pointsCount = new DataAnalyze();
......
...@@ -4,10 +4,10 @@ import cn.com.poc.agent_application.constant.AgentApplicationConstants; ...@@ -4,10 +4,10 @@ import cn.com.poc.agent_application.constant.AgentApplicationConstants;
import cn.com.poc.agent_application.entity.BizAgentApplicationInfoEntity; import cn.com.poc.agent_application.entity.BizAgentApplicationInfoEntity;
import cn.com.poc.agent_application.service.BizAgentApplicationInfoService; import cn.com.poc.agent_application.service.BizAgentApplicationInfoService;
import cn.com.poc.common.constant.CommonConstant; import cn.com.poc.common.constant.CommonConstant;
import cn.com.poc.common.utils.Assert;
import cn.com.poc.common.utils.DateUtils; import cn.com.poc.common.utils.DateUtils;
import cn.com.poc.data_analyze.constants.DataAnalyzeTimeRangeEnum; import cn.com.poc.data_analyze.constants.DataAnalyzeTimeRangeEnum;
import cn.com.poc.data_analyze.domain.DataAnalyzeTimeRange; import cn.com.poc.data_analyze.domain.DataAnalyzeTimeRange;
import cn.com.poc.data_analyze.domain.TimeRange;
import cn.com.poc.data_analyze.query.*; import cn.com.poc.data_analyze.query.*;
import cn.com.poc.data_analyze.service.BizDataAnalyzeDialogueRecordService; import cn.com.poc.data_analyze.service.BizDataAnalyzeDialogueRecordService;
import cn.com.poc.data_analyze.service.BizDataAnalyzePointRecordService; import cn.com.poc.data_analyze.service.BizDataAnalyzePointRecordService;
...@@ -15,7 +15,6 @@ import cn.com.poc.expose.aggregate.DataStatisticsService; ...@@ -15,7 +15,6 @@ import cn.com.poc.expose.aggregate.DataStatisticsService;
import cn.com.poc.expose.entity.PlatformAgentUsageDetailEntity; import cn.com.poc.expose.entity.PlatformAgentUsageDetailEntity;
import cn.com.poc.expose.entity.PlatformAgentUsageEntity; import cn.com.poc.expose.entity.PlatformAgentUsageEntity;
import cn.com.poc.expose.entity.PlatformPointUsageEntity; import cn.com.poc.expose.entity.PlatformPointUsageEntity;
import cn.com.yict.framemax.core.i18n.I18nMessageException;
import cn.com.yict.framemax.data.model.PagingInfo; import cn.com.yict.framemax.data.model.PagingInfo;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -66,33 +65,9 @@ public class DataStatisticsServiceImpl implements DataStatisticsService { ...@@ -66,33 +65,9 @@ public class DataStatisticsServiceImpl implements DataStatisticsService {
@Override @Override
public Map<String, List<MemberPointUsageTrendQueryItem>> platformPointTrend(Long memberId, List<String> channels, DataAnalyzeTimeRange timeRange) { public Map<String, List<MemberPointUsageTrendQueryItem>> platformPointTrend(Long memberId, List<String> channels, DataAnalyzeTimeRange timeRange) {
Map<String, List<MemberPointUsageTrendQueryItem>> result = new TreeMap<>(); Map<String, List<MemberPointUsageTrendQueryItem>> result = new TreeMap<>();
String startTime; TimeRange timeRangeResult = DataAnalyzeTimeRangeEnum.calculateTimeRange(timeRange);
String endTime; String endTime = timeRangeResult.getEndTime();
Date startDate; String startTime = timeRangeResult.getStartTime();
Date endDate;
switch (DataAnalyzeTimeRangeEnum.getByType(timeRange.getRangType())) {
case week:
endDate = DateUtils.getTodayEnd();
startDate = DateUtils.getDayStartTime(DateUtils.addDays(endDate, -6));
startTime = DateUtils.formatDate(startDate, DateUtils.yyyy_MM_dd);
endTime = DateUtils.formatDate(endDate, DateUtils.yyyy_MM_dd_HH_mm_ss);
break;
case month:
endDate = DateUtils.getTodayEnd();
startDate = DateUtils.getDayStartTime(DateUtils.addMonth(endDate, -1));
startTime = DateUtils.formatDate(startDate, DateUtils.yyyy_MM_dd);
endTime = DateUtils.formatDate(endDate, DateUtils.yyyy_MM_dd_HH_mm_ss);
break;
case customize:
Assert.notBlank(timeRange.getStartTime());
Assert.notBlank(timeRange.getEndTime());
startTime = timeRange.getStartTime();
endDate = DateUtils.getDayEnd(DateUtils.stringToDateShort(timeRange.getEndTime()));
endTime = DateUtils.formatDate(endDate, DateUtils.yyyy_MM_dd_HH_mm_ss);
break;
default:
throw new I18nMessageException("data-analyze/not.support.rang.type");
}
for (String channel : channels) { for (String channel : channels) {
MemberPointUsageTrendQueryCondition memberPointUsageTrendQueryCondition = new MemberPointUsageTrendQueryCondition(); MemberPointUsageTrendQueryCondition memberPointUsageTrendQueryCondition = new MemberPointUsageTrendQueryCondition();
memberPointUsageTrendQueryCondition.setStartDate(startTime); memberPointUsageTrendQueryCondition.setStartDate(startTime);
...@@ -126,33 +101,9 @@ public class DataStatisticsServiceImpl implements DataStatisticsService { ...@@ -126,33 +101,9 @@ public class DataStatisticsServiceImpl implements DataStatisticsService {
@Override @Override
public List<PlatformAgentUsageDetailEntity> platformAgentUsageDetail(Long memberId, DataAnalyzeTimeRange timeRange, PagingInfo pagingInfo) { public List<PlatformAgentUsageDetailEntity> platformAgentUsageDetail(Long memberId, DataAnalyzeTimeRange timeRange, PagingInfo pagingInfo) {
String startTime; TimeRange timeRangeResult = DataAnalyzeTimeRangeEnum.calculateTimeRange(timeRange);
String endTime; String endTime = timeRangeResult.getEndTime();
Date startDate; String startTime = timeRangeResult.getStartTime();
Date endDate;
switch (DataAnalyzeTimeRangeEnum.getByType(timeRange.getRangType())) {
case week:
endDate = DateUtils.getTodayEnd();
startDate = DateUtils.getDayStartTime(DateUtils.addDays(endDate, -6));
startTime = DateUtils.formatDate(startDate, DateUtils.yyyy_MM_dd);
endTime = DateUtils.formatDate(endDate, DateUtils.yyyy_MM_dd_HH_mm_ss);
break;
case month:
endDate = DateUtils.getTodayEnd();
startDate = DateUtils.getDayStartTime(DateUtils.addMonth(endDate, -1));
startTime = DateUtils.formatDate(startDate, DateUtils.yyyy_MM_dd);
endTime = DateUtils.formatDate(endDate, DateUtils.yyyy_MM_dd_HH_mm_ss);
break;
case customize:
Assert.notBlank(timeRange.getStartTime());
Assert.notBlank(timeRange.getEndTime());
startTime = timeRange.getStartTime();
endDate = DateUtils.getDayEnd(DateUtils.stringToDateShort(timeRange.getEndTime()));
endTime = DateUtils.formatDate(endDate, DateUtils.yyyy_MM_dd_HH_mm_ss);
break;
default:
throw new I18nMessageException("data-analyze/not.support.rang.type");
}
MemberAgentUsageDetailsQueryCondition memberAgentUsageDetailsQueryCondition = new MemberAgentUsageDetailsQueryCondition(); MemberAgentUsageDetailsQueryCondition memberAgentUsageDetailsQueryCondition = new MemberAgentUsageDetailsQueryCondition();
memberAgentUsageDetailsQueryCondition.setMemberId(memberId); memberAgentUsageDetailsQueryCondition.setMemberId(memberId);
memberAgentUsageDetailsQueryCondition.setStartDate(startTime); memberAgentUsageDetailsQueryCondition.setStartDate(startTime);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment