diff --git a/common/src/main/java/cn/org/gitlink/notification/common/constant/NotificationSystemConstant.java b/common/src/main/java/cn/org/gitlink/notification/common/constant/NotificationSystemConstant.java index 58d6c40..1424d54 100644 --- a/common/src/main/java/cn/org/gitlink/notification/common/constant/NotificationSystemConstant.java +++ b/common/src/main/java/cn/org/gitlink/notification/common/constant/NotificationSystemConstant.java @@ -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 PLATFORM_CODE_MAP = new HashMap() { { put("gitlink", PLATFORM_CODE_GITLINK); put("hehui", PLATFORM_CODE_HEHUI); + put("osredm", PLATFORM_CODE_OSREDM); } }; diff --git a/db/osredm-gns-notification.sql b/db/osredm-gns-notification.sql new file mode 100644 index 0000000..582c756 --- /dev/null +++ b/db/osredm-gns-notification.sql @@ -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 '额外信息(备用字段)'; \ No newline at end of file diff --git a/executor/src/main/java/cn/org/gitlink/notification/executor/service/email/EmailService.java b/executor/src/main/java/cn/org/gitlink/notification/executor/service/email/EmailService.java index ae533a0..aa46ef5 100644 --- a/executor/src/main/java/cn/org/gitlink/notification/executor/service/email/EmailService.java +++ b/executor/src/main/java/cn/org/gitlink/notification/executor/service/email/EmailService.java @@ -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); } } diff --git a/middleware/end_docker_compose.sh b/middleware/end_docker_compose.sh old mode 100755 new mode 100644 diff --git a/middleware/services.yml b/middleware/services.yml index bb1bb8f..3ed5fd8 100644 --- a/middleware/services.yml +++ b/middleware/services.yml @@ -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 diff --git a/middleware/start_docker_compose.sh b/middleware/start_docker_compose.sh old mode 100755 new mode 100644 diff --git a/model/src/main/java/cn/org/gitlink/notification/model/dao/mapper/SysNotificationMapper.java b/model/src/main/java/cn/org/gitlink/notification/model/dao/mapper/SysNotificationMapper.java index bffd80f..88d5d37 100644 --- a/model/src/main/java/cn/org/gitlink/notification/model/dao/mapper/SysNotificationMapper.java +++ b/model/src/main/java/cn/org/gitlink/notification/model/dao/mapper/SysNotificationMapper.java @@ -39,6 +39,7 @@ public interface SysNotificationMapper extends BaseMapper { List 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); diff --git a/model/src/main/java/cn/org/gitlink/notification/model/service/notification/SysNotificationService.java b/model/src/main/java/cn/org/gitlink/notification/model/service/notification/SysNotificationService.java index adc99b1..0c92047 100644 --- a/model/src/main/java/cn/org/gitlink/notification/model/service/notification/SysNotificationService.java +++ b/model/src/main/java/cn/org/gitlink/notification/model/service/notification/SysNotificationService.java @@ -36,16 +36,17 @@ public interface SysNotificationService extends IService { /** * 获取消息列表 * - * @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 getNotification(String platform, Integer receiver, Integer status, Integer type, Integer page, Integer size) throws Exception; + Page getNotification(String platform, Integer receiver, Integer status, Integer type, String source, Integer page, Integer size) throws Exception; /** * @Description: 批量删除系统消息 diff --git a/model/src/main/java/cn/org/gitlink/notification/model/service/notification/impl/SysNotificationServiceImpl.java b/model/src/main/java/cn/org/gitlink/notification/model/service/notification/impl/SysNotificationServiceImpl.java index 79a059c..5cf17cd 100644 --- a/model/src/main/java/cn/org/gitlink/notification/model/service/notification/impl/SysNotificationServiceImpl.java +++ b/model/src/main/java/cn/org/gitlink/notification/model/service/notification/impl/SysNotificationServiceImpl.java @@ -28,7 +28,7 @@ public class SysNotificationServiceImpl extends ServiceImpl sysNotificationList = new ArrayList<>(); List list = Arrays.asList(newSysNotificationVo.getReceivers().split(",")); for (String receiver : list) { @@ -51,7 +51,7 @@ public class SysNotificationServiceImpl extends ServiceImpl 0) { this.delUserCache(platform, receiver); @@ -60,7 +60,7 @@ public class SysNotificationServiceImpl extends ServiceImpl getNotification(String platform, Integer receiver, Integer status, Integer type, Integer page, Integer size) throws Exception { + public Page 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 pageItem = new Page(page, size); List 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 0) { this.delUserCache(platform, receiver); diff --git a/model/src/main/resources/mapper/notification/SysNotificationMapper.xml b/model/src/main/resources/mapper/notification/SysNotificationMapper.xml index 6dfbd6b..87a5808 100644 --- a/model/src/main/resources/mapper/notification/SysNotificationMapper.xml +++ b/model/src/main/resources/mapper/notification/SysNotificationMapper.xml @@ -202,6 +202,9 @@ and status = #{status} + + and source = #{source} + ORDER BY id DESC diff --git a/model/src/test/java/cn/org/gitlink/notification/model/service/notification/ServiceTests.java b/model/src/test/java/cn/org/gitlink/notification/model/service/notification/ServiceTests.java index 9aae278..d1ab2d7 100644 --- a/model/src/test/java/cn/org/gitlink/notification/model/service/notification/ServiceTests.java +++ b/model/src/test/java/cn/org/gitlink/notification/model/service/notification/ServiceTests.java @@ -28,7 +28,7 @@ public class ServiceTests { @Test public void testSysNotificationService() throws Exception { int i = sysNotificationService.getNotificationCount("gitlink", 234,1,1); - Page sysNotificationPage = sysNotificationService.getNotification("gitlink", 100,1,1,1,20); + Page sysNotificationPage = sysNotificationService.getNotification("gitlink", 100,1,1, "IssueChanged", 1,20); NewSysNotificationVo newSysNotificationVo = new NewSysNotificationVo(); newSysNotificationVo.setSender(1); newSysNotificationVo.setReceivers("7,8"); diff --git a/reader/src/main/java/cn/org/gitlink/notification/reader/controller/NotificationController.java b/reader/src/main/java/cn/org/gitlink/notification/reader/controller/NotificationController.java index 4db22aa..5368bd3 100644 --- a/reader/src/main/java/cn/org/gitlink/notification/reader/controller/NotificationController.java +++ b/reader/src/main/java/cn/org/gitlink/notification/reader/controller/NotificationController.java @@ -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());