This commit is contained in:
qaq
2025-08-15 12:57:56 +08:00
parent 6f80e26a8f
commit 23980578d7
5 changed files with 42 additions and 51 deletions
-3
View File
@@ -836,9 +836,6 @@ UPDATE \`statistics_flow\`
SET \`created_time\` = UNIX_TIMESTAMP() * 1000 SET \`created_time\` = UNIX_TIMESTAMP() * 1000
WHERE \`created_time\` = 0 OR \`created_time\` IS NULL; WHERE \`created_time\` = 0 OR \`created_time\` IS NULL;
EOF EOF
# 检查数据库容器 # 检查数据库容器
@@ -37,11 +37,11 @@ public class StatisticsFlowAsync {
long time = new Date().getTime(); long time = new Date().getTime();
// 删除48小时前的数据 // 删除48小时前的数据
long nowMs = System.currentTimeMillis(); long nowMs = new Date().getTime();
long cutoffMs = nowMs - 48L * 60 * 60 * 1000; long cutoffMs = nowMs - 48L * 60 * 60 * 1000;
statisticsFlowService.remove( statisticsFlowService.remove(
new LambdaQueryWrapper<StatisticsFlow>() new LambdaQueryWrapper<StatisticsFlow>()
.lt(StatisticsFlow::getCreateTime, cutoffMs) .lt(StatisticsFlow::getCreatedTime, cutoffMs)
); );
@@ -79,7 +79,7 @@ public class StatisticsFlowAsync {
statisticsFlow.setFlow(incrementFlow); statisticsFlow.setFlow(incrementFlow);
statisticsFlow.setTotalFlow(currentTotalFlow); statisticsFlow.setTotalFlow(currentTotalFlow);
statisticsFlow.setTime(hourString); statisticsFlow.setTime(hourString);
statisticsFlow.setCreateTime(time); statisticsFlow.setCreatedTime(time);
statisticsFlowList.add(statisticsFlow); statisticsFlowList.add(statisticsFlow);
} }
@@ -28,7 +28,7 @@ public class StatisticsFlow {
private String time; private String time;
private Long createTime; private Long createdTime;
} }
@@ -727,7 +727,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
* @return 最近24小时流量统计列表 * @return 最近24小时流量统计列表
*/ */
private List<StatisticsFlow> getLast24HoursFlowStatistics(Long userId) { private List<StatisticsFlow> getLast24HoursFlowStatistics(Long userId) {
try {
// 按ID倒序查最近24条记录(ID越大越新,时间就是23:00, 22:00, 21:00...这样倒序) // 按ID倒序查最近24条记录(ID越大越新,时间就是23:00, 22:00, 21:00...这样倒序)
List<StatisticsFlow> recentFlows = statisticsFlowService.list( List<StatisticsFlow> recentFlows = statisticsFlowService.list(
new QueryWrapper<StatisticsFlow>() new QueryWrapper<StatisticsFlow>()
@@ -766,11 +765,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
log.debug("用户 {} 获取到 {} 条实际记录,补齐为 {} 条24小时记录", userId, recentFlows.size(), result.size()); log.debug("用户 {} 获取到 {} 条实际记录,补齐为 {} 条24小时记录", userId, recentFlows.size(), result.size());
return result; return result;
} catch (Exception e) {
log.error("获取用户 {} 最近24小时流量统计失败", userId, e);
// 返回24条全0数据,时间从当前小时往前推
return generateEmpty24HourData(userId);
}
} }
/** /**
+2 -2
View File
@@ -215,7 +215,7 @@ export default function IndexPage() {
const checkResponse = await checkCaptcha(); const checkResponse = await checkCaptcha();
if (checkResponse.code !== 0) { if (checkResponse.code !== 0) {
toast.error("检查验证码状态失败,请重试"); toast.error("检查验证码状态失败,请重试" + checkResponse.msg);
setLoading(false); setLoading(false);
return; return;
} }
@@ -234,7 +234,7 @@ export default function IndexPage() {
} }
} catch (error) { } catch (error) {
console.error('检查验证码状态错误:', error); console.error('检查验证码状态错误:', error);
toast.error("网络错误,请稍后重试"); toast.error("网络错误,请稍后重试" + error);
setLoading(false); setLoading(false);
} }
}; };