From d9ef34138b577d5c4717968cac5ce0d396d65627 Mon Sep 17 00:00:00 2001 From: Leufolium Date: Tue, 30 Jul 2024 15:35:27 +0800 Subject: [PATCH] 1 --- api/consts/consts.go | 1 + .../imageaudittask/proto/imageaudittask_op.go | 38 ++++++++++++++++- apollostruct/audit_task_collection_reflect.go | 11 +++++ app/mix/dao/mongo.go | 31 +++++++++++++- app/mix/service/logic/audit_task_decorator.go | 4 ++ app/mix/service/logic/imageaudittask.go | 9 ++++ app/mix/service/service.go | 42 +++++++++++++++++-- library/contentaudit/imageaudit/imageaudit.go | 7 ++-- 8 files changed, 133 insertions(+), 10 deletions(-) create mode 100644 apollostruct/audit_task_collection_reflect.go create mode 100644 app/mix/service/logic/audit_task_decorator.go diff --git a/api/consts/consts.go b/api/consts/consts.go index 666e4274..20f81e3f 100644 --- a/api/consts/consts.go +++ b/api/consts/consts.go @@ -58,6 +58,7 @@ const ( StreamerScoreFormulaKey = "streamer_score_formula" HvyogoSingleDistributeChargePercentageKey = "hvyogo_single_distribute_charge_percentage" DefaultZoneTextKey = "default_zone_text" + AuditTaskCollectionReflectKey = "audit_task_collection_reflect" ) // del_flag diff --git a/api/proto/imageaudittask/proto/imageaudittask_op.go b/api/proto/imageaudittask/proto/imageaudittask_op.go index edea796a..e1ffae8c 100644 --- a/api/proto/imageaudittask/proto/imageaudittask_op.go +++ b/api/proto/imageaudittask/proto/imageaudittask_op.go @@ -2,6 +2,7 @@ package proto import ( "service/api/base" + "service/bizcommon/util" "service/dbstruct" ) @@ -61,7 +62,6 @@ type OpListReq struct { Limit int `json:"limit"` Sort string NotAlignedOpt int - IndexName string } type OpListData struct { @@ -75,6 +75,18 @@ type OpListResp struct { Data *OpListData `json:"data"` } +func (p *OpListReq) GetQueryArgs() (db string, tn string, status int64, offset int, limit int) { + if p == nil { + return "", "", 0, 0, 0 + } + db = util.DerefString(p.AssociativeDatabase) + tn = util.DerefString(p.AssociativeTableName) + status = util.DerefInt64(p.Status) + offset = p.Offset + limit = p.Limit + return +} + // op 批量更新 type OpUpdateByIdsReq struct { base.BaseRequest @@ -105,3 +117,27 @@ type OpReviewBatchResp struct { base.BaseResponse Data *OpReviewBatchData `json:"data"` } + +type OpListByCollectionInfosReq struct { + base.BaseRequest + AssociativeCollections []*CollectionInfo `json:"associative_collections"` + Status *int64 `json:"status"` + Offset int `json:"offset"` + Limit int `json:"limit"` +} + +type OpListByCollectionInfosData struct { + List []*ImageAuditTaskVO `json:"list"` + Offset int `json:"offset"` + More int `json:"more"` +} + +type OpListByCollectionInfosResp struct { + base.BaseResponse + Data *OpListByCollectionInfosData `json:"data"` +} + +type CollectionInfo struct { + AssociativeDatabase string `json:"associative_data_base"` + AssociativeTableName string `json:"associative_table_name"` +} diff --git a/apollostruct/audit_task_collection_reflect.go b/apollostruct/audit_task_collection_reflect.go new file mode 100644 index 00000000..312ca3fd --- /dev/null +++ b/apollostruct/audit_task_collection_reflect.go @@ -0,0 +1,11 @@ +package apollostruct + +// 账户初始化数据 +type AuditTaskCollectionReflectCfg struct { + Map map[string][]*CollectionInfo `json:"map"` +} + +type CollectionInfo struct { + Database string `json:"database"` // 数据库 + TableName string `json:"table_name"` // 表名 +} diff --git a/app/mix/dao/mongo.go b/app/mix/dao/mongo.go index 51370a72..37410720 100644 --- a/app/mix/dao/mongo.go +++ b/app/mix/dao/mongo.go @@ -3471,7 +3471,6 @@ func (m *Mongo) GetImageAuditTaskList(ctx *gin.Context, req *imageaudittaskproto if req.Sort != "" { sortClause = req.Sort } - opt := options2.Find().SetHint(req.IndexName) err := col.Find(ctx, query).Sort(sortClause).Skip(int64(req.Offset)).Limit(int64(req.Limit)).All(&list) if err == qmgo.ErrNoSuchDocuments { err = nil @@ -3480,6 +3479,36 @@ func (m *Mongo) GetImageAuditTaskList(ctx *gin.Context, req *imageaudittaskproto return list, err } +func (m *Mongo) GetImageAuditTaskListByCollectionInfos(ctx *gin.Context, req *imageaudittaskproto.OpListByCollectionInfosReq) ([]*dbstruct.ImageAuditTask, error) { + list := make([]*dbstruct.ImageAuditTask, 0) + col := m.getColImageAuditTask() + query := qmgo.M{ + "is_aligned": qmgo.M{ + "$ne": consts.ImageAuditIsAligned_Yes, + }, + "del_flag": 0, + } + if len(req.AssociativeCollections) > 0 { + orClause := make([]qmgo.M, 0) + for _, collectionInfo := range req.AssociativeCollections { + orClause = append(orClause, qmgo.M{ + "associative_database": collectionInfo.AssociativeDatabase, + "associative_table_name": collectionInfo.AssociativeTableName, + }) + } + query["$or"] = orClause + } + if req.Status != nil { + query["status"] = util.DerefInt64(req.Status) + } + err := col.Find(ctx, query).Sort("-ct").Skip(int64(req.Offset)).Limit(int64(req.Limit)).All(&list) + if err == qmgo.ErrNoSuchDocuments { + err = nil + return list, err + } + return list, err +} + func (m *Mongo) GetImageAuditTaskListByIds(ctx *gin.Context, ids []string) ([]*dbstruct.ImageAuditTask, error) { list := make([]*dbstruct.ImageAuditTask, 0) col := m.getColImageAuditTask() diff --git a/app/mix/service/logic/audit_task_decorator.go b/app/mix/service/logic/audit_task_decorator.go new file mode 100644 index 00000000..c4e78828 --- /dev/null +++ b/app/mix/service/logic/audit_task_decorator.go @@ -0,0 +1,4 @@ +package logic + +type ContentAuditTaskService interface { +} diff --git a/app/mix/service/logic/imageaudittask.go b/app/mix/service/logic/imageaudittask.go index 44326651..822123e9 100644 --- a/app/mix/service/logic/imageaudittask.go +++ b/app/mix/service/logic/imageaudittask.go @@ -65,6 +65,15 @@ func (p *ImageAuditTask) OpList(ctx *gin.Context, req *imageaudittaskproto.OpLis return list, nil } +func (p *ImageAuditTask) OpListByCollectionInfos(ctx *gin.Context, req *imageaudittaskproto.OpListByCollectionInfosReq) ([]*dbstruct.ImageAuditTask, error) { + list, err := p.store.GetImageAuditTaskListByCollectionInfos(ctx, req) + if err != nil { + logger.Error("GetImageAuditTaskListByCollectionInfos fail, err: %v", err) + return make([]*dbstruct.ImageAuditTask, 0), err + } + return list, nil +} + func (p *ImageAuditTask) OpUpdateByBatchId(ctx *gin.Context, batchId string, imageaudittask *dbstruct.ImageAuditTask) error { err := p.store.UpdateImageAuditTaskByBatchId(ctx, batchId, imageaudittask) if err != nil { diff --git a/app/mix/service/service.go b/app/mix/service/service.go index 93747f66..6428ba9e 100644 --- a/app/mix/service/service.go +++ b/app/mix/service/service.go @@ -3161,10 +3161,44 @@ func (s *Service) OpGetImageAuditTaskVOList(ctx *gin.Context, req *imageaudittas return } - // 仅查询未对齐的任务 - req.NotAlignedOpt = 1 - req.IndexName = "idx_list" // 指定索引 - list, err := _DefaultImageAuditTask.OpList(ctx, req) + // 获取映射表 + cfg := apollostruct.AuditTaskCollectionReflectCfg{} + err := apollo.GetJson(consts.AuditTaskCollectionReflectKey, &cfg, apollo.ApolloOpts().SetNamespace("application")) + if err != nil { + logger.Error("Apollo read failed : %v", err) + return make([]*imageaudittaskproto.ImageAuditTaskVO, 0), errcode.ErrCodeApolloReadFail + } + + // 将查询的集合信息进行映射,决定查询方式 + key := fmt.Sprintf("%v|%v", util.DerefString(req.AssociativeDatabase), util.DerefString(req.AssociativeTableName)) + collectionInfos, ok := cfg.Map[key] + + var queryFunc func(ctx *gin.Context, req *imageaudittaskproto.OpListReq) ([]*dbstruct.ImageAuditTask, error) + if !ok || len(collectionInfos) == 0 { + queryFunc = func(ctx *gin.Context, req *imageaudittaskproto.OpListReq) ([]*dbstruct.ImageAuditTask, error) { + // 仅查询未对齐的任务 + req.NotAlignedOpt = 1 + return _DefaultImageAuditTask.OpList(ctx, req) + } + } else { + queryFunc = func(ctx *gin.Context, req *imageaudittaskproto.OpListReq) ([]*dbstruct.ImageAuditTask, error) { + associativeCollections := make([]*imageaudittaskproto.CollectionInfo, 0) + for _, collectionInfo := range collectionInfos { + associativeCollections = append(associativeCollections, &imageaudittaskproto.CollectionInfo{ + AssociativeDatabase: collectionInfo.Database, + AssociativeTableName: collectionInfo.TableName, + }) + } + return _DefaultImageAuditTask.OpListByCollectionInfos(ctx, &imageaudittaskproto.OpListByCollectionInfosReq{ + BaseRequest: req.BaseRequest, + AssociativeCollections: associativeCollections, + Status: req.Status, + Offset: req.Offset, + Limit: req.Limit, + }) + } + } + list, err := queryFunc(ctx, req) if err != nil { logger.Error("OpGetImageAuditTaskListByMid fail, req: %v, err: %v", util.ToJson(req), err) ec = errcode.ErrCodeImageAuditTaskSrvFail diff --git a/library/contentaudit/imageaudit/imageaudit.go b/library/contentaudit/imageaudit/imageaudit.go index 81ace85a..b247281c 100644 --- a/library/contentaudit/imageaudit/imageaudit.go +++ b/library/contentaudit/imageaudit/imageaudit.go @@ -33,10 +33,9 @@ func Run(batchId string) (successNum int, failNum int, err error) { // 查询该批次所有审核任务 imageaudittasks, err := _DefaultImageAuditTask.OpList(&gin.Context{}, &imageaudittaskproto.OpListReq{ - BatchId: goproto.String(batchId), - Status: goproto.Int64(consts.ImageAudit_Created), - Sort: "ct", - IndexName: "idx_batch_id", + BatchId: goproto.String(batchId), + Status: goproto.Int64(consts.ImageAudit_Created), + Sort: "ct", }) if err != nil { logger.Info("_DefaultImageAuditTask OpList fail: %v", err)