Browse Source

ScanContentUtils新增voiceAsyncScan方法

dev_shibei_match
yinzuomei 5 years ago
parent
commit
809225ffe1
  1. 35
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/scan/param/VoiceScanParamDTO.java
  2. 31
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/scan/param/VoiceTaskDTO.java
  3. 49
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/scan/result/AsyncScanResult.java
  4. 25
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/scan/result/AsyncScanTaskDTO.java
  5. 66
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/ScanContentUtils.java
  6. 14
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanServiceImpl.java
  7. 5
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/VoiceAsyncScanParam.java
  8. 4
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanTaskDataDTO.java
  9. 28
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanTaskResult.java

35
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<VoiceTaskDTO> tasks;
}

31
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;
}

49
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<AsyncScanTaskDTO> successTasks=new ArrayList<>();
/**
* 提交失败的检测对象
*/
private List<AsyncScanTaskDTO> 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;
}
}

25
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;
}

66
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<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");
@ -97,4 +133,28 @@ public class ScanContentUtils {
}
}
}
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));
}
}
}
}

14
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<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的关系");

5
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;
/**
* 不必填
* 该字段用于标识您的业务场景您可以通过内容安全控制台创建业务场景具体操作请参见自定义机审标准或者提交工单联系我们帮助您创建业务场景

4
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;
/**
* 错误描述信息
*/

28
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<VoiceAsyncScanTaskDataDTO> taskList;
/**
* 提交成功的失败对象
*/
private List<VoiceAsyncScanTaskDataDTO> successTasks=new ArrayList<>();
/**
* 提交失败的检测对象
*/
private List<VoiceAsyncScanTaskDataDTO> failTasks=new ArrayList<>();
/**
* 是否全部提交成功
*/
private boolean isAllSuccess;
public boolean isAllSuccess() {
if (failTasks.isEmpty() && !successTasks.isEmpty()) {
return true;
}
return isAllSuccess;
}
}

Loading…
Cancel
Save