diff --git a/src/main/java/com/rymcu/vertical/dto/ArticleDTO.java b/src/main/java/com/rymcu/vertical/dto/ArticleDTO.java index 60aa8c2..50cedc3 100644 --- a/src/main/java/com/rymcu/vertical/dto/ArticleDTO.java +++ b/src/main/java/com/rymcu/vertical/dto/ArticleDTO.java @@ -51,4 +51,6 @@ public class ArticleDTO { private List tags; private List articleComments; + + private List portfolios; } diff --git a/src/main/java/com/rymcu/vertical/dto/PortfolioArticleDTO.java b/src/main/java/com/rymcu/vertical/dto/PortfolioArticleDTO.java new file mode 100644 index 0000000..e50c381 --- /dev/null +++ b/src/main/java/com/rymcu/vertical/dto/PortfolioArticleDTO.java @@ -0,0 +1,21 @@ +package com.rymcu.vertical.dto; + +import lombok.Data; + +/** + * @author ronger + */ +@Data +public class PortfolioArticleDTO { + + private Integer id; + + private Integer idPortfolio; + + private Integer idArticle; + + private String headImgUrl; + + private String portfolioTitle; + +} diff --git a/src/main/java/com/rymcu/vertical/mapper/ArticleMapper.java b/src/main/java/com/rymcu/vertical/mapper/ArticleMapper.java index 31eed56..6194cee 100644 --- a/src/main/java/com/rymcu/vertical/mapper/ArticleMapper.java +++ b/src/main/java/com/rymcu/vertical/mapper/ArticleMapper.java @@ -3,6 +3,7 @@ package com.rymcu.vertical.mapper; import com.rymcu.vertical.core.mapper.Mapper; import com.rymcu.vertical.dto.ArticleDTO; import com.rymcu.vertical.dto.ArticleTagDTO; +import com.rymcu.vertical.dto.PortfolioArticleDTO; import com.rymcu.vertical.entity.Article; import com.rymcu.vertical.entity.ArticleContent; import org.apache.ibatis.annotations.Param; @@ -118,4 +119,20 @@ public interface ArticleMapper extends Mapper
{ * @return */ List selectArticlesByIdPortfolio(@Param("idPortfolio") Integer idPortfolio); + + /** + * 查询作品集未绑定文章 + * @param idPortfolio + * @param searchText + * @param idUser + * @return + */ + List selectUnbindArticlesByIdPortfolio(@Param("idPortfolio") Integer idPortfolio, @Param("searchText") String searchText, @Param("idUser") Integer idUser); + + /** + * 查询文章所属作品集列表 + * @param idArticle + * @return + */ + List selectPortfolioArticles(@Param("idArticle") Integer idArticle); } diff --git a/src/main/java/com/rymcu/vertical/mapper/PortfolioMapper.java b/src/main/java/com/rymcu/vertical/mapper/PortfolioMapper.java index 23a6d20..c259b09 100644 --- a/src/main/java/com/rymcu/vertical/mapper/PortfolioMapper.java +++ b/src/main/java/com/rymcu/vertical/mapper/PortfolioMapper.java @@ -31,4 +31,28 @@ public interface PortfolioMapper extends Mapper { * @return */ Integer selectCountArticleNumber(@Param("idPortfolio") Integer idPortfolio); + + /** + * 查询文章是否已绑定 + * @param idArticle + * @param idPortfolio + * @return + */ + Integer selectCountPortfolioArticle(@Param("idArticle") Integer idArticle, @Param("idPortfolio") Integer idPortfolio); + + /** + * 插入文章与作品集绑定数据 + * @param idArticle + * @param idPortfolio + * @param maxSortNo + * @return + */ + Integer insertPortfolioArticle(@Param("idArticle") Integer idArticle, @Param("idPortfolio") Integer idPortfolio, @Param("maxSortNo") Integer maxSortNo); + + /** + * 查询作品集下最大排序号 + * @param idPortfolio + * @return + */ + Integer selectMaxSortNo(@Param("idPortfolio") Integer idPortfolio); } diff --git a/src/main/java/com/rymcu/vertical/service/ArticleService.java b/src/main/java/com/rymcu/vertical/service/ArticleService.java index 2ab3a97..497cdf8 100644 --- a/src/main/java/com/rymcu/vertical/service/ArticleService.java +++ b/src/main/java/com/rymcu/vertical/service/ArticleService.java @@ -96,4 +96,13 @@ public interface ArticleService extends Service
{ * @return */ List findArticlesByIdPortfolio(Integer idPortfolio); + + /** + * 查询作品集下未绑定文章 + * @param idPortfolio + * @param searchText + * @param idUser + * @return + */ + List selectUnbindArticles(Integer idPortfolio, String searchText, Integer idUser); } diff --git a/src/main/java/com/rymcu/vertical/service/PortfolioService.java b/src/main/java/com/rymcu/vertical/service/PortfolioService.java index 0d516bd..9291e5c 100644 --- a/src/main/java/com/rymcu/vertical/service/PortfolioService.java +++ b/src/main/java/com/rymcu/vertical/service/PortfolioService.java @@ -1,6 +1,7 @@ package com.rymcu.vertical.service; import com.rymcu.vertical.core.service.Service; +import com.rymcu.vertical.dto.PortfolioArticleDTO; import com.rymcu.vertical.dto.PortfolioDTO; import com.rymcu.vertical.dto.UserDTO; import com.rymcu.vertical.entity.Portfolio; @@ -22,15 +23,35 @@ public interface PortfolioService extends Service { List findUserPortfoliosByUser(UserDTO userDTO); /** 查询作品集 - * @param id + * @param idPortfolio * @return */ - PortfolioDTO findPortfolioDTOById(Integer id); + PortfolioDTO findPortfolioDTOById(Integer idPortfolio); /** * 保持/更新作品集 * @param portfolio + * @throws BaseApiException * @return */ Portfolio postPortfolio(Portfolio portfolio) throws BaseApiException; + + /** + * 查询作品集下未绑定文章 + * + * @param page + * @param rows + * @param searchText + * @param idPortfolio + * @throws BaseApiException + * @return + */ + Map findUnbindArticles(Integer page, Integer rows, String searchText, Integer idPortfolio) throws BaseApiException; + + /** + * 绑定文章 + * @param portfolioArticle + * @return + */ + Map bindArticle(PortfolioArticleDTO portfolioArticle); } diff --git a/src/main/java/com/rymcu/vertical/service/impl/ArticleServiceImpl.java b/src/main/java/com/rymcu/vertical/service/impl/ArticleServiceImpl.java index d3dcc44..c289f46 100644 --- a/src/main/java/com/rymcu/vertical/service/impl/ArticleServiceImpl.java +++ b/src/main/java/com/rymcu/vertical/service/impl/ArticleServiceImpl.java @@ -3,10 +3,7 @@ package com.rymcu.vertical.service.impl; import com.rymcu.vertical.core.constant.NotificationConstant; import com.rymcu.vertical.core.constant.ProjectConstant; import com.rymcu.vertical.core.service.AbstractService; -import com.rymcu.vertical.dto.ArticleDTO; -import com.rymcu.vertical.dto.ArticleTagDTO; -import com.rymcu.vertical.dto.Author; -import com.rymcu.vertical.dto.CommentDTO; +import com.rymcu.vertical.dto.*; import com.rymcu.vertical.entity.Article; import com.rymcu.vertical.entity.ArticleContent; import com.rymcu.vertical.entity.Tag; @@ -272,6 +269,15 @@ public class ArticleServiceImpl extends AbstractService
implements Arti return list; } + @Override + public List selectUnbindArticles(Integer idPortfolio, String searchText, Integer idUser) { + List list = articleMapper.selectUnbindArticlesByIdPortfolio(idPortfolio,searchText,idUser); + list.forEach(article->{ + genArticle(article,0); + }); + return list; + } + private ArticleDTO genArticle(ArticleDTO article, Integer type) { Author author = userService.selectAuthor(article.getArticleAuthorId()); article.setArticleAuthor(author); @@ -295,6 +301,9 @@ public class ArticleServiceImpl extends AbstractService
implements Arti } List commentDTOList = commentService.getArticleComments(article.getIdArticle()); article.setArticleComments(commentDTOList); + + List portfolioArticleDTOList = articleMapper.selectPortfolioArticles(article.getIdArticle()); + article.setPortfolios(portfolioArticleDTOList); return article; } } diff --git a/src/main/java/com/rymcu/vertical/service/impl/PortfolioServiceImpl.java b/src/main/java/com/rymcu/vertical/service/impl/PortfolioServiceImpl.java index 51db999..3fc3a32 100644 --- a/src/main/java/com/rymcu/vertical/service/impl/PortfolioServiceImpl.java +++ b/src/main/java/com/rymcu/vertical/service/impl/PortfolioServiceImpl.java @@ -1,15 +1,17 @@ package com.rymcu.vertical.service.impl; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; import com.rymcu.vertical.core.service.AbstractService; -import com.rymcu.vertical.dto.Author; -import com.rymcu.vertical.dto.PortfolioDTO; -import com.rymcu.vertical.dto.UserDTO; +import com.rymcu.vertical.dto.*; import com.rymcu.vertical.entity.Portfolio; import com.rymcu.vertical.entity.User; import com.rymcu.vertical.mapper.PortfolioMapper; +import com.rymcu.vertical.service.ArticleService; import com.rymcu.vertical.service.PortfolioService; import com.rymcu.vertical.service.UserService; import com.rymcu.vertical.util.UserUtils; +import com.rymcu.vertical.util.Utils; import com.rymcu.vertical.web.api.exception.BaseApiException; import org.springframework.stereotype.Service; @@ -29,6 +31,8 @@ public class PortfolioServiceImpl extends AbstractService implements private PortfolioMapper portfolioMapper; @Resource private UserService userService; + @Resource + private ArticleService articleService; @Override public List findUserPortfoliosByUser(UserDTO userDTO) { @@ -44,8 +48,8 @@ public class PortfolioServiceImpl extends AbstractService implements } @Override - public PortfolioDTO findPortfolioDTOById(Integer id) { - PortfolioDTO portfolio = portfolioMapper.selectPortfolioDTOById(id); + public PortfolioDTO findPortfolioDTOById(Integer idPortfolio) { + PortfolioDTO portfolio = portfolioMapper.selectPortfolioDTOById(idPortfolio); Author author = userService.selectAuthor(portfolio.getPortfolioAuthorId()); genPortfolioAuthor(portfolio,author); Integer articleNumber = portfolioMapper.selectCountArticleNumber(portfolio.getIdPortfolio()); @@ -68,6 +72,40 @@ public class PortfolioServiceImpl extends AbstractService implements return portfolio; } + @Override + public Map findUnbindArticles(Integer page, Integer rows, String searchText, Integer idPortfolio) throws BaseApiException { + Map map = new HashMap(1); + User user = UserUtils.getWxCurrentUser(); + Portfolio portfolio = portfolioMapper.selectByPrimaryKey(idPortfolio); + if (portfolio == null) { + map.put("message", "该作品集不存在或已被删除!"); + } else { + if (!user.getIdUser().equals(portfolio.getPortfolioAuthorId())) { + map.put("message", "非法操作!"); + } else { + PageHelper.startPage(page, rows); + List articles = articleService.selectUnbindArticles(idPortfolio,searchText,user.getIdUser()); + PageInfo pageInfo = new PageInfo(articles); + map = Utils.getArticlesGlobalResult(pageInfo); + } + } + return map; + } + + @Override + public Map bindArticle(PortfolioArticleDTO portfolioArticle) { + Map map = new HashMap(1); + Integer count = portfolioMapper.selectCountPortfolioArticle(portfolioArticle.getIdArticle(), portfolioArticle.getIdPortfolio()); + if (count == 0) { + Integer maxSortNo = portfolioMapper.selectMaxSortNo(portfolioArticle.getIdPortfolio()); + portfolioMapper.insertPortfolioArticle(portfolioArticle.getIdArticle(),portfolioArticle.getIdPortfolio(),maxSortNo); + map.put("message", "绑定成功!"); + } else { + map.put("message", "该文章已经在作品集下!!"); + } + return map; + } + private PortfolioDTO genPortfolioAuthor(PortfolioDTO portfolioDTO, Author author) { portfolioDTO.setPortfolioAuthorAvatarUrl(author.getUserAvatarURL()); portfolioDTO.setPortfolioAuthorName(author.getUserNickname()); diff --git a/src/main/java/com/rymcu/vertical/web/api/portfolio/PortfolioController.java b/src/main/java/com/rymcu/vertical/web/api/portfolio/PortfolioController.java index 10cbfc7..0f0f53a 100644 --- a/src/main/java/com/rymcu/vertical/web/api/portfolio/PortfolioController.java +++ b/src/main/java/com/rymcu/vertical/web/api/portfolio/PortfolioController.java @@ -2,6 +2,7 @@ package com.rymcu.vertical.web.api.portfolio; import com.rymcu.vertical.core.result.GlobalResult; import com.rymcu.vertical.core.result.GlobalResultGenerator; +import com.rymcu.vertical.dto.PortfolioArticleDTO; import com.rymcu.vertical.dto.PortfolioDTO; import com.rymcu.vertical.entity.Portfolio; import com.rymcu.vertical.service.PortfolioService; @@ -42,4 +43,16 @@ public class PortfolioController { return GlobalResultGenerator.genSuccessResult(portfolio); } + @GetMapping("/{id}/unbind-articles") + public GlobalResult unbindArticles(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows, @RequestParam(defaultValue = "") String searchText,@PathVariable Integer id) throws BaseApiException { + Map map = portfolioService.findUnbindArticles(page, rows, searchText, id); + return GlobalResultGenerator.genSuccessResult(map); + } + + @PostMapping("/bind-article") + public GlobalResult bindArticle(@RequestBody PortfolioArticleDTO portfolioArticle) { + Map map = portfolioService.bindArticle(portfolioArticle); + return GlobalResultGenerator.genSuccessResult(map); + } + } diff --git a/src/main/java/mapper/ArticleMapper.xml b/src/main/java/mapper/ArticleMapper.xml index ffeddf3..f2c10f5 100644 --- a/src/main/java/mapper/ArticleMapper.xml +++ b/src/main/java/mapper/ArticleMapper.xml @@ -54,6 +54,12 @@ + + + + + + insert into vertical_article_content (id_article,article_content,article_content_html,created_time,updated_time) values (#{idArticle},#{articleContent},#{articleContentHtml},sysdate(),sysdate()) @@ -102,7 +108,14 @@ select art.*,su.nickname,su.avatar_url from vertical_article art left join vertical_user su on art.article_author_id = su.id where article_status = '1' and art.article_author_id = #{idUser} order by updated_time desc + + \ No newline at end of file diff --git a/src/main/java/mapper/PortfolioMapper.xml b/src/main/java/mapper/PortfolioMapper.xml index 9ecb377..6fc9147 100644 --- a/src/main/java/mapper/PortfolioMapper.xml +++ b/src/main/java/mapper/PortfolioMapper.xml @@ -18,6 +18,9 @@ + + insert into vertical_portfolio_article (id_vertical_portfolio, id_vertical_article, sort_no) values (#{idPortfolio}, #{idArticle}, #{maxSortNo}) + @@ -27,4 +30,10 @@ + + \ No newline at end of file