Files
web_huakui_server/web/service/srv_playlet/operator.go
T
rootandClaude Opus 4.7 85c0071fd8 feat: 从黄果 NET hgdjnet-server 9bfbafe 导入 HKDJ 官网后端
来源:hgdjnet-server 9bfbafe10d417deea959bd53117bc88a10e60a83
项目身份 HKDJ / JHA-216,独立官网仓库,Jenkins 守卫键 hkdjnet
测试目录 /server/hkdj_net,App/Web API 30331/30332

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-10-16 11:20:04 +08:00

58 lines
1.6 KiB
Go

package srv_playlet
import (
"context"
"hkdj-web-server/pub/models/mwacc"
"hkdj-web-server/pub/models/playletmod"
"hkdj-web-server/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)
}