UserSysMsgController.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package com.cyksj.web.controller.sys;
  2. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  3. import com.cyksj.dto.Result;
  4. import com.cyksj.enums.GatewayResponse;
  5. import com.cyksj.mapper.UserSysMsgNotifyMapper;
  6. import com.cyksj.model.entity.UserSysMsgNotify;
  7. import com.cyksj.service.user.UserBindRelationService;
  8. import com.cyksj.web.util.StpUserUtil;
  9. import com.ejlchina.searcher.BeanSearcher;
  10. import com.ejlchina.searcher.SearchResult;
  11. import com.ejlchina.searcher.param.Operator;
  12. import com.ejlchina.searcher.util.MapUtils;
  13. import lombok.RequiredArgsConstructor;
  14. import org.springframework.web.bind.annotation.*;
  15. import javax.servlet.http.HttpServletRequest;
  16. import java.util.List;
  17. import java.util.Optional;
  18. /**
  19. * 项目名: yhlxj2
  20. * 文件名: UserSysMsgController
  21. * 创建者: JavaZou
  22. * 创建时间:2024/2/4 16:58
  23. */
  24. @RequestMapping("/sys/msg")
  25. @RestController
  26. @RequiredArgsConstructor
  27. public class UserSysMsgController {
  28. private final BeanSearcher beanSearcher;
  29. private final UserBindRelationService userBindRelationService;
  30. private final UserSysMsgNotifyMapper userSysMsgNotifyMapper;
  31. private final HttpServletRequest request;
  32. /**
  33. * 用户系统消息
  34. */
  35. @GetMapping("/get")
  36. public Result<SearchResult<UserSysMsgNotify>> getSysMsg() {
  37. long userId = StpUserUtil.getLoginIdAsLong();
  38. List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  39. SearchResult<UserSysMsgNotify> search = beanSearcher.search(UserSysMsgNotify.class, MapUtils.flatBuilder(request.getParameterMap()).field(UserSysMsgNotify::getUserId, userIdList).op(Operator.InList).field(UserSysMsgNotify::getDeleted, 1).orderBy(UserSysMsgNotify::getIsView).orderBy(UserSysMsgNotify::getCreatedTime).desc().onlySelect(UserSysMsgNotify::getId, UserSysMsgNotify::getAccount, UserSysMsgNotify::getRelationId, UserSysMsgNotify::getMsg, UserSysMsgNotify::getIsView).build());
  40. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  41. }
  42. /**
  43. * 查看消息
  44. */
  45. @GetMapping("/view/detail/{id}")
  46. public Result viewMsgDetail(@PathVariable Long id) {
  47. long userId = StpUserUtil.getLoginIdAsLong();
  48. List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  49. Optional.ofNullable(userSysMsgNotifyMapper.selectOne(Wrappers.lambdaQuery(UserSysMsgNotify.class).eq(UserSysMsgNotify::getId, id).in(UserSysMsgNotify::getUserId, userIdList).eq(UserSysMsgNotify::getDeleted, 1))).ifPresent(e -> {
  50. if (!e.getIsView()) {
  51. e.setIsView(false);
  52. userSysMsgNotifyMapper.updateById(e);
  53. }
  54. });
  55. return GatewayResponse.SUCCESS.newBuilder().toResult();
  56. }
  57. /**
  58. * 删除消息
  59. */
  60. @DeleteMapping("/del/{id}")
  61. public Result delMsg(@PathVariable Long id) {
  62. long userId = StpUserUtil.getLoginIdAsLong();
  63. List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  64. Optional.ofNullable(userSysMsgNotifyMapper.selectOne(Wrappers.lambdaQuery(UserSysMsgNotify.class).eq(UserSysMsgNotify::getId, id).in(UserSysMsgNotify::getUserId, userIdList).eq(UserSysMsgNotify::getDeleted, 1))).ifPresent(e -> {
  65. e.setDeleted(false);
  66. userSysMsgNotifyMapper.updateById(e);
  67. });
  68. return GatewayResponse.SUCCESS.newBuilder().toResult();
  69. }
  70. }