Skip to content

Commit

Permalink
feat: 公告支持设置通知范围
Browse files Browse the repository at this point in the history
  • Loading branch information
zk020106 authored and Charles7c committed Oct 23, 2024
1 parent e01df09 commit 29202ae
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,5 +36,5 @@ public interface NoticeMapper extends BaseMapper<NoticeDO> {
*
* @return 仪表盘公告列表
*/
List<DashboardNoticeResp> selectDashboardList();
List<DashboardNoticeResp> selectDashboardList(@Param("userId") Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
* 公告实体
Expand All @@ -30,7 +33,7 @@
* @since 2023/8/20 10:55
*/
@Data
@TableName("sys_notice")
@TableName(value = "sys_notice",autoResultMap = true)
public class NoticeDO extends BaseDO {

@Serial
Expand Down Expand Up @@ -60,4 +63,15 @@ public class NoticeDO extends BaseDO {
* 终止时间
*/
private LocalDateTime terminateTime;

/**
* 通知范围
*/
private Integer noticeScope;

/**
* 通知用户
*/
@TableField(typeHandler = JacksonTypeHandler.class)
private List<String> noticeUsers;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Long> userIds;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
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;

/**
* 创建或修改公告信息
Expand Down Expand Up @@ -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<String> noticeUsers;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import java.io.Serial;
import java.time.LocalDateTime;
import java.util.List;

/**
* 公告详情信息
Expand Down Expand Up @@ -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<String> noticeUsers;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.io.Serial;
import java.time.LocalDateTime;
import java.util.List;

/**
* 公告信息
Expand Down Expand Up @@ -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<String> noticeUsers;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

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;
Expand All @@ -42,6 +43,7 @@ public class NoticeServiceImpl extends BaseServiceImpl<NoticeMapper, NoticeDO, N

@Override
public List<DashboardNoticeResp> listDashboard() {
return baseMapper.selectDashboardList();
Long userId = UserContextHolder.isAdmin()? null: UserContextHolder.getUserId();
return baseMapper.selectDashboardList(userId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ public PageResp<UserResp> page(UserQuery query, PageQuery pageQuery) {
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
public Long add(UserDO user) {
user.setStatus(DisEnableStatusEnum.ENABLE);
Expand Down Expand Up @@ -488,6 +495,7 @@ protected QueryWrapper<UserDO> buildQueryWrapper(UserQuery query) {
DisEnableStatusEnum status = query.getStatus();
List<Date> createTimeList = query.getCreateTime();
Long deptId = query.getDeptId();
List<Long> userIdList = query.getUserIds();
return new QueryWrapper<UserDO>().and(StrUtil.isNotBlank(description), q -> q.like("t1.username", description)
.or()
.like("t1.nickname", description)
Expand All @@ -503,7 +511,7 @@ protected QueryWrapper<UserDO> buildQueryWrapper(UserQuery query) {
.collect(Collectors.toList());
deptIdList.add(deptId);
q.in("t1.dept_id", deptIdList);
});
}).in(CollUtil.isNotEmpty(userIdList),"t1.id", userIdList);
}

@Override
Expand Down
28 changes: 22 additions & 6 deletions continew-admin-system/src/main/resources/mapper/NoticeMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,27 @@
<select id="selectDashboardList"
resultType="top.continew.admin.system.model.resp.dashboard.DashboardNoticeResp">
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())
<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>
</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@
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
Expand All @@ -63,6 +65,11 @@ public class UserController extends BaseController<UserService, UserResp, UserDe

private final UserService userService;

@Override
public List<UserResp> list(UserQuery query, SortQuery sortQuery) {
return super.list(query, sortQuery);
}

@Override
public BaseIdResp<Long> add(@Validated(ValidateGroup.Crud.Add.class) @RequestBody UserReq req) {
String rawPassword = ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(req.getPassword()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 29202ae

Please sign in to comment.