|
|
|
@ -3,9 +3,11 @@ package com.jingcheng.cms.service.impl;
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.jingcheng.cms.constants.Constants;
|
|
|
|
|
import com.jingcheng.cms.mapper.ArticleCategoryMapper;
|
|
|
|
|
import com.jingcheng.cms.mapper.ArticleMapper;
|
|
|
|
|
import com.jingcheng.cms.mapper.CategoryMapper;
|
|
|
|
|
import com.jingcheng.cms.model.Article;
|
|
|
|
|
import com.jingcheng.cms.model.ArticleCategory;
|
|
|
|
|
import com.jingcheng.cms.model.Category;
|
|
|
|
|
import com.jingcheng.cms.service.ArticleSerive;
|
|
|
|
|
import com.jingcheng.cms.util.AjaxResult;
|
|
|
|
@ -17,6 +19,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import tk.mybatis.mapper.entity.Example;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
@ -27,6 +30,8 @@ public class ArticleSerivceImpl implements ArticleSerive {
|
|
|
|
|
private ArticleMapper articleMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private CategoryMapper categoryMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private ArticleCategoryMapper articleCategoryMapper;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -34,7 +39,7 @@ public class ArticleSerivceImpl implements ArticleSerive {
|
|
|
|
|
AjaxResult ajaxResult = new AjaxResult();
|
|
|
|
|
Long id = jsonObject.getLong("id");
|
|
|
|
|
String title = jsonObject.getString("title");
|
|
|
|
|
Long firstCategory = jsonObject.getLong("firstCategory");
|
|
|
|
|
JSONArray firstCategory = jsonObject.getJSONArray("firstCategory");
|
|
|
|
|
Long secondCategory = jsonObject.getLong("secondCategory");
|
|
|
|
|
String keyword = jsonObject.getString("keyword");
|
|
|
|
|
Integer fileType = jsonObject.getInteger("fileType");
|
|
|
|
@ -76,16 +81,16 @@ public class ArticleSerivceImpl implements ArticleSerive {
|
|
|
|
|
//新增
|
|
|
|
|
Article article = new Article();
|
|
|
|
|
article.setTitle(title);
|
|
|
|
|
article.setFirstCategory(firstCategory);
|
|
|
|
|
article.setSecondCategory(secondCategory);
|
|
|
|
|
article.setKeyword(keyword);
|
|
|
|
|
article.setFileType(fileType);
|
|
|
|
|
article.setState(state);
|
|
|
|
|
article.setContent(content);
|
|
|
|
|
article.setDescribe(describe);
|
|
|
|
|
article.setVideoUrl(videoUrl);
|
|
|
|
|
article.setSecondCategory(secondCategory);
|
|
|
|
|
article.setIsRecommend(isRecommend);
|
|
|
|
|
articleMapper.addArticle(article);
|
|
|
|
|
id = article.getId();
|
|
|
|
|
ajaxResult.setRetmsg("成功新增文章");
|
|
|
|
|
}else {
|
|
|
|
|
//修改
|
|
|
|
@ -100,8 +105,6 @@ public class ArticleSerivceImpl implements ArticleSerive {
|
|
|
|
|
criteria.andEqualTo("id",id);
|
|
|
|
|
article = new Article();
|
|
|
|
|
article.setTitle(title);
|
|
|
|
|
article.setFirstCategory(firstCategory);
|
|
|
|
|
article.setSecondCategory(secondCategory);
|
|
|
|
|
article.setKeyword(keyword);
|
|
|
|
|
article.setFileType(fileType);
|
|
|
|
|
article.setState(state);
|
|
|
|
@ -110,8 +113,26 @@ public class ArticleSerivceImpl implements ArticleSerive {
|
|
|
|
|
article.setVideoUrl(videoUrl);
|
|
|
|
|
article.setIsRecommend(isRecommend);
|
|
|
|
|
articleMapper.updateByExampleSelective(article,example);
|
|
|
|
|
ArticleCategory delArticleCategory = new ArticleCategory();
|
|
|
|
|
delArticleCategory.setArticleId(id);
|
|
|
|
|
//清除之前的1级分类
|
|
|
|
|
if (null !=firstCategory && firstCategory.size()>0){
|
|
|
|
|
articleCategoryMapper.delete(delArticleCategory);
|
|
|
|
|
}
|
|
|
|
|
ajaxResult.setRetmsg("成功修改文章");
|
|
|
|
|
}
|
|
|
|
|
if (null !=firstCategory && firstCategory.size()>0){
|
|
|
|
|
List<Long> firstCategoryIdList = JSONObject.parseArray(firstCategory.toJSONString(), Long.class);
|
|
|
|
|
List<ArticleCategory> articleCategoryList = new ArrayList<>();
|
|
|
|
|
for (Long categoryId:firstCategoryIdList){
|
|
|
|
|
ArticleCategory articleCategory = new ArticleCategory();
|
|
|
|
|
articleCategory.setArticleId(id);
|
|
|
|
|
articleCategory.setCategoryId(categoryId);
|
|
|
|
|
articleCategory.setState(Constants.STATE_VALID);
|
|
|
|
|
articleCategoryList.add(articleCategory);
|
|
|
|
|
}
|
|
|
|
|
articleCategoryMapper.addArticleCategory(articleCategoryList);
|
|
|
|
|
}
|
|
|
|
|
return ajaxResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -127,7 +148,12 @@ public class ArticleSerivceImpl implements ArticleSerive {
|
|
|
|
|
Long firstCategory = jsonObject.getLong("firstCategory");
|
|
|
|
|
Long secondCategory = jsonObject.getLong("secondCategory");
|
|
|
|
|
Integer fileType = jsonObject.getInteger("fileType");
|
|
|
|
|
List<ArticleVo> CategoryList = articleMapper.getArticleListByCondition(title,firstCategory,secondCategory,fileType);
|
|
|
|
|
Category category = categoryMapper.selectByPrimaryKey(firstCategory);
|
|
|
|
|
String firstCategoryName = null ;
|
|
|
|
|
if (category != null ){
|
|
|
|
|
firstCategoryName = "%" + category.getName() + "%" ;
|
|
|
|
|
}
|
|
|
|
|
List<ArticleVo> CategoryList = articleMapper.getArticleListByCondition(title,firstCategoryName,secondCategory,fileType);
|
|
|
|
|
JSONObject pageJson = PageUtils.page(CategoryList,pageNum,pageSize);
|
|
|
|
|
return pageJson;
|
|
|
|
|
}
|
|
|
|
@ -159,7 +185,12 @@ public class ArticleSerivceImpl implements ArticleSerive {
|
|
|
|
|
}
|
|
|
|
|
Long firstCategory = jsonObject.getLong("firstCategory");
|
|
|
|
|
Long secondCategory = jsonObject.getLong("secondCategory");
|
|
|
|
|
List<ArticleVo> CategoryList = articleMapper.searchArticleListByCondition(param,keyword,firstCategory,secondCategory);
|
|
|
|
|
Category category = categoryMapper.selectByPrimaryKey(firstCategory);
|
|
|
|
|
String firstCategoryName = null ;
|
|
|
|
|
if (category != null ){
|
|
|
|
|
firstCategoryName = "%" + category.getName() + "%" ;
|
|
|
|
|
}
|
|
|
|
|
List<ArticleVo> CategoryList = articleMapper.searchArticleListByCondition(param,keyword,firstCategoryName,secondCategory);
|
|
|
|
|
JSONObject pageJson = PageUtils.page(CategoryList,pageNum,pageSize);
|
|
|
|
|
return pageJson;
|
|
|
|
|
}
|
|
|
|
@ -184,6 +215,11 @@ public class ArticleSerivceImpl implements ArticleSerive {
|
|
|
|
|
article = new Article();
|
|
|
|
|
article.setState(Constants.DISABLE);
|
|
|
|
|
articleMapper.updateByExampleSelective(article,example);
|
|
|
|
|
ArticleCategory delArticleCategory = new ArticleCategory();
|
|
|
|
|
delArticleCategory.setArticleId(id);
|
|
|
|
|
//清除之前的1级分类
|
|
|
|
|
articleCategoryMapper.delete(delArticleCategory);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
ajaxResult.setRetmsg("批量删除成功");
|
|
|
|
|
return ajaxResult;
|
|
|
|
@ -198,13 +234,15 @@ public class ArticleSerivceImpl implements ArticleSerive {
|
|
|
|
|
ajaxResult.setRetmsg("未找到该文章");
|
|
|
|
|
return ajaxResult;
|
|
|
|
|
}else {
|
|
|
|
|
Long firstCategoryId = article.getFirstCategory();
|
|
|
|
|
Long secondCategoryId = article.getSecondCategory();
|
|
|
|
|
Category firstCategory = categoryMapper.selectByPrimaryKey(firstCategoryId);
|
|
|
|
|
ArticleCategory findArticleCategory = new ArticleCategory();
|
|
|
|
|
findArticleCategory.setArticleId(id);
|
|
|
|
|
findArticleCategory.setState(Constants.STATE_VALID);
|
|
|
|
|
List<ArticleCategory> firstCategoryList = articleCategoryMapper.select(findArticleCategory);
|
|
|
|
|
Category secondCategory = categoryMapper.selectByPrimaryKey(secondCategoryId);
|
|
|
|
|
ArticleVo articleVo = new ArticleVo();
|
|
|
|
|
articleVo.setTitle(article.getTitle());
|
|
|
|
|
articleVo.setFirstCategory(firstCategoryId);
|
|
|
|
|
// articleVo.setFirstCategory(firstCategoryId);
|
|
|
|
|
articleVo.setSecondCategory(secondCategoryId);
|
|
|
|
|
articleVo.setContent(article.getContent());
|
|
|
|
|
articleVo.setFileType(article.getFileType());
|
|
|
|
@ -214,15 +252,26 @@ public class ArticleSerivceImpl implements ArticleSerive {
|
|
|
|
|
articleVo.setCreateDateTime(article.getCreateDateTime());
|
|
|
|
|
articleVo.setVideoUrl(article.getVideoUrl());
|
|
|
|
|
articleVo.setIsRecommend(article.getIsRecommend());
|
|
|
|
|
if (null != firstCategory ){
|
|
|
|
|
articleVo.setFirstCategoryName(firstCategory.getName());
|
|
|
|
|
articleVo.setFirstLevel(firstCategory.getLevel());
|
|
|
|
|
articleVo.setFirstSortNum(firstCategory.getSortNum());
|
|
|
|
|
if (null != firstCategoryList && firstCategoryList.size()>0 ){
|
|
|
|
|
List<String> firstCategoryNameList = new ArrayList<>();
|
|
|
|
|
List<String> firstSortNumList = new ArrayList<>();
|
|
|
|
|
for (ArticleCategory articleCategory:firstCategoryList){
|
|
|
|
|
Category category = categoryMapper.selectByPrimaryKey(articleCategory.getCategoryId());
|
|
|
|
|
firstCategoryNameList.add(category.getName());
|
|
|
|
|
if (category.getSortNum()!=null){
|
|
|
|
|
firstSortNumList.add(String.valueOf(category.getSortNum()));
|
|
|
|
|
}else {
|
|
|
|
|
firstSortNumList.add("");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
String firstCategoryName = String.join(",", firstCategoryNameList);
|
|
|
|
|
String firstSortNum = String.join(",", firstSortNumList);
|
|
|
|
|
articleVo.setFirstCategoryName(firstCategoryName);
|
|
|
|
|
articleVo.setFirstSortNum(firstSortNum);
|
|
|
|
|
}
|
|
|
|
|
if (null != secondCategory ){
|
|
|
|
|
articleVo.setSecondCategoryName(secondCategory.getName());
|
|
|
|
|
articleVo.setSecondLevel(secondCategory.getLevel());
|
|
|
|
|
articleVo.setFirstSortNum(secondCategory.getSortNum());
|
|
|
|
|
articleVo.setSecondSortNum(secondCategory.getSortNum());
|
|
|
|
|
}
|
|
|
|
|
ajaxResult.setData(articleVo);
|
|
|
|
|
}
|
|
|
|
|