修改文章标签功能

This commit is contained in:
x ronger 2020-09-23 22:39:08 +08:00
parent c5454b6666
commit 3d64707c9b
5 changed files with 44 additions and 4 deletions

View File

@ -136,4 +136,12 @@ public interface ArticleMapper extends Mapper<Article> {
* @return
*/
List<PortfolioArticleDTO> selectPortfolioArticles(@Param("idArticle") Integer idArticle);
/**
* 更新文章标签
* @param idArticle
* @param tags
* @return
*/
Integer updateArticleTags(@Param("idArticle") Integer idArticle, @Param("tags") String tags);
}

View File

@ -105,4 +105,12 @@ public interface ArticleService extends Service<Article> {
* @return
*/
List<ArticleDTO> selectUnbindArticles(Integer idPortfolio, String searchText, Integer idUser);
/**
* 更新文章标签
* @param idArticle
* @param tags
* @return
*/
Map updateTags(Integer idArticle, String tags) throws UnsupportedEncodingException, BaseApiException;
}

View File

@ -25,10 +25,7 @@ import tk.mybatis.mapper.entity.Condition;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
* @author ronger
@ -294,6 +291,23 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
return list;
}
@Override
@Transactional(rollbackFor = Exception.class)
public Map updateTags(Integer idArticle, String tags) throws UnsupportedEncodingException, BaseApiException {
Map map = new HashMap(2);
Article article = articleMapper.selectByPrimaryKey(idArticle);
if (Objects.nonNull(article)) {
article.setArticleTags(tags);
articleMapper.updateArticleTags(idArticle, tags);
tagService.saveTagArticle(article);
map.put("success", true);
} else {
map.put("success", false);
map.put("message", "更新失败,文章不存在!");
}
return map;
}
private ArticleDTO genArticle(ArticleDTO article, Integer type) {
Integer ARTICLE_LIST = 0;
Integer ARTICLE_VIEW = 1;

View File

@ -6,6 +6,7 @@ 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.entity.Article;
import com.rymcu.vertical.service.ArticleService;
import com.rymcu.vertical.service.CommentService;
import com.rymcu.vertical.util.Utils;
@ -80,4 +81,10 @@ public class ArticleController {
return GlobalResultGenerator.genSuccessResult(map);
}
@PostMapping("/{id}/update-tags")
public GlobalResult updateTags(@PathVariable Integer id, @RequestBody Article article) throws BaseApiException, UnsupportedEncodingException {
Map map = articleService.updateTags(id, article.getArticleTags());
return GlobalResultGenerator.genSuccessResult(map);
}
}

View File

@ -71,6 +71,9 @@
<update id="updateArticleViewCount">
update vertical_article set article_view_count = #{articleViewCount} where id = #{id}
</update>
<update id="updateArticleTags">
update vertical_article set article_tags = #{tags} where id = #{idArticle}
</update>
<delete id="deleteTagArticle">
delete from vertical_tag_article where id_article = #{id}
</delete>