Merge pull request '通知功能迭代' (#107) from wanjia9506/gitlink-notification-system:master into master
This commit is contained in:
commit
cd04c9a417
|
@ -13,10 +13,12 @@ public class NotificationSystemConstant {
|
|||
//平台编码
|
||||
public static final String PLATFORM_CODE_GITLINK = "gitlink"; //gitlink平台
|
||||
public static final String PLATFORM_CODE_HEHUI = "hehui"; //hehui平台
|
||||
public static final String PLATFORM_CODE_OSREDM = "osredm"; //红山开源平台
|
||||
public static final Map<String, String> PLATFORM_CODE_MAP = new HashMap<String, String>() {
|
||||
{
|
||||
put("gitlink", PLATFORM_CODE_GITLINK);
|
||||
put("hehui", PLATFORM_CODE_HEHUI);
|
||||
put("osredm", PLATFORM_CODE_OSREDM);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
|
||||
USE gitlink_notification;
|
||||
|
||||
-- 2022-02-14 新增红山平台
|
||||
INSERT INTO gns_platform_info(platform_code,platform_name,created_at,is_delete) VALUES('osredm','红山平台',NOW(),-1);
|
||||
|
||||
DROP TABLE IF EXISTS `osredm_sys_notification`;
|
||||
CREATE TABLE `osredm_sys_notification` (
|
||||
`id` INT NOT NULL AUTO_INCREMENT,
|
||||
`sender` INT(11) NOT NULL COMMENT '发送者id',
|
||||
`receiver` INT(11) NOT NULL COMMENT '接受者id',
|
||||
`content` TEXT NOT NULL COMMENT '消息内容:富文本',
|
||||
`notification_url` VARCHAR(2000) DEFAULT NULL COMMENT '消息跳转链接',
|
||||
`created_at` DATETIME NOT NULL DEFAULT NOW() COMMENT '创建时间',
|
||||
`status` TINYINT(4) NOT NULL DEFAULT 1 COMMENT '已读状态: 1未读,2已读',
|
||||
`is_delete` TINYINT(1) NOT NULL DEFAULT '-1' COMMENT '是否删除: -1未删除,1已删除',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `index_on_receiver_and_status` (`receiver`,`status`),
|
||||
KEY `index_on_status` (`status`)
|
||||
) ENGINE=INNODB DEFAULT CHARSET=utf8mb3;
|
||||
|
||||
-- 2021-09-10 区分系统消息类型
|
||||
ALTER TABLE osredm_sys_notification ADD COLUMN (`type` TINYINT(4) NOT NULL DEFAULT 1 COMMENT '消息类型: 1系统消息,2@我');
|
||||
|
||||
-- 2021-09-10 新增 source 字段区分消息来源、新增 extra 字段保存额外信息
|
||||
ALTER TABLE osredm_sys_notification ADD source varchar(250) NULL COMMENT '消息来源';
|
||||
ALTER TABLE osredm_sys_notification ADD extra TEXT NULL COMMENT '额外信息(备用字段)';
|
|
@ -95,7 +95,8 @@ public class EmailService {
|
|||
flag = true;
|
||||
unSentEmailSendRecord.setSentAt(new Date());
|
||||
unSentEmailSendRecord.setStatus(flag ? NotificationSystemConstant.EMAIL_SENT_SUCCESS : NotificationSystemConstant.EMAIL_SENT_FAIL);
|
||||
} catch (MessagingException e) {
|
||||
} catch (Exception e) {
|
||||
unSentEmailSendRecord.setStatus(NotificationSystemConstant.EMAIL_SENT_FAIL);
|
||||
logger.error("发送邮件失败,email: " + unSentEmailSendRecord.getEmail() + "\n" + e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ services:
|
|||
- ${SQL_SCRIPT_PATH}/gns-notification.sql:/docker-entrypoint-initdb.d/0001.sql
|
||||
- ${SQL_SCRIPT_PATH}/hehui-gns-notification.sql:/docker-entrypoint-initdb.d/0002.sql
|
||||
- ${SQL_SCRIPT_PATH}/gns-email.sql:/docker-entrypoint-initdb.d/0003.sql
|
||||
- ${SQL_SCRIPT_PATH}/osredm-gns-notification.sql:/docker-entrypoint-initdb.d/0004.sql
|
||||
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
|
||||
ports:
|
||||
- ${MYSQL_LOCAL_PORT}:3306
|
||||
|
|
|
@ -39,6 +39,7 @@ public interface SysNotificationMapper extends BaseMapper<SysNotification> {
|
|||
|
||||
List<SysNotification> getSysNotificationPageList(Page page, String orderBy,
|
||||
@Param("type") int type,
|
||||
@Param("source") String source,
|
||||
@Param("platform") String platform,
|
||||
@Param("receiver") Integer receiver,
|
||||
@Param("status") Integer status);
|
||||
|
|
|
@ -36,16 +36,17 @@ public interface SysNotificationService extends IService<SysNotification> {
|
|||
/**
|
||||
* 获取消息列表
|
||||
*
|
||||
* @param type 类型 -1 全部 1 系统消息、2 @我
|
||||
* @param page 页码
|
||||
* @param size 页大小
|
||||
* @param platform 平台编号
|
||||
* @param receiver 消息接收者
|
||||
* @param status 状态 -1 全部、1 未读 2 已读
|
||||
* @param type 类型 -1 全部 1 系统消息、2 @我
|
||||
* @param source
|
||||
* @param page 页码
|
||||
* @param size 页大小
|
||||
* @return
|
||||
*/
|
||||
|
||||
Page<SysNotification> getNotification(String platform, Integer receiver, Integer status, Integer type, Integer page, Integer size) throws Exception;
|
||||
Page<SysNotification> getNotification(String platform, Integer receiver, Integer status, Integer type, String source, Integer page, Integer size) throws Exception;
|
||||
|
||||
/**
|
||||
* @Description: 批量删除系统消息
|
||||
|
|
|
@ -28,7 +28,7 @@ public class SysNotificationServiceImpl extends ServiceImpl<SysNotificationMappe
|
|||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean sendNotification(NewSysNotificationVo newSysNotificationVo) throws Exception {
|
||||
public boolean sendNotification(NewSysNotificationVo newSysNotificationVo) {
|
||||
List<SysNotification> sysNotificationList = new ArrayList<>();
|
||||
List<String> list = Arrays.asList(newSysNotificationVo.getReceivers().split(","));
|
||||
for (String receiver : list) {
|
||||
|
@ -51,7 +51,7 @@ public class SysNotificationServiceImpl extends ServiceImpl<SysNotificationMappe
|
|||
}
|
||||
|
||||
@Override
|
||||
public int markNotificationAs(String platform, Integer receiver, String notificationIds, Integer status, Integer type) throws Exception {
|
||||
public int markNotificationAs(String platform, Integer receiver, String notificationIds, Integer status, Integer type) {
|
||||
int count = baseMapper.updateStatusByNotificationId(platform, receiver, notificationIds, status, type);
|
||||
if (count > 0) {
|
||||
this.delUserCache(platform, receiver);
|
||||
|
@ -60,7 +60,7 @@ public class SysNotificationServiceImpl extends ServiceImpl<SysNotificationMappe
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getNotificationCount(String platform, Integer receiver, Integer type, Integer status) throws Exception {
|
||||
public int getNotificationCount(String platform, Integer receiver, Integer type, Integer status) {
|
||||
String cacheKey = cacheKeyForCount(platform, receiver, type, status);
|
||||
Object foundResult = this.redisUtil.get(cacheKey);
|
||||
if (foundResult != null) {
|
||||
|
@ -73,7 +73,7 @@ public class SysNotificationServiceImpl extends ServiceImpl<SysNotificationMappe
|
|||
|
||||
|
||||
@Override
|
||||
public Page<SysNotification> getNotification(String platform, Integer receiver, Integer status, Integer type, Integer page, Integer size) throws Exception {
|
||||
public Page<SysNotification> getNotification(String platform, Integer receiver, Integer status, Integer type, String source, Integer page, Integer size) {
|
||||
String cacheKey = cacheKeyForPage(platform, receiver, type, status, page, size);
|
||||
Object foundResult = this.redisUtil.get(cacheKey);
|
||||
if (foundResult != null) {
|
||||
|
@ -82,7 +82,7 @@ public class SysNotificationServiceImpl extends ServiceImpl<SysNotificationMappe
|
|||
|
||||
Page<SysNotification> pageItem = new Page<SysNotification>(page, size);
|
||||
List<SysNotification> sysNotificationList = baseMapper.getSysNotificationPageList(
|
||||
pageItem, "", type, platform, receiver, status
|
||||
pageItem, "", type, source, platform, receiver, status
|
||||
);
|
||||
pageItem.setRecords(sysNotificationList);
|
||||
this.redisUtil.set(cacheKey, pageItem);
|
||||
|
@ -90,7 +90,7 @@ public class SysNotificationServiceImpl extends ServiceImpl<SysNotificationMappe
|
|||
}
|
||||
|
||||
@Override
|
||||
public int deleteNotifications(String platform, Integer receiver, String notificationIds, Integer type) throws Exception {
|
||||
public int deleteNotifications(String platform, Integer receiver, String notificationIds, Integer type) {
|
||||
int count = baseMapper.deleteNotificationByIds(platform, receiver, notificationIds, type);
|
||||
if (count > 0) {
|
||||
this.delUserCache(platform, receiver);
|
||||
|
|
|
@ -202,6 +202,9 @@
|
|||
<if test="status != -1">
|
||||
and status = #{status}
|
||||
</if>
|
||||
<if test="source != null and source != ''">
|
||||
and source = #{source}
|
||||
</if>
|
||||
ORDER BY id DESC
|
||||
</select>
|
||||
<update id="deleteNotificationByIds">
|
||||
|
|
|
@ -28,7 +28,7 @@ public class ServiceTests {
|
|||
@Test
|
||||
public void testSysNotificationService() throws Exception {
|
||||
int i = sysNotificationService.getNotificationCount("gitlink", 234,1,1);
|
||||
Page<SysNotification> sysNotificationPage = sysNotificationService.getNotification("gitlink", 100,1,1,1,20);
|
||||
Page<SysNotification> sysNotificationPage = sysNotificationService.getNotification("gitlink", 100,1,1, "IssueChanged", 1,20);
|
||||
NewSysNotificationVo newSysNotificationVo = new NewSysNotificationVo();
|
||||
newSysNotificationVo.setSender(1);
|
||||
newSysNotificationVo.setReceivers("7,8");
|
||||
|
|
|
@ -52,6 +52,9 @@ public class NotificationController {
|
|||
@ApiParam(value = "消息类型:值为-1时,获取全部信息;值为1时,获取系统消息;值为2时,获取@我消息", defaultValue = "-1")
|
||||
@RequestParam(name = "type", required = false, defaultValue = "-1") Integer type,
|
||||
|
||||
@ApiParam(value = "消息来源")
|
||||
@RequestParam(name = "source", required = false) String source,
|
||||
|
||||
@ApiParam(value = "页码:值为-1时(默认值),不开启分页;", required = false, defaultValue = "-1")
|
||||
@RequestParam(name = "page", required = false, defaultValue = "-1") Integer page,
|
||||
|
||||
|
@ -88,7 +91,7 @@ public class NotificationController {
|
|||
}
|
||||
|
||||
//分页的数据
|
||||
Page foundPage = notificationService.getNotification(platform, receiver, status, type, page, size);
|
||||
Page foundPage = notificationService.getNotification(platform, receiver, status, type, source, page, size);
|
||||
if (foundPage != null) {
|
||||
notificationListVo.setPageNum(foundPage.getCurrent());
|
||||
notificationListVo.setPageSize(foundPage.getSize());
|
||||
|
|
Loading…
Reference in New Issue