@@ -0,0 +1,57 @@
|
||||
package srv_playlet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"videoweb/pub/models/mwacc"
|
||||
"videoweb/pub/models/playletmod"
|
||||
"videoweb/web/middleware/auth"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
// ResolveOperator 解析当前后台登录操作人,供短剧写操作与媒资入库共用。
|
||||
func ResolveOperator(ctx context.Context) (int64, string) {
|
||||
return resolvePlayletOperator(ctx)
|
||||
}
|
||||
|
||||
// resolvePlayletOperator 从后台登录态解析当前操作人。
|
||||
func resolvePlayletOperator(ctx context.Context) (int64, string) {
|
||||
c, ok := ctx.(*gin.Context)
|
||||
if !ok || c == nil {
|
||||
return 0, ""
|
||||
}
|
||||
accId := auth.GetAccount(c)
|
||||
if accId <= 0 {
|
||||
return 0, ""
|
||||
}
|
||||
acc, err := mwacc.FindOneAccByFilter(c, bson.M{
|
||||
mwacc.FN.MwAcc.Id: accId,
|
||||
}, options.FindOne().SetProjection(bson.D{
|
||||
{Key: mwacc.FN.MwAcc.Id, Value: 1},
|
||||
{Key: mwacc.FN.MwAcc.UserName, Value: 1},
|
||||
}))
|
||||
if err != nil || acc == nil {
|
||||
return accId, ""
|
||||
}
|
||||
return acc.Id, acc.UserName
|
||||
}
|
||||
|
||||
// applyPlayletOperatorToSetDoc 将当前操作人写入更新文档。
|
||||
func applyPlayletOperatorToSetDoc(ctx context.Context, setDoc bson.M) {
|
||||
if setDoc == nil {
|
||||
return
|
||||
}
|
||||
operatorId, operatorName := resolvePlayletOperator(ctx)
|
||||
setDoc[playletmod.FN.Playlet.OperatorId] = operatorId
|
||||
setDoc[playletmod.FN.Playlet.OperatorName] = operatorName
|
||||
}
|
||||
|
||||
// applyPlayletOperatorToDoc 将当前操作人写入新增文档。
|
||||
func applyPlayletOperatorToDoc(ctx context.Context, doc *playletmod.Playlet) {
|
||||
if doc == nil {
|
||||
return
|
||||
}
|
||||
doc.OperatorId, doc.OperatorName = resolvePlayletOperator(ctx)
|
||||
}
|
||||
Reference in New Issue
Block a user