From d747b6f9bc1e1f8a4b732158187e44e56e55907a Mon Sep 17 00:00:00 2001 From: x ronger Date: Tue, 21 Apr 2020 23:34:38 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E4=BD=9C=E5=93=81=E9=9B=86?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vertical/mapper/PortfolioMapper.java | 8 ++++ .../vertical/service/PortfolioService.java | 15 ++++++ .../service/impl/PortfolioServiceImpl.java | 47 +++++++++++++++++-- .../api/portfolio/PortfolioController.java | 12 +++++ src/main/java/mapper/PortfolioMapper.xml | 3 ++ 5 files changed, 82 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/rymcu/vertical/mapper/PortfolioMapper.java b/src/main/java/com/rymcu/vertical/mapper/PortfolioMapper.java index f9a11fb..58f40e2 100644 --- a/src/main/java/com/rymcu/vertical/mapper/PortfolioMapper.java +++ b/src/main/java/com/rymcu/vertical/mapper/PortfolioMapper.java @@ -65,4 +65,12 @@ public interface PortfolioMapper extends Mapper { * @return */ Integer updateArticleSortNo(@Param("idPortfolio") Integer idPortfolio, @Param("idArticle") Integer idArticle, @Param("sortNo") Integer sortNo); + + /** + * 取消绑定文章 + * @param idPortfolio + * @param idArticle + * @return + */ + Integer unbindArticle(@Param("idPortfolio") Integer idPortfolio, @Param("idArticle") Integer idArticle); } diff --git a/src/main/java/com/rymcu/vertical/service/PortfolioService.java b/src/main/java/com/rymcu/vertical/service/PortfolioService.java index ffd5241..504b687 100644 --- a/src/main/java/com/rymcu/vertical/service/PortfolioService.java +++ b/src/main/java/com/rymcu/vertical/service/PortfolioService.java @@ -62,4 +62,19 @@ public interface PortfolioService extends Service { * @return */ Map updateArticleSortNo(PortfolioArticleDTO portfolioArticle); + + /** + * 取消绑定文章 + * @param idPortfolio + * @param idArticle + * @return + */ + Map unbindArticle(Integer idPortfolio, Integer idArticle); + + /** + * 删除作品集 + * @param idPortfolio + * @return + */ + Map deletePortfolio(Integer idPortfolio); } 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 0cb5cb4..d5814bc 100644 --- a/src/main/java/com/rymcu/vertical/service/impl/PortfolioServiceImpl.java +++ b/src/main/java/com/rymcu/vertical/service/impl/PortfolioServiceImpl.java @@ -50,6 +50,9 @@ public class PortfolioServiceImpl extends AbstractService implements @Override public PortfolioDTO findPortfolioDTOById(Integer idPortfolio, Integer type) { PortfolioDTO portfolio = portfolioMapper.selectPortfolioDTOById(idPortfolio,type); + if (portfolio == null) { + return new PortfolioDTO(); + } Author author = userService.selectAuthor(portfolio.getPortfolioAuthorId()); genPortfolioAuthor(portfolio,author); Integer articleNumber = portfolioMapper.selectCountArticleNumber(portfolio.getIdPortfolio()); @@ -96,7 +99,7 @@ public class PortfolioServiceImpl extends AbstractService implements public Map bindArticle(PortfolioArticleDTO portfolioArticle) { Map map = new HashMap(1); Integer count = portfolioMapper.selectCountPortfolioArticle(portfolioArticle.getIdArticle(), portfolioArticle.getIdPortfolio()); - if (count == 0) { + if (count.equals(0)) { Integer maxSortNo = portfolioMapper.selectMaxSortNo(portfolioArticle.getIdPortfolio()); portfolioMapper.insertPortfolioArticle(portfolioArticle.getIdArticle(),portfolioArticle.getIdPortfolio(),maxSortNo); map.put("message", "绑定成功!"); @@ -109,10 +112,10 @@ public class PortfolioServiceImpl extends AbstractService implements @Override public Map updateArticleSortNo(PortfolioArticleDTO portfolioArticle) { Map map = new HashMap(1); - if (portfolioArticle.getIdPortfolio() == null || portfolioArticle.getIdPortfolio() == 0) { + if (portfolioArticle.getIdPortfolio() == null || portfolioArticle.getIdPortfolio().equals(0)) { map.put("message", "作品集数据异常!"); } - if (portfolioArticle.getIdArticle() == null || portfolioArticle.getIdArticle() == 0) { + if (portfolioArticle.getIdArticle() == null || portfolioArticle.getIdArticle().equals(0)) { map.put("message", "文章数据异常!"); } if (portfolioArticle.getSortNo() == null) { @@ -127,6 +130,44 @@ public class PortfolioServiceImpl extends AbstractService implements return map; } + @Override + public Map unbindArticle(Integer idPortfolio, Integer idArticle) { + Map map = new HashMap(1); + if (idPortfolio == null || idPortfolio.equals(0)) { + map.put("message", "作品集数据异常"); + } + if (idArticle == null || idArticle.equals(0)) { + map.put("message", "文章数据异常"); + } + Integer result = portfolioMapper.unbindArticle(idPortfolio,idArticle); + if (result > 0) { + map.put("message", "操作成功!"); + } else { + map.put("message", "操作失败!"); + } + return map; + } + + @Override + public Map deletePortfolio(Integer idPortfolio) { + Map map = new HashMap(1); + if (idPortfolio == null || idPortfolio.equals(0)) { + map.put("message", "作品集数据异常"); + } + + Integer articleNumber = portfolioMapper.selectCountArticleNumber(idPortfolio); + if (articleNumber > 0) { + map.put("message", "该作品集已绑定文章不允许删除!"); + } else { + Integer result = portfolioMapper.deleteByPrimaryKey(idPortfolio); + if (result.equals(0)) { + 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 425b681..4a4b0a2 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 @@ -61,4 +61,16 @@ public class PortfolioController { return GlobalResultGenerator.genSuccessResult(map); } + @DeleteMapping("/unbind-article") + public GlobalResult unbindArticle(Integer idArticle,Integer idPortfolio) { + Map map = portfolioService.unbindArticle(idPortfolio,idArticle); + return GlobalResultGenerator.genSuccessResult(map); + } + + @DeleteMapping("/delete") + public GlobalResult delete(Integer idPortfolio){ + Map map = portfolioService.deletePortfolio(idPortfolio); + return GlobalResultGenerator.genSuccessResult(map); + } + } diff --git a/src/main/java/mapper/PortfolioMapper.xml b/src/main/java/mapper/PortfolioMapper.xml index 0d367fa..c7f93a4 100644 --- a/src/main/java/mapper/PortfolioMapper.xml +++ b/src/main/java/mapper/PortfolioMapper.xml @@ -24,6 +24,9 @@ update vertical_portfolio_article set sort_no = #{sortNo} where id_vertical_portfolio = #{idPortfolio} and id_vertical_article = #{idArticle} + + delete from vertical_portfolio_article where id_vertical_portfolio = #{idPortfolio} and id_vertical_article = #{idArticle} +