diff --git a/ruoyi-cai/src/main/java/com/ruoyi/cai/ws/handler/MessageHandleApplication.java b/ruoyi-cai/src/main/java/com/ruoyi/cai/ws/handler/MessageHandleApplication.java index e87b75fe..259fe0c6 100644 --- a/ruoyi-cai/src/main/java/com/ruoyi/cai/ws/handler/MessageHandleApplication.java +++ b/ruoyi-cai/src/main/java/com/ruoyi/cai/ws/handler/MessageHandleApplication.java @@ -38,7 +38,7 @@ public class MessageHandleApplication { private ChatManager chatManager; public void processOn(WebSocketSession session, String message) { - log.info("调试日志:收到websocket的请求 message={}",message); + log.info("调试日志:收到websocket的请求111 message={}",message); if(StringUtil.isEmpty(message)){ return; } @@ -72,6 +72,7 @@ public class MessageHandleApplication { return; } FdCtxData fdCtxData = fdCtxDataCache.getByRoomId(session.getId()); + log.info("调试日志:收到websocket的请求222 message={} fdCtxData={}",message, JSON.toJSONString(fdCtxData)); handler.processOn(room,fdCtxData, jsonObject.getJSONObject("data")); } } diff --git a/ruoyi-cai/src/main/java/com/ruoyi/cai/ws/handler/message/GiftMessageHandler.java b/ruoyi-cai/src/main/java/com/ruoyi/cai/ws/handler/message/GiftMessageHandler.java index 258bb16d..fd2e85cd 100644 --- a/ruoyi-cai/src/main/java/com/ruoyi/cai/ws/handler/message/GiftMessageHandler.java +++ b/ruoyi-cai/src/main/java/com/ruoyi/cai/ws/handler/message/GiftMessageHandler.java @@ -1,5 +1,6 @@ package com.ruoyi.cai.ws.handler.message; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson2.JSONObject; import com.ruoyi.cai.domain.Account; import com.ruoyi.cai.domain.Gift; @@ -15,6 +16,7 @@ import com.ruoyi.cai.ws.bean.Room; import com.ruoyi.cai.ws.dto.WsRMsgGen; import com.ruoyi.cai.ws.handler.IMessageHandler; import com.ruoyi.cai.ws.handler.AbstractMessageHandle; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -22,14 +24,13 @@ import org.springframework.stereotype.Component; * 送礼物 */ @Component("gift") +@Slf4j public class GiftMessageHandler extends AbstractMessageHandle implements IMessageHandler { @Autowired private GiftService giftService; @Autowired private AccountService accountService; @Autowired - private UserGiftService userGiftService; - @Autowired private ConsumerManager consumerManager; @Override public void processOn(Room room, FdCtxData fdCtxData, JSONObject map) { @@ -58,11 +59,20 @@ public class GiftMessageHandler extends AbstractMessageHandle implements IMessag giveGiftReq.setToUserId(fdCtxData.getTarUserId()); giveGiftReq.setGiftId(giftId); giveGiftReq.setGiftCount(giftCount); - GiftConsumerResp consumeResp = consumerManager.sendGift(giveGiftReq); - if(!consumeResp.isSuccess()){ + try { + GiftConsumerResp consumeResp = consumerManager.sendGift(giveGiftReq); + if(!consumeResp.isSuccess()){ + sendToCurrent(fdCtxData,WsRMsgGen.sysNotice("赠送失败,请重试")); + return; + } + } catch (Exception e){ + log.error("直播送礼物失败!req={}", JSON.toJSONString(giveGiftReq),e); sendToCurrent(fdCtxData,WsRMsgGen.sysNotice("赠送失败,请重试")); return; } + + + sendToAll(room.getRoomId(),WsRMsgGen.gift(gift,fdCtxData.getUserId(),fdCtxData.getTarUserId())); } }