Merge pull request '添加type字段,完善service细节,完善单元测试' (#13) from wanjia9506/gitlink-notification-system:dev_gitlink_model into master

This commit is contained in:
baladiwei 2021-09-07 15:29:18 +08:00
commit a005acaa23
7 changed files with 65 additions and 21 deletions

View File

@ -25,4 +25,8 @@ CREATE TABLE `gitlink_sys_notification` (
PRIMARY KEY (`id`),
KEY `index_on_receiver_and_status` (`receiver`,`status`),
KEY `index_on_status` (`status`)
) ENGINE=INNODB DEFAULT CHARSET=utf8mb3;
) ENGINE=INNODB DEFAULT CHARSET=utf8mb3;
--2021-09-07
ALTER TABLE gitlink_sys_notification ADD COLUMN
( `type` TINYINT(4) NOT NULL DEFAULT 1 COMMENT '消息类型: 1系统消息2@我');

View File

@ -21,6 +21,8 @@ public class SysNotification {
private Byte status;
private Byte type;
private Boolean isDelete;
public Integer getId() {
@ -79,6 +81,14 @@ public class SysNotification {
this.status = status;
}
public Byte getType() {
return type;
}
public void setType(Byte type) {
this.type = type;
}
public Boolean getIsDelete() {
return isDelete;
}

View File

@ -21,7 +21,7 @@ public interface SysNotificationMapper extends BaseMapper<SysNotification> {
int updateByPrimaryKey(@Param("platform") String platform,@Param("record") SysNotification record);
int updateStatusByNotificationId(@Param("platform") String platform,
@Param("notificationId") Integer notificationId,
@Param("notificationIds") String notificationIds,
@Param("status") Byte status);
int getNewSysNotificationNumber(@Param("platform") String platform,
@ -29,9 +29,14 @@ public interface SysNotificationMapper extends BaseMapper<SysNotification> {
List<SysNotification> getUnreadSysNotificationsList(@Param("platform") String platform,
@Param("receiver") Integer receiver,
@Param("status") byte status);
@Param("status") byte status,
@Param("notificationNumber") Integer notificationNumber);
List<SysNotification> getSysNotificationPageList(Page page, String orderBy,
@Param("platform") String platform,
@Param("receiver") Integer receiver);
int getSysNotificationNumberByType(@Param("platform") String platform,
@Param("receiver") Integer receiver,
@Param("type") Byte type);
}

View File

@ -9,11 +9,13 @@ import java.util.List;
public interface SysNotificationService extends IService<SysNotification> {
int addSysNotificationForUsers(String platform, SysNotification sysNotification);
int changeStatusByNotificationIds(String platform, Integer notificationId, Byte status);
int changeStatusByNotificationIds(String platform, String notificationIds, Byte status);
int getNewSysNotificationNumber(String platform, Integer receiver);
int getAllNewSysNotificationNumber(String platform, Integer receiver);
List<SysNotification> getUnreadSysNotificationsList(String platform, Integer receiver);
List<SysNotification> getUnreadSysNotificationsList(String platform, Integer receiver, Integer notificationNumber);
int getSysNotificationNumberByType(String platform, Integer receiver, Byte type);
Page<SysNotification> getAllSysNotificationsPageList(int curPage, int pageSize, String orderBy, String platform, Integer receiver);
}

View File

@ -18,21 +18,26 @@ public class SysNotificationServiceImpl extends ServiceImpl<SysNotificationMappe
}
@Override
public int changeStatusByNotificationIds(String platform, Integer notificationId, Byte status) {
return baseMapper.updateStatusByNotificationId(platform, notificationId, status);
public int changeStatusByNotificationIds(String platform, String notificationIds, Byte status) {
return baseMapper.updateStatusByNotificationId(platform, notificationIds, status);
}
@Override
public int getNewSysNotificationNumber(String platform, Integer receiver) {
public int getAllNewSysNotificationNumber(String platform, Integer receiver) {
return baseMapper.getNewSysNotificationNumber(platform, receiver);
}
@Override
public List<SysNotification> getUnreadSysNotificationsList(String platform, Integer receiver) {
List<SysNotification> sysNotificationList = baseMapper.getUnreadSysNotificationsList(platform, receiver, (byte) 1);
public List<SysNotification> getUnreadSysNotificationsList(String platform, Integer receiver, Integer notificationNumber) {
List<SysNotification> sysNotificationList = baseMapper.getUnreadSysNotificationsList(platform, receiver, (byte) 1, notificationNumber);
return sysNotificationList;
}
@Override
public int getSysNotificationNumberByType(String platform, Integer receiver, Byte type) {
return baseMapper.getSysNotificationNumberByType(platform, receiver, type);
}
@Override
public Page<SysNotification> getAllSysNotificationsPageList(int curPage, int pageSize, String orderBy, String platform, Integer receiver) {
Page page = new Page<SysNotification>(curPage, pageSize);

View File

@ -9,10 +9,11 @@
<result column="notification_url" property="notificationUrl" jdbcType="VARCHAR" />
<result column="created_at" property="createdAt" jdbcType="TIMESTAMP" />
<result column="status" property="status" jdbcType="TINYINT" />
<result column="type" property="type" jdbcType="TINYINT" />
<result column="is_delete" property="isDelete" jdbcType="BIT" />
</resultMap>
<sql id="Base_Column_List" >
id, sender, receiver, content, notification_url, created_at, status, is_delete
id, sender, receiver, content, notification_url, created_at, status, type, is_delete
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
@ -27,10 +28,10 @@
<insert id="insert" parameterType="cn.org.gitlink.notification.model.dao.entity.SysNotification" >
insert into ${platform}_sys_notification (id, sender, receiver,
content, notification_url,
status)
status, type)
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})
#{record.status,jdbcType=TINYINT}, #{record.type,jdbcType=TINYINT})
</insert>
<insert id="insertSelective" parameterType="cn.org.gitlink.notification.model.dao.entity.SysNotification" >
insert into ${platform}_sys_notification
@ -56,6 +57,9 @@
<if test="record.status != null" >
status,
</if>
<if test="record.type != null" >
type,
</if>
<if test="record.isDelete != null" >
is_delete,
</if>
@ -82,6 +86,9 @@
<if test="record.status != null" >
#{record.status,jdbcType=TINYINT},
</if>
<if test="record.type != null" >
#{record.type,jdbcType=TINYINT},
</if>
<if test="record.isDelete != null" >
#{record.isDelete,jdbcType=BIT},
</if>
@ -108,6 +115,9 @@
<if test="record.status != null" >
status = #{record.status,jdbcType=TINYINT},
</if>
<if test="record.type != null" >
status = #{record.type,jdbcType=TINYINT},
</if>
<if test="record.isDelete != null" >
is_delete = #{record.isDelete,jdbcType=BIT},
</if>
@ -122,21 +132,27 @@
notification_url = #{notificationUrl,jdbcType=VARCHAR},
created_at = #{createdAt,jdbcType=TIMESTAMP},
status = #{status,jdbcType=TINYINT},
type = #{type,jdbcType=TINYINT},
is_delete = #{isDelete,jdbcType=BIT}
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateStatusByNotificationId">
update ${platform}_sys_notification set status = #{status} where id = #{notificationId}
update ${platform}_sys_notification set status = #{status} where id in (${notificationIds})
</update>
<select id="getNewSysNotificationNumber" resultType="java.lang.Integer">
select count(`receiver`)
from ${platform}_sys_notification
where receiver = #{receiver} and status = 1
where receiver = #{receiver} and status = 1 AND is_delete = -1
</select>
<select id="getSysNotificationNumberByType" resultType="java.lang.Integer">
select count(*)
from ${platform}_sys_notification
where receiver = #{receiver} and status = 1 and `type` = #{type} AND is_delete = -1
</select>
<select id="getUnreadSysNotificationsList" resultMap="BaseResultMap">
select * FROM ${platform}_sys_notification
where receiver = #{receiver} AND status = #{status}
ORDER BY id DESC
where receiver = #{receiver} AND status = #{status} AND is_delete = -1
ORDER BY id DESC limit #{notificationNumber}
</select>
<select id="getSysNotificationPageList" parameterType="cn.org.gitlink.notification.model.dao.entity.SysNotification" resultMap="BaseResultMap">
select * FROM ${platform}_sys_notification

View File

@ -28,8 +28,8 @@ public class ServiceTests {
@Test
public void testSysNotificationService(){
int i = sysNotificationService.getNewSysNotificationNumber("gitlink", 234);
List<SysNotification> sysNotificationList = sysNotificationService.getUnreadSysNotificationsList("gitlink", 100);
int i = sysNotificationService.getAllNewSysNotificationNumber("gitlink", 234);
List<SysNotification> sysNotificationList = sysNotificationService.getUnreadSysNotificationsList("gitlink", 100, 20);
Page<SysNotification> sysNotificationPage = sysNotificationService.getAllSysNotificationsPageList(1,10,"","gitlink", 100);
SysNotification sysNotification = new SysNotification();
sysNotification.setSender((long) -1);
@ -38,8 +38,10 @@ public class ServiceTests {
sysNotification.setNotificationUrl("www.baidu.com");
int j = sysNotificationService.addSysNotificationForUsers("gitlink", sysNotification);
logger.info("insertResult:" + j);
int k = sysNotificationService.changeStatusByNotificationIds("gitlink", 1, (byte) 2);
int k = sysNotificationService.changeStatusByNotificationIds("gitlink", "2,3", (byte) 2);
logger.info("updateStatus:" + k);
int l = sysNotificationService.getSysNotificationNumberByType("gitlink", 100, (byte) 1);
logger.info("SysNotificationNumber:" + l);
}
@Test