init: web_hgcg_server 初始化提交

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-10-27 16:44:55 +08:00
co-authored by Claude Opus 4.7
commit 189556e702
627 changed files with 126228 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
package srv_ipstat
import (
"context"
"time"
"videoweb/pub/common/log"
"videoweb/pub/common/utils"
"videoweb/pub/models/ipdailystatmod"
"videoweb/pub/pubdef"
)
// IpStatResp 今日和昨日访问 IP 去重数。
type IpStatResp struct {
TodayIP int64 `json:"todayIP"`
YesterdayIP int64 `json:"yesterdayIP"`
}
// FetchIpStat 返回 app 端同步到 MongoDB 的每日访问 IP 去重数。
func FetchIpStat(ctx context.Context) *IpStatResp {
resp := &IpStatResp{}
now := time.Now().In(utils.LocBJ)
today := now.Format("20060102")
yesterday := now.AddDate(0, 0, -1).Format("20060102")
if cnt, err := ipdailystatmod.FindCount(ctx, pubdef.AppId, today); err == nil {
resp.TodayIP = cnt
} else {
log.Warn("FetchIpStat: FindCount today failed",
log.Any("appId", pubdef.AppId), log.E(err))
}
if cnt, err := ipdailystatmod.FindCount(ctx, pubdef.AppId, yesterday); err == nil {
resp.YesterdayIP = cnt
} else {
log.Warn("FetchIpStat: FindCount yesterday failed",
log.Any("appId", pubdef.AppId), log.E(err))
}
return resp
}