MessageController.java 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package com.bosshand.virgo.controller;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.bosshand.virgo.core.response.Response;
  5. import com.bosshand.virgo.message.model.NotificationMessage;
  6. import com.bosshand.virgo.message.service.MessageService;
  7. import io.swagger.annotations.ApiOperation;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.web.bind.annotation.*;
  10. import java.util.HashMap;
  11. import java.util.List;
  12. import java.util.Map;
  13. @RestController
  14. @RequestMapping(value = "message")
  15. public class MessageController {
  16. @Autowired
  17. private MessageService messageService;
  18. @ApiOperation("分页获取消息列表")
  19. @RequestMapping(value = "/{currPage}/{pageSize}", method = RequestMethod.POST)
  20. public Response list(@RequestBody NotificationMessage notificationMessage, @PathVariable int currPage, @PathVariable int pageSize) {
  21. int totalCount = messageService.getTotalCount(notificationMessage);
  22. List<NotificationMessage> dataList = messageService.getLimit(notificationMessage, currPage, pageSize);
  23. Map<String, Object> result = new HashMap<>();
  24. result.put("dataList", dataList);
  25. result.put("totalCount", totalCount);
  26. return Response.ok(result);
  27. }
  28. @ApiOperation(value = "个人消息列表", notes = "个人消息列表")
  29. @RequestMapping(value = "/{userId}", method = RequestMethod.GET)
  30. public Response getByUserId(@PathVariable long userId) {
  31. return Response.ok(messageService.getMessageByUserId(userId));
  32. }
  33. @ApiOperation(value = "待办事项", notes = "待办事项")
  34. @RequestMapping(value = "/backlog/{userId}", method = RequestMethod.GET)
  35. public Response backlog(@PathVariable long userId) {
  36. return Response.ok(messageService.getMessage(userId, false));
  37. }
  38. @ApiOperation(value = "已办事项", notes = "已办事项")
  39. @RequestMapping(value = "/finishBacklog/{userId}", method = RequestMethod.GET)
  40. public Response finishBacklog(@PathVariable long userId) {
  41. return Response.ok(messageService.getMessage(userId, true));
  42. }
  43. @ApiOperation(value = "审核消息发送", notes = "审核消息发送")
  44. @RequestMapping(value = "/", method = RequestMethod.POST)
  45. public Response pushMesssage(@RequestBody JSONObject parameter) {
  46. messageService.pushMessage(parameter);
  47. return Response.ok();
  48. }
  49. @ApiOperation(value = "其他消息发送", notes = "其他消息发送")
  50. @RequestMapping(value = "/{userIds}", method = RequestMethod.POST)
  51. public Response pushOtherMesssage(@PathVariable String userIds, @RequestBody NotificationMessage message) {
  52. messageService.pushOtherMesssage(userIds, message);
  53. return Response.ok();
  54. }
  55. @ApiOperation(value = "提醒消息发送", notes = "提醒消息发送")
  56. @RequestMapping(value = "/reminder", method = RequestMethod.POST)
  57. public void pushReminderMessage(@RequestBody JSONArray data) {
  58. messageService.pushReminderMessage(data);
  59. }
  60. @ApiOperation(value = "修改", notes = "修改")
  61. @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
  62. public Response updateViewed(@PathVariable long id) {
  63. messageService.updateViewed(id);
  64. return Response.ok();
  65. }
  66. @ApiOperation(value = "详情", notes = "详情")
  67. @RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
  68. public Response get(@PathVariable long id) {
  69. return Response.ok(messageService.get(id));
  70. }
  71. @ApiOperation(value = "根据type获取消息列表", notes = "根据type获取消息列表")
  72. @RequestMapping(value = "/messageType/{userId}/{messageType}", method = RequestMethod.GET)
  73. public Response getByUserId(@PathVariable int messageType, @PathVariable long userId) {
  74. return Response.ok(messageService.getMessageByUserId(messageType, userId));
  75. }
  76. @ApiOperation(value = "统计未读消息数", notes = "统计未读消息数")
  77. @RequestMapping(value = "/countUnread/messageType/{userId}", method = RequestMethod.GET)
  78. public Response countUnread(@PathVariable long userId) {
  79. return Response.ok(messageService.countUnread(userId));
  80. }
  81. }