|
|
@ -4,9 +4,8 @@ import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.TypeReference; |
|
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
|
import com.epmet.commons.tools.scan.param.ImgScanParamDTO; |
|
|
|
import com.epmet.commons.tools.scan.param.TextScanParamDTO; |
|
|
|
import com.epmet.commons.tools.scan.param.TextTaskDTO; |
|
|
|
import com.epmet.commons.tools.scan.param.*; |
|
|
|
import com.epmet.commons.tools.scan.result.AsyncScanResult; |
|
|
|
import com.epmet.commons.tools.scan.result.SyncScanResult; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
@ -75,7 +74,44 @@ public class ScanContentUtils { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* desc:语音异步检测任务提交 |
|
|
|
* |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public static Result<AsyncScanResult> voiceAsyncScan(String url, VoiceScanParamDTO param){ |
|
|
|
log.debug("voiceAsyncScan param:{}", JSON.toJSONString(param)); |
|
|
|
if (StringUtils.isBlank(url) || param == null) { |
|
|
|
throw new RenException("参数错误"); |
|
|
|
} |
|
|
|
if (param.getOpenCallBack() && StringUtils.isBlank(param.getCallback())) { |
|
|
|
throw new RenException("参数错误,开启回调,callback必填"); |
|
|
|
} |
|
|
|
try { |
|
|
|
Result<String> result = HttpClientManager.getInstance().sendPostByJSON(url, JSON.toJSONString(param)); |
|
|
|
log.debug("voiceAsyncScan result:{}", JSON.toJSONString(result)); |
|
|
|
if (result.success()) { |
|
|
|
return JSON.parseObject(result.getData(),new TypeReference<Result<AsyncScanResult>>(){}); |
|
|
|
} |
|
|
|
Result<AsyncScanResult> resultResult = new Result<>(); |
|
|
|
resultResult.error(result.getCode(),result.getMsg()); |
|
|
|
resultResult.setInternalMsg(result.getInternalMsg()); |
|
|
|
return resultResult; |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("voiceAsyncScan exception:", e); |
|
|
|
throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode(), e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
//测试文本检测
|
|
|
|
// testTextSyncScan();
|
|
|
|
//测试语音检测
|
|
|
|
testVoiceAsyncScan(); |
|
|
|
} |
|
|
|
|
|
|
|
public static void testTextSyncScan(){ |
|
|
|
String url = "http://localhost:8107/epmetscan/api/textSyncScan"; |
|
|
|
TextTaskDTO p = new TextTaskDTO(); |
|
|
|
p.setDataId("1"); |
|
|
@ -95,6 +131,30 @@ public class ScanContentUtils { |
|
|
|
result.getFailDataIds().addAll(imgSyncScanResultData.getFailDataIds()); |
|
|
|
System.out.println("================"+JSON.toJSONString(result)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static void testVoiceAsyncScan(){ |
|
|
|
String url = "http://localhost:8107/epmetscan/api/voiceAsyncScan"; |
|
|
|
VoiceTaskDTO p = new VoiceTaskDTO(); |
|
|
|
p.setDataId("1"); |
|
|
|
p.setUrl("https://elink-esua-epdc.oss-cn-qingdao.aliyuncs.com/epmet/test/20201208/6480bd6be9f14a458162218cea84dfa5.aac"); |
|
|
|
List<VoiceTaskDTO> list = new ArrayList<>(); |
|
|
|
list.add(p); |
|
|
|
VoiceScanParamDTO param = new VoiceScanParamDTO(); |
|
|
|
param.setTasks(list); |
|
|
|
param.setOpenCallBack(false); |
|
|
|
Result<AsyncScanResult> asyncScanResultResult = ScanContentUtils.voiceAsyncScan(url, param); |
|
|
|
System.out.println(JSON.toJSONString(asyncScanResultResult)); |
|
|
|
AsyncScanResult result = new AsyncScanResult(); |
|
|
|
if (asyncScanResultResult != null) { |
|
|
|
AsyncScanResult asyncScanResult = asyncScanResultResult.getData(); |
|
|
|
if (asyncScanResultResult.success()) { |
|
|
|
result.setAllSuccess(asyncScanResult.isAllSuccess()); |
|
|
|
result.getSuccessTasks().addAll(asyncScanResult.getSuccessTasks()); |
|
|
|
result.getFailTasks().addAll(asyncScanResult.getFailTasks()); |
|
|
|
System.out.println("================" + JSON.toJSONString(result)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|