MessageController.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package com.uas.ps.message.api;
  2. import com.uas.ps.core.page.PageParams;
  3. import com.uas.ps.httplog.annotation.HttpLog;
  4. import com.uas.ps.message.domain.Message;
  5. import com.uas.ps.message.service.MessageService;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.data.domain.Page;
  8. import org.springframework.ui.ModelMap;
  9. import org.springframework.web.bind.annotation.RequestBody;
  10. import org.springframework.web.bind.annotation.RequestMapping;
  11. import org.springframework.web.bind.annotation.RequestMethod;
  12. import org.springframework.web.bind.annotation.RequestParam;
  13. import org.springframework.web.bind.annotation.RestController;
  14. import java.util.List;
  15. import java.util.Map;
  16. /**
  17. * Created by wangyc on 2018/1/13.
  18. *
  19. * @version 2018/1/13 15:36 wangyc
  20. */
  21. @RestController
  22. @RequestMapping(value = "/messages")
  23. public class MessageController {
  24. private final MessageService messageService;
  25. @Autowired
  26. public MessageController(MessageService messageService) {
  27. this.messageService = messageService;
  28. }
  29. /**
  30. * 获取消息
  31. * @param receiverUu 收信人uu
  32. * @param receiverEnuu 收信人企业uu
  33. * @param consumerApp 接收app
  34. * @param pageParams 分页参数
  35. * @param isRead 读取状态
  36. * @param type 类型
  37. * @param keyword 关键词
  38. * @param pageParams
  39. * @return
  40. */
  41. @HttpLog
  42. @RequestMapping(method = RequestMethod.GET, produces = "application/json")
  43. public Page<Message> getMessages(String receiverUu, String receiverEnuu, String consumerApp, String isRead, String type, String keyword, PageParams pageParams) {
  44. return messageService.getMessages(receiverUu, receiverEnuu, consumerApp, isRead, type, keyword, pageParams);
  45. }
  46. /**
  47. * 获取未读消息数量
  48. * @param receiverUu 收信人uu
  49. * @param receiverEnuu 收信人企业uu
  50. * @param consumerApp 接收app
  51. * @return
  52. */
  53. @RequestMapping(value = "/count/unread", method = RequestMethod.GET, produces = "application/json")
  54. public Map<String, Object> getUnReadMessageCount(String receiverUu, String receiverEnuu, String consumerApp) {
  55. return messageService.getUnReadMessageCount(receiverUu, receiverEnuu, consumerApp);
  56. }
  57. /**
  58. * 获取未读消息数量
  59. * @param receiverUu 收信人uu
  60. * @param receiverEnuu 收信人企业uu
  61. * @param consumerApp 接收app
  62. * @param isRead 阅读状态
  63. * @return
  64. */
  65. @RequestMapping(value = "/count", method = RequestMethod.GET, produces = "application/json")
  66. public Map<String, Object> getMessageCount(String receiverUu, String receiverEnuu, String consumerApp, @RequestParam(required = false) String isRead) {
  67. return messageService.getMessageCount(receiverUu, receiverEnuu, consumerApp, isRead);
  68. }
  69. /**
  70. * 保存消息
  71. * @param messages 消息
  72. * @return
  73. */
  74. @HttpLog
  75. @RequestMapping(method = RequestMethod.POST, produces = "application/json")
  76. public List<Message> saveMessages(@RequestBody String messages) {
  77. // TODO 日志
  78. return messageService.saveMessages(messages);
  79. }
  80. /**
  81. * 推送消息
  82. * @param consumerApp 接收消息app
  83. * @return
  84. */
  85. @HttpLog
  86. @RequestMapping(value = "/send", method = RequestMethod.POST, produces = "application/json")
  87. public Map<String, Object> sendMessage(@RequestBody String consumerApp) {
  88. return messageService.sendMessage(consumerApp);
  89. }
  90. /**
  91. * 阅读消息
  92. * @param cousumer 消息接收者信息
  93. * @return
  94. */
  95. @HttpLog
  96. @RequestMapping(value = "/read", method = RequestMethod.POST, produces = "application/json")
  97. public ModelMap read(@RequestBody String cousumer) {
  98. return messageService.readMessage(cousumer);
  99. }
  100. }