wip: 通知公告开发临时提交
通知公告开发临时提交
This commit is contained in:
@@ -11,14 +11,16 @@ import lombok.RequiredArgsConstructor;
|
|||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public enum NoticeWayEnum implements IBaseEnum<Integer> {
|
public enum NoticeWayEnum implements IBaseEnum<String> {
|
||||||
/**
|
/**
|
||||||
* 通知方式
|
* 通知方式
|
||||||
*/
|
*/
|
||||||
WEBSOCKET("webSocket", "发送websocket消息");
|
WEBSOCKET("webSocket", "发送websocket消息");
|
||||||
|
|
||||||
|
@Getter
|
||||||
private String value;
|
private String value;
|
||||||
|
|
||||||
|
@Getter
|
||||||
private String label;
|
private String label;
|
||||||
|
|
||||||
NoticeWayEnum(String value, String label) {
|
NoticeWayEnum(String value, String label) {
|
||||||
|
|||||||
@@ -58,6 +58,12 @@ public class NoticeController {
|
|||||||
NoticeForm formData = noticeService.getNoticeFormData(id);
|
NoticeForm formData = noticeService.getNoticeFormData(id);
|
||||||
return Result.success(formData);
|
return Result.success(formData);
|
||||||
}
|
}
|
||||||
|
@Operation(summary = "管理页面查看通知公告")
|
||||||
|
@GetMapping("/detail/{id}")
|
||||||
|
public Result<?> getReadNoticeDetail(
|
||||||
|
@Parameter(description = "通知公告ID")@PathVariable Long id) {
|
||||||
|
return Result.success(noticeService.getReadNoticeDetail(id));
|
||||||
|
}
|
||||||
|
|
||||||
@Operation(summary = "修改通知公告")
|
@Operation(summary = "修改通知公告")
|
||||||
@PutMapping(value = "/{id}")
|
@PutMapping(value = "/{id}")
|
||||||
@@ -96,9 +102,22 @@ public class NoticeController {
|
|||||||
return Result.judge(result);
|
return Result.judge(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "获取我的通知公告")
|
@Operation(summary = "获取未读的通知公告")
|
||||||
@GetMapping("/notice/{count}")
|
@GetMapping("/unread")
|
||||||
public Result<?> listNotices(@PathVariable Integer count) {
|
public Result<?> listUnreadNotices() {
|
||||||
return Result.success(noticeStatusService.listNotices(count));
|
return Result.success(noticeStatusService.listUnreadNotices());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "阅读通知公告")
|
||||||
|
@PatchMapping("/read/{id}")
|
||||||
|
public Result<?> readNotice(@PathVariable Long id) {
|
||||||
|
return Result.success(noticeService.readNotice(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "全部已读")
|
||||||
|
@PatchMapping("/readAll")
|
||||||
|
public Result<?> readAll() {
|
||||||
|
noticeStatusService.readAll();
|
||||||
|
return Result.success();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ public interface NoticeConverter{
|
|||||||
Page<NoticeVO> toPageVo(Page<NoticeBO> noticePage);
|
Page<NoticeVO> toPageVo(Page<NoticeBO> noticePage);
|
||||||
|
|
||||||
@Mappings({
|
@Mappings({
|
||||||
@Mapping(target = "noticeTypeLabel", expression = "java(com.youlai.boot.common.base.IBaseEnum.getLabelByValue(bo.getNoticeType(), com.youlai.boot.common.enums.NoticeWayEnum.class))")
|
|
||||||
})
|
})
|
||||||
NoticeVO toPageVo(NoticeBO bo);
|
NoticeVO toPageVo(NoticeBO bo);
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import com.youlai.boot.system.model.bo.NoticeBO;
|
|||||||
import com.youlai.boot.system.model.entity.Notice;
|
import com.youlai.boot.system.model.entity.Notice;
|
||||||
import com.youlai.boot.system.model.query.NoticeQuery;
|
import com.youlai.boot.system.model.query.NoticeQuery;
|
||||||
import com.youlai.boot.system.model.vo.NoticeVO;
|
import com.youlai.boot.system.model.vo.NoticeVO;
|
||||||
|
import com.youlai.boot.system.model.vo.NoticeDetailVO;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
@@ -27,4 +28,10 @@ public interface NoticeMapper extends BaseMapper<Notice> {
|
|||||||
*/
|
*/
|
||||||
Page<NoticeBO> getNoticePage(Page<NoticeVO> page, @Param("queryParams") NoticeQuery queryParams);
|
Page<NoticeBO> getNoticePage(Page<NoticeVO> page, @Param("queryParams") NoticeQuery queryParams);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取阅读时通知公告详情
|
||||||
|
* @param id 通知公告ID
|
||||||
|
* @return 通知公告详情
|
||||||
|
*/
|
||||||
|
NoticeDetailVO getReadNoticeVO(@Param("id") Long id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,11 @@ package com.youlai.boot.system.mapper;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.youlai.boot.system.model.entity.NoticeStatus;
|
import com.youlai.boot.system.model.entity.NoticeStatus;
|
||||||
|
import com.youlai.boot.system.model.vo.NoticeStatusVO;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户公告状态Mapper接口
|
* 用户公告状态Mapper接口
|
||||||
@@ -13,4 +17,10 @@ import org.apache.ibatis.annotations.Mapper;
|
|||||||
@Mapper
|
@Mapper
|
||||||
public interface NoticeStatusMapper extends BaseMapper<NoticeStatus> {
|
public interface NoticeStatusMapper extends BaseMapper<NoticeStatus> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取未读的通知公告
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @return 公告列表
|
||||||
|
*/
|
||||||
|
List<NoticeStatusVO> listUnreadNotices(@Param("userId")Long userId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package com.youlai.boot.system.model.vo;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 阅读通知公告VO
|
||||||
|
*
|
||||||
|
* @author Theo
|
||||||
|
* @since 2024-9-8 01:25:06
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class NoticeDetailVO {
|
||||||
|
|
||||||
|
@Schema(description = "通知ID")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "通知标题")
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
@Schema(description = "通知内容")
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
@Schema(description = "通知类型")
|
||||||
|
private String noticeTypeLabel;
|
||||||
|
|
||||||
|
@Schema(description = "发布人")
|
||||||
|
private String releaseBy;
|
||||||
|
|
||||||
|
@Schema(description = "优先级(0-低 1-中 2-高)")
|
||||||
|
private Integer priority;
|
||||||
|
|
||||||
|
@Schema(description = "发布状态(0-未发布 1已发布 2已撤回) 冗余字段,方便判断是否已经发布")
|
||||||
|
private Integer releaseStatus;
|
||||||
|
|
||||||
|
@Schema(description = "发布时间")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private LocalDateTime releaseTime;
|
||||||
|
}
|
||||||
@@ -14,9 +14,12 @@ import lombok.Data;
|
|||||||
public class NoticeStatusVO {
|
public class NoticeStatusVO {
|
||||||
|
|
||||||
@Schema(description = "公告ID")
|
@Schema(description = "公告ID")
|
||||||
private Long noticeId;
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "公告标题")
|
||||||
|
private String title;
|
||||||
|
|
||||||
@Schema(description = "是否已读")
|
@Schema(description = "是否已读")
|
||||||
private Boolean read;
|
private Integer readStatus;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ public class NoticeVO implements Serializable {
|
|||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Schema(description = "通知标题")
|
@Schema(description = "通知标题")
|
||||||
private String title;
|
private String title;
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import com.youlai.boot.system.model.entity.Notice;
|
|||||||
import com.youlai.boot.system.model.form.NoticeForm;
|
import com.youlai.boot.system.model.form.NoticeForm;
|
||||||
import com.youlai.boot.system.model.query.NoticeQuery;
|
import com.youlai.boot.system.model.query.NoticeQuery;
|
||||||
import com.youlai.boot.system.model.vo.NoticeVO;
|
import com.youlai.boot.system.model.vo.NoticeVO;
|
||||||
|
import com.youlai.boot.system.model.vo.NoticeDetailVO;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通知公告服务类
|
* 通知公告服务类
|
||||||
@@ -70,4 +71,19 @@ public interface NoticeService extends IService<Notice> {
|
|||||||
* @return 是否撤回成功
|
* @return 是否撤回成功
|
||||||
*/
|
*/
|
||||||
boolean recallNotice(Long id);
|
boolean recallNotice(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 阅读通知公告
|
||||||
|
*
|
||||||
|
* @param id 通知公告ID
|
||||||
|
* @return 通知公告对象
|
||||||
|
*/
|
||||||
|
NoticeDetailVO readNotice(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取阅读时通知公告详情
|
||||||
|
* @param id 通知公告ID
|
||||||
|
* @return 通知公告详情
|
||||||
|
*/
|
||||||
|
NoticeDetailVO getReadNoticeDetail(Long id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.youlai.boot.system.service;
|
package com.youlai.boot.system.service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.youlai.boot.common.result.Result;
|
|
||||||
import com.youlai.boot.system.model.entity.NoticeStatus;
|
import com.youlai.boot.system.model.entity.NoticeStatus;
|
||||||
import com.youlai.boot.system.model.vo.NoticeStatusVO;
|
import com.youlai.boot.system.model.vo.NoticeStatusVO;
|
||||||
|
|
||||||
@@ -15,5 +14,15 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public interface NoticeStatusService extends IService<NoticeStatus> {
|
public interface NoticeStatusService extends IService<NoticeStatus> {
|
||||||
|
|
||||||
List<NoticeStatusVO> listNotices(Integer count);
|
/**
|
||||||
|
* 获取未读的通知公告
|
||||||
|
* @return 公告列表
|
||||||
|
*/
|
||||||
|
List<NoticeStatusVO> listUnreadNotices();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 全部标记为已读
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
boolean readAll();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import com.youlai.boot.system.model.entity.User;
|
|||||||
import com.youlai.boot.system.model.form.NoticeForm;
|
import com.youlai.boot.system.model.form.NoticeForm;
|
||||||
import com.youlai.boot.system.model.query.NoticeQuery;
|
import com.youlai.boot.system.model.query.NoticeQuery;
|
||||||
import com.youlai.boot.system.model.vo.NoticeVO;
|
import com.youlai.boot.system.model.vo.NoticeVO;
|
||||||
|
import com.youlai.boot.system.model.vo.NoticeDetailVO;
|
||||||
import com.youlai.boot.system.service.NoticeService;
|
import com.youlai.boot.system.service.NoticeService;
|
||||||
import com.youlai.boot.system.service.NoticeStatusService;
|
import com.youlai.boot.system.service.NoticeStatusService;
|
||||||
import com.youlai.boot.system.service.UserService;
|
import com.youlai.boot.system.service.UserService;
|
||||||
@@ -225,4 +226,41 @@ public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> impleme
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 阅读通知公告
|
||||||
|
* @param id 通知公告ID
|
||||||
|
* @return 通知公告表单对象
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public NoticeDetailVO readNotice(Long id) {
|
||||||
|
NoticeDetailVO noticeDetailVO = this.getReadNoticeDetail(id);
|
||||||
|
Assert.isTrue(noticeDetailVO != null && noticeDetailVO.getReleaseStatus() == 1, "公告不存在或未发布");
|
||||||
|
//获取当前登录用户
|
||||||
|
Long userId = SecurityUtils.getUserId();
|
||||||
|
LambdaQueryWrapper<NoticeStatus> queryWrapper = new LambdaQueryWrapper<NoticeStatus>()
|
||||||
|
.eq(NoticeStatus::getUserId, userId)
|
||||||
|
.eq(NoticeStatus::getNoticeId, id)
|
||||||
|
.eq(NoticeStatus::getReadStatus, 0);
|
||||||
|
NoticeStatus noticeStatus = noticeStatusService.getOne(queryWrapper);
|
||||||
|
if (noticeStatus != null) {
|
||||||
|
noticeStatus.setReadStatus(1);
|
||||||
|
noticeStatusService.updateById(noticeStatus);
|
||||||
|
}
|
||||||
|
return noticeDetailVO;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取阅读时通知公告详情
|
||||||
|
* @param id 通知公告ID
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public NoticeDetailVO getReadNoticeDetail(Long id) {
|
||||||
|
Assert.notNull(id, "公告ID不能为空");
|
||||||
|
NoticeDetailVO noticeDetailVO = this.baseMapper.getReadNoticeVO(id);
|
||||||
|
Assert.isTrue(noticeDetailVO != null, "公告不存在");
|
||||||
|
return noticeDetailVO;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
package com.youlai.boot.system.service.impl;
|
package com.youlai.boot.system.service.impl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.youlai.boot.common.result.Result;
|
import com.youlai.boot.core.security.util.SecurityUtils;
|
||||||
import com.youlai.boot.system.mapper.NoticeStatusMapper;
|
import com.youlai.boot.system.mapper.NoticeStatusMapper;
|
||||||
import com.youlai.boot.system.model.entity.NoticeStatus;
|
import com.youlai.boot.system.model.entity.NoticeStatus;
|
||||||
import com.youlai.boot.system.model.vo.NoticeStatusVO;
|
import com.youlai.boot.system.model.vo.NoticeStatusVO;
|
||||||
import com.youlai.boot.system.service.NoticeService;
|
|
||||||
import com.youlai.boot.system.service.NoticeStatusService;
|
import com.youlai.boot.system.service.NoticeStatusService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -23,13 +22,31 @@ import java.util.List;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class NoticeStatusServiceImpl extends ServiceImpl<NoticeStatusMapper, NoticeStatus> implements NoticeStatusService {
|
public class NoticeStatusServiceImpl extends ServiceImpl<NoticeStatusMapper, NoticeStatus> implements NoticeStatusService {
|
||||||
|
|
||||||
private final NoticeService noticeService;
|
private final NoticeStatusMapper noticeStatusMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取未读的通知公告
|
||||||
|
* @return 公告列表
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<NoticeStatusVO> listNotices(Integer count) {
|
public List<NoticeStatusVO> listUnreadNotices() {
|
||||||
LambdaQueryWrapper<NoticeStatus> queryWrapper = new LambdaQueryWrapper<>();
|
//获取当前登录用户
|
||||||
//获取当前用户
|
Long userId = SecurityUtils.getUserId();
|
||||||
queryWrapper.eq(NoticeStatus::getUserId, 1L);
|
return noticeStatusMapper.listUnreadNotices(userId);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 全部标记为已读
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean readAll() {
|
||||||
|
Long userId = SecurityUtils.getUserId();
|
||||||
|
LambdaUpdateWrapper<NoticeStatus> updateWrapper = new LambdaUpdateWrapper<>();
|
||||||
|
updateWrapper.eq(NoticeStatus::getUserId, userId);
|
||||||
|
updateWrapper.set(NoticeStatus::getReadStatus, 1);
|
||||||
|
return this.update(updateWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,4 +41,25 @@
|
|||||||
DESC
|
DESC
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="getReadNoticeVO" resultType="com.youlai.boot.system.model.vo.NoticeDetailVO">
|
||||||
|
SELECT
|
||||||
|
sn.id,
|
||||||
|
sn.title,
|
||||||
|
sn.content,
|
||||||
|
sn.notice_type,
|
||||||
|
su.nickname AS release_by,
|
||||||
|
sn.priority,
|
||||||
|
sn.release_status,
|
||||||
|
sn.release_time
|
||||||
|
FROM
|
||||||
|
sys_notice sn
|
||||||
|
LEFT JOIN
|
||||||
|
sys_user su ON su.id = sn.release_by
|
||||||
|
where
|
||||||
|
sn.is_deleted = 0
|
||||||
|
AND sn.id = #{id}
|
||||||
|
AND sn.release_status = 1
|
||||||
|
|
||||||
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
@@ -2,4 +2,22 @@
|
|||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.youlai.boot.system.mapper.NoticeStatusMapper">
|
<mapper namespace="com.youlai.boot.system.mapper.NoticeStatusMapper">
|
||||||
|
|
||||||
|
<select id="listUnreadNotices" resultType="com.youlai.boot.system.model.vo.NoticeStatusVO">
|
||||||
|
SELECT
|
||||||
|
sn.id,
|
||||||
|
sn.title,
|
||||||
|
sns.read_status
|
||||||
|
FROM
|
||||||
|
sys_notice_status sns
|
||||||
|
LEFT JOIN
|
||||||
|
sys_notice sn
|
||||||
|
ON
|
||||||
|
sn.id = sns.notice_id
|
||||||
|
WHERE
|
||||||
|
user_id = #{userId}
|
||||||
|
AND sns.read_status = 0
|
||||||
|
ORDER BY
|
||||||
|
sn.release_time DESC
|
||||||
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
Reference in New Issue
Block a user