|
@@ -1,6 +1,8 @@
|
|
|
package com.txz.mall.controller.appcontroller;
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.txz.mall.core.AuthService;
|
|
@@ -30,8 +32,14 @@ public class AppNoticeController {
|
|
|
*/
|
|
|
@GetMapping("unread")
|
|
|
public Result unread() {
|
|
|
+ Long userId;
|
|
|
+ try {
|
|
|
+ userId = AuthService.getTokenUserId(null);
|
|
|
+ } catch (Exception e) {
|
|
|
+ return Result.success(0);
|
|
|
+ }
|
|
|
return Result.success(noticeService.count(Wrappers.<Notice>lambdaQuery()
|
|
|
- .eq(Notice::getUid, AuthService.getTokenUserId(null))
|
|
|
+ .eq(Notice::getUid, userId)
|
|
|
.eq(Notice::getUserDel, Boolean.FALSE)
|
|
|
.eq(Notice::getReadFlag, Boolean.FALSE)
|
|
|
)
|
|
@@ -44,12 +52,15 @@ public class AppNoticeController {
|
|
|
@GetMapping("page")
|
|
|
public Result<Page<Notice>> page(NoticeGroupEnum type, BasePageParam page) {
|
|
|
Page queryPage = new Page(page.getPage(), page.getSize());
|
|
|
+ LambdaQueryWrapper<Notice> eq = Wrappers.<Notice>lambdaQuery()
|
|
|
+ // .likeRight(ObjectUtil.isNotEmpty(type), Notice::getNoticeType, type.getData())
|
|
|
+ .eq(Notice::getUid, AuthService.getTokenUserId(null))
|
|
|
+ .eq(Notice::getUserDel, Boolean.FALSE);
|
|
|
+ if (ObjectUtil.isNotEmpty(type)) {
|
|
|
+ eq.likeRight(Notice::getNoticeType, type.getData());
|
|
|
+ }
|
|
|
return Result.success(
|
|
|
- noticeService.page(queryPage, Wrappers.<Notice>lambdaQuery()
|
|
|
- .likeRight(ObjectUtil.isNotEmpty(type), Notice::getNoticeType, type.getData())
|
|
|
- .eq(Notice::getUid, AuthService.getTokenUserId(null))
|
|
|
- .eq(Notice::getUserDel, Boolean.FALSE)
|
|
|
- )
|
|
|
+ noticeService.page(queryPage, eq)
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -76,13 +87,16 @@ public class AppNoticeController {
|
|
|
*/
|
|
|
@PatchMapping("readAll")
|
|
|
public Result readAll(NoticeGroupEnum type) {
|
|
|
- noticeService.update(Wrappers.<Notice>lambdaUpdate()
|
|
|
+ LambdaUpdateWrapper<Notice> updateWrapper = Wrappers.<Notice>lambdaUpdate()
|
|
|
.eq(Notice::getUid, AuthService.getTokenUserId(null))
|
|
|
.eq(Notice::getUserDel, Boolean.FALSE)
|
|
|
.eq(Notice::getReadFlag, Boolean.FALSE)
|
|
|
- .set(Notice::getReadFlag, Boolean.TRUE)
|
|
|
- .likeRight(ObjectUtil.isNotEmpty(type), Notice::getNoticeType, type.getData())
|
|
|
- );
|
|
|
+ .set(Notice::getReadFlag, Boolean.TRUE);
|
|
|
+ // .likeRight(ObjectUtil.isNotEmpty(type), Notice::getNoticeType, type.getData());
|
|
|
+ if (ObjectUtil.isNotEmpty(type)) {
|
|
|
+ updateWrapper.likeRight(Notice::getNoticeType, type.getData());
|
|
|
+ }
|
|
|
+ noticeService.update(updateWrapper);
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
@@ -105,12 +119,15 @@ public class AppNoticeController {
|
|
|
*/
|
|
|
@DeleteMapping("delete")
|
|
|
public Result delete(NoticeGroupEnum type) {
|
|
|
- noticeService.update(Wrappers.<Notice>lambdaUpdate()
|
|
|
- .likeRight(ObjectUtil.isNotEmpty(type), Notice::getNoticeType, type.getData())
|
|
|
+ LambdaUpdateWrapper<Notice> updateWrapper = Wrappers.<Notice>lambdaUpdate()
|
|
|
+ // .likeRight(ObjectUtil.isNotEmpty(type), Notice::getNoticeType, type.getData())
|
|
|
.eq(Notice::getUid, AuthService.getTokenUserId(null))
|
|
|
.set(Notice::getUserDel, Boolean.TRUE)
|
|
|
- .set(Notice::getReadFlag, Boolean.TRUE)
|
|
|
- );
|
|
|
+ .set(Notice::getReadFlag, Boolean.TRUE);
|
|
|
+ if (ObjectUtil.isNotEmpty(type)) {
|
|
|
+ updateWrapper.likeRight(Notice::getNoticeType, type.getData());
|
|
|
+ }
|
|
|
+ noticeService.update(updateWrapper);
|
|
|
return Result.success();
|
|
|
}
|
|
|
|