单元测试完善,service方法名修改 #11

Merged
baladiwei merged 1 commits from wanjia9506/gitlink-notification-system:dev_gitlink_model into master 2021-09-07 10:48:04 +08:00
6 changed files with 78 additions and 68 deletions

View File

@ -10,15 +10,15 @@ import java.util.List;
public interface SysNotificationMapper extends BaseMapper<SysNotification> {
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,

View File

@ -7,9 +7,9 @@ import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
public interface SysNotificationService extends IService<SysNotification> {
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);

View File

@ -13,12 +13,12 @@ import java.util.List;
public class SysNotificationServiceImpl extends ServiceImpl<SysNotificationMapper, SysNotification> 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);
}

View File

@ -12,15 +12,16 @@
</update>
<update id="createNewTable" parameterType="String">
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`))
</update>
</mapper>

View File

@ -26,93 +26,93 @@
</delete>
<insert id="insert" parameterType="cn.org.gitlink.notification.model.dao.entity.SysNotification" >
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>
<insert id="insertSelective" parameterType="cn.org.gitlink.notification.model.dao.entity.SysNotification" >
insert into ${platform}_sys_notification
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
<if test="record.id != null" >
id,
</if>
<if test="sender != null" >
<if test="record.sender != null" >
sender,
</if>
<if test="receiver != null" >
<if test="record.receiver != null" >
receiver,
</if>
<if test="content != null" >
<if test="record.content != null" >
content,
</if>
<if test="notificationUrl != null" >
<if test="record.notificationUrl != null" >
notification_url,
</if>
<if test="createdAt != null" >
<if test="record.createdAt != null" >
created_at,
</if>
<if test="status != null" >
<if test="record.status != null" >
status,
</if>
<if test="isDelete != null" >
<if test="record.isDelete != null" >
is_delete,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=INTEGER},
<if test="record.id != null" >
#{record.id,jdbcType=INTEGER},
</if>
<if test="sender != null" >
#{sender,jdbcType=INTEGER},
<if test="record.sender != null" >
#{record.sender,jdbcType=INTEGER},
</if>
<if test="receiver != null" >
#{receiver,jdbcType=INTEGER},
<if test="record.receiver != null" >
#{record.receiver,jdbcType=INTEGER},
</if>
<if test="content != null" >
#{content,jdbcType=VARCHAR},
<if test="record.content != null" >
#{record.content,jdbcType=VARCHAR},
</if>
<if test="notificationUrl != null" >
#{notificationUrl,jdbcType=VARCHAR},
<if test="record.notificationUrl != null" >
#{record.notificationUrl,jdbcType=VARCHAR},
</if>
<if test="createdAt != null" >
#{createdAt,jdbcType=TIMESTAMP},
<if test="record.createdAt != null" >
#{record.createdAt,jdbcType=TIMESTAMP},
</if>
<if test="status != null" >
#{status,jdbcType=TINYINT},
<if test="record.status != null" >
#{record.status,jdbcType=TINYINT},
</if>
<if test="isDelete != null" >
#{isDelete,jdbcType=BIT},
<if test="record.isDelete != null" >
#{record.isDelete,jdbcType=BIT},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="cn.org.gitlink.notification.model.dao.entity.SysNotification" >
update ${platform}_sys_notification
<set >
<if test="sender != null" >
sender = #{sender,jdbcType=INTEGER},
<if test="record.sender != null" >
sender = #{record.sender,jdbcType=INTEGER},
</if>
<if test="receiver != null" >
receiver = #{receiver,jdbcType=INTEGER},
<if test="record.receiver != null" >
receiver = #{record.receiver,jdbcType=INTEGER},
</if>
<if test="content != null" >
content = #{content,jdbcType=VARCHAR},
<if test="record.content != null" >
content = #{record.content,jdbcType=VARCHAR},
</if>
<if test="notificationUrl != null" >
notification_url = #{notificationUrl,jdbcType=VARCHAR},
<if test="record.notificationUrl != null" >
notification_url = #{record.notificationUrl,jdbcType=VARCHAR},
</if>
<if test="createdAt != null" >
created_at = #{createdAt,jdbcType=TIMESTAMP},
<if test="record.createdAt != null" >
created_at = #{record.createdAt,jdbcType=TIMESTAMP},
</if>
<if test="status != null" >
status = #{status,jdbcType=TINYINT},
<if test="record.status != null" >
status = #{record.status,jdbcType=TINYINT},
</if>
<if test="isDelete != null" >
is_delete = #{isDelete,jdbcType=BIT},
<if test="record.isDelete != null" >
is_delete = #{record.isDelete,jdbcType=BIT},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
where id = #{record.id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="cn.org.gitlink.notification.model.dao.entity.SysNotification" >
update ${platform}_sys_notification
@ -138,7 +138,7 @@
where receiver = #{receiver} AND status = #{status}
ORDER BY id DESC
</select>
<select id="getSysNotificationPageList" resultMap="BaseResultMap">
<select id="getSysNotificationPageList" parameterType="cn.org.gitlink.notification.model.dao.entity.SysNotification" resultMap="BaseResultMap">
select * FROM ${platform}_sys_notification
where receiver = #{receiver} AND is_delete = -1
ORDER BY id DESC

View File

@ -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<SysNotification> sysNotificationList = sysNotificationService.getUnreadSysNotificationsList("gitlink", 100);
Page<SysNotification> 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