✨ 作品集功能
This commit is contained in:
parent
5b84fa9358
commit
49ab45f3bd
@ -51,4 +51,6 @@ public class ArticleDTO {
|
||||
private List<ArticleTagDTO> tags;
|
||||
|
||||
private List<CommentDTO> articleComments;
|
||||
|
||||
private List<PortfolioArticleDTO> portfolios;
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
}
|
@ -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<Article> {
|
||||
* @return
|
||||
*/
|
||||
List<ArticleDTO> selectArticlesByIdPortfolio(@Param("idPortfolio") Integer idPortfolio);
|
||||
|
||||
/**
|
||||
* 查询作品集未绑定文章
|
||||
* @param idPortfolio
|
||||
* @param searchText
|
||||
* @param idUser
|
||||
* @return
|
||||
*/
|
||||
List<ArticleDTO> selectUnbindArticlesByIdPortfolio(@Param("idPortfolio") Integer idPortfolio, @Param("searchText") String searchText, @Param("idUser") Integer idUser);
|
||||
|
||||
/**
|
||||
* 查询文章所属作品集列表
|
||||
* @param idArticle
|
||||
* @return
|
||||
*/
|
||||
List<PortfolioArticleDTO> selectPortfolioArticles(@Param("idArticle") Integer idArticle);
|
||||
}
|
||||
|
@ -31,4 +31,28 @@ public interface PortfolioMapper extends Mapper<Portfolio> {
|
||||
* @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);
|
||||
}
|
||||
|
@ -96,4 +96,13 @@ public interface ArticleService extends Service<Article> {
|
||||
* @return
|
||||
*/
|
||||
List<ArticleDTO> findArticlesByIdPortfolio(Integer idPortfolio);
|
||||
|
||||
/**
|
||||
* 查询作品集下未绑定文章
|
||||
* @param idPortfolio
|
||||
* @param searchText
|
||||
* @param idUser
|
||||
* @return
|
||||
*/
|
||||
List<ArticleDTO> selectUnbindArticles(Integer idPortfolio, String searchText, Integer idUser);
|
||||
}
|
||||
|
@ -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<Portfolio> {
|
||||
List<PortfolioDTO> 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);
|
||||
}
|
||||
|
@ -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<Article> implements Arti
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ArticleDTO> selectUnbindArticles(Integer idPortfolio, String searchText, Integer idUser) {
|
||||
List<ArticleDTO> 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<Article> implements Arti
|
||||
}
|
||||
List<CommentDTO> commentDTOList = commentService.getArticleComments(article.getIdArticle());
|
||||
article.setArticleComments(commentDTOList);
|
||||
|
||||
List<PortfolioArticleDTO> portfolioArticleDTOList = articleMapper.selectPortfolioArticles(article.getIdArticle());
|
||||
article.setPortfolios(portfolioArticleDTOList);
|
||||
return article;
|
||||
}
|
||||
}
|
||||
|
@ -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<Portfolio> implements
|
||||
private PortfolioMapper portfolioMapper;
|
||||
@Resource
|
||||
private UserService userService;
|
||||
@Resource
|
||||
private ArticleService articleService;
|
||||
|
||||
@Override
|
||||
public List<PortfolioDTO> findUserPortfoliosByUser(UserDTO userDTO) {
|
||||
@ -44,8 +48,8 @@ public class PortfolioServiceImpl extends AbstractService<Portfolio> 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<Portfolio> 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<ArticleDTO> articles = articleService.selectUnbindArticles(idPortfolio,searchText,user.getIdUser());
|
||||
PageInfo<ArticleDTO> 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());
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -54,6 +54,12 @@
|
||||
<result column="tag_uri" property="tagUri"></result>
|
||||
<result column="tag_description" property="tagDescription"></result>
|
||||
</resultMap>
|
||||
<resultMap id="PortfolioArticleResultMap" type="com.rymcu.vertical.dto.PortfolioArticleDTO">
|
||||
<result column="id_vertical_portfolio" property="idPortfolio"></result>
|
||||
<result column="id_vertical_article" property="idArticle"></result>
|
||||
<result column="portfolio_title" property="portfolioTitle"></result>
|
||||
<result column="portfolio_head_img_url" property="headImgUrl"></result>
|
||||
</resultMap>
|
||||
<insert id="insertArticleContent">
|
||||
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
|
||||
</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 art.*,su.nickname,su.avatar_url from vertical_article art join vertical_portfolio_article vpa on vpa.id_vertical_article = art.id and vpa.id_vertical_portfolio = #{idPortfolio}
|
||||
left join vertical_user su on art.article_author_id = su.id where art.article_status = 0 and vpa.id_vertical_portfolio = #{idPortfolio} order by sort_no
|
||||
</select>
|
||||
<select id="selectUnbindArticlesByIdPortfolio" resultMap="DTOResultMap">
|
||||
select art.*,su.nickname,su.avatar_url from vertical_article art left join vertical_user su on su.id = #{idUser} and art.article_author_id = su.id where art.article_author_id = #{idUser} and art.article_status = 0
|
||||
and instr(art.article_title, #{searchText}) > 0 and art.id not in (select id_vertical_article from vertical_portfolio_article where id_vertical_portfolio = #{idPortfolio}) order by updated_time desc
|
||||
</select>
|
||||
<select id="selectPortfolioArticles" resultMap="PortfolioArticleResultMap">
|
||||
select vp.portfolio_title,vp.portfolio_head_img_url,vpa.id_vertical_portfolio,vpa.id_vertical_article from vertical_portfolio vp join vertical_portfolio_article vpa on vp.id = vpa.id_vertical_portfolio where vpa.id_vertical_article = #{idArticle}
|
||||
</select>
|
||||
</mapper>
|
@ -18,6 +18,9 @@
|
||||
<result column="portfolio_description" property="portfolioDescription"></result>
|
||||
<result column="updated_time" property="updatedTime"></result>
|
||||
</resultMap>
|
||||
<insert id="insertPortfolioArticle">
|
||||
insert into vertical_portfolio_article (id_vertical_portfolio, id_vertical_article, sort_no) values (#{idPortfolio}, #{idArticle}, #{maxSortNo})
|
||||
</insert>
|
||||
<select id="selectUserPortfoliosByIdUser" resultMap="DTOResultMap">
|
||||
select id, portfolio_head_img_url, portfolio_title, portfolio_author_id, portfolio_description, updated_time from vertical_portfolio where portfolio_author_id = #{idUser}
|
||||
</select>
|
||||
@ -27,4 +30,10 @@
|
||||
<select id="selectCountArticleNumber" resultType="java.lang.Integer">
|
||||
select count(*) from vertical_portfolio_article where id_vertical_portfolio = #{idPortfolio}
|
||||
</select>
|
||||
<select id="selectCountPortfolioArticle" resultType="java.lang.Integer">
|
||||
select count(*) from vertical_portfolio_article where id_vertical_portfolio = #{idPortfolio} and id_vertical_article = #{idArticle}
|
||||
</select>
|
||||
<select id="selectMaxSortNo" resultType="java.lang.Integer">
|
||||
select ifnull(max(sort_no),0) + 1 from vertical_portfolio_article where id_vertical_portfolio = #{idPortfolio}
|
||||
</select>
|
||||
</mapper>
|
Loading…
Reference in New Issue
Block a user