app通话
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package com.cool.store.enums;
|
||||
|
||||
public enum CallStatusEnum {
|
||||
|
||||
PENDING_CALL(0, "待呼叫"),
|
||||
CALL_ANSWERED(1, "呼叫接听"),
|
||||
CALL_MISSED(2, "呼叫未接听"),
|
||||
CALL_FAILED(3, "呼叫失败");
|
||||
|
||||
private final int code;
|
||||
private final String message;
|
||||
|
||||
CallStatusEnum(int code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
@@ -78,6 +78,8 @@ public enum ErrorCodeEnum {
|
||||
INTERVIEW_INTERVIEW_TIME_IS_UNUSABLE(1021114, "当前预约时间不可用,请和线索用户协商其他时间后确定预约时间\n面试人:{0} 手机号:{1}", null),
|
||||
INTERVIEW_PARTNER_NOT_EXIST(1021115, "线索下的加盟商不存在!", null),
|
||||
ROOM_STATUS_ERROR(10211156, "当前面试房间状态不允许进行该操作!", null),
|
||||
MOBILE_APP_NOT_ONLINE_ERROR(10211157, "拨出手机APP不在线!", null),
|
||||
CALL_UP_ERROR(10211158, "拨出电话异常!", null),
|
||||
CONTENT_DUPLICATED(10211200, "动态标题重复!", null),
|
||||
SIGN_FAIL(600000, "验签失败", null),
|
||||
GET_ACCESSTOKEN_ERROR(600001, "获取小程序TOKEN错误!", null),
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.cool.store.mapper;
|
||||
|
||||
import com.cool.store.entity.CallRecordDO;
|
||||
|
||||
/**
|
||||
* @author zhangchenbiao
|
||||
* @date 2023-08-11 01:03
|
||||
*/
|
||||
public interface CallRecordMapper {
|
||||
/**
|
||||
*
|
||||
* 默认插入方法,只会给有值的字段赋值
|
||||
* 会对传进来的字段做判空处理,如果字段为空,则使用数据库默认字段或者null
|
||||
* dateTime:2023-08-11 01:03
|
||||
*/
|
||||
int insertSelective(CallRecordDO record);
|
||||
|
||||
/**
|
||||
*
|
||||
* 默认更新方法,根据主键更新,不会把null值更新到数据库,避免覆盖之前有值的
|
||||
* dateTime:2023-08-11 01:03
|
||||
*/
|
||||
int updateByPrimaryKeySelective(CallRecordDO record);
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
<?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.cool.store.mapper.CallRecordMapper">
|
||||
<resultMap id="BaseResultMap" type="com.cool.store.entity.CallRecordDO">
|
||||
<id column="id" jdbcType="BIGINT" property="id" />
|
||||
<result column="partner_line_id" jdbcType="BIGINT" property="partnerLineId" />
|
||||
<result column="trans_no" jdbcType="VARCHAR" property="transNo" />
|
||||
<result column="outgoing_mobile" jdbcType="VARCHAR" property="outgoingMobile" />
|
||||
<result column="outgoing_user_id" jdbcType="VARCHAR" property="outgoingUserId" />
|
||||
<result column="incoming_mobile" jdbcType="VARCHAR" property="incomingMobile" />
|
||||
<result column="incoming_user_id" jdbcType="VARCHAR" property="incomingUserId" />
|
||||
<result column="call_start_time" jdbcType="TIMESTAMP" property="callStartTime" />
|
||||
<result column="call_end_time" jdbcType="TIMESTAMP" property="callEndTime" />
|
||||
<result column="record_url" jdbcType="VARCHAR" property="recordUrl" />
|
||||
<result column="call_status" jdbcType="TINYINT" property="callStatus" />
|
||||
<result column="fail_reason" jdbcType="VARCHAR" property="failReason" />
|
||||
<result column="creater" jdbcType="VARCHAR" property="creater" />
|
||||
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
|
||||
<result column="updater" jdbcType="VARCHAR" property="updater" />
|
||||
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
|
||||
<result column="remark" jdbcType="VARCHAR" property="remark" />
|
||||
</resultMap>
|
||||
<sql id="Base_Column_List">
|
||||
id, partner_line_id, trans_no, outgoing_mobile, outgoing_user_id, incoming_mobile,
|
||||
incoming_user_id, call_start_time, call_end_time, record_url, call_status, fail_reason,
|
||||
creater, create_time, updater, update_time, remark
|
||||
</sql>
|
||||
<insert id="insertSelective" keyColumn="id" keyProperty="record.id" useGeneratedKeys="true">
|
||||
insert into call_record
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="partnerLineId != null">
|
||||
partner_line_id,
|
||||
</if>
|
||||
<if test="transNo != null">
|
||||
trans_no,
|
||||
</if>
|
||||
<if test="outgoingMobile != null">
|
||||
outgoing_mobile,
|
||||
</if>
|
||||
<if test="outgoingUserId != null">
|
||||
outgoing_user_id,
|
||||
</if>
|
||||
<if test="incomingMobile != null">
|
||||
incoming_mobile,
|
||||
</if>
|
||||
<if test="incomingUserId != null">
|
||||
incoming_user_id,
|
||||
</if>
|
||||
<if test="callStartTime != null">
|
||||
call_start_time,
|
||||
</if>
|
||||
<if test="callEndTime != null">
|
||||
call_end_time,
|
||||
</if>
|
||||
<if test="recordUrl != null">
|
||||
record_url,
|
||||
</if>
|
||||
<if test="callStatus != null">
|
||||
call_status,
|
||||
</if>
|
||||
<if test="failReason != null">
|
||||
fail_reason,
|
||||
</if>
|
||||
<if test="creater != null">
|
||||
creater,
|
||||
</if>
|
||||
<if test="createTime != null">
|
||||
create_time,
|
||||
</if>
|
||||
<if test="updater != null">
|
||||
updater,
|
||||
</if>
|
||||
<if test="updateTime != null">
|
||||
update_time,
|
||||
</if>
|
||||
<if test="remark != null">
|
||||
remark,
|
||||
</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="partnerLineId != null">
|
||||
#{partnerLineId},
|
||||
</if>
|
||||
<if test="transNo != null">
|
||||
#{transNo},
|
||||
</if>
|
||||
<if test="outgoingMobile != null">
|
||||
#{outgoingMobile},
|
||||
</if>
|
||||
<if test="outgoingUserId != null">
|
||||
#{outgoingUserId},
|
||||
</if>
|
||||
<if test="incomingMobile != null">
|
||||
#{incomingMobile},
|
||||
</if>
|
||||
<if test="incomingUserId != null">
|
||||
#{incomingUserId},
|
||||
</if>
|
||||
<if test="callStartTime != null">
|
||||
#{callStartTime},
|
||||
</if>
|
||||
<if test="callEndTime != null">
|
||||
#{callEndTime},
|
||||
</if>
|
||||
<if test="recordUrl != null">
|
||||
#{recordUrl},
|
||||
</if>
|
||||
<if test="callStatus != null">
|
||||
#{callStatus},
|
||||
</if>
|
||||
<if test="failReason != null">
|
||||
#{failReason},
|
||||
</if>
|
||||
<if test="creater != null">
|
||||
#{creater},
|
||||
</if>
|
||||
<if test="createTime != null">
|
||||
#{createTime},
|
||||
</if>
|
||||
<if test="updater != null">
|
||||
#{updater},
|
||||
</if>
|
||||
<if test="updateTime != null">
|
||||
#{updateTime},
|
||||
</if>
|
||||
<if test="remark != null">
|
||||
#{remark},
|
||||
</if>
|
||||
</trim>
|
||||
</insert>
|
||||
<update id="updateByPrimaryKeySelective">
|
||||
update call_record
|
||||
<set>
|
||||
<if test="partnerLineId != null">
|
||||
partner_line_id = #{partnerLineId},
|
||||
</if>
|
||||
<if test="transNo != null">
|
||||
trans_no = #{transNo},
|
||||
</if>
|
||||
<if test="outgoingMobile != null">
|
||||
outgoing_mobile = #{outgoingMobile},
|
||||
</if>
|
||||
<if test="outgoingUserId != null">
|
||||
outgoing_user_id = #{outgoingUserId},
|
||||
</if>
|
||||
<if test="incomingMobile != null">
|
||||
incoming_mobile = #{incomingMobile},
|
||||
</if>
|
||||
<if test="incomingUserId != null">
|
||||
incoming_user_id = #{incomingUserId},
|
||||
</if>
|
||||
<if test="callStartTime != null">
|
||||
call_start_time = #{callStartTime},
|
||||
</if>
|
||||
<if test="callEndTime != null">
|
||||
call_end_time = #{callEndTime},
|
||||
</if>
|
||||
<if test="recordUrl != null">
|
||||
record_url = #{recordUrl},
|
||||
</if>
|
||||
<if test="callStatus != null">
|
||||
call_status = #{callStatus},
|
||||
</if>
|
||||
<if test="failReason != null">
|
||||
fail_reason = #{failReason},
|
||||
</if>
|
||||
<if test="creater != null">
|
||||
creater = #{creater},
|
||||
</if>
|
||||
<if test="createTime != null">
|
||||
create_time = #{createTime},
|
||||
</if>
|
||||
<if test="updater != null">
|
||||
updater = #{updater},
|
||||
</if>
|
||||
<if test="updateTime != null">
|
||||
update_time = #{updateTime},
|
||||
</if>
|
||||
<if test="remark != null">
|
||||
remark = #{remark},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id}
|
||||
</update>
|
||||
</mapper>
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.cool.store.dto.call;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @Author: young.yu
|
||||
* @Date: 2023-08-11 15:24
|
||||
* @Description:
|
||||
*/
|
||||
@Data
|
||||
public class CallUpDTO {
|
||||
private String transNo;
|
||||
private String outgoingMobile;
|
||||
private String incomingMobile;
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.cool.store.entity;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangchenbiao
|
||||
* @date 2023-08-11 01:03
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class CallRecordDO implements Serializable {
|
||||
@ApiModelProperty("id")
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty("线索id")
|
||||
private Long partnerLineId;
|
||||
|
||||
@ApiModelProperty("请求编号")
|
||||
private String transNo;
|
||||
|
||||
@ApiModelProperty("呼出人手机号")
|
||||
private String outgoingMobile;
|
||||
|
||||
@ApiModelProperty("呼出人用户id")
|
||||
private String outgoingUserId;
|
||||
|
||||
@ApiModelProperty("接听人手机号")
|
||||
private String incomingMobile;
|
||||
|
||||
@ApiModelProperty("接听人用户id")
|
||||
private String incomingUserId;
|
||||
|
||||
@ApiModelProperty("通话开始时间")
|
||||
private Date callStartTime;
|
||||
|
||||
@ApiModelProperty("通话结束时间")
|
||||
private Date callEndTime;
|
||||
|
||||
@ApiModelProperty("录音地址")
|
||||
private String recordUrl;
|
||||
|
||||
@ApiModelProperty("0.待呼叫1.呼叫接听2.呼叫未接听3.呼叫失败")
|
||||
private Integer callStatus;
|
||||
|
||||
@ApiModelProperty("失败原因")
|
||||
private String failReason;
|
||||
|
||||
@ApiModelProperty("创建人")
|
||||
private String creater;
|
||||
|
||||
@ApiModelProperty("创建时间")
|
||||
private Date createTime;
|
||||
|
||||
@ApiModelProperty("更新人")
|
||||
private String updater;
|
||||
|
||||
@ApiModelProperty("更新时间")
|
||||
private Date updateTime;
|
||||
|
||||
@ApiModelProperty("备注")
|
||||
private String remark;
|
||||
}
|
||||
@@ -117,25 +117,32 @@ public class WebSocketServer {
|
||||
* 实现服务
|
||||
* 器主动推送
|
||||
*/
|
||||
public void sendMessage(String message) {
|
||||
public boolean sendMessage(String message) {
|
||||
boolean flag = false;
|
||||
try {
|
||||
this.session.getBasicRemote().sendText(message);
|
||||
flag = true;
|
||||
} catch (IOException e) {
|
||||
log.error("发送消息失败:" + this.tenantId + ",原因:" + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送自定
|
||||
* 义消息
|
||||
**/
|
||||
public static void sendInfo(String message, String tenantId) {
|
||||
public static boolean sendInfo(String message, String tenantId) {
|
||||
boolean flag = false;
|
||||
log.info("发送消息到:" + tenantId + ",报文:" + message);
|
||||
if (StringUtils.isNotBlank(tenantId) && webSocketMap.containsKey(tenantId)) {
|
||||
webSocketMap.get(tenantId).sendMessage(message);
|
||||
flag = true;
|
||||
} else {
|
||||
log.error("用户" + tenantId + ",不在线!");
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -163,4 +170,13 @@ public class WebSocketServer {
|
||||
public static synchronized void subOnlineCount() {
|
||||
WebSocketServer.onlineCount--;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断用户是否在线
|
||||
* @param tenantId
|
||||
* @return
|
||||
*/
|
||||
public static boolean isOnline(String tenantId) {
|
||||
return webSocketMap.containsKey(tenantId);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,21 @@
|
||||
package com.cool.store.service.impl;
|
||||
|
||||
import cn.hutool.core.lang.UUID;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.cool.store.dto.call.CallUpDTO;
|
||||
import com.cool.store.entity.CallRecordDO;
|
||||
import com.cool.store.enums.CallStatusEnum;
|
||||
import com.cool.store.enums.ErrorCodeEnum;
|
||||
import com.cool.store.exception.ApiException;
|
||||
import com.cool.store.handler.WebSocketServer;
|
||||
import com.cool.store.mapper.CallRecordMapper;
|
||||
import com.cool.store.request.CallUpReq;
|
||||
import com.cool.store.service.CallService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author: young.yu
|
||||
* @Date: 2023-08-10 18:58
|
||||
@@ -13,8 +24,40 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
public class CallServiceImpl implements CallService {
|
||||
|
||||
@Autowired
|
||||
private CallRecordMapper callRecordMapper;
|
||||
@Override
|
||||
public void callUp(CallUpReq request) throws ApiException {
|
||||
//校验拨出手机号APP是否在线
|
||||
boolean isOnline = WebSocketServer.isOnline(request.getOutgoingMobile());
|
||||
if(!isOnline){
|
||||
throw new ApiException(ErrorCodeEnum.MOBILE_APP_NOT_ONLINE_ERROR);
|
||||
}
|
||||
CallRecordDO callRecordDO = new CallRecordDO();
|
||||
callRecordDO.setOutgoingMobile(request.getOutgoingMobile());
|
||||
callRecordDO.setIncomingMobile(request.getIncomingMobile());
|
||||
callRecordDO.setOutgoingUserId(request.getOutgoingUserId());
|
||||
callRecordDO.setIncomingUserId(request.getIncomingUserId());
|
||||
callRecordDO.setPartnerLineId(Long.valueOf(request.getLineId()));
|
||||
|
||||
//请求id
|
||||
String transNo = UUID.fastUUID().toString();
|
||||
callRecordDO.setTransNo(transNo);
|
||||
callRecordDO.setCreater(request.getOutgoingUserId());
|
||||
callRecordDO.setCreateTime(new Date());
|
||||
callRecordDO.setCallStatus(CallStatusEnum.PENDING_CALL.getCode());
|
||||
|
||||
//发起app通话请求
|
||||
CallUpDTO callUpDTO = new CallUpDTO();
|
||||
callUpDTO.setTransNo(transNo);
|
||||
callUpDTO.setOutgoingMobile(request.getOutgoingMobile());
|
||||
callUpDTO.setIncomingMobile(request.getIncomingMobile());
|
||||
boolean sendFlag = WebSocketServer.sendInfo(JSON.toJSONString(callUpDTO),callRecordDO.getOutgoingMobile());
|
||||
if(!sendFlag){
|
||||
throw new ApiException(ErrorCodeEnum.CALL_UP_ERROR);
|
||||
}
|
||||
|
||||
//保存通话记录
|
||||
callRecordMapper.insertSelective(callRecordDO);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user