|
|
|
@ -10,6 +10,8 @@ import com.aliyuncs.green.model.v20180509.VoiceAsyncScanRequest; |
|
|
|
import com.aliyuncs.green.model.v20180509.VoiceAsyncScanResultsRequest; |
|
|
|
import com.aliyuncs.http.FormatType; |
|
|
|
import com.aliyuncs.http.HttpResponse; |
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.openapi.scan.common.constant.SysConstant; |
|
|
|
import com.epmet.openapi.scan.common.enu.*; |
|
|
|
@ -30,6 +32,7 @@ import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
|
|
import java.io.UnsupportedEncodingException; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.UUID; |
|
|
|
|
|
|
|
@ -306,7 +309,18 @@ public class ScanServiceImpl implements ScanService { |
|
|
|
//成功返回
|
|
|
|
VoiceAsyncScanTaskResult resultDto=new VoiceAsyncScanTaskResult(); |
|
|
|
resultDto.setSeed(voiceAsyncScanParam.getSeed()); |
|
|
|
resultDto.setTaskList(taskList); |
|
|
|
List<VoiceAsyncScanTaskDataDTO> successList = new ArrayList<>(); |
|
|
|
List<VoiceAsyncScanTaskDataDTO> failedList = new ArrayList<>(); |
|
|
|
taskList.forEach(taskDetail -> { |
|
|
|
if (HttpStatus.SC_OK == taskDetail.getCode()) { |
|
|
|
successList.add(taskDetail); |
|
|
|
} else { |
|
|
|
failedList.add(taskDetail); |
|
|
|
} |
|
|
|
}); |
|
|
|
resultDto.setSuccessTasks(successList); |
|
|
|
resultDto.setFailTasks(failedList); |
|
|
|
resultDto.setAllSuccess(resultDto.isAllSuccess()); |
|
|
|
if (StringUtils.isNotBlank(voiceAsyncScanParam.getCallback())) { |
|
|
|
// 存储seed和 任务id、dataId的关系 用于回调鉴权
|
|
|
|
log.info("need to save seed and taskId、dataId的关系"); |
|
|
|
@ -400,11 +414,11 @@ public class ScanServiceImpl implements ScanService { |
|
|
|
try { |
|
|
|
request.setHttpContent(JSON.toJSONString(taskIds).getBytes(SysConstant.UTF8), SysConstant.UTF8, FormatType.JSON); |
|
|
|
} catch (UnsupportedEncodingException e) { |
|
|
|
log.error("getVoiceAsyncScanResult parse param exception", e); |
|
|
|
log.error("voiceResults parse param exception", e); |
|
|
|
return new Result<List<VoiceAsyncScanResult>>().error(SysResponseEnum.SCAN_PARAM_ERROR.getCode(), SysResponseEnum.SCAN_PARAM_ERROR.getMsg()); |
|
|
|
} |
|
|
|
|
|
|
|
log.info("语音异步检测结果查询入参:"+JSON.toJSONString(taskIds,true)); |
|
|
|
// log.info("语音异步检测结果查询入参:"+JSON.toJSONString(taskIds,true));
|
|
|
|
|
|
|
|
try { |
|
|
|
HttpResponse httpResponse = IAcsClientUtil.getIAcsClient().doAction(request); |
|
|
|
@ -417,12 +431,13 @@ public class ScanServiceImpl implements ScanService { |
|
|
|
//获取data列表
|
|
|
|
JSONArray dataResults = scrResponse.getJSONArray(SysConstant.DATA); |
|
|
|
List<VoiceAsyncScanResult> resultList = dataResults.toJavaList(VoiceAsyncScanResult.class); |
|
|
|
List<VoiceAsyncScanResult> resultData=processVoiceAsyncScanResult(resultList); |
|
|
|
//成功返回
|
|
|
|
return new Result<List<VoiceAsyncScanResult>>().ok(resultList); |
|
|
|
return new Result<List<VoiceAsyncScanResult>>().ok(resultData); |
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
log.warn("getVoiceAsyncScanResult detect not success. code:{}", scrResponse.getInteger(SysConstant.CODE)); |
|
|
|
log.warn("voiceResults detect not success. code:{}", scrResponse.getInteger(SysConstant.CODE)); |
|
|
|
throw new ExecuteHttpException(SysResponseEnum.THIRD_PLATFORM_RESP_CODE_ERROR.getCode(), |
|
|
|
SysResponseEnum.THIRD_PLATFORM_RESP_CODE_ERROR.getMsg() + ",status:" + httpResponse.getStatus()); |
|
|
|
} |
|
|
|
@ -433,12 +448,45 @@ public class ScanServiceImpl implements ScanService { |
|
|
|
SysResponseEnum.THIRD_PLATFORM_RESP_STATUS_ERROR.getMsg() + ",status:" + httpResponse.getStatus()); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("executeSyncVoice exception IAcsClientUtil do action exception", e); |
|
|
|
log.error("voiceResults exception IAcsClientUtil do action exception", e); |
|
|
|
throw new ExecuteHttpException(SysResponseEnum.THIRD_PLATFORM_SERVER_ERROR.getCode(), SysResponseEnum.THIRD_PLATFORM_SERVER_ERROR.getMsg()); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private List<VoiceAsyncScanResult> processVoiceAsyncScanResult(List<VoiceAsyncScanResult> resultList) { |
|
|
|
List<VoiceAsyncScanResult> list = new ArrayList<>(); |
|
|
|
for (VoiceAsyncScanResult voiceAsyncScanResult : resultList) { |
|
|
|
if (SysConstant.PROCESSING == voiceAsyncScanResult.getCode()) { |
|
|
|
//280:表示处理中,需要继续轮询
|
|
|
|
continue; |
|
|
|
} |
|
|
|
VoiceAsyncScanResult dto = ConvertUtils.sourceToTarget(voiceAsyncScanResult, VoiceAsyncScanResult.class); |
|
|
|
if (HttpStatus.SC_OK == voiceAsyncScanResult.getCode()) { |
|
|
|
if (!CollectionUtils.isEmpty(voiceAsyncScanResult.getResults()) && voiceAsyncScanResult.getResults().size() > NumConstant.ZERO) { |
|
|
|
//目前只有一个检测场景,所以只判断返回来的第一个场景
|
|
|
|
VoiceAsyncScanResultDTO voiceAsyncScanResultDTO = voiceAsyncScanResult.getResults().get(NumConstant.ZERO); |
|
|
|
if (null != voiceAsyncScanResultDTO) { |
|
|
|
dto.setLabel(voiceAsyncScanResultDTO.getLabel()); |
|
|
|
dto.setLabelDesc(LabelEnum.getDesc(voiceAsyncScanResultDTO.getLabel())); |
|
|
|
dto.setSuggestion(voiceAsyncScanResultDTO.getSuggestion()); |
|
|
|
} |
|
|
|
} |
|
|
|
} else if(HttpStatus.SC_NOT_FOUND == voiceAsyncScanResult.getCode()) { |
|
|
|
dto.setSuggestion(SuggestionEnum.REVIEW.getCode()); |
|
|
|
dto.setLabel(NumConstant.EMPTY_STR); |
|
|
|
dto.setLabelDesc("智能检测任务失败,结果已失效," + SuggestionEnum.REVIEW.getDesc()); |
|
|
|
}else{ |
|
|
|
//其他:表示任务失败
|
|
|
|
dto.setSuggestion(SuggestionEnum.REVIEW.getCode()); |
|
|
|
dto.setLabel(NumConstant.EMPTY_STR); |
|
|
|
dto.setLabelDesc("智能检测任务失败," + SuggestionEnum.REVIEW.getDesc()); |
|
|
|
} |
|
|
|
list.add(dto); |
|
|
|
} |
|
|
|
return list; |
|
|
|
} |
|
|
|
|
|
|
|
private VoiceAsyncScanResultsRequest getVoiceAsyncScanResultsRequest(){ |
|
|
|
VoiceAsyncScanResultsRequest getResultsRequest = new VoiceAsyncScanResultsRequest(); |
|
|
|
// 指定API返回格式。
|
|
|
|
|