feat: 公告支持设置通知范围

This commit is contained in:
kiki1373639299
2024-10-23 16:16:14 +08:00
committed by Charles_7c
parent e01df09127
commit 29202aea30
12 changed files with 114 additions and 10 deletions

View File

@@ -16,6 +16,7 @@
package top.continew.admin.system.mapper; 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.entity.NoticeDO;
import top.continew.admin.system.model.resp.dashboard.DashboardNoticeResp; import top.continew.admin.system.model.resp.dashboard.DashboardNoticeResp;
import top.continew.starter.data.mp.base.BaseMapper; import top.continew.starter.data.mp.base.BaseMapper;
@@ -35,5 +36,5 @@ public interface NoticeMapper extends BaseMapper<NoticeDO> {
* *
* @return 仪表盘公告列表 * @return 仪表盘公告列表
*/ */
List<DashboardNoticeResp> selectDashboardList(); List<DashboardNoticeResp> selectDashboardList(@Param("userId") Long userId);
} }

View File

@@ -16,12 +16,15 @@
package top.continew.admin.system.model.entity; package top.continew.admin.system.model.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import lombok.Data; import lombok.Data;
import top.continew.starter.extension.crud.model.entity.BaseDO; import top.continew.starter.extension.crud.model.entity.BaseDO;
import java.io.Serial; import java.io.Serial;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List;
/** /**
* 公告实体 * 公告实体
@@ -30,7 +33,7 @@ import java.time.LocalDateTime;
* @since 2023/8/20 10:55 * @since 2023/8/20 10:55
*/ */
@Data @Data
@TableName("sys_notice") @TableName(value = "sys_notice",autoResultMap = true)
public class NoticeDO extends BaseDO { public class NoticeDO extends BaseDO {
@Serial @Serial
@@ -60,4 +63,15 @@ public class NoticeDO extends BaseDO {
* 终止时间 * 终止时间
*/ */
private LocalDateTime terminateTime; private LocalDateTime terminateTime;
/**
* 通知范围
*/
private Integer noticeScope;
/**
* 通知用户
*/
@TableField(typeHandler = JacksonTypeHandler.class)
private List<String> noticeUsers;
} }

View File

@@ -66,4 +66,10 @@ public class UserQuery implements Serializable {
*/ */
@Schema(description = "部门 ID", example = "1") @Schema(description = "部门 ID", example = "1")
private Long deptId; private Long deptId;
/**
* 用户 IDS
*/
@Schema(description = "用户 ID数组",example = "[1,2,3]")
private List<Long> userIds;
} }

View File

@@ -19,12 +19,14 @@ package top.continew.admin.system.model.req;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Future; import jakarta.validation.constraints.Future;
import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data; import lombok.Data;
import org.hibernate.validator.constraints.Length; import org.hibernate.validator.constraints.Length;
import top.continew.starter.extension.crud.model.req.BaseReq; import top.continew.starter.extension.crud.model.req.BaseReq;
import java.io.Serial; import java.io.Serial;
import java.time.LocalDateTime; 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") @Schema(description = "终止时间", example = "2023-08-08 23:59:59", type = "string")
@Future(message = "终止时间必须是未来时间") @Future(message = "终止时间必须是未来时间")
private LocalDateTime terminateTime; private LocalDateTime terminateTime;
/**
* 通知范围
*/
@Schema(description = "通知范围(1.所有人 2.指定用户)",example = "1")
@NotNull(message = "通知范围不能为空")
private Integer noticeScope;
/**
* 指定用户
*/
@Schema(description = "指定用户",example = "[1,2,3]")
private List<String> noticeUsers;
} }

View File

@@ -24,6 +24,7 @@ import top.continew.starter.extension.crud.model.resp.BaseDetailResp;
import java.io.Serial; import java.io.Serial;
import java.time.LocalDateTime; 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") @Schema(description = "终止时间", example = "2023-08-08 23:59:59", type = "string")
@ExcelProperty(value = "终止时间") @ExcelProperty(value = "终止时间")
private LocalDateTime terminateTime; private LocalDateTime terminateTime;
/**
* 通知范围
*/
@Schema(description = "通知范围(1.所有人 2.指定用户)",example = "1")
private Integer noticeScope;
/**
* 指定用户
*/
@Schema(description = "指定用户",example = "[1,2,3]")
private List<String> noticeUsers;
} }

View File

@@ -23,6 +23,7 @@ import top.continew.starter.extension.crud.model.resp.BaseResp;
import java.io.Serial; import java.io.Serial;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List;
/** /**
* 公告信息 * 公告信息
@@ -70,4 +71,17 @@ public class NoticeResp extends BaseResp {
public NoticeStatusEnum getStatus() { public NoticeStatusEnum getStatus() {
return NoticeStatusEnum.getStatus(effectiveTime, terminateTime); return NoticeStatusEnum.getStatus(effectiveTime, terminateTime);
} }
/**
* 通知范围
*/
@Schema(description = "通知范围(1.所有人 2.指定用户)",example = "1")
private Integer noticeScope;
/**
* 指定用户
*/
@Schema(description = "指定用户",example = "[1,2,3]")
private List<String> noticeUsers;
} }

View File

@@ -18,6 +18,7 @@ package top.continew.admin.system.service.impl;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import top.continew.admin.common.context.UserContextHolder;
import top.continew.admin.system.mapper.NoticeMapper; import top.continew.admin.system.mapper.NoticeMapper;
import top.continew.admin.system.model.entity.NoticeDO; import top.continew.admin.system.model.entity.NoticeDO;
import top.continew.admin.system.model.query.NoticeQuery; import top.continew.admin.system.model.query.NoticeQuery;
@@ -42,6 +43,7 @@ public class NoticeServiceImpl extends BaseServiceImpl<NoticeMapper, NoticeDO, N
@Override @Override
public List<DashboardNoticeResp> listDashboard() { public List<DashboardNoticeResp> listDashboard() {
return baseMapper.selectDashboardList(); Long userId = UserContextHolder.isAdmin()? null: UserContextHolder.getUserId();
return baseMapper.selectDashboardList(userId);
} }
} }

View File

@@ -126,6 +126,13 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserRes
return pageResp; return pageResp;
} }
@Override
public List<UserResp> list(UserQuery query, SortQuery sortQuery) {
QueryWrapper<UserDO> queryWrapper = this.buildQueryWrapper(query);
List<UserDetailResp> entityList = baseMapper.selectUserList(queryWrapper);
return BeanUtil.copyToList(entityList, UserResp.class);
}
@Override @Override
public Long add(UserDO user) { public Long add(UserDO user) {
user.setStatus(DisEnableStatusEnum.ENABLE); user.setStatus(DisEnableStatusEnum.ENABLE);
@@ -488,6 +495,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserRes
DisEnableStatusEnum status = query.getStatus(); DisEnableStatusEnum status = query.getStatus();
List<Date> createTimeList = query.getCreateTime(); List<Date> createTimeList = query.getCreateTime();
Long deptId = query.getDeptId(); Long deptId = query.getDeptId();
List<Long> userIdList = query.getUserIds();
return new QueryWrapper<UserDO>().and(StrUtil.isNotBlank(description), q -> q.like("t1.username", description) return new QueryWrapper<UserDO>().and(StrUtil.isNotBlank(description), q -> q.like("t1.username", description)
.or() .or()
.like("t1.nickname", description) .like("t1.nickname", description)
@@ -503,7 +511,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserRes
.collect(Collectors.toList()); .collect(Collectors.toList());
deptIdList.add(deptId); deptIdList.add(deptId);
q.in("t1.dept_id", deptIdList); q.in("t1.dept_id", deptIdList);
}); }).in(CollUtil.isNotEmpty(userIdList),"t1.id", userIdList);
} }
@Override @Override

View File

@@ -5,11 +5,27 @@
<select id="selectDashboardList" <select id="selectDashboardList"
resultType="top.continew.admin.system.model.resp.dashboard.DashboardNoticeResp"> resultType="top.continew.admin.system.model.resp.dashboard.DashboardNoticeResp">
SELECT SELECT
id, title, type id,
FROM sys_notice title,
WHERE (effective_time IS NULL OR NOW() > effective_time) type
AND (terminate_time IS NULL OR terminate_time > NOW()) FROM
ORDER BY sort ASC, effective_time DESC sys_notice
LIMIT 5 WHERE
( effective_time IS NULL OR NOW() > effective_time )
AND (
terminate_time IS NULL
OR terminate_time > NOW())
<if test="userId != null">
AND ( notice_scope = 1
OR (
notice_scope = 2 AND
<!--转化为字符串类型,因为存储的也是字符串类型-->
JSON_EXTRACT(notice_users, "$[0]") = CAST(#{userId} AS CHAR)
))
</if>
ORDER BY
sort ASC,
effective_time DESC
LIMIT 5;
</select> </select>
</mapper> </mapper>

View File

@@ -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.annotation.CrudRequestMapping;
import top.continew.starter.extension.crud.controller.BaseController; import top.continew.starter.extension.crud.controller.BaseController;
import top.continew.starter.extension.crud.enums.Api; 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.model.resp.BaseIdResp;
import top.continew.starter.extension.crud.util.ValidateGroup; import top.continew.starter.extension.crud.util.ValidateGroup;
import java.io.IOException; import java.io.IOException;
import java.util.List;
/** /**
* 用户管理 API * 用户管理 API
@@ -63,6 +65,11 @@ public class UserController extends BaseController<UserService, UserResp, UserDe
private final UserService userService; private final UserService userService;
@Override
public List<UserResp> list(UserQuery query, SortQuery sortQuery) {
return super.list(query, sortQuery);
}
@Override @Override
public BaseIdResp<Long> add(@Validated(ValidateGroup.Crud.Add.class) @RequestBody UserReq req) { public BaseIdResp<Long> add(@Validated(ValidateGroup.Crud.Add.class) @RequestBody UserReq req) {
String rawPassword = ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(req.getPassword())); String rawPassword = ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(req.getPassword()));

View File

@@ -5,6 +5,8 @@ databaseChangeLog:
file: db/changelog/mysql/continew-admin_column.sql file: db/changelog/mysql/continew-admin_column.sql
- include: - include:
file: db/changelog/mysql/continew-admin_data.sql file: db/changelog/mysql/continew-admin_data.sql
- include:
file: db/changelog/mysql/continew-admin_change_v3.4.0.sql
# PostgreSQL # PostgreSQL
# - include: # - include:
# file: db/changelog/postgresql/continew-admin_table.sql # file: db/changelog/postgresql/continew-admin_table.sql

View File

@@ -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;