Merge remote-tracking branch 'origin/wx-dev' into wx-dev
This commit is contained in:
commit
af1ba638f4
19
src/main/java/com/rymcu/vertical/mapper/FollowMapper.java
Normal file
19
src/main/java/com/rymcu/vertical/mapper/FollowMapper.java
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
package com.rymcu.vertical.mapper;
|
||||||
|
|
||||||
|
import com.rymcu.vertical.core.mapper.Mapper;
|
||||||
|
import com.rymcu.vertical.entity.Follow;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ronger
|
||||||
|
*/
|
||||||
|
public interface FollowMapper extends Mapper<Follow> {
|
||||||
|
/**
|
||||||
|
* 判断是否关注
|
||||||
|
* @param followingId
|
||||||
|
* @param followerId
|
||||||
|
* @param followingType
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Boolean isFollow(@Param("followingId") Integer followingId, @Param("followerId") Integer followerId, @Param("followingType") String followingType);
|
||||||
|
}
|
35
src/main/java/com/rymcu/vertical/service/FollowService.java
Normal file
35
src/main/java/com/rymcu/vertical/service/FollowService.java
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package com.rymcu.vertical.service;
|
||||||
|
|
||||||
|
import com.rymcu.vertical.core.service.Service;
|
||||||
|
import com.rymcu.vertical.entity.Follow;
|
||||||
|
import com.rymcu.vertical.web.api.exception.BaseApiException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ronger
|
||||||
|
*/
|
||||||
|
public interface FollowService extends Service<Follow> {
|
||||||
|
/**
|
||||||
|
* 判断是否关注
|
||||||
|
* @param followingId
|
||||||
|
* @param followingType
|
||||||
|
* @return
|
||||||
|
* @throws BaseApiException
|
||||||
|
*/
|
||||||
|
Boolean isFollow(Integer followingId, String followingType) throws BaseApiException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关注操作
|
||||||
|
* @param follow
|
||||||
|
* @return
|
||||||
|
* @throws BaseApiException
|
||||||
|
*/
|
||||||
|
Boolean follow(Follow follow) throws BaseApiException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取消关注操作
|
||||||
|
* @param follow
|
||||||
|
* @return
|
||||||
|
* @throws BaseApiException
|
||||||
|
*/
|
||||||
|
Boolean cancelFollow(Follow follow) throws BaseApiException;
|
||||||
|
}
|
@ -118,7 +118,7 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
|
|||||||
String articleTags = article.getArticleTags();
|
String articleTags = article.getArticleTags();
|
||||||
String articleContent = article.getArticleContent();
|
String articleContent = article.getArticleContent();
|
||||||
String articleContentHtml = article.getArticleContentHtml();
|
String articleContentHtml = article.getArticleContentHtml();
|
||||||
User user = UserUtils.getWxCurrentUser();
|
User user = UserUtils.getCurrentUserByToken();
|
||||||
String reservedTag = checkTags(articleTags);
|
String reservedTag = checkTags(articleTags);
|
||||||
boolean notification = false;
|
boolean notification = false;
|
||||||
if (StringUtils.isNotBlank(reservedTag)) {
|
if (StringUtils.isNotBlank(reservedTag)) {
|
||||||
@ -249,7 +249,7 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
|
|||||||
@Override
|
@Override
|
||||||
public Map share(Integer id) throws BaseApiException {
|
public Map share(Integer id) throws BaseApiException {
|
||||||
Article article = articleMapper.selectByPrimaryKey(id);
|
Article article = articleMapper.selectByPrimaryKey(id);
|
||||||
User user = UserUtils.getWxCurrentUser();
|
User user = UserUtils.getCurrentUserByToken();
|
||||||
StringBuilder shareUrl = new StringBuilder(article.getArticlePermalink());
|
StringBuilder shareUrl = new StringBuilder(article.getArticlePermalink());
|
||||||
shareUrl.append("?s=").append(user.getNickname());
|
shareUrl.append("?s=").append(user.getNickname());
|
||||||
Map map = new HashMap(1);
|
Map map = new HashMap(1);
|
||||||
@ -259,7 +259,7 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ArticleDTO> findDrafts() throws BaseApiException {
|
public List<ArticleDTO> findDrafts() throws BaseApiException {
|
||||||
User user = UserUtils.getWxCurrentUser();
|
User user = UserUtils.getCurrentUserByToken();
|
||||||
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);
|
||||||
|
@ -0,0 +1,50 @@
|
|||||||
|
package com.rymcu.vertical.service.impl;
|
||||||
|
|
||||||
|
import com.rymcu.vertical.core.constant.NotificationConstant;
|
||||||
|
import com.rymcu.vertical.core.service.AbstractService;
|
||||||
|
import com.rymcu.vertical.entity.Follow;
|
||||||
|
import com.rymcu.vertical.entity.User;
|
||||||
|
import com.rymcu.vertical.mapper.FollowMapper;
|
||||||
|
import com.rymcu.vertical.service.FollowService;
|
||||||
|
import com.rymcu.vertical.util.NotificationUtils;
|
||||||
|
import com.rymcu.vertical.util.UserUtils;
|
||||||
|
import com.rymcu.vertical.web.api.exception.BaseApiException;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ronger
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class FollowServiceImpl extends AbstractService<Follow> implements FollowService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private FollowMapper followMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean isFollow(Integer followingId, String followingType) throws BaseApiException {
|
||||||
|
User tokenUser = UserUtils.getCurrentUserByToken();
|
||||||
|
Boolean b = followMapper.isFollow(followingId, tokenUser.getIdUser(), followingType);
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean follow(Follow follow) throws BaseApiException {
|
||||||
|
User tokenUser = UserUtils.getCurrentUserByToken();
|
||||||
|
follow.setFollowerId(tokenUser.getIdUser());
|
||||||
|
int result = followMapper.insertSelective(follow);
|
||||||
|
if (result > 0) {
|
||||||
|
NotificationUtils.saveNotification(follow.getFollowingId(), follow.getIdFollow(), NotificationConstant.Follow, tokenUser.getNickname() + " 关注了你!");
|
||||||
|
}
|
||||||
|
return result > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean cancelFollow(Follow follow) throws BaseApiException {
|
||||||
|
User tokenUser = UserUtils.getCurrentUserByToken();
|
||||||
|
follow.setFollowerId(tokenUser.getIdUser());
|
||||||
|
int result = followMapper.delete(follow);
|
||||||
|
return result == 0;
|
||||||
|
}
|
||||||
|
}
|
@ -5,14 +5,13 @@ import com.rymcu.vertical.dto.ArticleDTO;
|
|||||||
import com.rymcu.vertical.dto.Author;
|
import com.rymcu.vertical.dto.Author;
|
||||||
import com.rymcu.vertical.dto.NotificationDTO;
|
import com.rymcu.vertical.dto.NotificationDTO;
|
||||||
import com.rymcu.vertical.entity.Comment;
|
import com.rymcu.vertical.entity.Comment;
|
||||||
|
import com.rymcu.vertical.entity.Follow;
|
||||||
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.mapper.NotificationMapper;
|
import com.rymcu.vertical.mapper.NotificationMapper;
|
||||||
import com.rymcu.vertical.service.ArticleService;
|
import com.rymcu.vertical.service.*;
|
||||||
import com.rymcu.vertical.service.CommentService;
|
|
||||||
import com.rymcu.vertical.service.NotificationService;
|
|
||||||
import com.rymcu.vertical.service.UserService;
|
|
||||||
import com.rymcu.vertical.util.BeanCopierUtil;
|
import com.rymcu.vertical.util.BeanCopierUtil;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@ -35,6 +34,10 @@ public class NotificationServiceImpl extends AbstractService<Notification> imple
|
|||||||
private CommentService commentService;
|
private CommentService commentService;
|
||||||
@Resource
|
@Resource
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
|
@Resource
|
||||||
|
private FollowService followService;
|
||||||
|
@Value("${resource.domain}")
|
||||||
|
private String domain;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Notification> findUnreadNotifications(Integer idUser) {
|
public List<Notification> findUnreadNotifications(Integer idUser) {
|
||||||
@ -59,6 +62,7 @@ public class NotificationServiceImpl extends AbstractService<Notification> imple
|
|||||||
ArticleDTO article;
|
ArticleDTO article;
|
||||||
Comment comment;
|
Comment comment;
|
||||||
User user;
|
User user;
|
||||||
|
Follow follow;
|
||||||
switch (notification.getDataType()) {
|
switch (notification.getDataType()) {
|
||||||
case "0":
|
case "0":
|
||||||
// 系统公告/帖子
|
// 系统公告/帖子
|
||||||
@ -70,6 +74,11 @@ public class NotificationServiceImpl extends AbstractService<Notification> imple
|
|||||||
break;
|
break;
|
||||||
case "1":
|
case "1":
|
||||||
// 关注
|
// 关注
|
||||||
|
follow = followService.findById(notification.getDataId().toString());
|
||||||
|
notificationDTO.setDataTitle("关注提醒");
|
||||||
|
user = userService.findById(follow.getFollowerId().toString());
|
||||||
|
notificationDTO.setDataUrl(getFollowLink(follow.getFollowingType(), user.getNickname()));
|
||||||
|
notificationDTO.setAuthor(genAuthor(user));
|
||||||
break;
|
break;
|
||||||
case "2":
|
case "2":
|
||||||
// 回帖
|
// 回帖
|
||||||
@ -80,10 +89,25 @@ public class NotificationServiceImpl extends AbstractService<Notification> imple
|
|||||||
user = userService.findById(comment.getCommentAuthorId().toString());
|
user = userService.findById(comment.getCommentAuthorId().toString());
|
||||||
notificationDTO.setAuthor(genAuthor(user));
|
notificationDTO.setAuthor(genAuthor(user));
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return notificationDTO;
|
return notificationDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getFollowLink(String followingType, String id) {
|
||||||
|
StringBuilder url = new StringBuilder();
|
||||||
|
url.append(domain);
|
||||||
|
switch (followingType) {
|
||||||
|
case "0":
|
||||||
|
url = url.append("/user/").append(id);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
url.append("/notification");
|
||||||
|
}
|
||||||
|
return url.toString();
|
||||||
|
}
|
||||||
|
|
||||||
private Author genAuthor(User user) {
|
private Author genAuthor(User user) {
|
||||||
Author author = new Author();
|
Author author = new Author();
|
||||||
author.setUserNickname(user.getNickname());
|
author.setUserNickname(user.getNickname());
|
||||||
|
@ -62,7 +62,7 @@ public class PortfolioServiceImpl extends AbstractService<Portfolio> implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Portfolio postPortfolio(Portfolio portfolio) throws BaseApiException {
|
public Portfolio postPortfolio(Portfolio portfolio) throws BaseApiException {
|
||||||
User user = UserUtils.getWxCurrentUser();
|
User user = UserUtils.getCurrentUserByToken();
|
||||||
if (portfolio.getIdPortfolio() == null || portfolio.getIdPortfolio() == 0) {
|
if (portfolio.getIdPortfolio() == null || portfolio.getIdPortfolio() == 0) {
|
||||||
portfolio.setPortfolioAuthorId(user.getIdUser());
|
portfolio.setPortfolioAuthorId(user.getIdUser());
|
||||||
portfolio.setCreatedTime(new Date());
|
portfolio.setCreatedTime(new Date());
|
||||||
@ -78,7 +78,7 @@ public class PortfolioServiceImpl extends AbstractService<Portfolio> implements
|
|||||||
@Override
|
@Override
|
||||||
public Map findUnbindArticles(Integer page, Integer rows, String searchText, Integer idPortfolio) throws BaseApiException {
|
public Map findUnbindArticles(Integer page, Integer rows, String searchText, Integer idPortfolio) throws BaseApiException {
|
||||||
Map map = new HashMap(1);
|
Map map = new HashMap(1);
|
||||||
User user = UserUtils.getWxCurrentUser();
|
User user = UserUtils.getCurrentUserByToken();
|
||||||
Portfolio portfolio = portfolioMapper.selectByPrimaryKey(idPortfolio);
|
Portfolio portfolio = portfolioMapper.selectByPrimaryKey(idPortfolio);
|
||||||
if (portfolio == null) {
|
if (portfolio == null) {
|
||||||
map.put("message", "该作品集不存在或已被删除!");
|
map.put("message", "该作品集不存在或已被删除!");
|
||||||
|
@ -39,7 +39,7 @@ public class TagServiceImpl extends AbstractService<Tag> implements TagService {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = { UnsupportedEncodingException.class,BaseApiException.class })
|
@Transactional(rollbackFor = { UnsupportedEncodingException.class,BaseApiException.class })
|
||||||
public Integer saveTagArticle(Article article) throws UnsupportedEncodingException, BaseApiException {
|
public Integer saveTagArticle(Article article) throws UnsupportedEncodingException, BaseApiException {
|
||||||
User user = UserUtils.getWxCurrentUser();
|
User user = UserUtils.getCurrentUserByToken();
|
||||||
String articleTags = article.getArticleTags();
|
String articleTags = article.getArticleTags();
|
||||||
if(StringUtils.isNotBlank(articleTags)){
|
if(StringUtils.isNotBlank(articleTags)){
|
||||||
String[] tags = articleTags.split(",");
|
String[] tags = articleTags.split(",");
|
||||||
|
@ -25,7 +25,7 @@ public class UserUtils {
|
|||||||
* 通过token获取当前用户的信息
|
* 通过token获取当前用户的信息
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static User getWxCurrentUser() throws BaseApiException {
|
public static User getCurrentUserByToken() throws BaseApiException {
|
||||||
String authHeader = ContextHolderUtils.getRequest().getHeader(JwtConstants.AUTHORIZATION);
|
String authHeader = ContextHolderUtils.getRequest().getHeader(JwtConstants.AUTHORIZATION);
|
||||||
if (authHeader == null) {
|
if (authHeader == null) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -0,0 +1,45 @@
|
|||||||
|
package com.rymcu.vertical.web.api.follow;
|
||||||
|
|
||||||
|
import com.rymcu.vertical.core.result.GlobalResult;
|
||||||
|
import com.rymcu.vertical.core.result.GlobalResultGenerator;
|
||||||
|
import com.rymcu.vertical.entity.Follow;
|
||||||
|
import com.rymcu.vertical.jwt.def.JwtConstants;
|
||||||
|
import com.rymcu.vertical.service.FollowService;
|
||||||
|
import com.rymcu.vertical.web.api.exception.BaseApiException;
|
||||||
|
import com.rymcu.vertical.web.api.exception.ErrorCode;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ronger
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/v1/follow")
|
||||||
|
public class FollowController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private FollowService followService;
|
||||||
|
|
||||||
|
@GetMapping("/is-follow")
|
||||||
|
public GlobalResult isFollow(@RequestParam Integer followingId, @RequestParam String followingType) throws BaseApiException {
|
||||||
|
Boolean b = followService.isFollow(followingId, followingType);
|
||||||
|
return GlobalResultGenerator.genSuccessResult(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
public GlobalResult follow(@RequestBody Follow follow) throws BaseApiException {
|
||||||
|
Boolean b = followService.follow(follow);
|
||||||
|
return GlobalResultGenerator.genSuccessResult(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("cancel-follow")
|
||||||
|
public GlobalResult cancelFollow(@RequestBody Follow follow) throws BaseApiException {
|
||||||
|
Boolean b = followService.cancelFollow(follow);
|
||||||
|
return GlobalResultGenerator.genSuccessResult(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -30,7 +30,7 @@ public class NotificationController {
|
|||||||
|
|
||||||
@GetMapping("/all")
|
@GetMapping("/all")
|
||||||
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.getCurrentUserByToken();
|
||||||
PageHelper.startPage(page, rows);
|
PageHelper.startPage(page, rows);
|
||||||
List<NotificationDTO> list = notificationService.findNotifications(user.getIdUser());
|
List<NotificationDTO> list = notificationService.findNotifications(user.getIdUser());
|
||||||
PageInfo<NotificationDTO> pageInfo = new PageInfo(list);
|
PageInfo<NotificationDTO> pageInfo = new PageInfo(list);
|
||||||
@ -40,7 +40,7 @@ public class NotificationController {
|
|||||||
|
|
||||||
@GetMapping("/unread")
|
@GetMapping("/unread")
|
||||||
public GlobalResult unreadNotification(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows) throws BaseApiException {
|
public GlobalResult unreadNotification(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows) throws BaseApiException {
|
||||||
User user = UserUtils.getWxCurrentUser();
|
User user = UserUtils.getCurrentUserByToken();
|
||||||
PageHelper.startPage(page, rows);
|
PageHelper.startPage(page, rows);
|
||||||
List<Notification> list = notificationService.findUnreadNotifications(user.getIdUser());
|
List<Notification> list = notificationService.findUnreadNotifications(user.getIdUser());
|
||||||
PageInfo<Notification> pageInfo = new PageInfo(list);
|
PageInfo<Notification> pageInfo = new PageInfo(list);
|
||||||
|
8
src/main/java/mapper/FollowMapper.xml
Normal file
8
src/main/java/mapper/FollowMapper.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||||
|
<mapper namespace="com.rymcu.vertical.mapper.FollowMapper">
|
||||||
|
<select id="isFollow" resultType="java.lang.Boolean">
|
||||||
|
select ifnull((select true from vertical_follow where follower_id = #{followerId}
|
||||||
|
and following_id = #{followingId} and following_type = #{followingType}), false)
|
||||||
|
</select>
|
||||||
|
</mapper>
|
Loading…
Reference in New Issue
Block a user