mirror of
https://github.com/ctwj/urldb.git
synced 2025-11-25 03:15:04 +08:00
fix: 修复首页的今日资源数不对滴问题
This commit is contained in:
@@ -22,16 +22,20 @@ func GetStats(c *gin.Context) {
|
|||||||
db.DB.Model(&entity.Tag{}).Count(&totalTags)
|
db.DB.Model(&entity.Tag{}).Count(&totalTags)
|
||||||
db.DB.Model(&entity.Resource{}).Select("COALESCE(SUM(view_count), 0)").Scan(&totalViews)
|
db.DB.Model(&entity.Resource{}).Select("COALESCE(SUM(view_count), 0)").Scan(&totalViews)
|
||||||
|
|
||||||
// 获取今日数据
|
// 获取今日数据(在UTC+8时区的0点开始统计)
|
||||||
today := utils.GetTodayString()
|
now := utils.GetCurrentTime()
|
||||||
|
// 使用UTC+8时区的今天0点
|
||||||
|
loc, _ := time.LoadLocation("Asia/Shanghai") // UTC+8
|
||||||
|
startOfToday := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, loc)
|
||||||
|
endOfToday := startOfToday.Add(24 * time.Hour)
|
||||||
|
|
||||||
// 今日新增资源数量
|
// 今日新增资源数量(从0点开始)
|
||||||
var todayResources int64
|
var todayResources int64
|
||||||
db.DB.Model(&entity.Resource{}).Where("DATE(created_at) = ?", today).Count(&todayResources)
|
db.DB.Model(&entity.Resource{}).Where("created_at >= ? AND created_at < ?", startOfToday, endOfToday).Count(&todayResources)
|
||||||
|
|
||||||
// 今日更新资源数量(包括新增和修改)
|
// 今日更新资源数量(包括新增和修改,从0点开始)
|
||||||
var todayUpdates int64
|
var todayUpdates int64
|
||||||
db.DB.Model(&entity.Resource{}).Where("DATE(updated_at) = ?", today).Count(&todayUpdates)
|
db.DB.Model(&entity.Resource{}).Where("updated_at >= ? AND updated_at < ?", startOfToday, endOfToday).Count(&todayUpdates)
|
||||||
|
|
||||||
// 今日浏览量 - 使用访问记录表统计今日访问量
|
// 今日浏览量 - 使用访问记录表统计今日访问量
|
||||||
var todayViews int64
|
var todayViews int64
|
||||||
@@ -41,9 +45,9 @@ func GetStats(c *gin.Context) {
|
|||||||
todayViews = 0
|
todayViews = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// 今日搜索量
|
// 今日搜索量(从0点开始)
|
||||||
var todaySearches int64
|
var todaySearches int64
|
||||||
db.DB.Model(&entity.SearchStat{}).Where("DATE(date) = ?", today).Count(&todaySearches)
|
db.DB.Model(&entity.SearchStat{}).Where("date >= ? AND date < ?", startOfToday.Format(utils.TimeFormatDate), endOfToday.Format(utils.TimeFormatDate)).Count(&todaySearches)
|
||||||
|
|
||||||
// 添加调试日志
|
// 添加调试日志
|
||||||
utils.Info("统计数据 - 总资源: %d, 总分类: %d, 总标签: %d, 总浏览量: %d",
|
utils.Info("统计数据 - 总资源: %d, 总分类: %d, 总标签: %d, 总浏览量: %d",
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import { useSystemConfigStore } from '~/stores/systemConfig'
|
|||||||
const systemConfigStore = useSystemConfigStore()
|
const systemConfigStore = useSystemConfigStore()
|
||||||
await systemConfigStore.initConfig(false, false)
|
await systemConfigStore.initConfig(false, false)
|
||||||
const systemConfig = computed(() => systemConfigStore.config)
|
const systemConfig = computed(() => systemConfigStore.config)
|
||||||
console.log(systemConfig.value)
|
// console.log(systemConfig.value)
|
||||||
|
|
||||||
// 组件挂载时获取版本信息
|
// 组件挂载时获取版本信息
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
|||||||
@@ -221,7 +221,7 @@ const copyToClipboard = async (text: string) => {
|
|||||||
// 页面加载时获取配置
|
// 页面加载时获取配置
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
fetchApiToken()
|
fetchApiToken()
|
||||||
console.log('QQ 机器人标签已加载')
|
// console.log('QQ 机器人标签已加载')
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -433,7 +433,7 @@ watch(systemConfigError, (error) => {
|
|||||||
// 从 SSR 数据中获取值
|
// 从 SSR 数据中获取值
|
||||||
const safeResources = computed(() => {
|
const safeResources = computed(() => {
|
||||||
const data = resourcesData.value as any
|
const data = resourcesData.value as any
|
||||||
console.log('原始API数据结构:', JSON.stringify(data, null, 2))
|
// console.log('原始API数据结构:', JSON.stringify(data, null, 2))
|
||||||
|
|
||||||
// 处理嵌套的data结构:{data: {data: [...], total: ...}}
|
// 处理嵌套的data结构:{data: {data: [...], total: ...}}
|
||||||
if (data?.data?.data && Array.isArray(data.data.data)) {
|
if (data?.data?.data && Array.isArray(data.data.data)) {
|
||||||
@@ -444,16 +444,16 @@ const safeResources = computed(() => {
|
|||||||
// 处理直接的data结构:{data: [...], total: ...}
|
// 处理直接的data结构:{data: [...], total: ...}
|
||||||
if (data?.data && Array.isArray(data.data)) {
|
if (data?.data && Array.isArray(data.data)) {
|
||||||
const resources = data.data
|
const resources = data.data
|
||||||
console.log('第二层嵌套资源:', resources)
|
// console.log('第二层嵌套资源:', resources)
|
||||||
return resources
|
return resources
|
||||||
}
|
}
|
||||||
// 处理直接的数组结构
|
// 处理直接的数组结构
|
||||||
if (Array.isArray(data)) {
|
if (Array.isArray(data)) {
|
||||||
console.log('直接数组结构:', data)
|
// console.log('直接数组结构:', data)
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('未匹配到任何数据结构')
|
// console.log('未匹配到任何数据结构')
|
||||||
return []
|
return []
|
||||||
})
|
})
|
||||||
const safeStats = computed(() => (statsData.value as any) || { total_resources: 0, total_categories: 0, total_tags: 0, total_views: 0, today_resources: 0 })
|
const safeStats = computed(() => (statsData.value as any) || { total_resources: 0, total_categories: 0, total_tags: 0, total_views: 0, today_resources: 0 })
|
||||||
|
|||||||
Reference in New Issue
Block a user