by Robin at 20240429

This commit is contained in:
Leufolium 2024-04-29 14:17:29 +08:00
parent 58a238e9c9
commit f6c60cf574
1 changed files with 32 additions and 13 deletions

View File

@ -44,7 +44,7 @@ func Run(batchId string) (successNum int, failNum int, err error) {
ctrlBlock := NewTextAuditTaskBatchControlBlock(textaudittasks, batchId) ctrlBlock := NewTextAuditTaskBatchControlBlock(textaudittasks, batchId)
// 2.创建请求 // 2.创建请求
req, err := createScanTextRequest(ctrlBlock) reqs, err := createScanTextRequest(ctrlBlock)
if err != nil { if err != nil {
logger.Info("Create Scan TextRequest fail: %v", err) logger.Info("Create Scan TextRequest fail: %v", err)
handleBatchError(ctrlBlock, err) handleBatchError(ctrlBlock, err)
@ -55,21 +55,27 @@ func Run(batchId string) (successNum int, failNum int, err error) {
runtime := &teautils.RuntimeOptions{ runtime := &teautils.RuntimeOptions{
ConnectTimeout: tea.Int(30000), ConnectTimeout: tea.Int(30000),
} }
_result, err := defaultTextAuditClient.ScanTextWithOptions(req, runtime)
if err != nil { results := make([]*textaudit.ScanTextResponseBodyDataElements, 0)
logger.Error("ScanTextWithOptions fail : %v", err) for _, req := range reqs {
handleBatchError(ctrlBlock, err) var _result *textaudit.ScanTextResponse
return _result, err = defaultTextAuditClient.ScanTextWithOptions(req, runtime)
if err != nil {
logger.Error("ScanTextWithOptions fail : %v", err)
handleBatchError(ctrlBlock, err)
return
}
results = append(results, _result.Body.Data.Elements...)
} }
// 4.处理应答 // 4.处理应答
err = handleScanTextResponse(ctrlBlock, _result) err = handleScanTextResponseBodyDataElements(ctrlBlock, results)
successNum = len(textaudittasks) successNum = len(textaudittasks)
return return
} }
func createScanTextRequest(ctrlBlock *TextAuditTaskBatchControlBlock) (request *textaudit.ScanTextRequest, err error) { func createScanTextRequest(ctrlBlock *TextAuditTaskBatchControlBlock) (requests []*textaudit.ScanTextRequest, err error) {
reqTasks := make([]*textaudit.ScanTextRequestTasks, 0) reqTasks := make([]*textaudit.ScanTextRequestTasks, 0)
for _, taskCtrlBlock := range ctrlBlock.TaskCtrlBlocks { for _, taskCtrlBlock := range ctrlBlock.TaskCtrlBlocks {
reqTasks = append(reqTasks, &textaudit.ScanTextRequestTasks{ reqTasks = append(reqTasks, &textaudit.ScanTextRequestTasks{
@ -84,16 +90,29 @@ func createScanTextRequest(ctrlBlock *TextAuditTaskBatchControlBlock) (request *
} }
} }
request = &textaudit.ScanTextRequest{ // 阿里云一次最多审10条将待审图片按10条拆分
Labels: scanLabels, requests = make([]*textaudit.ScanTextRequest, 0)
Tasks: reqTasks, i := 0
for ; i < len(reqTasks)/10; i++ {
request := &textaudit.ScanTextRequest{
Labels: scanLabels,
Tasks: reqTasks[i*10 : (i+1)*10],
}
requests = append(requests, request)
} }
if i*10 < len(reqTasks) {
request := &textaudit.ScanTextRequest{
Labels: scanLabels,
Tasks: reqTasks[i*10 : (i+1)*10],
}
requests = append(requests, request)
}
logger.Info("本次打包:%v", reqTasks) logger.Info("本次打包:%v", reqTasks)
return return
} }
func handleScanTextResponse(ctrlBlock *TextAuditTaskBatchControlBlock, resp *textaudit.ScanTextResponse) (err error) { func handleScanTextResponseBodyDataElements(ctrlBlock *TextAuditTaskBatchControlBlock, results []*textaudit.ScanTextResponseBodyDataElements) (err error) {
results := resp.Body.Data.Elements
taskCtrlBlocks := ctrlBlock.TaskCtrlBlocks taskCtrlBlocks := ctrlBlock.TaskCtrlBlocks
actionMap := ctrlBlock.ActionMap actionMap := ctrlBlock.ActionMap
for i, result := range results { for i, result := range results {