From 29202aea307a7257c9d1e9649dee00140164c59c Mon Sep 17 00:00:00 2001 From: kiki1373639299 Date: Wed, 23 Oct 2024 16:16:14 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=85=AC=E5=91=8A=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E9=80=9A=E7=9F=A5=E8=8C=83=E5=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/system/mapper/NoticeMapper.java | 3 +- .../admin/system/model/entity/NoticeDO.java | 16 ++++++++++- .../admin/system/model/query/UserQuery.java | 6 ++++ .../admin/system/model/req/NoticeReq.java | 15 ++++++++++ .../system/model/resp/NoticeDetailResp.java | 13 +++++++++ .../admin/system/model/resp/NoticeResp.java | 14 ++++++++++ .../service/impl/NoticeServiceImpl.java | 4 ++- .../system/service/impl/UserServiceImpl.java | 10 ++++++- .../main/resources/mapper/NoticeMapper.xml | 28 +++++++++++++++---- .../controller/system/UserController.java | 7 +++++ .../db/changelog/db.changelog-master.yaml | 2 ++ .../mysql/continew-admin_change_v3.4.0.sql | 6 ++++ 12 files changed, 114 insertions(+), 10 deletions(-) create mode 100644 continew-admin-webapi/src/main/resources/db/changelog/mysql/continew-admin_change_v3.4.0.sql diff --git a/continew-admin-system/src/main/java/top/continew/admin/system/mapper/NoticeMapper.java b/continew-admin-system/src/main/java/top/continew/admin/system/mapper/NoticeMapper.java index 56ccfe64..aba45474 100644 --- a/continew-admin-system/src/main/java/top/continew/admin/system/mapper/NoticeMapper.java +++ b/continew-admin-system/src/main/java/top/continew/admin/system/mapper/NoticeMapper.java @@ -16,6 +16,7 @@ package top.continew.admin.system.mapper; +import org.apache.ibatis.annotations.Param; import top.continew.admin.system.model.entity.NoticeDO; import top.continew.admin.system.model.resp.dashboard.DashboardNoticeResp; import top.continew.starter.data.mp.base.BaseMapper; @@ -35,5 +36,5 @@ public interface NoticeMapper extends BaseMapper { * * @return 仪表盘公告列表 */ - List selectDashboardList(); + List selectDashboardList(@Param("userId") Long userId); } \ No newline at end of file diff --git a/continew-admin-system/src/main/java/top/continew/admin/system/model/entity/NoticeDO.java b/continew-admin-system/src/main/java/top/continew/admin/system/model/entity/NoticeDO.java index 7758dfed..880dceef 100644 --- a/continew-admin-system/src/main/java/top/continew/admin/system/model/entity/NoticeDO.java +++ b/continew-admin-system/src/main/java/top/continew/admin/system/model/entity/NoticeDO.java @@ -16,12 +16,15 @@ package top.continew.admin.system.model.entity; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; import lombok.Data; import top.continew.starter.extension.crud.model.entity.BaseDO; import java.io.Serial; import java.time.LocalDateTime; +import java.util.List; /** * 公告实体 @@ -30,7 +33,7 @@ import java.time.LocalDateTime; * @since 2023/8/20 10:55 */ @Data -@TableName("sys_notice") +@TableName(value = "sys_notice",autoResultMap = true) public class NoticeDO extends BaseDO { @Serial @@ -60,4 +63,15 @@ public class NoticeDO extends BaseDO { * 终止时间 */ private LocalDateTime terminateTime; + + /** + * 通知范围 + */ + private Integer noticeScope; + + /** + * 通知用户 + */ + @TableField(typeHandler = JacksonTypeHandler.class) + private List noticeUsers; } \ No newline at end of file diff --git a/continew-admin-system/src/main/java/top/continew/admin/system/model/query/UserQuery.java b/continew-admin-system/src/main/java/top/continew/admin/system/model/query/UserQuery.java index f3ae415a..0f3dfdb4 100644 --- a/continew-admin-system/src/main/java/top/continew/admin/system/model/query/UserQuery.java +++ b/continew-admin-system/src/main/java/top/continew/admin/system/model/query/UserQuery.java @@ -66,4 +66,10 @@ public class UserQuery implements Serializable { */ @Schema(description = "部门 ID", example = "1") private Long deptId; + + /** + * 用户 IDS + */ + @Schema(description = "用户 ID数组",example = "[1,2,3]") + private List userIds; } diff --git a/continew-admin-system/src/main/java/top/continew/admin/system/model/req/NoticeReq.java b/continew-admin-system/src/main/java/top/continew/admin/system/model/req/NoticeReq.java index 5daadb3a..8e548d82 100644 --- a/continew-admin-system/src/main/java/top/continew/admin/system/model/req/NoticeReq.java +++ b/continew-admin-system/src/main/java/top/continew/admin/system/model/req/NoticeReq.java @@ -19,12 +19,14 @@ package top.continew.admin.system.model.req; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.Future; import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; import lombok.Data; import org.hibernate.validator.constraints.Length; import top.continew.starter.extension.crud.model.req.BaseReq; import java.io.Serial; import java.time.LocalDateTime; +import java.util.List; /** * 创建或修改公告信息 @@ -74,4 +76,17 @@ public class NoticeReq extends BaseReq { @Schema(description = "终止时间", example = "2023-08-08 23:59:59", type = "string") @Future(message = "终止时间必须是未来时间") private LocalDateTime terminateTime; + + /** + * 通知范围 + */ + @Schema(description = "通知范围(1.所有人 2.指定用户)",example = "1") + @NotNull(message = "通知范围不能为空") + private Integer noticeScope; + + /** + * 指定用户 + */ + @Schema(description = "指定用户",example = "[1,2,3]") + private List noticeUsers; } \ No newline at end of file diff --git a/continew-admin-system/src/main/java/top/continew/admin/system/model/resp/NoticeDetailResp.java b/continew-admin-system/src/main/java/top/continew/admin/system/model/resp/NoticeDetailResp.java index d61d62b2..60876fb7 100644 --- a/continew-admin-system/src/main/java/top/continew/admin/system/model/resp/NoticeDetailResp.java +++ b/continew-admin-system/src/main/java/top/continew/admin/system/model/resp/NoticeDetailResp.java @@ -24,6 +24,7 @@ import top.continew.starter.extension.crud.model.resp.BaseDetailResp; import java.io.Serial; import java.time.LocalDateTime; +import java.util.List; /** * 公告详情信息 @@ -73,4 +74,16 @@ public class NoticeDetailResp extends BaseDetailResp { @Schema(description = "终止时间", example = "2023-08-08 23:59:59", type = "string") @ExcelProperty(value = "终止时间") private LocalDateTime terminateTime; + + /** + * 通知范围 + */ + @Schema(description = "通知范围(1.所有人 2.指定用户)",example = "1") + private Integer noticeScope; + + /** + * 指定用户 + */ + @Schema(description = "指定用户",example = "[1,2,3]") + private List noticeUsers; } \ No newline at end of file diff --git a/continew-admin-system/src/main/java/top/continew/admin/system/model/resp/NoticeResp.java b/continew-admin-system/src/main/java/top/continew/admin/system/model/resp/NoticeResp.java index 9bc8fe3d..86568e64 100644 --- a/continew-admin-system/src/main/java/top/continew/admin/system/model/resp/NoticeResp.java +++ b/continew-admin-system/src/main/java/top/continew/admin/system/model/resp/NoticeResp.java @@ -23,6 +23,7 @@ import top.continew.starter.extension.crud.model.resp.BaseResp; import java.io.Serial; import java.time.LocalDateTime; +import java.util.List; /** * 公告信息 @@ -70,4 +71,17 @@ public class NoticeResp extends BaseResp { public NoticeStatusEnum getStatus() { return NoticeStatusEnum.getStatus(effectiveTime, terminateTime); } + + + /** + * 通知范围 + */ + @Schema(description = "通知范围(1.所有人 2.指定用户)",example = "1") + private Integer noticeScope; + + /** + * 指定用户 + */ + @Schema(description = "指定用户",example = "[1,2,3]") + private List noticeUsers; } \ No newline at end of file diff --git a/continew-admin-system/src/main/java/top/continew/admin/system/service/impl/NoticeServiceImpl.java b/continew-admin-system/src/main/java/top/continew/admin/system/service/impl/NoticeServiceImpl.java index daab9cde..b60bcca6 100644 --- a/continew-admin-system/src/main/java/top/continew/admin/system/service/impl/NoticeServiceImpl.java +++ b/continew-admin-system/src/main/java/top/continew/admin/system/service/impl/NoticeServiceImpl.java @@ -18,6 +18,7 @@ package top.continew.admin.system.service.impl; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import top.continew.admin.common.context.UserContextHolder; import top.continew.admin.system.mapper.NoticeMapper; import top.continew.admin.system.model.entity.NoticeDO; import top.continew.admin.system.model.query.NoticeQuery; @@ -42,6 +43,7 @@ public class NoticeServiceImpl extends BaseServiceImpl listDashboard() { - return baseMapper.selectDashboardList(); + Long userId = UserContextHolder.isAdmin()? null: UserContextHolder.getUserId(); + return baseMapper.selectDashboardList(userId); } } \ No newline at end of file diff --git a/continew-admin-system/src/main/java/top/continew/admin/system/service/impl/UserServiceImpl.java b/continew-admin-system/src/main/java/top/continew/admin/system/service/impl/UserServiceImpl.java index 814d2ff8..6439dbc6 100644 --- a/continew-admin-system/src/main/java/top/continew/admin/system/service/impl/UserServiceImpl.java +++ b/continew-admin-system/src/main/java/top/continew/admin/system/service/impl/UserServiceImpl.java @@ -126,6 +126,13 @@ 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 Long add(UserDO user) { user.setStatus(DisEnableStatusEnum.ENABLE); @@ -488,6 +495,7 @@ public class UserServiceImpl extends BaseServiceImpl createTimeList = query.getCreateTime(); Long deptId = query.getDeptId(); + List userIdList = query.getUserIds(); return new QueryWrapper().and(StrUtil.isNotBlank(description), q -> q.like("t1.username", description) .or() .like("t1.nickname", description) @@ -503,7 +511,7 @@ public class UserServiceImpl extends BaseServiceImpl SELECT - id, title, type - FROM sys_notice - WHERE (effective_time IS NULL OR NOW() > effective_time) - AND (terminate_time IS NULL OR terminate_time > NOW()) - ORDER BY sort ASC, effective_time DESC - LIMIT 5 + id, + title, + type + FROM + sys_notice + WHERE + ( effective_time IS NULL OR NOW() > effective_time ) + AND ( + terminate_time IS NULL + OR terminate_time > NOW()) + + AND ( notice_scope = 1 + OR ( + notice_scope = 2 AND + + JSON_EXTRACT(notice_users, "$[0]") = CAST(#{userId} AS CHAR) + )) + + ORDER BY + sort ASC, + effective_time DESC + LIMIT 5; \ No newline at end of file diff --git a/continew-admin-webapi/src/main/java/top/continew/admin/controller/system/UserController.java b/continew-admin-webapi/src/main/java/top/continew/admin/controller/system/UserController.java index b5a0229e..3710342c 100644 --- a/continew-admin-webapi/src/main/java/top/continew/admin/controller/system/UserController.java +++ b/continew-admin-webapi/src/main/java/top/continew/admin/controller/system/UserController.java @@ -43,10 +43,12 @@ 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,6 +65,11 @@ public class UserController extends BaseController 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())); diff --git a/continew-admin-webapi/src/main/resources/db/changelog/db.changelog-master.yaml b/continew-admin-webapi/src/main/resources/db/changelog/db.changelog-master.yaml index 5a9f7bed..b529bf6c 100644 --- a/continew-admin-webapi/src/main/resources/db/changelog/db.changelog-master.yaml +++ b/continew-admin-webapi/src/main/resources/db/changelog/db.changelog-master.yaml @@ -5,6 +5,8 @@ databaseChangeLog: file: db/changelog/mysql/continew-admin_column.sql - include: file: db/changelog/mysql/continew-admin_data.sql + - include: + file: db/changelog/mysql/continew-admin_change_v3.4.0.sql # PostgreSQL # - include: # file: db/changelog/postgresql/continew-admin_table.sql diff --git a/continew-admin-webapi/src/main/resources/db/changelog/mysql/continew-admin_change_v3.4.0.sql b/continew-admin-webapi/src/main/resources/db/changelog/mysql/continew-admin_change_v3.4.0.sql new file mode 100644 index 00000000..96903ff4 --- /dev/null +++ b/continew-admin-webapi/src/main/resources/db/changelog/mysql/continew-admin_change_v3.4.0.sql @@ -0,0 +1,6 @@ +-- 消息通知表 新增通知范围 和 通知用户两个字段 +START TRANSACTION; +ALTER TABLE sys_notice + ADD COLUMN notice_scope INT NOT NULL COMMENT '通知范围' AFTER terminate_time, + ADD COLUMN notice_users JSON DEFAULT NULL COMMENT '通知用户' AFTER notice_scope; +COMMIT;