init: 初始化 web_hgdjb_server 项目

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-11-07 10:47:32 +08:00
co-authored by Claude Opus 4.7
commit f13d33af4d
707 changed files with 147705 additions and 0 deletions
+59
View File
@@ -0,0 +1,59 @@
package ipdailystatmod
import (
"context"
"time"
"videoweb/pub/mongos"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
var db *mongos.Collection
func Init(ctx context.Context) {
db = mongos.Shop.Coll(TN.IpDailyStat)
indexes := []mongo.IndexModel{
{
Keys: bson.D{
{Key: FN.IpDailyStat.AppId, Value: 1},
{Key: FN.IpDailyStat.Date, Value: 1},
},
Options: options.Index().SetUnique(true),
},
}
_, _ = db.CreateIndex(ctx, indexes)
}
func UpsertCount(ctx context.Context, appId int64, date string, count int64) error {
filter := bson.M{
FN.IpDailyStat.AppId: appId,
FN.IpDailyStat.Date: date,
}
update := bson.M{
"$set": bson.M{
FN.IpDailyStat.Count: count,
FN.IpDailyStat.UpdatedAt: time.Now(),
},
}
_, err := db.UpsertOne(ctx, filter, update)
return err
}
func FindCount(ctx context.Context, appId int64, date string) (int64, error) {
filter := bson.M{
FN.IpDailyStat.AppId: appId,
FN.IpDailyStat.Date: date,
}
var stat IpDailyStat
err := db.FindOneEx(ctx, &stat, filter)
if err != nil {
if err == mongo.ErrNoDocuments {
return 0, nil
}
return 0, err
}
return stat.Count, nil
}
+25
View File
@@ -0,0 +1,25 @@
package ipdailystatmod
type tagIpDailyStat struct {
AppId string
Date string
Count string
UpdatedAt string
}
var FN struct {
IpDailyStat tagIpDailyStat
}
var TN struct {
IpDailyStat string
}
func init() {
FN.IpDailyStat.AppId = "appId"
FN.IpDailyStat.Date = "date"
FN.IpDailyStat.Count = "count"
FN.IpDailyStat.UpdatedAt = "updatedAt"
TN.IpDailyStat = "ip_daily_stat"
}
+12
View File
@@ -0,0 +1,12 @@
package ipdailystatmod
import "time"
// IpDailyStat 每日访客 IP 去重统计。
// @table:ip_daily_stat
type IpDailyStat struct {
AppId int64 `bson:"appId"` // 站点 ID
Date string `bson:"date"` // 日期,格式 "20060102"
Count int64 `bson:"count"` // 当日去重 IP 数
UpdatedAt time.Time `bson:"updatedAt"` // 最后同步时间
}