ChatController.java 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package com.uas.demo.web;
  2. import com.uas.demo.model.ChatInfo;
  3. import com.uas.demo.service.ChatInfoService;
  4. import com.uas.demo.service.ChatService;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.stereotype.Controller;
  7. import org.springframework.ui.Model;
  8. import org.springframework.util.StringUtils;
  9. import org.springframework.web.bind.annotation.RequestMapping;
  10. import org.springframework.web.bind.annotation.RequestMethod;
  11. import org.springframework.web.bind.annotation.RequestParam;
  12. import javax.servlet.http.HttpServletResponse;
  13. import java.io.IOException;
  14. import java.util.Map;
  15. @Controller
  16. @RequestMapping(value = "/chat")
  17. public class ChatController {
  18. private final ChatService chatService;
  19. private final ChatInfoService chatInfoService;
  20. @Autowired
  21. public ChatController(ChatService chatService, ChatInfoService chatInfoService) {
  22. this.chatService = chatService;
  23. this.chatInfoService = chatInfoService;
  24. }
  25. /**
  26. * 跳转私聊页面
  27. *
  28. * @param from 信息发送者的手机号
  29. * @param to 信息接收者的手机号
  30. * @param model 模型属性
  31. */
  32. @Deprecated
  33. @RequestMapping(method = RequestMethod.GET)
  34. public String chatIndex(String from, String to, Model model, HttpServletResponse response) throws IOException {
  35. Map<String, String> map = chatService.findChatUserInfo(from, to);
  36. String type = map.get("type");
  37. if (StringUtils.isEmpty(type)) {
  38. response.sendRedirect("/login");
  39. } else if ("USER_LIST".equals(type)) {
  40. // TODO huxz 跳转到好友列表,暂时跳转到首页
  41. response.sendRedirect("/index");
  42. }
  43. for (Map.Entry<String, String> entry :map.entrySet()) {
  44. model.addAttribute(entry.getKey(), entry.getValue());
  45. }
  46. return "chat/private";
  47. }
  48. @RequestMapping(value = "/visit", method = RequestMethod.GET)
  49. public String visitWebIm(@RequestParam(value = "gid", required = false) String id, HttpServletResponse response) throws IOException {
  50. if (StringUtils.isEmpty(id)) {
  51. //response.sendRedirect("/");
  52. return "id不可为空";
  53. } else {
  54. ChatInfo chatInfo = chatInfoService.queryChatInfoWhenUserVisitWebSite(id);
  55. if (chatInfo == null || chatInfo.getUserInfo() == null || StringUtils.isEmpty(chatInfo.getUserInfo().getUserId())) {
  56. //response.sendRedirect("/");
  57. return "chat/chat-list";
  58. }
  59. }
  60. return "chat/chat-list";
  61. }
  62. }