From e8aa739860a9e01b9bf63a55ffae37ee92df4c44 Mon Sep 17 00:00:00 2001 From: Charles7c Date: Sat, 5 Apr 2025 22:42:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E4=B8=AA=E4=BA=BA?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E6=8E=A5=E5=8F=A3=EF=BC=8C=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E4=BF=A1=E6=81=AF=E6=8E=A5=E5=8F=A3=E5=9C=B0?= =?UTF-8?q?=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/system/mapper/NoticeMapper.java | 13 ++++ .../admin/system/model/query/NoticeQuery.java | 7 ++ .../service/impl/NoticeServiceImpl.java | 15 +++- .../main/resources/mapper/NoticeMapper.xml | 24 +++++++ .../system/UserMessageController.java | 71 +++++++++++++++++++ ...roller.java => UserProfileController.java} | 10 +-- 6 files changed, 135 insertions(+), 5 deletions(-) create mode 100644 continew-webapi/src/main/java/top/continew/admin/controller/system/UserMessageController.java rename continew-webapi/src/main/java/top/continew/admin/controller/system/{UserCenterController.java => UserProfileController.java} (97%) diff --git a/continew-module-system/src/main/java/top/continew/admin/system/mapper/NoticeMapper.java b/continew-module-system/src/main/java/top/continew/admin/system/mapper/NoticeMapper.java index 71b37bd5..71aea2f9 100644 --- a/continew-module-system/src/main/java/top/continew/admin/system/mapper/NoticeMapper.java +++ b/continew-module-system/src/main/java/top/continew/admin/system/mapper/NoticeMapper.java @@ -16,8 +16,12 @@ package top.continew.admin.system.mapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.apache.ibatis.annotations.Param; import top.continew.admin.system.model.entity.NoticeDO; +import top.continew.admin.system.model.query.NoticeQuery; +import top.continew.admin.system.model.resp.NoticeDetailResp; import top.continew.admin.system.model.resp.dashboard.DashboardNoticeResp; import top.continew.starter.data.mp.base.BaseMapper; @@ -38,4 +42,13 @@ public interface NoticeMapper extends BaseMapper { * @return 仪表盘公告列表 */ List selectDashboardList(@Param("userId") Long userId); + + /** + * 分页查询公告列表 + * + * @param page 分页条件 + * @param query 查询条件 + * @return 公告列表 + */ + IPage selectNoticePage(@Param("page") Page page, @Param("query") NoticeQuery query); } \ No newline at end of file diff --git a/continew-module-system/src/main/java/top/continew/admin/system/model/query/NoticeQuery.java b/continew-module-system/src/main/java/top/continew/admin/system/model/query/NoticeQuery.java index 7336c290..1b0432cc 100644 --- a/continew-module-system/src/main/java/top/continew/admin/system/model/query/NoticeQuery.java +++ b/continew-module-system/src/main/java/top/continew/admin/system/model/query/NoticeQuery.java @@ -16,6 +16,7 @@ package top.continew.admin.system.model.query; +import com.fasterxml.jackson.annotation.JsonIgnore; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import top.continew.starter.data.core.annotation.Query; @@ -49,4 +50,10 @@ public class NoticeQuery implements Serializable { */ @Schema(description = "类型", example = "1") private String type; + + /** + * 用户 ID + */ + @JsonIgnore + private Long userId; } \ No newline at end of file diff --git a/continew-module-system/src/main/java/top/continew/admin/system/service/impl/NoticeServiceImpl.java b/continew-module-system/src/main/java/top/continew/admin/system/service/impl/NoticeServiceImpl.java index 371e70f3..04475f6b 100644 --- a/continew-module-system/src/main/java/top/continew/admin/system/service/impl/NoticeServiceImpl.java +++ b/continew-module-system/src/main/java/top/continew/admin/system/service/impl/NoticeServiceImpl.java @@ -16,6 +16,8 @@ package top.continew.admin.system.service.impl; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import top.continew.admin.common.context.UserContextHolder; @@ -27,6 +29,8 @@ import top.continew.admin.system.model.resp.NoticeDetailResp; import top.continew.admin.system.model.resp.NoticeResp; import top.continew.admin.system.model.resp.dashboard.DashboardNoticeResp; import top.continew.admin.system.service.NoticeService; +import top.continew.starter.extension.crud.model.query.PageQuery; +import top.continew.starter.extension.crud.model.resp.PageResp; import top.continew.starter.extension.crud.service.BaseServiceImpl; import java.util.List; @@ -41,9 +45,18 @@ import java.util.List; @RequiredArgsConstructor public class NoticeServiceImpl extends BaseServiceImpl implements NoticeService { + @Override + public PageResp page(NoticeQuery query, PageQuery pageQuery) { + IPage page = baseMapper.selectNoticePage(new Page<>(pageQuery.getPage(), pageQuery + .getSize()), query); + PageResp pageResp = PageResp.build(page, super.getListClass()); + pageResp.getList().forEach(this::fill); + return pageResp; + } + @Override public List listDashboard() { - Long userId = UserContextHolder.isAdmin() ? null : UserContextHolder.getUserId(); + Long userId = UserContextHolder.getUserId(); return baseMapper.selectDashboardList(userId); } } \ No newline at end of file diff --git a/continew-module-system/src/main/resources/mapper/NoticeMapper.xml b/continew-module-system/src/main/resources/mapper/NoticeMapper.xml index 89de4842..71fb2e80 100644 --- a/continew-module-system/src/main/resources/mapper/NoticeMapper.xml +++ b/continew-module-system/src/main/resources/mapper/NoticeMapper.xml @@ -15,4 +15,28 @@ ORDER BY sort ASC, effective_time DESC LIMIT 5 + + \ No newline at end of file diff --git a/continew-webapi/src/main/java/top/continew/admin/controller/system/UserMessageController.java b/continew-webapi/src/main/java/top/continew/admin/controller/system/UserMessageController.java new file mode 100644 index 00000000..f56a320f --- /dev/null +++ b/continew-webapi/src/main/java/top/continew/admin/controller/system/UserMessageController.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package top.continew.admin.controller.system; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import top.continew.admin.common.context.UserContextHolder; +import top.continew.admin.system.enums.NoticeScopeEnum; +import top.continew.admin.system.model.query.NoticeQuery; +import top.continew.admin.system.model.resp.NoticeDetailResp; +import top.continew.admin.system.model.resp.NoticeResp; +import top.continew.admin.system.service.NoticeService; +import top.continew.starter.core.validation.CheckUtils; +import top.continew.starter.extension.crud.model.query.PageQuery; +import top.continew.starter.extension.crud.model.resp.BasePageResp; + +/** + * 个人消息 API + * + * @author Charles7c + * @since 2025/4/5 21:30 + */ +@Tag(name = "个人消息 API") +@Validated +@RestController +@RequiredArgsConstructor +@RequestMapping("/user/message") +public class UserMessageController { + + private final NoticeService noticeService; + + @Operation(summary = "分页查询公告列表", description = "分页查询公告列表") + @GetMapping("/notice") + public BasePageResp pageNotice(@Validated NoticeQuery query, @Validated PageQuery pageQuery) { + query.setUserId(UserContextHolder.getUserId()); + return noticeService.page(query, pageQuery); + } + + @Operation(summary = "查询公告详情", description = "查询公告") + @Parameter(name = "id", description = "ID", example = "1", in = ParameterIn.PATH) + @GetMapping("/notice/{id}") + public NoticeDetailResp getNotice(@PathVariable Long id) { + NoticeDetailResp detail = noticeService.get(id); + CheckUtils.throwIf(detail == null || (NoticeScopeEnum.USER.equals(detail.getNoticeScope()) && !detail + .getNoticeUsers() + .contains(UserContextHolder.getUserId().toString())), "公告不存在或无权限访问"); + return detail; + } +} diff --git a/continew-webapi/src/main/java/top/continew/admin/controller/system/UserCenterController.java b/continew-webapi/src/main/java/top/continew/admin/controller/system/UserProfileController.java similarity index 97% rename from continew-webapi/src/main/java/top/continew/admin/controller/system/UserCenterController.java rename to continew-webapi/src/main/java/top/continew/admin/controller/system/UserProfileController.java index 8135a0eb..77856123 100644 --- a/continew-webapi/src/main/java/top/continew/admin/controller/system/UserCenterController.java +++ b/continew-webapi/src/main/java/top/continew/admin/controller/system/UserProfileController.java @@ -41,6 +41,7 @@ import top.continew.admin.system.model.req.user.UserPasswordUpdateReq; import top.continew.admin.system.model.req.user.UserPhoneUpdateReq; import top.continew.admin.system.model.resp.AvatarResp; import top.continew.admin.system.model.resp.user.UserSocialBindResp; +import top.continew.admin.system.service.NoticeService; import top.continew.admin.system.service.UserService; import top.continew.admin.system.service.UserSocialService; import top.continew.starter.cache.redisson.util.RedisUtils; @@ -51,22 +52,23 @@ import java.io.IOException; import java.util.List; /** - * 个人中心 API + * 个人信息 API * * @author Charles7c * @since 2023/1/2 11:41 */ -@Tag(name = "个人中心 API") +@Tag(name = "个人信息 API") @Validated @RestController @RequiredArgsConstructor -@RequestMapping("/system/user") -public class UserCenterController { +@RequestMapping("/user/profile") +public class UserProfileController { private static final String DECRYPT_FAILED = "当前密码解密失败"; private static final String CAPTCHA_EXPIRED = "验证码已失效"; private final UserService userService; private final UserSocialService userSocialService; + private final NoticeService noticeService; private final AuthRequestFactory authRequestFactory; @Operation(summary = "修改头像", description = "用户修改个人头像")