|
...
|
...
|
@@ -24,6 +24,7 @@ import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Description: 日志管理
|
|
...
|
...
|
@@ -120,16 +121,19 @@ public class AiragLogServiceImpl extends ServiceImpl<AiragLogMapper, AiragLog> i |
|
|
|
// 5. 获取累计问答次数
|
|
|
|
long totalCount = this.count();
|
|
|
|
|
|
|
|
// 6. 计算平均问答次数(基于有记录的天数)
|
|
|
|
QueryWrapper<AiragLog> distinctDaysWrapper = new QueryWrapper<>();
|
|
|
|
distinctDaysWrapper.select("DISTINCT DATE(create_time)");
|
|
|
|
long distinctDays = this.count(distinctDaysWrapper);
|
|
|
|
|
|
|
|
// 6. 计算平均问答次数
|
|
|
|
Date latestDate = airagLogMapper.getLatestTime(); // 需要确保Mapper中有此方法
|
|
|
|
double averageCount = 0.0;
|
|
|
|
if (distinctDays > 0) {
|
|
|
|
averageCount = (double) totalCount / distinctDays;
|
|
|
|
// 保留两位小数
|
|
|
|
averageCount = Math.round(averageCount * 100.0) / 100.0;
|
|
|
|
if (earlisetTime != null && latestDate != null) {
|
|
|
|
// 计算时间跨度(天数)
|
|
|
|
long diffInMillis = latestDate.getTime() - earlisetTime.getTime();
|
|
|
|
long daysBetween = TimeUnit.DAYS.convert(diffInMillis, TimeUnit.MILLISECONDS) + 1; // +1 包含首尾两天
|
|
|
|
|
|
|
|
if (daysBetween > 0) {
|
|
|
|
averageCount = (double) totalCount / daysBetween;
|
|
|
|
// 保留两位小数
|
|
|
|
averageCount = Math.round(averageCount * 100.0) / 100.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
...
|
...
|
|