从阿里云服务器获取百度外呼回调数据。

This commit is contained in:
haown 2025-12-24 14:53:42 +08:00
parent eabcb21bc2
commit 456efaa186
7 changed files with 212 additions and 4 deletions

View File

@ -12,10 +12,10 @@ spring:
# 从库数据源
slave:
# 从数据源开关/默认关闭
enabled: false
url:
username:
password:
enabled: true
url: jdbc:mysql://8.131.93.145:54081/aiob_callback?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&allowMultiQueries=true
username: root
password: 1qaz!@#$
hkhis:
# 从数据源开关/默认关闭
enabled: true

View File

@ -0,0 +1,43 @@
package com.xinelu.manage.domain.aiob;
import java.util.Date;
import lombok.Data;
/**
* @description: 阿里云百度外呼回调对象
* @author: haown
* @create: 2025-12-22 15:11
**/
@Data
public class AIOBCallbackEntity {
/**
* 主键
*/
private Integer id;
/**
* 回调数据类型 0-任务呼叫单通电话回调 1-号码组终态回调 2-任务状态变更回调 3-实时呼叫单通电话回调
*/
private Integer callbackType;
/**
* 回调数据
*/
private String callbackData;
/**
* 已读状态0未读1已读
*/
private Integer readState;
/**
* 创建时间
*/
private Date createDate;
/**
* 修改时间
*/
private Date updateDate;
}

View File

@ -0,0 +1,22 @@
package com.xinelu.manage.mapper.aiob;
import com.xinelu.common.annotation.DataSource;
import com.xinelu.common.enums.DataSourceType;
import com.xinelu.manage.domain.aiob.AIOBCallbackEntity;
import java.util.List;
import org.apache.ibatis.annotations.Param;
/**
* @description 阿里云服务器百度外呼回调Mapper接口
* @Author haown
* @Date 2025-12-23 15:45
*/
@DataSource(DataSourceType.SLAVE)
public interface AIOBCallbackMapper {
List<AIOBCallbackEntity> getList(AIOBCallbackEntity query);
Integer updateReadState(@Param("readState")Integer readState, @Param("id")Integer id);
Integer deleteData();
}

View File

@ -0,0 +1,18 @@
package com.xinelu.manage.service.aiob;
import com.xinelu.manage.domain.aiob.AIOBCallbackEntity;
import java.util.List;
/**
* @description: 阿里云服务器百度外呼回调Service接口
* @author: haown
* @create: 2025-12-23 15:22
**/
public interface IAIOBCallbackService {
List<AIOBCallbackEntity> getList(AIOBCallbackEntity query);
Integer updateReadState(Integer readState, Integer id);
Integer deleteData();
}

View File

@ -0,0 +1,31 @@
package com.xinelu.manage.service.aiob.impl;
import com.xinelu.manage.domain.aiob.AIOBCallbackEntity;
import com.xinelu.manage.mapper.aiob.AIOBCallbackMapper;
import com.xinelu.manage.service.aiob.IAIOBCallbackService;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
/**
* @description: 阿里云服务器百度外呼回调Service实现
* @author: haown
* @create: 2025-12-23 15:30
**/
@Service
public class AIOBCallbackServiceImpl implements IAIOBCallbackService {
@Resource
private AIOBCallbackMapper aiobCallbackMapper;
@Override
public List<AIOBCallbackEntity> getList(AIOBCallbackEntity query) {
return aiobCallbackMapper.getList(query);
}
@Override public Integer updateReadState(Integer readState, Integer id) {
return aiobCallbackMapper.updateReadState(readState, id);
}
@Override public Integer deleteData() {
return aiobCallbackMapper.deleteData();
}
}

View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xinelu.manage.mapper.aiob.AIOBCallbackMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.xinelu.manage.domain.aiob.AIOBCallbackEntity">
<id column="id" property="id" />
<result column="callback_type" property="callbackType" />
<result column="callback_data" property="callbackData" />
<result column="read_state" property="readState" />
<result column="create_date" property="createDate" />
<result column="update_date" property="updateDate" />
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id, callback_type, callback_data, read_state, create_date, update_date
</sql>
<select id="getList" parameterType="AIOBCallbackEntity" resultMap="BaseResultMap">
select id, callback_type, callback_data, read_state, create_date, update_date from aiob_callback_data
<where>
<if test="readState != null">
and read_state = #{readState}
</if>
</where>
</select>
<update id="updateReadState">
update aiob_callback_data set read_state = #{readState}, update_date = sysdate()
where id = #{id}
</update>
<delete id="deleteData">
delete from aiob_callback_data where read_state = 1 and DATE(create_date) &lt; DATE_SUB(CURDATE(), INTERVAL 1 MONTH)
</delete>
</mapper>

View File

@ -0,0 +1,57 @@
package com.xinelu.quartz.task;
import com.alibaba.fastjson.JSON;
import com.aliyuncs.exceptions.ClientException;
import com.xinelu.manage.domain.aiob.AIOBCallbackEntity;
import com.xinelu.manage.dto.aiob.TaskCallbackDataDto;
import com.xinelu.manage.service.aiob.IAIOBCallbackService;
import com.xinelu.manage.service.aiob.IAIOBService;
import java.util.List;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
/**
* @description: 获取百度外呼回调数据
* @author: haown
* @create: 2025-12-23 15:12
**/
@Slf4j
@Component("GetAiobCallbackDataTask")
public class GetAiobCallbackDataTask {
@Resource
private IAIOBService aiobService;
@Resource
private IAIOBCallbackService aiobCallbackService;
public void syncCallbackData() {
log.info("开始执行同步百度外呼回调数据定时任务......");
AIOBCallbackEntity aiobCallbackEntity = new AIOBCallbackEntity();
aiobCallbackEntity.setReadState(0);
List<AIOBCallbackEntity> callbackEntityList = aiobCallbackService.getList(aiobCallbackEntity);
if (!CollectionUtils.isEmpty(callbackEntityList)) {
// 回调数据解析
callbackEntityList.forEach(callbackEntity -> {
// JSONString TaskCallbackDataDto
TaskCallbackDataDto taskCallbackDataDto = JSON.parseObject(callbackEntity.getCallbackData(), TaskCallbackDataDto.class);
try {
// 执行回调
aiobService.taskCallBack(callbackEntity.getCallbackType(), taskCallbackDataDto);
// 修改阿里云服务器回调数据已读状态
aiobCallbackService.updateReadState(1, callbackEntity.getId());
} catch (ClientException e) {
throw new RuntimeException(e);
}
});
}
log.info("完成同步百度外呼回调数据定时任务......");
}
public void clearCallbackData() {
log.info("开始执行清除过期的百度外呼回调数据定时任务......");
// 清除一个月前的数据
int count = aiobCallbackService.deleteData();
log.info("完成清除过期的百度外呼回调数据定时任务,共清除" + count +"条......");
}
}