This commit is contained in:
张良(004796)
2024-04-01 10:09:39 +08:00
parent 756ea2b6d4
commit e68467f1e9
2 changed files with 16 additions and 5 deletions

View File

@@ -38,7 +38,7 @@ public class MessageHandleApplication {
private ChatManager chatManager; private ChatManager chatManager;
public void processOn(WebSocketSession session, String message) { public void processOn(WebSocketSession session, String message) {
log.info("调试日志收到websocket的请求 message={}",message); log.info("调试日志收到websocket的请求111 message={}",message);
if(StringUtil.isEmpty(message)){ if(StringUtil.isEmpty(message)){
return; return;
} }
@@ -72,6 +72,7 @@ public class MessageHandleApplication {
return; return;
} }
FdCtxData fdCtxData = fdCtxDataCache.getByRoomId(session.getId()); FdCtxData fdCtxData = fdCtxDataCache.getByRoomId(session.getId());
log.info("调试日志收到websocket的请求222 message={} fdCtxData={}",message, JSON.toJSONString(fdCtxData));
handler.processOn(room,fdCtxData, jsonObject.getJSONObject("data")); handler.processOn(room,fdCtxData, jsonObject.getJSONObject("data"));
} }
} }

View File

@@ -1,5 +1,6 @@
package com.ruoyi.cai.ws.handler.message; package com.ruoyi.cai.ws.handler.message;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.cai.domain.Account; import com.ruoyi.cai.domain.Account;
import com.ruoyi.cai.domain.Gift; 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.dto.WsRMsgGen;
import com.ruoyi.cai.ws.handler.IMessageHandler; import com.ruoyi.cai.ws.handler.IMessageHandler;
import com.ruoyi.cai.ws.handler.AbstractMessageHandle; import com.ruoyi.cai.ws.handler.AbstractMessageHandle;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@@ -22,14 +24,13 @@ import org.springframework.stereotype.Component;
* 送礼物 * 送礼物
*/ */
@Component("gift") @Component("gift")
@Slf4j
public class GiftMessageHandler extends AbstractMessageHandle implements IMessageHandler { public class GiftMessageHandler extends AbstractMessageHandle implements IMessageHandler {
@Autowired @Autowired
private GiftService giftService; private GiftService giftService;
@Autowired @Autowired
private AccountService accountService; private AccountService accountService;
@Autowired @Autowired
private UserGiftService userGiftService;
@Autowired
private ConsumerManager consumerManager; private ConsumerManager consumerManager;
@Override @Override
public void processOn(Room room, FdCtxData fdCtxData, JSONObject map) { 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.setToUserId(fdCtxData.getTarUserId());
giveGiftReq.setGiftId(giftId); giveGiftReq.setGiftId(giftId);
giveGiftReq.setGiftCount(giftCount); giveGiftReq.setGiftCount(giftCount);
try {
GiftConsumerResp consumeResp = consumerManager.sendGift(giveGiftReq); GiftConsumerResp consumeResp = consumerManager.sendGift(giveGiftReq);
if(!consumeResp.isSuccess()){ if(!consumeResp.isSuccess()){
sendToCurrent(fdCtxData,WsRMsgGen.sysNotice("赠送失败,请重试")); sendToCurrent(fdCtxData,WsRMsgGen.sysNotice("赠送失败,请重试"));
return; 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())); sendToAll(room.getRoomId(),WsRMsgGen.gift(gift,fdCtxData.getUserId(),fdCtxData.getTarUserId()));
} }
} }