master
ck 5 years ago
parent 9b4160f6d9
commit eba6d9b0dc

@ -8,6 +8,8 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("/api/article")
public class ArticleController {
@ -39,4 +41,40 @@ public class ArticleController {
return ajaxResult;
}
/**
* 1
* @return
*/
@RequestMapping("/article-first-category")
public AjaxResult getFirstCategory() {
AjaxResult ajaxResult = new AjaxResult();
List<String> articleSeriveFirstCategory= articleSerive.getFirstCategory();
ajaxResult.setData(articleSeriveFirstCategory);
return ajaxResult;
}
/**
* 2
* @return
*/
@RequestMapping("/article-second-category")
public AjaxResult getSecondCategory(@RequestBody JSONObject jsonObject) {
AjaxResult ajaxResult = new AjaxResult();
List<String> articleSeriveFirstCategory= articleSerive.getSecondCategory(jsonObject);
ajaxResult.setData(articleSeriveFirstCategory);
return ajaxResult;
}
/**
*
* @param jsonObject
* @return
*/
@RequestMapping("/search-article-list")
public AjaxResult searchArticleListByPage(@RequestBody JSONObject jsonObject) {
AjaxResult ajaxResult = new AjaxResult();
JSONObject pageJson= articleSerive.searchArticleListByPage(jsonObject);
ajaxResult.setData(pageJson);
return ajaxResult;
}
}

@ -2,6 +2,7 @@ package com.jingcheng.cms.mapper;
import com.jingcheng.cms.model.Article;
import com.jingcheng.cms.util.CommonMapper;
import com.jingcheng.cms.vo.ArticleVo;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
@ -11,8 +12,16 @@ import java.util.List;
public interface ArticleMapper extends CommonMapper<Article> {
int addArticle(Article article);
List<Article> getArticleListByCondition(@Param("title") String title,
@Param("categoryName") String categoryName,
@Param("fileType") Integer fileType,
@Param("state") Integer state);
List<ArticleVo> getArticleListByCondition(@Param("title") String title,
@Param("firstCategory") Long firstCategory,
@Param("secondCategory") Long secondCategory,
@Param("fileType") Integer fileType,
@Param("state") Integer state);
List<String> getFirstCategory();
List<String> getSecondCategory(@Param("firstCategory") Long firstCategory);
List<ArticleVo> searchArticleListByCondition(@Param("param") String param,
@Param("firstCategory") Long firstCategory,
@Param("secondCategory") Long secondCategory);
}

@ -16,12 +16,12 @@ public class Article extends BaseEntity{
/**
* 1
*/
private String firstCategoryName;
private Long firstCategory;
/**
* 2
*/
private String secondCategoryName;
private Long secondCategory;
/**
*

@ -3,6 +3,8 @@ package com.jingcheng.cms.service;
import com.alibaba.fastjson.JSONObject;
import com.jingcheng.cms.util.AjaxResult;
import java.util.List;
public interface ArticleSerive {
/**
*
@ -16,4 +18,22 @@ public interface ArticleSerive {
* @return
*/
JSONObject getArticleListByPage(JSONObject jsonObject);
/**
* 1
*/
List<String> getFirstCategory();
/**
* 2
*/
List<String> getSecondCategory(JSONObject jsonObject);
/**
*
* @param jsonObject
* @return
*/
JSONObject searchArticleListByPage(JSONObject jsonObject);
}

@ -7,6 +7,7 @@ import com.jingcheng.cms.model.Article;
import com.jingcheng.cms.service.ArticleSerive;
import com.jingcheng.cms.util.AjaxResult;
import com.jingcheng.cms.util.PageUtils;
import com.jingcheng.cms.vo.ArticleVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -28,28 +29,32 @@ public class ArticleSerivceImpl implements ArticleSerive {
AjaxResult ajaxResult = new AjaxResult();
Long id = jsonObject.getLong("id");
String title = jsonObject.getString("title");
String firstCategoryName = jsonObject.getString("firstCategoryName");
String secondCategoryName = jsonObject.getString("secondCategoryName");
Long firstCategory = jsonObject.getLong("firstCategory");
Long secondCategory = jsonObject.getLong("secondCategory");
String keyword = jsonObject.getString("keyword");
Integer fileType = jsonObject.getInteger("fileType");
String content = jsonObject.getString("content");
Integer state = jsonObject.getInteger("state");
if (null == state){
ajaxResult.setRetcode(AjaxResult.FAILED);
ajaxResult.setRetmsg("是否启用不可为空");
return ajaxResult;
}
if (StringUtils.isBlank(title)){
ajaxResult.setRetcode(AjaxResult.FAILED);
ajaxResult.setRetmsg("文章标题不可为空");
return ajaxResult;
}
if (StringUtils.isBlank(firstCategoryName)||StringUtils.isBlank(secondCategoryName)){
if (null == firstCategory||null == secondCategory){
ajaxResult.setRetcode(AjaxResult.FAILED);
ajaxResult.setRetmsg("文章分类不可为空");
return ajaxResult;
}
if (null == fileType){
ajaxResult.setRetcode(AjaxResult.FAILED);
ajaxResult.setRetmsg("文章形式不可为空");
return ajaxResult;
@ -63,8 +68,8 @@ public class ArticleSerivceImpl implements ArticleSerive {
//新增
Article article = new Article();
article.setTitle(title);
article.setFirstCategoryName(firstCategoryName);
article.setSecondCategoryName(secondCategoryName);
article.setFirstCategory(firstCategory);
article.setSecondCategory(secondCategory);
article.setKeyword(keyword);
article.setFileType(fileType);
article.setState(state);
@ -80,8 +85,8 @@ public class ArticleSerivceImpl implements ArticleSerive {
return ajaxResult;
}
article.setTitle(title);
article.setFirstCategoryName(firstCategoryName);
article.setSecondCategoryName(secondCategoryName);
article.setFirstCategory(firstCategory);
article.setSecondCategory(secondCategory);
article.setKeyword(keyword);
article.setFileType(fileType);
article.setState(state);
@ -98,10 +103,39 @@ public class ArticleSerivceImpl implements ArticleSerive {
Integer pageNum = jsonObject.getInteger("pageNum") == null ? 1 : jsonObject.getInteger("pageNum");
Integer pageSize = jsonObject.getInteger("pageSize") == null ? 5 : jsonObject.getInteger("pageSize");
String title = jsonObject.getString("title");
String categoryName = jsonObject.getString("categoryName");
if (StringUtils.isNotEmpty(title)){
title = "%" + title + "%" ;
}
Long firstCategory = jsonObject.getLong("firstCategory");
Long secondCategory = jsonObject.getLong("secondCategory");
Integer fileType = jsonObject.getInteger("fileType");
Integer state = jsonObject.getInteger("state");
List<Article> CategoryList = articleMapper.getArticleListByCondition(title,categoryName,fileType,state);
List<ArticleVo> CategoryList = articleMapper.getArticleListByCondition(title,firstCategory,secondCategory,fileType,state);
JSONObject pageJson = PageUtils.page(CategoryList,pageNum,pageSize);
return pageJson;
}
@Override
public List<String> getFirstCategory() {
List<String> categoryName = articleMapper.getFirstCategory();
return categoryName;
}
@Override
public List<String> getSecondCategory(JSONObject jsonObject) {
Long firstCategory = jsonObject.getLong("firstCategory");
List<String> categoryName = articleMapper.getSecondCategory(firstCategory);
return categoryName;
}
@Override
public JSONObject searchArticleListByPage(JSONObject jsonObject) {
Integer pageNum = jsonObject.getInteger("pageNum") == null ? 1 : jsonObject.getInteger("pageNum");
Integer pageSize = jsonObject.getInteger("pageSize") == null ? 5 : jsonObject.getInteger("pageSize");
String param = jsonObject.getString("param");
Long firstCategory = jsonObject.getLong("firstCategory");
Long secondCategory = jsonObject.getLong("secondCategory");
List<ArticleVo> CategoryList = articleMapper.searchArticleListByCondition(param,firstCategory,secondCategory);
JSONObject pageJson = PageUtils.page(CategoryList,pageNum,pageSize);
return pageJson;
}

@ -0,0 +1,21 @@
package com.jingcheng.cms.vo;
import com.jingcheng.cms.model.Category;
import lombok.Data;
@Data
public class ArticleVo extends Category {
private String firstCategoryName;
private String secondCategoryName;
private Integer firstSortNum;
private Integer secondSortNum;
private Integer firstLevel;
private Integer secondLevel;
}

@ -7,16 +7,27 @@
values (#{title},#{firstCategoryName},#{secondCategoryName},#{keyword},#{fileType},#{content},#{state})
</insert>
<select id="getArticleListByCondition" resultType="com.jingcheng.cms.model.Article">
select `id`,`title`,`first_category_name`,`second_category_name`,`keyword`,`file_type`,`content`,`create_date_time`,
`update_date_time`,`state` FROM article
<select id="getArticleListByCondition" resultType="com.jingcheng.cms.vo.ArticleVo">
select ar.`id`,ar.`title`,c1.`name` as `first_category_name`,c2.`name` as `second_category_name`,
ar.`keyword`,ar.`file_type`,ar.`content`,ar.`create_date_time`,ar.`update_date_time`,ar.`state`,
c1.level as `first_level`,c2.level as `second_level`,c1.`sort_num` as `first_sort_num`,c2.`sort_num` as `second_sort_num`
FROM article ar
left join category c1
on
ar.first_category = c1.id and c1.level = 1
left join category c2
on
ar.second_category = c2.id and c2.level = 2
where
1 = 1
<if test="title != null and title != ''">
and title like #{title}
and ar.title like #{title}
</if>
<if test="categoryName != null and categoryName != ''">
and (first_category_name like #{categoryName} or second_category_name like #{categoryName})
<if test="firstCategory != null ">
and ar.first_category = #{firstCategory}
</if>
<if test="secondCategory != null ">
and ar.second_category = #{secondCategory}
</if>
<if test="fileType != null ">
and file_type = #{fileType}
@ -25,4 +36,54 @@
and state = #{state}
</if>
</select>
<select id="getFirstCategory" resultType="String">
select c.`name`
from article ar
left join category c
on c.id = ar.`first_category`
where c.level = 1 and ar.state = 1
group by c.name
order by c.sort_num ASC
</select>
<select id="getSecondCategory" resultType="String" parameterType="Long">
select c.`name`
from article ar
left join category c
on ar.`second_category` = c.`id`
where
1=1
<if test="firstCategory != null ">
and ar.first_category = #{firstCategory}
</if>
and c.level = 2 and ar.state = 1
group by c.name
order by c.sort_num ASC
</select>
<select id="searchArticleListByCondition" resultType="com.jingcheng.cms.vo.ArticleVo">
select ar.`id`,ar.`title`,c1.`name` as `first_category_name`,c2.`name` as `second_category_name`,
ar.`keyword`,ar.`file_type`,ar.`content`,ar.`create_date_time`,ar.`update_date_time`,ar.`state`,
c1.level as `first_level`,c2.level as `second_level`,c1.`sort_num` as `first_sort_num`,c2.`sort_num` as `second_sort_num`
FROM article ar
left join category c1
on
ar.first_category = c1.id and c1.level = 1
left join category c2
on
ar.second_category = c2.id and c2.level = 2
where
1 = 1
<if test="param != null and param != ''">
and (ar.title like #{param} OR ar.keyword like #{param} or c1.name like #{param} or c2.name like #{param} )
</if>
<if test="firstCategory != null ">
and ar.first_category = #{firstCategory}
</if>
<if test="secondCategory != null ">
and ar.second_category = #{secondCategory}
</if>
and state = 1
</select>
</mapper>
Loading…
Cancel
Save