Initial commit
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,182 @@
|
||||
package analyticsdailystat
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"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.AnalyticsDailyInfo)
|
||||
// 获取数据库表
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.AnalyticsDailyInfo.AppId, Value: 1},
|
||||
{Key: FN.AnalyticsDailyInfo.CreatedAt, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.AnalyticsDailyInfo.SumDate, Value: 1},
|
||||
{Key: FN.AnalyticsDailyInfo.AppId, Value: 1},
|
||||
},
|
||||
Options: options.Index().SetUnique(true),
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.AnalyticsDailyInfo.CreatedAt, Value: -1},
|
||||
},
|
||||
},
|
||||
}
|
||||
if _, err := db.CreateIndex(ctx, indexes); err != nil {
|
||||
panic(fmt.Sprintf("(AnalyticsDailyInfo:initAnalyticsDailyInfoIndex) Create AnalyticsDailyInfo Index failed! err:%+v:", err))
|
||||
}
|
||||
}
|
||||
|
||||
// InsertOneAnalyticsDailyInfo 插入一个评论
|
||||
func InsertOneAnalyticsDailyInfo(ctx context.Context, AnalyticsDailyInfo *AnalyticsDailyInfo) *srvdef.SrvErr {
|
||||
if _, err := db.InsertOne(ctx, AnalyticsDailyInfo); err != nil {
|
||||
log.Warn("AnalyticsDailyInfo:InsertOneAnalyticsDailyInfo db.InsertOne failed", log.E(err))
|
||||
return srvdef.New(srvdef.ErrDbInsertError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DelOneAnalyticsDailyInfo 删除一个评论
|
||||
func DelOneAnalyticsDailyInfo(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.DeleteOne(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("AnalyticsDailyInfo:DelOneAnalyticsDailyInfo db.DeleteOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbDeleteError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// DelManyAnalyticsDailyInfo 删除一个评论评论
|
||||
func DelManyAnalyticsDailyInfo(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.DeleteMany(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("AnalyticsDailyInfo:DelOneAnalyticsDailyInfo db.DeleteOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbDeleteError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// FindOneAnalyticsDailyInfo 查找一个评论
|
||||
func FindOneAnalyticsDailyInfo(ctx context.Context, filter bson.M, opts ...*options.FindOneOptions) (
|
||||
*AnalyticsDailyInfo, *srvdef.SrvErr) {
|
||||
var AnalyticsDailyInfo AnalyticsDailyInfo
|
||||
if err := db.FindOneEx(
|
||||
ctx, &AnalyticsDailyInfo, filter, opts...); err != nil {
|
||||
if err != mongo.ErrNoDocuments {
|
||||
log.Info("AnalyticsDailyInfo:FindOneAnalyticsDailyInfo db.FindOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return nil, srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return &AnalyticsDailyInfo, nil
|
||||
}
|
||||
|
||||
// CountAnalyticsDailyInfos 统计评论视频评论数量
|
||||
func CountAnalyticsDailyInfos(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.Count(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("AnalyticsDailyInfo:CountAnalyticsDailyInfos db.Count failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// UpdateOneAnalyticsDailyInfo 更新一个评论
|
||||
func UpdateOneAnalyticsDailyInfo(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
||||
result, err := db.UpdateOne(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("AnalyticsDailyInfo:UpdateOneAnalyticsDailyInfo db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
if result.MatchedCount != 1 {
|
||||
log.Warn("AnalyticsDailyInfo:UpdateOneAnalyticsDailyInfo db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateManyAnalyticsDailyInfo 更新一批评论
|
||||
func UpdateManyAnalyticsDailyInfo(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
||||
result, err := db.UpdateMMany(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("AnalyticsDailyInfo:UpdateManyAnalyticsDailyInfo db.UpdateMMany failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
if result.MatchedCount <= 0 {
|
||||
log.Warn("AnalyticsDailyInfo:UpdateManyAnalyticsDailyInfo db.UpdateMMany failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
//return srvdef.New(srvdef.ErrAnalyticsDailyInfoNotExsit, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// FindManyAnalyticsDailyInfo 查找一批评论
|
||||
func FindManyAnalyticsDailyInfo(ctx context.Context, filter bson.M,
|
||||
opts ...*options.FindOptions) (AnalyticsDailyInfoList, *srvdef.SrvErr) {
|
||||
data := make(AnalyticsDailyInfoList, 0)
|
||||
if err := db.Find(ctx, &data, filter, opts...); err != nil {
|
||||
log.Warn("AnalyticsDailyInfo:FindManyAnalyticsDailyInfo db.Find failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// InsertManyAnalyticsDailyInfo 插入一批用户
|
||||
func InsertManyAnalyticsDailyInfo(ctx context.Context, histrory *AnalyticsDailyInfoList) *srvdef.SrvErr {
|
||||
if _, err := db.InsertMany(ctx, histrory); err != nil {
|
||||
log.Warn("AnalyticsDailyInfo:InsertManyAnalyticsDailyInfo db.InsertMany failed", log.E(err))
|
||||
return srvdef.New(srvdef.ErrDbInsertError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AggregateAnalyticsDailyInfo 聚合查找一批数据
|
||||
func AggregateAnalyticsDailyInfo(ctx context.Context,
|
||||
bind interface{}, pipeline []bson.M) *srvdef.SrvErr {
|
||||
if err := db.Aggregate(ctx, bind, pipeline); err != nil {
|
||||
log.Warn("AnalyticsDailyInfo:AggregateAnalyticsDailyInfo db.Aggregate failed",
|
||||
log.E(err), log.Any("pipeline", pipeline))
|
||||
return srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ObjectAggregateAnalyticsDailyInfo 聚合查找一批数据
|
||||
func ObjectAggregateAnalyticsDailyInfo(ctx context.Context,
|
||||
bind interface{}, pipeline []bson.M) *srvdef.SrvErr {
|
||||
if err := db.ObjectAggregate(ctx, bind, pipeline); err != nil {
|
||||
log.Warn("AnalyticsDailyInfo:AggregateAnalyticsDailyInfo db.Aggregate failed",
|
||||
log.E(err), log.Any("pipeline", pipeline))
|
||||
return srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Executable
+42
@@ -0,0 +1,42 @@
|
||||
package analyticsdailystat
|
||||
|
||||
type TagAnalyticsDailyInfo struct {
|
||||
AppId string
|
||||
AppName string
|
||||
CreatedAt string
|
||||
Id string
|
||||
LeadAmount string
|
||||
LeadNewCount string
|
||||
SumDate string
|
||||
UpdatedAt string
|
||||
YestodayActiveUsers string
|
||||
YestodayNewUsers string
|
||||
YestodayPV string
|
||||
YestodaySessions string
|
||||
YestodayUV string
|
||||
}
|
||||
|
||||
var FN struct {
|
||||
AnalyticsDailyInfo TagAnalyticsDailyInfo
|
||||
}
|
||||
|
||||
var TN struct {
|
||||
AnalyticsDailyInfo string
|
||||
}
|
||||
|
||||
func init() {
|
||||
FN.AnalyticsDailyInfo.AppId = "appId"
|
||||
FN.AnalyticsDailyInfo.AppName = "appName"
|
||||
FN.AnalyticsDailyInfo.CreatedAt = "createdAt"
|
||||
FN.AnalyticsDailyInfo.Id = "_id"
|
||||
FN.AnalyticsDailyInfo.LeadAmount = "leadAmount"
|
||||
FN.AnalyticsDailyInfo.LeadNewCount = "leadNewCount"
|
||||
FN.AnalyticsDailyInfo.SumDate = "sumDate"
|
||||
FN.AnalyticsDailyInfo.UpdatedAt = "updatedAt"
|
||||
FN.AnalyticsDailyInfo.YestodayActiveUsers = "yestodayActiveUsers"
|
||||
FN.AnalyticsDailyInfo.YestodayNewUsers = "yestodayNewUsers"
|
||||
FN.AnalyticsDailyInfo.YestodayPV = "yestodayPV"
|
||||
FN.AnalyticsDailyInfo.YestodaySessions = "yestodaySessions"
|
||||
FN.AnalyticsDailyInfo.YestodayUV = "yestodayUV"
|
||||
TN.AnalyticsDailyInfo = "analytics_daily_info"
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package analyticsdailystat
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
// 数据统计
|
||||
// @table:analytics_daily_info
|
||||
type AnalyticsDailyInfo struct {
|
||||
Id primitive.ObjectID `bson:"_id,omitempty"`
|
||||
SumDate time.Time `json:"sumDate" bson:"sumDate"` // 时间半小时
|
||||
AppId int64 `json:"appId" bson:"appId"` // appId
|
||||
AppName string `json:"appName" bson:"appName"` // APP名称
|
||||
YestodayPV int64 `json:"yestodayPV" bson:"yestodayPV"` // 页面浏览量 (PV)
|
||||
YestodayUV int64 `json:"yestodayUV" bson:"yestodayUV"` // 独立用户数 (UV)
|
||||
YestodayActiveUsers int64 `json:"yestodayActiveUsers" bson:"yestodayActiveUsers"` // 活跃用户数
|
||||
YestodaySessions int64 `json:"yestodaySessions" bson:"yestodaySessions"` // 会话数
|
||||
YestodayNewUsers int64 `json:"yestodayNewUsers" bson:"yestodayNewUsers"` // 新增数量
|
||||
LeadNewCount float64 `json:"leadNewCount" bson:"leadNewCount"` // 日导量新增
|
||||
LeadAmount float64 `json:"leadAmount" bson:"leadAmount"` // 日导量充值
|
||||
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` // 更新时间
|
||||
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` // 创建时间
|
||||
}
|
||||
|
||||
type AnalyticsDailyInfoList []*AnalyticsDailyInfo
|
||||
@@ -0,0 +1,182 @@
|
||||
package analyticsstat
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"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.AnalyticsInfo)
|
||||
// 获取数据库表
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.AnalyticsInfo.AppId, Value: 1},
|
||||
{Key: FN.AnalyticsInfo.CreatedAt, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.AnalyticsInfo.SumDate, Value: 1},
|
||||
{Key: FN.AnalyticsInfo.AppId, Value: 1},
|
||||
},
|
||||
Options: options.Index().SetUnique(true),
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.AnalyticsInfo.CreatedAt, Value: -1},
|
||||
},
|
||||
},
|
||||
}
|
||||
if _, err := db.CreateIndex(ctx, indexes); err != nil {
|
||||
panic(fmt.Sprintf("(AnalyticsInfo:initAnalyticsInfoIndex) Create AnalyticsInfo Index failed! err:%+v:", err))
|
||||
}
|
||||
}
|
||||
|
||||
// InsertOneAnalyticsInfo 插入一个评论
|
||||
func InsertOneAnalyticsInfo(ctx context.Context, AnalyticsInfo *AnalyticsInfo) *srvdef.SrvErr {
|
||||
if _, err := db.InsertOne(ctx, AnalyticsInfo); err != nil {
|
||||
log.Warn("AnalyticsInfo:InsertOneAnalyticsInfo db.InsertOne failed", log.E(err))
|
||||
return srvdef.New(srvdef.ErrDbInsertError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DelOneAnalyticsInfo 删除一个评论
|
||||
func DelOneAnalyticsInfo(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.DeleteOne(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("AnalyticsInfo:DelOneAnalyticsInfo db.DeleteOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbDeleteError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// DelManyAnalyticsInfo 删除一个评论评论
|
||||
func DelManyAnalyticsInfo(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.DeleteMany(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("AnalyticsInfo:DelOneAnalyticsInfo db.DeleteOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbDeleteError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// FindOneAnalyticsInfo 查找一个评论
|
||||
func FindOneAnalyticsInfo(ctx context.Context, filter bson.M, opts ...*options.FindOneOptions) (
|
||||
*AnalyticsInfo, *srvdef.SrvErr) {
|
||||
var AnalyticsInfo AnalyticsInfo
|
||||
if err := db.FindOneEx(
|
||||
ctx, &AnalyticsInfo, filter, opts...); err != nil {
|
||||
if err != mongo.ErrNoDocuments {
|
||||
log.Info("AnalyticsInfo:FindOneAnalyticsInfo db.FindOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return nil, srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return &AnalyticsInfo, nil
|
||||
}
|
||||
|
||||
// CountAnalyticsInfos 统计评论视频评论数量
|
||||
func CountAnalyticsInfos(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.Count(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("AnalyticsInfo:CountAnalyticsInfos db.Count failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// UpdateOneAnalyticsInfo 更新一个评论
|
||||
func UpdateOneAnalyticsInfo(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
||||
result, err := db.UpdateOne(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("AnalyticsInfo:UpdateOneAnalyticsInfo db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
if result.MatchedCount != 1 {
|
||||
log.Warn("AnalyticsInfo:UpdateOneAnalyticsInfo db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateManyAnalyticsInfo 更新一批评论
|
||||
func UpdateManyAnalyticsInfo(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
||||
result, err := db.UpdateMMany(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("AnalyticsInfo:UpdateManyAnalyticsInfo db.UpdateMMany failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
if result.MatchedCount <= 0 {
|
||||
log.Warn("AnalyticsInfo:UpdateManyAnalyticsInfo db.UpdateMMany failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
//return srvdef.New(srvdef.ErrAnalyticsInfoNotExsit, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// FindManyAnalyticsInfo 查找一批评论
|
||||
func FindManyAnalyticsInfo(ctx context.Context, filter bson.M,
|
||||
opts ...*options.FindOptions) (AnalyticsInfoList, *srvdef.SrvErr) {
|
||||
data := make(AnalyticsInfoList, 0)
|
||||
if err := db.Find(ctx, &data, filter, opts...); err != nil {
|
||||
log.Warn("AnalyticsInfo:FindManyAnalyticsInfo db.Find failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// InsertManyAnalyticsInfo 插入一批用户
|
||||
func InsertManyAnalyticsInfo(ctx context.Context, histrory *AnalyticsInfoList) *srvdef.SrvErr {
|
||||
if _, err := db.InsertMany(ctx, histrory); err != nil {
|
||||
log.Warn("AnalyticsInfo:InsertManyAnalyticsInfo db.InsertMany failed", log.E(err))
|
||||
return srvdef.New(srvdef.ErrDbInsertError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AggregateAnalyticsInfo 聚合查找一批数据
|
||||
func AggregateAnalyticsInfo(ctx context.Context,
|
||||
bind interface{}, pipeline []bson.M) *srvdef.SrvErr {
|
||||
if err := db.Aggregate(ctx, bind, pipeline); err != nil {
|
||||
log.Warn("AnalyticsInfo:AggregateAnalyticsInfo db.Aggregate failed",
|
||||
log.E(err), log.Any("pipeline", pipeline))
|
||||
return srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ObjectAggregateAnalyticsInfo 聚合查找一批数据
|
||||
func ObjectAggregateAnalyticsInfo(ctx context.Context,
|
||||
bind interface{}, pipeline []bson.M) *srvdef.SrvErr {
|
||||
if err := db.ObjectAggregate(ctx, bind, pipeline); err != nil {
|
||||
log.Warn("AnalyticsInfo:AggregateAnalyticsInfo db.Aggregate failed",
|
||||
log.E(err), log.Any("pipeline", pipeline))
|
||||
return srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Executable
+42
@@ -0,0 +1,42 @@
|
||||
package analyticsstat
|
||||
|
||||
type TagAnalyticsInfo struct {
|
||||
ActiveUsers string
|
||||
AppId string
|
||||
AppName string
|
||||
CreatedAt string
|
||||
DaySumDate string
|
||||
Id string
|
||||
SumDate string
|
||||
UpdatedAt string
|
||||
YestodayActiveUsers string
|
||||
YestodayNewUsers string
|
||||
YestodayPV string
|
||||
YestodaySessions string
|
||||
YestodayUV string
|
||||
}
|
||||
|
||||
var FN struct {
|
||||
AnalyticsInfo TagAnalyticsInfo
|
||||
}
|
||||
|
||||
var TN struct {
|
||||
AnalyticsInfo string
|
||||
}
|
||||
|
||||
func init() {
|
||||
FN.AnalyticsInfo.ActiveUsers = "activeUsers"
|
||||
FN.AnalyticsInfo.AppId = "appId"
|
||||
FN.AnalyticsInfo.AppName = "appName"
|
||||
FN.AnalyticsInfo.CreatedAt = "createdAt"
|
||||
FN.AnalyticsInfo.DaySumDate = "daySumDate"
|
||||
FN.AnalyticsInfo.Id = "_id"
|
||||
FN.AnalyticsInfo.SumDate = "sumDate"
|
||||
FN.AnalyticsInfo.UpdatedAt = "updatedAt"
|
||||
FN.AnalyticsInfo.YestodayActiveUsers = "yestodayActiveUsers"
|
||||
FN.AnalyticsInfo.YestodayNewUsers = "yestodayNewUsers"
|
||||
FN.AnalyticsInfo.YestodayPV = "yestodayPV"
|
||||
FN.AnalyticsInfo.YestodaySessions = "yestodaySessions"
|
||||
FN.AnalyticsInfo.YestodayUV = "yestodayUV"
|
||||
TN.AnalyticsInfo = "analytics_info"
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package analyticsstat
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
// 数据统计
|
||||
// @table:analytics_info
|
||||
type AnalyticsInfo struct {
|
||||
Id primitive.ObjectID `bson:"_id,omitempty"`
|
||||
SumDate time.Time `json:"sumDate" bson:"sumDate"` // 时间半小时
|
||||
DaySumDate time.Time `json:"daySumDate" bson:"daySumDate"` // 当天
|
||||
AppId int64 `json:"appId" bson:"appId"` // appId
|
||||
AppName string `json:"appName" bson:"appName"` // APP名称
|
||||
ActiveUsers int64 `json:"activeUsers" bson:"activeUsers"` // 最近半小时活跃数
|
||||
YestodayPV int64 `json:"yestodayPV" bson:"yestodayPV"` // 页面浏览量 (PV)
|
||||
YestodayUV int64 `json:"yestodayUV" bson:"yestodayUV"` // 独立用户数 (UV)
|
||||
YestodayActiveUsers int64 `json:"yestodayActiveUsers" bson:"yestodayActiveUsers"` // 活跃用户数
|
||||
YestodaySessions int64 `json:"yestodaySessions" bson:"yestodaySessions"` // 会话数
|
||||
YestodayNewUsers int64 `json:"yestodayNewUsers" bson:"yestodayNewUsers"` // 新增数量
|
||||
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` // 更新时间
|
||||
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` // 创建时间
|
||||
}
|
||||
|
||||
type AnalyticsInfoList []*AnalyticsInfo
|
||||
@@ -0,0 +1,9 @@
|
||||
package cfg
|
||||
|
||||
import (
|
||||
"videoweb/pub/mongos"
|
||||
)
|
||||
|
||||
var (
|
||||
sysCfgColl *mongos.Collection
|
||||
)
|
||||
@@ -0,0 +1,55 @@
|
||||
package cfg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/mongos"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
)
|
||||
|
||||
// Init 初始化数据
|
||||
func Init(ctx context.Context) {
|
||||
sysCfgColl = mongos.Shop.Coll(TN.SysCfg)
|
||||
}
|
||||
|
||||
// FindOneSysCfg 查找一个系统配置
|
||||
func FindOneSysCfg(ctx context.Context, filter bson.M) (
|
||||
*SysCfg, *srvdef.SrvErr) {
|
||||
var sysCfg SysCfg
|
||||
if err := sysCfgColl.FindOneEx(
|
||||
ctx, &sysCfg, filter); err != nil {
|
||||
if err != mongo.ErrNoDocuments {
|
||||
log.Info("cfg:FindOneSysCfg db.FindOneEx failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return &sysCfg, nil
|
||||
}
|
||||
|
||||
// UpdateOneSysCfg 更新一个系统配置
|
||||
func UpdateOneSysCfg(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
||||
result, err := sysCfgColl.UpdateOne(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("cfg:UpdateOneSysCfg db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
if result.MatchedCount != 1 {
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func DeleteOneSysCfg(ctx context.Context, filter bson.M) *srvdef.SrvErr {
|
||||
_, err := sysCfgColl.DeleteOne(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("cfg:DeleteOneSysCfg db.DeleteOne failed", log.Any("filter", filter), log.E(err))
|
||||
return srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Executable
+68
@@ -0,0 +1,68 @@
|
||||
package cfg
|
||||
|
||||
type TagSysCfg struct {
|
||||
AppAddr string
|
||||
ForeverUrlAddr string
|
||||
GitAddr string
|
||||
GmailAddr string
|
||||
Id string
|
||||
ImgAppCdn string
|
||||
ImgWebCdn string
|
||||
MediaAppCdn string
|
||||
MediaWebCdn string
|
||||
NewUrlAddr string
|
||||
NewUrlAddr1 string
|
||||
NewUrlAddr2 string
|
||||
QQ string
|
||||
Telegram string
|
||||
TelegramAdd string
|
||||
TgGroup string
|
||||
TranslationAddr string
|
||||
TwitterAddr string
|
||||
WatermarkImage string
|
||||
WatermarkMedia string
|
||||
WatermarkMediaTop string
|
||||
WeiChart string
|
||||
DHNewUrlAddr1 string
|
||||
DHNewUrlAddr2 string
|
||||
DHNewUrlAddr3 string
|
||||
DHForeverUrlAddr string
|
||||
}
|
||||
|
||||
var FN struct {
|
||||
SysCfg TagSysCfg
|
||||
}
|
||||
|
||||
var TN struct {
|
||||
SysCfg string
|
||||
}
|
||||
|
||||
func init() {
|
||||
FN.SysCfg.AppAddr = "appAddr"
|
||||
FN.SysCfg.ForeverUrlAddr = "foreverUrlAddr"
|
||||
FN.SysCfg.GitAddr = "gitAddr"
|
||||
FN.SysCfg.GmailAddr = "gmailAddr"
|
||||
FN.SysCfg.Id = "_id"
|
||||
FN.SysCfg.ImgAppCdn = "imgAppCdn"
|
||||
FN.SysCfg.ImgWebCdn = "imgWebCdn"
|
||||
FN.SysCfg.MediaAppCdn = "mediaAppCdn"
|
||||
FN.SysCfg.MediaWebCdn = "mediaWebCdn"
|
||||
FN.SysCfg.NewUrlAddr = "newUrlAddr"
|
||||
FN.SysCfg.NewUrlAddr1 = "newUrlAddr1"
|
||||
FN.SysCfg.NewUrlAddr2 = "newUrlAddr2"
|
||||
FN.SysCfg.QQ = "qq"
|
||||
FN.SysCfg.Telegram = "telegram"
|
||||
FN.SysCfg.TelegramAdd = "telegramAdd"
|
||||
FN.SysCfg.TgGroup = "tgGroup"
|
||||
FN.SysCfg.TranslationAddr = "translationAddr"
|
||||
FN.SysCfg.TwitterAddr = "twitterAddr"
|
||||
FN.SysCfg.WatermarkImage = "watermarkImage"
|
||||
FN.SysCfg.WatermarkMedia = "watermarkMedia"
|
||||
FN.SysCfg.WatermarkMediaTop = "watermarkMediaTop"
|
||||
FN.SysCfg.WeiChart = "weiChart"
|
||||
FN.SysCfg.DHNewUrlAddr1 = "dHNewUrlAddr1"
|
||||
FN.SysCfg.DHNewUrlAddr2 = "dHNewUrlAddr2"
|
||||
FN.SysCfg.DHNewUrlAddr3 = "dHNewUrlAddr3"
|
||||
FN.SysCfg.DHForeverUrlAddr = "dHForeverUrlAddr"
|
||||
TN.SysCfg = "sys_cfg"
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package cfg
|
||||
|
||||
// @table:sys_cfg
|
||||
type SysCfg struct {
|
||||
Id int64 `json:"id" bson:"_id"`
|
||||
UnencryptedCdn string `json:"unencryptedCdn" bson:"unencryptedCdn"` // 不加密资源使用的cdn
|
||||
SitemapDefaultImages []string `json:"sitemapDefaultImages" bson:"sitemapDefaultImages"` // Sitemap里面默认封面图
|
||||
ImgAppCdn string `json:"imgAppCdn" bson:"imgAppCdn"` // 图片CDN(app使用)
|
||||
ImgWebCdn string `json:"imgWebCdn" bson:"imgWebCdn"` // 图片CDN(web使用)
|
||||
MediaWebCdn string `json:"mediaWebCdn" bson:"mediaWebCdn"` // 视频CDN(web使用)
|
||||
MediaAppCdn string `json:"mediaAppCdn" bson:"mediaAppCdn"` // 视频CDN(app使用)
|
||||
WatermarkImage string `json:"watermarkImage" bson:"watermarkImage"` // 图片水印文件
|
||||
WatermarkMedia string `json:"watermarkMedia" bson:"watermarkMedia"` // 视频水印文件(底部)
|
||||
WatermarkMediaTop string `json:"watermarkMediaTop" bson:"watermarkMediaTop"` // 视频水印文件(顶部)
|
||||
Mp4Addr string `json:"mp4Addr" bson:"mp4Addr"` // mp4地址(web使用)
|
||||
PdfAddr string `json:"pdfAddr" bson:"pdfAddr"` // 回家的路PDF
|
||||
//网站管理
|
||||
NewUrlAddr string `json:"newUrlAddr" bson:"newUrlAddr"` //最新地址
|
||||
NewUrlAddr1 string `json:"newUrlAddr1" bson:"newUrlAddr1"` //最新地址(备用地址1)
|
||||
NewUrlAddr2 string `json:"newUrlAddr2" bson:"newUrlAddr2"` //最新地址(备用地址2)
|
||||
ForeverUrlAddr string `json:"foreverUrlAddr" bson:"foreverUrlAddr"` //永久地址
|
||||
GmailAddr string `json:"gmailAddr" bson:"gmailAddr"` //邮箱地址
|
||||
AppAddr string `json:"appAddr" bson:"appAddr"` //APP下载地址(落地页)
|
||||
WeiChart string `json:"weiChart" bson:"weiChart"` //微信群
|
||||
QQ string `json:"qq" bson:"qq"` //qq群
|
||||
TgGroup string `json:"tgGroup" bson:"tgGroup"` //tg群
|
||||
PotaoGroup string `json:"potaoGroup" bson:"potaoGroup"` //土豆群
|
||||
GitAddr string `json:"gitAddr" bson:"gitAddr"` //git地址
|
||||
TwitterAddr string `json:"twitterAddr" bson:"twitterAddr"` //推特地址
|
||||
Telegram string `json:"telegram" bson:"telegram"` //商务tg
|
||||
TelegramAdd string `json:"telegramAdd" bson:"telegramAdd"` //加入我们tg
|
||||
TranslationAddr string `json:"translationAddr" bson:"translationAddr"` //应用导航
|
||||
//SEO
|
||||
WebTitle string `json:"webTitle" bson:"webTitle"` // 网站SEO标题
|
||||
WebKeyworld []string `json:"webKeyworld" bson:"webKeyworld"` // 网站SEO关键字
|
||||
WebDescription string `json:"webDescription" bson:"webDescription"` // 网站SEO描述
|
||||
WebSiteName string `json:"webSiteName" bson:"webSiteName"` // 网站SEO网站名称
|
||||
WebAddr string `json:"webAddr" bson:"webAddr"` // 网站SEO网站地址
|
||||
DHNewUrlAddr1 string `json:"dhNewUrlAddr1" bson:"dhNewUrlAddr1"` // 导航页-线路1
|
||||
DHNewUrlAddr2 string `json:"dhNewUrlAddr2" bson:"dhNewUrlAddr2"` // 导航页-线路2
|
||||
DHNewUrlAddr3 string `json:"dhNewUrlAddr3" bson:"dhNewUrlAddr3"` // 导航页-线路3
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
package commentmod
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"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.Comment)
|
||||
// 获取数据库表
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.Comment.ObjectId, Value: 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.Comment.Id, Value: 1},
|
||||
{Key: FN.Comment.CreatedAt, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.Comment.CreatedAt, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.Comment.ObjectId, Value: 1},
|
||||
{Key: FN.Comment.ReviewStatus, Value: 1},
|
||||
{Key: FN.Comment.Level, Value: 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.Comment.ObjectId, Value: 1},
|
||||
{Key: FN.Comment.ReviewStatus, Value: 1},
|
||||
{Key: FN.Comment.Level, Value: 1},
|
||||
{Key: FN.Comment.CreatedAt, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.Comment.ParentsId, Value: 1},
|
||||
{Key: FN.Comment.ReviewStatus, Value: 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.Comment.TopRank, Value: -1},
|
||||
},
|
||||
},
|
||||
}
|
||||
if _, err := db.CreateIndex(ctx, indexes); err != nil {
|
||||
panic(fmt.Sprintf("(comment:initCommentIndex) Create Comment Index failed! err:%+v:", err))
|
||||
}
|
||||
}
|
||||
|
||||
// InsertOneComment 插入一个评论
|
||||
func InsertOneComment(ctx context.Context, Comment *CommentModel) *srvdef.SrvErr {
|
||||
if _, err := db.InsertOne(ctx, Comment); err != nil {
|
||||
log.Warn("comment:InsertOneComment db.InsertOne failed", log.E(err))
|
||||
return srvdef.New(srvdef.ErrDbInsertError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DelOneComment 删除一个评论
|
||||
func DelOneComment(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.DeleteOne(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("comment:DelOneComment db.DeleteOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbDeleteError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// DelManyComment 删除一个评论评论
|
||||
func DelManyComment(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.DeleteMany(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("comment:DelOneComment db.DeleteOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbDeleteError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// FindOneComment 查找一个评论
|
||||
func FindOneComment(ctx context.Context, filter bson.M, opts ...*options.FindOneOptions) (
|
||||
*CommentModel, *srvdef.SrvErr) {
|
||||
var Comment CommentModel
|
||||
if err := db.FindOneEx(
|
||||
ctx, &Comment, filter, opts...); err != nil {
|
||||
if err != mongo.ErrNoDocuments {
|
||||
log.Info("comment:FindOneComment db.FindOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return nil, srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return &Comment, nil
|
||||
}
|
||||
|
||||
// CountComments 统计评论视频评论数量
|
||||
func CountComments(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.Count(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("comment:CountComments db.Count failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// UpdateOneComment 更新一个评论
|
||||
func UpdateOneComment(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
||||
result, err := db.UpdateOne(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("comment:UpdateOneComment db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
if result.MatchedCount != 1 {
|
||||
log.Warn("comment:UpdateOneComment db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateManyComment 更新一批评论
|
||||
func UpdateManyComment(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
||||
result, err := db.UpdateMMany(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("comment:UpdateManyComment db.UpdateMMany failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
if result.MatchedCount <= 0 {
|
||||
log.Warn("comment:UpdateManyComment db.UpdateMMany failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
//return srvdef.New(srvdef.ErrCommentNotExsit, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// FindManyComment 查找一批评论
|
||||
func FindManyComment(ctx context.Context, filter bson.M,
|
||||
opts ...*options.FindOptions) (CommentModelList, *srvdef.SrvErr) {
|
||||
data := make(CommentModelList, 0)
|
||||
if err := db.Find(ctx, &data, filter, opts...); err != nil {
|
||||
log.Warn("comment:FindManyComment db.Find failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// InsertManyComment 插入一批用户
|
||||
func InsertManyComment(ctx context.Context, histrory *CommentModelList) *srvdef.SrvErr {
|
||||
if _, err := db.InsertMany(ctx, histrory); err != nil {
|
||||
log.Warn("comment:InsertManyComment db.InsertMany failed", log.E(err))
|
||||
return srvdef.New(srvdef.ErrDbInsertError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AggregateComment 聚合查找一批数据
|
||||
func AggregateComment(ctx context.Context,
|
||||
bind interface{}, pipeline []bson.M) *srvdef.SrvErr {
|
||||
if err := db.Aggregate(ctx, bind, pipeline); err != nil {
|
||||
log.Warn("comment:AggregateComment db.Aggregate failed",
|
||||
log.E(err), log.Any("pipeline", pipeline))
|
||||
return srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ObjectAggregateComment 聚合查找一批数据
|
||||
func ObjectAggregateComment(ctx context.Context,
|
||||
bind interface{}, pipeline []bson.M) *srvdef.SrvErr {
|
||||
if err := db.ObjectAggregate(ctx, bind, pipeline); err != nil {
|
||||
log.Warn("comment:AggregateComment db.Aggregate failed",
|
||||
log.E(err), log.Any("pipeline", pipeline))
|
||||
return srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Executable
+44
@@ -0,0 +1,44 @@
|
||||
package commentmod
|
||||
|
||||
type TagComment struct {
|
||||
CreatedAt string
|
||||
Id string
|
||||
Level string
|
||||
ObjectId string
|
||||
ParentsId string
|
||||
ReplyUserName string
|
||||
Text string
|
||||
TopRank string
|
||||
UpdatedAt string
|
||||
UserName string
|
||||
ReviewStatus string
|
||||
CommentCount string
|
||||
Ip string
|
||||
ObjectName string
|
||||
}
|
||||
|
||||
var FN struct {
|
||||
Comment TagComment
|
||||
}
|
||||
|
||||
var TN struct {
|
||||
Comment string
|
||||
}
|
||||
|
||||
func init() {
|
||||
FN.Comment.CreatedAt = "createdAt"
|
||||
FN.Comment.Id = "_id"
|
||||
FN.Comment.Level = "level"
|
||||
FN.Comment.ObjectId = "objectId"
|
||||
FN.Comment.ParentsId = "parentsId"
|
||||
FN.Comment.ReplyUserName = "replyUserName"
|
||||
FN.Comment.Text = "text"
|
||||
FN.Comment.TopRank = "topRank"
|
||||
FN.Comment.UpdatedAt = "updatedAt"
|
||||
FN.Comment.UserName = "userName"
|
||||
FN.Comment.ReviewStatus = "reviewStatus"
|
||||
FN.Comment.Ip = "ip"
|
||||
FN.Comment.CommentCount = "commentCount"
|
||||
FN.Comment.ObjectName = "objectName"
|
||||
TN.Comment = "_comment"
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package commentmod
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// 评论管理
|
||||
// @table:comment
|
||||
type CommentModel struct {
|
||||
Id int64 `json:"id" bson:"_id,omitempty"` // 评论ID
|
||||
Ip string `json:"ip" bson:"ip"` // 评论IP
|
||||
ObjectId int64 `json:"objectId" bson:"objectId"` // 对象ID
|
||||
ObjectName string `json:"objectName" bson:"objectName"` // 对象名
|
||||
UserName string `json:"userName" bson:"userName"` // 用户名称
|
||||
Level int64 `json:"level" bson:"level"` // 评论级别
|
||||
ParentsId int64 `json:"parentsId" bson:"parentsId"` // 上级评论ID
|
||||
ReplyUserName string `json:"replyUserName" bson:"replyUserName"` // 回复名称
|
||||
Text string `json:"text" bson:"text"` // 评论内容
|
||||
CommentCount int64 `json:"commentCount" bson:"commentCount"` // 该评论回复数量
|
||||
ReviewStatus int `json:"reviewStatus" bson:"reviewStatus"` // 审核状态 0 未审核 1审核成功 2 审核失败
|
||||
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` // 更新时间
|
||||
CreatedAt time.Time `bson:"createdAt" json:"createdAt"` // 创建时间
|
||||
TopRank int64 `json:"topRank" bson:"topRank"` // 置顶排序
|
||||
}
|
||||
|
||||
type CommentModelList []*CommentModel
|
||||
@@ -0,0 +1,54 @@
|
||||
package esmod
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
"videoweb/pub/common/srvdef"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
const (
|
||||
FiveMinuteScale = 5 //对齐时间(分钟)
|
||||
)
|
||||
|
||||
var (
|
||||
videoIndex = "webmdgw_video_index_v3"
|
||||
)
|
||||
|
||||
func GetVideoIndex() string {
|
||||
return videoIndex
|
||||
}
|
||||
|
||||
func GetRecordByESIndex(ctx context.Context, esIndex string) (
|
||||
*ESTimestamp, *srvdef.SrvErr) {
|
||||
|
||||
filter := bson.M{FN.ESRecord.EsIndex: esIndex}
|
||||
esRecord, serr := FindOneESRecord(ctx, filter)
|
||||
if serr != nil {
|
||||
if serr.Code != srvdef.ErrNoData {
|
||||
return nil, serr
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
return &esRecord.Timestamp, nil
|
||||
}
|
||||
|
||||
func SetOneEsRecord(ctx context.Context, esIndex string,
|
||||
timestamp *ESTimestamp) *srvdef.SrvErr {
|
||||
filter := bson.M{FN.ESRecord.EsIndex: esIndex}
|
||||
upsertDoc := bson.M{
|
||||
"$set": bson.M{
|
||||
FN.ESRecord.Timestamp.T: timestamp.T,
|
||||
FN.ESRecord.Timestamp.I: timestamp.I,
|
||||
FN.ESRecord.UpdatedAt: time.Now(),
|
||||
},
|
||||
"$setOnInsert": bson.M{
|
||||
FN.ESRecord.Id: primitive.NewObjectID(),
|
||||
FN.ESRecord.CreatedAt: time.Now(),
|
||||
},
|
||||
}
|
||||
serr := UpsertOneESRecord(ctx, filter, upsertDoc)
|
||||
return serr
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
package esmod
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"videoweb/pub/esmanager"
|
||||
"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
|
||||
|
||||
// Init 初始化数据
|
||||
func Init(ctx context.Context) {
|
||||
initDBIndex(ctx)
|
||||
initIndex()
|
||||
return
|
||||
}
|
||||
|
||||
// initIndex 初始化索引
|
||||
func initIndex() {
|
||||
if esmanager.Instance == nil {
|
||||
return
|
||||
}
|
||||
initVideoIndex(videoIndex)
|
||||
}
|
||||
|
||||
// initDBIndex 初始化数据库索引
|
||||
func initDBIndex(ctx context.Context) {
|
||||
//获取数据库表
|
||||
db = mongos.Shop.Coll(TN.ESRecord)
|
||||
// 获取数据库表
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.ESRecord.EsIndex, Value: 1},
|
||||
},
|
||||
Options: options.Index().SetUnique(true),
|
||||
},
|
||||
}
|
||||
if _, err := db.CreateIndex(ctx, indexes); err != nil {
|
||||
panic(fmt.Sprintf("(esmod:initDBIndex) Create es_record Index failed! err:%+v:", err))
|
||||
}
|
||||
}
|
||||
|
||||
func initVideoIndex(esIndex string) {
|
||||
var setting = esmanager.M{
|
||||
"settings": esmanager.M{
|
||||
"number_of_shards": esmanager.NumberOfShards,
|
||||
"number_of_replicas": esmanager.NumberOfReplicas,
|
||||
"analysis": esmanager.M{
|
||||
"analyzer": esmanager.M{
|
||||
"ik": esmanager.M{
|
||||
"tokenizer": esmanager.AnalyzerIkSmart,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"mappings": esmanager.M{
|
||||
"properties": esmanager.M{
|
||||
FN.ESVideo.Title: esmanager.M{
|
||||
"type": "text",
|
||||
"analyzer": esmanager.AnalyzerIkMaxWord,
|
||||
"search_analyzer": esmanager.AnalyzerIkSmart,
|
||||
},
|
||||
FN.ESVideo.MediaType: esmanager.M{
|
||||
"type": "integer",
|
||||
},
|
||||
FN.ESVideo.Remark: esmanager.M{
|
||||
"type": "text",
|
||||
"analyzer": esmanager.AnalyzerIkSmart,
|
||||
"search_analyzer": esmanager.AnalyzerIkSmart,
|
||||
},
|
||||
FN.ESVideo.Desc: esmanager.M{
|
||||
"type": "text",
|
||||
"analyzer": esmanager.AnalyzerIkSmart,
|
||||
"search_analyzer": esmanager.AnalyzerIkSmart,
|
||||
},
|
||||
FN.ESVideo.Keyworld: esmanager.M{
|
||||
"type": "text",
|
||||
"analyzer": esmanager.AnalyzerIkSmart,
|
||||
"search_analyzer": esmanager.AnalyzerIkSmart,
|
||||
},
|
||||
FN.ESVideo.CreatorName: esmanager.M{
|
||||
"type": "text",
|
||||
"analyzer": esmanager.AnalyzerIkSmart,
|
||||
"search_analyzer": esmanager.AnalyzerIkSmart,
|
||||
},
|
||||
FN.ESVideo.Status: esmanager.M{
|
||||
"type": "integer",
|
||||
},
|
||||
//FN.ESVideo.IsHot: esmanager.M{
|
||||
// "type": "boolean",
|
||||
//},
|
||||
//FN.ESVideo.Sort: esmanager.M{
|
||||
// "type": "integer",
|
||||
//},
|
||||
FN.ESVideo.WatchTimes: esmanager.M{
|
||||
"type": "integer",
|
||||
},
|
||||
FN.ESVideo.ShowTimes: esmanager.M{
|
||||
"type": "integer",
|
||||
},
|
||||
FN.ESVideo.Comments: esmanager.M{
|
||||
"type": "integer",
|
||||
},
|
||||
FN.ESVideo.AddedTime: esmanager.M{
|
||||
"type": "date",
|
||||
"format": "strict_date_optional_time||epoch_millis||yyyy-MM-dd HH:mm:ss",
|
||||
},
|
||||
//FN.ESVideo.CreatedAt: esmanager.M{
|
||||
// "type": "date",
|
||||
// "format": "strict_date_optional_time||epoch_millis||yyyy-MM-dd HH:mm:ss",
|
||||
//},
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := esmanager.Instance.InitIndices(esIndex, setting); err != nil {
|
||||
panic(fmt.Sprintf("ElasticSearch Index %s initMediaIndex error", esIndex))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
package esmod
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"time"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/srvdef"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
// InsertOneESRecord 插入ES操作记录
|
||||
func InsertOneESRecord(ctx context.Context, esRecord *ESRecord) *srvdef.SrvErr {
|
||||
if _, err := db.InsertOne(ctx, esRecord); err != nil {
|
||||
log.Warn("esmod:InsertOneESRecord db.InsertOne failed", log.E(err))
|
||||
return srvdef.New(srvdef.ErrDbInsertError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DelOneESRecord 删除一个ES操作记录
|
||||
func DelOneESRecord(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.DeleteOne(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("esmod:DelOnAppTag db.DeleteOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbDeleteError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// FindOneESRecord 查找一个ES操作记录
|
||||
func FindOneESRecord(ctx context.Context, filter bson.M) (
|
||||
*ESRecord, *srvdef.SrvErr) {
|
||||
var esRecord ESRecord
|
||||
if err := db.FindOneEx(
|
||||
ctx, &esRecord, filter); err != nil {
|
||||
if err != mongo.ErrNoDocuments {
|
||||
log.Info("esmod:FindOnESRecord db.FindOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return nil, srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return &esRecord, nil
|
||||
}
|
||||
|
||||
// CountESRecords 统计ES操作记录
|
||||
func CountESRecords(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.Count(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("esmod:CountMediaCats db.Count failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// UpdateOneESRecord 更新ES操作记录
|
||||
func UpdateOneESRecord(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
||||
result, err := db.UpdateOne(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("esmod:UpdateOnESRecord db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
if result.MatchedCount != 1 {
|
||||
log.Warn("esmod:UpdateOnESRecord db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrMediaRecordNotExsit, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpsertOneESRecord 插入或更新一条ES操作记录
|
||||
func UpsertOneESRecord(ctx context.Context,
|
||||
filter bson.M, update bson.M) *srvdef.SrvErr {
|
||||
if _, err := db.UpsertOne(ctx, filter, update); err != nil {
|
||||
log.Info("esmod:UpsertOneESRecord db.InsertOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateManyESRecord 更新一批ES操作记录
|
||||
func UpdateManyESRecord(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
||||
result, err := db.UpdateMMany(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("esmod:UpdateManyMediaCat db.UpdateMMany failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
if result.MatchedCount <= 0 {
|
||||
log.Warn("esmod:UpdateManyMediaCat db.UpdateMMany failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
//return srvdef.New(srvdef.ErrMediaTagNotExsit, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// FindManyESRecord 查找一批ES操作记录
|
||||
func FindManyESRecord(ctx context.Context, filter bson.M,
|
||||
opts ...*options.FindOptions) (ESRecordList, *srvdef.SrvErr) {
|
||||
data := make(ESRecordList, 0)
|
||||
if err := db.Find(ctx, &data, filter, opts...); err != nil {
|
||||
log.Warn("esmod:FindManyESRecord db.Find failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func GetRecordTimeByESIndex(ctx context.Context, esIndex string) (*ESRecord, *srvdef.SrvErr) {
|
||||
filter := bson.M{FN.ESRecord.EsIndex: esIndex}
|
||||
esRecord, serr := FindOneESRecord(ctx, filter)
|
||||
if serr != nil {
|
||||
if serr.Code != srvdef.ErrNoData {
|
||||
return nil, serr
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
return esRecord, nil
|
||||
}
|
||||
func SetOneEsRecordTime(ctx context.Context, esIndex string, recordTime time.Time) *srvdef.SrvErr {
|
||||
filter := bson.M{FN.ESRecord.EsIndex: esIndex}
|
||||
upsertDoc := bson.M{
|
||||
"$set": bson.M{
|
||||
FN.ESRecord.RecordTime: recordTime,
|
||||
FN.ESRecord.UpdatedAt: time.Now(),
|
||||
},
|
||||
"$setOnInsert": bson.M{
|
||||
FN.ESRecord.Id: primitive.NewObjectID(),
|
||||
FN.ESRecord.CreatedAt: time.Now(),
|
||||
},
|
||||
}
|
||||
serr := UpsertOneESRecord(ctx, filter, upsertDoc)
|
||||
return serr
|
||||
}
|
||||
Executable
+90
@@ -0,0 +1,90 @@
|
||||
package esmod
|
||||
|
||||
type TagESRecord struct {
|
||||
CreatedAt string
|
||||
EsIndex string
|
||||
Id string
|
||||
RecordTime string
|
||||
Timestamp struct {
|
||||
I string
|
||||
T string
|
||||
}
|
||||
UpdatedAt string
|
||||
}
|
||||
type TagESVideo struct {
|
||||
Id string
|
||||
Title string
|
||||
MediaType string
|
||||
AddedTime string
|
||||
CreatorName string
|
||||
Keyworlds string
|
||||
Desc string
|
||||
Remark string
|
||||
Status string
|
||||
IsHot string
|
||||
Sort string
|
||||
WatchTimes string
|
||||
ShowTimes string
|
||||
Comments string
|
||||
UpdatedAt string
|
||||
CreatedAt string
|
||||
|
||||
Keyworld string
|
||||
CreatorId string
|
||||
FirstTag string
|
||||
SecondTags string
|
||||
CoverImg string
|
||||
Nodes string
|
||||
Video string
|
||||
CategoryIds string
|
||||
Tags string
|
||||
Real string
|
||||
}
|
||||
|
||||
var FN struct {
|
||||
ESRecord TagESRecord
|
||||
ESVideo TagESVideo
|
||||
}
|
||||
|
||||
var TN struct {
|
||||
ESRecord string
|
||||
ESVideo string
|
||||
}
|
||||
|
||||
func init() {
|
||||
FN.ESRecord = TagESRecord{
|
||||
CreatedAt: "createdAt",
|
||||
EsIndex: "esIndex",
|
||||
Id: "_id",
|
||||
RecordTime: "recordTime",
|
||||
Timestamp: struct {
|
||||
I string
|
||||
T string
|
||||
}{
|
||||
I: "i",
|
||||
T: "t",
|
||||
},
|
||||
UpdatedAt: "updatedAt",
|
||||
}
|
||||
FN.ESVideo = TagESVideo{
|
||||
Id: "_id",
|
||||
Title: "title",
|
||||
Desc: "desc",
|
||||
Status: "status",
|
||||
AddedTime: "addedTime",
|
||||
MediaType: "mediaType",
|
||||
CreatorName: "creatorName",
|
||||
Keyworlds: "keyworlds",
|
||||
Remark: "remark",
|
||||
IsHot: "isHot",
|
||||
Sort: "sort",
|
||||
UpdatedAt: "updatedAt",
|
||||
CreatedAt: "createdAt",
|
||||
WatchTimes: "watchTimes",
|
||||
ShowTimes: "showTimes",
|
||||
Comments: "comments",
|
||||
}
|
||||
|
||||
TN.ESRecord = "es_record"
|
||||
TN.ESVideo = "es_video"
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
//go:generate gen_bson_tag -m esmod
|
||||
//esmod essearch数据结构定义
|
||||
|
||||
package esmod
|
||||
|
||||
import (
|
||||
"time"
|
||||
"videoweb/pub/models/videoinformationmod"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
type ESTimestamp struct {
|
||||
T uint32 `json:"t" bson:"t"`
|
||||
I uint32 `json:"i" bson:"i"`
|
||||
}
|
||||
|
||||
func (v *ESTimestamp) IsZero() bool {
|
||||
if v == nil {
|
||||
return true
|
||||
}
|
||||
return v.T == 0 && v.I == 0
|
||||
}
|
||||
|
||||
// ESOperator es操作记录
|
||||
// @table:es_record
|
||||
type ESRecord struct {
|
||||
Id primitive.ObjectID `json:"id" bson:"_id"`
|
||||
EsIndex string `json:"esIndex" bson:"esIndex"` //es索引名称
|
||||
Timestamp ESTimestamp `json:"timestamp" bson:"timestamp"` //操作时间
|
||||
RecordTime time.Time `json:"recordTime" bson:"recordTime"` // 操作记录时间
|
||||
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` //更新时间
|
||||
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` //创建时间
|
||||
}
|
||||
|
||||
type ESRecordList []*ESRecord
|
||||
|
||||
// ESVideo es中存储的media数据
|
||||
// @table:es_video
|
||||
type ESVideo struct {
|
||||
Id int64 `json:"id" bson:"_id,omitempty"`
|
||||
Title string `json:"title" bson:"title"` // 帖子标题
|
||||
MediaType videoinformationmod.MediaType `json:"mediaType" bson:"mediaType"` // 资源类型
|
||||
AddedTime time.Time `json:"addedTime" bson:"addedTime"` // 帖子上架时间
|
||||
CreatorName string `json:"creatorName" bson:"creatorName"` // 作者名称
|
||||
Keyworlds string `bson:"keyworlds,omitempty" json:"keyworlds"` // 关键字
|
||||
Desc string `bson:"desc,omitempty" json:"desc"` // 详细描述
|
||||
Remark string `bson:"remark,omitempty" json:"remark"` // 备注
|
||||
Status videoinformationmod.InformationSatus `json:"status" bson:"status"` // 帖子上架状态
|
||||
IsHot bool `json:"isHot" bson:"isHot"` // 是否热门
|
||||
Sort int64 `json:"sort" bson:"sort"` // 排序
|
||||
WatchTimes int64 `json:"watchTimes" bson:"watchTimes"` // 观看次数
|
||||
ShowTimes int64 `json:"showTimes" bson:"showTimes"` // 展示次数
|
||||
Comments int64 `json:"comments" bson:"comments"` // 评论条数
|
||||
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` // 更新时间
|
||||
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` // 创建时间
|
||||
Keyworld []string `bson:"keyworld,omitempty" json:"keyworld"` // 关键字
|
||||
CreatorId int64 `json:"creatorId" bson:"creatorId"` // 作者Id
|
||||
FirstTag string `bson:"firstTag,omitempty" json:"firstTag"` // 一级标签
|
||||
SecondTags []string `bson:"secondTags,omitempty" json:"secondTags"` // 二级标签标签
|
||||
CoverImg string `bson:"coverImg,omitempty" json:"coverImg"` // 封面
|
||||
Nodes []videoinformationmod.Node `json:"nodes" bson:"nodes"` // 节点
|
||||
Video videoinformationmod.VideoInfo `json:"video" bson:"video"` // 视频
|
||||
CategoryIds []int64 `json:"categoryIds" bson:"categoryIds"` // 分类Id
|
||||
Tags []int64 `json:"tags" bson:"tags"` // 标签
|
||||
Real videoinformationmod.Flow `json:"real" bson:"real"` // 真实流量
|
||||
VideoCount int64 `json:"videoCount" bson:"videoCount"` // 合集视频数量
|
||||
}
|
||||
|
||||
type ESVideoList []*ESVideo
|
||||
type ESTotal struct {
|
||||
Value int64 `json:"value"`
|
||||
}
|
||||
|
||||
type ESVideoSource struct {
|
||||
ID string `json:"_id"`
|
||||
Score float32 `json:"_score"`
|
||||
Source *ESVideo `json:"_source"`
|
||||
}
|
||||
|
||||
// ESVideoHits search media hits
|
||||
type ESVideoHits struct {
|
||||
Total ESTotal `json:"total"`
|
||||
Hits []*ESVideoSource `json:"hits"`
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
package esmod
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"videoweb/app/api/proto"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/esmanager"
|
||||
"videoweb/pub/models/videoinformationmod"
|
||||
)
|
||||
|
||||
// SearchVideo 根据关键字搜索媒体
|
||||
func SearchVideo(content string, from int64, size int64, sort string) (int64, []*videoinformationmod.VideoInformation, *srvdef.SrvErr) {
|
||||
fields := []string{FN.ESVideo.Title, FN.ESVideo.CreatorName, FN.ESVideo.Keyworld, FN.ESVideo.Desc, FN.ESVideo.Remark}
|
||||
must := esmanager.M{
|
||||
"bool": esmanager.M{
|
||||
"must": esmanager.A{
|
||||
{"multi_match": esmanager.M{
|
||||
"query": content,
|
||||
"type": "best_fields",
|
||||
"fields": fields},
|
||||
},
|
||||
{"term": esmanager.M{FN.ESVideo.Status: videoinformationmod.InformationSatusVerifyOK}},
|
||||
},
|
||||
},
|
||||
}
|
||||
switch sort {
|
||||
case string(proto.SearchSortTypeHot):
|
||||
must = esmanager.M{
|
||||
"function_score": esmanager.M{
|
||||
"query": esmanager.M{
|
||||
"bool": esmanager.M{
|
||||
"must": esmanager.A{
|
||||
{"multi_match": esmanager.M{
|
||||
"query": content,
|
||||
"type": "best_fields",
|
||||
"fields": fields,
|
||||
}},
|
||||
{"term": esmanager.M{FN.ESVideo.Status: videoinformationmod.InformationSatusVerifyOK}},
|
||||
},
|
||||
},
|
||||
},
|
||||
"functions": esmanager.A{
|
||||
esmanager.M{
|
||||
"field_value_factor": esmanager.M{
|
||||
"field": FN.ESVideo.WatchTimes,
|
||||
"factor": 1.0,
|
||||
"modifier": "none",
|
||||
},
|
||||
},
|
||||
},
|
||||
"score_mode": "sum",
|
||||
"boost_mode": "multiply",
|
||||
},
|
||||
}
|
||||
case string(proto.SearchSortTypeNew):
|
||||
must = esmanager.M{
|
||||
"bool": esmanager.M{
|
||||
"must": esmanager.A{
|
||||
{"multi_match": esmanager.M{
|
||||
"query": content,
|
||||
"type": "best_fields",
|
||||
"fields": fields},
|
||||
},
|
||||
{"term": esmanager.M{FN.ESVideo.Status: videoinformationmod.InformationSatusVerifyOK}},
|
||||
},
|
||||
"should": esmanager.A{
|
||||
{"range": esmanager.M{FN.ESVideo.AddedTime: esmanager.M{"gte": "now-30d/d", "boost": 2.0}}}, //7天内提升4倍权重
|
||||
{"range": esmanager.M{FN.ESVideo.AddedTime: esmanager.M{"gte": "now-180d/d", "boost": 1.5}}}, // 30天内提升3倍权重
|
||||
{"range": esmanager.M{FN.ESVideo.AddedTime: esmanager.M{"gte": "now-365d/d", "boost": 1.1}}}, // 90天内提升1.5倍权重
|
||||
},
|
||||
"minimum_should_match": 0, // 允许不匹配任何should条件
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
query := esmanager.M{
|
||||
"query": must,
|
||||
"sort": esmanager.A{
|
||||
esmanager.M{"_score": esmanager.M{"order": "desc"}},
|
||||
},
|
||||
"from": from,
|
||||
"size": size,
|
||||
}
|
||||
|
||||
videos := &ESVideoHits{}
|
||||
err := esmanager.Instance.Search(videoIndex, videos, query)
|
||||
if err != nil {
|
||||
info := fmt.Sprintf(
|
||||
"(esmod:SearchVideo) Search failed! err:%+v:", err)
|
||||
log.Warn(info,
|
||||
log.Any("keywords", content),
|
||||
log.Any("from", from),
|
||||
log.Any("size", size))
|
||||
return 0, nil, srvdef.New(srvdef.ErrElsOperError, "", "")
|
||||
}
|
||||
total := int64(0)
|
||||
rslData := make([]*videoinformationmod.VideoInformation, 0)
|
||||
if videos != nil && videos.Hits != nil && len(videos.Hits) > 0 {
|
||||
total = videos.Total.Value
|
||||
for _, video := range videos.Hits {
|
||||
rslData = append(rslData, EsVideoInfoToData(video.Source))
|
||||
}
|
||||
}
|
||||
return total, rslData, nil
|
||||
}
|
||||
|
||||
func EsVideoInfoToData(esInfo *ESVideo) *videoinformationmod.VideoInformation {
|
||||
info := &videoinformationmod.VideoInformation{
|
||||
Id: esInfo.Id,
|
||||
Title: esInfo.Title,
|
||||
MediaType: esInfo.MediaType,
|
||||
AddedTime: esInfo.AddedTime,
|
||||
CreatorId: esInfo.CreatorId,
|
||||
CreatorName: esInfo.CreatorName,
|
||||
Keyworld: esInfo.Keyworld,
|
||||
FirstTag: esInfo.FirstTag,
|
||||
SecondTags: esInfo.SecondTags,
|
||||
CoverImg: esInfo.CoverImg,
|
||||
Desc: esInfo.Desc,
|
||||
Remark: esInfo.Remark,
|
||||
Nodes: esInfo.Nodes,
|
||||
Status: esInfo.Status,
|
||||
Video: esInfo.Video,
|
||||
CategoryIds: esInfo.CategoryIds,
|
||||
Tags: esInfo.Tags,
|
||||
IsHot: esInfo.IsHot,
|
||||
Sort: esInfo.Sort,
|
||||
Real: esInfo.Real,
|
||||
VideoCount: esInfo.VideoCount,
|
||||
UpdatedAt: esInfo.UpdatedAt,
|
||||
CreatedAt: esInfo.CreatedAt,
|
||||
}
|
||||
return info
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package ipblackmod
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"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.IPBlackModel)
|
||||
// 初始化索引
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.IPBlackModel.Ip, Value: 1},
|
||||
},
|
||||
Options: options.Index().SetUnique(true),
|
||||
},
|
||||
}
|
||||
if _, err := db.CreateIndex(ctx, indexes); err != nil {
|
||||
panic(fmt.Sprintf("(IPBlackModel:InitIPBlackModel) Create IPBlackModel Index failed! err:%+v:", err))
|
||||
}
|
||||
}
|
||||
|
||||
// CountIPBlackModel 统计活动数量
|
||||
func CountIPBlackModel(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.Count(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("IPBlackModelmod:CountIPBlackModel db.Count failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// InsertOneIPBlackModel 插入一条活动
|
||||
func InsertOneIPBlackModel(ctx context.Context, IPBlackModel *IPBlackModel) *srvdef.SrvErr {
|
||||
if _, err := db.InsertOne(ctx, IPBlackModel); err != nil {
|
||||
log.Info("IPBlackModelmod:InsertOneIPBlackModel db.InsertOne failed",
|
||||
log.E(err), log.Any("IPBlackModel", IPBlackModel))
|
||||
return srvdef.New(srvdef.ErrDbInsertError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DelOneIPBlackModel 删除一个活动
|
||||
func DelOneIPBlackModel(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.DeleteOne(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("IPBlackModelmod:DelOneIPBlackModel db.DeleteOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbDeleteError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// UpdateOneIPBlackModel 更新一个IPBlackModel
|
||||
func UpdateOneIPBlackModel(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
||||
result, err := db.UpdateOne(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("IPBlackModelmod:UpdateOneIPBlackModel db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
if result.MatchedCount != 1 {
|
||||
log.Warn("IPBlackModelmod:UpdateOneIPBlackModel db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ObjectNotExist, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// FindManyIPBlackModel 查找一批活动数据
|
||||
func FindManyIPBlackModel(ctx context.Context, filter bson.M,
|
||||
opts ...*options.FindOptions) (IPBlackModelList, *srvdef.SrvErr) {
|
||||
data := make(IPBlackModelList, 0)
|
||||
if err := db.Find(ctx, &data, filter, opts...); err != nil {
|
||||
log.Warn("IPBlackModelmod:FindManyAcivities db.Find failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// FindOneIPBlackModel 查找一个媒体
|
||||
func FindOneIPBlackModel(ctx context.Context, filter bson.M) (
|
||||
*IPBlackModel, *srvdef.SrvErr) {
|
||||
var IPBlackModel IPBlackModel
|
||||
if err := db.FindOneEx(ctx, &IPBlackModel, filter); err != nil {
|
||||
if err != mongo.ErrNoDocuments {
|
||||
log.Warn("IPBlackModel:FindOneIPBlackModel db.FindOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return nil, srvdef.New(srvdef.ObjectDayStatDoesNotExist, "", "")
|
||||
}
|
||||
return &IPBlackModel, nil
|
||||
}
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
package ipblackmod
|
||||
|
||||
type TagIPBlackModel struct {
|
||||
CreatedAt string
|
||||
ID string
|
||||
Ip string
|
||||
Desc string
|
||||
UpdatedAt string
|
||||
}
|
||||
|
||||
var FN struct {
|
||||
IPBlackModel TagIPBlackModel
|
||||
}
|
||||
|
||||
var TN struct {
|
||||
IPBlackModel string
|
||||
}
|
||||
|
||||
func init() {
|
||||
FN.IPBlackModel.CreatedAt = "createdAt"
|
||||
FN.IPBlackModel.ID = "_id"
|
||||
FN.IPBlackModel.Ip = "ip"
|
||||
FN.IPBlackModel.UpdatedAt = "updatedAt"
|
||||
FN.IPBlackModel.Desc = "desc"
|
||||
TN.IPBlackModel = "ip_black"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package ipblackmod
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
// 资源同步
|
||||
// @table:ip_black
|
||||
type IPBlackModel struct {
|
||||
ID primitive.ObjectID `bson:"_id,omitempty"`
|
||||
Ip string `json:"ip" bson:"ip"`
|
||||
Desc string `json:"desc" bson:"desc"` // 备注
|
||||
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` // 创建时间
|
||||
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` // 更新时间
|
||||
}
|
||||
type IPBlackModelList []*IPBlackModel
|
||||
@@ -0,0 +1,53 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/models/analyticsdailystat"
|
||||
"videoweb/pub/models/analyticsstat"
|
||||
"videoweb/pub/models/cfg"
|
||||
"videoweb/pub/models/commentmod"
|
||||
"videoweb/pub/models/esmod"
|
||||
"videoweb/pub/models/ipblackmod"
|
||||
"videoweb/pub/models/mwacc"
|
||||
"videoweb/pub/models/oplog"
|
||||
"videoweb/pub/models/richtextcontentmod"
|
||||
"videoweb/pub/models/syncfilemod"
|
||||
"videoweb/pub/models/translationcategorymod"
|
||||
"videoweb/pub/models/translationmod"
|
||||
"videoweb/pub/models/videocategorymod"
|
||||
"videoweb/pub/models/videocollectionmediamod"
|
||||
"videoweb/pub/models/videocreatermod"
|
||||
|
||||
"videoweb/pub/models/videoinformationmod"
|
||||
"videoweb/pub/models/videotagmod"
|
||||
)
|
||||
|
||||
func Init() {
|
||||
log.Info("models init start..")
|
||||
ctx := context.Background()
|
||||
cfg.Init(ctx)
|
||||
mwacc.Init(ctx)
|
||||
oplog.Init(ctx)
|
||||
|
||||
videocategorymod.Init(ctx)
|
||||
videoinformationmod.Init(ctx)
|
||||
videotagmod.Init(ctx)
|
||||
|
||||
translationcategorymod.Init(ctx)
|
||||
translationmod.Init(ctx)
|
||||
videocategorymod.Init(ctx)
|
||||
videocreatermod.Init(ctx)
|
||||
videotagmod.Init(ctx)
|
||||
videoinformationmod.Init(ctx)
|
||||
videocreatermod.Init(ctx)
|
||||
syncfilemod.Init(ctx)
|
||||
richtextcontentmod.Init(ctx)
|
||||
commentmod.Init(ctx)
|
||||
videocollectionmediamod.Init(ctx)
|
||||
ipblackmod.Init(ctx)
|
||||
esmod.Init(ctx)
|
||||
analyticsstat.Init(ctx)
|
||||
analyticsdailystat.Init(ctx)
|
||||
log.Info("models init end")
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
package mwacc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
"videoweb/pub/common/errors"
|
||||
sErr "videoweb/pub/common/errors"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/mongos"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
// 过滤查询数量
|
||||
func AccCountByFilter(ctx context.Context, filters primitive.M, opts ...*options.CountOptions) (c int64, err error) {
|
||||
c, err = mwAccColl.Count(ctx, filters)
|
||||
return
|
||||
}
|
||||
|
||||
// 过滤查询账号
|
||||
func FindOneAccByFilter(ctx context.Context, filters primitive.M, opts ...*options.FindOneOptions) (*MwAcc, error) {
|
||||
var res MwAcc
|
||||
err := mwAccColl.FindOne(ctx, &res, filters, opts...)
|
||||
if err != nil {
|
||||
log.Error("mwacc FindOneAccByFilter err", log.Any("filters", filters), log.E(err))
|
||||
}
|
||||
return &res, err
|
||||
}
|
||||
|
||||
// 过滤更新
|
||||
func UpOneAccByFilter(ctx context.Context, query primitive.M, update primitive.M) (err error) {
|
||||
_, err = mwAccColl.UpdateOne(ctx, query, primitive.M{"$set": update})
|
||||
return
|
||||
}
|
||||
|
||||
// 过滤删除角色
|
||||
func DelAccByFilter(ctx context.Context, filters primitive.M) (err error) {
|
||||
_, err = mwAccColl.DeleteOne(ctx, filters)
|
||||
if err != nil {
|
||||
log.Error("mwacc DelAccByFilter err", log.Any("filters", filters), log.E(err))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// // 更新最后登录时间
|
||||
// func UpAccLastTimeById(ctx context.Context, id int64) (*mongo.UpdateResult, error) {
|
||||
// ret, err := mwAccColl.UpdateOne(ctx, primitive.M{FN.MwAcc.Id: id}, primitive.M{"$set": primitive.M{FN.MwAcc.LastTime: time.Now()}})
|
||||
// if err != nil {
|
||||
// log.Error("mvacc UpLastTimeById err", log.Any(FN.MwAcc.Id, id), log.E(err))
|
||||
// }
|
||||
// return ret, err
|
||||
// }
|
||||
|
||||
// 绑定二维码
|
||||
func BindAccQurl(ctx context.Context, acc string) (ok bool, err error) {
|
||||
|
||||
res, dataErr := FindOneAccByFilter(ctx, primitive.M{
|
||||
FN.MwAcc.Acc: acc,
|
||||
})
|
||||
|
||||
if dataErr != nil || res.Id == 0 {
|
||||
err = sErr.MakeWithMsg(sErr.Logo, "用户不存在!")
|
||||
return false, err
|
||||
}
|
||||
|
||||
if res.IsEnb == false {
|
||||
err = sErr.MakeWithMsg(sErr.UserPermission, "用户被禁用!")
|
||||
return false, err
|
||||
}
|
||||
err = UpOneAccByFilter(ctx, primitive.M{
|
||||
FN.MwAcc.Acc: acc,
|
||||
}, primitive.M{
|
||||
FN.MwAcc.IsBase32: true,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return true, err
|
||||
}
|
||||
|
||||
// 插入角色
|
||||
func AccAdd(ctx context.Context, insertReq *AccInsertDoc) (id int64, ok bool, err error) {
|
||||
|
||||
insertReq.Id = int64(mongos.Lid.MwAcc.Get())
|
||||
insertReq.CreatedAt = time.Now()
|
||||
|
||||
_, err = mwAccColl.InsertOne(ctx, insertReq)
|
||||
if err != nil {
|
||||
log.ZapLog.Error(fmt.Sprintf("InsertRole mongo error %v", err))
|
||||
err = errors.MakeWithErr(errors.DBInsert, err)
|
||||
return 0, false, err
|
||||
}
|
||||
return insertReq.Id, true, nil
|
||||
}
|
||||
|
||||
// 获取角色列表
|
||||
func GetAccList(ctx context.Context, search primitive.M, sort []primitive.M) (
|
||||
total int64, data []*AccGetListRec, err error) {
|
||||
|
||||
var countPipe []primitive.M
|
||||
countPipe = append(countPipe, search, bson.M{"$count": "total"})
|
||||
var aggCount AggStatCount
|
||||
err = mwAccColl.ObjectAggregate(ctx, &aggCount, countPipe)
|
||||
if err != nil {
|
||||
return 0, nil, err
|
||||
}
|
||||
total = aggCount.Total
|
||||
|
||||
var pip []primitive.M
|
||||
pip = append(pip, search)
|
||||
pip = append(pip, sort...)
|
||||
pip = append(pip,
|
||||
primitive.M{
|
||||
"$lookup": primitive.M{
|
||||
"localField": FN.MwAcc.RoleId,
|
||||
"from": TN.MwRole,
|
||||
"foreignField": FN.MwRole.Id,
|
||||
"as": "roles",
|
||||
},
|
||||
},
|
||||
primitive.M{"$unwind": primitive.M{
|
||||
"path": "$roles",
|
||||
"preserveNullAndEmptyArrays": true,
|
||||
},
|
||||
},
|
||||
primitive.M{
|
||||
"$project": primitive.M{
|
||||
FN.MwAcc.Id: 1,
|
||||
FN.MwAcc.UserName: 1,
|
||||
FN.MwAcc.Acc: 1,
|
||||
FN.MwAcc.Pwd: 1,
|
||||
FN.MwAcc.Email: 1,
|
||||
FN.MwAcc.RoleId: 1,
|
||||
FN.MwAcc.RoleName: "$roles.name",
|
||||
FN.MwAcc.Base32: 1,
|
||||
FN.MwAcc.IsBase32: 1,
|
||||
// mwacc.FN.MwAcc.LastTime: 1,
|
||||
FN.MwAcc.IsEnb: 1,
|
||||
FN.MwAcc.Feedback: 1,
|
||||
FN.MwAcc.CreatedAt: 1,
|
||||
FN.MwAcc.UpdatedAt: 1,
|
||||
FN.MwAcc.LimitIP: 1,
|
||||
},
|
||||
})
|
||||
|
||||
err = mwAccColl.Aggregate(ctx, &data, pip)
|
||||
if err != nil {
|
||||
err = errors.MakeWithErr(errors.DBQuery, err)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 过滤查询账号
|
||||
func FindManyAccByFilter(ctx context.Context, filters primitive.M, opts ...*options.FindOptions) ([]*MwAcc, *srvdef.SrvErr) {
|
||||
var res []*MwAcc
|
||||
err := mwAccColl.Find(ctx, &res, filters, opts...)
|
||||
if err != nil {
|
||||
log.Error("mwacc FindOneAccByFilter err", log.Any("filters", filters), log.E(err))
|
||||
return res, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
log.Info("success")
|
||||
|
||||
return res, nil
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package mwacc
|
||||
|
||||
import "videoweb/pub/mongos"
|
||||
|
||||
var (
|
||||
mwAccColl *mongos.Collection = nil
|
||||
mwRoleColl *mongos.Collection = nil
|
||||
mwAccTokenColl *mongos.Collection = nil
|
||||
)
|
||||
|
||||
type AggStatCount struct {
|
||||
Total int64 `bson:"total"`
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package mwacc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"videoweb/pub/mongos"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
)
|
||||
|
||||
// Init 初始化数据
|
||||
func Init(ctx context.Context) {
|
||||
mwAccColl = mongos.Shop.Coll(TN.MwAcc)
|
||||
mwRoleColl = mongos.Shop.Coll(TN.MwRole)
|
||||
mwAccTokenColl = mongos.Shop.Coll(TN.MwAccToken)
|
||||
initIndex(ctx)
|
||||
return
|
||||
}
|
||||
|
||||
// initIndex 初始化索引
|
||||
func initIndex(ctx context.Context) {
|
||||
initAccIndex(ctx)
|
||||
initRoleIndex(ctx)
|
||||
initAccTokenIndex(ctx)
|
||||
}
|
||||
|
||||
func initAccIndex(ctx context.Context) {
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{
|
||||
{FN.MwAcc.Id, 1},
|
||||
},
|
||||
},
|
||||
}
|
||||
if _, err := mwAccColl.CreateIndex(ctx, indexes); err != nil {
|
||||
panic(fmt.Sprintf("(mwacc:initAccIndex) Create mwacc Index failed! err:%+v:", err))
|
||||
}
|
||||
}
|
||||
|
||||
func initRoleIndex(ctx context.Context) {
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{
|
||||
{FN.MwRole.Id, 1},
|
||||
},
|
||||
// Options: options.Index().SetUnique(true),
|
||||
},
|
||||
}
|
||||
if _, err := mwRoleColl.CreateIndex(ctx, indexes); err != nil {
|
||||
panic(fmt.Sprintf("(mwacc:initRoleIndex) Create mwacc Index failed! err:%+v:", err))
|
||||
}
|
||||
}
|
||||
func initAccTokenIndex(ctx context.Context) {
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{
|
||||
{FN.MwAccToken.Id, 1},
|
||||
},
|
||||
// Options: options.Index().SetUnique(true),
|
||||
},
|
||||
}
|
||||
if _, err := mwAccTokenColl.CreateIndex(ctx, indexes); err != nil {
|
||||
panic(fmt.Sprintf("(mwacc:initAccTokenIndex) Create mwacc Index failed! err:%+v:", err))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package mwacc
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"videoweb/pub/pubdef"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
|
||||
func MakeSearch(keyWords string, status int64, page pubdef.Page) (searchs bson.M) {
|
||||
var search []bson.M
|
||||
if len(keyWords) > 0 {
|
||||
userId, _ := strconv.ParseInt(keyWords, 10, 64)
|
||||
search = append(search, bson.M{FN.MwAcc.Id: userId})
|
||||
search = append(search, bson.M{FN.MwAcc.UserName: bson.M{"$regex": keyWords}})
|
||||
search = append(search, bson.M{FN.MwAcc.Acc: bson.M{"$regex": keyWords}})
|
||||
search = append(search, bson.M{FN.MwAcc.Email: bson.M{"$regex": keyWords}})
|
||||
}
|
||||
|
||||
match := bson.M{}
|
||||
if len(search) > 0 {
|
||||
match["$or"] = search
|
||||
}
|
||||
|
||||
if status > 0 {
|
||||
if status == 1 {
|
||||
match[FN.MwAcc.IsEnb] = true
|
||||
} else {
|
||||
match[FN.MwAcc.IsEnb] = false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
searchs = bson.M{}
|
||||
searchs["$match"] = match
|
||||
return
|
||||
}
|
||||
|
||||
func MakeSort(pageNum int64, pageSize int64) (sort []bson.M) {
|
||||
sort = append(sort, bson.M{
|
||||
"$sort": bson.M{
|
||||
FN.MwAcc.CreatedAt: -1,
|
||||
},
|
||||
})
|
||||
if pageNum <= 0 {
|
||||
pageNum = 1
|
||||
}
|
||||
if pageSize <= 0 {
|
||||
pageSize = 10
|
||||
}
|
||||
skip := (pageNum - 1) * pageSize
|
||||
sort = append(sort, bson.M{
|
||||
"$skip": skip,
|
||||
})
|
||||
|
||||
sort = append(sort, bson.M{
|
||||
"$limit": pageSize,
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
// Code generated by gen_bson_tag. DO NOT EDIT.
|
||||
package mwacc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/srvdef"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
// CreateOneMwAcc 创建一个MwAcc
|
||||
func CreateOneMwAcc(ctx context.Context, data *MwAcc) *srvdef.SrvErr {
|
||||
_, err := mwAccColl.InsertOne(ctx, data)
|
||||
if err != nil {
|
||||
log.Error("mwacc:CreateOneMwAcc db.InsertOne failed",
|
||||
log.Any("doc", data),
|
||||
log.E(err))
|
||||
return srvdef.New(srvdef.ErrDbInsertError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// FindOneMwAcc 查找一个MwAcc
|
||||
func FindOneMwAcc(ctx context.Context, filter bson.M) (
|
||||
*MwAcc, *srvdef.SrvErr) {
|
||||
var data *MwAcc
|
||||
if err := mwAccColl.FindOneEx(ctx, &data, filter); err != nil {
|
||||
if err != mongo.ErrNoDocuments {
|
||||
log.Warn("mwacc:FindOneMwAcc mwAccColl.FindOneEx failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return nil, srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// DelOneOneMwAcc 删除一个MwAcc
|
||||
func DelOneOneMwAcc(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := mwAccColl.DeleteOne(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("mwacc:DelOneOneMwAcc mwAccColl.DeleteOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbDeleteError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// UpdateOneMwAcc 更新一个MwAcc
|
||||
func UpdateOneMwAcc(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
||||
result, err := mwAccColl.UpdateOne(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("mwacc:UpdateOneMwAcc mwAccColl.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
if result.MatchedCount != 1 {
|
||||
return srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CountMwAccs 统计MwAcc数量
|
||||
func CountMwAccs(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := mwAccColl.Count(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("mwacc:CountMwAccs mwAccColl.Count failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// FindManyMwAccs 查找一批MwAcc
|
||||
func FindManyMwAccs(ctx context.Context, filter bson.M,
|
||||
opts ...*options.FindOptions) (MwAccList, *srvdef.SrvErr) {
|
||||
data := make(MwAccList, 0)
|
||||
if err := mwAccColl.Find(ctx, &data, filter, opts...); err != nil {
|
||||
log.Warn("mwacc:FindManyMwAccs mwAccColl.Find failed", log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// FindManyMwAccsWithBind 用自己定义结构查找一批MwAcc数据
|
||||
func FindManyMwAccsWithBind(ctx context.Context, bind interface{}, filter bson.M,
|
||||
opts ...*options.FindOptions) *srvdef.SrvErr {
|
||||
if err := mwAccColl.Find(ctx, bind, filter, opts...); err != nil {
|
||||
log.Warn("mwacc:FindManyMwAccsWithBind mwAccColl.Find failed", log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AggregateMwAccs 聚合查找一批MwAcc
|
||||
func AggregateMwAccs(ctx context.Context,
|
||||
bind interface{}, pipeline []bson.M) *srvdef.SrvErr {
|
||||
if err := mwAccColl.Aggregate(ctx, bind, pipeline); err != nil {
|
||||
log.Warn("mwacc:AggregateMwAccs mwAccColl.Aggregate failed",
|
||||
log.E(err), log.Any("pipeline", pipeline))
|
||||
return srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ObjectAggregateMwAccs 聚合查找一批MwAcc数据
|
||||
func ObjectAggregateMwAccs(ctx context.Context,
|
||||
bind interface{}, pipeline []bson.M) *srvdef.SrvErr {
|
||||
if err := mwAccColl.ObjectAggregate(ctx, bind, pipeline); err != nil {
|
||||
log.Warn("mwacc:AggregateMwAccs mwAccColl.Aggregate failed",
|
||||
log.E(err), log.Any("pipeline", pipeline))
|
||||
return srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ObjectAggregateMwAccs 批量写入或者更新MwAcc数据
|
||||
func BulkWriteMwAccs(ctx context.Context,
|
||||
docs []mongo.WriteModel, opts ...*options.BulkWriteOptions) *srvdef.SrvErr {
|
||||
_, err := mwAccColl.BulkWrite(ctx, docs, opts...)
|
||||
if err != nil {
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
package mwacc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
"videoweb/pub/common/errors"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/pageopt"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/mongos"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
// 角色聚集处理
|
||||
func RoleAggregate(ctx context.Context, filters []primitive.M, opts ...*options.AggregateOptions) (roles []*MwRole, err error) {
|
||||
roles = make([]*MwRole, 0)
|
||||
err = mwRoleColl.Aggregate(ctx, &roles, filters)
|
||||
return
|
||||
}
|
||||
|
||||
// 过滤查询数量
|
||||
func RoleCountByFilter(ctx context.Context, filters primitive.M, opts ...*options.CountOptions) (c int64, err error) {
|
||||
c, err = mwRoleColl.Count(ctx, filters)
|
||||
return
|
||||
}
|
||||
|
||||
// 过滤查询角色
|
||||
func FindOneRoleByFilter(ctx context.Context, filters primitive.M, opts ...*options.FindOneOptions) (*MwRole, *srvdef.SrvErr) {
|
||||
var res MwRole
|
||||
err := mwRoleColl.FindOne(ctx, &res, filters, opts...)
|
||||
if err != nil {
|
||||
log.Error("mwacc FindOneRoleByFilter err", log.Any("filters", filters), log.E(err))
|
||||
return &res, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// 过滤更新
|
||||
func UpOneRoleByFilter(ctx context.Context, query primitive.M, update primitive.M) *srvdef.SrvErr {
|
||||
_, err := mwRoleColl.UpdateOne(ctx, query, update)
|
||||
if err != nil {
|
||||
log.Error("mwacc UpOneRoleByFilter: db.UpdateOne err", log.Any("update", update), log.E(err))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 过滤删除角色
|
||||
func DelRoleByFilter(ctx context.Context, filters primitive.M) *srvdef.SrvErr {
|
||||
_, err := mwRoleColl.DeleteOne(ctx, filters)
|
||||
if err != nil {
|
||||
log.Error("mwacc DelRoleByFilter err", log.Any("filters", filters), log.E(err))
|
||||
return srvdef.New(srvdef.ErrDbDeleteError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 更新角色权限
|
||||
func UpRoleAuth(ctx context.Context, id int64, keys []string, dataRouter []*Router) (ok bool, err error) {
|
||||
|
||||
_, err = mwRoleColl.UpdateOne(ctx, primitive.M{
|
||||
FN.MwRole.Id: id,
|
||||
}, primitive.M{
|
||||
"$set": primitive.M{
|
||||
FN.MwRole.ApiMenus: keys,
|
||||
FN.MwRole.Router: dataRouter,
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
log.Error("mvacc UpRoleAuth err", log.Any(FN.MwRole.Id, id), log.E(err))
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// 获取角色列表
|
||||
func GetRoleList(ctx context.Context, skip, limit int64, matchs ...pageopt.Matcher) (data []*RoleGetListRec, err error) {
|
||||
data = make([]*RoleGetListRec, 0)
|
||||
|
||||
err = mwRoleColl.Aggregate(ctx, &data,
|
||||
[]primitive.M{
|
||||
{"$match": pageopt.MergeM(matchs)},
|
||||
{"$sort": primitive.M{FN.MwRole.Id: -1}},
|
||||
{"$skip": skip},
|
||||
{"$limit": limit},
|
||||
{"$lookup": primitive.M{
|
||||
"localField": FN.MwRole.Id,
|
||||
"from": TN.MwAcc,
|
||||
"foreignField": FN.MwAcc.RoleId,
|
||||
"as": "onlyRole",
|
||||
}},
|
||||
{"$project": primitive.M{
|
||||
FN.MwRole.Id: 1,
|
||||
FN.MwRole.Name: 1,
|
||||
FN.MwRole.Desc: 1,
|
||||
FN.MwRole.IsEnb: 1,
|
||||
FN.MwRole.ApiMenus: 1,
|
||||
FN.MwRole.CreatedAt: 1,
|
||||
FN.MwRole.UpdatedAt: 1,
|
||||
"account": primitive.M{
|
||||
"$size": "$onlyRole",
|
||||
},
|
||||
}},
|
||||
})
|
||||
if err != nil && err.Error() != errors.NotFind {
|
||||
log.ZapLog.Error(fmt.Sprintf("mwacc GetRoleList error %v", err))
|
||||
err = errors.MakeWithErr(errors.DBQuery, err)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 下拉列表
|
||||
func RoleDrop(ctx context.Context) (data []*RoleDropDoc, err error) {
|
||||
|
||||
query := primitive.M{FN.MwRole.IsEnb: true}
|
||||
|
||||
opt := options.Find().SetProjection(primitive.M{
|
||||
FN.MwRole.Id: 1,
|
||||
FN.MwRole.Name: 1,
|
||||
})
|
||||
|
||||
err = mwRoleColl.Find(ctx, &data, query, opt)
|
||||
if err != nil {
|
||||
err = errors.MakeWithErr(errors.DBQuery, err)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 插入角色
|
||||
func RoleAdd(ctx context.Context, name string, desc string, isEnb bool) (ok bool, err error) {
|
||||
c, err := mwRoleColl.Count(ctx, primitive.M{FN.MwRole.Name: name})
|
||||
if c > 0 {
|
||||
err = errors.MakeWithMsg(errors.DBInsert, "角色名称")
|
||||
return false, err
|
||||
}
|
||||
|
||||
_, err = mwRoleColl.InsertOne(ctx, primitive.M{
|
||||
FN.MwRole.Id: mongos.Lid.MwRole.Get(),
|
||||
FN.MwRole.Name: name,
|
||||
FN.MwRole.Desc: desc,
|
||||
FN.MwRole.IsEnb: isEnb,
|
||||
FN.MwRole.CreatedAt: time.Now(),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
log.ZapLog.Error(fmt.Sprintf("InsertRole mongo error %v", err))
|
||||
err = errors.MakeWithErr(errors.DBInsert, err)
|
||||
return false, err
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
Executable
+88
@@ -0,0 +1,88 @@
|
||||
package mwacc
|
||||
|
||||
type TagMwRole struct {
|
||||
ApiMenus string
|
||||
CreatedAt string
|
||||
Desc string
|
||||
Id string
|
||||
IsEnb string
|
||||
Name string
|
||||
Router string
|
||||
UpdatedAt string
|
||||
}
|
||||
type TagMwAcc struct {
|
||||
Acc string
|
||||
Base32 string
|
||||
Code string
|
||||
CreatedAt string
|
||||
Email string
|
||||
Feedback string
|
||||
Id string
|
||||
IsBase32 string
|
||||
IsEnb string
|
||||
LastTime string
|
||||
LimitIP string
|
||||
Pwd string
|
||||
Qurl string
|
||||
RoleId string
|
||||
RoleName string
|
||||
Token string
|
||||
UpdatedAt string
|
||||
UserName string
|
||||
}
|
||||
type TagMwAccToken struct {
|
||||
AccId string
|
||||
CreatedAt string
|
||||
Id string
|
||||
Token string
|
||||
UpdatedAt string
|
||||
}
|
||||
|
||||
var FN struct {
|
||||
MwRole TagMwRole
|
||||
MwAcc TagMwAcc
|
||||
MwAccToken TagMwAccToken
|
||||
}
|
||||
|
||||
var TN struct {
|
||||
MwRole string
|
||||
MwAcc string
|
||||
MwAccToken string
|
||||
}
|
||||
|
||||
func init() {
|
||||
FN.MwRole.ApiMenus = "apiMenus"
|
||||
FN.MwRole.CreatedAt = "createdAt"
|
||||
FN.MwRole.Desc = "desc"
|
||||
FN.MwRole.Id = "_id"
|
||||
FN.MwRole.IsEnb = "isEnb"
|
||||
FN.MwRole.Name = "name"
|
||||
FN.MwRole.Router = "router"
|
||||
FN.MwRole.UpdatedAt = "updatedAt"
|
||||
FN.MwAcc.Acc = "acc"
|
||||
FN.MwAcc.Base32 = "base32"
|
||||
FN.MwAcc.Code = "code"
|
||||
FN.MwAcc.CreatedAt = "createdAt"
|
||||
FN.MwAcc.Email = "email"
|
||||
FN.MwAcc.Feedback = "feedback"
|
||||
FN.MwAcc.Id = "_id"
|
||||
FN.MwAcc.IsBase32 = "isBase32"
|
||||
FN.MwAcc.IsEnb = "isEnb"
|
||||
FN.MwAcc.LastTime = "lastTime"
|
||||
FN.MwAcc.LimitIP = "limitIP"
|
||||
FN.MwAcc.Pwd = "pwd"
|
||||
FN.MwAcc.Qurl = "qurl"
|
||||
FN.MwAcc.RoleId = "roleId"
|
||||
FN.MwAcc.RoleName = "roleName"
|
||||
FN.MwAcc.Token = "token"
|
||||
FN.MwAcc.UpdatedAt = "updatedAt"
|
||||
FN.MwAcc.UserName = "userName"
|
||||
FN.MwAccToken.AccId = "accId"
|
||||
FN.MwAccToken.CreatedAt = "createdAt"
|
||||
FN.MwAccToken.Id = "_id"
|
||||
FN.MwAccToken.Token = "token"
|
||||
FN.MwAccToken.UpdatedAt = "updatedAt"
|
||||
TN.MwRole = "mw_role"
|
||||
TN.MwAcc = "mw_acc"
|
||||
TN.MwAccToken = "mw_acc_token"
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package mwacc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
"videoweb/pub/common/errors"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/mongos"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
// 过滤更新
|
||||
func UpOneTokenByFilter(ctx context.Context, query primitive.M, update primitive.M) (err error) {
|
||||
_, err = mwAccTokenColl.UpdateOne(ctx, query, primitive.M{"$set": update})
|
||||
return
|
||||
}
|
||||
|
||||
func SaveToken(ctx context.Context, accId int64, token string) (ok bool, err error) {
|
||||
var booToken MwAccToken
|
||||
|
||||
// 查找
|
||||
err = mwAccTokenColl.FindOne(ctx, &booToken, primitive.M{FN.MwAccToken.AccId: accId})
|
||||
|
||||
if booToken.AccId > 0 {
|
||||
// 更新
|
||||
err = UpOneTokenByFilter(ctx, primitive.M{
|
||||
FN.MwAccToken.AccId: accId,
|
||||
}, primitive.M{
|
||||
FN.MwAccToken.Token: token,
|
||||
FN.MwAccToken.UpdatedAt: time.Now(),
|
||||
})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
if err != nil || booToken.AccId == 0 {
|
||||
if _, err := mwAccTokenColl.InsertOne(ctx,
|
||||
primitive.M{
|
||||
FN.MwAccToken.Id: mongos.Lid.MwAccToken.Get(),
|
||||
FN.MwAccToken.AccId: accId,
|
||||
FN.MwAccToken.Token: token,
|
||||
FN.MwAccToken.CreatedAt: time.Now(),
|
||||
}); err != nil {
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func CheckToken(ctx context.Context, token string) (ok bool, err error) {
|
||||
var booToken MwAccToken
|
||||
Terr := mwAccTokenColl.FindOne(ctx, &booToken, primitive.M{FN.MwAccToken.Token: token})
|
||||
if Terr != nil || booToken.AccId == 0 {
|
||||
err = errors.MakeWithMsg(errors.NoToken, "token 不存在或已过期")
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// // 检测Token
|
||||
// func CheckToken(ctx context.Context, token string) (ok bool, err error) {
|
||||
// var booToken WebToken
|
||||
// Terr := tokenColl.FindOne(ctx, &booToken, primitive.M{"token": token})
|
||||
// if Terr != nil || booToken.Id == 0 {
|
||||
// err = errors.MakeWithMsg(errors.NoToken, "token 不存在或已过期")
|
||||
// return
|
||||
// }
|
||||
// return true, nil
|
||||
// }
|
||||
|
||||
// 删除token
|
||||
func DeleteOneToken(ctx context.Context, filter bson.M) *srvdef.SrvErr {
|
||||
if _, err := mwAccTokenColl.DeleteOne(ctx, filter); err != nil {
|
||||
log.Warn("mwacc:DeleteOneToken db.DeleteOne failed", log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbDeleteError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package mwacc
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Meta struct {
|
||||
Title string `bson:"title"`
|
||||
Icon string `bson:"icon"`
|
||||
NoCache bool `bson:"noCache"`
|
||||
}
|
||||
|
||||
type Apiurl struct {
|
||||
Url []string `bson:"url"`
|
||||
Desc string `bson:"desc"`
|
||||
Status bool `bson:"status"`
|
||||
Method []string `bson:"method"`
|
||||
}
|
||||
|
||||
// 编辑返回去的数据
|
||||
type Router struct {
|
||||
Path string `bson:"path"`
|
||||
Component string `bson:"component"`
|
||||
Redirect string `bson:"redirect"`
|
||||
Name string `bson:"name"`
|
||||
IsShow bool `bson:"isShow"`
|
||||
Hidden bool `bson:"hidden"`
|
||||
Meta Meta `bson:"meta"`
|
||||
Children []Router `bson:"children"`
|
||||
ApiUrl []Apiurl `bson:"apiUrl"`
|
||||
}
|
||||
|
||||
// 角色
|
||||
// @table:mw_role
|
||||
type MwRole struct {
|
||||
Id int64 `bson:"_id"`
|
||||
Name string `bson:"name"` // 角色名称
|
||||
Desc string `bson:"desc"` // 描述
|
||||
IsEnb bool `bson:"isEnb"` // 是否启用 false:禁用 true:启用
|
||||
ApiMenus []string `bson:"apiMenus"` // 已有权限的api
|
||||
Router []Router `bson:"router"`
|
||||
CreatedAt time.Time `bson:"createdAt"` // 创建时间
|
||||
UpdatedAt time.Time `bson:"updatedAt"` // 更新时间
|
||||
}
|
||||
|
||||
// 账号
|
||||
// @table:mw_acc
|
||||
type MwAcc struct {
|
||||
Id int64 `bson:"_id"` // id
|
||||
UserName string `bson:"userName"` // 用户名
|
||||
Acc string `bson:"acc"` // 账号
|
||||
Pwd string `bson:"pwd"` // 密码
|
||||
Email string `bson:"email"` // 邮箱
|
||||
RoleId int64 `bson:"roleId"` // 角色Id
|
||||
RoleName string `bson:"roleName"` // 角色名
|
||||
Base32 string `bson:"base32"` // 二步签名
|
||||
IsBase32 bool `bson:"isBase32"` // 是否已签名
|
||||
Code string `bson:"code"` // 验证码
|
||||
Qurl []byte `bson:"qurl"` // 二维码链接
|
||||
Token string `bson:"token"` // token
|
||||
LastTime time.Time `bson:"lastTime"` // 登录时间
|
||||
IsEnb bool `bson:"isEnb"` // 使能
|
||||
Feedback string `bson:"feedback"` // 禁用原因
|
||||
CreatedAt time.Time `bson:"createdAt"` // 创建时间
|
||||
UpdatedAt time.Time `bson:"updatedAt"` // 更新时间
|
||||
LimitIP []string `bson:"limitIP"` // 限制IP
|
||||
}
|
||||
type MwAccList []*MwAcc
|
||||
|
||||
// 账号Token
|
||||
// @table:mw_acc_token
|
||||
type MwAccToken struct {
|
||||
Id int64 `bson:"_id"` // id
|
||||
AccId int64 `bson:"accId"` // 账号id
|
||||
Token string `bson:"token"` // token
|
||||
CreatedAt time.Time `bson:"createdAt"` // 创建时间
|
||||
UpdatedAt time.Time `bson:"updatedAt"` // 更新时间
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package mwacc
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type AccGetListRec struct {
|
||||
Id int64 `bson:"_id"` // id
|
||||
Username string `bson:"username"` // 用户名
|
||||
Acc string `bson:"acc"` // 用户名
|
||||
Pwd string `bson:"pwd"` // 密码
|
||||
Email string `bson:"email"` // 邮箱
|
||||
RoleId int64 `bson:"roleId"` // 角色Id
|
||||
RoleName string `bson:"roleName"` // 角色名
|
||||
// Base32 string `bson:"base32"` // 二步签名
|
||||
IsBase32 bool `bson:"isBase32"` // 是否已签名
|
||||
IsEnb bool `bson:"isEnb"` // 使能
|
||||
Feedback string `bson:"feedback"` // 禁用原因
|
||||
CreatedAt time.Time `bson:"createdAt"` // 创建时间
|
||||
UpdatedAt time.Time `bson:"updatedAt"` // 更新时间
|
||||
LimitIP []string `bson:"limitIP"` // 允许访问的IP
|
||||
}
|
||||
|
||||
type RoleGetListRec struct {
|
||||
Id int64 `bson:"_id"` // 角色Id
|
||||
Name string `bson:"name"` // 角色名称
|
||||
Desc string `bson:"desc"` // 描述
|
||||
IsEnb bool `bson:"isEnb"` // 是否启用 false:禁用 true:启用
|
||||
ApiMenus []string `bson:"apiMenus"` // 已有权限的api
|
||||
CreatedAt time.Time `bson:"createdAt"` // 创建时间
|
||||
UpdatedAt time.Time `bson:"updatedAt"` // 更新时间
|
||||
AccCount int64 `bson:"accCount"` // 账户数量
|
||||
}
|
||||
|
||||
type AccInsertDoc struct {
|
||||
Id int64 `bson:"_id"` // id
|
||||
UserName string `bson:"userName"` // 用户名
|
||||
Pwd string `bson:"pwd"` // 密码
|
||||
Acc string `bson:"acc"` // 用户名
|
||||
Email string `bson:"email"` // 邮箱
|
||||
RoleId int64 `bson:"roleId"` // 角色Id
|
||||
Base32 string `bson:"base32"` // 二步签名
|
||||
IsBase32 bool `bson:"isBase32"` // 是否已签名
|
||||
IsEnb bool `bson:"isEnb"` // 使能
|
||||
LastTime time.Time `bson:"lastTime"` // 登录时间
|
||||
CreatedAt time.Time `bson:"createdAt"` // 创建时间
|
||||
LimitIP []string `bson:"limitIP"` // 允许访问的IP
|
||||
}
|
||||
|
||||
type RoleDropDoc struct {
|
||||
Id int64 `bson:"_id"` // 角色Id
|
||||
Name string `bson:"name"` // 角色名称
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package oplog
|
||||
|
||||
import (
|
||||
"videoweb/pub/mongos"
|
||||
)
|
||||
|
||||
var (
|
||||
opLogColl *mongos.Collection
|
||||
)
|
||||
@@ -0,0 +1,175 @@
|
||||
package oplog
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/common/utils"
|
||||
"videoweb/pub/mongos"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
// Init 初始化数据
|
||||
func Init(ctx context.Context) {
|
||||
opLogColl = mongos.ShopLog.Coll(TN.OpLog)
|
||||
initIndex(ctx)
|
||||
return
|
||||
}
|
||||
|
||||
func initIndex(ctx context.Context) {
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{
|
||||
{FN.OpLog.ActId, 1},
|
||||
{FN.OpLog.Action, 1},
|
||||
{FN.OpLog.Path, 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{FN.OpLog.CreatedAt, -1},
|
||||
},
|
||||
},
|
||||
}
|
||||
if _, err := opLogColl.CreateIndex(ctx, indexes); err != nil {
|
||||
panic(fmt.Sprintf("(oplog:initIndex) Create adLog Index failed! err:%+v:", err))
|
||||
}
|
||||
}
|
||||
|
||||
// 添加日志
|
||||
func AddLog(ctx context.Context, path string, desc string, actId int64, rawData, ip string) (err error) {
|
||||
_, err = opLogColl.InsertOne(ctx, primitive.M{
|
||||
FN.OpLog.Id: mongos.Lid.MwOpLog.Get(),
|
||||
FN.OpLog.Action: desc,
|
||||
FN.OpLog.Path: path,
|
||||
FN.OpLog.ActId: actId,
|
||||
FN.OpLog.RawData: rawData,
|
||||
FN.OpLog.CreatedAt: utils.Now(),
|
||||
FN.OpLog.IP: ip,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
type LogReq struct {
|
||||
PageNum int64 `json:"pageNum"` // 页码
|
||||
PageSize int64 `json:"pageSize"` //
|
||||
Path *string `json:"path"` // 请求接口
|
||||
Action *string `json:"action"` // 操作目的
|
||||
ActId *int64 `json:"actId"` // 操作人Id
|
||||
StartTime *time.Time `json:"startTime"` // 开始时间
|
||||
EndTime *time.Time `json:"endTime"` // 开始时间
|
||||
}
|
||||
|
||||
// 操作日志信息
|
||||
type OpLogInfo struct {
|
||||
Path string `json:"path" bson:"path"` // 请求接口
|
||||
ActId int64 `json:"actId" bson:"actId"` // 操作人Id
|
||||
Action string `json:"action" bson:"action"` // 操作目的
|
||||
Param string `json:"param" bson:"rawData"` // 操作内容
|
||||
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` // 操作时间
|
||||
ActName string `json:"actName" bson:"actName"` // 操作人
|
||||
}
|
||||
|
||||
type OpPageRes struct {
|
||||
Total int64 `json:"total" bson:"total"`
|
||||
List []*OpLogInfo `json:"list" bson:"list"`
|
||||
}
|
||||
|
||||
// 获取日志列表
|
||||
func PageLogList(ctx context.Context, req *LogReq) (res *OpPageRes, err error) {
|
||||
filter := bson.M{}
|
||||
if req.Path != nil && *req.Path != "" {
|
||||
filter[FN.OpLog.Path] = bson.M{"$regex": req.Path}
|
||||
}
|
||||
if req.Action != nil && *req.Action != "" {
|
||||
filter[FN.OpLog.Action] = req.Action
|
||||
}
|
||||
if req.ActId != nil && *req.ActId > 0 {
|
||||
filter[FN.OpLog.ActId] = req.ActId
|
||||
}
|
||||
if req.StartTime != nil && req.EndTime != nil {
|
||||
filter[FN.OpLog.CreatedAt] = bson.M{"$gte": req.StartTime, "$lt": req.EndTime}
|
||||
}
|
||||
res = new(OpPageRes)
|
||||
res.Total, err = mongos.ShopLog.Coll(TN.OpLog).Count(ctx, filter)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
sort := bson.M{FN.OpLog.CreatedAt: -1}
|
||||
opt := &options.FindOptions{}
|
||||
opt.SetSort(sort)
|
||||
skip := (req.PageNum - 1) * req.PageSize
|
||||
opt.SetSkip(skip)
|
||||
opt.SetLimit(req.PageSize)
|
||||
list := make(OpLogList, 0)
|
||||
err = mongos.ShopLog.Coll(TN.OpLog).Find(ctx, &list, filter, opt)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
actIds := make([]int64, 0)
|
||||
for _, v := range list {
|
||||
actIds = append(actIds, v.ActId)
|
||||
}
|
||||
// err = opLogColl.Aggregate(ctx, &res.List, []bson.M{
|
||||
// {"$match": conf},
|
||||
// {"$sort": bson.M{FN.OpLog.CreatedAt: -1}},
|
||||
// {"$skip": (req.PageNum - 1) * req.PageSize},
|
||||
// {"$limit": req.PageSize},
|
||||
// {"$lookup": bson.M{
|
||||
// "localField": FN.OpLog.ActId,
|
||||
// "from": mwacc.TN.MwAcc,
|
||||
// "foreignField": mwacc.FN.MwAcc.Id,
|
||||
// "as": "admins",
|
||||
// }},
|
||||
// {"$unwind": "$admins"},
|
||||
// {"$project": bson.M{
|
||||
// FN.OpLog.Path: 1,
|
||||
// FN.OpLog.Action: 1,
|
||||
// FN.OpLog.ActId: 1,
|
||||
// FN.OpLog.RawData: 1,
|
||||
// FN.OpLog.CreatedAt: 1,
|
||||
// "actName": "$admins.userName",
|
||||
// }},
|
||||
// })
|
||||
return
|
||||
}
|
||||
|
||||
// CountOpLogs 计算某个查询的数量
|
||||
func CountOpLogs(ctx context.Context, filter bson.M) (int64, *srvdef.SrvErr) {
|
||||
total, err := mongos.ShopLog.Coll(TN.OpLog).Count(ctx, filter)
|
||||
if err != nil {
|
||||
log.Info("oplog:CountOpLogs db.Count failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return total, nil
|
||||
}
|
||||
|
||||
// InsertOneUser 插入一个用户
|
||||
func InsertOneUser(ctx context.Context, opLog *OpLog) *srvdef.SrvErr {
|
||||
if _, err := mongos.ShopLog.Coll(TN.OpLog).InsertOne(ctx, opLog); err != nil {
|
||||
log.Warn("oplog:InsertOneUser db.InsertOne failed", log.E(err))
|
||||
return srvdef.New(srvdef.ErrDbInsertError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// FindManyOpLogs 查找一批数据
|
||||
func FindManyOpLogs(ctx context.Context,
|
||||
filter bson.M, opts ...*options.FindOptions) (
|
||||
OpLogList, *srvdef.SrvErr) {
|
||||
data := make(OpLogList, 0)
|
||||
if err := mongos.ShopLog.Coll(TN.OpLog).Find(ctx, &data, filter, opts...); err != nil {
|
||||
log.Warn("oplog:FindManyOpLogs db.Find failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
Executable
+34
@@ -0,0 +1,34 @@
|
||||
package oplog
|
||||
|
||||
type TagOpLog struct {
|
||||
ActId string
|
||||
Action string
|
||||
CreatedAt string
|
||||
IP string
|
||||
Id string
|
||||
IsWhite string
|
||||
OpType string
|
||||
Path string
|
||||
RawData string
|
||||
}
|
||||
|
||||
var FN struct {
|
||||
OpLog TagOpLog
|
||||
}
|
||||
|
||||
var TN struct {
|
||||
OpLog string
|
||||
}
|
||||
|
||||
func init() {
|
||||
FN.OpLog.ActId = "actId"
|
||||
FN.OpLog.Action = "action"
|
||||
FN.OpLog.CreatedAt = "createdAt"
|
||||
FN.OpLog.IP = "ip"
|
||||
FN.OpLog.Id = "_id"
|
||||
FN.OpLog.IsWhite = "isWhite"
|
||||
FN.OpLog.OpType = "opType"
|
||||
FN.OpLog.Path = "path"
|
||||
FN.OpLog.RawData = "rawData"
|
||||
TN.OpLog = "mw_op_log"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package oplog
|
||||
|
||||
import (
|
||||
"time"
|
||||
"videoweb/pub/common"
|
||||
)
|
||||
|
||||
// 操作日志
|
||||
// @table:mw_op_log
|
||||
type OpLog struct {
|
||||
Id int64 `bson:"_id"` // id
|
||||
Path string `bson:"path"` // 请求接口
|
||||
OpType common.ApiOpType `bson:"opType"` // 操作类型
|
||||
IsWhite bool `bson:"isWhite"` // 是否白名单
|
||||
ActId int64 `bson:"actId"` // 操作人Id
|
||||
Action string `bson:"action"` // 操作目的
|
||||
RawData string `bson:"rawData"` // 原始数据
|
||||
CreatedAt time.Time `bson:"createdAt"` // 操作时间
|
||||
IP string `bson:"ip"` // 操作人IP
|
||||
}
|
||||
|
||||
type OpLogList []*OpLog
|
||||
@@ -0,0 +1,153 @@
|
||||
package richtextcontentmod
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/srvdef"
|
||||
|
||||
"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.RichTextContentModel)
|
||||
// 初始化索引
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.RichTextContentModel.CreatedAt, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.RichTextContentModel.Status, Value: 1},
|
||||
},
|
||||
},
|
||||
}
|
||||
if _, err := db.CreateIndex(ctx, indexes); err != nil {
|
||||
panic(fmt.Sprintf("(RichTextContentModelModel:initRichTextContentModelModelIndex) Create RichTextContentModelModel Index failed! err:%+v:", err))
|
||||
}
|
||||
}
|
||||
|
||||
// InsertOneRichTextContentModelModel 插入定时任务
|
||||
func InsertOneRichTextContentModelModel(ctx context.Context, RichTextContentModelModel *RichTextContentModel) *srvdef.SrvErr {
|
||||
if _, err := db.InsertOne(ctx, RichTextContentModelModel); err != nil {
|
||||
log.Warn("RichTextContentModelModel:InsertOneRichTextContentModelModel db.InsertOne failed", log.E(err))
|
||||
return srvdef.New(srvdef.ErrDbInsertError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// FindOneRichTextContentModelModel 插入定时任务
|
||||
func FindOneRichTextContentModelModel(ctx context.Context, filter bson.M) (
|
||||
*RichTextContentModel, *srvdef.SrvErr) {
|
||||
var RichTextContentModelModel RichTextContentModel
|
||||
if err := db.FindOneEx(ctx, &RichTextContentModelModel, filter); err != nil {
|
||||
if err != mongo.ErrNoDocuments {
|
||||
log.Warn("RichTextContentModelModel:FindOneRichTextContentModelModel db.FindOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return nil, srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return &RichTextContentModelModel, nil
|
||||
}
|
||||
|
||||
// DelOneRichTextContentModelModel 插入定时任务
|
||||
func DelOneRichTextContentModelModel(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.DeleteOne(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("RichTextContentModelModel:DelOneRichTextContentModelModel db.DeleteOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbDeleteError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// UpdateOneRichTextContentModelModel 插入定时任务
|
||||
func UpdateOneRichTextContentModelModel(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
||||
result, err := db.UpdateOne(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("RichTextContentModelModel:UpdateOneRichTextContentModelModel db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
if result.MatchedCount != 1 {
|
||||
return srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpsertOneRichTextContentModelModel 更新插入一个记录
|
||||
func UpsertOneRichTextContentModelModel(ctx context.Context, filter bson.M, upsertDoc bson.M) *srvdef.SrvErr {
|
||||
_, err := db.UpsertOne(ctx, filter, upsertDoc)
|
||||
if err != nil {
|
||||
log.Info("RichTextContentModelModel:UpsertOneRichTextContentModelModel db.UpsertOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CountRichTextContentModelModels 统计用户数量
|
||||
func CountRichTextContentModelModels(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.Count(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("RichTextContentModelModel:CountRichTextContentModelModels db.Count failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// UpdateManyRichTextContentModelModel 更新满足条件的用户
|
||||
func UpdateManyRichTextContentModelModel(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
||||
_, err := db.UpdateMany(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("RichTextContentModelModel:UpdateManyRichTextContentModelModel db.UpdateMany failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// FindManyRichTextContentModelModel 查找一批用户数据
|
||||
func FindManyRichTextContentModelModel(ctx context.Context, filter bson.M,
|
||||
opts ...*options.FindOptions) (RichTextContentModelList, *srvdef.SrvErr) {
|
||||
data := make(RichTextContentModelList, 0)
|
||||
if err := db.Find(ctx, &data, filter, opts...); err != nil {
|
||||
log.Warn("RichTextContentModelModel:FindManyRichTextContentModelModel db.Find failed", log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// FindManyRichTextContentModelModelWithBind 用自己定义结构查找一批用户数据
|
||||
func FindManyRichTextContentModelModelWithBind(ctx context.Context, bind interface{}, filter bson.M,
|
||||
opts ...*options.FindOptions) *srvdef.SrvErr {
|
||||
if err := db.Find(ctx, bind, filter, opts...); err != nil {
|
||||
log.Warn("RichTextContentModelModel:FindManyRichTextContentModelModelWithBind db.Find failed", log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AggregateRichTextContentModelModels 聚合查找一批用户信息
|
||||
func AggregateRichTextContentModelModels(ctx context.Context,
|
||||
bind interface{}, pipeline []bson.M) *srvdef.SrvErr {
|
||||
if err := db.Aggregate(ctx, bind, pipeline); err != nil {
|
||||
log.Warn("feedback:AggregateRichTextContentModelModels db.Aggregate failed",
|
||||
log.E(err), log.Any("pipeline", pipeline))
|
||||
return srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Executable
+40
@@ -0,0 +1,40 @@
|
||||
package richtextcontentmod
|
||||
|
||||
type TagRichTextContentModel struct {
|
||||
Content string
|
||||
CreatedAt string
|
||||
Desc string
|
||||
Id string
|
||||
SeoInfo struct {
|
||||
Description string
|
||||
Keyworld string
|
||||
Title string
|
||||
}
|
||||
Sort string
|
||||
Status string
|
||||
Title string
|
||||
UpdatedAt string
|
||||
}
|
||||
|
||||
var FN struct {
|
||||
RichTextContentModel TagRichTextContentModel
|
||||
}
|
||||
|
||||
var TN struct {
|
||||
RichTextContentModel string
|
||||
}
|
||||
|
||||
func init() {
|
||||
FN.RichTextContentModel.Content = "content"
|
||||
FN.RichTextContentModel.CreatedAt = "createdAt"
|
||||
FN.RichTextContentModel.Desc = "desc"
|
||||
FN.RichTextContentModel.Id = "_id"
|
||||
FN.RichTextContentModel.SeoInfo.Description = "seoInfo.webDescription"
|
||||
FN.RichTextContentModel.SeoInfo.Keyworld = "seoInfo.webKeyworld"
|
||||
FN.RichTextContentModel.SeoInfo.Title = "seoInfo.webTitle"
|
||||
FN.RichTextContentModel.Sort = "sort"
|
||||
FN.RichTextContentModel.Status = "status"
|
||||
FN.RichTextContentModel.Title = "title"
|
||||
FN.RichTextContentModel.UpdatedAt = "updatedAt"
|
||||
TN.RichTextContentModel = "rich_text_content"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package richtextcontentmod
|
||||
|
||||
import (
|
||||
"time"
|
||||
"videoweb/pub/pubdef"
|
||||
)
|
||||
|
||||
// RichTextContentModel 富文本内容
|
||||
// @table:rich_text_content
|
||||
type RichTextContentModel struct {
|
||||
Id int64 `json:"id" bson:"_id,omitempty"`
|
||||
Title string `json:"title" bson:"title"` // 标题(内部)
|
||||
Content string `json:"content" bson:"content"` // 内容
|
||||
Status bool `json:"status" bson:"status"` // 是否启用
|
||||
Sort int64 `json:"sort" bson:"sort"` // 排序值
|
||||
Desc string `json:"desc" bson:"desc"` // 标题(app)
|
||||
SeoInfo pubdef.SeoValue `json:"seoInfo" bson:"seoInfo"` // Seo相关信息
|
||||
CreatedAt time.Time `bson:"createdAt" json:"createdAt" ` // 创建时间
|
||||
UpdatedAt time.Time `bson:"updatedAt" json:"updatedAt" ` // 更新时间
|
||||
}
|
||||
|
||||
type RichTextContentModelList []*RichTextContentModel
|
||||
@@ -0,0 +1,153 @@
|
||||
package skdrecord
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/srvdef"
|
||||
|
||||
"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.SkdRecord)
|
||||
// 初始化索引
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.SkdRecord.Job, Value: 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.SkdRecord.CreatedAt, Value: 1},
|
||||
},
|
||||
},
|
||||
}
|
||||
if _, err := db.CreateIndex(ctx, indexes); err != nil {
|
||||
panic(fmt.Sprintf("(SkdRecord:initSkdRecordIndex) Create SkdRecord Index failed! err:%+v:", err))
|
||||
}
|
||||
}
|
||||
|
||||
// InsertOneSkdRecord 插入定时任务
|
||||
func InsertOneSkdRecord(ctx context.Context, SkdRecord *SkdRecord) *srvdef.SrvErr {
|
||||
if _, err := db.InsertOne(ctx, SkdRecord); err != nil {
|
||||
log.Warn("SkdRecord:InsertOneSkdRecord db.InsertOne failed", log.E(err))
|
||||
return srvdef.New(srvdef.ErrDbInsertError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// FindOneSkdRecord 插入定时任务
|
||||
func FindOneSkdRecord(ctx context.Context, filter bson.M) (
|
||||
*SkdRecord, *srvdef.SrvErr) {
|
||||
var SkdRecord SkdRecord
|
||||
if err := db.FindOneEx(ctx, &SkdRecord, filter); err != nil {
|
||||
if err != mongo.ErrNoDocuments {
|
||||
log.Warn("SkdRecord:FindOneSkdRecord db.FindOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return nil, srvdef.New(srvdef.ErrSkdRecordNotExsit, "", "")
|
||||
}
|
||||
return &SkdRecord, nil
|
||||
}
|
||||
|
||||
// DelOneSkdRecord 插入定时任务
|
||||
func DelOneSkdRecord(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.DeleteOne(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("SkdRecord:DelOneSkdRecord db.DeleteOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbDeleteError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// UpdateOneSkdRecord 插入定时任务
|
||||
func UpdateOneSkdRecord(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
||||
result, err := db.UpdateOne(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("SkdRecord:UpdateOneSkdRecord db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
if result.MatchedCount != 1 {
|
||||
return srvdef.New(srvdef.ErrSkdRecordNotExsit, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpsertOneSkdRecord 更新插入一个记录
|
||||
func UpsertOneSkdRecord(ctx context.Context, filter bson.M, upsertDoc bson.M) *srvdef.SrvErr {
|
||||
_, err := db.UpsertOne(ctx, filter, upsertDoc)
|
||||
if err != nil {
|
||||
log.Info("SkdRecord:UpsertOneSkdRecord db.UpsertOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CountSkdRecords 统计用户数量
|
||||
func CountSkdRecords(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.Count(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("SkdRecord:CountSkdRecords db.Count failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// UpdateManySkdRecord 更新满足条件的用户
|
||||
func UpdateManySkdRecord(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
||||
_, err := db.UpdateMany(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("SkdRecord:UpdateManySkdRecord db.UpdateMany failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// FindManySkdRecord 查找一批用户数据
|
||||
func FindManySkdRecord(ctx context.Context, filter bson.M,
|
||||
opts ...*options.FindOptions) (SkdRecordList, *srvdef.SrvErr) {
|
||||
data := make(SkdRecordList, 0)
|
||||
if err := db.Find(ctx, &data, filter, opts...); err != nil {
|
||||
log.Warn("SkdRecord:FindManySkdRecord db.Find failed", log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// FindManySkdRecordWithBind 用自己定义结构查找一批用户数据
|
||||
func FindManySkdRecordWithBind(ctx context.Context, bind interface{}, filter bson.M,
|
||||
opts ...*options.FindOptions) *srvdef.SrvErr {
|
||||
if err := db.Find(ctx, bind, filter, opts...); err != nil {
|
||||
log.Warn("SkdRecord:FindManySkdRecordWithBind db.Find failed", log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AggregateSkdRecords 聚合查找一批用户信息
|
||||
func AggregateSkdRecords(ctx context.Context,
|
||||
bind interface{}, pipeline []bson.M) *srvdef.SrvErr {
|
||||
if err := db.Aggregate(ctx, bind, pipeline); err != nil {
|
||||
log.Warn("feedback:AggregateSkdRecords db.Aggregate failed",
|
||||
log.E(err), log.Any("pipeline", pipeline))
|
||||
return srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Executable
+30
@@ -0,0 +1,30 @@
|
||||
package skdrecord
|
||||
|
||||
type TagSkdRecord struct {
|
||||
CreatedAt string
|
||||
FirstRecordTime string
|
||||
ID string
|
||||
Item string
|
||||
Job string
|
||||
RecordTime string
|
||||
UpdatedAt string
|
||||
}
|
||||
|
||||
var FN struct {
|
||||
SkdRecord TagSkdRecord
|
||||
}
|
||||
|
||||
var TN struct {
|
||||
SkdRecord string
|
||||
}
|
||||
|
||||
func init() {
|
||||
FN.SkdRecord.CreatedAt = "createdAt"
|
||||
FN.SkdRecord.FirstRecordTime = "firstRecordTime"
|
||||
FN.SkdRecord.ID = "_id"
|
||||
FN.SkdRecord.Item = "item"
|
||||
FN.SkdRecord.Job = "job"
|
||||
FN.SkdRecord.RecordTime = "recordTime"
|
||||
FN.SkdRecord.UpdatedAt = "updatedAt"
|
||||
TN.SkdRecord = "skd_record"
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package skdrecord
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
// 表名
|
||||
// SkdRecord 获取充值记录
|
||||
// @table:skd_record
|
||||
type SkdRecord struct {
|
||||
ID primitive.ObjectID `bson:"_id,omitempty"`
|
||||
Job string `bson:"job"` // 工作
|
||||
Item string `bson:"item"` // 统计项
|
||||
RecordTime time.Time `bson:"recordTime"` // 提交时间
|
||||
FirstRecordTime time.Time `bson:"firstRecordTime"` // 第一次提交时间
|
||||
CreatedAt time.Time `bson:"createdAt"` // 创建时间
|
||||
UpdatedAt time.Time `bson:"updatedAt"` // 更新时间
|
||||
}
|
||||
|
||||
const (
|
||||
GameRecordJob = "GameRecordJob" // 按天统计访问信息
|
||||
LoufengUpdate = "LoufengUpdate" // 楼风更新信息
|
||||
)
|
||||
|
||||
type SkdRecordList []*SkdRecord
|
||||
@@ -0,0 +1,108 @@
|
||||
package syncfilemod
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"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.SyncRecord)
|
||||
// 初始化索引
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.SyncRecord.CreatedAt, Value: -1},
|
||||
},
|
||||
},
|
||||
}
|
||||
if _, err := db.CreateIndex(ctx, indexes); err != nil {
|
||||
panic(fmt.Sprintf("(SyncRecord:InitSyncRecord) Create SyncRecord Index failed! err:%+v:", err))
|
||||
}
|
||||
}
|
||||
|
||||
// CountSyncRecord 统计活动数量
|
||||
func CountSyncRecord(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.Count(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("SyncRecordmod:CountSyncRecord db.Count failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// InsertOneSyncRecord 插入一条活动
|
||||
func InsertOneSyncRecord(ctx context.Context, SyncRecord *SyncRecord) *srvdef.SrvErr {
|
||||
if _, err := db.InsertOne(ctx, SyncRecord); err != nil {
|
||||
log.Info("SyncRecordmod:InsertOneSyncRecord db.InsertOne failed",
|
||||
log.E(err), log.Any("SyncRecord", SyncRecord))
|
||||
return srvdef.New(srvdef.ErrDbInsertError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DelOneSyncRecord 删除一个活动
|
||||
func DelOneSyncRecord(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.DeleteOne(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("SyncRecordmod:DelOneSyncRecord db.DeleteOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbDeleteError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// UpdateOneSyncRecord 更新一个SyncRecord
|
||||
func UpdateOneSyncRecord(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
||||
result, err := db.UpdateOne(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("SyncRecordmod:UpdateOneSyncRecord db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
if result.MatchedCount != 1 {
|
||||
log.Warn("SyncRecordmod:UpdateOneSyncRecord db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ObjectNotExist, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// FindManySyncRecord 查找一批活动数据
|
||||
func FindManySyncRecord(ctx context.Context, filter bson.M,
|
||||
opts ...*options.FindOptions) (SyncRecordList, *srvdef.SrvErr) {
|
||||
data := make(SyncRecordList, 0)
|
||||
if err := db.Find(ctx, &data, filter, opts...); err != nil {
|
||||
log.Warn("SyncRecordmod:FindManyAcivities db.Find failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// FindOneSyncRecord 查找一个媒体
|
||||
func FindOneSyncRecord(ctx context.Context, filter bson.M) (
|
||||
*SyncRecord, *srvdef.SrvErr) {
|
||||
var SyncRecord SyncRecord
|
||||
if err := db.FindOneEx(ctx, &SyncRecord, filter); err != nil {
|
||||
if err != mongo.ErrNoDocuments {
|
||||
log.Warn("SyncRecord:FindOneSyncRecord db.FindOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return nil, srvdef.New(srvdef.ObjectDayStatDoesNotExist, "", "")
|
||||
}
|
||||
return &SyncRecord, nil
|
||||
}
|
||||
Executable
+30
@@ -0,0 +1,30 @@
|
||||
package syncfilemod
|
||||
|
||||
type TagSyncRecord struct {
|
||||
CreatedAt string
|
||||
ID string
|
||||
Job string
|
||||
RecordId string
|
||||
SuccessAt string
|
||||
UpdatedAt string
|
||||
RecordTime string
|
||||
}
|
||||
|
||||
var FN struct {
|
||||
SyncRecord TagSyncRecord
|
||||
}
|
||||
|
||||
var TN struct {
|
||||
SyncRecord string
|
||||
}
|
||||
|
||||
func init() {
|
||||
FN.SyncRecord.CreatedAt = "createdAt"
|
||||
FN.SyncRecord.ID = "_id"
|
||||
FN.SyncRecord.Job = "job"
|
||||
FN.SyncRecord.RecordId = "recordId"
|
||||
FN.SyncRecord.SuccessAt = "successAt"
|
||||
FN.SyncRecord.UpdatedAt = "updatedAt"
|
||||
FN.SyncRecord.RecordTime = "recordTime"
|
||||
TN.SyncRecord = "sync_record"
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package syncfilemod
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
// 资源同步
|
||||
// @table:sync_record
|
||||
type SyncRecord struct {
|
||||
ID primitive.ObjectID `bson:"_id,omitempty"`
|
||||
Job string `json:"job" bson:"job"` // 工作
|
||||
RecordId int64 `json:"recordId" bson:"recordId"` // 用户ID
|
||||
RecordTime time.Time `json:"recordTime" bson:"recordTime"` // 记录时间
|
||||
SuccessAt time.Time `json:"successAt" bson:"successAt"` // 成功时间
|
||||
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` // 创建时间
|
||||
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` // 更新时间
|
||||
}
|
||||
type SyncRecordList []*SyncRecord
|
||||
|
||||
const (
|
||||
NovelJob = "novelJob" // 小说记录同步
|
||||
ComicsJob = "comicsJob" // 漫画记录同步
|
||||
PostJob = "postJob" // 帖子记录同步
|
||||
VideoJob = "videoJob" // 视频同步
|
||||
)
|
||||
|
||||
var SyncJobDescribe = map[string]string{
|
||||
NovelJob: "小说记录同步",
|
||||
ComicsJob: "漫画记录同步",
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package translationcategorymod
|
||||
|
||||
import (
|
||||
"context"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/mongos"
|
||||
|
||||
"fmt"
|
||||
|
||||
"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.TranslationCategory)
|
||||
// 获取数据库表
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.TranslationCategory.Status, Value: 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.TranslationCategory.CreatedAt, Value: -1},
|
||||
},
|
||||
},
|
||||
}
|
||||
if _, err := db.CreateIndex(ctx, indexes); err != nil {
|
||||
panic(fmt.Sprintf("(channelmod:initTranslationCategoryIndex) Create TranslationCategory Index failed! err:%+v:", err))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// InsertOneTranslationCategory 插入一个导航分类
|
||||
func InsertOneTranslationCategory(ctx context.Context, qa *TranslationCategory) *srvdef.SrvErr {
|
||||
if _, err := db.InsertOne(ctx, qa); err != nil {
|
||||
// log.Warn("TranslationCategorymod:InsertOneTranslationCategory db.InsertOne failed", log.E(err))
|
||||
return srvdef.New(srvdef.ErrDbInsertError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DelOneTranslationCategory 删除一个导航分类
|
||||
func DelOneTranslationCategory(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.DeleteOne(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("TranslationCategorymod:DelOneTranslationCategory db.DeleteOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbDeleteError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// FindOneTranslationCategory 查找一个导航分类
|
||||
func FindOneTranslationCategory(ctx context.Context, filter bson.M) (
|
||||
*TranslationCategory, *srvdef.SrvErr) {
|
||||
var TranslationCategory TranslationCategory
|
||||
if err := db.FindOneEx(ctx, &TranslationCategory, filter); err != nil {
|
||||
if err != mongo.ErrNoDocuments {
|
||||
log.Warn("TranslationCategorymod:FindOneTranslationCategory db.FindOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return nil, srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return &TranslationCategory, nil
|
||||
}
|
||||
|
||||
func FindManyTranslationCategorys(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (TranslationCategoryList, *srvdef.SrvErr) {
|
||||
data := make(TranslationCategoryList, 0)
|
||||
if err := db.Find(ctx, &data, filter, opts...); nil != err {
|
||||
log.Warn("faq:FindManyTranslationCategorys", log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQuery.Code, "", "")
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// CountTranslationCategorys 统计导航分类数量
|
||||
func CountTranslationCategorys(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.Count(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("faqmod:CountTranslationCategorys db.Count failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// UpdateOneTranslationCategory 更新一个导航分类
|
||||
func UpdateOneTranslationCategory(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
||||
result, err := db.UpdateOne(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("post:UpdateOneTranslationCategory db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
if result.MatchedCount != 1 {
|
||||
log.Warn("post:UpdateOneTranslationCategory db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Executable
+30
@@ -0,0 +1,30 @@
|
||||
package translationcategorymod
|
||||
|
||||
type TagTranslationCategory struct {
|
||||
CreatedAt string
|
||||
Id string
|
||||
Name string
|
||||
Rank string
|
||||
Status string
|
||||
UpdatedAt string
|
||||
UrlValue string
|
||||
}
|
||||
|
||||
var FN struct {
|
||||
TranslationCategory TagTranslationCategory
|
||||
}
|
||||
|
||||
var TN struct {
|
||||
TranslationCategory string
|
||||
}
|
||||
|
||||
func init() {
|
||||
FN.TranslationCategory.CreatedAt = "createdAt"
|
||||
FN.TranslationCategory.Id = "_id"
|
||||
FN.TranslationCategory.Name = "name"
|
||||
FN.TranslationCategory.Rank = "rank"
|
||||
FN.TranslationCategory.Status = "status"
|
||||
FN.TranslationCategory.UpdatedAt = "updatedAt"
|
||||
FN.TranslationCategory.UrlValue = "urlValue"
|
||||
TN.TranslationCategory = "translation_category"
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package translationcategorymod
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// @table:translation_category
|
||||
type TranslationCategory struct {
|
||||
Id int64 `json:"id" bson:"_id,omitempty"` // Id
|
||||
Name string `json:"name" bson:"name"` // 分类名称
|
||||
Status bool `json:"status" bson:"status"` // 上架状态
|
||||
VideoCategoryId int64 `json:"videoCategoryId" bson:"videoCategoryId"` // 视频分类
|
||||
Rank int64 `json:"rank" bson:"rank"` // 排序
|
||||
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` // 更新时间
|
||||
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` // 创建时间
|
||||
}
|
||||
type TranslationCategoryList []*TranslationCategory
|
||||
Executable
+36
@@ -0,0 +1,36 @@
|
||||
package translationmod
|
||||
|
||||
type TagTranslationInfo struct {
|
||||
CreatedAt string
|
||||
HtmlId string
|
||||
Id string
|
||||
Link string
|
||||
Name string
|
||||
Rank string
|
||||
Status string
|
||||
TransCategoryId string
|
||||
UpdatedAt string
|
||||
VideoCategoryId string
|
||||
}
|
||||
|
||||
var FN struct {
|
||||
TranslationInfo TagTranslationInfo
|
||||
}
|
||||
|
||||
var TN struct {
|
||||
TranslationInfo string
|
||||
}
|
||||
|
||||
func init() {
|
||||
FN.TranslationInfo.CreatedAt = "createdAt"
|
||||
FN.TranslationInfo.HtmlId = "htmlId"
|
||||
FN.TranslationInfo.Id = "_id"
|
||||
FN.TranslationInfo.Link = "link"
|
||||
FN.TranslationInfo.Name = "name"
|
||||
FN.TranslationInfo.Rank = "rank"
|
||||
FN.TranslationInfo.Status = "status"
|
||||
FN.TranslationInfo.TransCategoryId = "transCategoryId"
|
||||
FN.TranslationInfo.UpdatedAt = "updatedAt"
|
||||
FN.TranslationInfo.VideoCategoryId = "videoCategoryId"
|
||||
TN.TranslationInfo = "translation_info"
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package translationmod
|
||||
|
||||
import (
|
||||
"context"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/mongos"
|
||||
|
||||
"fmt"
|
||||
|
||||
"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.TranslationInfo)
|
||||
// 获取数据库表
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.TranslationInfo.Status, Value: 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.TranslationInfo.CreatedAt, Value: -1},
|
||||
},
|
||||
},
|
||||
}
|
||||
if _, err := db.CreateIndex(ctx, indexes); err != nil {
|
||||
panic(fmt.Sprintf("(channelmod:initTranslationInfoIndex) Create TranslationInfo Index failed! err:%+v:", err))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// InsertOneTranslationInfo 插入一个渠道统计
|
||||
func InsertOneTranslationInfo(ctx context.Context, qa *TranslationInfo) *srvdef.SrvErr {
|
||||
if _, err := db.InsertOne(ctx, qa); err != nil {
|
||||
// log.Warn("TranslationInfomod:InsertOneTranslationInfo db.InsertOne failed", log.E(err))
|
||||
return srvdef.New(srvdef.ErrDbInsertError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DelOneTranslationInfo 删除一个渠道统计
|
||||
func DelOneTranslationInfo(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.DeleteOne(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("TranslationInfomod:DelOneTranslationInfo db.DeleteOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbDeleteError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// FindOneTranslationInfo 查找一个渠道统计
|
||||
func FindOneTranslationInfo(ctx context.Context, filter bson.M) (
|
||||
*TranslationInfo, *srvdef.SrvErr) {
|
||||
var TranslationInfo TranslationInfo
|
||||
if err := db.FindOneEx(ctx, &TranslationInfo, filter); err != nil {
|
||||
if err != mongo.ErrNoDocuments {
|
||||
log.Warn("TranslationInfomod:FindOneTranslationInfo db.FindOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return nil, srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return &TranslationInfo, nil
|
||||
}
|
||||
|
||||
func FindManyTranslationInfos(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (TranslationInfoList, *srvdef.SrvErr) {
|
||||
data := make(TranslationInfoList, 0)
|
||||
if err := db.Find(ctx, &data, filter, opts...); nil != err {
|
||||
log.Warn("faq:FindManyTranslationInfos", log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQuery.Code, "", "")
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// CountTranslationInfos 统计渠道统计数量
|
||||
func CountTranslationInfos(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.Count(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("faqmod:CountTranslationInfos db.Count failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// UpdateOneTranslationInfo 更新一个渠道统计
|
||||
func UpdateOneTranslationInfo(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
||||
result, err := db.UpdateOne(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("post:UpdateOneTranslationInfo db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
if result.MatchedCount != 1 {
|
||||
log.Warn("post:UpdateOneTranslationInfo db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package translationmod
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// @table:translation_info
|
||||
type TranslationInfo struct {
|
||||
Id int64 `json:"id" bson:"_id,omitempty"` // Id
|
||||
Name string `json:"name" bson:"name"` // 分类名称
|
||||
TransCategoryId int64 `json:"transCategoryId" bson:"transCategoryId"` // 导航分类
|
||||
VideoCategoryId int64 `json:"videoCategoryId" bson:"videoCategoryId"` // 视频分类
|
||||
HtmlId int64 `json:"htmlId" bson:"htmlId"` // 富文本ID
|
||||
Link string `json:"link" bson:"link"` // 外部跳转
|
||||
Rank int64 `json:"rank" bson:"rank"` // 排序
|
||||
Status bool `json:"status" bson:"status"` // 上架状态
|
||||
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` // 更新时间
|
||||
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` // 创建时间
|
||||
}
|
||||
type TranslationInfoList []*TranslationInfo
|
||||
@@ -0,0 +1 @@
|
||||
package utils
|
||||
@@ -0,0 +1,11 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
// Init 初始化数据
|
||||
func Init(ctx context.Context) {
|
||||
//initIndex(ctx)
|
||||
return
|
||||
}
|
||||
Executable
+30
@@ -0,0 +1,30 @@
|
||||
package utils
|
||||
|
||||
type TagGenerateId struct {
|
||||
BusinessId string
|
||||
CreateAt string
|
||||
Desc string
|
||||
Id string
|
||||
MaxId string
|
||||
Step string
|
||||
UpdateAt string
|
||||
}
|
||||
|
||||
var FN struct {
|
||||
GenerateId TagGenerateId
|
||||
}
|
||||
|
||||
var TN struct {
|
||||
GenerateId string
|
||||
}
|
||||
|
||||
func init() {
|
||||
FN.GenerateId.BusinessId = "businessId"
|
||||
FN.GenerateId.CreateAt = "createAt"
|
||||
FN.GenerateId.Desc = "desc"
|
||||
FN.GenerateId.Id = "_id"
|
||||
FN.GenerateId.MaxId = "maxId"
|
||||
FN.GenerateId.Step = "step"
|
||||
FN.GenerateId.UpdateAt = "updateAt"
|
||||
TN.GenerateId = "generate_id"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
// @table:generate_id
|
||||
type GenerateId struct {
|
||||
Id primitive.ObjectID `bson:"_id"`
|
||||
UpdateAt time.Time `bson:"updateAt"`
|
||||
BusinessId string `bson:"businessId"`
|
||||
MaxId int64 `bson:"maxId"`
|
||||
Step int64 `bson:"step"`
|
||||
Desc string `bson:"desc"`
|
||||
CreateAt time.Time `bson:"createAt"`
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
package videocategorymod
|
||||
|
||||
import (
|
||||
"context"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/mongos"
|
||||
|
||||
"fmt"
|
||||
|
||||
"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.VideoCategory)
|
||||
// 获取数据库表
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoCategory.Status, Value: 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoCategory.ContentType, Value: 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoCategory.CreatedAt, Value: -1},
|
||||
},
|
||||
},
|
||||
}
|
||||
if _, err := db.CreateIndex(ctx, indexes); err != nil {
|
||||
panic(fmt.Sprintf("(channelmod:initVideoCategoryIndex) Create VideoCategory Index failed! err:%+v:", err))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// InsertOneVideoCategory 插入一个渠道统计
|
||||
func InsertOneVideoCategory(ctx context.Context, qa *VideoCategory) *srvdef.SrvErr {
|
||||
if _, err := db.InsertOne(ctx, qa); err != nil {
|
||||
// log.Warn("VideoCategorymod:InsertOneVideoCategory db.InsertOne failed", log.E(err))
|
||||
return srvdef.New(srvdef.ErrDbInsertError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DelOneVideoCategory 删除一个渠道统计
|
||||
func DelOneVideoCategory(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.DeleteOne(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("VideoCategorymod:DelOneVideoCategory db.DeleteOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbDeleteError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// FindOneVideoCategory 查找一个渠道统计
|
||||
func FindOneVideoCategory(ctx context.Context, filter bson.M) (
|
||||
*VideoCategory, *srvdef.SrvErr) {
|
||||
var VideoCategory VideoCategory
|
||||
if err := db.FindOneEx(ctx, &VideoCategory, filter); err != nil {
|
||||
if err != mongo.ErrNoDocuments {
|
||||
log.Warn("VideoCategorymod:FindOneVideoCategory db.FindOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return nil, srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return &VideoCategory, nil
|
||||
}
|
||||
|
||||
func FindManyVideoCategorys(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (VideoCategoryList, *srvdef.SrvErr) {
|
||||
data := make(VideoCategoryList, 0)
|
||||
if err := db.Find(ctx, &data, filter, opts...); nil != err {
|
||||
log.Warn("faq:FindManyVideoCategorys", log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQuery.Code, "", "")
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// CountVideoCategorys 统计渠道统计数量
|
||||
func CountVideoCategorys(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.Count(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("faqmod:CountVideoCategorys db.Count failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// UpdateOneVideoCategory 更新一个渠道统计
|
||||
func UpdateOneVideoCategory(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
||||
result, err := db.UpdateOne(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("post:UpdateOneVideoCategory db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
if result.MatchedCount != 1 {
|
||||
log.Warn("post:UpdateOneVideoCategory db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func UpdateManyVideoCategory(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
||||
result, err := db.UpdateMany(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("post:UpdateManyVideoCategory db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
if result.MatchedCount < 1 {
|
||||
log.Warn("post:UpdateManyVideoInfomation db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Executable
+46
@@ -0,0 +1,46 @@
|
||||
package videocategorymod
|
||||
|
||||
type TagVideoCategory struct {
|
||||
ContentType string
|
||||
CreatedAt string
|
||||
Desc string
|
||||
Id string
|
||||
IndexNow string
|
||||
Name string
|
||||
Rank string
|
||||
SeoInfo struct {
|
||||
Description string
|
||||
Keyworld string
|
||||
Title string
|
||||
}
|
||||
SortType string
|
||||
Status string
|
||||
Title string
|
||||
UpdatedAt string
|
||||
}
|
||||
|
||||
var FN struct {
|
||||
VideoCategory TagVideoCategory
|
||||
}
|
||||
|
||||
var TN struct {
|
||||
VideoCategory string
|
||||
}
|
||||
|
||||
func init() {
|
||||
FN.VideoCategory.ContentType = "contentType"
|
||||
FN.VideoCategory.CreatedAt = "createdAt"
|
||||
FN.VideoCategory.Desc = "desc"
|
||||
FN.VideoCategory.Id = "_id"
|
||||
FN.VideoCategory.IndexNow = "indexNow"
|
||||
FN.VideoCategory.Name = "name"
|
||||
FN.VideoCategory.Rank = "rank"
|
||||
FN.VideoCategory.SeoInfo.Description = "seoInfo.webDescription"
|
||||
FN.VideoCategory.SeoInfo.Keyworld = "seoInfo.webKeyworld"
|
||||
FN.VideoCategory.SeoInfo.Title = "seoInfo.webTitle"
|
||||
FN.VideoCategory.SortType = "sortType"
|
||||
FN.VideoCategory.Status = "status"
|
||||
FN.VideoCategory.Title = "title"
|
||||
FN.VideoCategory.UpdatedAt = "updatedAt"
|
||||
TN.VideoCategory = "video_category"
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package videocategorymod
|
||||
|
||||
import (
|
||||
"time"
|
||||
"videoweb/pub/pubdef"
|
||||
)
|
||||
|
||||
// @table:video_category
|
||||
type VideoCategory struct {
|
||||
Id int64 `json:"id" bson:"_id,omitempty"` // Id
|
||||
Name string `json:"name" bson:"name"` // 分类名称
|
||||
Title string `json:"title" bson:"title"` // APP显示
|
||||
Desc string `json:"desc" bson:"desc"` // 描述
|
||||
Status bool `json:"status" bson:"status"` // 上架状态
|
||||
ContentType int64 `json:"contentType" bson:"contentType"` // 内容:0: 默认 1:首页 2:今日 3:合集
|
||||
SortType int64 `json:"sortType" bson:"sortType"` // 排序方式 0:上线时间 1:观看次数 2排序
|
||||
Rank int64 `json:"rank" bson:"rank"` // 排序
|
||||
SeoInfo pubdef.SeoValue `json:"seoInfo" bson:"seoInfo"` // Seo相关信息
|
||||
IndexNow int64 `json:"indexNow" bson:"indexNow"` // 是否需要提交 0:代表提交 1:表示已提交 运营通过接口可以修改
|
||||
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` // 更新时间
|
||||
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` // 创建时间
|
||||
}
|
||||
type VideoCategoryList []*VideoCategory
|
||||
type VideoSortType int32
|
||||
|
||||
const (
|
||||
VideoSortTypeAddTime VideoSortType = 0 // 上线时间
|
||||
VideoSortTypeWatchs VideoSortType = 1 // 观看次数
|
||||
VideoSortTypeRank VideoSortType = 2 // 视频排序
|
||||
)
|
||||
Executable
+30
@@ -0,0 +1,30 @@
|
||||
package videocollectionmediamod
|
||||
|
||||
type TagVideoCollectionMediaModel struct {
|
||||
ID string
|
||||
CollectionID string
|
||||
VideoId string
|
||||
Status string
|
||||
Rank string
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
}
|
||||
|
||||
var FN struct {
|
||||
VideoCollectionMediaModel TagVideoCollectionMediaModel
|
||||
}
|
||||
|
||||
var TN struct {
|
||||
VideoCollectionMediaModel string
|
||||
}
|
||||
|
||||
func init() {
|
||||
FN.VideoCollectionMediaModel.ID = "_id"
|
||||
FN.VideoCollectionMediaModel.CollectionID = "collectionId"
|
||||
FN.VideoCollectionMediaModel.VideoId = "videoId"
|
||||
FN.VideoCollectionMediaModel.Status = "status"
|
||||
FN.VideoCollectionMediaModel.Rank = "rank"
|
||||
FN.VideoCollectionMediaModel.CreatedAt = "createdAt"
|
||||
FN.VideoCollectionMediaModel.UpdatedAt = "updatedAt"
|
||||
TN.VideoCollectionMediaModel = "video_collection_media"
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package videocollectionmediamod
|
||||
|
||||
import (
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"time"
|
||||
"videoweb/pub/models/videoinformationmod"
|
||||
)
|
||||
|
||||
// VideoCollectionMediaModel 视频合集资源
|
||||
// @table:video_collection_media
|
||||
type VideoCollectionMediaModel struct {
|
||||
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"` // 唯一ID
|
||||
CollectionID int64 `json:"collectionId" bson:"collectionId"` // 合集ID
|
||||
VideoId int64 `json:"videoId" bson:"videoId"` // 视频ID
|
||||
Status videoinformationmod.InformationSatus `json:"status" bson:"status"` // 状态
|
||||
Rank int64 `json:"rank" bson:"rank"` // 排序
|
||||
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` // 创建时间
|
||||
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` // 刷新时间
|
||||
|
||||
}
|
||||
type VideoCollectionMediaModelList []*VideoCollectionMediaModel
|
||||
@@ -0,0 +1,154 @@
|
||||
package videocollectionmediamod
|
||||
|
||||
import (
|
||||
"context"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/mongos"
|
||||
|
||||
"fmt"
|
||||
|
||||
"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.VideoCollectionMediaModel)
|
||||
// 获取数据库表
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoCollectionMediaModel.Status, Value: 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoCollectionMediaModel.CollectionID, Value: 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoCollectionMediaModel.CollectionID, Value: 1},
|
||||
{Key: FN.VideoCollectionMediaModel.Rank, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoCollectionMediaModel.CollectionID, Value: 1},
|
||||
{Key: FN.VideoCollectionMediaModel.VideoId, Value: 1},
|
||||
},
|
||||
Options: options.Index().SetUnique(true),
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoCollectionMediaModel.VideoId, Value: 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoCollectionMediaModel.CreatedAt, Value: -1},
|
||||
},
|
||||
},
|
||||
}
|
||||
if _, err := db.CreateIndex(ctx, indexes); err != nil {
|
||||
panic(fmt.Sprintf("(channelmod:initVideoCollectionMediaModelIndex) Create VideoCollectionMediaModel Index failed! err:%+v:", err))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// InsertOneVideoCollectionMediaModel 插入一个渠道统计
|
||||
func InsertOneVideoCollectionMediaModel(ctx context.Context, qa *VideoCollectionMediaModel) *srvdef.SrvErr {
|
||||
if _, err := db.InsertOne(ctx, qa); err != nil {
|
||||
// log.Warn("VideoCollectionMediaModelmod:InsertOneVideoCollectionMediaModel db.InsertOne failed", log.E(err))
|
||||
return srvdef.New(srvdef.ErrDbInsertError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DelOneVideoCollectionMediaModel 删除一个渠道统计
|
||||
func DelOneVideoCollectionMediaModel(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.DeleteOne(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("VideoCollectionMediaModelmod:DelOneVideoCollectionMediaModel db.DeleteOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbDeleteError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
func DelManyVideoCollectionMediaModel(ctx context.Context, filter bson.M) (int64, *srvdef.SrvErr) {
|
||||
count, err := db.DeleteMany(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("VideoCollectionMediaModelmod:DelManyVideoCollectionMediaModel db.DeleteMany failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbDeleteError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// FindOneVideoCollectionMediaModel 查找一个渠道统计
|
||||
func FindOneVideoCollectionMediaModel(ctx context.Context, filter bson.M) (
|
||||
*VideoCollectionMediaModel, *srvdef.SrvErr) {
|
||||
var VideoCollectionMediaModel VideoCollectionMediaModel
|
||||
if err := db.FindOneEx(ctx, &VideoCollectionMediaModel, filter); err != nil {
|
||||
if err != mongo.ErrNoDocuments {
|
||||
log.Warn("VideoCollectionMediaModelmod:FindOneVideoCollectionMediaModel db.FindOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return nil, srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return &VideoCollectionMediaModel, nil
|
||||
}
|
||||
|
||||
func FindManyVideoCollectionMediaModels(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (VideoCollectionMediaModelList, *srvdef.SrvErr) {
|
||||
data := make(VideoCollectionMediaModelList, 0)
|
||||
if err := db.Find(ctx, &data, filter, opts...); nil != err {
|
||||
log.Warn("faq:FindManyVideoCollectionMediaModels", log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQuery.Code, "", "")
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// CountVideoCollectionMediaModels 统计渠道统计数量
|
||||
func CountVideoCollectionMediaModels(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.Count(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("faqmod:CountVideoCollectionMediaModels db.Count failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// UpdateOneVideoCollectionMediaModel 更新一个渠道统计
|
||||
func UpdateOneVideoCollectionMediaModel(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
||||
result, err := db.UpdateOne(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("post:UpdateOneVideoCollectionMediaModel db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
if result.MatchedCount != 1 {
|
||||
log.Warn("post:UpdateOneVideoCollectionMediaModel db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func InsertManyVideoCollectionMedia(ctx context.Context, list []*VideoCollectionMediaModel) *srvdef.SrvErr {
|
||||
_, err := db.InsertMany(ctx, &list)
|
||||
if err != nil {
|
||||
log.Warn("post:InsertManyVideoCollectionMediaModel db.InsertMany failed",
|
||||
log.E(err))
|
||||
return srvdef.New(srvdef.ErrDbInsertError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
package videocreatermod
|
||||
|
||||
import (
|
||||
"context"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/mongos"
|
||||
|
||||
"fmt"
|
||||
|
||||
"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.VideoCreaterInfo)
|
||||
// 获取数据库表
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoCreaterInfo.Status, Value: 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoCreaterInfo.CreatedAt, Value: -1},
|
||||
},
|
||||
},
|
||||
}
|
||||
if _, err := db.CreateIndex(ctx, indexes); err != nil {
|
||||
panic(fmt.Sprintf("(channelmod:initVideoCreaterInfoIndex) Create VideoCreaterInfo Index failed! err:%+v:", err))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// InsertOneVideoCreaterInfo 插入一个渠道统计
|
||||
func InsertOneVideoCreaterInfo(ctx context.Context, qa *VideoCreaterInfo) *srvdef.SrvErr {
|
||||
if _, err := db.InsertOne(ctx, qa); err != nil {
|
||||
log.Warn("VideoCreaterInfomod:InsertOneVideoCreaterInfo db.InsertOne failed", log.E(err))
|
||||
return srvdef.New(srvdef.ErrDbInsertError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DelOneVideoCreaterInfo 删除一个渠道统计
|
||||
func DelOneVideoCreaterInfo(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.DeleteOne(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("VideoCreaterInfomod:DelOneVideoCreaterInfo db.DeleteOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbDeleteError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// FindOneVideoCreaterInfo 查找一个渠道统计
|
||||
func FindOneVideoCreaterInfo(ctx context.Context, filter bson.M) (
|
||||
*VideoCreaterInfo, *srvdef.SrvErr) {
|
||||
var VideoCreaterInfo VideoCreaterInfo
|
||||
if err := db.FindOneEx(ctx, &VideoCreaterInfo, filter); err != nil {
|
||||
if err != mongo.ErrNoDocuments {
|
||||
log.Warn("VideoCreaterInfomod:FindOneVideoCreaterInfo db.FindOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return nil, srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return &VideoCreaterInfo, nil
|
||||
}
|
||||
|
||||
func FindManyVideoCreaterInfos(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (VideoCreaterInfoList, *srvdef.SrvErr) {
|
||||
data := make(VideoCreaterInfoList, 0)
|
||||
if err := db.Find(ctx, &data, filter, opts...); nil != err {
|
||||
log.Warn("faq:FindManyVideoCreaterInfos", log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQuery.Code, "", "")
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// CountVideoCreaterInfos 统计渠道统计数量
|
||||
func CountVideoCreaterInfos(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.Count(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("faqmod:CountVideoCreaterInfos db.Count failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// UpdateOneVideoCreaterInfo 更新一个渠道统计
|
||||
func UpdateOneVideoCreaterInfo(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
||||
result, err := db.UpdateOne(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("post:UpdateOneVideoCreaterInfo db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
if result.MatchedCount != 1 {
|
||||
log.Warn("post:UpdateOneVideoCreaterInfo db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func UpdateManyVideoCreaterInfo(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
||||
result, err := db.UpdateMany(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("post:UpdateManyVideoCreaterInfo db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
if result.MatchedCount < 1 {
|
||||
log.Warn("post:UpdateManyVideoInfomation db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Executable
+38
@@ -0,0 +1,38 @@
|
||||
package videocreatermod
|
||||
|
||||
type TagVideoCreaterInfo struct {
|
||||
CreatedAt string
|
||||
Id string
|
||||
IndexNow string
|
||||
Name string
|
||||
SeoInfo struct {
|
||||
Description string
|
||||
Keyworld string
|
||||
Title string
|
||||
}
|
||||
Sort string
|
||||
Status string
|
||||
UpdatedAt string
|
||||
}
|
||||
|
||||
var FN struct {
|
||||
VideoCreaterInfo TagVideoCreaterInfo
|
||||
}
|
||||
|
||||
var TN struct {
|
||||
VideoCreaterInfo string
|
||||
}
|
||||
|
||||
func init() {
|
||||
FN.VideoCreaterInfo.CreatedAt = "createdAt"
|
||||
FN.VideoCreaterInfo.Id = "_id"
|
||||
FN.VideoCreaterInfo.IndexNow = "indexNow"
|
||||
FN.VideoCreaterInfo.Name = "name"
|
||||
FN.VideoCreaterInfo.SeoInfo.Description = "seoInfo.webDescription"
|
||||
FN.VideoCreaterInfo.SeoInfo.Keyworld = "seoInfo.webKeyworld"
|
||||
FN.VideoCreaterInfo.SeoInfo.Title = "seoInfo.webTitle"
|
||||
FN.VideoCreaterInfo.Sort = "sort"
|
||||
FN.VideoCreaterInfo.Status = "status"
|
||||
FN.VideoCreaterInfo.UpdatedAt = "updatedAt"
|
||||
TN.VideoCreaterInfo = "video_creater"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package videocreatermod
|
||||
|
||||
import (
|
||||
"time"
|
||||
"videoweb/pub/pubdef"
|
||||
)
|
||||
|
||||
// @table:video_creater
|
||||
type VideoCreaterInfo struct {
|
||||
Id int64 `json:"id" bson:"_id,omitempty"`
|
||||
Name string `json:"name" bson:"name"` // 帖子标题
|
||||
Status bool `json:"status" bson:"status"` // 上架状态
|
||||
Sort int64 `json:"sort" bson:"sort"` // 排序
|
||||
SeoInfo pubdef.SeoValue `json:"seoInfo" bson:"seoInfo"` // Seo相关信息
|
||||
IndexNow int64 `json:"indexNow" bson:"indexNow"` // 是否需要提交 0:代表提交 1:表示已提交 运营通过接口可以修改
|
||||
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` // 更新时间
|
||||
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` // 创建时间
|
||||
}
|
||||
type VideoCreaterInfoList []*VideoCreaterInfo
|
||||
@@ -0,0 +1,248 @@
|
||||
package videoinformationmod
|
||||
|
||||
import (
|
||||
"context"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/mongos"
|
||||
|
||||
"fmt"
|
||||
|
||||
"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.VideoInformation)
|
||||
// 获取数据库表
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoInformation.AddedTime, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoInformation.CategoryIds, Value: 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoInformation.Tags, Value: 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoInformation.CreatorId, Value: 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoInformation.Status, Value: 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoInformation.CreatedAt, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoInformation.Status, Value: 1},
|
||||
{Key: FN.VideoInformation.CategoryIds, Value: 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoInformation.Video.FileId, Value: 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoInformation.Status, Value: 1},
|
||||
{Key: FN.VideoInformation.Real.WatchTimes, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoInformation.Status, Value: 1},
|
||||
{Key: FN.VideoInformation.Sort, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoInformation.Status, Value: 1},
|
||||
{Key: FN.VideoInformation.AddedTime, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoInformation.Status, Value: 1},
|
||||
{Key: FN.VideoInformation.CategoryIds, Value: 1},
|
||||
{Key: FN.VideoInformation.AddedTime, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoInformation.CreatorId, Value: 1},
|
||||
{Key: FN.VideoInformation.Status, Value: 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: "nodes.nodeId", Value: 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoInformation.Status, Value: 1},
|
||||
{Key: FN.VideoInformation.AddedTime, Value: -1},
|
||||
{Key: FN.VideoInformation.Real.WatchTimes, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoInformation.Status, Value: 1},
|
||||
{Key: FN.VideoInformation.AddedTime, Value: -1},
|
||||
{Key: FN.VideoInformation.Sort, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoInformation.CreatorId, Value: 1},
|
||||
{Key: FN.VideoInformation.Status, Value: 1},
|
||||
{Key: FN.VideoInformation.AddedTime, Value: -1},
|
||||
{Key: FN.VideoInformation.Real.WatchTimes, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoInformation.Status, Value: 1},
|
||||
{Key: FN.VideoInformation.Tags, Value: 1},
|
||||
{Key: FN.VideoInformation.AddedTime, Value: -1},
|
||||
{Key: FN.VideoInformation.Real.WatchTimes, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoInformation.Status, Value: 1},
|
||||
{Key: FN.VideoInformation.AddedTime, Value: -1},
|
||||
{Key: FN.VideoInformation.IsTop, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoInformation.IsTop, Value: -1},
|
||||
{Key: FN.VideoInformation.AddedTime, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoInformation.Sort, Value: -1},
|
||||
{Key: FN.VideoInformation.AddedTime, Value: -1},
|
||||
},
|
||||
},
|
||||
}
|
||||
if _, err := db.CreateIndex(ctx, indexes); err != nil {
|
||||
panic(fmt.Sprintf("(channelmod:initVideoInformationIndex) Create VideoInformation Index failed! err:%+v:", err))
|
||||
}
|
||||
}
|
||||
|
||||
// InsertOneVideoInformation 插入一个渠道统计
|
||||
func InsertOneVideoInformation(ctx context.Context, qa *VideoInformation) *srvdef.SrvErr {
|
||||
if _, err := db.InsertOne(ctx, qa); err != nil {
|
||||
// log.Warn("VideoInformationmod:InsertOneVideoInformation db.InsertOne failed", log.E(err))
|
||||
return srvdef.New(srvdef.ErrDbInsertError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func InsertManyVideoInformation(ctx context.Context, qa []*VideoInformation) *srvdef.SrvErr {
|
||||
if _, err := db.InsertMany(ctx, &qa); err != nil {
|
||||
return srvdef.New(srvdef.ErrDbInsertError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DelOneVideoInformation 删除一个渠道统计
|
||||
func DelOneVideoInformation(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.DeleteOne(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("VideoInformationmod:DelOneVideoInformation db.DeleteOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbDeleteError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// FindOneVideoInformation 查找一个渠道统计
|
||||
func FindOneVideoInformation(ctx context.Context, filter bson.M) (
|
||||
*VideoInformation, *srvdef.SrvErr) {
|
||||
var VideoInformation VideoInformation
|
||||
if err := db.FindOneEx(ctx, &VideoInformation, filter); err != nil {
|
||||
if err != mongo.ErrNoDocuments {
|
||||
log.Warn("VideoInformationmod:FindOneVideoInformation db.FindOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return nil, srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return &VideoInformation, nil
|
||||
}
|
||||
|
||||
func FindManyVideoInformations(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (VideoInformationList, *srvdef.SrvErr) {
|
||||
data := make(VideoInformationList, 0)
|
||||
if err := db.Find(ctx, &data, filter, opts...); nil != err {
|
||||
log.Warn("faq:FindManyVideoInformations", log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQuery.Code, "", "")
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// CountVideoInformations 统计渠道统计数量
|
||||
func CountVideoInformations(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.Count(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("faqmod:CountVideoInformations db.Count failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// UpdateOneVideoInformation 更新一个渠道统计
|
||||
func UpdateOneVideoInformation(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
||||
result, err := db.UpdateOne(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("post:UpdateOneVideoInformation db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
if result.MatchedCount != 1 {
|
||||
log.Warn("post:UpdateOneVideoInformation db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func UpdateManyVideoInformation(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
||||
result, err := db.UpdateMany(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("post:UpdateManyVideoInformation db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
if result.MatchedCount < 1 {
|
||||
log.Warn("post:UpdateManyVideoInfomation db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Executable
+100
@@ -0,0 +1,100 @@
|
||||
package videoinformationmod
|
||||
|
||||
type TagVideoInformation struct {
|
||||
AddedTime string
|
||||
CategoryIds string
|
||||
CoverImg string
|
||||
CreatedAt string
|
||||
CreatorId string
|
||||
CreatorName string
|
||||
Desc string
|
||||
FirstTag string
|
||||
Id string
|
||||
IndexNow string
|
||||
IsHot string
|
||||
IsTop string
|
||||
Keyworld string
|
||||
MediaType string
|
||||
Nodes string
|
||||
Real struct {
|
||||
Comments string
|
||||
MonthWatchs string
|
||||
ShowTimes string
|
||||
TodayWatchs string
|
||||
WatchTimes string
|
||||
WeekWatchs string
|
||||
}
|
||||
Remark string
|
||||
SecondTags string
|
||||
Sort string
|
||||
Status string
|
||||
Tags string
|
||||
Title string
|
||||
UpdatedAt string
|
||||
PageUpdatedAt string
|
||||
Video struct {
|
||||
Cover string
|
||||
FileId string
|
||||
Height string
|
||||
PreMp4FileNameFs string
|
||||
TaskId string
|
||||
Url string
|
||||
VideoTime string
|
||||
Width string
|
||||
UnencryptedPreMp4 string
|
||||
}
|
||||
VideoCount string
|
||||
UnencryptedImage string
|
||||
}
|
||||
|
||||
var FN struct {
|
||||
VideoInformation TagVideoInformation
|
||||
}
|
||||
|
||||
var TN struct {
|
||||
VideoInformation string
|
||||
}
|
||||
|
||||
func init() {
|
||||
FN.VideoInformation.AddedTime = "addedTime"
|
||||
FN.VideoInformation.CategoryIds = "categoryIds"
|
||||
FN.VideoInformation.CoverImg = "coverImg"
|
||||
FN.VideoInformation.CreatedAt = "createdAt"
|
||||
FN.VideoInformation.CreatorId = "creatorId"
|
||||
FN.VideoInformation.CreatorName = "creatorName"
|
||||
FN.VideoInformation.Desc = "desc"
|
||||
FN.VideoInformation.FirstTag = "firstTag"
|
||||
FN.VideoInformation.Id = "_id"
|
||||
FN.VideoInformation.IndexNow = "indexNow"
|
||||
FN.VideoInformation.IsHot = "isHot"
|
||||
FN.VideoInformation.IsTop = "isTop"
|
||||
FN.VideoInformation.Keyworld = "keyworld"
|
||||
FN.VideoInformation.MediaType = "mediaType"
|
||||
FN.VideoInformation.Nodes = "nodes"
|
||||
FN.VideoInformation.Real.Comments = "real.comments"
|
||||
FN.VideoInformation.Real.MonthWatchs = "real.monthWatchs"
|
||||
FN.VideoInformation.Real.ShowTimes = "real.showTimes"
|
||||
FN.VideoInformation.Real.TodayWatchs = "real.todayWatchs"
|
||||
FN.VideoInformation.Real.WatchTimes = "real.watchTimes"
|
||||
FN.VideoInformation.Real.WeekWatchs = "real.weekWatchs"
|
||||
FN.VideoInformation.Remark = "remark"
|
||||
FN.VideoInformation.SecondTags = "secondTags"
|
||||
FN.VideoInformation.Sort = "sort"
|
||||
FN.VideoInformation.Status = "status"
|
||||
FN.VideoInformation.Tags = "tags"
|
||||
FN.VideoInformation.Title = "title"
|
||||
FN.VideoInformation.UpdatedAt = "updatedAt"
|
||||
FN.VideoInformation.PageUpdatedAt = "pageUpdatedAt"
|
||||
FN.VideoInformation.Video.Cover = "video.cover"
|
||||
FN.VideoInformation.Video.FileId = "video.fileId"
|
||||
FN.VideoInformation.Video.Height = "video.height"
|
||||
FN.VideoInformation.Video.PreMp4FileNameFs = "video.preMp4FileNameFs"
|
||||
FN.VideoInformation.Video.TaskId = "video.taskId"
|
||||
FN.VideoInformation.Video.Url = "video.url"
|
||||
FN.VideoInformation.Video.VideoTime = "video.videoTime"
|
||||
FN.VideoInformation.Video.Width = "video.width"
|
||||
FN.VideoInformation.Video.UnencryptedPreMp4 = "video.unencryptedPreMp4"
|
||||
FN.VideoInformation.VideoCount = "videoCount"
|
||||
FN.VideoInformation.UnencryptedImage = "unencryptedImage"
|
||||
TN.VideoInformation = "video_information"
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package videoinformationmod
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// @table:video_information
|
||||
type VideoInformation struct {
|
||||
Id int64 `json:"id" bson:"_id,omitempty"`
|
||||
Title string `json:"title" bson:"title"` // 帖子标题
|
||||
MediaType MediaType `json:"mediaType" bson:"mediaType"` // 资源类型
|
||||
AddedTime time.Time `json:"addedTime" bson:"addedTime"` // 帖子上架时间
|
||||
CreatorId int64 `json:"creatorId" bson:"creatorId"` // 作者Id
|
||||
CreatorName string `json:"creatorName" bson:"creatorName"` // 作者名称
|
||||
Keyworld []string `bson:"keyworld,omitempty" json:"keyworld"` // 关键字
|
||||
FirstTag string `bson:"firstTag,omitempty" json:"firstTag"` // 一级标签
|
||||
SecondTags []string `bson:"secondTags,omitempty" json:"secondTags"` // 二级标签标签
|
||||
CoverImg string `bson:"coverImg,omitempty" json:"coverImg"` // 封面
|
||||
UnencryptedImage string `bson:"unencryptedImage,omitempty" json:"unencryptedImage"` // 不加密封面
|
||||
Desc string `bson:"desc,omitempty" json:"desc"` // 详细描述
|
||||
Remark string `bson:"remark,omitempty" json:"remark"` // 备注
|
||||
Nodes []Node `json:"nodes" bson:"nodes"` // 节点
|
||||
Status InformationSatus `json:"status" bson:"status"` // 帖子上架状态
|
||||
Video VideoInfo `json:"video" bson:"video"` // 视频
|
||||
CategoryIds []int64 `json:"categoryIds" bson:"categoryIds"` // 分类Id
|
||||
Tags []int64 `json:"tags" bson:"tags"` // 标签
|
||||
IsHot bool `json:"isHot" bson:"isHot"` // 是否热门
|
||||
Sort int64 `json:"sort" bson:"sort"` // 排序
|
||||
Real Flow `json:"real" bson:"real"` // 真实流量
|
||||
VideoCount int64 `json:"videoCount" bson:"videoCount"` // 合集视频数量
|
||||
IndexNow int64 `json:"indexNow" bson:"indexNow"` // 是否需要提交 0:代表提交 1:表示已提交 运营通过接口可以修改
|
||||
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` // 更新时间
|
||||
PageUpdatedAt time.Time `json:"pageUpdatedAt" bson:"pageUpdatedAt"` // 页面展示更新时间
|
||||
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` // 创建时间
|
||||
IsTop bool `json:"isTop" bson:"isTop"` // 是否置顶
|
||||
}
|
||||
type VideoInformationList []*VideoInformation
|
||||
|
||||
type Node struct {
|
||||
NodeId string `json:"nodeId" bson:"nodeId"` // 节点ID
|
||||
Title string `bson:"title" json:"title"` // 节点标题
|
||||
Videos []VideoInfo `json:"videos" bson:"videos"` // 视频信息列表
|
||||
Images []string `json:"images" bson:"images"` // 图片
|
||||
Url string `json:"url" bson:"url"` // 链接
|
||||
Text string `json:"text" bson:"text"` // 文本
|
||||
}
|
||||
|
||||
type VideoInfo struct {
|
||||
TaskId string `json:"taskId" bson:"taskId"` // 视频ID(视频才会存在)
|
||||
FileId string `json:"fileId" bson:"fileId"` // 媒资库ID
|
||||
Url string `json:"url" bson:"url"` // 视频URl
|
||||
Cover string `json:"cover" bson:"cover"` // 视频封面
|
||||
Height int64 `json:"height" bson:"height"` // 分辨率高(视频才会存在)
|
||||
Width int64 `json:"width" bson:"width"` // 分辨率宽(视频才会存在)
|
||||
VideoTime int32 `bson:"videoTime" json:"videoTime"` // 影片长度
|
||||
PreMp4FileNameFs string `bson:"preMp4FileNameFs,omitempty" json:"preMp4FileNameFs"` // 预览MP4文件
|
||||
UnencryptedPreMp4 string `bson:"unencryptedPreMp4,omitempty" json:"unencryptedPreMp4"` // 不加密的预览MP4
|
||||
VttFile string `bson:"vttFile" json:"vttFile"` // 雪碧图
|
||||
TotalFrames int64 `bson:"totalFrames,omitempty" json:"totalFrames"` // 总帧数
|
||||
}
|
||||
|
||||
type InformationSatus int32
|
||||
|
||||
const (
|
||||
InformationSatusWaiting InformationSatus = 0 // 初始化
|
||||
InformationSatusVerifyOK InformationSatus = 1 // 上架
|
||||
InformationSatusVerifyCancel InformationSatus = 2 // 下架
|
||||
)
|
||||
|
||||
type Flow struct {
|
||||
WatchTimes int64 `json:"watchTimes" bson:"watchTimes"` // 观看次数
|
||||
ShowTimes int64 `json:"showTimes" bson:"showTimes"` // 展示次数
|
||||
Comments int64 `json:"comments" bson:"comments"` // 评论条数
|
||||
WeekWatchs int64 `json:"weekWatchs" bson:"weekWatchs"` // 本周观看次数
|
||||
MonthWatchs int64 `json:"monthWatchs" bson:"monthWatchs"` // 本月观看次数
|
||||
TodayWatchs int64 `json:"todayWatchs" bson:"todayWatchs"` // 当日观看次数
|
||||
}
|
||||
|
||||
type MediaType int64
|
||||
|
||||
const (
|
||||
MediaType_Video MediaType = 0 // 视频
|
||||
MediaType_Collection MediaType = 1 // 合集
|
||||
MediaType_Advitise MediaType = 2 // 广告
|
||||
)
|
||||
Executable
+38
@@ -0,0 +1,38 @@
|
||||
package videotagmod
|
||||
|
||||
type TagVideoTagInfo struct {
|
||||
CreatedAt string
|
||||
Id string
|
||||
IndexNow string
|
||||
SeoInfo struct {
|
||||
Description string
|
||||
Keyworld string
|
||||
Title string
|
||||
}
|
||||
Sort string
|
||||
Status string
|
||||
Title string
|
||||
UpdatedAt string
|
||||
}
|
||||
|
||||
var FN struct {
|
||||
VideoTagInfo TagVideoTagInfo
|
||||
}
|
||||
|
||||
var TN struct {
|
||||
VideoTagInfo string
|
||||
}
|
||||
|
||||
func init() {
|
||||
FN.VideoTagInfo.CreatedAt = "createdAt"
|
||||
FN.VideoTagInfo.Id = "_id"
|
||||
FN.VideoTagInfo.IndexNow = "indexNow"
|
||||
FN.VideoTagInfo.SeoInfo.Description = "seoInfo.webDescription"
|
||||
FN.VideoTagInfo.SeoInfo.Keyworld = "seoInfo.webKeyworld"
|
||||
FN.VideoTagInfo.SeoInfo.Title = "seoInfo.webTitle"
|
||||
FN.VideoTagInfo.Sort = "sort"
|
||||
FN.VideoTagInfo.Status = "status"
|
||||
FN.VideoTagInfo.Title = "title"
|
||||
FN.VideoTagInfo.UpdatedAt = "updatedAt"
|
||||
TN.VideoTagInfo = "video_taginfo"
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
package videotagmod
|
||||
|
||||
import (
|
||||
"context"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/mongos"
|
||||
|
||||
"fmt"
|
||||
|
||||
"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.VideoTagInfo)
|
||||
// 获取数据库表
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoTagInfo.Status, Value: 1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoTagInfo.CreatedAt, Value: -1},
|
||||
},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{
|
||||
{Key: FN.VideoTagInfo.Status, Value: 1},
|
||||
{Key: FN.VideoTagInfo.Sort, Value: -1},
|
||||
},
|
||||
},
|
||||
}
|
||||
if _, err := db.CreateIndex(ctx, indexes); err != nil {
|
||||
panic(fmt.Sprintf("(channelmod:initVideoTagInfoIndex) Create VideoTagInfo Index failed! err:%+v:", err))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// InsertOneVideoTagInfo 插入一个渠道统计
|
||||
func InsertOneVideoTagInfo(ctx context.Context, qa *VideoTagInfo) *srvdef.SrvErr {
|
||||
if _, err := db.InsertOne(ctx, qa); err != nil {
|
||||
// log.Warn("VideoTagInfomod:InsertOneVideoTagInfo db.InsertOne failed", log.E(err))
|
||||
return srvdef.New(srvdef.ErrDbInsertError, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DelOneVideoTagInfo 删除一个渠道统计
|
||||
func DelOneVideoTagInfo(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.DeleteOne(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("VideoTagInfomod:DelOneVideoTagInfo db.DeleteOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbDeleteError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// FindOneVideoTagInfo 查找一个渠道统计
|
||||
func FindOneVideoTagInfo(ctx context.Context, filter bson.M) (
|
||||
*VideoTagInfo, *srvdef.SrvErr) {
|
||||
var VideoTagInfo VideoTagInfo
|
||||
if err := db.FindOneEx(ctx, &VideoTagInfo, filter); err != nil {
|
||||
if err != mongo.ErrNoDocuments {
|
||||
log.Warn("VideoTagInfomod:FindOneVideoTagInfo db.FindOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return nil, srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return &VideoTagInfo, nil
|
||||
}
|
||||
|
||||
func FindManyVideoTagInfos(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (VideoTagInfoList, *srvdef.SrvErr) {
|
||||
data := make(VideoTagInfoList, 0)
|
||||
if err := db.Find(ctx, &data, filter, opts...); nil != err {
|
||||
log.Warn("faq:FindManyVideoTagInfos", log.E(err), log.Any("filter", filter))
|
||||
return nil, srvdef.New(srvdef.ErrDbQuery.Code, "", "")
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// CountVideoTagInfos 统计渠道统计数量
|
||||
func CountVideoTagInfos(ctx context.Context, filter bson.M) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
count, err := db.Count(ctx, filter)
|
||||
if err != nil {
|
||||
log.Warn("faqmod:CountVideoTagInfos db.Count failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return 0, srvdef.New(srvdef.ErrDbQueryError, "", "")
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// UpdateOneVideoTagInfo 更新一个渠道统计
|
||||
func UpdateOneVideoTagInfo(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
||||
result, err := db.UpdateOne(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("post:UpdateOneVideoTagInfo db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
if result.MatchedCount != 1 {
|
||||
log.Warn("post:UpdateOneVideoTagInfo db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func UpdateManyVideoTagInfo(ctx context.Context, filter bson.M, update bson.M) *srvdef.SrvErr {
|
||||
result, err := db.UpdateMany(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("post:UpdateManyVideoTagInfo db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrDbUpdateError, "", "")
|
||||
}
|
||||
if result.MatchedCount < 1 {
|
||||
log.Warn("post:UpdateManyVideoInfomation db.UpdateOne failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return srvdef.New(srvdef.ErrNoData, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package videotagmod
|
||||
|
||||
import (
|
||||
"time"
|
||||
"videoweb/pub/pubdef"
|
||||
)
|
||||
|
||||
// @table:video_taginfo
|
||||
type VideoTagInfo struct {
|
||||
Id int64 `json:"id" bson:"_id,omitempty"`
|
||||
Title string `json:"title" bson:"title"` // 帖子标题
|
||||
Status bool `json:"status" bson:"status"` // 上架状态
|
||||
Sort int64 `json:"sort" bson:"sort"` // 排序
|
||||
SeoInfo pubdef.SeoValue `json:"seoInfo" bson:"seoInfo"` // Seo相关信息
|
||||
IndexNow int64 `json:"indexNow" bson:"indexNow"` // 是否需要提交 0:代表提交 1:表示已提交 运营通过接口可以修改
|
||||
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` // 更新时间
|
||||
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` // 创建时间
|
||||
}
|
||||
type VideoTagInfoList []*VideoTagInfo
|
||||
Reference in New Issue
Block a user