Commit 08ef93c7 by zhangjw

1:完善订单推送逻辑

parent ddcf6b33
package com.ym.im.entity; package com.ym.im.entity;
import com.ym.im.validation.group.ChatRecordSaveGroup;
import com.ym.im.validation.group.ChatRecordSendGroup;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import javax.validation.constraints.NotNull;
import javax.validation.groups.Default;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.Date;
/** /**
* 行程表 * 行程表
...@@ -144,6 +139,4 @@ public class Stroke implements Serializable { ...@@ -144,6 +139,4 @@ public class Stroke implements Serializable {
@ApiModelProperty("是否是优惠调机,0-否,1-是") @ApiModelProperty("是否是优惠调机,0-否,1-是")
private Boolean isDiscount; private Boolean isDiscount;
@ApiModelProperty(value = "发送时间")
private Date sendTime;
} }
package com.ym.im.mq; package com.ym.im.mq;
import com.ym.im.entity.MsgBody; import com.ym.im.entity.*;
import com.ym.im.entity.StaffSocketInfo;
import com.ym.im.entity.Stroke;
import com.ym.im.entity.UserSocketInfo;
import com.ym.im.entity.base.NettyConstant; import com.ym.im.entity.base.NettyConstant;
import com.ym.im.entity.model.IdModel; import com.ym.im.entity.model.IdModel;
import com.ym.im.handler.ChannelGroupHandler; import com.ym.im.handler.ChannelGroupHandler;
import com.ym.im.service.ChatService;
import com.ym.im.service.StaffService; import com.ym.im.service.StaffService;
import com.ym.im.util.JsonUtils; import com.ym.im.util.JsonUtils;
import lombok.SneakyThrows; import lombok.SneakyThrows;
...@@ -28,9 +26,6 @@ import java.util.Set; ...@@ -28,9 +26,6 @@ import java.util.Set;
@Component @Component
public class Receiver { public class Receiver {
@Autowired
private Queue queue;
@Resource(name = "myRedisTemplate") @Resource(name = "myRedisTemplate")
private RedisTemplate redisTemplate; private RedisTemplate redisTemplate;
...@@ -40,6 +35,9 @@ public class Receiver { ...@@ -40,6 +35,9 @@ public class Receiver {
@Autowired @Autowired
private ChannelGroupHandler channelGroup; private ChannelGroupHandler channelGroup;
@Autowired
private ChatService staffSingleChatServiceImpl;
@RabbitListener(queues = "#{staffOfflineQueue.name}") @RabbitListener(queues = "#{staffOfflineQueue.name}")
public void offlineHandler(StaffSocketInfo staffSocketInfo) { public void offlineHandler(StaffSocketInfo staffSocketInfo) {
...@@ -67,7 +65,7 @@ public class Receiver { ...@@ -67,7 +65,7 @@ public class Receiver {
/** /**
* 订单相关处理 * 订单相关处理
* *
* @param orderModel * @param json
*/ */
@SneakyThrows @SneakyThrows
@RabbitListener(queues = "#{orderQueue.name}") @RabbitListener(queues = "#{orderQueue.name}")
...@@ -76,14 +74,15 @@ public class Receiver { ...@@ -76,14 +74,15 @@ public class Receiver {
log.info("订单信息: " + json); log.info("订单信息: " + json);
final Long mcId = stroke.getMcId(); final Long mcId = stroke.getMcId();
final Long userId = stroke.getUserId(); final Long userId = stroke.getUserId();
final UserSocketInfo userSocketInfo = channelGroup.USER_GROUP.get(userId); final UserSocketInfo userSocketInfo = channelGroup.USER_GROUP.get(20L);
if (userSocketInfo == null) { if (userSocketInfo == null) {
return; return;
} }
stroke.setSendTime(new Date());
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) : channelGroup.getMerchantStaff(userSocketInfo.getStaffId(stroke.getMcId())); final StaffSocketInfo staffSocketInfo = channelGroup.getMerchantStaff(userSocketInfo.getStaffId(stroke.getMcId())) == null ? staffService.getIdleStaff(mcId, userId) : channelGroup.getMerchantStaff(userSocketInfo.getStaffId(stroke.getMcId()));
if (staffSocketInfo != null) { if (staffSocketInfo != null) {
final ChatRecord chatRecord = new ChatRecord().setMsgInfo(json).setUserId(userId).setSendTime(new Date()).setMsgType(MsgBody.ORDER);
final MsgBody<ChatRecord> orderInfo = new MsgBody<ChatRecord>().setCode(MsgBody.ORDER).setData(chatRecord);
staffSingleChatServiceImpl.save(staffSocketInfo.getStaffId(), orderInfo);
staffSocketInfo.writeAndFlush(orderInfo); staffSocketInfo.writeAndFlush(orderInfo);
log.info("客服订单: " + "给客服(" + staffSocketInfo.getStaffId() + ")发送订单:" + json); log.info("客服订单: " + "给客服(" + staffSocketInfo.getStaffId() + ")发送订单:" + json);
} }
......
...@@ -15,7 +15,21 @@ import javax.validation.constraints.NotNull; ...@@ -15,7 +15,21 @@ import javax.validation.constraints.NotNull;
**/ **/
public interface MsgBodyService { public interface MsgBodyService {
/**
* 消息流程处理器
*
* @param ctx
* @param msgBody
* @throws JsonProcessingException
*/
void msgBodyHandle(@NotNull ChannelHandlerContext ctx, @Valid MsgBody<ChatRecord> msgBody) throws JsonProcessingException; void msgBodyHandle(@NotNull ChannelHandlerContext ctx, @Valid MsgBody<ChatRecord> msgBody) throws JsonProcessingException;
/**
* 发送与回执
*
* @param channel
* @param msgBody
* @throws JsonProcessingException
*/
void sendAndAck(NioSocketChannel channel, MsgBody<ChatRecord> msgBody) throws JsonProcessingException; void sendAndAck(NioSocketChannel channel, MsgBody<ChatRecord> msgBody) throws JsonProcessingException;
} }
...@@ -113,6 +113,7 @@ public class UserSingleChatServiceImpl implements ChatService { ...@@ -113,6 +113,7 @@ public class UserSingleChatServiceImpl implements ChatService {
if (staffId == null) { if (staffId == null) {
staffSocketInfo = staffService.getIdleStaff(merchantId, id); staffSocketInfo = staffService.getIdleStaff(merchantId, id);
if (staffSocketInfo == null) { if (staffSocketInfo == null) {
log.info("当前没有客服在线! ");
return null; return null;
} }
} else { } else {
......
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