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 acec015..7bb57e6 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 @@ -10,15 +10,15 @@ import java.util.List; public interface SysNotificationMapper extends BaseMapper { int deleteByPrimaryKey(@Param("platform") String platform, Integer id); - int insert(@Param("platform") String platform, SysNotification record); + int insert(@Param("platform") String platform,@Param("record") SysNotification record); - int insertSelective(@Param("platform") String platform, SysNotification record); + int insertSelective(@Param("platform") String platform,@Param("record") SysNotification record); SysNotification selectByPrimaryKey(@Param("platform") String platform, Integer id); int updateByPrimaryKeySelective(@Param("platform") String platform, SysNotification record); - int updateByPrimaryKey(@Param("platform") String platform, SysNotification record); + int updateByPrimaryKey(@Param("platform") String platform,@Param("record") SysNotification record); int updateStatusByNotificationId(@Param("platform") String platform, @Param("notificationId") Integer notificationId, 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 8d5b107..48f9f2a 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 @@ -7,9 +7,9 @@ import com.baomidou.mybatisplus.extension.service.IService; import java.util.List; public interface SysNotificationService extends IService { - int insertSysNotification(String platform, SysNotification sysNotification); + int addSysNotificationForUsers(String platform, SysNotification sysNotification); - int updateStatusByNotificationId(String platform, Integer notificationId, Byte status); + int changeStatusByNotificationIds(String platform, Integer notificationId, Byte status); int getNewSysNotificationNumber(String platform, Integer receiver); 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 6da6eb2..c50fb85 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 @@ -13,12 +13,12 @@ import java.util.List; public class SysNotificationServiceImpl extends ServiceImpl implements SysNotificationService { @Override - public int insertSysNotification(String platform, SysNotification sysNotification) { + public int addSysNotificationForUsers(String platform, SysNotification sysNotification) { return baseMapper.insertSelective(platform, sysNotification); } @Override - public int updateStatusByNotificationId(String platform, Integer notificationId, Byte status) { + public int changeStatusByNotificationIds(String platform, Integer notificationId, Byte status) { return baseMapper.updateStatusByNotificationId(platform, notificationId, status); } diff --git a/model/src/main/java/resources/mapper/notification/OperateTableMapper.xml b/model/src/main/java/resources/mapper/notification/OperateTableMapper.xml index 820952b..68e9285 100644 --- a/model/src/main/java/resources/mapper/notification/OperateTableMapper.xml +++ b/model/src/main/java/resources/mapper/notification/OperateTableMapper.xml @@ -12,15 +12,16 @@ CREATE TABLE ${tableName}_sys_notification ( - `id` int NOT NULL AUTO_INCREMENT, - `sender` int NOT NULL COMMENT '发送者id', - `receiver` int NOT NULL COMMENT '接受者id', - `content` text NOT NULL COMMENT '消息内容', - `notifacation_url` varchar(255) DEFAULT NULL COMMENT '消息跳转url', - `created_at` datetime DEFAULT NULL COMMENT '创建时间', - `status` tinyint(4) NOT NULL COMMENT '消息状态1-未读2-已读3-未删除4-已删除', - PRIMARY KEY (`id`), - KEY `index_on_receiver_and_status` (`receiver`,`status`), - KEY `index_on_status` (`status`)) + `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`)) diff --git a/model/src/main/java/resources/mapper/notification/SysNotificationMapper.xml b/model/src/main/java/resources/mapper/notification/SysNotificationMapper.xml index 05fd741..662592a 100644 --- a/model/src/main/java/resources/mapper/notification/SysNotificationMapper.xml +++ b/model/src/main/java/resources/mapper/notification/SysNotificationMapper.xml @@ -26,93 +26,93 @@ insert into ${platform}_sys_notification (id, sender, receiver, - content, notification_url, created_at, - status, is_delete) - values (#{id,jdbcType=INTEGER}, #{sender,jdbcType=INTEGER}, #{receiver,jdbcType=INTEGER}, - #{content,jdbcType=VARCHAR}, #{notificationUrl,jdbcType=VARCHAR}, #{createdAt,jdbcType=TIMESTAMP}, - #{status,jdbcType=TINYINT}, #{isDelete,jdbcType=BIT}) + content, notification_url, + status) + values (#{record.id,jdbcType=INTEGER}, #{record.sender,jdbcType=INTEGER}, #{record.receiver,jdbcType=INTEGER}, + #{record.content,jdbcType=VARCHAR}, #{record.notificationUrl,jdbcType=VARCHAR}, + #{record.status,jdbcType=TINYINT}) insert into ${platform}_sys_notification - + id, - + sender, - + receiver, - + content, - + notification_url, - + created_at, - + status, - + is_delete, - - #{id,jdbcType=INTEGER}, + + #{record.id,jdbcType=INTEGER}, - - #{sender,jdbcType=INTEGER}, + + #{record.sender,jdbcType=INTEGER}, - - #{receiver,jdbcType=INTEGER}, + + #{record.receiver,jdbcType=INTEGER}, - - #{content,jdbcType=VARCHAR}, + + #{record.content,jdbcType=VARCHAR}, - - #{notificationUrl,jdbcType=VARCHAR}, + + #{record.notificationUrl,jdbcType=VARCHAR}, - - #{createdAt,jdbcType=TIMESTAMP}, + + #{record.createdAt,jdbcType=TIMESTAMP}, - - #{status,jdbcType=TINYINT}, + + #{record.status,jdbcType=TINYINT}, - - #{isDelete,jdbcType=BIT}, + + #{record.isDelete,jdbcType=BIT}, update ${platform}_sys_notification - - sender = #{sender,jdbcType=INTEGER}, + + sender = #{record.sender,jdbcType=INTEGER}, - - receiver = #{receiver,jdbcType=INTEGER}, + + receiver = #{record.receiver,jdbcType=INTEGER}, - - content = #{content,jdbcType=VARCHAR}, + + content = #{record.content,jdbcType=VARCHAR}, - - notification_url = #{notificationUrl,jdbcType=VARCHAR}, + + notification_url = #{record.notificationUrl,jdbcType=VARCHAR}, - - created_at = #{createdAt,jdbcType=TIMESTAMP}, + + created_at = #{record.createdAt,jdbcType=TIMESTAMP}, - - status = #{status,jdbcType=TINYINT}, + + status = #{record.status,jdbcType=TINYINT}, - - is_delete = #{isDelete,jdbcType=BIT}, + + is_delete = #{record.isDelete,jdbcType=BIT}, - where id = #{id,jdbcType=INTEGER} + where id = #{record.id,jdbcType=INTEGER} update ${platform}_sys_notification @@ -138,7 +138,7 @@ where receiver = #{receiver} AND status = #{status} ORDER BY id DESC - select * FROM ${platform}_sys_notification where receiver = #{receiver} AND is_delete = -1 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 7f9f991..81ea2b6 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 @@ -3,10 +3,7 @@ package cn.org.gitlink.notification.model.service.notification; import cn.org.gitlink.notification.model.ModelApplicationTest; import cn.org.gitlink.notification.model.dao.entity.SysNotification; -import cn.org.gitlink.notification.model.service.notification.OperateTableService; -import cn.org.gitlink.notification.model.service.notification.SysNotificationService; -import javafx.application.Application; -import junit.textui.TestRunner; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.junit.Test; import org.junit.runner.RunWith; import org.slf4j.Logger; @@ -15,6 +12,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; +import java.util.List; + @RunWith(SpringRunner.class) @SpringBootTest(classes = ModelApplicationTest.class) @@ -28,9 +27,19 @@ public class ServiceTests { Logger logger = LoggerFactory.getLogger(this.getClass()); @Test - public void test1(){ + public void testSysNotificationService(){ int i = sysNotificationService.getNewSysNotificationNumber("gitlink", 234); - logger.info("id:" + i); + List sysNotificationList = sysNotificationService.getUnreadSysNotificationsList("gitlink", 100); + Page sysNotificationPage = sysNotificationService.getAllSysNotificationsPageList(1,10,"","gitlink", 100); + SysNotification sysNotification = new SysNotification(); + sysNotification.setSender((long) -1); + sysNotification.setReceiver((long) 100); + sysNotification.setContent("baladiwei 在 gitlink-notification-system 修改ReadMe 文件的标题"); + sysNotification.setNotificationUrl("www.baidu.com"); + int j = sysNotificationService.addSysNotificationForUsers("gitlink", sysNotification); + logger.info("insertResult:" + j); + int k = sysNotificationService.changeStatusByNotificationIds("gitlink", 1, (byte) 2); + logger.info("updateStatus:" + k); } @Test