智能外呼
parent
bab34da581
commit
ae192e68c1
|
|
@ -0,0 +1,217 @@
|
|||
package com.whdc.utils;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.whdc.model.entity.AutoCallPerson;
|
||||
import com.whdc.model.entity.AutoCallTask;
|
||||
import com.whdc.model.entity.autocall.AICCCallRespDetail;
|
||||
import com.whdc.model.entity.autocall.AICCCallRespTask;
|
||||
import com.whdc.model.entity.autocall.AICCCallRespWrapper;
|
||||
import com.whdc.model.entity.autocall.AICCUploadTask;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
class AICCHelperTest {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AICCHelperTest.class);
|
||||
|
||||
public static void main(String[] args) throws InterruptedException, ParseException, GeneralSecurityException, UnsupportedEncodingException {
|
||||
AICCHelper helper = new AICCHelper();
|
||||
helper.setProcessId("1935233125932101634");
|
||||
helper.setCallerGroup("02759325005");
|
||||
helper.setSecret("yxt@2024-1234567");
|
||||
helper.setSysUserId("HBSL01");
|
||||
|
||||
long millis = System.currentTimeMillis();
|
||||
Date now = new Date(millis);
|
||||
|
||||
AutoCallTask task = new AutoCallTask();
|
||||
task.setId(1);
|
||||
task.setWarnId(1);
|
||||
task.setStatus(1);
|
||||
task.setWarnName("测试预警");
|
||||
task.setWarnTm(now);
|
||||
task.setWarnLevel("橙色");
|
||||
task.setCreateTm(now);
|
||||
|
||||
AutoCallPerson person = new AutoCallPerson();
|
||||
person.setId(0);
|
||||
person.setTaskId(1);
|
||||
String uniqueId = millis + "-0";
|
||||
person.setUploadRequestId(uniqueId);
|
||||
person.setUploadCustId(uniqueId);
|
||||
person.setUploadCustName("李");
|
||||
person.setUploadContent("测试测试测试,这是第一个联系人");
|
||||
person.setUploadNumber("15671545233");
|
||||
person.setStatus(0);
|
||||
person.setLevel(1);
|
||||
person.setCreateTm(now);
|
||||
|
||||
task.setCallList(new ArrayList<>());
|
||||
task.getCallList().add(person);
|
||||
|
||||
AICCUploadTask uploadTask = new AICCUploadTask();
|
||||
uploadTask.setTaskName(person.getUploadRequestId());
|
||||
uploadTask.setProcessId("1935233125932101634");
|
||||
uploadTask.setCallerGroup("02759325005");
|
||||
uploadTask.setRequestId(person.getUploadRequestId());
|
||||
uploadTask.genMutiTimeRange();
|
||||
AICCUploadTask.Cust param = AICCUploadTask.Cust.builder()
|
||||
.setCustName(person.getUploadCustName())
|
||||
.setCustId(person.getUploadCustId())
|
||||
.setContent(person.getUploadContent())
|
||||
.set_numbers(Collections.singletonList(person.getUploadNumber()))
|
||||
.build();
|
||||
uploadTask.setParam(Lists.newArrayList(param));
|
||||
|
||||
uploadTask.setCalleeType(1);
|
||||
uploadTask.setRepeatTimes(1);
|
||||
uploadTask.setAutoCall("0");
|
||||
uploadTask.setSpanSeconds(10);
|
||||
|
||||
LOG.info("上传外呼任务: {}", JSON.toJSONString(uploadTask));
|
||||
AICCCallRespWrapper<AICCCallRespTask> AICCCallRespWrapper = helper.apiUploadCallData(uploadTask);
|
||||
String msg = AICCCallRespWrapper.getResult().getMsg();
|
||||
person.setUploadRespMsg(msg);
|
||||
LOG.info("上传外呼任务结果: {}", JSON.toJSONString(AICCCallRespWrapper));
|
||||
|
||||
int pendingDuration = 60 * 1000 * 2;
|
||||
int loopGap = 1000;
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
while (true) {
|
||||
Thread.sleep(loopGap);
|
||||
pendingDuration -= loopGap;
|
||||
if (pendingDuration <= 0) break;
|
||||
|
||||
AICCCallRespWrapper<AICCCallRespDetail> detail = helper.apiGetTaskCallDetail(person.getUploadRequestId(), "");
|
||||
LOG.info("外呼任务详情: {}", JSON.toJSONString(detail));
|
||||
List<AICCCallRespDetail.Record> records = detail.getResult().getData().getRecords();
|
||||
if (records.isEmpty()) continue;
|
||||
|
||||
AICCCallRespDetail.Record record = records.get(0);
|
||||
String dialRemark = record.getRemark();
|
||||
boolean done = false;
|
||||
if ("接通".equals(dialRemark)) {
|
||||
done = true;
|
||||
} else if (records.size() > 1) {
|
||||
done = true;
|
||||
}
|
||||
|
||||
if (done) {
|
||||
person.setDetailRemark(dialRemark);
|
||||
person.setDetailTalkTimes(record.getTalkTimes());
|
||||
AICCCallRespDetail.RawVarListMap rawVarListMap = record.getRawVarListMap();
|
||||
person.setDetailSipTermCause(rawVarListMap.getSipTermCause());
|
||||
|
||||
Date d;
|
||||
long l;
|
||||
if (rawVarListMap.getStartringAt() != null) {
|
||||
d = new Date();
|
||||
l = Long.parseLong(rawVarListMap.getStartringAt().substring(0, 13));
|
||||
d.setTime(l);
|
||||
person.setDetailStartringAt(d);
|
||||
}
|
||||
|
||||
if (rawVarListMap.getConnectedAt() != null) {
|
||||
d = new Date();
|
||||
l = Long.parseLong(rawVarListMap.getConnectedAt().substring(0, 13));
|
||||
d.setTime(l);
|
||||
person.setDetailConnectedAt(d);
|
||||
}
|
||||
|
||||
if (rawVarListMap.getStartedAt() != null) {
|
||||
d = new Date();
|
||||
l = Long.parseLong(rawVarListMap.getStartedAt());
|
||||
d.setTime(l);
|
||||
person.setDetailStartedAt(d);
|
||||
}
|
||||
|
||||
if (rawVarListMap.getEndringAt() != null) {
|
||||
d = new Date();
|
||||
l = Long.parseLong(rawVarListMap.getEndringAt().substring(0, 13));
|
||||
d.setTime(l);
|
||||
person.setDetailEndringAt(d);
|
||||
}
|
||||
|
||||
if (rawVarListMap.getDisconnectedAt() != null) {
|
||||
d = new Date();
|
||||
l = Long.parseLong(rawVarListMap.getDisconnectedAt().substring(0, 13));
|
||||
d.setTime(l);
|
||||
person.setDetailDisconnectedAt(d);
|
||||
}
|
||||
|
||||
if (rawVarListMap.getStopedAt() != null) {
|
||||
d = new Date();
|
||||
l = Long.parseLong(rawVarListMap.getStopedAt());
|
||||
d.setTime(l);
|
||||
person.setDetailStopedAt(d);
|
||||
}
|
||||
|
||||
if (rawVarListMap.getLastModify() != null) {
|
||||
d = new Date();
|
||||
l = Long.parseLong(rawVarListMap.getLastModify());
|
||||
d.setTime(l);
|
||||
person.setDetailLastModify(d);
|
||||
}
|
||||
|
||||
LOG.info("外呼任务完成: {}", JSON.toJSONString(uploadTask));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (pendingDuration <= 0) {
|
||||
person.setDetailRemark("超时");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main2(String[] args) throws GeneralSecurityException, UnsupportedEncodingException {
|
||||
AICCHelper helper = new AICCHelper();
|
||||
helper.setProcessId("1935233125932101634");
|
||||
helper.setCallerGroup("02759325005");
|
||||
helper.setSecret("yxt@2024-1234567");
|
||||
helper.setSysUserId("HBSL01");
|
||||
String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6IkhCU0wwMSIsInRlbmFudElkIjoiOTYzOTM2NTE3IiwiZXhwIjoxNzUyMTU0NTE0fQ.R4Yg7OhZek9YbJ7xGj2rQTe_YY0KLPQDM2zRebLkRdY";
|
||||
|
||||
String prefix = System.currentTimeMillis() + "";
|
||||
|
||||
AICCUploadTask task = new AICCUploadTask();
|
||||
task.setTaskName("requestId" + prefix);
|
||||
task.setProcessId("1935233125932101634");
|
||||
task.setCallerGroup("02759325005");
|
||||
task.setRequestId("requestId" + prefix);
|
||||
task.genMutiTimeRange();
|
||||
AICCUploadTask.Cust param1 = AICCUploadTask.Cust.builder()
|
||||
.setCustName("秦")
|
||||
.setCustId("秦" + prefix)
|
||||
.setContent("测试测试测试,这是第一个联系人")
|
||||
.set_numbers(Collections.singletonList("13933930962"))
|
||||
.build();
|
||||
AICCUploadTask.Cust param2 = AICCUploadTask.Cust.builder()
|
||||
.setCustName("李")
|
||||
.setCustId("李" + prefix)
|
||||
.setContent("测试测试测试,这是第二个联系人")
|
||||
.set_numbers(Collections.singletonList("15671545233"))
|
||||
.build();
|
||||
task.setParam(Lists.newArrayList(param1, param2));
|
||||
|
||||
AICCCallRespWrapper<AICCCallRespTask> AICCCallRespWrapper = helper.apiUploadCallData(task);
|
||||
String msg = AICCCallRespWrapper.getResult().getMsg();
|
||||
System.out.println(msg);
|
||||
}
|
||||
|
||||
|
||||
class Cust {
|
||||
private String custName;
|
||||
private String custId;
|
||||
private String content;
|
||||
private String number;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue