|
@@ -9,6 +9,7 @@ import com.my.bigevent.mapper.CategoryMapper;
|
|
import com.my.bigevent.pojo.Article;
|
|
import com.my.bigevent.pojo.Article;
|
|
import com.my.bigevent.pojo.ArticleCoverImg;
|
|
import com.my.bigevent.pojo.ArticleCoverImg;
|
|
import com.my.bigevent.pojo.PageBean;
|
|
import com.my.bigevent.pojo.PageBean;
|
|
|
|
+import com.my.bigevent.pojo.Result;
|
|
import com.my.bigevent.service.ArticleService;
|
|
import com.my.bigevent.service.ArticleService;
|
|
import com.my.bigevent.utils.ThreadLocalUtil;
|
|
import com.my.bigevent.utils.ThreadLocalUtil;
|
|
import org.junit.platform.commons.util.StringUtils;
|
|
import org.junit.platform.commons.util.StringUtils;
|
|
@@ -103,7 +104,16 @@ public class ArticleServiceImpl implements ArticleService
|
|
// 调用 mapper
|
|
// 调用 mapper
|
|
Map<String,Object> map=ThreadLocalUtil.get();
|
|
Map<String,Object> map=ThreadLocalUtil.get();
|
|
Integer userId=(Integer)map.get("id");
|
|
Integer userId=(Integer)map.get("id");
|
|
- List<Article> as=articleMapper.list(userId,categoryId,state);
|
|
|
|
|
|
+ String categoryIdStr=categoryId==null?"":categoryId.toString();
|
|
|
|
+ List<Article> as=articleMapper.list(userId,categoryIdStr,state);
|
|
|
|
+ if (!as.isEmpty()){
|
|
|
|
+ for (Article a : as) {
|
|
|
|
+ ArticleCoverImg articleCoverImg= coverImgMapper.selectByArticleId(a.getId());
|
|
|
|
+ if(null!=articleCoverImg&&articleCoverImg.getCoverImgData()!=null){
|
|
|
|
+ a.setCoverImg(articleCoverImg.getCoverImgData());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
// Page 中提供了方法,可以获取 PageHelper 分页查询后,得到的总记录条数和当前页数据
|
|
// Page 中提供了方法,可以获取 PageHelper 分页查询后,得到的总记录条数和当前页数据
|
|
Page<Article> p=(Page<Article>) as;
|
|
Page<Article> p=(Page<Article>) as;
|
|
|
|
|
|
@@ -122,10 +132,11 @@ public class ArticleServiceImpl implements ArticleService
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@Transactional
|
|
@Transactional
|
|
- public void insertOrUpdateArticle(String title, String categoryIds,String profile, String content, String state, MultipartFile coverImage, Integer id) {
|
|
|
|
|
|
+ public void insertOrUpdateArticle(String title, String categoryIds,String profile, String content, String state, MultipartFile coverImage, Integer id,String productId) {
|
|
Optional.ofNullable(title).orElseThrow(() -> new RuntimeException("请传标题"));
|
|
Optional.ofNullable(title).orElseThrow(() -> new RuntimeException("请传标题"));
|
|
Optional.ofNullable(content).orElseThrow(() -> new RuntimeException("请书写文章内容"));
|
|
Optional.ofNullable(content).orElseThrow(() -> new RuntimeException("请书写文章内容"));
|
|
Optional.ofNullable(state).orElseThrow(() -> new RuntimeException("请传递发布类型"));
|
|
Optional.ofNullable(state).orElseThrow(() -> new RuntimeException("请传递发布类型"));
|
|
|
|
+ Optional.ofNullable(productId).orElseThrow(() -> new RuntimeException("请传递产品类型"));
|
|
|
|
|
|
// 新增
|
|
// 新增
|
|
if (id == null) {
|
|
if (id == null) {
|
|
@@ -142,6 +153,7 @@ public class ArticleServiceImpl implements ArticleService
|
|
article.setCreateTime(LocalDateTime.now());
|
|
article.setCreateTime(LocalDateTime.now());
|
|
article.setUpdateTime(LocalDateTime.now());
|
|
article.setUpdateTime(LocalDateTime.now());
|
|
article.setCreateUser(6);
|
|
article.setCreateUser(6);
|
|
|
|
+ article.setProductId(productId);
|
|
|
|
|
|
articleMapper.insert(article);
|
|
articleMapper.insert(article);
|
|
log.info("文章的id{}", article.getId());
|
|
log.info("文章的id{}", article.getId());
|
|
@@ -163,6 +175,7 @@ public class ArticleServiceImpl implements ArticleService
|
|
article.setState(state);
|
|
article.setState(state);
|
|
article.setUpdateTime(LocalDateTime.now());
|
|
article.setUpdateTime(LocalDateTime.now());
|
|
article.setId(id);
|
|
article.setId(id);
|
|
|
|
+ article.setProductId(productId);
|
|
articleMapper.update(article);
|
|
articleMapper.update(article);
|
|
|
|
|
|
if (coverImage != null) {
|
|
if (coverImage != null) {
|
|
@@ -213,6 +226,13 @@ public class ArticleServiceImpl implements ArticleService
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public Result deleteById(Integer articleId) {
|
|
|
|
+ articleMapper.deleteById(articleId);
|
|
|
|
+ coverImgMapper.deleteByArticleId(articleId);
|
|
|
|
+ return Result.success();
|
|
|
|
+ }
|
|
|
|
+
|
|
private void handleCoverImage(MultipartFile coverImage, Integer articleId) {
|
|
private void handleCoverImage(MultipartFile coverImage, Integer articleId) {
|
|
String fileName = coverImage.getOriginalFilename();
|
|
String fileName = coverImage.getOriginalFilename();
|
|
String fileType = fileName.substring(fileName.lastIndexOf("."));
|
|
String fileType = fileName.substring(fileName.lastIndexOf("."));
|