作品集功能

This commit is contained in:
ronger 2020-04-08 17:53:32 +08:00
parent 686cbb925e
commit 27db7a83f7
13 changed files with 278 additions and 5 deletions

View File

@ -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;
}

View File

@ -111,4 +111,11 @@ public interface ArticleMapper extends Mapper<Article> {
* @return
*/
Integer deleteUnusedArticleTag(@Param("idArticleTag") Integer idArticleTag);
/**
* 查询作品集下文章
* @param idPortfolio
* @return
*/
List<ArticleDTO> selectArticlesByIdPortfolio(@Param("idPortfolio") Integer idPortfolio);
}

View File

@ -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<Portfolio> {
/**
* 查询用户作品集
* @param idUser
* @return
*/
List<PortfolioDTO> selectUserPortfoliosByIdUser(@Param("idUser") Integer idUser);
/**
* 查询作品集
* @param id
* @return
*/
PortfolioDTO selectPortfolioDTOById(@Param("id") Integer id);
/**
* 统计作品集下文章数
* @param idPortfolio
* @return
*/
Integer selectCountArticleNumber(@Param("idPortfolio") Integer idPortfolio);
}

View File

@ -78,13 +78,22 @@ public interface ArticleService extends Service<Article> {
/**
* 获取分享链接数据
* @param id
* @throws BaseApiException
* @return
*/
Map share(Integer id) throws BaseApiException;
/**
* 查询草稿文章类别
* @throws BaseApiException
* @return
*/
List<ArticleDTO> findDrafts() throws BaseApiException;
/**
* 查询作品集下文章
* @param idPortfolio
* @return
*/
List<ArticleDTO> findArticlesByIdPortfolio(Integer idPortfolio);
}

View File

@ -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<Portfolio> {
/**
* 查询用户作品集
* @param userDTO
* @return
*/
List<PortfolioDTO> findUserPortfoliosByUser(UserDTO userDTO);
/** 查询作品集
* @param id
* @return
*/
PortfolioDTO findPortfolioDTOById(Integer id);
/**
* 保持/更新作品集
* @param portfolio
* @return
*/
Portfolio postPortfolio(Portfolio portfolio) throws BaseApiException;
}

View File

@ -263,6 +263,15 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
return list;
}
@Override
public List<ArticleDTO> findArticlesByIdPortfolio(Integer idPortfolio) {
List<ArticleDTO> 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);

View File

@ -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<Portfolio> implements
@Resource
private PortfolioMapper portfolioMapper;
@Resource
private UserService userService;
@Override
public List<PortfolioDTO> findUserPortfoliosByUser(UserDTO userDTO) {
List<PortfolioDTO> 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;
}
}

View File

@ -107,7 +107,7 @@ public class TagServiceImpl extends AbstractService<Tag> 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) {

View File

@ -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<Map<String, Object>> portfolio(@PathVariable Integer id){
PortfolioDTO portfolioDTO = portfolioService.findPortfolioDTOById(id);
Map<String, Object> 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<ArticleDTO> list = articleService.findArticlesByIdPortfolio(id);
PageInfo<ArticleDTO> pageInfo = new PageInfo(list);
Map map = Utils.getArticlesGlobalResult(pageInfo);
return GlobalResultGenerator.genSuccessResult(map);
}
}

View File

@ -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);
}
}

View File

@ -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<PortfolioDTO> list = portfolioService.findUserPortfoliosByUser(userDTO);
PageInfo<PortfolioDTO> 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);
}
}

View File

@ -101,4 +101,8 @@
<select id="selectDrafts" resultMap="DTOResultMap">
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
</select>
<select id="selectArticlesByIdPortfolio" resultMap="DTOResultMap">
select art.*,su.nickname,su.avatar_url from vertical_article art left join vertical_user su on art.article_author_id = su.id where art.article_status = 0
and art.id in (select id_vertical_article from vertical_portfolio_article where id_vertical_portfolio = #{idPortfolio}) order by updated_time desc
</select>
</mapper>

View File

@ -10,4 +10,21 @@
<result column="created_time" property="createdTime"></result>
<result column="updated_time" property="updatedTime"></result>
</resultMap>
<resultMap id="DTOResultMap" type="com.rymcu.vertical.dto.PortfolioDTO">
<result column="id" property="idPortfolio"></result>
<result column="head_img_url" property="headImgUrl"></result>
<result column="name" property="name"></result>
<result column="portfolio_author_id" property="portfolioAuthorId"></result>
<result column="description" property="description"></result>
<result column="updated_time" property="updatedTime"></result>
</resultMap>
<select id="selectUserPortfoliosByIdUser" resultMap="DTOResultMap">
select id, head_img_url, name, portfolio_author_id, description, updated_time from vertical_portfolio where portfolio_author_id = #{idUser}
</select>
<select id="selectPortfolioDTOById" resultMap="DTOResultMap">
select id, head_img_url, name, portfolio_author_id, description, updated_time from vertical_portfolio where id = #{id}
</select>
<select id="selectCountArticleNumber" resultType="java.lang.Integer">
select count(*) from vertical_portfolio_article where id_vertical_portfolio = #{idPortfolio}
</select>
</mapper>