AppApiController.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. package com.goafanti.app.controller;
  2. import java.lang.reflect.InvocationTargetException;
  3. import javax.servlet.http.HttpServletRequest;
  4. import org.apache.commons.lang3.StringUtils;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.web.bind.annotation.RequestMapping;
  7. import org.springframework.web.bind.annotation.RequestMethod;
  8. import org.springframework.web.bind.annotation.RestController;
  9. import com.goafanti.common.bo.Result;
  10. import com.goafanti.common.constant.AFTConstants;
  11. import com.goafanti.common.constant.ErrorConstants;
  12. import com.goafanti.common.controller.BaseApiController;
  13. import com.goafanti.common.model.MessageFromSystem;
  14. import com.goafanti.common.model.User;
  15. import com.goafanti.common.utils.DateUtils;
  16. import com.goafanti.core.shiro.token.TokenManager;
  17. import com.goafanti.message.bo.MessageListBo;
  18. import com.goafanti.message.service.MessageService;
  19. import com.goafanti.user.service.UserService;
  20. @RestController
  21. @RequestMapping(path = "/api/user/app", method = RequestMethod.GET)
  22. public class AppApiController extends BaseApiController {
  23. @Autowired
  24. private UserService userServiceImpl;
  25. @Autowired
  26. private MessageService messageServiceImpl;
  27. @RequestMapping(value = "/uploadImg",method = RequestMethod.POST)
  28. public Result uploadAvatar(HttpServletRequest req){
  29. Result res = new Result();
  30. String headPortraitUrl = handleFile(res, "/avatar/", false, req, "");
  31. if(TokenManager.getToken() instanceof User){
  32. User u = (User)TokenManager.getToken();
  33. u.setHeadPortraitUrl(headPortraitUrl);
  34. userServiceImpl.updateByPrimaryKeySelective(u);
  35. }
  36. res.setData(headPortraitUrl);
  37. return res;
  38. }
  39. @RequestMapping(value = "/updateUser",method = RequestMethod.POST)
  40. public Result updateUser(User u){
  41. Result res = new Result();
  42. if(null != u){
  43. u.setId(TokenManager.getUserId());
  44. userServiceImpl.updateByPrimaryKeySelective(u);
  45. }else{
  46. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR));
  47. }
  48. return res;
  49. }
  50. @RequestMapping(value = "/logout",method = RequestMethod.GET)
  51. public Result logout(HttpServletRequest request){
  52. Result res = new Result();
  53. TokenManager.logout();
  54. return res;
  55. }
  56. @RequestMapping(value = "/userInfo",method = RequestMethod.GET)
  57. public Result userInfo(HttpServletRequest request){
  58. Result res = new Result();
  59. res.setData(userServiceImpl.selectBaseInfo());
  60. return res;
  61. }
  62. @RequestMapping(value = "/index", method = RequestMethod.GET)
  63. public Result index(){
  64. Result res = new Result();
  65. res.setData(messageServiceImpl.selectMessageWithGroup());
  66. return res;
  67. }
  68. @RequestMapping(value = "/listMessage", method = RequestMethod.POST)
  69. public Result listMessage(Integer subject,Integer sourceType,Integer pageNo,Integer pageSize){
  70. Result res = new Result();
  71. if(null == subject){
  72. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "必须指定消息类型"));
  73. return res;
  74. }
  75. res.setData(messageServiceImpl.listPersonalMessage(subject,sourceType,pageNo,pageSize));
  76. return res;
  77. }
  78. /**
  79. * 同步绑定账号
  80. * @param uuid
  81. * @param registrationId
  82. * @param userName
  83. */
  84. @RequestMapping(value = "/synBindingAccount",method = RequestMethod.POST)
  85. private Result synBindingAccount(String uuid,String registrationId,String easemobName,String easemobPass){
  86. Result res = new Result();
  87. //更新 jpush_easemob_account
  88. messageServiceImpl.updateJpushEasemobAccount(uuid, registrationId, easemobName,easemobPass);
  89. return res;
  90. }
  91. /**
  92. * 读取消息
  93. * @param messageId
  94. * @throws IllegalAccessException
  95. * @throws InvocationTargetException
  96. */
  97. @RequestMapping(value = "/readMessage",method = RequestMethod.GET)
  98. private Result readMessage(String messageId){
  99. Result res = new Result();
  100. if(StringUtils.isBlank(messageId)){
  101. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "消息编号为空"));
  102. return res;
  103. }
  104. //读取消息详情
  105. MessageFromSystem mfs = messageServiceImpl.selectSystemMessageDetail(messageId);
  106. MessageListBo bo = new MessageListBo();
  107. bo.setCreateTime(bo.getCreateTime()==null?"":DateUtils.formatDate(mfs.getCreateTime(), AFTConstants.YYYYMMDDHHMMSS));
  108. bo.setResourceType(String.valueOf(mfs.getResourceType()));
  109. bo.setSubject(String.valueOf(mfs.getSubject()));
  110. bo.setMessageId(mfs.getId());
  111. bo.setTitle(mfs.getTitle());
  112. bo.setBody(mfs.getBody());
  113. res.setData(bo);
  114. //更新 message_consumer
  115. messageServiceImpl.updateMessageConsumer(messageId);
  116. return res;
  117. }
  118. }