ChatMessageService.java 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package com.webchat.client.mall.service;
  2. import com.webchat.common.bean.APIResponseBean;
  3. import com.webchat.common.bean.APIResponseBeanUtil;
  4. import com.webchat.common.exception.BusinessException;
  5. import com.webchat.common.util.JsonUtil;
  6. import com.webchat.domain.vo.response.chatting.ChattingListResponseVO;
  7. import com.webchat.domain.vo.response.mess.ChatMessageResponseVO;
  8. import com.webchat.rmi.ugc.ChatMessageClient;
  9. import lombok.extern.slf4j.Slf4j;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.stereotype.Service;
  12. import java.util.Collections;
  13. import java.util.List;
  14. @Slf4j
  15. @Service
  16. public class ChatMessageService {
  17. @Autowired
  18. private ChatMessageClient chatMessageClient;
  19. public List<ChatMessageResponseVO> list(String currentUserId, String chatUserId, Long lastId, Long fixedMessageId, Integer size) {
  20. APIResponseBean<List<ChatMessageResponseVO>> messageResponse = chatMessageClient.list(currentUserId, chatUserId, size, lastId, fixedMessageId);
  21. if (APIResponseBeanUtil.isOk(messageResponse)) {
  22. return messageResponse.getData();
  23. }
  24. return Collections.emptyList();
  25. }
  26. public List<ChattingListResponseVO> listChatting(String userId, Long lastChatTime, Integer size) {
  27. // RPC 远程调用,请求 UGC 核心服务获取对话列表数据
  28. APIResponseBean<List<ChattingListResponseVO>> responseBean = chatMessageClient.listChatting(userId, lastChatTime, size);
  29. if (APIResponseBeanUtil.isOk(responseBean)) {
  30. return responseBean.getData();
  31. }
  32. log.error("chatMessageClient.listChatting RPC invoke error =====> " +
  33. "userId:{}, lastChatTime:{}, size:{}, response:{}", userId, lastChatTime, size, JsonUtil.toJsonString(responseBean));
  34. throw new BusinessException(responseBean.getMsg());
  35. }
  36. }