diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/scan/param/VoiceScanParamDTO.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/scan/param/VoiceScanParamDTO.java new file mode 100644 index 0000000000..e315848ec1 --- /dev/null +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/scan/param/VoiceScanParamDTO.java @@ -0,0 +1,35 @@ +package com.epmet.commons.tools.scan.param; + +import lombok.Data; + +import javax.validation.Valid; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.util.List; + +/** + * 语音检测入参DTO + * + * @author yinzuomei@elink-cn.com + * @date 2020/12/18 10:15 + */ +@Data +public class VoiceScanParamDTO implements Serializable { + + /** + * 是否开启回调 + */ + @NotNull(message = "openCallBack必填,true开启;false不开启") + private Boolean openCallBack; + + /** + * 异步检测结果回调地址,执行异步审查内容时 必填 + * openCallBack=true时,callback必填 + */ + private String callback; + + @Valid + @NotEmpty(message = "任务列表不能为空") + private List tasks; +} diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/scan/param/VoiceTaskDTO.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/scan/param/VoiceTaskDTO.java new file mode 100644 index 0000000000..a0abe2303a --- /dev/null +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/scan/param/VoiceTaskDTO.java @@ -0,0 +1,31 @@ +package com.epmet.commons.tools.scan.param; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + +/** + * 语音异步检测对象 + * + * @author yinzuomei@elink-cn.com + * @date 2020/12/18 10:21 + */ +@Data +public class VoiceTaskDTO implements Serializable { + /** + * 不必填 + * 要检测的数据id 非必填 + * 检测对象对应的数据ID。 + * 由大小写英文字母、数字、下划线(_)、短划线(-)、英文句号(.)组成,不超过128个字符,可以用于唯一标识您的业务数据。 + * */ + @NotBlank(message = "dataId不能为空") + private String dataId; + + /** + * 必填 + * 需要检测的音频文件或语音流的下载地址。 + */ + @NotBlank(message = "音频URL不能为空") + private String url; +} diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/scan/result/AsyncScanResult.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/scan/result/AsyncScanResult.java new file mode 100644 index 0000000000..77cabbfed7 --- /dev/null +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/scan/result/AsyncScanResult.java @@ -0,0 +1,49 @@ +package com.epmet.commons.tools.scan.result; + +import lombok.Data; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * 语音异步检测 返参 + * + * @author yinzuomei@elink-cn.com + * @date 2020/12/18 10:09 + */ +@Data +public class AsyncScanResult implements Serializable { + private static final long serialVersionUID = -939433332419948118L; + + /** + * 随机字符串,该值用于回调通知请求中的签名。 + */ + private String seed; + + /** + * 提交成功的失败对象 + */ + private List successTasks=new ArrayList<>(); + + /** + * 提交失败的检测对象 + */ + private List failTasks=new ArrayList<>(); + + /** + * 是否全部提交成功 + */ + private boolean isAllSuccess; + + public boolean isAllSuccess() { + if (failTasks.isEmpty() && !successTasks.isEmpty()) { + return true; + } + return isAllSuccess; + } + + public void setAllSuccess(boolean allSuccess) { + isAllSuccess = allSuccess; + } +} diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/scan/result/AsyncScanTaskDTO.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/scan/result/AsyncScanTaskDTO.java new file mode 100644 index 0000000000..e09ed9ae5d --- /dev/null +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/scan/result/AsyncScanTaskDTO.java @@ -0,0 +1,25 @@ +package com.epmet.commons.tools.scan.result; + +import lombok.Data; + +import java.io.Serializable; + +/** + * 语音异步检测 -返回的task集合 + * + * @author yinzuomei@elink-cn.com + * @date 2020/12/18 10:31 + */ +@Data +public class AsyncScanTaskDTO implements Serializable { + /** + * 检测对象对应的数据ID。 + * 由大小写英文字母、数字、下划线(_)、短划线(-)、英文句号(.)组成,不超过128个字符,可以用于唯一标识您的业务数据。 + */ + private String dataId; + + /** + * 任务id + */ + private String taskId; +} diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/ScanContentUtils.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/ScanContentUtils.java index ef7a3257a6..2ab6e7dda6 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/ScanContentUtils.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/ScanContentUtils.java @@ -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 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 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 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 list = new ArrayList<>(); + list.add(p); + VoiceScanParamDTO param = new VoiceScanParamDTO(); + param.setTasks(list); + param.setOpenCallBack(false); + Result 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)); } } + } } diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanServiceImpl.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanServiceImpl.java index 86897f5a9e..27e6ce3ea0 100644 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanServiceImpl.java +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanServiceImpl.java @@ -30,6 +30,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 +307,18 @@ public class ScanServiceImpl implements ScanService { //成功返回 VoiceAsyncScanTaskResult resultDto=new VoiceAsyncScanTaskResult(); resultDto.setSeed(voiceAsyncScanParam.getSeed()); - resultDto.setTaskList(taskList); + List successList = new ArrayList<>(); + List 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的关系"); diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/VoiceAsyncScanParam.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/VoiceAsyncScanParam.java index d83b8784a0..baa8e51be0 100644 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/VoiceAsyncScanParam.java +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/VoiceAsyncScanParam.java @@ -17,6 +17,11 @@ import java.util.List; public class VoiceAsyncScanParam implements Serializable { private static final long serialVersionUID = 3408043673247901184L; + /** + * 是否开启回调 + */ + private Boolean openCallBack; + /** * 不必填 * 该字段用于标识您的业务场景。您可以通过内容安全控制台创建业务场景(具体操作,请参见自定义机审标准),或者提交工单联系我们帮助您创建业务场景。 diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanTaskDataDTO.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanTaskDataDTO.java index 6c94bfa757..ce43fec932 100644 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanTaskDataDTO.java +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanTaskDataDTO.java @@ -6,7 +6,7 @@ import lombok.Data; import java.io.Serializable; /** - * 描述一下 + * 语音异步检测,返回检测对象列表 * * @author yinzuomei@elink-cn.com * @date 2020/12/9 16:38 @@ -17,7 +17,7 @@ public class VoiceAsyncScanTaskDataDTO implements Serializable { * 错误码,和HTTP状态码一致。 * 更多信息,请参见公共错误码。 */ - private String code; + private Integer code; /** * 错误描述信息。 */ diff --git a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanTaskResult.java b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanTaskResult.java index 44d54fcf3a..2dcbecc398 100644 --- a/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanTaskResult.java +++ b/epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanTaskResult.java @@ -3,10 +3,11 @@ package com.epmet.openapi.scan.support.result; import lombok.Data; import java.io.Serializable; +import java.util.ArrayList; import java.util.List; /** - * 音频审查返参,用于接收taskId + * 语音异步检测,返参 * * @author yinzuomei@elink-cn.com * @date 2020/12/9 9:23 @@ -18,5 +19,28 @@ public class VoiceAsyncScanTaskResult implements Serializable { * 随机字符串,该值用于回调通知请求中的签名。 */ private String seed; - private List taskList; + + /** + * 提交成功的失败对象 + */ + private List successTasks=new ArrayList<>(); + + /** + * 提交失败的检测对象 + */ + private List failTasks=new ArrayList<>(); + + /** + * 是否全部提交成功 + */ + private boolean isAllSuccess; + + public boolean isAllSuccess() { + if (failTasks.isEmpty() && !successTasks.isEmpty()) { + return true; + } + return isAllSuccess; + } + + }