Commit 0a30aeef by zhangjw

1:订单推送到客服模块

2:完善MQ配置和逻辑
parent 15696384
......@@ -18,15 +18,9 @@ import io.geekidea.springbootplus.framework.shiro.util.JwtUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Set;
......
package com.jumeirah.common.mq;
import com.jumeirah.common.entity.Stroke;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
......@@ -18,13 +17,9 @@ public class Queue {
@Autowired
private AmqpTemplate rabbitTemplate;
@Value("${spring.rabbitmq.user-queue-name}")
private String userQueueName;
@Value("${spring.rabbitmq.order-queue-name}")
private String orderQueueName;
/**
* 推送订单状态到客服系统
*
......@@ -34,14 +29,5 @@ public class Queue {
rabbitTemplate.convertAndSend(orderQueueName, stroke);
}
/**
* 禁用用户
*
* @param userId
*/
public void disableUserQueue(String userId) {
rabbitTemplate.convertAndSend(userQueueName, userId);
}
}
\ No newline at end of file
......@@ -30,8 +30,7 @@ spring:
port: 5672
username: root
password: root
user-queue-name: disable.user.dev
order-queue-name: push.order
order-queue-name: push.order.dev
# 打印SQL语句和结果集,本地开发环境可开启,线上注释掉
mybatis-plus:
......
......@@ -26,6 +26,13 @@ spring:
password: temple123456
port: 6379
rabbitmq:
host: 47.99.47.225
port: 5672
username: root
password: root
order-queue-name: push.order
# 打印SQL语句和结果集,本地开发环境可开启,线上注释掉
mybatis-plus:
configuration:
......
package com.ym.im.handler;
import com.ym.im.entity.base.ChannelAttributeKey;
import com.ym.im.exception.HttpException;
import com.ym.im.factory.SingleChatFactory;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
......@@ -30,10 +29,10 @@ public abstract class BaseHandler<T> extends SimpleChannelInboundHandler<T> {
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
if (cause instanceof HttpException) {
return;
}
singleChatFactory.getService(ctx.channel().attr(ChannelAttributeKey.ROLE_TYPE).get()).offline(ctx);
// if (cause instanceof HttpException) {
// return;
// }
// singleChatFactory.getService(ctx.channel().attr(ChannelAttributeKey.ROLE_TYPE).get()).offline(ctx);
}
}
package com.ym.im.mq;
import com.ym.im.config.RabbitConfig;
import com.ym.im.entity.*;
import com.ym.im.entity.base.NettyConstant;
import com.ym.im.entity.enums.RoleEnum;
......@@ -14,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
......@@ -30,7 +32,7 @@ public class Receiver {
@Autowired
private Queue queue;
@Autowired
@Resource(name = "myRedisTemplate")
private RedisTemplate redisTemplate;
@Autowired
......@@ -64,9 +66,10 @@ public class Receiver {
redisTemplate.delete(NettyConstant.STAFF_USERIDS_KEY + staffId);
//客服真离线后 才转发
if (channelGroup.getMerchantStaff(staffId) == null) {
final Set<Long> userIds = staffSocketInfo.getUserIds();
final Set userIds = staffSocketInfo.getUserIds();
log.info("客服离线队列: " + "ID: " + "UserIds:" + userIds);
userIds.forEach(userId -> {
userIds.forEach(uid -> {
Long userId = Long.valueOf(uid.toString());
//用户在线才重新分配和转发
if (channelGroup.USER_GROUP.get(userId) != null) {
final StaffSocketInfo idleStaff = staffService.getIdleStaff(staffSocketInfo.getMerchantId(), userId);
......@@ -105,33 +108,32 @@ public class Receiver {
@RabbitListener(queues = ORDER_QUEUE_NAME)
public void orderHandler(String json) {
final Stroke stroke = JsonUtils.json2Obj(json, Stroke.class);
final Long mcId = stroke.getMcId();
final Long userId = stroke.getUserId();
final UserSocketInfo userSocketInfo = channelGroup.USER_GROUP.get(userId);
if (userSocketInfo == null) {
return;
}
StaffSocketInfo staffSocketInfo = channelGroup.getMerchantStaff(userSocketInfo.getStaffId(stroke.getMcId()));
final MsgBody<Stroke> orderInfo = new MsgBody<Stroke>().setCode(MsgBody.ORDER).setData(stroke);
/**
* 绑定客服在线,发送订单信息
*/
final StaffSocketInfo staffSocketInfo = channelGroup.getMerchantStaff(userSocketInfo.getStaffId(stroke.getMcId())) == null ? staffService.getIdleStaff(mcId, userId) : null;
if (staffSocketInfo != null) {
staffSocketInfo.writeAndFlush(orderInfo);
log.info("客服订单: " + "给客服(" + staffSocketInfo.getStaffId() + ")发送订单:" + orderInfo.toString());
return;
}
/**
* 绑定客服不在线,给历史客服发送订单信息
*/
final Long staffId = (Long) redisTemplate.opsForHash().get(NettyConstant.IM_USERS, userId);
if (staffId != null) {
log.info("客服订单: " + "尝试给历史客服(" + staffId + ")发送订单:" + orderInfo.toString());
staffSocketInfo = channelGroup.getMerchantStaff(staffId);
if (staffSocketInfo != null) {
staffSocketInfo.writeAndFlush(orderInfo);
log.info("客服订单: " + "给历史客服(" + staffId + ")发送订单:" + orderInfo.toString());
}
}
// /**
// * 绑定客服不在线,给历史客服发送订单信息
// */
// final Long staffId = (Long) redisTemplate.opsForHash().get(NettyConstant.IM_USERS, userId);
// if (staffId != null) {
// log.info("客服订单: " + "尝试给历史客服(" + staffId + ")发送订单:" + orderInfo.toString());
// staffSocketInfo = channelGroup.getMerchantStaff(staffId);
// if (staffSocketInfo != null) {
// staffSocketInfo.writeAndFlush(orderInfo);
// log.info("客服订单: " + "给历史客服(" + staffId + ")发送订单:" + orderInfo.toString());
// }
// }
}
......
......@@ -28,10 +28,10 @@ public class StaffServiceImpl implements StaffService {
@Override
public StaffSocketInfo getIdleStaff(Long merchantId, Long userId) {
// final LinkedHashMap<Long, StaffSocketInfo> socketInfoMap = channelGroup.STAFF_GROUP.get(merchantId);
// if (socketInfoMap == null || socketInfoMap.size() == 0) {
// return null;
// }
if (channelGroup.STAFF_GROUP.get(merchantId) == null) {
return null;
}
final LinkedHashMap<Long, StaffSocketInfo> collect = channelGroup.STAFF_GROUP.get(merchantId)
.entrySet()
.stream()
......
......@@ -24,10 +24,10 @@ spring:
jackson:
default-property-inclusion: non_null
rabbitmq:
host: 127.0.0.1
host: 47.99.47.225
port: 5672
username: admin
password: admin
username: root
password: root
delay-queue-name: delay.ack.dev
staff-offline-Queue-Name: staff.offline.dev
exchange-name: delay.exchange.dev
......
......@@ -29,9 +29,9 @@ spring:
port: 5672
username: root
password: root
delay-queue-name: delay.ack-Jw
staff-offline-Queue-Name: staff.offline-Jw
exchange-name: delay.exchange
delay-queue-name: delay.ack.dev
staff-offline-Queue-Name: staff.offline.dev
exchange-name: delay.exchange.dev
listener:
simple:
default-requeue-rejected: false
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment