|
|
@ -8,6 +8,7 @@ import com.epmet.commons.tools.exception.RenException; |
|
|
|
import com.epmet.commons.tools.scan.param.*; |
|
|
|
import com.epmet.commons.tools.scan.result.AsyncScanResult; |
|
|
|
import com.epmet.commons.tools.scan.result.SyncScanResult; |
|
|
|
import com.epmet.commons.tools.scan.result.VideoAsyncScanResultDTO; |
|
|
|
import com.epmet.commons.tools.scan.result.VoiceResultDTO; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
@ -136,6 +137,65 @@ public class ScanContentUtils { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param url 视频地址 |
|
|
|
* @param param |
|
|
|
* @author yinzuomei |
|
|
|
* @description 异步检测-提交检测任务 |
|
|
|
**/ |
|
|
|
public static Result<AsyncScanResult> videoAsyncScan(String url, VideoScanParamDTO param){ |
|
|
|
log.debug("videoAsyncScan 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("videoAsyncScan 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("videoAsyncScan exception:", e); |
|
|
|
throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode(), e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param url |
|
|
|
* @param taskIds |
|
|
|
* @author yinzuomei |
|
|
|
* @description 查询视频检测结果 |
|
|
|
**/ |
|
|
|
public static Result<VideoAsyncScanResultDTO> videoResults(String url, List<String> taskIds) { |
|
|
|
if (StringUtils.isBlank(url) || CollectionUtils.isEmpty(taskIds)) { |
|
|
|
throw new RenException("参数错误"); |
|
|
|
} |
|
|
|
if (taskIds.size() > NumConstant.ONE_HUNDRED) { |
|
|
|
throw new RenException("参数错误,查询检测任务最大不能超过100"); |
|
|
|
} |
|
|
|
try { |
|
|
|
Result<String> result = HttpClientManager.getInstance().sendPostByJSON(url, JSON.toJSONString(taskIds)); |
|
|
|
log.debug("videoResults result:{}", JSON.toJSONString(result)); |
|
|
|
if (result.success()) { |
|
|
|
return JSON.parseObject(result.getData(), new TypeReference<Result<VideoAsyncScanResultDTO>>() { |
|
|
|
}); |
|
|
|
} |
|
|
|
Result<VideoAsyncScanResultDTO> resultResult = new Result<>(); |
|
|
|
resultResult.error(result.getCode(), result.getMsg()); |
|
|
|
resultResult.setInternalMsg(result.getInternalMsg()); |
|
|
|
return resultResult; |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("voiceResults exception:", e); |
|
|
|
throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode(), e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
//测试文本检测
|
|
|
@ -143,7 +203,11 @@ public class ScanContentUtils { |
|
|
|
//测试语音检测
|
|
|
|
// testVoiceAsyncScan();
|
|
|
|
//语音检测结果
|
|
|
|
testVoiceResults(); |
|
|
|
// testVoiceResults();
|
|
|
|
//视频检测任务提交
|
|
|
|
testVideoAsyncScan(); |
|
|
|
//查询视频检测结果
|
|
|
|
// testVideoResults();
|
|
|
|
} |
|
|
|
|
|
|
|
public static void testTextSyncScan(){ |
|
|
@ -200,4 +264,26 @@ public class ScanContentUtils { |
|
|
|
Result<List<VoiceResultDTO>> asyncScanResultResult = ScanContentUtils.voiceResults(url, taskIds); |
|
|
|
System.out.println("================" + JSON.toJSONString(asyncScanResultResult)); |
|
|
|
} |
|
|
|
|
|
|
|
public static void testVideoAsyncScan(){ |
|
|
|
String url = "http://localhost:8107/epmetscan/api/videoAsyncScan"; |
|
|
|
VideoTaskDTO p = new VideoTaskDTO(); |
|
|
|
p.setDataId("1"); |
|
|
|
p.setUrl("???"); |
|
|
|
List<VideoTaskDTO> list = new ArrayList<>(); |
|
|
|
list.add(p); |
|
|
|
VideoScanParamDTO param = new VideoScanParamDTO(); |
|
|
|
param.setTasks(list); |
|
|
|
param.setOpenCallBack(false); |
|
|
|
Result<AsyncScanResult> asyncScanResultResult = ScanContentUtils.videoAsyncScan(url, param); |
|
|
|
System.out.println(JSON.toJSONString(asyncScanResultResult)); |
|
|
|
} |
|
|
|
|
|
|
|
public static void testVideoResults(){ |
|
|
|
String url = "http://localhost:8107/epmetscan/api/videoResults"; |
|
|
|
List<String> taskIds=new ArrayList<>(); |
|
|
|
taskIds.add("???"); |
|
|
|
Result<VideoAsyncScanResultDTO> result = ScanContentUtils.videoResults(url, taskIds); |
|
|
|
System.out.println("================" + JSON.toJSONString(result)); |
|
|
|
} |
|
|
|
} |
|
|
|