Browse Source

feat: announcement

Blizzard 1 year ago
parent
commit
e2314f5e60

+ 104 - 0
blade-service-api/wt-okr-api/src/main/java/com/wtkj/entity/Announcement.java

@@ -0,0 +1,104 @@
+package com.wtkj.entity;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import org.springblade.core.mp.base.BaseEntity;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.time.LocalDateTime;
+
+/**
+ * @author Blizzard
+ * @create at 2023-09-23 11:05
+ * @describe
+ */
+@Data
+@TableName("blade_announcement")
+@EqualsAndHashCode(callSuper = true)
+public class Announcement extends BaseEntity {
+
+	private static final long serialVersionUID = 1L;
+
+
+	/**
+	 * 标题
+	 */
+	@TableField("title")
+	private String title;
+	/**
+	 * 内容
+	 */
+	@TableField("msg_content")
+	private String msgContent;
+	/**
+	 * 开始时间
+	 */
+	@TableField("start_time")
+	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+	private LocalDateTime startTime;
+
+	/**
+	 * 结束时间
+	 */
+	@TableField("end_time")
+	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+	private LocalDateTime endTime;
+	/**
+	 * 优先级(L低,M中,H高)
+	 */
+	@TableField("priority")
+	private String priority;
+	/**
+	 * 消息类型1:通知公告2:系统消息
+	 */
+	@TableField("msg_category")
+	private Integer msgCategory;
+	/**
+	 * 通告对象类型(1:指定用户,2:全体用户)
+	 */
+	@TableField("msg_type")
+	private Integer msgType;
+	/**
+	 * 发布状态(0未发布,1已发布,2已撤销)
+	 */
+	@TableField("send_status")
+	private Integer sendStatus;
+	/**
+	 * 发布时间
+	 */
+	@TableField("send_time")
+	private LocalDateTime sendTime;
+	/**
+	 * 撤销时间
+	 */
+	@TableField("cancelTime")
+	private LocalDateTime cancelTime;
+	/**
+	 * 打开方式(组件:component 路由:url)
+	 */
+	@TableField("open_type")
+	private String openType;
+	/**
+	 * 指定用户
+	 */
+	@TableField("user_ids")
+	private String userIds;
+	/**
+	 * 摘要
+	 */
+	@TableField("msg_abstract")
+	private String msgAbstract;
+	/**
+	 * 组件/路由 地址
+	 */
+	@TableField("open_page")
+	private String openPage;
+
+	@TableField("header")
+	private String header = "asset";
+}

+ 45 - 0
blade-service-api/wt-okr-api/src/main/java/com/wtkj/entity/AnnouncementSend.java

@@ -0,0 +1,45 @@
+package com.wtkj.entity;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import org.springblade.core.mp.base.BaseEntity;
+
+import java.util.Date;
+
+/**
+ * @author Blizzard
+ * @create at 2023-09-23 11:03
+ * @describe
+ */
+@Data
+@TableName("blade_announcement_send")
+@EqualsAndHashCode(callSuper = true)
+public class AnnouncementSend extends BaseEntity {
+
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * 通告ID
+	 */
+	@TableField("anno_id")
+	@JsonSerialize(using = ToStringSerializer.class)
+	private Long annoId;
+	/**
+	 * 用户id
+	 */
+	@TableField("user_id")
+	private Long userId;
+	/**
+	 * 阅读状态(0未读,1已读)
+	 */
+	@TableField("read_flag")
+	private Integer readFlag;
+
+	@TableField("read_time")
+	private Date readTime;
+
+}

+ 18 - 0
blade-service-api/wt-okr-api/src/main/java/com/wtkj/vo/AnnouncementSendVO.java

@@ -0,0 +1,18 @@
+package com.wtkj.vo;
+
+import com.wtkj.entity.Announcement;
+import com.wtkj.entity.AnnouncementSend;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * @author Blizzard
+ * @create at 2023-09-23 11:33
+ * @describe
+ */
+@EqualsAndHashCode(callSuper = true)
+@Data
+public class AnnouncementSendVO extends AnnouncementSend {
+
+	private Announcement announcement;
+}

+ 156 - 0
blade-service/wt-okr/src/main/java/com/wtkj/controller/AnnouncementController.java

@@ -0,0 +1,156 @@
+package com.wtkj.controller;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
+import com.wtkj.entity.Announcement;
+import com.wtkj.entity.AnnouncementSend;
+import com.wtkj.service.IAnnouncementSendService;
+import com.wtkj.service.IAnnouncementService;
+import com.wtkj.vo.AnnouncementSendVO;
+import com.wtkj.wrapper.AnnouncementSendWrapper;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import lombok.AllArgsConstructor;
+import org.springblade.core.mp.support.Condition;
+import org.springblade.core.mp.support.Query;
+import org.springblade.core.secure.utils.AuthUtil;
+import org.springblade.core.tool.api.R;
+import org.springblade.core.tool.utils.Func;
+import org.springframework.web.bind.annotation.*;
+
+import javax.validation.Valid;
+
+/**
+ * @author Blizzard
+ * @create at 2023-09-23 11:24
+ * @describe
+ */
+@RestController
+@AllArgsConstructor
+@RequestMapping("/announcement")
+@Api(value = "通知公告模块", tags = "通知公告模块")
+public class AnnouncementController {
+
+	private final IAnnouncementService announcementService;
+	private final IAnnouncementSendService announcementSendService;
+
+	/**
+	 * 详情
+	 */
+	@GetMapping("/detail")
+	@ApiOperationSupport(order = 1)
+	@ApiOperation(value = "详情", notes = "传入announcement")
+	public R<Announcement> detail(Announcement announcement) {
+		Announcement detail = announcementService.getOne(Condition.getQueryWrapper(announcement));
+		return R.data(detail);
+	}
+
+	/**
+	 * 分页 系统通告表
+	 */
+	@GetMapping("/page")
+	@ApiOperationSupport(order = 2)
+	@ApiOperation(value = "分页", notes = "传入announcement")
+	public R<IPage<Announcement>> list(Announcement announcement, Query query) {
+		IPage<Announcement> pages = announcementService.page(Condition.getPage(query), Condition.getQueryWrapper(announcement));
+		return R.data(pages);
+	}
+
+
+	/**
+	 * 新增或修改 系统通告表
+	 */
+	@PostMapping("/submit")
+	@ApiOperationSupport(order = 3)
+	@ApiOperation(value = "新增或修改", notes = "传入announcement")
+	public R submit(@Valid @RequestBody Announcement announcement) {
+		return R.status(announcementService.saveOrUpdate(announcement));
+	}
+
+
+	/**
+	 * 删除 系统通告表
+	 */
+	@PostMapping("/remove")
+	@ApiOperationSupport(order = 4)
+	@ApiOperation(value = "逻辑删除", notes = "传入ids")
+	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
+		return R.status(announcementService.deleteLogic(Func.toLongList(ids)));
+	}
+
+
+	@GetMapping("/send-detail")
+	@ApiOperationSupport(order = 5)
+	@ApiOperation(value = "发送详情", notes = "传入announcementSend")
+	public R<AnnouncementSendVO> detail(AnnouncementSend announcementSend) {
+		AnnouncementSend detail = announcementSendService.getOne(Condition.getQueryWrapper(announcementSend));
+		return R.data(AnnouncementSendWrapper.build().entityVO(detail));
+	}
+
+
+	/**
+	 * 自定义分页 获取用户消息列表
+	 */
+	@GetMapping("/send-page")
+	@ApiOperationSupport(order = 6)
+	@ApiOperation(value = "发送分页", notes = "")
+	public R<IPage<AnnouncementSendVO>> page(Query query) {
+		Long userId = AuthUtil.getUserId();
+		if (userId == -1L) {
+			return R.fail("获取用户信息失败!");
+		}
+		IPage<AnnouncementSend> pages = announcementSendService.selectAnnouncementSendPage(Condition.getPage(query), userId);
+		return R.data(AnnouncementSendWrapper.build().pageVO(pages));
+	}
+
+	/**
+	 * 获取用户未读消息数量
+	 */
+	@GetMapping("/send-notReadCount")
+	@ApiOperationSupport(order = 7)
+	@ApiOperation(value = "获取用户未读消息数量", notes = "")
+	public R notReadCount() {
+		Long userId = AuthUtil.getUserId();
+		if (userId == -1L) {
+			return R.fail("获取用户信息失败!");
+		}
+		return R.data(announcementSendService.notReadCount(userId));
+	}
+
+
+	/**
+	 * 用户阅读状态修改
+	 */
+	@PostMapping("/send-read")
+	@ApiOperationSupport(order = 8)
+	@ApiOperation(value = "用户阅读状态修改", notes = "传入id")
+	public R read(@ApiParam(value = "主键ID", required = true) @RequestParam Long id) {
+		return R.status(announcementSendService.updateReadFlag(id));
+	}
+
+	/**
+	 * 用户阅读状态修改
+	 */
+	@PostMapping("/send-allRead")
+	@ApiOperationSupport(order = 9)
+	@ApiOperation(value = "一键全部已读", notes = "")
+	public R allRead() {
+		Long userId = AuthUtil.getUserId();
+		if (userId == -1L) {
+			return R.fail("获取用户信息失败!");
+		}
+		return R.status(announcementSendService.allRead(userId));
+	}
+
+
+	/**
+	 * 删除 用户通告阅读标记表
+	 */
+	@PostMapping("/send-remove")
+	@ApiOperationSupport(order = 10)
+	@ApiOperation(value = "发送逻辑删除", notes = "传入ids")
+	public R removeSend(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
+		return R.status(announcementSendService.deleteLogic(Func.toLongList(ids)));
+	}
+}

+ 12 - 0
blade-service/wt-okr/src/main/java/com/wtkj/mapper/AnnouncementMapper.java

@@ -0,0 +1,12 @@
+package com.wtkj.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.wtkj.entity.Announcement;
+
+/**
+ * @author Blizzard
+ * @create at 2023-09-23 11:13
+ * @describe
+ */
+public interface AnnouncementMapper extends BaseMapper<Announcement> {
+}

+ 6 - 0
blade-service/wt-okr/src/main/java/com/wtkj/mapper/AnnouncementMapper.xml

@@ -0,0 +1,6 @@
+<?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="com.wtkj.mapper.AnnouncementMapper">
+
+
+</mapper>

+ 20 - 0
blade-service/wt-okr/src/main/java/com/wtkj/mapper/AnnouncementSendMapper.java

@@ -0,0 +1,20 @@
+package com.wtkj.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.wtkj.entity.AnnouncementSend;
+
+import java.util.List;
+
+/**
+ * @author Blizzard
+ * @create at 2023-09-23 11:15
+ * @describe
+ */
+public interface AnnouncementSendMapper extends BaseMapper<AnnouncementSend> {
+	List<AnnouncementSend> selectAnnouncementSendPage(IPage<AnnouncementSend> page, Long userId);
+
+	Integer notReadCount(Long userId);
+
+	List<AnnouncementSend> allNotRead(Long userId);
+}

+ 18 - 0
blade-service/wt-okr/src/main/java/com/wtkj/mapper/AnnouncementSendMapper.xml

@@ -0,0 +1,18 @@
+<?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="com.wtkj.mapper.AnnouncementSendMapper">
+
+
+    <select id="allNotRead" resultType="com.wtkj.entity.AnnouncementSend">
+        select * from blade_announcement_send where is_deleted = 0 and user_id = #{userId} and read_flag=0
+    </select>
+
+    <select id="notReadCount" resultType="java.lang.Integer">
+        select count(id) from blade_announcement_send where is_deleted = 0 and user_id = #{userId} and read_flag=0
+    </select>
+
+    <select id="selectAnnouncementSendPage" resultType="com.wtkj.entity.AnnouncementSend">
+        select * from blade_announcement_send where is_deleted = 0 and user_id = #{userId} order by
+        read_flag,create_time desc
+    </select>
+</mapper>

+ 38 - 0
blade-service/wt-okr/src/main/java/com/wtkj/service/IAnnouncementSendService.java

@@ -0,0 +1,38 @@
+package com.wtkj.service;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.wtkj.entity.AnnouncementSend;
+import org.springblade.core.mp.base.BaseService;
+
+/**
+ * @author Blizzard
+ * @create at 2023-09-23 11:22
+ * @describe
+ */
+public interface IAnnouncementSendService extends BaseService<AnnouncementSend> {
+	IPage<AnnouncementSend> selectAnnouncementSendPage(IPage<AnnouncementSend> page, Long userId);
+
+	/**
+	 * 获取用户未读数量
+	 *
+	 * @param userId
+	 * @return
+	 */
+	Integer notReadCount(Long userId);
+
+	/**
+	 * 用户阅读状态修改
+	 *
+	 * @param id
+	 * @return
+	 */
+	Boolean updateReadFlag(Long id);
+
+	/**
+	 * 一键全部消息已读
+	 *
+	 * @param userId
+	 * @return
+	 */
+	Boolean allRead(Long userId);
+}

+ 12 - 0
blade-service/wt-okr/src/main/java/com/wtkj/service/IAnnouncementService.java

@@ -0,0 +1,12 @@
+package com.wtkj.service;
+
+import com.wtkj.entity.Announcement;
+import org.springblade.core.mp.base.BaseService;
+
+/**
+ * @author Blizzard
+ * @create at 2023-09-23 11:20
+ * @describe
+ */
+public interface IAnnouncementService extends BaseService<Announcement> {
+}

+ 60 - 0
blade-service/wt-okr/src/main/java/com/wtkj/service/impl/AnnouncementSendServiceImpl.java

@@ -0,0 +1,60 @@
+package com.wtkj.service.impl;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.wtkj.entity.AnnouncementSend;
+import com.wtkj.mapper.AnnouncementSendMapper;
+import com.wtkj.service.IAnnouncementSendService;
+import lombok.AllArgsConstructor;
+import org.springblade.core.mp.base.BaseServiceImpl;
+import org.springblade.core.tool.utils.DateUtil;
+import org.springblade.core.tool.utils.ObjectUtil;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+
+import java.util.List;
+
+/**
+ * @author Blizzard
+ * @create at 2023-09-23 11:22
+ * @describe
+ */
+@Service
+@AllArgsConstructor
+public class AnnouncementSendServiceImpl extends BaseServiceImpl<AnnouncementSendMapper, AnnouncementSend> implements IAnnouncementSendService {
+	@Override
+	public IPage<AnnouncementSend> selectAnnouncementSendPage(IPage<AnnouncementSend> page, Long userId) {
+		return page.setRecords(baseMapper.selectAnnouncementSendPage(page, userId));
+	}
+
+	@Override
+	public Integer notReadCount(Long userId) {
+		return baseMapper.notReadCount(userId);
+	}
+
+	@Override
+	public Boolean updateReadFlag(Long id) {
+		boolean flag = false;
+		AnnouncementSend announcementSend = this.getById(id);
+		if (ObjectUtil.isNotEmpty(announcementSend)) {
+			if (announcementSend.getReadFlag() == 0) {//还未阅读
+				announcementSend.setReadFlag(1);
+				announcementSend.setReadTime(DateUtil.now());
+				flag = this.updateById(announcementSend);
+			}
+		}
+		return flag;
+	}
+
+	@Override
+	public Boolean allRead(Long userId) {
+		boolean flag = false;
+		List<AnnouncementSend> list = baseMapper.allNotRead(userId);
+		if (!CollectionUtils.isEmpty(list)) {
+			list.forEach(e -> e.setReadFlag(1));
+			flag = this.updateBatchById(list);
+		}
+		return flag;
+	}
+
+
+}

+ 18 - 0
blade-service/wt-okr/src/main/java/com/wtkj/service/impl/AnnouncementServiceImpl.java

@@ -0,0 +1,18 @@
+package com.wtkj.service.impl;
+
+import com.wtkj.entity.Announcement;
+import com.wtkj.mapper.AnnouncementMapper;
+import com.wtkj.service.IAnnouncementService;
+import lombok.AllArgsConstructor;
+import org.springblade.core.mp.base.BaseServiceImpl;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author Blizzard
+ * @create at 2023-09-23 11:21
+ * @describe
+ */
+@Service
+@AllArgsConstructor
+public class AnnouncementServiceImpl extends BaseServiceImpl<AnnouncementMapper, Announcement> implements IAnnouncementService {
+}

+ 39 - 0
blade-service/wt-okr/src/main/java/com/wtkj/wrapper/AnnouncementSendWrapper.java

@@ -0,0 +1,39 @@
+package com.wtkj.wrapper;
+
+import com.wtkj.entity.Announcement;
+import com.wtkj.entity.AnnouncementSend;
+import com.wtkj.service.IAnnouncementService;
+import com.wtkj.vo.AnnouncementSendVO;
+import org.springblade.core.mp.support.BaseEntityWrapper;
+import org.springblade.core.tool.utils.BeanUtil;
+import org.springblade.core.tool.utils.SpringUtil;
+
+import java.util.Objects;
+
+/**
+ * @author Blizzard
+ * @create at 2023-09-23 11:52
+ * @describe
+ */
+public class AnnouncementSendWrapper extends BaseEntityWrapper<AnnouncementSend, AnnouncementSendVO> {
+
+	private static IAnnouncementService announcementService;
+
+	public static AnnouncementSendWrapper build() {
+		announcementService = SpringUtil.getBean(IAnnouncementService.class);
+		return new AnnouncementSendWrapper();
+	}
+
+	@Override
+	public AnnouncementSendVO entityVO(AnnouncementSend entity) {
+		AnnouncementSendVO vo = Objects.requireNonNull(BeanUtil.copy(entity, AnnouncementSendVO.class));
+		Long annoId = entity.getAnnoId();
+		if (annoId != null) {
+			Announcement byId = announcementService.getById(annoId);
+			if (byId != null) {
+				vo.setAnnouncement(byId);
+			}
+		}
+		return vo;
+	}
+}