🐛 修复文章被删除,消息中心残留未读消息问题(如文章被删除则清除相关未读消息通知)

This commit is contained in:
ronger 2022-05-26 15:43:53 +08:00
parent f2cd5f82e5
commit cc23959133
5 changed files with 29 additions and 0 deletions

View File

@ -58,4 +58,12 @@ public interface NotificationMapper extends Mapper<Notification> {
* @return
*/
Integer readAllNotification(@Param("idUser") Integer idUser);
/**
* 删除相关未读消息
* @param dataId
* @param dataType
* @return
*/
Integer deleteUnreadNotification(@Param("dataId") Integer dataId, @Param("dataType") String dataType);
}

View File

@ -58,4 +58,12 @@ public interface NotificationService extends Service<Notification> {
* @throws BaseApiException
*/
Integer readAllNotification() throws BaseApiException;
/**
* 删除相关未读消息
* @param dataId
* @param dataType
* @return
*/
Integer deleteUnreadNotification(Integer dataId, String dataType);
}

View File

@ -10,6 +10,7 @@ import com.rymcu.forest.entity.User;
import com.rymcu.forest.lucene.service.LuceneService;
import com.rymcu.forest.mapper.ArticleMapper;
import com.rymcu.forest.service.ArticleService;
import com.rymcu.forest.service.NotificationService;
import com.rymcu.forest.service.TagService;
import com.rymcu.forest.service.UserService;
import com.rymcu.forest.util.*;
@ -43,6 +44,8 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
private UserService userService;
@Resource
private LuceneService luceneService;
@Resource
private NotificationService notificationService;
@Value("${resource.domain}")
private String domain;
@ -257,6 +260,8 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
articleMapper.deleteTagArticle(id);
// 删除文章内容表
articleMapper.deleteArticleContent(id);
// 删除相关未读消息
notificationService.deleteUnreadNotification(id, NotificationConstant.PostArticle);
}
@Override

View File

@ -77,4 +77,9 @@ public class NotificationServiceImpl extends AbstractService<Notification> imple
public Integer readAllNotification() throws BaseApiException {
return notificationMapper.readAllNotification(Objects.requireNonNull(UserUtils.getCurrentUserByToken()).getIdUser());
}
@Override
public Integer deleteUnreadNotification(Integer dataId, String dataType) {
return notificationMapper.deleteUnreadNotification(dataId, dataType);
}
}

View File

@ -28,6 +28,9 @@
<update id="readAllNotification">
update forest_notification set has_read = '1' where id_user = #{idUser} and has_read = '0'
</update>
<delete id="deleteUnreadNotification">
delete from forest_notification where has_read = '0' and data_id = #{dataId} and data_type = #{dataType}
</delete>
<select id="selectUnreadNotifications" resultMap="BaseResultMapper">
select * from forest_notification where has_read = '0' and id_user = #{idUser} order by created_time desc
</select>