Initial commit

This commit is contained in:
2026-05-20 16:13:58 +08:00
commit ceffbe382e
500 changed files with 157469 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
package tfpackagemod
type TagTfPackage struct {
AppId string
CountDownloadNum string
CreatedAt string
DayDownloadedNum string
DayMaxDownloadNum string
DownloadUrl string
HourDLNum string
HourMaxDownloadNum string
Id string
LastDownloadTime string
OffTime string
OnTime string
Status string
UpdatedAt string
}
var FN struct {
TfPackage TagTfPackage
}
var TN struct {
TfPackage string
}
func init() {
FN.TfPackage.AppId = "appId"
FN.TfPackage.CountDownloadNum = "countDownloadNum"
FN.TfPackage.CreatedAt = "createdAt"
FN.TfPackage.DayDownloadedNum = "dayDownloadedNum"
FN.TfPackage.DayMaxDownloadNum = "dayMaxDownloadNum"
FN.TfPackage.DownloadUrl = "downloadUrl"
FN.TfPackage.HourDLNum = "hourDlNum"
FN.TfPackage.HourMaxDownloadNum = "hourMaxDownloadNum"
FN.TfPackage.Id = "_id"
FN.TfPackage.LastDownloadTime = "lastDownloadTime"
FN.TfPackage.OffTime = "offTime"
FN.TfPackage.OnTime = "onTime"
FN.TfPackage.Status = "status"
FN.TfPackage.UpdatedAt = "updatedAt"
TN.TfPackage = "tf_package"
}
+133
View File
@@ -0,0 +1,133 @@
package tfpackagemod
import (
"context"
"fmt"
"stat/common/log"
"stat/common/mongos"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
var db *mongos.MongoTool
func Init(ctx context.Context) {
// 获取数据库表
db = mongos.New(mongos.MgoManager, TN.TfPackage)
// 初始化索引
indexes := []mongo.IndexModel{
{
Keys: bson.D{
{Key: FN.TfPackage.AppId, Value: 1},
},
},
{
Keys: bson.D{
{Key: FN.TfPackage.Id, Value: 1},
{Key: FN.TfPackage.AppId, Value: 1},
},
},
}
if _, err := db.CreateIndex(ctx, indexes); err != nil {
panic(fmt.Sprintf("(TfPackage:initTfPackageIndex) Create TfPackage Index failed! err:%+v:", err))
}
}
//InsertOneTfPackage 插入一个VIP购买记录
func InsertOneTfPackage(ctx context.Context, TfPackage *TfPackage) error {
if _, err := db.InsertOne(ctx, TfPackage); err != nil {
log.Warn("TfPackage:InsertOneTfPackage db.InsertOne failed", log.E(err))
return err
}
return nil
}
//FindOneTfPackage 查找一个VIP购买记录
func FindOneTfPackage(ctx context.Context, filter bson.M) (
*TfPackage, error) {
var TfPackage TfPackage
if err := db.FindOne(ctx, &TfPackage, filter); err != nil {
return nil, err
}
return &TfPackage, nil
}
//DelOneTfPackage 删除一个VIP购买记录
func DelOneTfPackage(ctx context.Context, filter bson.M) (
int64, error) {
count, err := db.DeleteOne(ctx, filter)
if err != nil {
log.Warn("TfPackage:DelOneTfPackage db.DeleteOne failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
//UpdateOneTfPackage 更新一个VIP购买记录
func UpdateOneTfPackage(ctx context.Context, filter bson.M, update bson.M) error {
_, err := db.UpdateOne(ctx, filter, update)
if err != nil {
log.Warn("user:UpdateOneTfPackage db.UpdateOne failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
//CountTfPackages 统计VIP购买记录数量
func CountTfPackages(ctx context.Context, filter bson.M) (
int64, error) {
count, err := db.Count(ctx, filter)
if err != nil {
log.Warn("TfPackage:CountTfPackages db.Count failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
//UpdateManyTfPackage 更新满足条件的VIP购买记录
func UpdateManyTfPackage(ctx context.Context, filter bson.M, update bson.M) error {
_, err := db.UpdateMany(ctx, filter, update)
if err != nil {
log.Warn("user:UpdateManyTfPackage db.UpdateMany failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
//FindManyTfPackage 查找一批VIP购买记录数据
func FindManyTfPackage(ctx context.Context, filter bson.M,
opts ...*options.FindOptions) (TfPackageList, error) {
data := make(TfPackageList, 0)
if err := db.Find(ctx, &data, filter, opts...); err != nil {
log.Warn("TfPackage:FindManyTfPackage db.Find failed", log.E(err), log.Any("filter", filter))
return nil, err
}
return data, nil
}
//FindManyTfPackageWithBind 用自己定义结构查找一批VIP购买记录数据
func FindManyTfPackageWithBind(ctx context.Context, bind interface{}, filter bson.M,
opts ...*options.FindOptions) error {
if err := db.Find(ctx, bind, filter, opts...); err != nil {
log.Warn("TfPackage:FindManyTfPackageWithBind db.Find failed", log.E(err), log.Any("filter", filter))
return err
}
return nil
}
//AggregateTfPackages 聚合查找一批VIP购买记录信息
func AggregateTfPackages(ctx context.Context,
bind interface{}, pipeline []bson.M) error {
if err := db.Aggregate(ctx, bind, pipeline); err != nil {
log.Warn("feedback:AggregateTfPackages db.Aggregate failed",
log.E(err), log.Any("pipeline", pipeline))
return err
}
return nil
}
+35
View File
@@ -0,0 +1,35 @@
package tfpackagemod
import (
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
)
// @table:tf_package
type TfPackage struct {
Id primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"`
AppId int32 `bson:"appId" json:"appId"` // appID
DownloadUrl string `bson:"downloadUrl" json:"downloadUrl"` // 下载链接
CountDownloadNum int64 `bson:"countDownloadNum" json:"countDownloadNum"` // 总已经下载数量
DayMaxDownloadNum int64 `bson:"dayMaxDownloadNum" json:"dayMaxDownloadNum"` // 当天设置最大下载数量
DayDownloadedNum int64 `bson:"dayDownloadedNum" json:"dayDownloadedNum"` // 当天已经下载数量
HourMaxDownloadNum int64 `bson:"hourMaxDownloadNum" json:"hourMaxDownloadNum"` // 每小时设置最大下载数量
HourDLNum int64 `bson:"hourDlNum" json:"hourDlNum"` // 每小时实际下载数量
LastDownloadTime time.Time `bson:"lastDownloadTime" json:"lastDownloadTime"` // 上一次下载时间
Status TFStatus `bson:"status" json:"status"` // 状态;0未使用,1下架,2上架
OnTime time.Time `bson:"onTime" json:"onTime"` // 上架时间
OffTime time.Time `bson:"offTime" json:"offTime"` // 下架时间
CreatedAt time.Time `bson:"createdAt" json:"createdAt"` // 创建时间
UpdatedAt time.Time `bson:"updatedAt" json:"updatedAt"` // 更新时间
}
type TfPackageList []*TfPackage
type TFStatus int8
const (
TFUnUsed TFStatus = 0 + iota // 未使用
TFOffShelf // 下架
TFOnShelf // 上架
)