| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.common.constant.HttpStatus; |
| | | import com.ruoyi.common.core.domain.BasePage; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | |
| | | @GetMapping("/getUserMessage") |
| | | public R<Page<TbMessage>> getUserMessage(UserMessageQuery query) { |
| | | LoginUser loginUser = tokenService.getLoginUser(); |
| | | if(loginUser==null){ |
| | | return R.fail(HttpStatus.UNAUTHORIZED,"请重新登录"); |
| | | } |
| | | Long userId = loginUser.getUserId(); |
| | | Page<TbMessage> page = messageService.page(new Page<>(query.getPageNum(), query.getPageSize()), new LambdaQueryWrapper<TbMessage>().eq(query.getIsRead()!=null, TbMessage::getIsRead, query.getIsRead()).eq(TbMessage::getUserId, userId).orderByDesc(TbMessage::getCreateTime)); |
| | | page.getRecords().forEach(item -> { |
| | |
| | | return R.ok(page); |
| | | } |
| | | |
| | | @ApiOperation(value = "获取用户消息未读",tags = {"消息模块"}) |
| | | @GetMapping("/getUserMessageNum") |
| | | public R<?> getUserMessageNum() { |
| | | LoginUser loginUser = tokenService.getLoginUser(); |
| | | if(loginUser==null){ |
| | | return R.fail(HttpStatus.UNAUTHORIZED,"请重新登录"); |
| | | } |
| | | Long userId = loginUser.getUserId(); |
| | | long count = messageService.count(new LambdaQueryWrapper<TbMessage>().eq(TbMessage::getIsRead, 0).eq(TbMessage::getUserId, userId)); |
| | | return R.ok(count); |
| | | } |
| | | |
| | | @ApiOperation(value = "消息已读",tags = {"消息模块"}) |
| | | @PostMapping("/readMessage") |
| | | public R<?> readMessage(String id) { |
| | | LoginUser loginUser = tokenService.getLoginUser(); |
| | | if(loginUser==null){ |
| | | return R.fail(HttpStatus.UNAUTHORIZED,"请重新登录"); |
| | | } |
| | | Long userId = loginUser.getUserId(); |
| | | TbMessage message = messageService.getById(id); |
| | | if(!message.getUserId().equals(userId.toString())){ |
| | |
| | | @GetMapping("/accountCancellation") |
| | | public R<?> accountCancellation() { |
| | | LoginUser loginUser = tokenService.getLoginUser(); |
| | | if(loginUser==null){ |
| | | return R.fail(HttpStatus.UNAUTHORIZED,"请重新登录"); |
| | | } |
| | | Long userId = loginUser.getUserId(); |
| | | TbUser user = userService.getById(userId); |
| | | user.setStatus(3); |