This commit is contained in:
jiaji.H 2025-12-17 09:14:09 +08:00
commit 345bf66c43
7 changed files with 191 additions and 16 deletions

View File

@ -485,6 +485,12 @@ type MediaUserInfo struct {
MediaAccountUuid string `protobuf:"bytes,8,opt,name=mediaAccountUuid,proto3" json:"mediaAccountUuid"`
CreatedDate string `protobuf:"bytes,9,opt,name=createdDate,proto3" json:"createdDate"`
AuthStatus AuthStatusENUM `protobuf:"varint,10,opt,name=authStatus,proto3,enum=Cast.AuthStatusENUM" json:"authStatus"`
PendingVideoCount int32 `protobuf:"varint,11,opt,name=pendingVideoCount,proto3" json:"pendingVideoCount"`
UploadedVideoCount int32 `protobuf:"varint,12,opt,name=uploadedVideoCount,proto3" json:"uploadedVideoCount"`
ReleasedVideoTotal int32 `protobuf:"varint,13,opt,name=releasedVideoTotal,proto3" json:"releasedVideoTotal"`
PendingPostCount int32 `protobuf:"varint,14,opt,name=pendingPostCount,proto3" json:"pendingPostCount"`
UploadedPostCount int32 `protobuf:"varint,15,opt,name=uploadedPostCount,proto3" json:"uploadedPostCount"`
ReleasedPostTotal int32 `protobuf:"varint,16,opt,name=releasedPostTotal,proto3" json:"releasedPostTotal"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
@ -589,6 +595,48 @@ func (x *MediaUserInfo) GetAuthStatus() AuthStatusENUM {
return AuthStatusENUM_UNKNOWNAuth
}
func (x *MediaUserInfo) GetPendingVideoCount() int32 {
if x != nil {
return x.PendingVideoCount
}
return 0
}
func (x *MediaUserInfo) GetUploadedVideoCount() int32 {
if x != nil {
return x.UploadedVideoCount
}
return 0
}
func (x *MediaUserInfo) GetReleasedVideoTotal() int32 {
if x != nil {
return x.ReleasedVideoTotal
}
return 0
}
func (x *MediaUserInfo) GetPendingPostCount() int32 {
if x != nil {
return x.PendingPostCount
}
return 0
}
func (x *MediaUserInfo) GetUploadedPostCount() int32 {
if x != nil {
return x.UploadedPostCount
}
return 0
}
func (x *MediaUserInfo) GetReleasedPostTotal() int32 {
if x != nil {
return x.ReleasedPostTotal
}
return 0
}
type MediaUserListResp struct {
state protoimpl.MessageState `protogen:"open.v1"`
Data []*MediaUserInfo `protobuf:"bytes,1,rep,name=data,proto3" json:"data"`
@ -12153,7 +12201,7 @@ const file_pb_fiee_cast_proto_rawDesc = "" +
"authStatus\x18\n" +
" \x01(\x0e2\x14.Cast.AuthStatusENUMR\n" +
"authStatus\x12 \n" +
"\vmediaUserID\x18\v \x01(\tR\vmediaUserID\"\x8d\x03\n" +
"\vmediaUserID\x18\v \x01(\tR\vmediaUserID\"\xa3\x05\n" +
"\rMediaUserInfo\x12*\n" +
"\x10platformUserName\x18\x01 \x01(\tR\x10platformUserName\x12\x1e\n" +
"\n" +
@ -12173,7 +12221,13 @@ const file_pb_fiee_cast_proto_rawDesc = "" +
"\n" +
"authStatus\x18\n" +
" \x01(\x0e2\x14.Cast.AuthStatusENUMR\n" +
"authStatus\"R\n" +
"authStatus\x12,\n" +
"\x11pendingVideoCount\x18\v \x01(\x05R\x11pendingVideoCount\x12.\n" +
"\x12uploadedVideoCount\x18\f \x01(\x05R\x12uploadedVideoCount\x12.\n" +
"\x12releasedVideoTotal\x18\r \x01(\x05R\x12releasedVideoTotal\x12*\n" +
"\x10pendingPostCount\x18\x0e \x01(\x05R\x10pendingPostCount\x12,\n" +
"\x11uploadedPostCount\x18\x0f \x01(\x05R\x11uploadedPostCount\x12,\n" +
"\x11releasedPostTotal\x18\x10 \x01(\x05R\x11releasedPostTotal\"R\n" +
"\x11MediaUserListResp\x12'\n" +
"\x04data\x18\x01 \x03(\v2\x13.Cast.MediaUserInfoR\x04data\x12\x14\n" +
"\x05count\x18\x02 \x01(\x03R\x05count\"\xd1\x03\n" +

View File

@ -199,6 +199,18 @@ func (m *MediaUserInfo) validate(all bool) error {
// no validation rules for AuthStatus
// no validation rules for PendingVideoCount
// no validation rules for UploadedVideoCount
// no validation rules for ReleasedVideoTotal
// no validation rules for PendingPostCount
// no validation rules for UploadedPostCount
// no validation rules for ReleasedPostTotal
if len(errors) > 0 {
return MediaUserInfoMultiError(errors)
}

View File

@ -30,6 +30,7 @@ func InitTasks() error {
err = cm.AddTask("artistAutoConfirmAnalysis", "0 */1 * * * *", ArtistAutoConfirmAnalysisTask)
err = cm.AddTask("refreshWorkAnalysisApprovalStatus", "0 */1 * * * *", RefreshWorkAnalysisApprovalStatusTask)
err = cm.AddTask("scheduledPublish", "0 */1 * * * *", ScheduledPublishTask)
if err != nil {
log.Printf("添加定时任务失败: %v", err)
}
@ -307,3 +308,79 @@ func processWorkPublishQueueData(data string) error {
zap.L().Info("发布工作成功", zap.String("work_uuid", workUuid))
return nil
}
// ScheduledPublishTask 定时发布任务从Redis Sorted Set中获取所有workUuid并根据score判断处理
func ScheduledPublishTask() {
// 加上锁
lockKey := "scheduled_publish:lock"
reply := cache.RedisClient.SetNX(lockKey, time.Now().Format("2006-01-02 15:04:05"), 1*time.Hour)
if !reply.Val() {
zap.L().Warn("定时发布任务正在被其他实例处理")
return
}
defer func() {
cache.RedisClient.Del(lockKey)
}()
// 获取所有数据不限制score范围
opt := redis.ZRangeBy{
Min: "-inf",
Max: "+inf",
}
// 从Redis Sorted Set中获取所有workUuid及其score
workList, err := cache.RedisClient.ZRangeByScoreWithScores(modelCast.ScheduledPublishQueueKey, opt).Result()
if err != nil {
zap.L().Error("获取定时发布任务失败", zap.Error(err))
return
}
if len(workList) == 0 {
zap.L().Debug("没有定时发布任务")
return
}
publishCount := 0
expiredCount := 0
zap.L().Info("发现定时发布任务", zap.Int("total_count", len(workList)))
// 遍历所有数据根据score判断处理
for _, item := range workList {
workUuid := item.Member.(string)
score := item.Score
now := float64(time.Now().Unix())
// 如果score小于当前时间删除但不消费不发布
if score < now {
zap.L().Info("发现过期的定时发布任务,直接删除不发布",
zap.String("work_uuid", workUuid),
zap.Float64("score", score),
zap.Float64("now", now))
removed, delErr := cache.RedisClient.ZRem(modelCast.ScheduledPublishQueueKey, workUuid).Result()
if delErr != nil {
zap.L().Error("删除过期定时发布任务失败", zap.Error(delErr), zap.String("work_uuid", workUuid))
} else if removed > 0 {
expiredCount++
zap.L().Info("已删除过期定时发布任务", zap.String("work_uuid", workUuid))
}
continue
}
// score大于等于当前时间正常发布
zap.L().Info("处理定时发布任务",
zap.String("work_uuid", workUuid),
zap.Float64("score", score))
_ = serverCast.PublishWork(context.Background(), &cast.PublishReq{
WorkUuids: []string{workUuid},
})
removed, delErr := cache.RedisClient.ZRem(modelCast.ScheduledPublishQueueKey, workUuid).Result()
if delErr != nil {
zap.L().Error("删除定时发布任务失败", zap.Error(delErr), zap.String("work_uuid", workUuid))
} else if removed > 0 {
publishCount++
zap.L().Info("已发布并删除定时发布任务", zap.String("work_uuid", workUuid))
}
}
zap.L().Info("定时发布任务处理完成",
zap.Int("published_count", publishCount),
zap.Int("expired_count", expiredCount),
zap.Int("total_count", len(workList)))
}

View File

@ -16,6 +16,7 @@ const (
AutoConfirmQueueKey = "auto_confirm:queue"
AutoConfirmLockKey = "auto_confirm:lock:%s"
WorkPublishQueueKey = "work:publish:queue"
ScheduledPublishQueueKey = "scheduled:publish:queue" // 定时发布队列
)
var WorkCategoryMM = map[int]string{

View File

@ -261,6 +261,8 @@ func WorkAnalysisConfirm(c *gin.Context) { // 确认数据分析并扣除余量
ConfirmRemark: req.ConfirmRemark,
ConfirmStatus: 2,
})
fmt.Println("res:", res)
fmt.Println("err:", err)
if err != nil {
service.Error(c, errors.New(common.UpdateWorkStatusFailed))
return
@ -310,6 +312,8 @@ func WorkAnalysisConfirm(c *gin.Context) { // 确认数据分析并扣除余量
CostType: resp.UsedType,
ConfirmStatus: 1,
})
fmt.Println("res:", res)
fmt.Println("err:", err)
if err != nil {
service.Error(c, errors.New(common.UpdateWorkStatusFailed))
return

View File

@ -37,6 +37,32 @@ func MediaUserList(ctx *gin.Context) {
service.Error(ctx, err)
return
}
var statResp *bundle.ArtistUploadStatsResponse
for _, v := range resp.Data {
statResp, err = service.BundleProvider.GetArtistUploadStatsList(context.Background(), &bundle.TaskQueryRequest{
Keyword: v.ArtistPhone,
Page: 0,
PageSize: 0,
SortBy: "",
SortType: "",
LastTaskAssignee: "",
SubNums: nil,
})
if err != nil {
service.Error(ctx, errors.New("查询艺人数据错误"))
return
}
info := statResp.Items[0]
// "pendingVideoCount": 10, // 待上传视频数 "uploadedVideoCount": 25, // 已上传视频数 "releasedVideoTotal": 35, // 已释放视频总数
//"pendingPostCount": 14, // 待上传图文数 "uploadedPostCount": 21, // 已上传图文数 "releasedPostTotal": 35, // 已释放图文总数
v.PendingVideoCount = info.PendingVideoCount
v.UploadedVideoCount = info.UploadedVideoCount
v.ReleasedVideoTotal = info.ReleasedVideoTotal
v.PendingPostCount = info.PendingPostCount
v.UploadedPostCount = info.UploadedPostCount
v.ReleasedPostTotal = info.ReleasedPostTotal
}
go func() {
for _, v := range resp.Data {
_ = SyncAsAuth(v.ArtistUuid)

View File

@ -367,7 +367,8 @@ func CheckUserBundleBalance(userID int32, balanceType modelCast.BalanceTypeEnum)
}
case modelCast.BalanceTypeDataValue:
if resp.DataAnalysisNumber-resp.DataAnalysisConsumptionNumber <= 0 {
err = errors.New(e.ErrorBalanceInsufficient)
err = errors.New("该艺人数据可用次数为0")
// err = errors.New(e.ErrorBalanceInsufficient)
return
}
}