From e1941eca455a066dae631b1533d63f8d9a193161 Mon Sep 17 00:00:00 2001 From: Charles7c Date: Tue, 5 Nov 2024 23:21:40 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E5=85=AC=E5=91=8A=E9=83=A8=E5=88=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/context/UserContextHolder.java | 2 +- .../admin/system/enums/NoticeScopeEnum.java | 45 +++++++++++++++++++ .../admin/system/mapper/NoticeMapper.java | 1 + .../admin/system/model/query/UserQuery.java | 4 +- .../admin/system/model/req/NoticeReq.java | 5 ++- .../system/model/resp/NoticeDetailResp.java | 5 ++- .../system/service/impl/UserServiceImpl.java | 7 --- .../main/resources/mapper/NoticeMapper.xml | 27 +++-------- .../controller/system/NoticeController.java | 14 ++++-- .../controller/system/UserController.java | 10 +---- 10 files changed, 74 insertions(+), 46 deletions(-) create mode 100644 continew-module-system/src/main/java/top/continew/admin/system/enums/NoticeScopeEnum.java diff --git a/continew-common/src/main/java/top/continew/admin/common/context/UserContextHolder.java b/continew-common/src/main/java/top/continew/admin/common/context/UserContextHolder.java index b9578fe9..d460d7ba 100644 --- a/continew-common/src/main/java/top/continew/admin/common/context/UserContextHolder.java +++ b/continew-common/src/main/java/top/continew/admin/common/context/UserContextHolder.java @@ -178,7 +178,7 @@ public class UserContextHolder { * * @return 是否为管理员 */ - public static Boolean isAdmin() { + public static boolean isAdmin() { StpUtil.checkLogin(); return getContext().isAdmin(); } diff --git a/continew-module-system/src/main/java/top/continew/admin/system/enums/NoticeScopeEnum.java b/continew-module-system/src/main/java/top/continew/admin/system/enums/NoticeScopeEnum.java new file mode 100644 index 00000000..9ab84fb8 --- /dev/null +++ b/continew-module-system/src/main/java/top/continew/admin/system/enums/NoticeScopeEnum.java @@ -0,0 +1,45 @@ +/* + * 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.system.enums; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import top.continew.starter.core.enums.BaseEnum; + +/** + * 公告通知范围枚举 + * + * @author Charles7c + * @since 2023/8/20 10:55 + */ +@Getter +@RequiredArgsConstructor +public enum NoticeScopeEnum implements BaseEnum { + + /** + * 所有人 + */ + ALL(1, "所有人"), + + /** + * 指定用户 + */ + USER(2, "指定用户"),; + + private final Integer value; + private final String description; +} 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 aba45474..71b37bd5 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 @@ -34,6 +34,7 @@ public interface NoticeMapper extends BaseMapper { /** * 查询仪表盘公告列表 * + * @param userId 用户 ID * @return 仪表盘公告列表 */ List selectDashboardList(@Param("userId") Long userId); diff --git a/continew-module-system/src/main/java/top/continew/admin/system/model/query/UserQuery.java b/continew-module-system/src/main/java/top/continew/admin/system/model/query/UserQuery.java index a5f2e2f6..c7ebb354 100644 --- a/continew-module-system/src/main/java/top/continew/admin/system/model/query/UserQuery.java +++ b/continew-module-system/src/main/java/top/continew/admin/system/model/query/UserQuery.java @@ -68,8 +68,8 @@ public class UserQuery implements Serializable { private Long deptId; /** - * 用户 IDS + * 用户 ID 列表 */ - @Schema(description = "用户 ID数组", example = "[1,2,3]") + @Schema(description = "用户 ID 列表", example = "[1,2,3]") private List userIds; } diff --git a/continew-module-system/src/main/java/top/continew/admin/system/model/req/NoticeReq.java b/continew-module-system/src/main/java/top/continew/admin/system/model/req/NoticeReq.java index d7fc3066..d5676547 100644 --- a/continew-module-system/src/main/java/top/continew/admin/system/model/req/NoticeReq.java +++ b/continew-module-system/src/main/java/top/continew/admin/system/model/req/NoticeReq.java @@ -22,6 +22,7 @@ import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; import lombok.Data; import org.hibernate.validator.constraints.Length; +import top.continew.admin.system.enums.NoticeScopeEnum; import top.continew.starter.extension.crud.model.req.BaseReq; import java.io.Serial; @@ -80,9 +81,9 @@ public class NoticeReq extends BaseReq { /** * 通知范围 */ - @Schema(description = "通知范围(1.所有人 2.指定用户)", example = "1") + @Schema(description = "通知范围", example = "2") @NotNull(message = "通知范围不能为空") - private Integer noticeScope; + private NoticeScopeEnum noticeScope; /** * 指定用户 diff --git a/continew-module-system/src/main/java/top/continew/admin/system/model/resp/NoticeDetailResp.java b/continew-module-system/src/main/java/top/continew/admin/system/model/resp/NoticeDetailResp.java index 218dd6fb..c01d35cb 100644 --- a/continew-module-system/src/main/java/top/continew/admin/system/model/resp/NoticeDetailResp.java +++ b/continew-module-system/src/main/java/top/continew/admin/system/model/resp/NoticeDetailResp.java @@ -20,6 +20,7 @@ import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; import com.alibaba.excel.annotation.ExcelProperty; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; +import top.continew.admin.system.enums.NoticeScopeEnum; import top.continew.starter.extension.crud.model.resp.BaseDetailResp; import java.io.Serial; @@ -78,8 +79,8 @@ public class NoticeDetailResp extends BaseDetailResp { /** * 通知范围 */ - @Schema(description = "通知范围(1.所有人 2.指定用户)", example = "1") - private Integer noticeScope; + @Schema(description = "通知范围", example = "2") + private NoticeScopeEnum noticeScope; /** * 指定用户 diff --git a/continew-module-system/src/main/java/top/continew/admin/system/service/impl/UserServiceImpl.java b/continew-module-system/src/main/java/top/continew/admin/system/service/impl/UserServiceImpl.java index 4d3693ee..ad8571ae 100644 --- a/continew-module-system/src/main/java/top/continew/admin/system/service/impl/UserServiceImpl.java +++ b/continew-module-system/src/main/java/top/continew/admin/system/service/impl/UserServiceImpl.java @@ -128,13 +128,6 @@ public class UserServiceImpl extends BaseServiceImpl list(UserQuery query, SortQuery sortQuery) { - QueryWrapper queryWrapper = this.buildQueryWrapper(query); - List entityList = baseMapper.selectUserList(queryWrapper); - return BeanUtil.copyToList(entityList, UserResp.class); - } - @Override public void beforeAdd(UserReq req) { final String errorMsgTemplate = "新增失败,[{}] 已存在"; diff --git a/continew-module-system/src/main/resources/mapper/NoticeMapper.xml b/continew-module-system/src/main/resources/mapper/NoticeMapper.xml index c25aa03c..89de4842 100644 --- a/continew-module-system/src/main/resources/mapper/NoticeMapper.xml +++ b/continew-module-system/src/main/resources/mapper/NoticeMapper.xml @@ -5,27 +5,14 @@ \ No newline at end of file diff --git a/continew-webapi/src/main/java/top/continew/admin/controller/system/NoticeController.java b/continew-webapi/src/main/java/top/continew/admin/controller/system/NoticeController.java index 45c38bde..f9e31735 100644 --- a/continew-webapi/src/main/java/top/continew/admin/controller/system/NoticeController.java +++ b/continew-webapi/src/main/java/top/continew/admin/controller/system/NoticeController.java @@ -21,6 +21,7 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; +import top.continew.admin.system.enums.NoticeScopeEnum; import top.continew.admin.system.model.query.NoticeQuery; import top.continew.admin.system.model.req.NoticeReq; import top.continew.admin.system.model.resp.NoticeDetailResp; @@ -48,26 +49,31 @@ public class NoticeController extends BaseController add(@Validated(ValidateGroup.Crud.Add.class) @RequestBody NoticeReq req) { - this.checkTime(req); + this.check(req); return super.add(req); } @Override public void update(@Validated(ValidateGroup.Crud.Update.class) @RequestBody NoticeReq req, @PathVariable Long id) { - this.checkTime(req); + this.check(req); super.update(req, id); } /** - * 检查时间 + * 校验 * * @param req 创建或修改信息 */ - private void checkTime(NoticeReq req) { + private void check(NoticeReq req) { + // 校验生效时间 LocalDateTime effectiveTime = req.getEffectiveTime(); LocalDateTime terminateTime = req.getTerminateTime(); if (null != effectiveTime && null != terminateTime) { ValidationUtils.throwIf(terminateTime.isBefore(effectiveTime), "终止时间必须晚于生效时间"); } + // 校验通知范围 + if (NoticeScopeEnum.USER.equals(req.getNoticeScope())) { + ValidationUtils.throwIfEmpty(req.getNoticeUsers(), "请选择通知用户"); + } } } \ No newline at end of file diff --git a/continew-webapi/src/main/java/top/continew/admin/controller/system/UserController.java b/continew-webapi/src/main/java/top/continew/admin/controller/system/UserController.java index ca71d7a1..903d2e5f 100644 --- a/continew-webapi/src/main/java/top/continew/admin/controller/system/UserController.java +++ b/continew-webapi/src/main/java/top/continew/admin/controller/system/UserController.java @@ -46,12 +46,10 @@ import top.continew.starter.core.util.validate.ValidationUtils; import top.continew.starter.extension.crud.annotation.CrudRequestMapping; import top.continew.starter.extension.crud.controller.BaseController; import top.continew.starter.extension.crud.enums.Api; -import top.continew.starter.extension.crud.model.query.SortQuery; import top.continew.starter.extension.crud.model.resp.BaseIdResp; import top.continew.starter.extension.crud.util.ValidateGroup; import java.io.IOException; -import java.util.List; /** * 用户管理 API @@ -63,16 +61,12 @@ import java.util.List; @Validated @RestController @RequiredArgsConstructor -@CrudRequestMapping(value = "/system/user", api = {Api.PAGE, Api.GET, Api.ADD, Api.UPDATE, Api.DELETE, Api.EXPORT}) +@CrudRequestMapping(value = "/system/user", api = {Api.PAGE, Api.LIST, Api.GET, Api.ADD, Api.UPDATE, Api.DELETE, + Api.EXPORT}) public class UserController extends BaseController { private final UserService userService; - @Override - public List list(UserQuery query, SortQuery sortQuery) { - return super.list(query, sortQuery); - } - @Override public BaseIdResp add(@Validated(ValidateGroup.Crud.Add.class) @RequestBody UserReq req) { String rawPassword = ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(req.getPassword()));