BY ROBIN AT 20240428

This commit is contained in:
Leufolium 2024-04-28 21:16:18 +08:00
parent 6bf1f9e472
commit e8649e1111
1 changed files with 35 additions and 18 deletions

View File

@ -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
}