package com.uas.demo.web; import com.uas.demo.model.ChatInfo; import com.uas.demo.service.ChatInfoService; import com.uas.demo.service.ChatService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.Map; @Controller @RequestMapping(value = "/chat") public class ChatController { private final ChatService chatService; private final ChatInfoService chatInfoService; @Autowired public ChatController(ChatService chatService, ChatInfoService chatInfoService) { this.chatService = chatService; this.chatInfoService = chatInfoService; } /** * 跳转私聊页面 * * @param from 信息发送者的手机号 * @param to 信息接收者的手机号 * @param model 模型属性 */ @Deprecated @RequestMapping(method = RequestMethod.GET) public String chatIndex(String from, String to, Model model, HttpServletResponse response) throws IOException { Map map = chatService.findChatUserInfo(from, to); String type = map.get("type"); if (StringUtils.isEmpty(type)) { response.sendRedirect("/login"); } else if ("USER_LIST".equals(type)) { // TODO huxz 跳转到好友列表,暂时跳转到首页 response.sendRedirect("/index"); } for (Map.Entry entry :map.entrySet()) { model.addAttribute(entry.getKey(), entry.getValue()); } return "chat/private"; } @RequestMapping(value = "/visit", method = RequestMethod.GET) public String visitWebIm(@RequestParam(value = "gid", required = false) String id, HttpServletResponse response) throws IOException { if (StringUtils.isEmpty(id)) { //response.sendRedirect("/"); return "id不可为空"; } else { ChatInfo chatInfo = chatInfoService.queryChatInfoWhenUserVisitWebSite(id); if (chatInfo == null || chatInfo.getUserInfo() == null || StringUtils.isEmpty(chatInfo.getUserInfo().getUserId())) { //response.sendRedirect("/"); return "chat/chat-list"; } } return "chat/chat-list"; } }