AdminSystemController.java 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package com.goafanti.admin.controller;
  2. import org.springframework.beans.factory.annotation.Autowired;
  3. import org.springframework.http.HttpMethod;
  4. import org.springframework.stereotype.Controller;
  5. import org.springframework.ui.ModelMap;
  6. import org.springframework.web.bind.annotation.RequestMapping;
  7. import org.springframework.web.bind.annotation.RequestMethod;
  8. import com.alibaba.fastjson.JSONObject;
  9. import com.goafanti.common.bo.Result;
  10. import com.goafanti.common.constant.AFTConstants;
  11. import com.goafanti.common.controller.BaseApiController;
  12. import com.goafanti.core.shiro.token.TokenManager;
  13. import com.goafanti.easemob.EasemobUtils;
  14. import com.goafanti.easemob.bo.EasemobInfo;
  15. import com.goafanti.easemob.enums.EasemonSysUsers;
  16. @Controller
  17. @RequestMapping(value = "/api/admin")
  18. public class AdminSystemController extends BaseApiController {
  19. @Autowired
  20. EasemobUtils easemobUtils;
  21. /**
  22. * 初始化系统消息用户
  23. */
  24. @RequestMapping(value = "/sys/initEasemob", method = RequestMethod.GET)
  25. public Result initEasemob() {
  26. if (isSuperAdmin()) {
  27. for (EasemonSysUsers esu : EasemonSysUsers.values()) {
  28. JSONObject jo = new JSONObject();
  29. jo.put("username", esu.getUsername());
  30. jo.put("nickname", esu.getNickname());
  31. jo.put("password", System.currentTimeMillis());
  32. easemobUtils.sendLater(new EasemobInfo().uri("/users").data(jo.toJSONString()).method(HttpMethod.POST));
  33. }
  34. return res().data(true);
  35. }
  36. return res().data(false);
  37. }
  38. /**
  39. * 测试发送消息
  40. */
  41. @RequestMapping(value = "/sys/sendMsg", method = RequestMethod.GET)
  42. public Result sendMsg(String from, String to, String msg) {
  43. if (isSuperAdmin()) {
  44. easemobUtils.sendMessage(from, to, new ModelMap("nickname", EasemonSysUsers.getNickname(from)), msg, true);
  45. return res().data(true);
  46. }
  47. return res().data(false);
  48. }
  49. private boolean isSuperAdmin() {
  50. return TokenManager.hasRole(AFTConstants.SUPERADMIN);
  51. }
  52. }