diff --git a/src/main/java/com/rymcu/vertical/dto/PortfolioDTO.java b/src/main/java/com/rymcu/vertical/dto/PortfolioDTO.java new file mode 100644 index 0000000..772f46a --- /dev/null +++ b/src/main/java/com/rymcu/vertical/dto/PortfolioDTO.java @@ -0,0 +1,35 @@ +package com.rymcu.vertical.dto; + +import lombok.Data; + +import java.util.Date; + +/** + * @author ronger + */ +@Data +public class PortfolioDTO { + + private Integer idPortfolio; + /** 作品集头像 */ + private String headImgUrl; + /** 作品集作者 */ + private Integer portfolioAuthorId; + /** 作品集作者 */ + private String portfolioAuthorName; + /** 作品集作者头像 */ + private String portfolioAuthorAvatarUrl; + /** 作品集名称 */ + private String name; + /** 作品集介绍 */ + private String description; + /** 更新时间 */ + private Date updatedTime; + /** 过去时长 */ + private String timeAgo; + + private Author portfolioAuthor; + + private Integer articleNumber; + +} diff --git a/src/main/java/com/rymcu/vertical/mapper/ArticleMapper.java b/src/main/java/com/rymcu/vertical/mapper/ArticleMapper.java index 4135199..31eed56 100644 --- a/src/main/java/com/rymcu/vertical/mapper/ArticleMapper.java +++ b/src/main/java/com/rymcu/vertical/mapper/ArticleMapper.java @@ -111,4 +111,11 @@ public interface ArticleMapper extends Mapper
{ * @return */ Integer deleteUnusedArticleTag(@Param("idArticleTag") Integer idArticleTag); + + /** + * 查询作品集下文章 + * @param idPortfolio + * @return + */ + List selectArticlesByIdPortfolio(@Param("idPortfolio") Integer idPortfolio); } diff --git a/src/main/java/com/rymcu/vertical/mapper/PortfolioMapper.java b/src/main/java/com/rymcu/vertical/mapper/PortfolioMapper.java index fbe5c7c..23a6d20 100644 --- a/src/main/java/com/rymcu/vertical/mapper/PortfolioMapper.java +++ b/src/main/java/com/rymcu/vertical/mapper/PortfolioMapper.java @@ -1,10 +1,34 @@ package com.rymcu.vertical.mapper; import com.rymcu.vertical.core.mapper.Mapper; +import com.rymcu.vertical.dto.PortfolioDTO; import com.rymcu.vertical.entity.Portfolio; +import org.apache.ibatis.annotations.Param; + +import java.util.List; /** * @author ronger */ public interface PortfolioMapper extends Mapper { + /** + * 查询用户作品集 + * @param idUser + * @return + */ + List selectUserPortfoliosByIdUser(@Param("idUser") Integer idUser); + + /** + * 查询作品集 + * @param id + * @return + */ + PortfolioDTO selectPortfolioDTOById(@Param("id") Integer id); + + /** + * 统计作品集下文章数 + * @param idPortfolio + * @return + */ + Integer selectCountArticleNumber(@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 30325a3..2ab3a97 100644 --- a/src/main/java/com/rymcu/vertical/service/ArticleService.java +++ b/src/main/java/com/rymcu/vertical/service/ArticleService.java @@ -78,13 +78,22 @@ public interface ArticleService extends Service
{ /** * 获取分享链接数据 * @param id + * @throws BaseApiException * @return */ Map share(Integer id) throws BaseApiException; /** * 查询草稿文章类别 + * @throws BaseApiException * @return */ List findDrafts() throws BaseApiException; + + /** + * 查询作品集下文章 + * @param idPortfolio + * @return + */ + List findArticlesByIdPortfolio(Integer idPortfolio); } diff --git a/src/main/java/com/rymcu/vertical/service/PortfolioService.java b/src/main/java/com/rymcu/vertical/service/PortfolioService.java index 6d0b9b0..0d516bd 100644 --- a/src/main/java/com/rymcu/vertical/service/PortfolioService.java +++ b/src/main/java/com/rymcu/vertical/service/PortfolioService.java @@ -1,10 +1,36 @@ package com.rymcu.vertical.service; import com.rymcu.vertical.core.service.Service; +import com.rymcu.vertical.dto.PortfolioDTO; +import com.rymcu.vertical.dto.UserDTO; import com.rymcu.vertical.entity.Portfolio; +import com.rymcu.vertical.web.api.exception.BaseApiException; + +import java.util.List; +import java.util.Map; /** * @author ronger */ public interface PortfolioService extends Service { + + /** + * 查询用户作品集 + * @param userDTO + * @return + */ + List findUserPortfoliosByUser(UserDTO userDTO); + + /** 查询作品集 + * @param id + * @return + */ + PortfolioDTO findPortfolioDTOById(Integer id); + + /** + * 保持/更新作品集 + * @param portfolio + * @return + */ + Portfolio postPortfolio(Portfolio portfolio) throws BaseApiException; } 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 8a6a80e..d3dcc44 100644 --- a/src/main/java/com/rymcu/vertical/service/impl/ArticleServiceImpl.java +++ b/src/main/java/com/rymcu/vertical/service/impl/ArticleServiceImpl.java @@ -263,6 +263,15 @@ public class ArticleServiceImpl extends AbstractService
implements Arti return list; } + @Override + public List findArticlesByIdPortfolio(Integer idPortfolio) { + List list = articleMapper.selectArticlesByIdPortfolio(idPortfolio); + list.forEach(article->{ + genArticle(article,0); + }); + return list; + } + private ArticleDTO genArticle(ArticleDTO article, Integer type) { Author author = userService.selectAuthor(article.getArticleAuthorId()); article.setArticleAuthor(author); 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 2630d6c..51db999 100644 --- a/src/main/java/com/rymcu/vertical/service/impl/PortfolioServiceImpl.java +++ b/src/main/java/com/rymcu/vertical/service/impl/PortfolioServiceImpl.java @@ -1,12 +1,23 @@ package com.rymcu.vertical.service.impl; 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.entity.Portfolio; +import com.rymcu.vertical.entity.User; import com.rymcu.vertical.mapper.PortfolioMapper; import com.rymcu.vertical.service.PortfolioService; +import com.rymcu.vertical.service.UserService; +import com.rymcu.vertical.util.UserUtils; +import com.rymcu.vertical.web.api.exception.BaseApiException; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * @author ronger @@ -16,5 +27,52 @@ public class PortfolioServiceImpl extends AbstractService implements @Resource private PortfolioMapper portfolioMapper; + @Resource + private UserService userService; + @Override + public List findUserPortfoliosByUser(UserDTO userDTO) { + List list = portfolioMapper.selectUserPortfoliosByIdUser(userDTO.getIdUser()); + Author author = new Author(); + author.setIdUser(userDTO.getIdUser()); + author.setUserAvatarURL(userDTO.getAvatarUrl()); + author.setUserNickname(userDTO.getNickname()); + list.forEach(portfolioDTO -> { + genPortfolioAuthor(portfolioDTO,author); + }); + return list; + } + + @Override + public PortfolioDTO findPortfolioDTOById(Integer id) { + PortfolioDTO portfolio = portfolioMapper.selectPortfolioDTOById(id); + Author author = userService.selectAuthor(portfolio.getPortfolioAuthorId()); + genPortfolioAuthor(portfolio,author); + Integer articleNumber = portfolioMapper.selectCountArticleNumber(portfolio.getIdPortfolio()); + portfolio.setArticleNumber(articleNumber); + return portfolio; + } + + @Override + public Portfolio postPortfolio(Portfolio portfolio) throws BaseApiException { + User user = UserUtils.getWxCurrentUser(); + if (portfolio.getIdPortfolio() == null || portfolio.getIdPortfolio() == 0) { + portfolio.setPortfolioAuthorId(user.getIdUser()); + portfolio.setCreatedTime(new Date()); + portfolio.setUpdatedTime(portfolio.getCreatedTime()); + portfolioMapper.insertSelective(portfolio); + } else { + portfolio.setUpdatedTime(new Date()); + portfolioMapper.updateByPrimaryKeySelective(portfolio); + } + return portfolio; + } + + private PortfolioDTO genPortfolioAuthor(PortfolioDTO portfolioDTO, Author author) { + portfolioDTO.setPortfolioAuthorAvatarUrl(author.getUserAvatarURL()); + portfolioDTO.setPortfolioAuthorName(author.getUserNickname()); + portfolioDTO.setPortfolioAuthorId(author.getIdUser()); + portfolioDTO.setPortfolioAuthor(author); + return portfolioDTO; + } } diff --git a/src/main/java/com/rymcu/vertical/service/impl/TagServiceImpl.java b/src/main/java/com/rymcu/vertical/service/impl/TagServiceImpl.java index 16b25fd..1d0352d 100644 --- a/src/main/java/com/rymcu/vertical/service/impl/TagServiceImpl.java +++ b/src/main/java/com/rymcu/vertical/service/impl/TagServiceImpl.java @@ -107,7 +107,7 @@ public class TagServiceImpl extends AbstractService implements TagService { @Override @Transactional(rollbackFor = Exception.class) public Map saveTag(Tag tag) { - Integer result = 0; + Integer result; Map map = new HashMap(1); if (tag.getIdTag() == null) { diff --git a/src/main/java/com/rymcu/vertical/web/api/common/CommonApiController.java b/src/main/java/com/rymcu/vertical/web/api/common/CommonApiController.java index b26ea25..311fc80 100644 --- a/src/main/java/com/rymcu/vertical/web/api/common/CommonApiController.java +++ b/src/main/java/com/rymcu/vertical/web/api/common/CommonApiController.java @@ -6,13 +6,11 @@ import com.rymcu.vertical.core.result.GlobalResult; import com.rymcu.vertical.core.result.GlobalResultGenerator; import com.rymcu.vertical.core.result.GlobalResultMessage; import com.rymcu.vertical.core.service.log.annotation.VisitLogger; -import com.rymcu.vertical.dto.ArticleDTO; -import com.rymcu.vertical.dto.ForgetPasswordDTO; -import com.rymcu.vertical.dto.TokenUser; -import com.rymcu.vertical.dto.UserRegisterInfoDTO; +import com.rymcu.vertical.dto.*; import com.rymcu.vertical.entity.User; import com.rymcu.vertical.service.ArticleService; import com.rymcu.vertical.service.JavaMailService; +import com.rymcu.vertical.service.PortfolioService; import com.rymcu.vertical.service.UserService; import com.rymcu.vertical.util.UserUtils; import com.rymcu.vertical.util.Utils; @@ -38,6 +36,8 @@ public class CommonApiController { private UserService userService; @Resource private ArticleService articleService; + @Resource + private PortfolioService portfolioService; @ApiOperation(value = "获取邮件验证码") @GetMapping("/get-email-code") @@ -120,4 +120,22 @@ public class CommonApiController { Map map = userService.forgetPassword(forgetPassword.getCode(), forgetPassword.getPassword()); return GlobalResultGenerator.genSuccessResult(map); } + + @GetMapping("/portfolio/{id}") + @VisitLogger + public GlobalResult> portfolio(@PathVariable Integer id){ + PortfolioDTO portfolioDTO = portfolioService.findPortfolioDTOById(id); + Map map = new HashMap<>(1); + map.put("portfolio", portfolioDTO); + return GlobalResultGenerator.genSuccessResult(map); + } + + @GetMapping("/portfolio/{id}/articles") + public GlobalResult articles(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows, @PathVariable Integer id) { + PageHelper.startPage(page, rows); + List list = articleService.findArticlesByIdPortfolio(id); + PageInfo pageInfo = new PageInfo(list); + Map map = Utils.getArticlesGlobalResult(pageInfo); + return GlobalResultGenerator.genSuccessResult(map); + } } 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 new file mode 100644 index 0000000..10cbfc7 --- /dev/null +++ b/src/main/java/com/rymcu/vertical/web/api/portfolio/PortfolioController.java @@ -0,0 +1,45 @@ +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.PortfolioDTO; +import com.rymcu.vertical.entity.Portfolio; +import com.rymcu.vertical.service.PortfolioService; +import com.rymcu.vertical.web.api.exception.BaseApiException; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.Map; + +/** + * @author ronger + */ +@RestController +@RequestMapping("/api/v1/portfolio") +public class PortfolioController { + + @Resource + private PortfolioService portfolioService; + + @GetMapping("/detail/{id}") + public GlobalResult detail(@PathVariable Integer id) { + PortfolioDTO portfolio = portfolioService.findPortfolioDTOById(id); + Map map = new HashMap<>(1); + map.put("portfolio", portfolio); + return GlobalResultGenerator.genSuccessResult(map); + } + + @PostMapping("/post") + public GlobalResult add(@RequestBody Portfolio portfolio) throws BaseApiException { + portfolio = portfolioService.postPortfolio(portfolio); + return GlobalResultGenerator.genSuccessResult(portfolio); + } + + @PutMapping("/post") + public GlobalResult update(@RequestBody Portfolio portfolio) throws BaseApiException { + portfolio = portfolioService.postPortfolio(portfolio); + return GlobalResultGenerator.genSuccessResult(portfolio); + } + +} diff --git a/src/main/java/com/rymcu/vertical/web/api/user/UserController.java b/src/main/java/com/rymcu/vertical/web/api/user/UserController.java index 206578f..10f218c 100644 --- a/src/main/java/com/rymcu/vertical/web/api/user/UserController.java +++ b/src/main/java/com/rymcu/vertical/web/api/user/UserController.java @@ -5,13 +5,16 @@ import com.github.pagehelper.PageInfo; import com.rymcu.vertical.core.result.GlobalResult; import com.rymcu.vertical.core.result.GlobalResultGenerator; import com.rymcu.vertical.dto.ArticleDTO; +import com.rymcu.vertical.dto.PortfolioDTO; import com.rymcu.vertical.dto.UserDTO; import com.rymcu.vertical.service.ArticleService; +import com.rymcu.vertical.service.PortfolioService; import com.rymcu.vertical.service.UserService; import com.rymcu.vertical.util.Utils; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -26,6 +29,8 @@ public class UserController { private UserService userService; @Resource private ArticleService articleService; + @Resource + private PortfolioService portfolioService; @GetMapping("/{nickname}") public GlobalResult detail(@PathVariable String nickname){ @@ -46,4 +51,20 @@ public class UserController { return GlobalResultGenerator.genSuccessResult(map); } + @GetMapping("/{nickname}/portfolios") + public GlobalResult userPortfolios(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "12") Integer rows, @PathVariable String nickname){ + UserDTO userDTO = userService.findUserDTOByNickname(nickname); + if (userDTO == null){ + return GlobalResultGenerator.genErrorResult("用户不存在!"); + } + PageHelper.startPage(page, rows); + List list = portfolioService.findUserPortfoliosByUser(userDTO); + PageInfo pageInfo = new PageInfo(list); + Map map = new HashMap(2); + map.put("portfolios", list); + Map pagination = Utils.getPagination(pageInfo); + map.put("pagination", pagination); + return GlobalResultGenerator.genSuccessResult(map); + } + } diff --git a/src/main/java/mapper/ArticleMapper.xml b/src/main/java/mapper/ArticleMapper.xml index 407ec77..ffeddf3 100644 --- a/src/main/java/mapper/ArticleMapper.xml +++ b/src/main/java/mapper/ArticleMapper.xml @@ -101,4 +101,8 @@ + \ No newline at end of file diff --git a/src/main/java/mapper/PortfolioMapper.xml b/src/main/java/mapper/PortfolioMapper.xml index 54dac69..e78ece3 100644 --- a/src/main/java/mapper/PortfolioMapper.xml +++ b/src/main/java/mapper/PortfolioMapper.xml @@ -10,4 +10,21 @@ + + + + + + + + + + + \ No newline at end of file