master
parent
6bda276c3b
commit
abee56bbf6
@ -0,0 +1,75 @@
|
|||||||
|
package com.jingcheng.cms.controller;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.jingcheng.cms.model.Category;
|
||||||
|
import com.jingcheng.cms.model.CategoryType;
|
||||||
|
import com.jingcheng.cms.service.CategoryService;
|
||||||
|
import com.jingcheng.cms.util.AjaxRequest;
|
||||||
|
import com.jingcheng.cms.util.AjaxResult;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/category")
|
||||||
|
public class CategoryController {
|
||||||
|
@Autowired
|
||||||
|
private CategoryService categoryService;
|
||||||
|
|
||||||
|
@RequestMapping("/all-category-type")
|
||||||
|
public AjaxResult getAllCategory() {
|
||||||
|
AjaxResult ajaxResult = new AjaxResult();
|
||||||
|
List<CategoryType> categoryTypeList= categoryService.getAllCategoryType();
|
||||||
|
if (null == categoryTypeList || 0 == categoryTypeList.size()){
|
||||||
|
ajaxResult.setRetmsg("分类类别列表为空");
|
||||||
|
}else {
|
||||||
|
ajaxResult.setData(categoryTypeList);
|
||||||
|
}
|
||||||
|
return ajaxResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取分类分页
|
||||||
|
* @param jsonObject
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@RequestMapping("/category-list")
|
||||||
|
public AjaxResult getAllCategory(@RequestBody JSONObject jsonObject) {
|
||||||
|
AjaxResult ajaxResult = new AjaxResult();
|
||||||
|
JSONObject pageJson= categoryService.getCategoryListByPage(jsonObject);
|
||||||
|
ajaxResult.setData(pageJson);
|
||||||
|
return ajaxResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增或者更新类别
|
||||||
|
* @param jsonObject
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@RequestMapping("/save-category")
|
||||||
|
public AjaxResult saveCategory(@RequestBody JSONObject jsonObject) {
|
||||||
|
AjaxResult ajaxResult = categoryService.saveCategory(jsonObject);
|
||||||
|
return ajaxResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除类别
|
||||||
|
* @param jsonObject
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@RequestMapping("/del-category")
|
||||||
|
public AjaxResult delCategory(@RequestBody JSONObject jsonObject) {
|
||||||
|
AjaxResult ajaxResult = new AjaxResult();
|
||||||
|
Long id = jsonObject.getLong("id");
|
||||||
|
if (null == id){
|
||||||
|
ajaxResult.setRetmsg("id不可为空");
|
||||||
|
return ajaxResult;
|
||||||
|
}
|
||||||
|
ajaxResult= categoryService.delCategory(id);
|
||||||
|
return ajaxResult;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
package com.jingcheng.cms.controller;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.jingcheng.cms.service.PopularLabelService;
|
||||||
|
import com.jingcheng.cms.util.AjaxResult;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/popularLabel")
|
||||||
|
public class PopularLabelController {
|
||||||
|
@Autowired
|
||||||
|
private PopularLabelService popularLabelService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取热门标签分页
|
||||||
|
* @param jsonObject
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@RequestMapping("/popular-label-list")
|
||||||
|
public AjaxResult getPopularLabelListByPage(@RequestBody JSONObject jsonObject) {
|
||||||
|
AjaxResult ajaxResult = new AjaxResult();
|
||||||
|
JSONObject pageJson= popularLabelService.getPopularLabelListByPage(jsonObject);
|
||||||
|
ajaxResult.setData(pageJson);
|
||||||
|
return ajaxResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增或者更新热门
|
||||||
|
* @param jsonObject
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@RequestMapping("/save-popular-label")
|
||||||
|
public AjaxResult savePopularLabel(@RequestBody JSONObject jsonObject) {
|
||||||
|
AjaxResult ajaxResult = popularLabelService.savePopularLabel(jsonObject);
|
||||||
|
return ajaxResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除热门标签
|
||||||
|
* @param jsonObject
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@RequestMapping("/del-popular-label")
|
||||||
|
public AjaxResult delPopularLabel(@RequestBody JSONObject jsonObject) {
|
||||||
|
AjaxResult ajaxResult = new AjaxResult();
|
||||||
|
Long id = jsonObject.getLong("id");
|
||||||
|
if (null == id){
|
||||||
|
ajaxResult.setRetmsg("id不可为空");
|
||||||
|
return ajaxResult;
|
||||||
|
}
|
||||||
|
ajaxResult= popularLabelService.delPopularLabel(id);
|
||||||
|
return ajaxResult;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package com.jingcheng.cms.mapper;
|
||||||
|
|
||||||
|
import com.jingcheng.cms.model.Article;
|
||||||
|
import com.jingcheng.cms.util.CommonMapper;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface ArticleMapper extends CommonMapper<Article> {
|
||||||
|
int addArticle(Article article);
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.jingcheng.cms.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.jingcheng.cms.model.Category;
|
||||||
|
|
||||||
|
import com.jingcheng.cms.util.CommonMapper;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface CategoryMapper extends CommonMapper<Category> {
|
||||||
|
int addCategory(Category category);
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package com.jingcheng.cms.mapper;
|
||||||
|
|
||||||
|
import com.jingcheng.cms.model.CategoryType;
|
||||||
|
import com.jingcheng.cms.util.CommonMapper;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
import tk.mybatis.mapper.common.BaseMapper;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface CategoryTypeMapper extends CommonMapper<CategoryType> {
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package com.jingcheng.cms.mapper;
|
||||||
|
|
||||||
|
import com.jingcheng.cms.model.PopularLabel;
|
||||||
|
import com.jingcheng.cms.util.CommonMapper;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface PopularLabelMapper extends CommonMapper<PopularLabel> {
|
||||||
|
int addPopularLabel(PopularLabel popularLabel);
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package com.jingcheng.cms.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.jingcheng.cms.model.Users;
|
||||||
|
import com.jingcheng.cms.util.CommonMapper;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface UsersMapper extends CommonMapper<Users>,BaseMapper<Users>{
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
package com.jingcheng.cms.model;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@TableName("article")
|
||||||
|
public class Article extends BaseEntity{
|
||||||
|
/**
|
||||||
|
* 文章标题
|
||||||
|
*/
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1级分类名称
|
||||||
|
*/
|
||||||
|
private String firstCategoryName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 2级分类名称
|
||||||
|
*/
|
||||||
|
private String secondCategoryName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关键字
|
||||||
|
*/
|
||||||
|
private String keyword;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 形式 0-图文 1-视频
|
||||||
|
*/
|
||||||
|
private Integer fileType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件路径
|
||||||
|
*/
|
||||||
|
private String filePath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章文字
|
||||||
|
*/
|
||||||
|
private byte[] content;
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.jingcheng.cms.model;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@TableName("category")
|
||||||
|
public class Category extends BaseEntity{
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private Integer level;
|
||||||
|
|
||||||
|
private String typeName;
|
||||||
|
|
||||||
|
private Integer sortNum;
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package com.jingcheng.cms.model;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@TableName("category_type")
|
||||||
|
public class CategoryType extends BaseEntity{
|
||||||
|
|
||||||
|
private String typeName;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package com.jingcheng.cms.model;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@TableName("popular_label")
|
||||||
|
public class PopularLabel extends BaseEntity{
|
||||||
|
private String name;
|
||||||
|
private Integer sortNum;
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package com.jingcheng.cms.model;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@TableName("users")
|
||||||
|
public class Users extends BaseEntity{
|
||||||
|
|
||||||
|
private String userName;
|
||||||
|
|
||||||
|
private String userNo;
|
||||||
|
|
||||||
|
private String password;
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
package com.jingcheng.cms.service;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.jingcheng.cms.util.AjaxResult;
|
||||||
|
|
||||||
|
public interface ArticleSerive {
|
||||||
|
AjaxResult saveArticle(JSONObject jsonObject);
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
package com.jingcheng.cms.service;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.jingcheng.cms.model.Category;
|
||||||
|
import com.jingcheng.cms.model.CategoryType;
|
||||||
|
import com.jingcheng.cms.util.AjaxRequest;
|
||||||
|
import com.jingcheng.cms.util.AjaxResult;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface CategoryService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取所有的分类类别
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<CategoryType> getAllCategoryType();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页获取分类
|
||||||
|
* @param jsonObject
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
JSONObject getCategoryListByPage(JSONObject jsonObject);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增或修改分类
|
||||||
|
* @param jsonObject
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
AjaxResult saveCategory(JSONObject jsonObject);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除分类
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
AjaxResult delCategory(Long id);
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package com.jingcheng.cms.service;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.jingcheng.cms.util.AjaxResult;
|
||||||
|
|
||||||
|
public interface PopularLabelService {
|
||||||
|
/**
|
||||||
|
* 分页获取分类
|
||||||
|
* @param jsonObject
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
JSONObject getPopularLabelListByPage(JSONObject jsonObject);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增或修改热门标签
|
||||||
|
* @param jsonObject
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
AjaxResult savePopularLabel(JSONObject jsonObject);
|
||||||
|
|
||||||
|
AjaxResult delPopularLabel(Long id);
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package com.jingcheng.cms.service;
|
||||||
|
|
||||||
|
import com.jingcheng.cms.model.Users;
|
||||||
|
|
||||||
|
public interface UsersService {
|
||||||
|
|
||||||
|
Users currentUser();
|
||||||
|
|
||||||
|
Users selectByUserNo(String key);
|
||||||
|
|
||||||
|
Users findUser(String userName, String password);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,80 @@
|
|||||||
|
package com.jingcheng.cms.service.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.jingcheng.cms.mapper.ArticleMapper;
|
||||||
|
import com.jingcheng.cms.model.Article;
|
||||||
|
import com.jingcheng.cms.service.ArticleSerive;
|
||||||
|
import com.jingcheng.cms.util.AjaxResult;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Transactional
|
||||||
|
public class ArticleSerivceImpl implements ArticleSerive {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ArticleMapper articleMapper;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AjaxResult saveArticle(JSONObject jsonObject) {
|
||||||
|
AjaxResult ajaxResult = new AjaxResult();
|
||||||
|
Long id = jsonObject.getLong("id");
|
||||||
|
String title = jsonObject.getString("title");
|
||||||
|
String firstCategoryName = jsonObject.getString("firstCategoryName");
|
||||||
|
String secondCategoryName = jsonObject.getString("secondCategoryName");
|
||||||
|
String keyword = jsonObject.getString("keyword");
|
||||||
|
Integer fileType = jsonObject.getInteger("fileType");
|
||||||
|
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)){
|
||||||
|
ajaxResult.setRetcode(AjaxResult.FAILED);
|
||||||
|
ajaxResult.setRetmsg("文章分类不可为空");
|
||||||
|
return ajaxResult;
|
||||||
|
}
|
||||||
|
if (null == fileType){
|
||||||
|
ajaxResult.setRetcode(AjaxResult.FAILED);
|
||||||
|
ajaxResult.setRetmsg("文章形式不可为空");
|
||||||
|
return ajaxResult;
|
||||||
|
}
|
||||||
|
if (null == id){
|
||||||
|
//新增
|
||||||
|
Article article = new Article();
|
||||||
|
article.setTitle(title);
|
||||||
|
article.setFirstCategoryName(firstCategoryName);
|
||||||
|
article.setSecondCategoryName(secondCategoryName);
|
||||||
|
article.setKeyword(keyword);
|
||||||
|
article.setFileType(fileType);
|
||||||
|
article.setState(state);
|
||||||
|
|
||||||
|
}else {
|
||||||
|
//修改
|
||||||
|
Article article = articleMapper.selectByPrimaryKey(id);
|
||||||
|
if (null == article){
|
||||||
|
ajaxResult.setRetcode(AjaxResult.FAILED);
|
||||||
|
ajaxResult.setRetmsg("未找到文章");
|
||||||
|
return ajaxResult;
|
||||||
|
}
|
||||||
|
article.setTitle(title);
|
||||||
|
article.setFirstCategoryName(firstCategoryName);
|
||||||
|
article.setSecondCategoryName(secondCategoryName);
|
||||||
|
article.setKeyword(keyword);
|
||||||
|
article.setFileType(fileType);
|
||||||
|
article.setState(state);
|
||||||
|
articleMapper.updateByPrimaryKeySelective(article);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,128 @@
|
|||||||
|
package com.jingcheng.cms.service.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import com.jingcheng.cms.constants.Constants;
|
||||||
|
import com.jingcheng.cms.mapper.CategoryMapper;
|
||||||
|
import com.jingcheng.cms.mapper.CategoryTypeMapper;
|
||||||
|
import com.jingcheng.cms.model.CaseCategory;
|
||||||
|
import com.jingcheng.cms.model.Category;
|
||||||
|
import com.jingcheng.cms.model.CategoryType;
|
||||||
|
import com.jingcheng.cms.service.CategoryService;
|
||||||
|
import com.jingcheng.cms.util.AjaxRequest;
|
||||||
|
import com.jingcheng.cms.util.AjaxResult;
|
||||||
|
import com.jingcheng.cms.util.PageUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import tk.mybatis.mapper.entity.Example;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
@Service
|
||||||
|
@Transactional
|
||||||
|
public class CategoryServiceImpl implements CategoryService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private CategoryMapper categoryMapper;
|
||||||
|
@Resource
|
||||||
|
private CategoryTypeMapper categoryTypeMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<CategoryType> getAllCategoryType() {
|
||||||
|
|
||||||
|
CategoryType findCategoryType = new CategoryType();
|
||||||
|
findCategoryType.setState(Constants.STATE_VALID);
|
||||||
|
List<CategoryType> categoryTypeList = categoryTypeMapper.select(findCategoryType);
|
||||||
|
return categoryTypeList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject getCategoryListByPage(JSONObject jsonObject) {
|
||||||
|
|
||||||
|
Example example = new Example(Category.class);
|
||||||
|
example.setOrderByClause("id ASC");
|
||||||
|
Example.Criteria criteria = example.createCriteria();
|
||||||
|
criteria.andEqualTo("state",Constants.STATE_VALID);
|
||||||
|
Integer pageNum = jsonObject.getInteger("pageNum") == null ? 1 : jsonObject.getInteger("pageNum");
|
||||||
|
Integer pageSize = jsonObject.getInteger("pageSize") == null ? 5 : jsonObject.getInteger("pageSize");
|
||||||
|
Integer level = jsonObject.getInteger("level") == null ? 1 : jsonObject.getInteger("level");
|
||||||
|
criteria.andEqualTo("level",level);
|
||||||
|
List<Category> CategoryList = categoryMapper.selectByExample(example);
|
||||||
|
JSONObject pageJson = PageUtils.page(CategoryList,pageNum,pageSize);
|
||||||
|
return pageJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AjaxResult saveCategory(JSONObject jsonObject) {
|
||||||
|
AjaxResult ajaxResult = new AjaxResult();
|
||||||
|
Long id = jsonObject.getLong("id");
|
||||||
|
String name = jsonObject.getString("name");
|
||||||
|
String typeName = jsonObject.getString("typeName");
|
||||||
|
Integer level = jsonObject.getInteger("level") == null ? 1:jsonObject.getInteger("level");
|
||||||
|
Integer sortNum = jsonObject.getInteger("sortNum");
|
||||||
|
if (StringUtils.isBlank(name)){
|
||||||
|
ajaxResult.setRetmsg("分类名称不可为空");
|
||||||
|
ajaxResult.setRetcode(AjaxResult.FAILED);
|
||||||
|
return ajaxResult;
|
||||||
|
}
|
||||||
|
if (StringUtils.isBlank(typeName)){
|
||||||
|
ajaxResult.setRetmsg("分类类别名称不可为空");
|
||||||
|
ajaxResult.setRetcode(AjaxResult.FAILED);
|
||||||
|
return ajaxResult;
|
||||||
|
}
|
||||||
|
if (level <= 0){
|
||||||
|
ajaxResult.setRetmsg("分类等级错误");
|
||||||
|
ajaxResult.setRetcode(AjaxResult.FAILED);
|
||||||
|
return ajaxResult;
|
||||||
|
}
|
||||||
|
if (null != id){
|
||||||
|
Category category = categoryMapper.selectByPrimaryKey(id);
|
||||||
|
if (null == category){
|
||||||
|
ajaxResult.setRetmsg("未找到该id分类");
|
||||||
|
ajaxResult.setRetcode(AjaxResult.FAILED);
|
||||||
|
return ajaxResult;
|
||||||
|
}else {
|
||||||
|
category.setName(name);
|
||||||
|
category.setSortNum(sortNum);
|
||||||
|
category.setTypeName(typeName);
|
||||||
|
categoryMapper.updateByPrimaryKeySelective(category);
|
||||||
|
}
|
||||||
|
ajaxResult.setRetmsg("成功修改分类");
|
||||||
|
}else {
|
||||||
|
Category category = new Category();
|
||||||
|
category.setLevel(level);
|
||||||
|
category.setName(name);
|
||||||
|
category.setTypeName(typeName);
|
||||||
|
category.setSortNum(sortNum);
|
||||||
|
categoryMapper.addCategory(category);
|
||||||
|
ajaxResult.setRetmsg("成功新增分类");
|
||||||
|
}
|
||||||
|
return ajaxResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AjaxResult delCategory(Long id) {
|
||||||
|
AjaxResult ajaxResult = new AjaxResult();
|
||||||
|
Category findCategory = new Category();
|
||||||
|
findCategory.setId(id);
|
||||||
|
findCategory.setState(Constants.STATE_VALID);
|
||||||
|
Category category = categoryMapper.selectOne(findCategory);
|
||||||
|
if (null == category){
|
||||||
|
ajaxResult.setRetmsg("未找到该分类");
|
||||||
|
ajaxResult.setRetcode(AjaxResult.FAILED);
|
||||||
|
return ajaxResult;
|
||||||
|
}else {
|
||||||
|
category.setState(Constants.DISABLE);
|
||||||
|
categoryMapper.updateByPrimaryKeySelective(category);
|
||||||
|
ajaxResult.setRetmsg("分类删除成功");
|
||||||
|
return ajaxResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,85 @@
|
|||||||
|
package com.jingcheng.cms.service.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.jingcheng.cms.constants.Constants;
|
||||||
|
import com.jingcheng.cms.mapper.PopularLabelMapper;
|
||||||
|
import com.jingcheng.cms.model.PopularLabel;
|
||||||
|
import com.jingcheng.cms.service.PopularLabelService;
|
||||||
|
import com.jingcheng.cms.util.AjaxResult;
|
||||||
|
import com.jingcheng.cms.util.PageUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import tk.mybatis.mapper.entity.Example;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Transactional
|
||||||
|
public class PopularLabelServiceImpl implements PopularLabelService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private PopularLabelMapper popularLabelMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject getPopularLabelListByPage(JSONObject jsonObject) {
|
||||||
|
Example example = new Example(PopularLabel.class);
|
||||||
|
example.setOrderByClause("id ASC");
|
||||||
|
Example.Criteria criteria = example.createCriteria();
|
||||||
|
criteria.andEqualTo("state",Constants.STATE_VALID);
|
||||||
|
Integer pageNum = jsonObject.getInteger("pageNum") == null ? 1 : jsonObject.getInteger("pageNum");
|
||||||
|
Integer pageSize = jsonObject.getInteger("pageSize") == null ? 5 : jsonObject.getInteger("pageSize");
|
||||||
|
List<PopularLabel> CategoryList = popularLabelMapper.selectByExample(example);
|
||||||
|
JSONObject pageJson = PageUtils.page(CategoryList,pageNum,pageSize);
|
||||||
|
return pageJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AjaxResult savePopularLabel(JSONObject jsonObject) {
|
||||||
|
AjaxResult ajaxResult = new AjaxResult();
|
||||||
|
Long id = jsonObject.getLong("id");
|
||||||
|
String name = jsonObject.getString("name");
|
||||||
|
Integer sortNum = jsonObject.getInteger("sortNum");
|
||||||
|
if (null != id){
|
||||||
|
PopularLabel popularLabel = popularLabelMapper.selectByPrimaryKey(id);
|
||||||
|
if (null == popularLabel){
|
||||||
|
ajaxResult.setRetmsg("未找到该id热门标签");
|
||||||
|
ajaxResult.setRetcode(AjaxResult.FAILED);
|
||||||
|
return ajaxResult;
|
||||||
|
}else {
|
||||||
|
popularLabel.setName(name);
|
||||||
|
popularLabel.setSortNum(sortNum);
|
||||||
|
popularLabelMapper.updateByPrimaryKeySelective(popularLabel);
|
||||||
|
}
|
||||||
|
ajaxResult.setRetmsg("成功修改热门标签");
|
||||||
|
}else {
|
||||||
|
PopularLabel popularLabel = new PopularLabel();
|
||||||
|
popularLabel.setName(name);
|
||||||
|
popularLabel.setSortNum(sortNum);
|
||||||
|
popularLabelMapper.addPopularLabel(popularLabel);
|
||||||
|
ajaxResult.setRetmsg("成功新增热门标签");
|
||||||
|
}
|
||||||
|
return ajaxResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AjaxResult delPopularLabel(Long id) {
|
||||||
|
AjaxResult ajaxResult = new AjaxResult();
|
||||||
|
PopularLabel findPopularLabel = new PopularLabel();
|
||||||
|
findPopularLabel.setId(id);
|
||||||
|
findPopularLabel.setState(Constants.STATE_VALID);
|
||||||
|
PopularLabel popularLabel = popularLabelMapper.selectOne(findPopularLabel);
|
||||||
|
if (null == popularLabel){
|
||||||
|
ajaxResult.setRetmsg("未找到该热门标签");
|
||||||
|
ajaxResult.setRetcode(AjaxResult.FAILED);
|
||||||
|
return ajaxResult;
|
||||||
|
}else {
|
||||||
|
popularLabel.setState(Constants.DISABLE);
|
||||||
|
popularLabelMapper.updateByPrimaryKeySelective(popularLabel);
|
||||||
|
ajaxResult.setRetmsg("热门标签删除成功");
|
||||||
|
return ajaxResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
package com.jingcheng.cms.service.impl;
|
||||||
|
|
||||||
|
import com.jingcheng.cms.mapper.UsersMapper;
|
||||||
|
import com.jingcheng.cms.model.Users;
|
||||||
|
import com.jingcheng.cms.service.UsersService;
|
||||||
|
import com.jingcheng.cms.util.JWTUtil;
|
||||||
|
import com.jingcheng.cms.util.LogUtils;
|
||||||
|
import org.apache.shiro.SecurityUtils;
|
||||||
|
import org.apache.shiro.subject.Subject;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Transactional
|
||||||
|
public class UsersServiceImpl implements UsersService {
|
||||||
|
|
||||||
|
private Logger logger = LogUtils.getBussinessLogger();
|
||||||
|
@Resource
|
||||||
|
private UsersMapper usersMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Users currentUser() {
|
||||||
|
Subject subject = SecurityUtils.getSubject();
|
||||||
|
String key = JWTUtil.getKey(subject.getPrincipal().toString());
|
||||||
|
Users users = selectByUserNo(key);
|
||||||
|
return users;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Users selectByUserNo(String key) {
|
||||||
|
Users users = new Users();
|
||||||
|
users.setUserNo(key);
|
||||||
|
users = usersMapper.selectOne(users);
|
||||||
|
return users;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Users findUser(String userName, String password) {
|
||||||
|
Users users = new Users();
|
||||||
|
users.setUserName(userName);
|
||||||
|
users.setPassword(password);
|
||||||
|
users = usersMapper.selectOne(users);
|
||||||
|
|
||||||
|
if (null == users) {
|
||||||
|
users = new Users();
|
||||||
|
users.setUserNo(userName);
|
||||||
|
users.setPassword(password);
|
||||||
|
}
|
||||||
|
users = usersMapper.selectOne(users);
|
||||||
|
return users;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.jingcheng.cms.mapper.ArticleMapper">
|
||||||
|
|
||||||
|
<insert id="addArticle" parameterType="com.jingcheng.cms.model.Article">
|
||||||
|
INSERT INTO article(`title`,``,`type_name`,`sort_num`)
|
||||||
|
values (#{name},#{level},#{typeName},#{sortNum})
|
||||||
|
</insert>
|
||||||
|
</mapper>
|
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.jingcheng.cms.mapper.CategoryMapper">
|
||||||
|
|
||||||
|
<insert id="addCategory" parameterType="com.jingcheng.cms.model.Category">
|
||||||
|
INSERT INTO category(`name`,`level`,`type_name`,`sort_num`)
|
||||||
|
values (#{name},#{level},#{typeName},#{sortNum})
|
||||||
|
</insert>
|
||||||
|
</mapper>
|
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.jingcheng.cms.mapper.PopularLabelMapper">
|
||||||
|
|
||||||
|
<insert id="addPopularLabel" parameterType="com.jingcheng.cms.model.PopularLabel">
|
||||||
|
INSERT INTO popular_label(`name`,`sort_num`)
|
||||||
|
values (#{name},#{sortNum})
|
||||||
|
</insert>
|
||||||
|
</mapper>
|
Loading…
Reference in New Issue