Skip to content

Commit

Permalink
修改webim功能
Browse files Browse the repository at this point in the history
  • Loading branch information
SAM2O2O committed May 4, 2018
1 parent b95beea commit ae1094a
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 385 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,43 @@
public class FileController {
private static final Logger logger = LoggerFactory.getLogger(FileController.class);

// 跳转到聊天主页面
@RequestMapping("/upload")
public String uploadFile(HttpServletRequest request, HttpServletResponse response) {

return null;
}

// 跳转到聊天主页面
@RequestMapping("/download")
public String downloadFile(HttpServletRequest request, HttpServletResponse response, String fileId) {
String result = writeFileStream(request, response, fileId);
logger.info("dowoload file id={} result={}", fileId, result);
return null;
}

// 跳转到聊天主页面
@RequestMapping("/site-logo")
// @ResponseBody
public String getSiteLogo(HttpServletRequest request, HttpServletResponse response) {
String logoFileId = SiteConfig.getSiteLogo();
System.out.println("fileId=" + logoFileId);

if (StringUtils.isNotEmpty(logoFileId)) {
String fileUrl = FilePathUtils.getFilePathByFileId(logoFileId);
String result = writeFileStream(request, response, logoFileId);
logger.info("dowoload site logo fileId={} result={}", logoFileId, result);

return null;
}

private String writeFileStream(HttpServletRequest request, HttpServletResponse response, String fileId) {
String result = "error";
if (StringUtils.isNotEmpty(fileId)) {
String fileUrl = FilePathUtils.getFilePathByFileId(fileId);
System.out.println("fileUrl = " + fileUrl);
File file = new File(fileUrl);

if (file.exists()) {
response.setContentType("application/force-download");
response.addHeader("Content-Disposition", "attachment;fileName=" + logoFileId);
response.addHeader("Content-Disposition", "attachment;fileName=" + fileId);
// 每次写1M缓存数据大小
byte[] bufferContent = new byte[1024];
FileInputStream fis = null;
Expand All @@ -59,6 +81,7 @@ public String getSiteLogo(HttpServletRequest request, HttpServletResponse respon
break;
}
}
result = "success";
logger.info("download site logo success!");
fis.close();
bis.close();
Expand All @@ -80,10 +103,9 @@ public String getSiteLogo(HttpServletRequest request, HttpServletResponse respon
}
}
} else {
System.out.println("文件不存在");
logger.warn("file is not exits");
}
}
return null;
return result;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.akaxin.site.business.impl.site.SiteConfig;
import com.akaxin.site.storage.bean.SimpleGroupBean;
import com.akaxin.site.storage.bean.SimpleUserBean;
import com.akaxin.site.storage.bean.UserProfileBean;
import com.akaxin.site.web.chat.service.WebChatService;

/**
Expand Down Expand Up @@ -47,25 +48,46 @@ public ModelAndView toChatIndex() {
public ModelAndView toChatMain(@RequestParam String sessionId) {
ModelAndView modelAndView = new ModelAndView("webChat/akaxin_chat_main");
System.out.println("/akaxin/chat sessionid=" + sessionId);
modelAndView.addObject("siteName", SiteConfig.getConfig(ConfigProto.ConfigKey.SITE_NAME_VALUE));
modelAndView.addObject("sessionId", sessionId);
String siteUserId = "77151873-0fc7-4cf1-8bd6-67d00190fcf6";

UserProfileBean bean = webChatService.getUserProfile(siteUserId);
if (bean != null) {
modelAndView.addObject("siteLogoId", SiteConfig.getSiteLogo());
modelAndView.addObject("siteName", SiteConfig.getConfig(ConfigProto.ConfigKey.SITE_NAME_VALUE));
modelAndView.addObject("sessionId", sessionId);
modelAndView.addObject("userId", bean.getSiteUserId());
modelAndView.addObject("userName", bean.getUserName());
modelAndView.addObject("userPhoto", bean.getUserPhoto());
}

return modelAndView;
}

@RequestMapping(value = "/chatList", produces = "application/json;charset=UTF-8")
@ResponseBody
public List<Object> getUserChatList() {
public String getChatSessions(@RequestParam String sessionId) {
List<Object> resData = new ArrayList<Object>();
String siteUserId = "77151873-0fc7-4cf1-8bd6-67d00190fcf6";

Map<String, String> map = new HashMap<String, String>();
resData.add(map);
return resData;
List<SimpleUserBean> friendList = webChatService.getUserFriendList(siteUserId);
if (friendList != null) {
for (SimpleUserBean bean : friendList) {
Map<String, String> map = new HashMap<String, String>();
map.put("id", bean.getUserId());
map.put("stype", "u2");// u2 or group
map.put("name", bean.getUserName());
map.put("photo", bean.getUserPhoto());
map.put("msg", "目前我们已经解决了大部分问题");
resData.add(map);
}
}

return GsonUtils.toJson(resData);
}

@RequestMapping(value = "/friendList", produces = "application/json;charset=UTF-8")
@ResponseBody
public String getFriendList() {
public String getFriendList(@RequestParam String sessionId) {
List<Object> resData = new ArrayList<Object>();
String siteUserId = "77151873-0fc7-4cf1-8bd6-67d00190fcf6";

Expand All @@ -82,9 +104,9 @@ public String getFriendList() {
return GsonUtils.toJson(resData);
}

@RequestMapping(value = "/GroupList", produces = "application/json;charset=UTF-8")
@RequestMapping(value = "/groupList", produces = "application/json;charset=UTF-8")
@ResponseBody
public List<Object> getGroupList() {
public List<Object> getGroupList(@RequestParam String sessionId) {
List<Object> resData = new ArrayList<Object>();
String siteUserId = "77151873-0fc7-4cf1-8bd6-67d00190fcf6";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@

import com.akaxin.site.business.dao.UserFriendDao;
import com.akaxin.site.business.dao.UserGroupDao;
import com.akaxin.site.business.dao.UserProfileDao;
import com.akaxin.site.storage.bean.SimpleGroupBean;
import com.akaxin.site.storage.bean.SimpleUserBean;
import com.akaxin.site.storage.bean.UserProfileBean;

@Service("webChatService")
public class WebChatService {

public UserProfileBean getUserProfile(String siteUserId) {
return UserProfileDao.getInstance().getUserProfileById(siteUserId);
}

public List<SimpleUserBean> getChatList(String siteUserId) {
// return UserFriendDao.getInstance().getUserFriends(siteUserId);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,25 +113,6 @@
dataType="json",
}); */

function toUtf8(str) {
var out, i, len, c;
out = "";
len = str.length;
for (i = 0; i < len; i++) {
c = str.charCodeAt(i);
if ((c >= 0x0001) && (c <= 0x007F)) {
out += str.charAt(i);
} else if (c > 0x07FF) {
out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
} else {
out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
}
}
return out;
}

function akxWebGuid() {
function S4() {
Expand Down
Loading

0 comments on commit ae1094a

Please sign in to comment.