|
@@ -1,9 +1,117 @@
|
|
|
package com.txz.mall.controller.appcontroller;
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.txz.mall.core.AuthService;
|
|
|
+import com.txz.mall.core.Result;
|
|
|
+import com.txz.mall.enums.NoticeGroupEnum;
|
|
|
+import com.txz.mall.model.Notice;
|
|
|
+import com.txz.mall.service.NoticeService;
|
|
|
+import com.txz.mall.web.param.BasePageParam;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
/**
|
|
|
+ * app端通知
|
|
|
+ *
|
|
|
* @author: MTD®️
|
|
|
* @date: 2025/8/26
|
|
|
*/
|
|
|
-
|
|
|
+@RestController
|
|
|
+@RequiredArgsConstructor
|
|
|
+@RequestMapping("app/notice")
|
|
|
public class AppNoticeController {
|
|
|
+
|
|
|
+ private final NoticeService noticeService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取未读条数
|
|
|
+ */
|
|
|
+ @GetMapping("unread")
|
|
|
+ public Result unread() {
|
|
|
+ return Result.success(noticeService.count(Wrappers.<Notice>lambdaQuery()
|
|
|
+ .eq(Notice::getUid, AuthService.getTokenUserId(null))
|
|
|
+ .eq(Notice::getUserDel, Boolean.FALSE)
|
|
|
+ .eq(Notice::getReadFlag, Boolean.FALSE)
|
|
|
+ )
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取消息分页
|
|
|
+ */
|
|
|
+ @GetMapping("page")
|
|
|
+ public Result page(NoticeGroupEnum type, BasePageParam page) {
|
|
|
+ Page queryPage = new Page(page.getPage(), page.getSize());
|
|
|
+ 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)
|
|
|
+ )
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 已读
|
|
|
+ */
|
|
|
+ @PatchMapping("read/{id:^\\d+$}")
|
|
|
+ public Result read(@PathVariable("id") Long id) {
|
|
|
+ Notice readInfo = noticeService.getOne(Wrappers.<Notice>lambdaQuery()
|
|
|
+ .eq(Notice::getId, id)
|
|
|
+ .eq(Notice::getUid, AuthService.getTokenUserId(null))
|
|
|
+ .eq(Notice::getUserDel, Boolean.FALSE)
|
|
|
+ .eq(Notice::getReadFlag, Boolean.FALSE)
|
|
|
+ );
|
|
|
+ if (ObjectUtil.isNotEmpty(readInfo)) {
|
|
|
+ readInfo.setReadFlag(Boolean.TRUE);
|
|
|
+ noticeService.updateById(readInfo);
|
|
|
+ }
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 一键已读
|
|
|
+ */
|
|
|
+ @PatchMapping("readAll")
|
|
|
+ public Result readAll(NoticeGroupEnum type) {
|
|
|
+ noticeService.update(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())
|
|
|
+ );
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除消息
|
|
|
+ */
|
|
|
+ @DeleteMapping("delete/{id:^\\d+$}")
|
|
|
+ public Result delete(@PathVariable("id") Long id) {
|
|
|
+ noticeService.update(Wrappers.<Notice>lambdaUpdate()
|
|
|
+ .eq(Notice::getId, id)
|
|
|
+ .eq(Notice::getUid, AuthService.getTokenUserId(null))
|
|
|
+ .set(Notice::getUserDel, Boolean.TRUE)
|
|
|
+ .set(Notice::getReadFlag, Boolean.TRUE)
|
|
|
+ );
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 一键删除消息
|
|
|
+ */
|
|
|
+ @DeleteMapping("delete")
|
|
|
+ public Result delete(NoticeGroupEnum type) {
|
|
|
+ noticeService.update(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)
|
|
|
+ );
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
}
|