MessageController.java 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package com.uas.ps.message.api;
  2. import com.uas.ps.message.domain.Message;
  3. import com.uas.ps.message.service.MessageService;
  4. import java.util.List;
  5. import java.util.Map;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.web.bind.annotation.RequestBody;
  8. import org.springframework.web.bind.annotation.RequestMapping;
  9. import org.springframework.web.bind.annotation.RequestMethod;
  10. import org.springframework.web.bind.annotation.RequestParam;
  11. import org.springframework.web.bind.annotation.RestController;
  12. /**
  13. * Created by wangyc on 2018/1/13.
  14. *
  15. * @version 2018/1/13 15:36 wangyc
  16. */
  17. @RestController
  18. @RequestMapping(value = "/messages")
  19. public class MessageController {
  20. private final MessageService messageService;
  21. @Autowired
  22. private MessageController(MessageService messageService) {
  23. this.messageService = messageService;
  24. }
  25. /**
  26. * 获取消息
  27. * @param receiver 收信人
  28. * @param consumerApp 接收app
  29. * @return
  30. */
  31. @RequestMapping(method = RequestMethod.GET, produces = "application/json")
  32. public List<Message> getMessages(@RequestParam String receiver, String consumerApp) {
  33. return messageService.getMessages(receiver, consumerApp);
  34. }
  35. /**
  36. * 保存消息
  37. * @param messages 消息
  38. * @return
  39. */
  40. @RequestMapping(method = RequestMethod.POST, produces = "application/json")
  41. public List<Message> saveMessages(@RequestBody String messages) {
  42. // TODO 日志
  43. return messageService.saveMessages(messages);
  44. }
  45. /**
  46. * 推送消息
  47. * @param consumerApp 接收消息app
  48. * @return
  49. */
  50. @RequestMapping(value = "/send", method = RequestMethod.POST, produces = "application/json")
  51. public Map<String, Object> sendMessage(@RequestBody String consumerApp) {
  52. return messageService.sendMessage(consumerApp);
  53. }
  54. }