|
@@ -2,14 +2,17 @@ package com.firerock.webttkuaiban.demos.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.firerock.webttkuaiban.demos.mapper.ArticleMapper;
|
|
import com.firerock.webttkuaiban.demos.mapper.ArticleMapper;
|
|
|
|
+import com.firerock.webttkuaiban.demos.mapper.CategoryMapper;
|
|
import com.firerock.webttkuaiban.demos.mapper.UserMapper;
|
|
import com.firerock.webttkuaiban.demos.mapper.UserMapper;
|
|
import com.firerock.webttkuaiban.demos.pojo.Article;
|
|
import com.firerock.webttkuaiban.demos.pojo.Article;
|
|
|
|
+import com.firerock.webttkuaiban.demos.pojo.Category;
|
|
import com.firerock.webttkuaiban.demos.service.ArticleService;
|
|
import com.firerock.webttkuaiban.demos.service.ArticleService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.util.StringUtils;
|
|
import org.springframework.util.StringUtils;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.StringJoiner;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
public class ArticleServiceImpl implements ArticleService {
|
|
public class ArticleServiceImpl implements ArticleService {
|
|
@@ -18,6 +21,8 @@ public class ArticleServiceImpl implements ArticleService {
|
|
private UserMapper userMapper;
|
|
private UserMapper userMapper;
|
|
@Autowired
|
|
@Autowired
|
|
private ArticleMapper articleMapper;
|
|
private ArticleMapper articleMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private CategoryMapper categoryMapper;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -42,9 +47,27 @@ public class ArticleServiceImpl implements ArticleService {
|
|
Article articleById = articleMapper.getArticleById(articleId);
|
|
Article articleById = articleMapper.getArticleById(articleId);
|
|
if (articleById!=null&& !StringUtils.isEmpty(articleById.getCategoryIds())){
|
|
if (articleById!=null&& !StringUtils.isEmpty(articleById.getCategoryIds())){
|
|
List<String> strings = JSONObject.parseArray(articleById.getCategoryIds(), String.class);
|
|
List<String> strings = JSONObject.parseArray(articleById.getCategoryIds(), String.class);
|
|
- return articleMapper.relatedList(strings);
|
|
|
|
|
|
+ return articleMapper.relatedList(strings,articleById.getId());
|
|
}else {
|
|
}else {
|
|
return new ArrayList<>();
|
|
return new ArrayList<>();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Article getArticleById(Integer articleId) {
|
|
|
|
+ Article article = articleMapper.getArticleById(articleId);
|
|
|
|
+ if (article!=null&&article.getCategoryIds()!=null&& !StringUtils.isEmpty(article.getCategoryIds())) {
|
|
|
|
+ List<String> categoryIds = JSONObject.parseArray(article.getCategoryIds(), String.class);
|
|
|
|
+ List<Category> list = categoryMapper.listByIds(categoryIds);
|
|
|
|
+ StringJoiner stringJoiner = new StringJoiner(",");
|
|
|
|
+ if (list != null && !list.isEmpty()) {
|
|
|
|
+ list.forEach(a -> stringJoiner.add(a.getCategoryName()));
|
|
|
|
+ article.setCategoryNames(stringJoiner.toString());
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ article.setCategoryNames("");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return article;
|
|
|
|
+ }
|
|
}
|
|
}
|