获取百度外呼通话记录录音定时任务。

This commit is contained in:
haown 2024-11-08 15:13:26 +08:00
parent 7b2dbce441
commit 447d7d0250
7 changed files with 166 additions and 29 deletions

View File

@ -0,0 +1,24 @@
package com.xinelu.manage.dto.phonedialrecord;
import io.swagger.annotations.ApiModelProperty;
import java.time.LocalDateTime;
import lombok.Data;
/**
* @description: 电话拨打记录查询传输对象
* @author: haown
* @create: 2024-11-08 14:42
**/
@Data
public class PhoneDialRecordDto {
@ApiModelProperty(value = "呼叫时间")
private LocalDateTime dialTime;
/**
* AI 自动外呼 COMMON人工随访电话否则为空
*/
@ApiModelProperty(value = "AI :自动外呼 或 COMMON人工随访电话否则为空")
private String phoneDialMethod;
}

View File

@ -1,6 +1,7 @@
package com.xinelu.manage.mapper.phonedialrecord;
import com.xinelu.manage.domain.phonedialrecord.PhoneDialRecord;
import com.xinelu.manage.dto.phonedialrecord.PhoneDialRecordDto;
import com.xinelu.manage.dto.statistics.FollowUpRateDto;
import com.xinelu.manage.vo.phonedialrecord.PhoneDialRecordVo;
import java.util.List;
@ -60,7 +61,29 @@ public interface PhoneDialRecordMapper {
*/
int deletePhoneDialRecordByIds(Long[] ids);
/**
* @description 统计页面查询电话拨打记录列表
* @Param queryDto 随访成功率查询传输对象
* @return 电话拨打记录列表
* @Author haown
* @Date 2024-11-8 14:44
*/
List<PhoneDialRecordVo> getPhoneDialStatistic(FollowUpRateDto queryDto);
/**
* @description 根据任务主键获取最新一次的电话拨打记录
* @Param manageRouteNodeId 任务主键
* @return 最新一次的电话拨打记录
* @Author haown
* @Date 2024-11-8 14:43
*/
PhoneDialRecord getLastRecord(Long manageRouteNodeId);
/**
* 查询未获取录音地址的电话拨打记录列表
*
* @param phoneDialRecordDto 电话拨打记录查询传输对象
* @return 电话拨打记录集合
*/
List<PhoneDialRecord> getNoVideoList(PhoneDialRecordDto phoneDialRecordDto);
}

View File

@ -72,7 +72,21 @@ public interface IAIOBService {
*/
JSONObject taskCallBack(Integer callbackType, TaskCallbackDataDto data) throws ClientException;
/**
* @description
* @Param ccUUID 通话录音唯一标识
* @return 录音下载地址
* @Author haown
* @Date 2024-11-8 13:47
*/
String record(String ccUUID);
/**
* @description 通话录音保存到本地并返回本地虚拟路径
* @Param ccUuid 通话录音唯一标识
* @return 录音本地虚拟路径
* @Author haown
* @Date 2024-11-8 13:49
*/
String getPhoneDialRecord(String ccUuid);
}

View File

@ -100,6 +100,7 @@ import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;
/**
@ -364,6 +365,7 @@ public class AIOBServiceImpl implements IAIOBService {
* @Date 2024-9-2 14:20
*/
@Override
@Transactional(rollbackFor = Exception.class)
public JSONObject taskCallBack(Integer callbackType, TaskCallbackDataDto data) throws ClientException {
JSONObject retObj = new JSONObject();
retObj.fluentPut("code", 200).fluentPut("msg", "success");
@ -483,6 +485,13 @@ public class AIOBServiceImpl implements IAIOBService {
return retObj;
}
/**
* @description
* @Param ccUUID 通话录音唯一标识
* @return 录音下载地址
* @Author haown
* @Date 2024-11-8 13:47
*/
@Override public String record(String ccUUID) {
String accessToken = getAccessToken();
HttpHeaders headers = new HttpHeaders();
@ -744,40 +753,48 @@ public class AIOBServiceImpl implements IAIOBService {
scriptInfoTaskInfoMapper.insertScriptInfoTaskInfo(scriptInfoTaskInfo);
}
/**
* @description 通话录音保存到本地并返回本地虚拟路径
* @Param ccUuid 通话录音唯一标识
* @return 录音本地虚拟路径
* @Author haown
* @Date 2024-11-8 13:49
*/
@Override
public String getPhoneDialRecord(String ccUuid) {
String url = "";
String downLoadUrl = record(ccUuid);
if (StringUtils.isNotBlank(downLoadUrl)) {
url = systemBusinessConfig.getProfile() + systemBusinessConfig.getPhoneDialRecordVideo() + "/" + ccUuid + ".wav";
File outputPath = new File(url);
File dir = outputPath.getParentFile();
if (!dir.exists()){
dir.mkdirs();
}
try {
outputPath.createNewFile(); // 创建文件
URL fileUrl = new URL(downLoadUrl);
HttpURLConnection connection = (HttpURLConnection)fileUrl.openConnection();
connection.setRequestMethod("GET");
connection.connect();
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
InputStream inputStream = new BufferedInputStream(connection.getInputStream());
FileOutputStream outputStream = new FileOutputStream(outputPath);
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
outputStream.close();
inputStream.close();
return Constants.RESOURCE_PREFIX + systemBusinessConfig.getPhoneDialRecordVideo() + "/" + ccUuid + ".wav";
} else {
throw new ServiceException("下载录音失败");
if (StringUtils.isBlank(downLoadUrl)) {
throw new ServiceException("暂未获取到录音,请稍后再试!");
}
url = systemBusinessConfig.getProfile() + systemBusinessConfig.getPhoneDialRecordVideo() + "/" + ccUuid + ".wav";
File outputPath = new File(url);
File dir = outputPath.getParentFile();
if (!dir.exists()){
dir.mkdirs();
}
try {
outputPath.createNewFile(); // 创建文件
URL fileUrl = new URL(downLoadUrl);
HttpURLConnection connection = (HttpURLConnection)fileUrl.openConnection();
connection.setRequestMethod("GET");
connection.connect();
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
InputStream inputStream = new BufferedInputStream(connection.getInputStream());
FileOutputStream outputStream = new FileOutputStream(outputPath);
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
} catch (IOException e) {
e.printStackTrace();
outputStream.close();
inputStream.close();
return Constants.RESOURCE_PREFIX + systemBusinessConfig.getPhoneDialRecordVideo() + "/" + ccUuid + ".wav";
} else {
throw new ServiceException("下载录音失败,请稍后再试");
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}

View File

@ -589,7 +589,7 @@ public class SignPatientManageRouteNodeServiceImpl implements ISignPatientManage
@Override public String getPhoneDialVideo(Long id) {
PhoneDialRecord phoneDialRecord = phoneDialRecordMapper.getLastRecord(id);
if(ObjectUtils.isEmpty(phoneDialRecord) || StringUtils.isBlank(phoneDialRecord.getCtUuid())) {
throw new ServiceException("获取录音失败");
throw new ServiceException("暂未获取到录音,请稍后再试");
}
if (StringUtils.isBlank(phoneDialRecord.getPhoneDialRecordVideo())) {
String videoUrl = aiobService.getPhoneDialRecord(phoneDialRecord.getCtUuid());

View File

@ -269,4 +269,17 @@
where manage_route_node_id = #{manageRouteNodeId}
order by dial_time desc limit 1
</select>
<select id="getNoVideoList" parameterType="com.xinelu.manage.dto.phonedialrecord.PhoneDialRecordDto" resultMap="PhoneDialRecordResult">
<include refid="selectPhoneDialRecordVo"/>
<where>
error_code = 0 and (phone_dial_record_video is null or phone_dial_record_video = '')
<if test="dialTime != null">
and date_format(dial_time, '%y%M%d%H%i') &lt;= date_format(#{dialTime}, '%y%M%d%H%i')
</if>
<if test="phoneDialMethod != null">
and phone_dial_method = #{phoneDialMethod}
</if>
</where>
</select>
</mapper>

View File

@ -0,0 +1,46 @@
package com.xinelu.quartz.task;
import com.xinelu.common.enums.PhoneDialMethodEnum;
import com.xinelu.common.utils.StringUtils;
import com.xinelu.manage.domain.phonedialrecord.PhoneDialRecord;
import com.xinelu.manage.dto.phonedialrecord.PhoneDialRecordDto;
import com.xinelu.manage.mapper.phonedialrecord.PhoneDialRecordMapper;
import com.xinelu.manage.service.aibo.IAIOBService;
import java.time.LocalDateTime;
import java.util.List;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* @description: 获取百度外呼通话记录录音定时任务
* @author: haown
* @create: 2024-11-08 13:34
**/
@Slf4j
@Component("GetAiboRecordVideoTask")
public class GetAiboRecordVideoTask {
@Resource
private PhoneDialRecordMapper phoneDialRecordMapper;
@Resource
private IAIOBService aiobService;
public void getVideo() {
// 查询超过两分钟没有录音地址的通话记录
PhoneDialRecordDto phoneDialRecordQuery = new PhoneDialRecordDto();
LocalDateTime localDateTime = LocalDateTime.now();
localDateTime.minusMinutes(2);
phoneDialRecordQuery.setDialTime(localDateTime);
phoneDialRecordQuery.setPhoneDialMethod(PhoneDialMethodEnum.AI.getInfo());
List<PhoneDialRecord> phoneDialRecordList = phoneDialRecordMapper.getNoVideoList(phoneDialRecordQuery);
phoneDialRecordList.forEach(phoneDialRecord -> {
if (StringUtils.isNotBlank(phoneDialRecord.getCtUuid())) {
String videoUrl = aiobService.getPhoneDialRecord(phoneDialRecord.getCtUuid());
phoneDialRecord.setPhoneDialRecordVideo(videoUrl);
phoneDialRecordMapper.updatePhoneDialRecord(phoneDialRecord);
}
});
}
}