app通话
This commit is contained in:
@@ -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