✨ 消息功能优化
This commit is contained in:
parent
5b66d56232
commit
5a8d158658
17
src/main/java/com/rymcu/vertical/dto/ArticleSearchDTO.java
Normal file
17
src/main/java/com/rymcu/vertical/dto/ArticleSearchDTO.java
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package com.rymcu.vertical.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ronger
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ArticleSearchDTO {
|
||||||
|
|
||||||
|
private String searchText;
|
||||||
|
|
||||||
|
private String topicUri;
|
||||||
|
|
||||||
|
private String tag;
|
||||||
|
|
||||||
|
}
|
@ -43,7 +43,7 @@ public class Notification implements Serializable,Cloneable {
|
|||||||
* 数据摘要
|
* 数据摘要
|
||||||
*/
|
*/
|
||||||
@Column(name = "data_summary")
|
@Column(name = "data_summary")
|
||||||
private String dataSummary ;
|
private String dataSummary;
|
||||||
/**
|
/**
|
||||||
* 是否已读
|
* 是否已读
|
||||||
*/
|
*/
|
||||||
|
@ -8,6 +8,9 @@ import javax.servlet.http.HttpServletRequest;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ronger
|
||||||
|
*/
|
||||||
public interface CommentService extends Service<Comment> {
|
public interface CommentService extends Service<Comment> {
|
||||||
|
|
||||||
List<CommentDTO> getArticleComments(Integer idArticle);
|
List<CommentDTO> getArticleComments(Integer idArticle);
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package com.rymcu.vertical.service;
|
package com.rymcu.vertical.service;
|
||||||
|
|
||||||
import com.rymcu.vertical.core.service.Service;
|
import com.rymcu.vertical.core.service.Service;
|
||||||
|
import com.rymcu.vertical.dto.NotificationDTO;
|
||||||
import com.rymcu.vertical.entity.Notification;
|
import com.rymcu.vertical.entity.Notification;
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ public interface NotificationService extends Service<Notification> {
|
|||||||
* @param idUser
|
* @param idUser
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<Notification> findNotifications(Integer idUser);
|
List<NotificationDTO> findNotifications(Integer idUser);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取消息数据
|
* 获取消息数据
|
||||||
@ -48,5 +48,5 @@ public interface NotificationService extends Service<Notification> {
|
|||||||
* 标记消息已读
|
* 标记消息已读
|
||||||
* @param id
|
* @param id
|
||||||
*/
|
*/
|
||||||
void readNotification(Integer id);
|
Integer readNotification(Integer id);
|
||||||
}
|
}
|
||||||
|
@ -62,19 +62,19 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
|
|||||||
} else {
|
} else {
|
||||||
list = articleMapper.selectArticles(searchDTO.getSearchText(), searchDTO.getTag(), searchDTO.getTopicUri());
|
list = articleMapper.selectArticles(searchDTO.getSearchText(), searchDTO.getTag(), searchDTO.getTopicUri());
|
||||||
}
|
}
|
||||||
list.forEach(article->{
|
list.forEach(article -> {
|
||||||
genArticle(article,0);
|
genArticle(article, 0);
|
||||||
});
|
});
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ArticleDTO findArticleDTOById(Integer id, Integer type) {
|
public ArticleDTO findArticleDTOById(Integer id, Integer type) {
|
||||||
ArticleDTO articleDTO = articleMapper.selectArticleDTOById(id,type);
|
ArticleDTO articleDTO = articleMapper.selectArticleDTOById(id, type);
|
||||||
if (articleDTO == null) {
|
if (articleDTO == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
articleDTO = genArticle(articleDTO,type);
|
articleDTO = genArticle(articleDTO, type);
|
||||||
return articleDTO;
|
return articleDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
|
|||||||
public List<ArticleDTO> findArticlesByTopicUri(String name) {
|
public List<ArticleDTO> findArticlesByTopicUri(String name) {
|
||||||
List<ArticleDTO> articleDTOS = articleMapper.selectArticlesByTopicUri(name);
|
List<ArticleDTO> articleDTOS = articleMapper.selectArticlesByTopicUri(name);
|
||||||
articleDTOS.forEach(articleDTO -> {
|
articleDTOS.forEach(articleDTO -> {
|
||||||
genArticle(articleDTO,0);
|
genArticle(articleDTO, 0);
|
||||||
});
|
});
|
||||||
return articleDTOS;
|
return articleDTOS;
|
||||||
}
|
}
|
||||||
@ -96,22 +96,22 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
|
|||||||
@Override
|
@Override
|
||||||
public List<ArticleDTO> findUserArticlesByIdUser(Integer idUser) {
|
public List<ArticleDTO> findUserArticlesByIdUser(Integer idUser) {
|
||||||
List<ArticleDTO> list = articleMapper.selectUserArticles(idUser);
|
List<ArticleDTO> list = articleMapper.selectUserArticles(idUser);
|
||||||
list.forEach(article->{
|
list.forEach(article -> {
|
||||||
genArticle(article,0);
|
genArticle(article, 0);
|
||||||
});
|
});
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = { UnsupportedEncodingException.class, BaseApiException.class })
|
@Transactional(rollbackFor = {UnsupportedEncodingException.class, BaseApiException.class})
|
||||||
public Map postArticle(ArticleDTO article, HttpServletRequest request) throws UnsupportedEncodingException, BaseApiException {
|
public Map postArticle(ArticleDTO article, HttpServletRequest request) throws UnsupportedEncodingException, BaseApiException {
|
||||||
Map map = new HashMap(1);
|
Map map = new HashMap(1);
|
||||||
if(StringUtils.isBlank(article.getArticleTitle())){
|
if (StringUtils.isBlank(article.getArticleTitle())) {
|
||||||
map.put("message","标题不能为空!");
|
map.put("message", "标题不能为空!");
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
if(StringUtils.isBlank(article.getArticleContent())){
|
if (StringUtils.isBlank(article.getArticleContent())) {
|
||||||
map.put("message","正文不能为空!");
|
map.put("message", "正文不能为空!");
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
String articleTitle = article.getArticleTitle();
|
String articleTitle = article.getArticleTitle();
|
||||||
@ -131,7 +131,7 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Article newArticle;
|
Article newArticle;
|
||||||
if(article.getIdArticle() == null || article.getIdArticle() == 0){
|
if (article.getIdArticle() == null || article.getIdArticle() == 0) {
|
||||||
newArticle = new Article();
|
newArticle = new Article();
|
||||||
newArticle.setArticleTitle(articleTitle);
|
newArticle.setArticleTitle(articleTitle);
|
||||||
newArticle.setArticleAuthorId(user.getIdUser());
|
newArticle.setArticleAuthorId(user.getIdUser());
|
||||||
@ -140,21 +140,21 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
|
|||||||
newArticle.setUpdatedTime(newArticle.getCreatedTime());
|
newArticle.setUpdatedTime(newArticle.getCreatedTime());
|
||||||
newArticle.setArticleStatus(article.getArticleStatus());
|
newArticle.setArticleStatus(article.getArticleStatus());
|
||||||
articleMapper.insertSelective(newArticle);
|
articleMapper.insertSelective(newArticle);
|
||||||
articleMapper.insertArticleContent(newArticle.getIdArticle(),articleContent,articleContentHtml);
|
articleMapper.insertArticleContent(newArticle.getIdArticle(), articleContent, articleContentHtml);
|
||||||
if (!ProjectConstant.ENV.equals(env) && defaultStatus.equals(newArticle.getArticleStatus())) {
|
if (!ProjectConstant.ENV.equals(env) && defaultStatus.equals(newArticle.getArticleStatus())) {
|
||||||
BaiDuUtils.sendSEOData(newArticle.getArticlePermalink());
|
BaiDuUtils.sendSEOData(newArticle.getArticlePermalink());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
newArticle = articleMapper.selectByPrimaryKey(article.getIdArticle());
|
newArticle = articleMapper.selectByPrimaryKey(article.getIdArticle());
|
||||||
if(!user.getIdUser().equals(newArticle.getArticleAuthorId())){
|
if (!user.getIdUser().equals(newArticle.getArticleAuthorId())) {
|
||||||
map.put("message","非法访问!");
|
map.put("message", "非法访问!");
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
newArticle.setArticleTitle(articleTitle);
|
newArticle.setArticleTitle(articleTitle);
|
||||||
newArticle.setArticleTags(articleTags);
|
newArticle.setArticleTags(articleTags);
|
||||||
newArticle.setArticleStatus(article.getArticleStatus());
|
newArticle.setArticleStatus(article.getArticleStatus());
|
||||||
newArticle.setUpdatedTime(new Date());
|
newArticle.setUpdatedTime(new Date());
|
||||||
articleMapper.updateArticleContent(newArticle.getIdArticle(),articleContent,articleContentHtml);
|
articleMapper.updateArticleContent(newArticle.getIdArticle(), articleContent, articleContentHtml);
|
||||||
if (!ProjectConstant.ENV.equals(env) && defaultStatus.equals(newArticle.getArticleStatus())) {
|
if (!ProjectConstant.ENV.equals(env) && defaultStatus.equals(newArticle.getArticleStatus())) {
|
||||||
BaiDuUtils.sendUpdateSEOData(newArticle.getArticlePermalink());
|
BaiDuUtils.sendUpdateSEOData(newArticle.getArticlePermalink());
|
||||||
}
|
}
|
||||||
@ -174,12 +174,12 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
|
|||||||
newArticle.setArticleLink("/draft/" + newArticle.getIdArticle());
|
newArticle.setArticleLink("/draft/" + newArticle.getIdArticle());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(StringUtils.isNotBlank(articleContentHtml)){
|
if (StringUtils.isNotBlank(articleContentHtml)) {
|
||||||
Integer length = articleContentHtml.length();
|
Integer length = articleContentHtml.length();
|
||||||
if(length > MAX_PREVIEW){
|
if (length > MAX_PREVIEW) {
|
||||||
length = MAX_PREVIEW;
|
length = MAX_PREVIEW;
|
||||||
}
|
}
|
||||||
String articlePreviewContent = articleContentHtml.substring(0,length);
|
String articlePreviewContent = articleContentHtml.substring(0, length);
|
||||||
newArticle.setArticlePreviewContent(Html2TextUtil.getContent(articlePreviewContent));
|
newArticle.setArticlePreviewContent(Html2TextUtil.getContent(articlePreviewContent));
|
||||||
}
|
}
|
||||||
articleMapper.updateByPrimaryKeySelective(newArticle);
|
articleMapper.updateByPrimaryKeySelective(newArticle);
|
||||||
@ -190,7 +190,7 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
|
|||||||
|
|
||||||
private String checkTags(String articleTags) {
|
private String checkTags(String articleTags) {
|
||||||
// 判断文章是否有标签
|
// 判断文章是否有标签
|
||||||
if(StringUtils.isBlank(articleTags)){
|
if (StringUtils.isBlank(articleTags)) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
// 判断是否存在系统配置的保留标签词
|
// 判断是否存在系统配置的保留标签词
|
||||||
@ -206,7 +206,7 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String articleTag: articleTagArr) {
|
for (String articleTag : articleTagArr) {
|
||||||
if (StringUtils.isBlank(articleTag)) {
|
if (StringUtils.isBlank(articleTag)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -223,13 +223,13 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Map delete(Integer id) {
|
public Map delete(Integer id) {
|
||||||
Map<String,String> map = new HashMap(1);
|
Map<String, String> map = new HashMap(1);
|
||||||
Integer result;
|
Integer result;
|
||||||
// 删除引用标签记录
|
// 删除引用标签记录
|
||||||
result = articleMapper.deleteTagArticle(id);
|
result = articleMapper.deleteTagArticle(id);
|
||||||
if (result > 0){
|
if (result > 0) {
|
||||||
result = articleMapper.deleteByPrimaryKey(id);
|
result = articleMapper.deleteByPrimaryKey(id);
|
||||||
if (result < 1){
|
if (result < 1) {
|
||||||
map.put("message", "删除失败!");
|
map.put("message", "删除失败!");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -261,8 +261,8 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
|
|||||||
public List<ArticleDTO> findDrafts() throws BaseApiException {
|
public List<ArticleDTO> findDrafts() throws BaseApiException {
|
||||||
User user = UserUtils.getWxCurrentUser();
|
User user = UserUtils.getWxCurrentUser();
|
||||||
List<ArticleDTO> list = articleMapper.selectDrafts(user.getIdUser());
|
List<ArticleDTO> list = articleMapper.selectDrafts(user.getIdUser());
|
||||||
list.forEach(article->{
|
list.forEach(article -> {
|
||||||
genArticle(article,0);
|
genArticle(article, 0);
|
||||||
});
|
});
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
@ -270,17 +270,17 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
|
|||||||
@Override
|
@Override
|
||||||
public List<ArticleDTO> findArticlesByIdPortfolio(Integer idPortfolio) {
|
public List<ArticleDTO> findArticlesByIdPortfolio(Integer idPortfolio) {
|
||||||
List<ArticleDTO> list = articleMapper.selectArticlesByIdPortfolio(idPortfolio);
|
List<ArticleDTO> list = articleMapper.selectArticlesByIdPortfolio(idPortfolio);
|
||||||
list.forEach(article->{
|
list.forEach(article -> {
|
||||||
genArticle(article,0);
|
genArticle(article, 0);
|
||||||
});
|
});
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ArticleDTO> selectUnbindArticles(Integer idPortfolio, String searchText, Integer idUser) {
|
public List<ArticleDTO> selectUnbindArticles(Integer idPortfolio, String searchText, Integer idUser) {
|
||||||
List<ArticleDTO> list = articleMapper.selectUnbindArticlesByIdPortfolio(idPortfolio,searchText,idUser);
|
List<ArticleDTO> list = articleMapper.selectUnbindArticlesByIdPortfolio(idPortfolio, searchText, idUser);
|
||||||
list.forEach(article->{
|
list.forEach(article -> {
|
||||||
genArticle(article,0);
|
genArticle(article, 0);
|
||||||
});
|
});
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
@ -296,7 +296,7 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
|
|||||||
article.setTags(tags);
|
article.setTags(tags);
|
||||||
if (!type.equals(ARTICLE_LIST)) {
|
if (!type.equals(ARTICLE_LIST)) {
|
||||||
ArticleContent articleContent = articleMapper.selectArticleContent(article.getIdArticle());
|
ArticleContent articleContent = articleMapper.selectArticleContent(article.getIdArticle());
|
||||||
if (type.equals(ARTICLE_VIEW)){
|
if (type.equals(ARTICLE_VIEW)) {
|
||||||
article.setArticleContent(articleContent.getArticleContentHtml());
|
article.setArticleContent(articleContent.getArticleContentHtml());
|
||||||
// 获取所属作品集列表数据
|
// 获取所属作品集列表数据
|
||||||
List<PortfolioArticleDTO> portfolioArticleDTOList = articleMapper.selectPortfolioArticles(article.getIdArticle());
|
List<PortfolioArticleDTO> portfolioArticleDTOList = articleMapper.selectPortfolioArticles(article.getIdArticle());
|
||||||
|
@ -83,7 +83,7 @@ public class CommentServiceImpl extends AbstractService<Comment> implements Comm
|
|||||||
comment.setCreatedTime(new Date());
|
comment.setCreatedTime(new Date());
|
||||||
commentMapper.insertSelective(comment);
|
commentMapper.insertSelective(comment);
|
||||||
StringBuilder commentSharpUrl = new StringBuilder(article.getArticlePermalink());
|
StringBuilder commentSharpUrl = new StringBuilder(article.getArticlePermalink());
|
||||||
commentSharpUrl.append("/comment/").append(comment.getIdComment());
|
commentSharpUrl.append("#comment-").append(comment.getIdComment());
|
||||||
commentMapper.updateCommentSharpUrl(comment.getIdComment(), commentSharpUrl.toString());
|
commentMapper.updateCommentSharpUrl(comment.getIdComment(), commentSharpUrl.toString());
|
||||||
|
|
||||||
String commentContent = comment.getCommentContent();
|
String commentContent = comment.getCommentContent();
|
||||||
|
@ -1,13 +1,25 @@
|
|||||||
package com.rymcu.vertical.service.impl;
|
package com.rymcu.vertical.service.impl;
|
||||||
|
|
||||||
import com.rymcu.vertical.core.service.AbstractService;
|
import com.rymcu.vertical.core.service.AbstractService;
|
||||||
|
import com.rymcu.vertical.dto.ArticleDTO;
|
||||||
|
import com.rymcu.vertical.dto.Author;
|
||||||
|
import com.rymcu.vertical.dto.NotificationDTO;
|
||||||
|
import com.rymcu.vertical.entity.Comment;
|
||||||
import com.rymcu.vertical.entity.Notification;
|
import com.rymcu.vertical.entity.Notification;
|
||||||
|
import com.rymcu.vertical.entity.User;
|
||||||
import com.rymcu.vertical.mapper.NotificationMapper;
|
import com.rymcu.vertical.mapper.NotificationMapper;
|
||||||
|
import com.rymcu.vertical.service.ArticleService;
|
||||||
|
import com.rymcu.vertical.service.CommentService;
|
||||||
import com.rymcu.vertical.service.NotificationService;
|
import com.rymcu.vertical.service.NotificationService;
|
||||||
|
import com.rymcu.vertical.service.UserService;
|
||||||
|
import com.rymcu.vertical.util.BeanCopierUtil;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author ronger
|
* @author ronger
|
||||||
@ -17,31 +29,83 @@ public class NotificationServiceImpl extends AbstractService<Notification> imple
|
|||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private NotificationMapper notificationMapper;
|
private NotificationMapper notificationMapper;
|
||||||
|
@Resource
|
||||||
|
private ArticleService articleService;
|
||||||
|
@Resource
|
||||||
|
private CommentService commentService;
|
||||||
|
@Resource
|
||||||
|
private UserService userService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Notification> findUnreadNotifications(Integer idUser){
|
public List<Notification> findUnreadNotifications(Integer idUser) {
|
||||||
List<Notification> list = notificationMapper.selectUnreadNotifications(idUser);
|
List<Notification> list = notificationMapper.selectUnreadNotifications(idUser);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Notification> findNotifications(Integer idUser) {
|
public List<NotificationDTO> findNotifications(Integer idUser) {
|
||||||
List<Notification> list = notificationMapper.selectNotifications(idUser);
|
List<Notification> list = notificationMapper.selectNotifications(idUser);
|
||||||
return list;
|
List<NotificationDTO> notifications = new ArrayList<>();
|
||||||
|
list.forEach(notification -> {
|
||||||
|
NotificationDTO notificationDTO = genNotification(notification);
|
||||||
|
notifications.add(notificationDTO);
|
||||||
|
});
|
||||||
|
return notifications;
|
||||||
|
}
|
||||||
|
|
||||||
|
private NotificationDTO genNotification(Notification notification) {
|
||||||
|
NotificationDTO notificationDTO = new NotificationDTO();
|
||||||
|
BeanCopierUtil.copy(notification, notificationDTO);
|
||||||
|
ArticleDTO article;
|
||||||
|
Comment comment;
|
||||||
|
User user;
|
||||||
|
switch (notification.getDataType()) {
|
||||||
|
case "0":
|
||||||
|
// 系统公告/帖子
|
||||||
|
article = articleService.findArticleDTOById(notification.getDataId(), 0);
|
||||||
|
notificationDTO.setDataTitle("系统公告");
|
||||||
|
notificationDTO.setDataUrl(article.getArticlePermalink());
|
||||||
|
user = userService.findById(article.getArticleAuthorId().toString());
|
||||||
|
notificationDTO.setAuthor(genAuthor(user));
|
||||||
|
break;
|
||||||
|
case "1":
|
||||||
|
// 关注
|
||||||
|
break;
|
||||||
|
case "2":
|
||||||
|
// 回帖
|
||||||
|
comment = commentService.findById(notification.getDataId().toString());
|
||||||
|
article = articleService.findArticleDTOById(comment.getCommentArticleId(), 0);
|
||||||
|
notificationDTO.setDataTitle(article.getArticleTitle());
|
||||||
|
notificationDTO.setDataUrl(comment.getCommentSharpUrl());
|
||||||
|
user = userService.findById(comment.getCommentAuthorId().toString());
|
||||||
|
notificationDTO.setAuthor(genAuthor(user));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return notificationDTO;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Author genAuthor(User user) {
|
||||||
|
Author author = new Author();
|
||||||
|
author.setUserNickname(user.getNickname());
|
||||||
|
author.setUserAvatarURL(user.getAvatarUrl());
|
||||||
|
author.setIdUser(user.getIdUser());
|
||||||
|
return author;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Notification findNotification(Integer idUser, Integer dataId, String dataType) {
|
public Notification findNotification(Integer idUser, Integer dataId, String dataType) {
|
||||||
return notificationMapper.selectNotification(idUser,dataId,dataType);
|
return notificationMapper.selectNotification(idUser, dataId, dataType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Integer save(Integer idUser, Integer dataId, String dataType, String dataSummary) {
|
public Integer save(Integer idUser, Integer dataId, String dataType, String dataSummary) {
|
||||||
return notificationMapper.insertNotification(idUser,dataId,dataType,dataSummary);
|
return notificationMapper.insertNotification(idUser, dataId, dataType, dataSummary);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readNotification(Integer id) {
|
@Transactional(rollbackFor = Exception.class)
|
||||||
notificationMapper.readNotification(id);
|
public Integer readNotification(Integer id) {
|
||||||
|
return notificationMapper.readNotification(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package com.rymcu.vertical.util;
|
|||||||
|
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import com.rymcu.vertical.dto.ArticleDTO;
|
import com.rymcu.vertical.dto.ArticleDTO;
|
||||||
|
import com.rymcu.vertical.dto.NotificationDTO;
|
||||||
import com.rymcu.vertical.entity.Notification;
|
import com.rymcu.vertical.entity.Notification;
|
||||||
import com.rymcu.vertical.entity.User;
|
import com.rymcu.vertical.entity.User;
|
||||||
import org.apache.shiro.SecurityUtils;
|
import org.apache.shiro.SecurityUtils;
|
||||||
@ -34,20 +35,19 @@ public class Utils {
|
|||||||
String plain = Encodes.unescapeHtml(plainPassword);
|
String plain = Encodes.unescapeHtml(plainPassword);
|
||||||
byte[] salt = Digests.generateSalt(SALT_SIZE);
|
byte[] salt = Digests.generateSalt(SALT_SIZE);
|
||||||
byte[] hashPassword = Digests.sha1(plain.getBytes(), salt, HASH_INTERATIONS);
|
byte[] hashPassword = Digests.sha1(plain.getBytes(), salt, HASH_INTERATIONS);
|
||||||
return Encodes.encodeHex(salt) + Encodes.encodeHex(hashPassword);
|
return Encodes.encodeHex(salt)+Encodes.encodeHex(hashPassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 一般检查工具密码比对 add by xlf 2018-11-8
|
*一般检查工具密码比对 add by xlf 2018-11-8
|
||||||
*
|
|
||||||
* @param pwd
|
* @param pwd
|
||||||
* @param enpwd 加密的密码
|
* @param enpwd 加密的密码
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static boolean comparePwd(String pwd, String enpwd) {
|
public static boolean comparePwd(String pwd,String enpwd){
|
||||||
byte[] salt = Encodes.decodeHex(enpwd.substring(0, 16));
|
byte[] salt = Encodes.decodeHex(enpwd.substring(0,16));
|
||||||
byte[] hashPassword = Digests.sha1(pwd.getBytes(), salt, HASH_INTERATIONS);
|
byte[] hashPassword = Digests.sha1(pwd.getBytes(), salt, HASH_INTERATIONS);
|
||||||
return enpwd.equals(Encodes.encodeHex(salt) + Encodes.encodeHex(hashPassword));
|
return enpwd.equals(Encodes.encodeHex(salt)+Encodes.encodeHex(hashPassword));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static User getCurrentUser() {
|
public static User getCurrentUser() {
|
||||||
@ -55,34 +55,33 @@ public class Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Session getSession() {
|
public static Session getSession() {
|
||||||
try {
|
try{
|
||||||
Subject subject = SecurityUtils.getSubject();
|
Subject subject = SecurityUtils.getSubject();
|
||||||
Session session = subject.getSession(false);
|
Session session = subject.getSession(false);
|
||||||
if (session == null) {
|
if (session == null){
|
||||||
session = subject.getSession();
|
session = subject.getSession();
|
||||||
}
|
}
|
||||||
if (session != null) {
|
if (session != null){
|
||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
subject.logout();
|
subject.logout();
|
||||||
} catch (InvalidSessionException e) {
|
}catch (InvalidSessionException e){
|
||||||
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Integer genCode() {
|
public static Integer genCode() {
|
||||||
Integer code = (int) ((Math.random() * 9 + 1) * 100000);
|
Integer code = (int)((Math.random()*9+1)*100000);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取配置文件内属性
|
* 获取配置文件内属性
|
||||||
*
|
|
||||||
* @param key 键值
|
* @param key 键值
|
||||||
* @return 属性值
|
* @return 属性值
|
||||||
*/
|
* */
|
||||||
public static String getProperty(String key) {
|
public static String getProperty(String key){
|
||||||
return env.getProperty(key);
|
return env.getProperty(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,24 +97,24 @@ public class Utils {
|
|||||||
LocalDate today = LocalDate.now();
|
LocalDate today = LocalDate.now();
|
||||||
|
|
||||||
Period p = Period.between(oldLocalDate, today);
|
Period p = Period.between(oldLocalDate, today);
|
||||||
if (p.getYears() > 0) {
|
if(p.getYears() > 0){
|
||||||
timeAgo = p.getYears() + " 年前 ";
|
timeAgo = p.getYears()+" 年前 ";
|
||||||
} else if (p.getMonths() > 0) {
|
}else if(p.getMonths() > 0){
|
||||||
timeAgo = p.getMonths() + " 月前 ";
|
timeAgo = p.getMonths()+" 月前 ";
|
||||||
} else if (p.getDays() > 0) {
|
}else if(p.getDays() > 0){
|
||||||
timeAgo = p.getDays() + " 天前 ";
|
timeAgo = p.getDays()+" 天前 ";
|
||||||
} else {
|
}else {
|
||||||
long to = System.currentTimeMillis();
|
long to = System.currentTimeMillis();
|
||||||
long from = date.getTime();
|
long from = date.getTime();
|
||||||
int hours = (int) ((to - from) / (1000 * 60 * 60));
|
int hours = (int) ((to - from)/(1000 * 60 * 60));
|
||||||
if (hours > 0) {
|
if(hours > 0){
|
||||||
timeAgo = hours + " 小时前 ";
|
timeAgo = hours+" 小时前 ";
|
||||||
} else {
|
}else {
|
||||||
int minutes = (int) ((to - from) / (1000 * 60));
|
int minutes = (int) ((to - from)/(1000 * 60));
|
||||||
if (minutes < 5) {
|
if(minutes == 0){
|
||||||
timeAgo = " 刚刚 ";
|
timeAgo = " 刚刚 ";
|
||||||
} else {
|
}else {
|
||||||
timeAgo = minutes + " 分钟前 ";
|
timeAgo = minutes+" 分钟前 ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -124,13 +123,13 @@ public class Utils {
|
|||||||
|
|
||||||
public static Map getPagination(PageInfo pageInfo) {
|
public static Map getPagination(PageInfo pageInfo) {
|
||||||
Map pagination = new HashMap(3);
|
Map pagination = new HashMap(3);
|
||||||
pagination.put("pageSize", pageInfo.getPageSize());
|
pagination.put("pageSize",pageInfo.getPageSize());
|
||||||
pagination.put("total", pageInfo.getTotal());
|
pagination.put("total",pageInfo.getTotal());
|
||||||
pagination.put("currentPage", pageInfo.getPageNum());
|
pagination.put("currentPage",pageInfo.getPageNum());
|
||||||
return pagination;
|
return pagination;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args){
|
||||||
LocalDate localDate = LocalDate.parse("2019-11-15");
|
LocalDate localDate = LocalDate.parse("2019-11-15");
|
||||||
ZoneId zone = ZoneId.systemDefault();
|
ZoneId zone = ZoneId.systemDefault();
|
||||||
Instant instant = localDate.atStartOfDay().atZone(zone).toInstant();
|
Instant instant = localDate.atStartOfDay().atZone(zone).toInstant();
|
||||||
@ -142,9 +141,9 @@ public class Utils {
|
|||||||
Map map = new HashMap(2);
|
Map map = new HashMap(2);
|
||||||
map.put("articles", pageInfo.getList());
|
map.put("articles", pageInfo.getList());
|
||||||
Map pagination = new HashMap(4);
|
Map pagination = new HashMap(4);
|
||||||
pagination.put("pageSize", pageInfo.getPageSize());
|
pagination.put("pageSize",pageInfo.getPageSize());
|
||||||
pagination.put("total", pageInfo.getTotal());
|
pagination.put("total",pageInfo.getTotal());
|
||||||
pagination.put("currentPage", pageInfo.getPageNum());
|
pagination.put("currentPage",pageInfo.getPageNum());
|
||||||
map.put("pagination", pagination);
|
map.put("pagination", pagination);
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
@ -153,9 +152,9 @@ public class Utils {
|
|||||||
Map map = new HashMap(2);
|
Map map = new HashMap(2);
|
||||||
map.put("notifications", pageInfo.getList());
|
map.put("notifications", pageInfo.getList());
|
||||||
Map pagination = new HashMap(4);
|
Map pagination = new HashMap(4);
|
||||||
pagination.put("pageSize", pageInfo.getPageSize());
|
pagination.put("pageSize",pageInfo.getPageSize());
|
||||||
pagination.put("total", pageInfo.getTotal());
|
pagination.put("total",pageInfo.getTotal());
|
||||||
pagination.put("currentPage", pageInfo.getPageNum());
|
pagination.put("currentPage",pageInfo.getPageNum());
|
||||||
map.put("pagination", pagination);
|
map.put("pagination", pagination);
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
@ -184,4 +183,15 @@ public class Utils {
|
|||||||
|
|
||||||
return ip;
|
return ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Map getNotificationDTOsGlobalResult(PageInfo<NotificationDTO> pageInfo) {
|
||||||
|
Map map = new HashMap(2);
|
||||||
|
map.put("notifications", pageInfo.getList());
|
||||||
|
Map pagination = new HashMap(4);
|
||||||
|
pagination.put("pageSize",pageInfo.getPageSize());
|
||||||
|
pagination.put("total",pageInfo.getTotal());
|
||||||
|
pagination.put("currentPage",pageInfo.getPageNum());
|
||||||
|
map.put("pagination", pagination);
|
||||||
|
return map;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import com.github.pagehelper.PageHelper;
|
|||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import com.rymcu.vertical.core.result.GlobalResult;
|
import com.rymcu.vertical.core.result.GlobalResult;
|
||||||
import com.rymcu.vertical.core.result.GlobalResultGenerator;
|
import com.rymcu.vertical.core.result.GlobalResultGenerator;
|
||||||
|
import com.rymcu.vertical.dto.NotificationDTO;
|
||||||
import com.rymcu.vertical.entity.Notification;
|
import com.rymcu.vertical.entity.Notification;
|
||||||
import com.rymcu.vertical.entity.User;
|
import com.rymcu.vertical.entity.User;
|
||||||
import com.rymcu.vertical.service.NotificationService;
|
import com.rymcu.vertical.service.NotificationService;
|
||||||
@ -31,9 +32,9 @@ public class NotificationController {
|
|||||||
public GlobalResult notifications(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows) throws BaseApiException {
|
public GlobalResult notifications(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows) throws BaseApiException {
|
||||||
User user = UserUtils.getWxCurrentUser();
|
User user = UserUtils.getWxCurrentUser();
|
||||||
PageHelper.startPage(page, rows);
|
PageHelper.startPage(page, rows);
|
||||||
List<Notification> list = notificationService.findNotifications(user.getIdUser());
|
List<NotificationDTO> list = notificationService.findNotifications(user.getIdUser());
|
||||||
PageInfo<Notification> pageInfo = new PageInfo(list);
|
PageInfo<NotificationDTO> pageInfo = new PageInfo(list);
|
||||||
Map map = Utils.getNotificationsGlobalResult(pageInfo);
|
Map map = Utils.getNotificationDTOsGlobalResult(pageInfo);
|
||||||
return GlobalResultGenerator.genSuccessResult(map);
|
return GlobalResultGenerator.genSuccessResult(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,8 +49,12 @@ public class NotificationController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/read/{id}")
|
@PutMapping("/read/{id}")
|
||||||
public void read(@PathVariable Integer id) {
|
public GlobalResult read(@PathVariable Integer id) {
|
||||||
notificationService.readNotification(id);
|
Integer result = notificationService.readNotification(id);
|
||||||
|
if (result == 0) {
|
||||||
|
return GlobalResultGenerator.genErrorResult("标记已读失败");
|
||||||
|
}
|
||||||
|
return GlobalResultGenerator.genSuccessResult("标记已读成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user