From e8649e1111c2d1b3ac5e654b12b013793c3f3e14 Mon Sep 17 00:00:00 2001 From: Leufolium Date: Sun, 28 Apr 2024 21:16:18 +0800 Subject: [PATCH] BY ROBIN AT 20240428 --- library/contentaudit/imageaudit/imageaudit.go | 53 ++++++++++++------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/library/contentaudit/imageaudit/imageaudit.go b/library/contentaudit/imageaudit/imageaudit.go index 5ea73d74..20a08668 100644 --- a/library/contentaudit/imageaudit/imageaudit.go +++ b/library/contentaudit/imageaudit/imageaudit.go @@ -48,7 +48,7 @@ func Run(batchId string) (successNum int, failNum int, err error) { // 2.创建请求 // oss不在上海的服务器,需要调用Advance接口 - req, err := createScanImageAdvanceRequest(ctrlBlock) + reqs, err := createScanImageAdvanceRequest(ctrlBlock) if err != nil { logger.Info("Create Scan ImageRequest fail: %v", err) handleBatchError(ctrlBlock, err) @@ -60,25 +60,29 @@ func Run(batchId string) (successNum int, failNum int, err error) { runtime := &teautils.RuntimeOptions{ ConnectTimeout: tea.Int(30000), } - _result, err := defaultImageAuditClient.ScanImageAdvance(req, runtime) - if err != nil { - if _t, ok := err.(*tea.SDKError); ok { - logger.Error("ScanImageAdvance fail, errinfo : %v", util.DerefString(_t.Data)) - } - handleBatchError(ctrlBlock, err) - failNum = len(imageaudittasks) - return - } - logger.Info("Receive the response from ScanImageAdvance: %v", _result.String()) - // 4.处理应答 - err = handleScanImageResponse(ctrlBlock, _result) + for _, req := range reqs { + var _result *imageaudit.ScanImageResponse + _result, err = defaultImageAuditClient.ScanImageAdvance(req, runtime) + if err != nil { + if _t, ok := err.(*tea.SDKError); ok { + logger.Error("ScanImageAdvance fail, errinfo : %v", util.DerefString(_t.Data)) + } + handleBatchError(ctrlBlock, err) + failNum = len(imageaudittasks) + return + } + logger.Info("Receive the response from ScanImageAdvance: %v", _result.String()) + + // 4.处理应答 + err = handleScanImageResponse(ctrlBlock, _result) + } successNum = len(imageaudittasks) return } -func createScanImageAdvanceRequest(ctrlBlock *ImageAuditTaskBatchControlBlock) (request *imageaudit.ScanImageAdvanceRequest, err error) { +func createScanImageAdvanceRequest(ctrlBlock *ImageAuditTaskBatchControlBlock) (requests []*imageaudit.ScanImageAdvanceRequest, err error) { httpClient := http.Client{} imageauditIds := ctrlBlock.ImageAuditIds reqTasks := make([]*imageaudit.ScanImageAdvanceRequestTask, 0) @@ -90,7 +94,6 @@ func createScanImageAdvanceRequest(ctrlBlock *ImageAuditTaskBatchControlBlock) ( logger.Error("httpClient Get fail : %v", err) return } - reqTasks = append(reqTasks, &imageaudit.ScanImageAdvanceRequestTask{ DataId: goproto.String(imageauditIds[i]), ImageURLObject: file.Body, @@ -101,10 +104,24 @@ func createScanImageAdvanceRequest(ctrlBlock *ImageAuditTaskBatchControlBlock) ( }) } - request = &imageaudit.ScanImageAdvanceRequest{ - Scene: scenes, - Task: reqTasks, + // 阿里云一次最多审10条,将待审图片按10条拆分 + requests = make([]*imageaudit.ScanImageAdvanceRequest, 0) + i := 0 + for ; i < len(reqTasks)/10; i++ { + request := &imageaudit.ScanImageAdvanceRequest{ + Scene: scenes, + Task: reqTasks[i*10 : (i+1)*10], + } + requests = append(requests, request) } + if i*10 < len(reqTasks) { + request := &imageaudit.ScanImageAdvanceRequest{ + Scene: scenes, + Task: reqTasks[i*10:], + } + requests = append(requests, request) + } + logger.Info("本次打包:%v", reqs) return }