mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-10-27 06:57:12 +08:00
feat: 重构公告及消息,公告支持系统消息推送提醒、定时发布、置顶、记录读取状态
This commit is contained in:
@@ -24,7 +24,6 @@ import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.ReUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.xkcoding.justauth.autoconfigure.JustAuthProperties;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import me.zhyd.oauth.AuthRequestBuilder;
|
||||
@@ -54,11 +53,9 @@ import top.continew.admin.system.service.UserSocialService;
|
||||
import top.continew.starter.core.autoconfigure.project.ProjectProperties;
|
||||
import top.continew.starter.core.exception.BadRequestException;
|
||||
import top.continew.starter.core.validation.ValidationUtils;
|
||||
import top.continew.starter.messaging.websocket.util.WebSocketUtils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
@@ -168,15 +165,10 @@ public class SocialLoginHandler extends AbstractLoginHandler<SocialLoginReq> {
|
||||
* @param user 用户信息
|
||||
*/
|
||||
private void sendSecurityMsg(UserDO user) {
|
||||
MessageReq req = new MessageReq();
|
||||
MessageTemplateEnum socialRegister = MessageTemplateEnum.SOCIAL_REGISTER;
|
||||
req.setTitle(socialRegister.getTitle().formatted(projectProperties.getName()));
|
||||
req.setContent(socialRegister.getContent().formatted(user.getNickname()));
|
||||
req.setType(MessageTypeEnum.SECURITY);
|
||||
messageService.add(req, CollUtil.toList(user.getId()));
|
||||
List<String> tokenList = StpUtil.getTokenValueListByLoginId(user.getId());
|
||||
for (String token : tokenList) {
|
||||
WebSocketUtils.sendMessage(token, "1");
|
||||
}
|
||||
MessageTemplateEnum template = MessageTemplateEnum.SOCIAL_REGISTER;
|
||||
MessageReq req = new MessageReq(MessageTypeEnum.SECURITY);
|
||||
req.setTitle(template.getTitle().formatted(projectProperties.getName()));
|
||||
req.setContent(template.getContent().formatted(user.getNickname()));
|
||||
messageService.add(req, CollUtil.toList(user.getId().toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,8 +32,14 @@ public enum MessageTemplateEnum {
|
||||
/**
|
||||
* 第三方登录
|
||||
*/
|
||||
SOCIAL_REGISTER("欢迎注册 %s", "尊敬的 %s,欢迎注册使用,请及时配置您的密码。");
|
||||
SOCIAL_REGISTER("欢迎注册 %s", "尊敬的 %s,欢迎注册使用,请及时配置您的密码。", "/user/profile"),
|
||||
|
||||
/**
|
||||
* 公告发布
|
||||
*/
|
||||
NOTICE_PUBLISH("您有一条新的公告", "公告《%s》已发布,请及时查看。", "/user/notice?id=%s");
|
||||
|
||||
private final String title;
|
||||
private final String content;
|
||||
private final String path;
|
||||
}
|
||||
|
||||
@@ -31,10 +31,15 @@ import top.continew.starter.core.enums.BaseEnum;
|
||||
@RequiredArgsConstructor
|
||||
public enum MessageTypeEnum implements BaseEnum<Integer> {
|
||||
|
||||
/**
|
||||
* 系统消息
|
||||
*/
|
||||
SYSTEM(1, "系统消息", UiConstants.COLOR_PRIMARY),
|
||||
|
||||
/**
|
||||
* 安全消息
|
||||
*/
|
||||
SECURITY(1, "安全消息", UiConstants.COLOR_PRIMARY),;
|
||||
SECURITY(2, "安全消息", UiConstants.COLOR_WARNING),;
|
||||
|
||||
private final Integer value;
|
||||
private final String description;
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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 2025/5/8 21:18
|
||||
*/
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum NoticeMethodEnum implements BaseEnum<Integer> {
|
||||
|
||||
/**
|
||||
* 系统消息
|
||||
*/
|
||||
SYSTEM_MESSAGE(1, "系统消息"),;
|
||||
|
||||
private final Integer value;
|
||||
private final String description;
|
||||
}
|
||||
@@ -21,8 +21,6 @@ import lombok.RequiredArgsConstructor;
|
||||
import top.continew.admin.common.constant.UiConstants;
|
||||
import top.continew.starter.core.enums.BaseEnum;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 公告状态枚举
|
||||
*
|
||||
@@ -33,40 +31,22 @@ import java.time.LocalDateTime;
|
||||
@RequiredArgsConstructor
|
||||
public enum NoticeStatusEnum implements BaseEnum<Integer> {
|
||||
|
||||
/**
|
||||
* 草稿
|
||||
*/
|
||||
DRAFT(1, "草稿", UiConstants.COLOR_WARNING),
|
||||
|
||||
/**
|
||||
* 待发布
|
||||
*/
|
||||
PENDING_RELEASE(1, "待发布", UiConstants.COLOR_PRIMARY),
|
||||
PENDING(2, "待发布", UiConstants.COLOR_PRIMARY),
|
||||
|
||||
/**
|
||||
* 已发布
|
||||
*/
|
||||
PUBLISHED(2, "已发布", UiConstants.COLOR_SUCCESS),
|
||||
|
||||
/**
|
||||
* 已过期
|
||||
*/
|
||||
EXPIRED(3, "已过期", UiConstants.COLOR_ERROR),;
|
||||
PUBLISHED(3, "已发布", UiConstants.COLOR_SUCCESS),;
|
||||
|
||||
private final Integer value;
|
||||
private final String description;
|
||||
private final String color;
|
||||
|
||||
/**
|
||||
* 获取公告状态
|
||||
*
|
||||
* @param effectiveTime 生效时间
|
||||
* @param terminateTime 终止时间
|
||||
* @return 公告状态
|
||||
*/
|
||||
public static NoticeStatusEnum getStatus(LocalDateTime effectiveTime, LocalDateTime terminateTime) {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
if (effectiveTime != null && effectiveTime.isAfter(now)) {
|
||||
return PENDING_RELEASE;
|
||||
}
|
||||
if (terminateTime != null && terminateTime.isBefore(now)) {
|
||||
return EXPIRED;
|
||||
}
|
||||
return PUBLISHED;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,24 +16,15 @@
|
||||
|
||||
package top.continew.admin.system.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import top.continew.admin.system.model.entity.MessageUserDO;
|
||||
import top.continew.admin.system.model.entity.MessageLogDO;
|
||||
import top.continew.starter.data.mp.base.BaseMapper;
|
||||
|
||||
/**
|
||||
* 消息和用户 Mapper
|
||||
* 消息日志 Mapper
|
||||
*
|
||||
* @author Bull-BCLS
|
||||
* @author Charles7c
|
||||
* @since 2023/10/15 20:25
|
||||
*/
|
||||
public interface MessageUserMapper extends BaseMapper<MessageUserDO> {
|
||||
|
||||
/**
|
||||
* 根据用户 ID 和消息类型查询未读消息数量
|
||||
*
|
||||
* @param userId 用户 ID
|
||||
* @param type 消息类型
|
||||
* @return 未读消息信息
|
||||
*/
|
||||
Long selectUnreadCountByUserIdAndType(@Param("userId") Long userId, @Param("type") Integer type);
|
||||
public interface MessageLogMapper extends BaseMapper<MessageLogDO> {
|
||||
}
|
||||
@@ -16,14 +16,16 @@
|
||||
|
||||
package top.continew.admin.system.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import top.continew.admin.system.model.entity.MessageDO;
|
||||
import top.continew.admin.system.model.query.MessageQuery;
|
||||
import top.continew.admin.system.model.resp.message.MessageResp;
|
||||
import top.continew.starter.data.mp.base.BaseMapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 消息 Mapper
|
||||
*
|
||||
@@ -33,12 +35,28 @@ import top.continew.starter.data.mp.base.BaseMapper;
|
||||
public interface MessageMapper extends BaseMapper<MessageDO> {
|
||||
|
||||
/**
|
||||
* 分页查询列表
|
||||
* 分页查询消息列表
|
||||
*
|
||||
* @param page 分页查询条件
|
||||
* @param queryWrapper 查询条件
|
||||
* @return 分页信息
|
||||
* @param page 分页参数
|
||||
* @param query 查询条件
|
||||
* @return 消息列表
|
||||
*/
|
||||
IPage<MessageResp> selectPageByUserId(@Param("page") IPage<Object> page,
|
||||
@Param(Constants.WRAPPER) QueryWrapper<MessageDO> queryWrapper);
|
||||
IPage<MessageResp> selectMessagePage(@Param("page") Page<MessageDO> page, @Param("query") MessageQuery query);
|
||||
|
||||
/**
|
||||
* 查询未读消息列表
|
||||
*
|
||||
* @param userId 用户 ID
|
||||
* @return 消息列表
|
||||
*/
|
||||
List<MessageDO> selectUnreadListByUserId(@Param("userId") Long userId);
|
||||
|
||||
/**
|
||||
* 查询未读消息数量
|
||||
*
|
||||
* @param userId 用户 ID
|
||||
* @param type 消息类型
|
||||
* @return 未读消息数量
|
||||
*/
|
||||
Long selectUnreadCountByUserIdAndType(@Param("userId") Long userId, @Param("type") Integer type);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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.mapper;
|
||||
|
||||
import top.continew.admin.system.model.entity.NoticeLogDO;
|
||||
import top.continew.starter.data.mp.base.BaseMapper;
|
||||
|
||||
/**
|
||||
* 公告日志 Mapper
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2025/5/18 19:17
|
||||
*/
|
||||
public interface NoticeLogMapper extends BaseMapper<NoticeLogDO> {
|
||||
}
|
||||
@@ -21,8 +21,8 @@ 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.admin.system.model.resp.notice.NoticeResp;
|
||||
import top.continew.starter.data.mp.base.BaseMapper;
|
||||
|
||||
import java.util.List;
|
||||
@@ -35,14 +35,6 @@ import java.util.List;
|
||||
*/
|
||||
public interface NoticeMapper extends BaseMapper<NoticeDO> {
|
||||
|
||||
/**
|
||||
* 查询仪表盘公告列表
|
||||
*
|
||||
* @param userId 用户 ID
|
||||
* @return 仪表盘公告列表
|
||||
*/
|
||||
List<DashboardNoticeResp> selectDashboardList(@Param("userId") Long userId);
|
||||
|
||||
/**
|
||||
* 分页查询公告列表
|
||||
*
|
||||
@@ -50,5 +42,21 @@ public interface NoticeMapper extends BaseMapper<NoticeDO> {
|
||||
* @param query 查询条件
|
||||
* @return 公告列表
|
||||
*/
|
||||
IPage<NoticeDetailResp> selectNoticePage(@Param("page") Page<NoticeDO> page, @Param("query") NoticeQuery query);
|
||||
IPage<NoticeResp> selectNoticePage(@Param("page") Page<NoticeDO> page, @Param("query") NoticeQuery query);
|
||||
|
||||
/**
|
||||
* 查询未读公告数量
|
||||
*
|
||||
* @param userId 用户 ID
|
||||
* @return 未读公告数量
|
||||
*/
|
||||
Long selectUnreadCountByUserId(@Param("userId") Long userId);
|
||||
|
||||
/**
|
||||
* 查询仪表盘公告列表
|
||||
*
|
||||
* @param userId 用户 ID
|
||||
* @return 仪表盘公告列表
|
||||
*/
|
||||
List<DashboardNoticeResp> selectDashboardList(@Param("userId") Long userId);
|
||||
}
|
||||
@@ -20,12 +20,15 @@ import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||
import lombok.Data;
|
||||
import top.continew.admin.system.enums.MessageTypeEnum;
|
||||
import top.continew.admin.system.enums.NoticeScopeEnum;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 消息实体
|
||||
@@ -57,15 +60,25 @@ public class MessageDO implements Serializable {
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 类型(1:系统消息)
|
||||
* 类型
|
||||
*/
|
||||
private MessageTypeEnum type;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
* 跳转路径
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Long createUser;
|
||||
private String path;
|
||||
|
||||
/**
|
||||
* 通知范围
|
||||
*/
|
||||
private NoticeScopeEnum scope;
|
||||
|
||||
/**
|
||||
* 通知用户
|
||||
*/
|
||||
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||
private List<String> users;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
|
||||
@@ -18,20 +18,23 @@ package top.continew.admin.system.model.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 消息和用户关联实体
|
||||
* 消息日志实体
|
||||
*
|
||||
* @author Charles7c
|
||||
* @author Bull-BCLS
|
||||
* @since 2023/10/15 20:25
|
||||
*/
|
||||
@Data
|
||||
@TableName("sys_message_user")
|
||||
public class MessageUserDO implements Serializable {
|
||||
@NoArgsConstructor
|
||||
@TableName("sys_message_log")
|
||||
public class MessageLogDO implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
@@ -46,13 +49,14 @@ public class MessageUserDO implements Serializable {
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 是否已读
|
||||
*/
|
||||
private Boolean isRead;
|
||||
|
||||
/**
|
||||
* 读取时间
|
||||
*/
|
||||
private LocalDateTime readTime;
|
||||
|
||||
public MessageLogDO(Long messageId, Long userId, LocalDateTime readTime) {
|
||||
this.messageId = messageId;
|
||||
this.userId = userId;
|
||||
this.readTime = readTime;
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||
import lombok.Data;
|
||||
import top.continew.admin.common.model.entity.BaseDO;
|
||||
import top.continew.admin.system.enums.NoticeScopeEnum;
|
||||
import top.continew.admin.system.enums.NoticeStatusEnum;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.time.LocalDateTime;
|
||||
@@ -51,20 +52,10 @@ public class NoticeDO extends BaseDO {
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 类型
|
||||
* 分类(取值于字典 notice_type)
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 生效时间
|
||||
*/
|
||||
private LocalDateTime effectiveTime;
|
||||
|
||||
/**
|
||||
* 终止时间
|
||||
*/
|
||||
private LocalDateTime terminateTime;
|
||||
|
||||
/**
|
||||
* 通知范围
|
||||
*/
|
||||
@@ -75,4 +66,30 @@ public class NoticeDO extends BaseDO {
|
||||
*/
|
||||
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||
private List<String> noticeUsers;
|
||||
|
||||
/**
|
||||
* 通知方式
|
||||
*/
|
||||
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||
private List<Integer> noticeMethods;
|
||||
|
||||
/**
|
||||
* 是否定时
|
||||
*/
|
||||
private Boolean isTiming;
|
||||
|
||||
/**
|
||||
* 发布时间
|
||||
*/
|
||||
private LocalDateTime publishTime;
|
||||
|
||||
/**
|
||||
* 是否置顶
|
||||
*/
|
||||
private Boolean isTop;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private NoticeStatusEnum status;
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.model.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 公告日志实体
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2025/5/18 19:16
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@TableName("sys_notice_log")
|
||||
public class NoticeLogDO implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 公告 ID
|
||||
*/
|
||||
private Long noticeId;
|
||||
|
||||
/**
|
||||
* 用户 ID
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 读取时间
|
||||
*/
|
||||
private LocalDateTime readTime;
|
||||
|
||||
public NoticeLogDO(Long noticeId, Long userId, LocalDateTime readTime) {
|
||||
this.noticeId = noticeId;
|
||||
this.userId = userId;
|
||||
this.readTime = readTime;
|
||||
}
|
||||
}
|
||||
@@ -18,10 +18,6 @@ package top.continew.admin.system.model.query;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import top.continew.admin.system.enums.MessageTypeEnum;
|
||||
import top.continew.starter.data.core.annotation.Query;
|
||||
import top.continew.starter.data.core.annotation.QueryIgnore;
|
||||
import top.continew.starter.data.core.enums.QueryType;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
@@ -49,26 +45,23 @@ public class MessageQuery implements Serializable {
|
||||
* 标题
|
||||
*/
|
||||
@Schema(description = "标题", example = "欢迎注册 xxx")
|
||||
@Query(type = QueryType.LIKE)
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
@Schema(description = "类型", example = "1")
|
||||
private MessageTypeEnum type;
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 是否已读
|
||||
*/
|
||||
@Schema(description = "是否已读", example = "true")
|
||||
@QueryIgnore
|
||||
private Boolean isRead;
|
||||
|
||||
/**
|
||||
* 用户 ID
|
||||
*/
|
||||
@Schema(hidden = true)
|
||||
@QueryIgnore
|
||||
private Long userId;
|
||||
}
|
||||
@@ -16,11 +16,8 @@
|
||||
|
||||
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;
|
||||
import top.continew.starter.data.core.enums.QueryType;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
@@ -42,18 +39,17 @@ public class NoticeQuery implements Serializable {
|
||||
* 标题
|
||||
*/
|
||||
@Schema(description = "标题", example = "这是公告标题")
|
||||
@Query(type = QueryType.LIKE)
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 类型
|
||||
* 分类(取值于字典 notice_type)
|
||||
*/
|
||||
@Schema(description = "类型", example = "1")
|
||||
@Schema(description = "分类(取值于字典 notice_type)", example = "1")
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 用户 ID
|
||||
*/
|
||||
@JsonIgnore
|
||||
@Schema(hidden = true)
|
||||
private Long userId;
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
import top.continew.admin.system.enums.MessageTypeEnum;
|
||||
|
||||
@@ -33,6 +34,7 @@ import java.io.Serializable;
|
||||
* @since 2023/10/15 19:05
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@Schema(description = "消息创建请求参数")
|
||||
public class MessageReq implements Serializable {
|
||||
|
||||
@@ -58,7 +60,17 @@ public class MessageReq implements Serializable {
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
@Schema(description = "类型(1:系统消息)", example = "1")
|
||||
@Schema(description = "类型", example = "1")
|
||||
@NotNull(message = "类型无效")
|
||||
private MessageTypeEnum type;
|
||||
|
||||
/**
|
||||
* 跳转路径
|
||||
*/
|
||||
@Schema(description = "跳转路径", example = "/user/profile")
|
||||
private String path;
|
||||
|
||||
public MessageReq(MessageTypeEnum type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
@@ -17,12 +17,12 @@
|
||||
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.admin.system.enums.NoticeScopeEnum;
|
||||
import top.continew.admin.system.enums.NoticeStatusEnum;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
@@ -58,26 +58,13 @@ public class NoticeReq implements Serializable {
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 类型(取值于字典 notice_type)
|
||||
* 分类(取值于字典 notice_type)
|
||||
*/
|
||||
@Schema(description = "类型(取值于字典 notice_type)", example = "1")
|
||||
@NotBlank(message = "类型不能为空")
|
||||
@Length(max = 30, message = "类型长度不能超过 {max} 个字符")
|
||||
@Schema(description = "分类(取值于字典 notice_type)", example = "1")
|
||||
@NotBlank(message = "分类不能为空")
|
||||
@Length(max = 30, message = "分类长度不能超过 {max} 个字符")
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 生效时间
|
||||
*/
|
||||
@Schema(description = "生效时间", example = "2023-08-08 00:00:00", type = "string")
|
||||
private LocalDateTime effectiveTime;
|
||||
|
||||
/**
|
||||
* 终止时间
|
||||
*/
|
||||
@Schema(description = "终止时间", example = "2023-08-08 23:59:59", type = "string")
|
||||
@Future(message = "终止时间必须是未来时间")
|
||||
private LocalDateTime terminateTime;
|
||||
|
||||
/**
|
||||
* 通知范围
|
||||
*/
|
||||
@@ -86,8 +73,38 @@ public class NoticeReq implements Serializable {
|
||||
private NoticeScopeEnum noticeScope;
|
||||
|
||||
/**
|
||||
* 指定用户
|
||||
* 通知用户
|
||||
*/
|
||||
@Schema(description = "指定用户", example = "[1,2,3]")
|
||||
@Schema(description = "通知用户", example = "[1,2,3]")
|
||||
private List<String> noticeUsers;
|
||||
|
||||
/**
|
||||
* 通知方式
|
||||
*/
|
||||
@Schema(description = "通知方式", example = "[1,2]")
|
||||
private List<Integer> noticeMethods;
|
||||
|
||||
/**
|
||||
* 是否定时
|
||||
*/
|
||||
@Schema(description = "是否定时", example = "false")
|
||||
private Boolean isTiming;
|
||||
|
||||
/**
|
||||
* 发布时间
|
||||
*/
|
||||
@Schema(description = "发布时间", example = "2023-08-08 00:00:00", type = "string")
|
||||
private LocalDateTime publishTime;
|
||||
|
||||
/**
|
||||
* 是否置顶
|
||||
*/
|
||||
@Schema(description = "是否置顶", example = "false")
|
||||
private Boolean isTop;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@Schema(description = "状态", example = "3")
|
||||
private NoticeStatusEnum status;
|
||||
}
|
||||
@@ -52,4 +52,10 @@ public class DashboardNoticeResp implements Serializable {
|
||||
*/
|
||||
@Schema(description = "类型(取值于字典 notice_type)", example = "1")
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 是否置顶
|
||||
*/
|
||||
@Schema(description = "是否置顶", example = "false")
|
||||
private Boolean isTop;
|
||||
}
|
||||
@@ -16,11 +16,8 @@
|
||||
|
||||
package top.continew.admin.system.model.resp.message;
|
||||
|
||||
import cn.crane4j.annotation.Assemble;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import top.continew.admin.common.constant.ContainerConstants;
|
||||
import top.continew.admin.system.enums.MessageTypeEnum;
|
||||
|
||||
import java.io.Serial;
|
||||
@@ -61,9 +58,15 @@ public class MessageResp implements Serializable {
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
@Schema(description = "类型(1:系统消息)", example = "1")
|
||||
@Schema(description = "类型", example = "1")
|
||||
private MessageTypeEnum type;
|
||||
|
||||
/**
|
||||
* 跳转路径
|
||||
*/
|
||||
@Schema(description = "跳转路径", example = "/user/profile")
|
||||
private String path;
|
||||
|
||||
/**
|
||||
* 是否已读
|
||||
*/
|
||||
@@ -76,19 +79,6 @@ public class MessageResp implements Serializable {
|
||||
@Schema(description = "读取时间", example = "2023-08-08 23:59:59", type = "string")
|
||||
private LocalDateTime readTime;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
@JsonIgnore
|
||||
@Assemble(prop = ":createUserString", container = ContainerConstants.USER_NICKNAME)
|
||||
private Long createUser;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
@Schema(description = "创建人", example = "超级管理员")
|
||||
private String createUserString;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
|
||||
@@ -39,7 +39,7 @@ public class MessageTypeUnreadResp implements Serializable {
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
@Schema(description = "类型(1:系统消息)", example = "1")
|
||||
@Schema(description = "类型", example = "1")
|
||||
private MessageTypeEnum type;
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.admin.system.model.resp;
|
||||
package top.continew.admin.system.model.resp.notice;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
@@ -52,6 +52,14 @@ public class NoticeDetailResp extends BaseDetailResp {
|
||||
@ExcelProperty(value = "标题", order = 2)
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 分类(取值于字典 notice_type)
|
||||
*/
|
||||
@Schema(description = "分类(取值于字典 notice_type)", example = "1")
|
||||
@ExcelProperty(value = "分类", converter = ExcelDictConverter.class, order = 3)
|
||||
@DictExcelProperty("notice_type")
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 内容
|
||||
*/
|
||||
@@ -59,47 +67,49 @@ public class NoticeDetailResp extends BaseDetailResp {
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 类型(取值于字典 notice_type)
|
||||
* 通知范围
|
||||
*/
|
||||
@Schema(description = "类型(取值于字典 notice_type)", example = "1")
|
||||
@ExcelProperty(value = "类型", converter = ExcelDictConverter.class, order = 3)
|
||||
@DictExcelProperty("notice_type")
|
||||
private String type;
|
||||
@Schema(description = "通知范围", example = "2")
|
||||
@ExcelProperty(value = "通知范围", converter = ExcelBaseEnumConverter.class, order = 4)
|
||||
private NoticeScopeEnum noticeScope;
|
||||
|
||||
/**
|
||||
* 通知用户
|
||||
*/
|
||||
@Schema(description = "通知用户", example = "[1,2,3]")
|
||||
private List<String> noticeUsers;
|
||||
|
||||
/**
|
||||
* 通知方式
|
||||
*/
|
||||
@Schema(description = "通知方式", example = "[1,2]")
|
||||
private List<Integer> noticeMethods;
|
||||
|
||||
/**
|
||||
* 是否定时
|
||||
*/
|
||||
@Schema(description = "是否定时", example = "false")
|
||||
@ExcelProperty(value = "是否定时", order = 5)
|
||||
private Boolean isTiming;
|
||||
|
||||
/**
|
||||
* 发布时间
|
||||
*/
|
||||
@Schema(description = "发布时间", example = "2023-08-08 00:00:00", type = "string")
|
||||
@ExcelProperty(value = "发布时间", order = 6)
|
||||
private LocalDateTime publishTime;
|
||||
|
||||
/**
|
||||
* 是否置顶
|
||||
*/
|
||||
@Schema(description = "是否置顶", example = "false")
|
||||
@ExcelProperty(value = "是否置顶", order = 7)
|
||||
private Boolean isTop;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@Schema(description = "状态", example = "1")
|
||||
@ExcelProperty(value = "状态", converter = ExcelBaseEnumConverter.class, order = 4)
|
||||
@Schema(description = "状态", example = "3")
|
||||
@ExcelProperty(value = "状态", converter = ExcelBaseEnumConverter.class, order = 8)
|
||||
private NoticeStatusEnum status;
|
||||
|
||||
/**
|
||||
* 生效时间
|
||||
*/
|
||||
@Schema(description = "生效时间", example = "2023-08-08 00:00:00", type = "string")
|
||||
@ExcelProperty(value = "生效时间", order = 5)
|
||||
private LocalDateTime effectiveTime;
|
||||
|
||||
/**
|
||||
* 终止时间
|
||||
*/
|
||||
@Schema(description = "终止时间", example = "2023-08-08 23:59:59", type = "string")
|
||||
@ExcelProperty(value = "终止时间", order = 6)
|
||||
private LocalDateTime terminateTime;
|
||||
|
||||
/**
|
||||
* 通知范围
|
||||
*/
|
||||
@Schema(description = "通知范围", example = "2")
|
||||
private NoticeScopeEnum noticeScope;
|
||||
|
||||
/**
|
||||
* 指定用户
|
||||
*/
|
||||
@Schema(description = "指定用户", example = "[1,2,3]")
|
||||
private List<String> noticeUsers;
|
||||
|
||||
public NoticeStatusEnum getStatus() {
|
||||
return NoticeStatusEnum.getStatus(effectiveTime, terminateTime);
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.admin.system.model.resp;
|
||||
package top.continew.admin.system.model.resp.notice;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
@@ -46,33 +46,11 @@ public class NoticeResp extends BaseResp {
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 类型(取值于字典 notice_type)
|
||||
* 分类(取值于字典 notice_type)
|
||||
*/
|
||||
@Schema(description = "类型(取值于字典 notice_type)", example = "1")
|
||||
@Schema(description = "分类(取值于字典 notice_type)", example = "1")
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 生效时间
|
||||
*/
|
||||
@Schema(description = "生效时间", example = "2023-08-08 00:00:00", type = "string")
|
||||
private LocalDateTime effectiveTime;
|
||||
|
||||
/**
|
||||
* 终止时间
|
||||
*/
|
||||
@Schema(description = "终止时间", example = "2023-08-08 23:59:59", type = "string")
|
||||
private LocalDateTime terminateTime;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*
|
||||
* @return 公告状态
|
||||
*/
|
||||
@Schema(description = "状态", example = "1")
|
||||
public NoticeStatusEnum getStatus() {
|
||||
return NoticeStatusEnum.getStatus(effectiveTime, terminateTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通知范围
|
||||
*/
|
||||
@@ -80,8 +58,38 @@ public class NoticeResp extends BaseResp {
|
||||
private NoticeScopeEnum noticeScope;
|
||||
|
||||
/**
|
||||
* 指定用户
|
||||
* 通知方式
|
||||
*/
|
||||
@Schema(description = "指定用户", example = "[1,2,3]")
|
||||
private List<String> noticeUsers;
|
||||
@Schema(description = "通知方式", example = "[1,2]")
|
||||
private List<Integer> noticeMethods;
|
||||
|
||||
/**
|
||||
* 是否定时
|
||||
*/
|
||||
@Schema(description = "是否定时", example = "false")
|
||||
private Boolean isTiming;
|
||||
|
||||
/**
|
||||
* 发布时间
|
||||
*/
|
||||
@Schema(description = "发布时间", example = "2023-08-08 00:00:00", type = "string")
|
||||
private LocalDateTime publishTime;
|
||||
|
||||
/**
|
||||
* 是否置顶
|
||||
*/
|
||||
@Schema(description = "是否置顶", example = "false")
|
||||
private Boolean isTop;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@Schema(description = "状态", example = "3")
|
||||
private NoticeStatusEnum status;
|
||||
|
||||
/**
|
||||
* 是否已读
|
||||
*/
|
||||
@Schema(description = "是否已读", example = "false")
|
||||
private Boolean isRead;
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.model.resp.notice;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 未读公告响应参数
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2025/5/20 22:00
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@Schema(description = "未读公告响应参数")
|
||||
public class NoticeUnreadResp implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 未读公告数量
|
||||
*/
|
||||
@Schema(description = "未读公告数量", example = "1")
|
||||
private Long total;
|
||||
|
||||
public NoticeUnreadResp(Long total) {
|
||||
this.total = total;
|
||||
}
|
||||
}
|
||||
@@ -16,41 +16,32 @@
|
||||
|
||||
package top.continew.admin.system.service;
|
||||
|
||||
import top.continew.admin.system.model.resp.message.MessageUnreadResp;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 消息和用户关联业务接口
|
||||
* 消息日志业务接口
|
||||
*
|
||||
* @author Bull-BCLS
|
||||
* @author Charles7c
|
||||
* @since 2023/10/15 19:05
|
||||
*/
|
||||
public interface MessageUserService {
|
||||
|
||||
/**
|
||||
* 根据用户 ID 查询未读消息数量
|
||||
*
|
||||
* @param userId 用户 ID
|
||||
* @param isDetail 是否查询详情
|
||||
* @return 未读消息信息
|
||||
*/
|
||||
MessageUnreadResp countUnreadMessageByUserId(Long userId, Boolean isDetail);
|
||||
public interface MessageLogService {
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*
|
||||
* @param messageId 消息 ID
|
||||
* @param userIdList 用户 ID 列表
|
||||
* @param userIds 用户 ID 列表
|
||||
* @param messageId 消息 ID
|
||||
*/
|
||||
void add(Long messageId, List<Long> userIdList);
|
||||
void addWithMessageId(List<Long> userIds, Long messageId);
|
||||
|
||||
/**
|
||||
* 将消息标记已读
|
||||
* 新增
|
||||
*
|
||||
* @param ids 消息ID(为空则将所有消息标记已读)
|
||||
* @param messageIds 消息 ID 列表
|
||||
* @param userId 用户 ID
|
||||
*/
|
||||
void readMessage(List<Long> ids);
|
||||
void addWithUserId(List<Long> messageIds, Long userId);
|
||||
|
||||
/**
|
||||
* 根据消息 ID 删除
|
||||
@@ -19,6 +19,7 @@ package top.continew.admin.system.service;
|
||||
import top.continew.admin.system.model.query.MessageQuery;
|
||||
import top.continew.admin.system.model.req.MessageReq;
|
||||
import top.continew.admin.system.model.resp.message.MessageResp;
|
||||
import top.continew.admin.system.model.resp.message.MessageUnreadResp;
|
||||
import top.continew.starter.extension.crud.model.query.PageQuery;
|
||||
import top.continew.starter.extension.crud.model.resp.PageResp;
|
||||
|
||||
@@ -28,6 +29,7 @@ import java.util.List;
|
||||
* 消息业务接口
|
||||
*
|
||||
* @author Bull-BCLS
|
||||
* @author Charles7c
|
||||
* @since 2023/10/15 19:05
|
||||
*/
|
||||
public interface MessageService {
|
||||
@@ -41,13 +43,30 @@ public interface MessageService {
|
||||
*/
|
||||
PageResp<MessageResp> page(MessageQuery query, PageQuery pageQuery);
|
||||
|
||||
/**
|
||||
* 将消息标记已读
|
||||
*
|
||||
* @param ids 消息ID(为空则将所有消息标记已读)
|
||||
* @param userId 用户ID
|
||||
*/
|
||||
void readMessage(List<Long> ids, Long userId);
|
||||
|
||||
/**
|
||||
* 查询未读消息数量
|
||||
*
|
||||
* @param userId 用户 ID
|
||||
* @param isDetail 是否查询详情
|
||||
* @return 未读消息数量
|
||||
*/
|
||||
MessageUnreadResp countUnreadByUserId(Long userId, Boolean isDetail);
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*
|
||||
* @param req 请求参数
|
||||
* @param userIdList 接收人列表
|
||||
*/
|
||||
void add(MessageReq req, List<Long> userIdList);
|
||||
void add(MessageReq req, List<String> userIdList);
|
||||
|
||||
/**
|
||||
* 删除
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 公告日志业务接口
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2025/5/18 19:12
|
||||
*/
|
||||
public interface NoticeLogService {
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*
|
||||
* @param userIds 用户 ID 列表
|
||||
* @param noticeId 公告 ID
|
||||
* @return 是否新增成功(true:成功;false:无变更/失败)
|
||||
*/
|
||||
boolean add(List<Long> userIds, Long noticeId);
|
||||
|
||||
/**
|
||||
* 根据公告 ID 列表删除
|
||||
*
|
||||
* @param noticeIds 公告 ID 列表
|
||||
*/
|
||||
void deleteByNoticeIds(List<Long> noticeIds);
|
||||
|
||||
/**
|
||||
* 根据公告 ID 查询用户 ID 列表
|
||||
*
|
||||
* @param noticeId 公告 ID
|
||||
* @return 用户 ID 列表
|
||||
*/
|
||||
List<Long> listUserIdByNoticeId(Long noticeId);
|
||||
}
|
||||
@@ -19,9 +19,10 @@ package top.continew.admin.system.service;
|
||||
import top.continew.admin.system.model.entity.NoticeDO;
|
||||
import top.continew.admin.system.model.query.NoticeQuery;
|
||||
import top.continew.admin.system.model.req.NoticeReq;
|
||||
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.model.resp.notice.NoticeDetailResp;
|
||||
import top.continew.admin.system.model.resp.notice.NoticeResp;
|
||||
import top.continew.admin.system.model.resp.notice.NoticeUnreadResp;
|
||||
import top.continew.starter.data.mp.service.IService;
|
||||
import top.continew.starter.extension.crud.service.BaseService;
|
||||
|
||||
@@ -35,6 +36,29 @@ import java.util.List;
|
||||
*/
|
||||
public interface NoticeService extends BaseService<NoticeResp, NoticeDetailResp, NoticeQuery, NoticeReq>, IService<NoticeDO> {
|
||||
|
||||
/**
|
||||
* 发布公告
|
||||
*
|
||||
* @param notice 公告信息
|
||||
*/
|
||||
void publish(NoticeDO notice);
|
||||
|
||||
/**
|
||||
* 查询未读公告数量
|
||||
*
|
||||
* @param userId 用户 ID
|
||||
* @return 未读公告响应参数
|
||||
*/
|
||||
NoticeUnreadResp countUnreadByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 阅读公告
|
||||
*
|
||||
* @param id 公告 ID
|
||||
* @param userId 用户 ID
|
||||
*/
|
||||
void readNotice(Long id, Long userId);
|
||||
|
||||
/**
|
||||
* 查询仪表盘公告列表
|
||||
*
|
||||
|
||||
@@ -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.system.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import top.continew.admin.system.mapper.MessageLogMapper;
|
||||
import top.continew.admin.system.model.entity.MessageLogDO;
|
||||
import top.continew.admin.system.service.MessageLogService;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 消息日志业务实现
|
||||
*
|
||||
* @author Bull-BCLS
|
||||
* @author Charles7c
|
||||
* @since 2023/10/15 19:05
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class MessageLogServiceImpl implements MessageLogService {
|
||||
|
||||
private final MessageLogMapper baseMapper;
|
||||
|
||||
@Override
|
||||
public void addWithMessageId(List<Long> userIdList, Long messageId) {
|
||||
if (CollUtil.isEmpty(userIdList)) {
|
||||
return;
|
||||
}
|
||||
List<MessageLogDO> list = userIdList.stream()
|
||||
.map(userId -> new MessageLogDO(userId, messageId, LocalDateTime.now()))
|
||||
.toList();
|
||||
baseMapper.insert(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addWithUserId(List<Long> messageIds, Long userId) {
|
||||
if (CollUtil.isEmpty(messageIds)) {
|
||||
return;
|
||||
}
|
||||
List<MessageLogDO> list = messageIds.stream()
|
||||
.map(messageId -> new MessageLogDO(userId, messageId, LocalDateTime.now()))
|
||||
.toList();
|
||||
baseMapper.insert(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteByMessageIds(List<Long> messageIds) {
|
||||
if (CollUtil.isEmpty(messageIds)) {
|
||||
return;
|
||||
}
|
||||
baseMapper.lambdaUpdate().in(MessageLogDO::getMessageId, messageIds).remove();
|
||||
}
|
||||
}
|
||||
@@ -17,32 +17,37 @@
|
||||
package top.continew.admin.system.service.impl;
|
||||
|
||||
import cn.crane4j.annotation.AutoOperate;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import top.continew.admin.system.enums.MessageTypeEnum;
|
||||
import top.continew.admin.system.enums.NoticeScopeEnum;
|
||||
import top.continew.admin.system.mapper.MessageMapper;
|
||||
import top.continew.admin.system.model.entity.MessageDO;
|
||||
import top.continew.admin.system.model.query.MessageQuery;
|
||||
import top.continew.admin.system.model.req.MessageReq;
|
||||
import top.continew.admin.system.model.resp.message.MessageResp;
|
||||
import top.continew.admin.system.model.resp.message.MessageTypeUnreadResp;
|
||||
import top.continew.admin.system.model.resp.message.MessageUnreadResp;
|
||||
import top.continew.admin.system.service.MessageLogService;
|
||||
import top.continew.admin.system.service.MessageService;
|
||||
import top.continew.admin.system.service.MessageUserService;
|
||||
import top.continew.starter.core.validation.CheckUtils;
|
||||
import top.continew.starter.data.mp.util.QueryWrapperHelper;
|
||||
import top.continew.starter.extension.crud.model.query.PageQuery;
|
||||
import top.continew.starter.extension.crud.model.resp.PageResp;
|
||||
import top.continew.starter.messaging.websocket.util.WebSocketUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 消息业务实现
|
||||
*
|
||||
* @author Bull-BCLS
|
||||
* @author Charles7c
|
||||
* @since 2023/10/15 19:05
|
||||
*/
|
||||
@Service
|
||||
@@ -50,32 +55,71 @@ import java.util.List;
|
||||
public class MessageServiceImpl implements MessageService {
|
||||
|
||||
private final MessageMapper baseMapper;
|
||||
private final MessageUserService messageUserService;
|
||||
private final MessageLogService messageLogService;
|
||||
|
||||
@Override
|
||||
@AutoOperate(type = MessageResp.class, on = "list")
|
||||
public PageResp<MessageResp> page(MessageQuery query, PageQuery pageQuery) {
|
||||
QueryWrapper<MessageDO> queryWrapper = QueryWrapperHelper.build(query, pageQuery.getSort());
|
||||
queryWrapper.apply(null != query.getUserId(), "t2.user_id={0}", query.getUserId())
|
||||
.apply(null != query.getIsRead(), "t2.is_read={0}", query.getIsRead());
|
||||
IPage<MessageResp> page = baseMapper.selectPageByUserId(new Page<>(pageQuery.getPage(), pageQuery
|
||||
.getSize()), queryWrapper);
|
||||
IPage<MessageResp> page = baseMapper.selectMessagePage(new Page<>(pageQuery.getPage(), pageQuery
|
||||
.getSize()), query);
|
||||
return PageResp.build(page);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readMessage(List<Long> ids, Long userId) {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
// 查询当前用户的未读消息
|
||||
List<MessageDO> list = baseMapper.selectUnreadListByUserId(userId);
|
||||
ids = list.stream().map(MessageDO::getId).toList();
|
||||
}
|
||||
messageLogService.addWithMessageId(ids, userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageUnreadResp countUnreadByUserId(Long userId, Boolean isDetail) {
|
||||
MessageUnreadResp result = new MessageUnreadResp();
|
||||
Long total = 0L;
|
||||
if (Boolean.TRUE.equals(isDetail)) {
|
||||
List<MessageTypeUnreadResp> detailList = new ArrayList<>();
|
||||
for (MessageTypeEnum messageType : MessageTypeEnum.values()) {
|
||||
MessageTypeUnreadResp resp = new MessageTypeUnreadResp();
|
||||
resp.setType(messageType);
|
||||
Long count = baseMapper.selectUnreadCountByUserIdAndType(userId, messageType.getValue());
|
||||
resp.setCount(count);
|
||||
detailList.add(resp);
|
||||
total += count;
|
||||
}
|
||||
result.setDetails(detailList);
|
||||
} else {
|
||||
total = baseMapper.selectUnreadCountByUserIdAndType(userId, null);
|
||||
}
|
||||
result.setTotal(total);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void add(MessageReq req, List<Long> userIdList) {
|
||||
CheckUtils.throwIf(() -> CollUtil.isEmpty(userIdList), "消息接收人不能为空");
|
||||
public void add(MessageReq req, List<String> userIdList) {
|
||||
MessageDO message = BeanUtil.copyProperties(req, MessageDO.class);
|
||||
message.setScope(CollUtil.isEmpty(userIdList) ? NoticeScopeEnum.ALL : NoticeScopeEnum.USER);
|
||||
message.setUsers(userIdList);
|
||||
baseMapper.insert(message);
|
||||
messageUserService.add(message.getId(), userIdList);
|
||||
// 发送消息给指定在线用户
|
||||
if (CollUtil.isNotEmpty(userIdList)) {
|
||||
userIdList.parallelStream().forEach(userId -> {
|
||||
List<String> tokenList = StpUtil.getTokenValueListByLoginId(userId);
|
||||
tokenList.parallelStream().forEach(token -> WebSocketUtils.sendMessage(token, "1"));
|
||||
});
|
||||
return;
|
||||
}
|
||||
// 发送消息给所有在线用户
|
||||
// TODO WebSocketUtils.sendMessage("1");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(List<Long> ids) {
|
||||
baseMapper.deleteByIds(ids);
|
||||
messageUserService.deleteByMessageIds(ids);
|
||||
messageLogService.deleteByMessageIds(ids);
|
||||
}
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
/*
|
||||
* 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.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import top.continew.admin.system.enums.MessageTypeEnum;
|
||||
import top.continew.admin.system.mapper.MessageUserMapper;
|
||||
import top.continew.admin.system.model.entity.MessageUserDO;
|
||||
import top.continew.admin.system.model.resp.message.MessageTypeUnreadResp;
|
||||
import top.continew.admin.system.model.resp.message.MessageUnreadResp;
|
||||
import top.continew.admin.system.service.MessageUserService;
|
||||
import top.continew.starter.core.validation.CheckUtils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 消息和用户关联业务实现
|
||||
*
|
||||
* @author Bull-BCLS
|
||||
* @since 2023/10/15 19:05
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class MessageUserServiceImpl implements MessageUserService {
|
||||
|
||||
private final MessageUserMapper baseMapper;
|
||||
|
||||
@Override
|
||||
public MessageUnreadResp countUnreadMessageByUserId(Long userId, Boolean isDetail) {
|
||||
MessageUnreadResp result = new MessageUnreadResp();
|
||||
Long total = 0L;
|
||||
if (Boolean.TRUE.equals(isDetail)) {
|
||||
List<MessageTypeUnreadResp> detailList = new ArrayList<>();
|
||||
for (MessageTypeEnum messageType : MessageTypeEnum.values()) {
|
||||
MessageTypeUnreadResp resp = new MessageTypeUnreadResp();
|
||||
resp.setType(messageType);
|
||||
Long count = baseMapper.selectUnreadCountByUserIdAndType(userId, messageType.getValue());
|
||||
resp.setCount(count);
|
||||
detailList.add(resp);
|
||||
total += count;
|
||||
}
|
||||
result.setDetails(detailList);
|
||||
} else {
|
||||
total = baseMapper.selectUnreadCountByUserIdAndType(userId, null);
|
||||
}
|
||||
result.setTotal(total);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(Long messageId, List<Long> userIdList) {
|
||||
CheckUtils.throwIfEmpty(userIdList, "消息接收人不能为空");
|
||||
List<MessageUserDO> messageUserList = userIdList.stream().map(userId -> {
|
||||
MessageUserDO messageUser = new MessageUserDO();
|
||||
messageUser.setUserId(userId);
|
||||
messageUser.setMessageId(messageId);
|
||||
messageUser.setIsRead(false);
|
||||
return messageUser;
|
||||
}).toList();
|
||||
baseMapper.insert(messageUserList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readMessage(List<Long> ids) {
|
||||
baseMapper.lambdaUpdate()
|
||||
.set(MessageUserDO::getIsRead, true)
|
||||
.set(MessageUserDO::getReadTime, LocalDateTime.now())
|
||||
.eq(MessageUserDO::getIsRead, false)
|
||||
.in(CollUtil.isNotEmpty(ids), MessageUserDO::getMessageId, ids)
|
||||
.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteByMessageIds(List<Long> messageIds) {
|
||||
if (CollUtil.isEmpty(messageIds)) {
|
||||
return;
|
||||
}
|
||||
baseMapper.lambdaUpdate().in(MessageUserDO::getMessageId, messageIds).remove();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import top.continew.admin.system.mapper.NoticeLogMapper;
|
||||
import top.continew.admin.system.model.entity.NoticeLogDO;
|
||||
import top.continew.admin.system.service.NoticeLogService;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 公告日志业务实现
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2025/5/18 19:15
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class NoticeLogServiceImpl implements NoticeLogService {
|
||||
|
||||
private final NoticeLogMapper baseMapper;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean add(List<Long> userIds, Long noticeId) {
|
||||
// 检查是否有变更
|
||||
List<Long> oldUserIdList = baseMapper.lambdaQuery()
|
||||
.select(NoticeLogDO::getUserId)
|
||||
.eq(NoticeLogDO::getNoticeId, noticeId)
|
||||
.list()
|
||||
.stream()
|
||||
.map(NoticeLogDO::getUserId)
|
||||
.toList();
|
||||
Collection<Long> subtract = CollUtil.subtract(userIds, oldUserIdList);
|
||||
if (CollUtil.isEmpty(subtract)) {
|
||||
return false;
|
||||
}
|
||||
// 新增没有关联的
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
List<NoticeLogDO> list = subtract.stream().map(userId -> new NoticeLogDO(noticeId, userId, now)).toList();
|
||||
return baseMapper.insertBatch(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteByNoticeIds(List<Long> noticeIds) {
|
||||
if (CollUtil.isEmpty(noticeIds)) {
|
||||
return;
|
||||
}
|
||||
baseMapper.lambdaUpdate().in(NoticeLogDO::getNoticeId, noticeIds).remove();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> listUserIdByNoticeId(Long noticeId) {
|
||||
return baseMapper.lambdaQuery()
|
||||
.select(NoticeLogDO::getUserId)
|
||||
.eq(NoticeLogDO::getNoticeId, noticeId)
|
||||
.list()
|
||||
.stream()
|
||||
.map(NoticeLogDO::getUserId)
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
@@ -16,23 +16,32 @@
|
||||
|
||||
package top.continew.admin.system.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
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;
|
||||
import top.continew.admin.system.enums.*;
|
||||
import top.continew.admin.system.mapper.NoticeMapper;
|
||||
import top.continew.admin.system.model.entity.NoticeDO;
|
||||
import top.continew.admin.system.model.query.NoticeQuery;
|
||||
import top.continew.admin.system.model.req.MessageReq;
|
||||
import top.continew.admin.system.model.req.NoticeReq;
|
||||
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.model.resp.notice.NoticeDetailResp;
|
||||
import top.continew.admin.system.model.resp.notice.NoticeResp;
|
||||
import top.continew.admin.system.model.resp.notice.NoticeUnreadResp;
|
||||
import top.continew.admin.system.service.MessageService;
|
||||
import top.continew.admin.system.service.NoticeLogService;
|
||||
import top.continew.admin.system.service.NoticeService;
|
||||
import top.continew.starter.core.validation.CheckUtils;
|
||||
import top.continew.starter.core.validation.ValidationUtils;
|
||||
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.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -45,15 +54,130 @@ import java.util.List;
|
||||
@RequiredArgsConstructor
|
||||
public class NoticeServiceImpl extends BaseServiceImpl<NoticeMapper, NoticeDO, NoticeResp, NoticeDetailResp, NoticeQuery, NoticeReq> implements NoticeService {
|
||||
|
||||
private final NoticeLogService noticeLogService;
|
||||
private final MessageService messageService;
|
||||
|
||||
@Override
|
||||
public PageResp<NoticeResp> page(NoticeQuery query, PageQuery pageQuery) {
|
||||
IPage<NoticeDetailResp> page = baseMapper.selectNoticePage(new Page<>(pageQuery.getPage(), pageQuery
|
||||
IPage<NoticeResp> page = baseMapper.selectNoticePage(new Page<>(pageQuery.getPage(), pageQuery
|
||||
.getSize()), query);
|
||||
PageResp<NoticeResp> pageResp = PageResp.build(page, super.getListClass());
|
||||
PageResp<NoticeResp> pageResp = PageResp.build(page);
|
||||
pageResp.getList().forEach(this::fill);
|
||||
return pageResp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeCreate(NoticeReq req) {
|
||||
// 校验定时发布
|
||||
if (Boolean.TRUE.equals(req.getIsTiming())) {
|
||||
ValidationUtils.throwIf(req.getPublishTime() == null, "定时发布时间不能为空");
|
||||
ValidationUtils.throwIf(req.getPublishTime().isBefore(LocalDateTime.now()), "定时发布时间不能早于当前时间");
|
||||
}
|
||||
if (!NoticeStatusEnum.DRAFT.equals(req.getStatus())) {
|
||||
if (Boolean.TRUE.equals(req.getIsTiming())) {
|
||||
// 待发布
|
||||
req.setStatus(NoticeStatusEnum.PENDING);
|
||||
} else {
|
||||
// 已发布
|
||||
req.setStatus(NoticeStatusEnum.PUBLISHED);
|
||||
req.setPublishTime(LocalDateTime.now());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCreate(NoticeReq req, NoticeDO entity) {
|
||||
// 发送消息
|
||||
if (NoticeStatusEnum.PUBLISHED.equals(entity.getStatus())) {
|
||||
this.publish(entity);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeUpdate(NoticeReq req, Long id) {
|
||||
NoticeDO oldNotice = super.getById(id);
|
||||
switch (oldNotice.getStatus()) {
|
||||
case PUBLISHED -> {
|
||||
CheckUtils.throwIfNotEqual(req.getStatus(), oldNotice.getStatus(), "公告已发布,不允许修改状态");
|
||||
CheckUtils.throwIfNotEqual(req.getIsTiming(), oldNotice.getIsTiming(), "公告已发布,不允许修改定时发布信息");
|
||||
CheckUtils.throwIfNotEqual(req.getNoticeScope(), oldNotice.getNoticeScope(), "公告已发布,不允许修改通知范围");
|
||||
if (NoticeScopeEnum.USER.equals(oldNotice.getNoticeScope())) {
|
||||
CheckUtils.throwIfNotEmpty(CollUtil.disjunction(req.getNoticeUsers(), oldNotice
|
||||
.getNoticeUsers()), "公告已发布,不允许修改通知用户");
|
||||
}
|
||||
CheckUtils.throwIf(!CollUtil.isEqualList(req.getNoticeMethods(), oldNotice
|
||||
.getNoticeMethods()), "公告已发布,不允许修改通知方式");
|
||||
// 修正定时发布信息
|
||||
if (Boolean.TRUE.equals(oldNotice.getIsTiming())) {
|
||||
CheckUtils.throwIfNotEqual(req.getPublishTime(), oldNotice.getPublishTime(), "公告已发布,不允许修改定时发布信息");
|
||||
}
|
||||
req.setPublishTime(oldNotice.getPublishTime());
|
||||
}
|
||||
case DRAFT, PENDING -> {
|
||||
// 校验定时发布
|
||||
if (Boolean.TRUE.equals(req.getIsTiming())) {
|
||||
ValidationUtils.throwIf(req.getPublishTime() == null, "定时发布时间不能为空");
|
||||
ValidationUtils.throwIf(req.getPublishTime().isBefore(LocalDateTime.now()), "定时发布时间不能早于当前时间");
|
||||
}
|
||||
// 已发布
|
||||
if (NoticeStatusEnum.PUBLISHED.equals(req.getStatus())) {
|
||||
if (Boolean.TRUE.equals(req.getIsTiming())) {
|
||||
// 待发布
|
||||
req.setStatus(NoticeStatusEnum.PENDING);
|
||||
} else {
|
||||
// 已发布
|
||||
req.setStatus(NoticeStatusEnum.PUBLISHED);
|
||||
req.setPublishTime(LocalDateTime.now());
|
||||
}
|
||||
}
|
||||
}
|
||||
default -> throw new IllegalArgumentException("状态无效");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterUpdate(NoticeReq req, NoticeDO entity) {
|
||||
// 重置定时发布时间
|
||||
if (!NoticeStatusEnum.PUBLISHED.equals(entity.getStatus()) && Boolean.FALSE.equals(entity
|
||||
.getIsTiming()) && entity.getPublishTime() != null) {
|
||||
baseMapper.lambdaUpdate().set(NoticeDO::getPublishTime, null).eq(NoticeDO::getId, entity.getId()).update();
|
||||
}
|
||||
// 发送消息
|
||||
if (Boolean.FALSE.equals(entity.getIsTiming()) && NoticeStatusEnum.PUBLISHED.equals(entity.getStatus())) {
|
||||
this.publish(entity);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterDelete(List<Long> ids) {
|
||||
// 删除公告日志
|
||||
noticeLogService.deleteByNoticeIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void publish(NoticeDO notice) {
|
||||
List<Integer> noticeMethods = notice.getNoticeMethods();
|
||||
if (CollUtil.isNotEmpty(noticeMethods) && noticeMethods.contains(NoticeMethodEnum.SYSTEM_MESSAGE.getValue())) {
|
||||
MessageTemplateEnum template = MessageTemplateEnum.NOTICE_PUBLISH;
|
||||
MessageReq req = new MessageReq(MessageTypeEnum.SYSTEM);
|
||||
req.setTitle(template.getTitle());
|
||||
req.setContent(template.getContent().formatted(notice.getTitle()));
|
||||
req.setPath(template.getPath().formatted(notice.getId()));
|
||||
// 新增消息
|
||||
messageService.add(req, notice.getNoticeUsers());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NoticeUnreadResp countUnreadByUserId(Long userId) {
|
||||
return new NoticeUnreadResp(baseMapper.selectUnreadCountByUserId(userId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readNotice(Long id, Long userId) {
|
||||
noticeLogService.add(List.of(userId), id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DashboardNoticeResp> listDashboard() {
|
||||
Long userId = UserContextHolder.getUserId();
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="top.continew.admin.system.mapper.MessageLogMapper">
|
||||
</mapper>
|
||||
@@ -1,14 +1,56 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="top.continew.admin.system.mapper.MessageMapper">
|
||||
<select id="selectPageByUserId" resultType="top.continew.admin.system.model.resp.message.MessageResp">
|
||||
|
||||
<select id="selectMessagePage" resultType="top.continew.admin.system.model.resp.message.MessageResp">
|
||||
SELECT
|
||||
t1.*,
|
||||
t2.user_id,
|
||||
t2.is_read,
|
||||
t2.read_time
|
||||
t1.id,
|
||||
t1.title,
|
||||
t1.content,
|
||||
t1.type,
|
||||
t1.path,
|
||||
t1.scope,
|
||||
t1.users,
|
||||
t1.create_time,
|
||||
t2.read_time IS NOT NULL AS isRead,
|
||||
t2.read_time AS readTime
|
||||
FROM sys_message AS t1
|
||||
LEFT JOIN sys_message_user AS t2 ON t2.message_id = t1.id
|
||||
${ew.getCustomSqlSegment}
|
||||
LEFT JOIN sys_message_log AS t2 ON t2.message_id = t1.id
|
||||
<where>
|
||||
<if test="query.userId != null">
|
||||
(t1.scope = 1 OR (t1.scope = 2 AND JSON_EXTRACT(t1.users, "$[0]") = CAST(#{query.userId} AS CHAR)))
|
||||
</if>
|
||||
<if test="query.title != null and query.title != ''">
|
||||
AND t1.title LIKE CONCAT('%', #{query.title}, '%')
|
||||
</if>
|
||||
<if test="query.type != null and query.type != ''">
|
||||
AND t1.type = #{query.type}
|
||||
</if>
|
||||
<if test="query.isRead != null">
|
||||
AND t2.read_time IS <if test="query.isRead">NOT</if> NULL
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY t1.create_time DESC
|
||||
</select>
|
||||
|
||||
<select id="selectUnreadListByUserId" resultType="top.continew.admin.system.model.entity.MessageDO">
|
||||
SELECT
|
||||
t1.*
|
||||
FROM sys_message AS t1
|
||||
LEFT JOIN sys_message_log AS t2 ON t2.message_id = t1.id
|
||||
WHERE (t1.scope = 1 OR (t1.scope = 2 AND JSON_CONTAINS(t1.users, CONCAT('"', #{userId}, '"'))))
|
||||
AND t2.read_time IS NULL
|
||||
</select>
|
||||
|
||||
<select id="selectUnreadCountByUserIdAndType" resultType="java.lang.Long">
|
||||
SELECT
|
||||
COUNT(1)
|
||||
FROM sys_message AS t1
|
||||
LEFT JOIN sys_message_log AS t2 ON t2.message_id = t1.id
|
||||
WHERE (t1.scope = 1 OR (t1.scope = 2 AND JSON_CONTAINS(t1.users, CONCAT('"', #{userId}, '"'))))
|
||||
AND t2.read_time IS NULL
|
||||
<if test="type != null">
|
||||
AND t1.type = #{type}
|
||||
</if>
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="top.continew.admin.system.mapper.MessageUserMapper">
|
||||
<select id="selectUnreadCountByUserIdAndType" resultType="Long">
|
||||
SELECT
|
||||
COUNT(t1.message_id)
|
||||
FROM sys_message_user AS t1
|
||||
LEFT JOIN sys_message AS t2 ON t2.id = t1.message_id
|
||||
WHERE t1.user_id = #{userId} AND t1.is_read = false
|
||||
<if test="type != null">
|
||||
AND t2.type = #{type}
|
||||
</if>
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -2,28 +2,29 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="top.continew.admin.system.mapper.NoticeMapper">
|
||||
|
||||
<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())
|
||||
<if test="userId != null">
|
||||
AND (notice_scope = 1 OR (notice_scope = 2 AND JSON_CONTAINS(notice_users, CONCAT('"', #{userId}, '"'))))
|
||||
</if>
|
||||
ORDER BY sort ASC, effective_time DESC
|
||||
LIMIT 5
|
||||
</select>
|
||||
<resultMap id="notice" type="top.continew.admin.system.model.resp.notice.NoticeResp">
|
||||
<id property="id" column="id" />
|
||||
<result property="noticeMethods" column="notice_methods" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler" />
|
||||
</resultMap>
|
||||
|
||||
<select id="selectNoticePage" resultType="top.continew.admin.system.model.resp.NoticeDetailResp">
|
||||
SELECT *
|
||||
<select id="selectNoticePage" resultMap="notice">
|
||||
SELECT
|
||||
t1.id,
|
||||
t1.title,
|
||||
t1.type,
|
||||
t1.notice_scope,
|
||||
t1.notice_methods,
|
||||
t1.is_timing,
|
||||
t1.publish_time,
|
||||
t1.is_top,
|
||||
t1.status,
|
||||
t1.create_user,
|
||||
t2.read_time IS NOT NULL AS isRead
|
||||
FROM sys_notice AS t1
|
||||
LEFT JOIN sys_notice_log AS t2 ON t2.notice_id = t1.id
|
||||
<where>
|
||||
<if test="query.userId != null">
|
||||
t1.notice_scope = 1 OR (t1.notice_scope = 2 AND JSON_EXTRACT(t1.notice_users, "$[0]") = CAST(#{query.userId} AS CHAR))
|
||||
AND (t1.effective_time IS NULL OR NOW() > t1.effective_time)
|
||||
AND (t1.terminate_time IS NULL OR t1.terminate_time > NOW())
|
||||
(t1.notice_scope = 1 OR (t1.notice_scope = 2 AND JSON_EXTRACT(t1.notice_users, "$[0]") = CAST(#{query.userId} AS CHAR)))
|
||||
</if>
|
||||
<if test="query.title != null and query.title != ''">
|
||||
AND t1.title LIKE CONCAT('%', #{query.title}, '%')
|
||||
@@ -33,10 +34,32 @@
|
||||
</if>
|
||||
</where>
|
||||
<if test="query.userId != null">
|
||||
ORDER BY t1.sort ASC, t1.effective_time DESC
|
||||
ORDER BY t1.is_top DESC, t1.publish_time DESC
|
||||
</if>
|
||||
<if test="query.userId == null">
|
||||
ORDER BY t1.create_time DESC
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="selectUnreadCountByUserId" resultType="java.lang.Long">
|
||||
SELECT
|
||||
COUNT(1)
|
||||
FROM sys_notice AS t1
|
||||
LEFT JOIN sys_notice_log AS t2 ON t2.notice_id = t1.id
|
||||
WHERE (t1.notice_scope = 1 OR (t1.notice_scope = 2 AND JSON_CONTAINS(t1.notice_users, CONCAT('"', #{userId}, '"'))))
|
||||
AND t2.read_time IS NULL
|
||||
</select>
|
||||
|
||||
<select id="selectDashboardList"
|
||||
resultType="top.continew.admin.system.model.resp.dashboard.DashboardNoticeResp">
|
||||
SELECT
|
||||
id, title, type, is_top
|
||||
FROM sys_notice
|
||||
WHERE status = 3
|
||||
<if test="userId != null">
|
||||
AND (notice_scope = 1 OR (notice_scope = 2 AND JSON_CONTAINS(notice_users, CONCAT('"', #{userId}, '"'))))
|
||||
</if>
|
||||
ORDER BY is_top DESC, publish_time DESC
|
||||
LIMIT 5
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user