Browse Source

Merge remote-tracking branch 'origin/dev_voice_scan' into dev_voice_share_point

master
yinzuomei 5 years ago
parent
commit
7c802843ad
  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. 50
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/scan/result/VoiceResultDTO.java
  6. 109
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/ScanContentUtils.java
  7. 11
      epmet-module/data-report/data-report-client/src/main/java/com/epmet/evaluationindex/screen/dto/result/AgencyDistributionResultDTO.java
  8. 6
      epmet-module/data-report/data-report-client/src/main/java/com/epmet/evaluationindex/screen/dto/result/CompartmentResultDTO.java
  9. 4
      epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/evaluationindex/screen/impl/AgencyServiceImpl.java
  10. 22
      epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/fact/impl/FactIndexServiceImpl.java
  11. 6
      epmet-module/data-report/data-report-server/src/main/resources/mapper/screen/ScreenCustomerAgencyDao.xml
  12. 3
      epmet-module/data-report/data-report-server/src/main/resources/mapper/screen/ScreenCustomerGridDao.xml
  13. 6
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/constant/SysConstant.java
  14. 66
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/LabelEnum.java
  15. 60
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanServiceImpl.java
  16. 5
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/param/VoiceAsyncScanParam.java
  17. 52
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanResult.java
  18. 4
      epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanTaskDataDTO.java
  19. 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;
}

50
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/scan/result/VoiceResultDTO.java

@ -0,0 +1,50 @@
package com.epmet.commons.tools.scan.result;
import lombok.Data;
import java.io.Serializable;
/**
* 检测成功检测成功+检测失败的的任务详情
* 处理中的该接口不返回继续轮询即可
* @author yinzuomei@elink-cn.com
* @date 2020/12/18 13:10
*/
@Data
public class VoiceResultDTO implements Serializable {
private static final long serialVersionUID = 8006827312407034344L;
/**
* 检测对象对应的数据ID
*/
private String dataId;
/**
* 检测任务的ID
*/
private String taskId;
/**
* 建议您执行的后续操作取值
* pass结果正常无需进行其余操作
* review结果不确定需要进行人工审核
* block结果违规建议直接删除或者限制公开
*/
private String suggestion;
/**
* 检测结果的分类取值
* normal正常文本
* spam含垃圾信息
* ad广告
* politics涉政
* terrorism暴恐
* abuse辱骂
* porn色情
* flood灌水
* contraband违禁
* meaningless无意义
* customized自定义例如命中自定义关键词
*/
private String label;
private String labelDesc;
}

109
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/ScanContentUtils.java

@ -2,14 +2,16 @@ package com.epmet.commons.tools.utils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.epmet.commons.tools.constant.NumConstant;
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 com.epmet.commons.tools.scan.result.VoiceResultDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
@ -75,7 +77,76 @@ public class ScanContentUtils {
}
}
/**
* desc:语音异步检测任务提交
*
* @return 返回检测对象对应的任务id
*/
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());
}
}
/**
* desc:语音异步检测结果查询
*
* @param taskIds 数组中的元素个数不超过100个
* @return 注意该接口只返回检测任务完成的即检测成功或失败的任务正在处理中的不返回继续轮询即可
*/
public static Result<List<VoiceResultDTO>> voiceResults(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("voiceResults result:{}", JSON.toJSONString(result));
if (result.success()) {
return JSON.parseObject(result.getData(), new TypeReference<Result<List<VoiceResultDTO>>>() {
});
}
Result<List<VoiceResultDTO>> 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) {
//测试文本检测
// testTextSyncScan();
//测试语音检测
// testVoiceAsyncScan();
//语音检测结果
testVoiceResults();
}
public static void testTextSyncScan(){
String url = "http://localhost:8107/epmetscan/api/textSyncScan";
TextTaskDTO p = new TextTaskDTO();
p.setDataId("1");
@ -95,6 +166,38 @@ 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));
}
}
}
public static void testVoiceResults(){
String url = "http://localhost:8107/epmetscan/api/voiceResults";
List<String> taskIds=new ArrayList<>();
taskIds.add("vc_f_6CXRk1VcAwM6u0FMA@CfoW-1tDgIp");
Result<List<VoiceResultDTO>> asyncScanResultResult = ScanContentUtils.voiceResults(url, taskIds);
System.out.println("================" + JSON.toJSONString(asyncScanResultResult));
}
}

11
epmet-module/data-report/data-report-client/src/main/java/com/epmet/evaluationindex/screen/dto/result/AgencyDistributionResultDTO.java

@ -38,6 +38,17 @@ public class AgencyDistributionResultDTO implements Serializable {
*/
private String type;
/**
* 若果是组织对应返回screen_customer_agency的 level
* 机关级别
* 社区级community
* 街道:street,
* 区县级: district,
* 市级: city
* 省级:province
*/
private String agencyLevel;
public AgencyDistributionResultDTO() {
this.subAreaMarks = "";
this.subCenterMark = "";

6
epmet-module/data-report/data-report-client/src/main/java/com/epmet/evaluationindex/screen/dto/result/CompartmentResultDTO.java

@ -31,7 +31,10 @@ public class CompartmentResultDTO implements Serializable {
*/
private String areaMarks = "";
@JsonIgnore
private String level;
/**
* 当前组织的级别
* 机关级别
* 社区级community
* 街道:street,
@ -39,8 +42,7 @@ public class CompartmentResultDTO implements Serializable {
* 市级: city
* 省级:province
*/
@JsonIgnore
private String level;
private String agencyLevel;
/**
* 子级用户分布

4
epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/evaluationindex/screen/impl/AgencyServiceImpl.java

@ -195,7 +195,7 @@ public class AgencyServiceImpl implements AgencyService {
if (null == agencyAreaInfo){
return new CompartmentResultDTO();
}
if (agencyAreaInfo.getLevel().equals(ScreenConstant.COMMUNITY)){
if (agencyAreaInfo.getAgencyLevel().equals(ScreenConstant.COMMUNITY)){
// 当level为"community"时,查询screen_customer_grid表
List<AgencyDistributionResultDTO> agencyDistributionResultDTOS = screenCustomerGridDao.selectSubDistribution(compartmentFormDTO.getAgencyId());
agencyAreaInfo.setAgencyDistribution(agencyDistributionResultDTOS);
@ -213,7 +213,7 @@ public class AgencyServiceImpl implements AgencyService {
if (null == agencyAreaInfo){
return new CompartmentResultDTO();
}
if (agencyAreaInfo.getLevel().equals(ScreenConstant.COMMUNITY)){
if (agencyAreaInfo.getAgencyLevel().equals(ScreenConstant.COMMUNITY)){
// 当level为"community"时,查询screen_customer_grid表
List<AgencyDistributionResultDTO> agencyDistributionResultDTOS = screenCustomerGridDao.selectSubDistribution(compartmentFormDTO.getAgencyId());
agencyAreaInfo.setAgencyDistribution(agencyDistributionResultDTOS);

22
epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/fact/impl/FactIndexServiceImpl.java

@ -77,12 +77,12 @@ public class FactIndexServiceImpl implements FactIndexService {
}
//4.根据组织级别判断查询哪类数据表
//区县级、乡镇街道级
if ("district".equals(agency.getLevel()) || "street".equals(agency.getLevel())) {
if ("district".equals(agency.getAgencyLevel()) || "street".equals(agency.getAgencyLevel())) {
//4-1.查询过去12个月党建能力、治理能力、服务能力每月总分数据
list = factIndexAgencyScoreDao.selectAgencyAblityWeightScoreIndex(formDTO);
//社区级
} else if ("community".equals(agency.getLevel())) {
} else if ("community".equals(agency.getAgencyLevel())) {
//4-1.查询过去12个月党建能力、治理能力、服务能力每月总分、本级得分、下级得分数据
list = factIndexCommunityScoreDao.selectCommunityAblityWeightScore(formDTO);
} else {
@ -179,11 +179,11 @@ public class FactIndexServiceImpl implements FactIndexService {
}
//3.根据组织级别判断查询哪类数据表
//区县级、乡镇街道级
if ("district".equals(agency.getLevel()) || "street".equals(agency.getLevel())) {
if ("district".equals(agency.getAgencyLevel()) || "street".equals(agency.getAgencyLevel())) {
//3-1.查询当前组织某一月份党建能力、治理能力、服务能力对应的总分、本级分、下级分
resultList = factIndexAgencyScoreDao.selectAgencyWeightScoreList(formDTO);
//社区级
} else if ("community".equals(agency.getLevel())) {
} else if ("community".equals(agency.getAgencyLevel())) {
//3-1.查询当前组织某一月份党建能力、治理能力、服务能力对应的总分、本级分、下级分
resultList = factIndexCommunityScoreDao.selectCommunityWeightScoreList(formDTO);
} else {
@ -227,12 +227,12 @@ public class FactIndexServiceImpl implements FactIndexService {
}
//4.根据组织级别判断查询哪类数据表
//区县级、乡镇街道级
if ("district".equals(agency.getLevel()) || "street".equals(agency.getLevel())) {
if ("district".equals(agency.getAgencyLevel()) || "street".equals(agency.getAgencyLevel())) {
//4-1.查询过去12个月党建能力、治理能力、服务能力每月总分、本级得分、下级得分数据
list = factIndexAgencyScoreDao.selectAgencyMonthWeightScoreList(formDTO);
//社区级
} else if ("community".equals(agency.getLevel())) {
} else if ("community".equals(agency.getAgencyLevel())) {
//4-1.查询过去12个月党建能力、治理能力、服务能力每月总分、本级得分、下级得分数据
list = factIndexCommunityScoreDao.selectCommunityMonthWeightScoreList(formDTO);
} else {
@ -298,8 +298,8 @@ public class FactIndexServiceImpl implements FactIndexService {
}
//3.根据组织级别拼接查询条件,判断查询不同数据表
//区县级、乡镇街道级
if ("district".equals(agency.getLevel()) || "street".equals(agency.getLevel())) {
if ("district".equals(agency.getLevel())) {
if ("district".equals(agency.getAgencyLevel()) || "street".equals(agency.getAgencyLevel())) {
if ("district".equals(agency.getAgencyLevel())) {
formDTO.setAllParentIndexCode(FactConstant.QUAN_QU_XIANG_GUAN + ":" + formDTO.getIndexCode());
} else {
formDTO.setAllParentIndexCode(FactConstant.JIE_DAO_XIANG_GUAN + ":" + formDTO.getIndexCode());
@ -307,7 +307,7 @@ public class FactIndexServiceImpl implements FactIndexService {
resultList = factIndexAgencySubScoreDao.selectAblityList(formDTO);
//社区级
} else if ("community".equals(agency.getLevel())) {
} else if ("community".equals(agency.getAgencyLevel())) {
formDTO.setAllParentIndexCode(FactConstant.SHE_QU_XIANG_GUAN + ":" + formDTO.getIndexCode());
resultList = factIndexCommunitySubScoreDao.selectCommunityAblityList(formDTO);
} else {
@ -366,10 +366,10 @@ public class FactIndexServiceImpl implements FactIndexService {
}
//4.根据组织级别拼接查询条件,判断查询不同数据表
//区县级、乡镇街道级
if ("district".equals(agency.getLevel()) || "street".equals(agency.getLevel())) {
if ("district".equals(agency.getAgencyLevel()) || "street".equals(agency.getAgencyLevel())) {
resultList = factIndexAgencySubScoreDao.selectMonthAblityList(formDTO);
//社区级
} else if ("community".equals(agency.getLevel())) {
} else if ("community".equals(agency.getAgencyLevel())) {
resultList = factIndexCommunitySubScoreDao.selectCommunityMonthAblityList(formDTO);
} else {
//throw new RenException(String.format("根据组织Id查询到的组织级别信息错误,组织Id:%s", formDTO.getOrgId()));

6
epmet-module/data-report/data-report-server/src/main/resources/mapper/screen/ScreenCustomerAgencyDao.xml

@ -44,7 +44,8 @@
agency_id AS agencyId,
agency_name AS name,
area_marks AS areaMarks,
level AS level
level as level,
level as agencyLevel
FROM
screen_customer_agency
WHERE
@ -60,7 +61,8 @@
agency_name AS subName,
area_marks AS subAreaMarks,
center_mark AS subCenterMark,
'agency' AS type
'agency' AS type,
level as agencyLevel
FROM
screen_customer_agency
WHERE

3
epmet-module/data-report/data-report-server/src/main/resources/mapper/screen/ScreenCustomerGridDao.xml

@ -10,7 +10,8 @@
grid_name AS subName,
area_marks AS subAreaMarks,
center_mark AS subCenterMark,
'grid' AS type
'grid' AS type,
'' as agencyLevel
FROM
screen_customer_grid
WHERE

6
epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/constant/SysConstant.java

@ -21,4 +21,10 @@ public class SysConstant {
public static final String CODE = "code";
public static final String DATA = "data";
/**
* 任务正在执行中建议您等待一段时间例如5s后再查询结果
*/
public static final int PROCESSING=280;
}

66
epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/common/enu/LabelEnum.java

@ -0,0 +1,66 @@
package com.epmet.openapi.scan.common.enu;
import java.util.ArrayList;
import java.util.List;
/**
* 阿里检测结果的分类字典
*
* @author yinzuomei@elink-cn.com
* @date 2020/12/18 14:04
*/
public enum LabelEnum {
NORMAL("normal", "正常文本"),
SPAM("spam", "含垃圾信息"),
AD("ad", "广告"),
POLITICS("politics","涉政"),
TERRORISM("terrorism","暴恐"),
ABUSE("abuse","辱骂"),
PORN("porn","色情"),
FLOOD("flood","灌水"),
CONTRABAND("contraband","违禁"),
MEANINGLESS("meaningless","无意义"),
CUSTOMIZED("customized","自定义");
private String code;
private String desc;
LabelEnum(String code, String desc) {
this.code = code;
this.desc = desc;
}
public static List<String> getLabelEnumList() {
List<String> result = new ArrayList<>();
LabelEnum[] values = LabelEnum.values();
for (LabelEnum v : values) {
result.add(v.getCode());
}
return result;
}
public static String getDesc(String code) {
LabelEnum[] businessModeEnums = values();
for (LabelEnum labelEnum : businessModeEnums) {
if (labelEnum.getCode().equals(code)) {
return labelEnum.getDesc();
}
}
return "";
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
}

60
epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/service/impl/ScanServiceImpl.java

@ -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返回格式。

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

52
epmet-openapi/epmet-openapi-scan/src/main/java/com/epmet/openapi/scan/support/result/VoiceAsyncScanResult.java

@ -15,6 +15,43 @@ import java.util.List;
@Data
public class VoiceAsyncScanResult implements Serializable {
private static final long serialVersionUID = 8702129292884498023L;
/**
* 检测对象对应的数据ID
*/
private String dataId;
/**
* 检测任务的ID
*/
private String taskId;
/**
* 检测结果的分类取值
* normal正常文本
* spam含垃圾信息
* ad广告
* politics涉政
* terrorism暴恐
* abuse辱骂
* porn色情
* flood灌水
* contraband违禁
* meaningless无意义
* customized自定义例如命中自定义关键词
*/
private String label;
private String labelDesc;
/**
* 建议您执行的后续操作取值
* pass结果正常无需进行其余操作
* review结果不确定需要进行人工审核
* block结果违规建议直接删除或者限制公开
*/
private String suggestion;
/**
* 错误码和HTTP状态码一致
* 200表示检测成功
@ -22,20 +59,13 @@ public class VoiceAsyncScanResult implements Serializable {
* 其他表示任务失败
* 更多信息请参见公共错误码
*/
private String code;
@JsonIgnore
private Integer code;
/**
* 错误描述信息
*/
@JsonIgnore
private String msg;
/**
* 检测对象对应的数据ID
*/
private String dataId;
/**
* 检测任务的ID
*/
private String taskId;
/**
* 暂时没用所以返回忽略
@ -45,7 +75,9 @@ public class VoiceAsyncScanResult implements Serializable {
/**
* 检测成功code=200返回的检测结果该结果包含一个或多个元素每个元素是个结构体对应一个场景关于每个元素的结构描述请参见result
* 暂时不展示审核结果明细
*/
@JsonIgnore
private List<VoiceAsyncScanResultDTO> results;
}

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