作者 dong

首页数据修正

@@ -36,4 +36,5 @@ public interface AiragLogMapper extends BaseMapper<AiragLog> { @@ -36,4 +36,5 @@ public interface AiragLogMapper extends BaseMapper<AiragLog> {
36 List<Map<String, Object>> getDailyRejectedCountForLast7Days(); 36 List<Map<String, Object>> getDailyRejectedCountForLast7Days();
37 37
38 Date getEarliestTime(); 38 Date getEarliestTime();
  39 + Date getLatestTime();
39 } 40 }
@@ -157,4 +157,8 @@ @@ -157,4 +157,8 @@
157 SELECT MIN(create_time) AS earliest_time 157 SELECT MIN(create_time) AS earliest_time
158 FROM airag_log 158 FROM airag_log
159 </select> 159 </select>
  160 +
  161 + <select id="getLatestTime" resultType="java.util.Date">
  162 + SELECT MAX(create_time) FROM airag_log
  163 + </select>
160 </mapper> 164 </mapper>
@@ -24,6 +24,7 @@ import org.springframework.stereotype.Service; @@ -24,6 +24,7 @@ import org.springframework.stereotype.Service;
24 24
25 import java.text.SimpleDateFormat; 25 import java.text.SimpleDateFormat;
26 import java.util.*; 26 import java.util.*;
  27 +import java.util.concurrent.TimeUnit;
27 28
28 /** 29 /**
29 * @Description: 日志管理 30 * @Description: 日志管理
@@ -120,17 +121,20 @@ public class AiragLogServiceImpl extends ServiceImpl<AiragLogMapper, AiragLog> i @@ -120,17 +121,20 @@ public class AiragLogServiceImpl extends ServiceImpl<AiragLogMapper, AiragLog> i
120 // 5. 获取累计问答次数 121 // 5. 获取累计问答次数
121 long totalCount = this.count(); 122 long totalCount = this.count();
122 123
123 - // 6. 计算平均问答次数(基于有记录的天数)  
124 - QueryWrapper<AiragLog> distinctDaysWrapper = new QueryWrapper<>();  
125 - distinctDaysWrapper.select("DISTINCT DATE(create_time)");  
126 - long distinctDays = this.count(distinctDaysWrapper);  
127 - 124 + // 6. 计算平均问答次数
  125 + Date latestDate = airagLogMapper.getLatestTime(); // 需要确保Mapper中有此方法
128 double averageCount = 0.0; 126 double averageCount = 0.0;
129 - if (distinctDays > 0) {  
130 - averageCount = (double) totalCount / distinctDays; 127 + if (earlisetTime != null && latestDate != null) {
  128 + // 计算时间跨度(天数)
  129 + long diffInMillis = latestDate.getTime() - earlisetTime.getTime();
  130 + long daysBetween = TimeUnit.DAYS.convert(diffInMillis, TimeUnit.MILLISECONDS) + 1; // +1 包含首尾两天
  131 +
  132 + if (daysBetween > 0) {
  133 + averageCount = (double) totalCount / daysBetween;
131 // 保留两位小数 134 // 保留两位小数
132 averageCount = Math.round(averageCount * 100.0) / 100.0; 135 averageCount = Math.round(averageCount * 100.0) / 100.0;
133 } 136 }
  137 + }
134 138
135 139
136 // 8. 获取最近12个月的月度数据 140 // 8. 获取最近12个月的月度数据