我的草稿功能

This commit is contained in:
ronger 2020-03-13 17:32:56 +08:00
parent 6d13d5e6af
commit dc700dce4a
8 changed files with 113 additions and 2 deletions

View File

@ -41,6 +41,8 @@ public class ArticleDTO {
private String articlePermalink;
/** 站内链接 */
private String articleLink;
/** 文章状态 */
private String articleStatus;
/** 更新时间 */
private Date updatedTime;

View File

@ -46,4 +46,6 @@ public class Article implements Serializable,Cloneable {
private Date createdTime;
/** 更新时间 */
private Date updatedTime;
/** 文章状态 */
private String articleStatus;
}

View File

@ -10,34 +10,105 @@ import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @author ronger
*/
public interface ArticleMapper extends Mapper<Article> {
/**
* 获取文章列表
* @param searchText
* @param tag
* @return
*/
List<ArticleDTO> selectArticles(@Param("searchText") String searchText, @Param("tag") String tag);
/**
* 根据用户 ID 获取作者信息
* @param id
* @return
*/
Author selectAuthor(@Param("id") Integer id);
/**
* 根据文章 ID 查询文章
* @param id
* @return
*/
ArticleDTO selectArticleDTOById(@Param("id") Integer id);
/**
* 保存文章内容
* @param idArticle
* @param articleContent
* @param articleContentHtml
* @return
*/
Integer insertArticleContent(@Param("idArticle") Integer idArticle, @Param("articleContent") String articleContent, @Param("articleContentHtml") String articleContentHtml);
/**
* 更新文章内容
* @param idArticle
* @param articleContent
* @param articleContentHtml
* @return
*/
Integer updateArticleContent(@Param("idArticle") Integer idArticle, @Param("articleContent") String articleContent, @Param("articleContentHtml") String articleContentHtml);
/**
* 获取文章正文内容
* @param idArticle
* @return
*/
ArticleContent selectArticleContent(@Param("idArticle") Integer idArticle);
/**
* 获取主题下文章列表
* @param topicName
* @return
*/
List<ArticleDTO> selectArticlesByTopicUri(@Param("topicName") String topicName);
/**
* 获取标签下文章列表
* @param tagName
* @return
*/
List<ArticleDTO> selectArticlesByTagName(@Param("tagName") String tagName);
/**
* 获取用户文章列表
* @param idUser
* @return
*/
List<ArticleDTO> selectUserArticles(@Param("idUser") Integer idUser);
/**
* 删除文章标签
* @param id
* @return
*/
Integer deleteTagArticle(@Param("id") Integer id);
/**
* 获取文章标签列表
* @param idArticle
* @return
*/
List<ArticleTagDTO> selectTags(@Param("idArticle") Integer idArticle);
/**
*
* 更新文章浏览数
* @param id
* @param articleViewCount
* @return
*/
Integer updateArticleViewCount(@Param("id") Integer id, @Param("articleViewCount") Integer articleViewCount);
/**
* 获取草稿列表
* @param idUser
* @return
*/
List<ArticleDTO> selectDrafts(@Param("idUser") Integer idUser);
}

View File

@ -74,4 +74,10 @@ public interface ArticleService extends Service<Article> {
* @param id
*/
void incrementArticleViewCount(Integer id);
/**
* 查询草稿文章类别
* @return
*/
List<ArticleDTO> findDrafts() throws BaseApiException;
}

View File

@ -127,6 +127,7 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
newArticle.setArticleTags(articleTags);
newArticle.setCreatedTime(new Date());
newArticle.setUpdatedTime(newArticle.getCreatedTime());
newArticle.setArticleStatus(article.getArticleStatus());
articleMapper.insertSelective(newArticle);
newArticle.setArticlePermalink(domain + "/article/"+newArticle.getIdArticle());
newArticle.setArticleLink("/article/"+newArticle.getIdArticle());
@ -226,6 +227,16 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
articleMapper.updateArticleViewCount(article.getIdArticle(), articleViewCount);
}
@Override
public List<ArticleDTO> findDrafts() throws BaseApiException {
User user = UserUtils.getWxCurrentUser();
List<ArticleDTO> list = articleMapper.selectDrafts(user.getIdUser());
list.forEach(article->{
genArticle(article,0);
});
return list;
}
private ArticleDTO genArticle(ArticleDTO article,Integer type) {
Author author = articleMapper.selectAuthor(article.getArticleAuthorId());
article.setArticleAuthor(author);

View File

@ -20,6 +20,9 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
/**
* @author ronger
*/
@Service
public class CommentServiceImpl extends AbstractService<Comment> implements CommentService {

View File

@ -1,11 +1,14 @@
package com.rymcu.vertical.web.api.article;
import com.github.pagehelper.PageHelper;
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.CommentDTO;
import com.rymcu.vertical.service.ArticleService;
import com.rymcu.vertical.service.CommentService;
import com.rymcu.vertical.util.Utils;
import com.rymcu.vertical.web.api.exception.BaseApiException;
import org.springframework.web.bind.annotation.*;
@ -64,4 +67,13 @@ public class ArticleController {
return GlobalResultGenerator.genSuccessResult(map);
}
@GetMapping("/drafts")
public GlobalResult drafts(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows) throws BaseApiException {
PageHelper.startPage(page, rows);
List<ArticleDTO> list = articleService.findDrafts();
PageInfo<ArticleDTO> pageInfo = new PageInfo(list);
Map map = Utils.getArticlesGlobalResult(pageInfo);
return GlobalResultGenerator.genSuccessResult(map);
}
}

View File

@ -35,6 +35,7 @@
<result column="time_ago" property="timeAgo"></result>
<result column="article_permalink" property="articlePermalink"></result>
<result column="article_link" property="articleLink"></result>
<result column="article_status" property="articleStatus"></result>
<result column="updated_time" property="updatedTime"></result>
</resultMap>
<resultMap id="AuthorResultMap" type="com.rymcu.vertical.dto.Author">
@ -70,7 +71,7 @@
delete from vertical_tag_article where id_article = #{id}
</delete>
<select id="selectArticles" 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 order by updated_time desc
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 = '0' order by updated_time desc
</select>
<select id="selectAuthor" resultMap="AuthorResultMap">
select * from vertical_user where id = #{id}
@ -96,4 +97,7 @@
<select id="selectTags" resultMap="ArticleTagDTOResultMap">
select vt.id, vt.tag_title, vt.tag_icon_path, vt.tag_uri, vt.tag_description from vertical_tag vt left join vertical_tag_article vta on vt.id = vta.id_tag where vta.id_article = #{idArticle}
</select>
<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>
</mapper>