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

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; package com.xinelu.manage.mapper.phonedialrecord;
import com.xinelu.manage.domain.phonedialrecord.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.dto.statistics.FollowUpRateDto;
import com.xinelu.manage.vo.phonedialrecord.PhoneDialRecordVo; import com.xinelu.manage.vo.phonedialrecord.PhoneDialRecordVo;
import java.util.List; import java.util.List;
@ -60,7 +61,29 @@ public interface PhoneDialRecordMapper {
*/ */
int deletePhoneDialRecordByIds(Long[] ids); int deletePhoneDialRecordByIds(Long[] ids);
/**
* @description 统计页面查询电话拨打记录列表
* @Param queryDto 随访成功率查询传输对象
* @return 电话拨打记录列表
* @Author haown
* @Date 2024-11-8 14:44
*/
List<PhoneDialRecordVo> getPhoneDialStatistic(FollowUpRateDto queryDto); List<PhoneDialRecordVo> getPhoneDialStatistic(FollowUpRateDto queryDto);
/**
* @description 根据任务主键获取最新一次的电话拨打记录
* @Param manageRouteNodeId 任务主键
* @return 最新一次的电话拨打记录
* @Author haown
* @Date 2024-11-8 14:43
*/
PhoneDialRecord getLastRecord(Long manageRouteNodeId); 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; JSONObject taskCallBack(Integer callbackType, TaskCallbackDataDto data) throws ClientException;
/**
* @description
* @Param ccUUID 通话录音唯一标识
* @return 录音下载地址
* @Author haown
* @Date 2024-11-8 13:47
*/
String record(String ccUUID); String record(String ccUUID);
/**
* @description 通话录音保存到本地并返回本地虚拟路径
* @Param ccUuid 通话录音唯一标识
* @return 录音本地虚拟路径
* @Author haown
* @Date 2024-11-8 13:49
*/
String getPhoneDialRecord(String ccUuid); String getPhoneDialRecord(String ccUuid);
} }

View File

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

View File

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

View File

@ -269,4 +269,17 @@
where manage_route_node_id = #{manageRouteNodeId} where manage_route_node_id = #{manageRouteNodeId}
order by dial_time desc limit 1 order by dial_time desc limit 1
</select> </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> </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);
}
});
}
}