|
|
@ -1,10 +1,12 @@ |
|
|
|
package com.ccsens.game.service; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import com.ccsens.cloudutil.feign.TallFeignClient; |
|
|
|
import com.ccsens.game.bean.dto.message.AckMessageDto; |
|
|
|
import com.ccsens.game.bean.dto.message.AuthMessageDto; |
|
|
|
import com.ccsens.game.bean.dto.message.ChromeMessageDto; |
|
|
|
import com.ccsens.game.bean.dto.message.*; |
|
|
|
import com.ccsens.game.bean.po.GameUserJoin; |
|
|
|
import com.ccsens.game.bean.po.GameUserJoinExample; |
|
|
|
import com.ccsens.game.netty.ChannelManager; |
|
|
|
import com.ccsens.game.persist.dao.GameUserJoinDao; |
|
|
|
import com.ccsens.util.JacksonUtil; |
|
|
|
import com.ccsens.util.config.RabbitMQConfig; |
|
|
|
import io.netty.channel.ChannelHandlerContext; |
|
|
@ -12,12 +14,19 @@ import org.springframework.amqp.core.AmqpTemplate; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import static com.ccsens.game.netty.ChannelManager.sendTo; |
|
|
|
|
|
|
|
|
|
|
|
@Service |
|
|
|
public class MessageService implements IMessageService{ |
|
|
|
public class MessageService implements IMessageService { |
|
|
|
@Autowired |
|
|
|
private AmqpTemplate rabbitTemplate; |
|
|
|
@Autowired |
|
|
|
private TallFeignClient tallFeignClient; |
|
|
|
@Autowired |
|
|
|
private GameUserJoinDao gameUserJoinDao; |
|
|
|
|
|
|
|
@Override |
|
|
|
public void sendGameMessageWithGetUrl(ChromeMessageDto message) throws Exception { |
|
|
@ -40,11 +49,16 @@ public class MessageService implements IMessageService{ |
|
|
|
System.out.println(message); |
|
|
|
//ws连接认证
|
|
|
|
String userId = message.getData().getUserId(); |
|
|
|
if(userId == null){ |
|
|
|
if (userId == null) { |
|
|
|
String token = message.getData().getToken(); |
|
|
|
userId = tallFeignClient.getUserId(token); |
|
|
|
} |
|
|
|
ChannelManager.authChannel(ctx.channel(),userId,1,1); |
|
|
|
String recordId = message.getData().getId(); |
|
|
|
ChannelManager.authChannel(ctx.channel(), userId, 1, 1, recordId); |
|
|
|
AuthMessageWithAnswerDto messageWithAnswerDto = new AuthMessageWithAnswerDto(true, "ok"); |
|
|
|
sendTo(ctx.channel(), messageWithAnswerDto); |
|
|
|
|
|
|
|
|
|
|
|
// if(userId == null){
|
|
|
|
//// logger.warn(String.format("Auth failed: %s",userId,message.getData().getToken()));
|
|
|
|
//// ChannelManager.removeChannel(ctx.channel());
|
|
|
@ -55,7 +69,7 @@ public class MessageService implements IMessageService{ |
|
|
|
// }
|
|
|
|
// String channelId = message.getData().getChannelId();
|
|
|
|
// if(ChannelManager.authChannel(ctx.channel(),userId)){ //认证成功
|
|
|
|
//查找所有该用户相关未收到的消息和未读消息依次发送给该用户
|
|
|
|
//查找所有该用户相关未收到的消息和未读消息依次发送给该用户
|
|
|
|
// sendAllUnSendSuccessedMessagesByUserId(userId,0L);
|
|
|
|
// AuthMessageWithAnswerDto messageWithAnswerDto = new AuthMessageWithAnswerDto(true,"ok");
|
|
|
|
// sendTo(ctx.channel(),messageWithAnswerDto);
|
|
|
@ -64,4 +78,18 @@ public class MessageService implements IMessageService{ |
|
|
|
//// sendTo(ctx.channel(),messageWithAnswerDto);
|
|
|
|
// }
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void doChangeStatusMessageDto(GameMessageWithChangeStatusOut gameMessage) { |
|
|
|
Long recordId = gameMessage.getData().getRecordId(); |
|
|
|
GameUserJoinExample gameUserJoinExample = new GameUserJoinExample(); |
|
|
|
gameUserJoinExample.createCriteria().andRecordIdEqualTo(recordId); |
|
|
|
List<GameUserJoin> userJoinList = gameUserJoinDao.selectByExample(gameUserJoinExample); |
|
|
|
if (CollectionUtil.isNotEmpty(userJoinList)) { |
|
|
|
for(GameUserJoin userJoin : userJoinList){ |
|
|
|
sendTo(userJoin.getUserId().toString(),gameMessage); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|