ImReplyController.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. package jnpf.message.controller;
  2. import io.swagger.v3.oas.annotations.Operation;
  3. import io.swagger.v3.oas.annotations.Parameter;
  4. import io.swagger.v3.oas.annotations.Parameters;
  5. import io.swagger.v3.oas.annotations.tags.Tag;
  6. import jnpf.base.ActionResult;
  7. import jnpf.base.controller.SuperController;
  8. import jnpf.base.vo.ListVO;
  9. import jnpf.message.entity.ImReplyEntity;
  10. import jnpf.message.model.ImReplyListModel;
  11. import jnpf.message.model.ImReplyListVo;
  12. import jnpf.message.service.ImContentService;
  13. import jnpf.message.service.ImReplyService;
  14. import jnpf.permission.entity.UserEntity;
  15. import jnpf.permission.service.UserService;
  16. import jnpf.util.JsonUtil;
  17. import jnpf.util.StringUtil;
  18. import jnpf.util.UploaderUtil;
  19. import jnpf.util.UserProvider;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.web.bind.annotation.*;
  22. import java.util.ArrayList;
  23. import java.util.Arrays;
  24. import java.util.Comparator;
  25. import java.util.List;
  26. import java.util.stream.Collectors;
  27. /**
  28. * 消息会话接口
  29. *
  30. * @author JNPF开发平台组
  31. * @version V3.1.0
  32. * @copyright 引迈信息技术有限公司(https://www.jnpfsoft.com)
  33. * @date 2021-05-29
  34. */
  35. @Tag(name = "消息会话接口", description = "imreply")
  36. @RestController
  37. @RequestMapping("/api/message/imreply")
  38. public class ImReplyController extends SuperController<ImReplyService, ImReplyEntity> {
  39. @Autowired
  40. private ImReplyService imReplyService;
  41. @Autowired
  42. private ImContentService imContentService;
  43. @Autowired
  44. private UserService userService;
  45. /**
  46. * 获取消息会话列表
  47. *
  48. * @return
  49. */
  50. @Operation(summary = "获取消息会话列表")
  51. @GetMapping
  52. public ActionResult<ListVO<ImReplyListVo>> getList(@RequestParam("keyword") String keyword) {
  53. List<ImReplyListModel> imReplyList = imReplyService.getImReplyList();
  54. //过滤 发送者删除标记
  55. imReplyList = imReplyList.stream().filter(t -> {
  56. List<String> deleteId = StringUtil.isNotEmpty(t.getImreplyDeleteUser()) ? Arrays.asList(t.getImreplyDeleteUser().split(",")) : new ArrayList<>();
  57. return !deleteId.contains(UserProvider.getUser().getUserId());
  58. }).collect(Collectors.toList());
  59. List<ImReplyListModel> imReplyLists = new ArrayList<>(imReplyList);
  60. for (ImReplyListModel vo : imReplyList) {
  61. UserEntity entity = userService.getInfo(vo.getId());
  62. if (entity == null || entity.getEnabledMark() == 0) {
  63. imReplyLists.remove(vo);
  64. continue;
  65. }
  66. //拼接账号和名称
  67. vo.setRealName(entity.getRealName());
  68. vo.setAccount(entity.getAccount());
  69. //头像路径拼接
  70. vo.setHeadIcon(UploaderUtil.uploaderImg(vo.getHeadIcon()));
  71. //获取未读消息
  72. vo.setUnreadMessage(imContentService.getUnreadCount(vo.getId(), UserProvider.getUser().getUserId()));
  73. if (vo.getDeleteUserId() != null && vo.getDeleteUserId().equals(UserProvider.getUser().getUserId()) || vo.getDeleteMark() == 1) {
  74. vo.setLatestMessage("");
  75. vo.setMessageType("");
  76. }
  77. }
  78. if (StringUtil.isNotEmpty(keyword)) {
  79. imReplyLists = imReplyLists.stream().filter(t -> t.getAccount().contains(keyword) || t.getRealName().contains(keyword)).collect(Collectors.toList());
  80. }
  81. //排序
  82. imReplyLists = imReplyLists.stream().sorted(Comparator.comparing(ImReplyListModel::getLatestDate).reversed()).collect(Collectors.toList());
  83. List<ImReplyListVo> imReplyListVoList = JsonUtil.getJsonToList(imReplyLists, ImReplyListVo.class);
  84. ListVO listVO = new ListVO();
  85. listVO.setList(imReplyListVoList);
  86. return ActionResult.success(listVO);
  87. }
  88. /**
  89. * 删除聊天记录
  90. *
  91. * @param id 主键
  92. * @return ignore
  93. */
  94. @Operation(summary = "删除聊天记录")
  95. @Parameters({
  96. @Parameter(name = "id", description = "主键", required = true)
  97. })
  98. @DeleteMapping("/deleteChatRecord/{id}")
  99. public ActionResult deleteChatRecord(@PathVariable("id") String id) {
  100. imContentService.deleteChatRecord(UserProvider.getUser().getUserId(), id);
  101. return ActionResult.success("");
  102. }
  103. /**
  104. * 移除会话列表
  105. *
  106. * @param id 主键
  107. * @return ignore
  108. */
  109. @Operation(summary = "移除会话列表")
  110. @Parameters({
  111. @Parameter(name = "id", description = "主键", required = true)
  112. })
  113. @DeleteMapping("/relocation/{id}")
  114. public ActionResult relocation(@PathVariable("id") String id) {
  115. imReplyService.relocation(UserProvider.getUser().getUserId(), id);
  116. return ActionResult.success("");
  117. }
  118. }