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