master
ck 5 years ago
parent 6bda276c3b
commit abee56bbf6

@ -185,5 +185,6 @@
<orderEntry type="library" name="Maven: com.aliyun.oss:aliyun-sdk-oss:2.8.3" level="project" />
<orderEntry type="library" name="Maven: org.jdom:jdom:1.1" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-configuration-processor:2.1.3.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.xerial:sqlite-jdbc:3.21.0.1" level="project" />
</component>
</module>

@ -4,8 +4,8 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.bsd</groupId>
<artifactId>case</artifactId>
<groupId>com.jingcheng.cms</groupId>
<artifactId>cms</artifactId>
<version>1.0.0-SNAPSHOT</version>
<parent>
@ -251,6 +251,12 @@
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<!-- SQLite 驱动 -->
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.21.0.1</version>
</dependency>
</dependencies>
<build>

@ -16,7 +16,7 @@ import tk.mybatis.spring.annotation.MapperScan;
@SpringBootApplication
@EnableConfigurationProperties
@EnableScheduling
@MapperScan(basePackages = "com.bsd.cases.mapper")
@MapperScan(basePackages = "com.jingcheng.cms.mapper")
public class Application implements CommandLineRunner {
private Logger logger = LoggerFactory.getLogger(Application.class);

@ -51,8 +51,7 @@ public class ShiroConfig {
// 所有请求通过我们自己的JWT Filter
filterRuleMap.put("/**", "jwt");
// 访问401和404页面不通过我们的Filter
filterRuleMap.put("/api/adminlogin", "anon");
filterRuleMap.put("/api/autologin", "anon");
filterRuleMap.put("/api/login", "anon");
filterRuleMap.put("/api/401", "anon");
factoryBean.setFilterChainDefinitionMap(filterRuleMap);
return factoryBean;

@ -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;
}
}

@ -2,7 +2,9 @@ package com.jingcheng.cms.controller;
import com.alibaba.fastjson.JSONObject;
import com.jingcheng.cms.model.CaseUsers;
import com.jingcheng.cms.model.Users;
import com.jingcheng.cms.service.CaseUsersService;
import com.jingcheng.cms.service.UsersService;
import com.jingcheng.cms.util.AjaxResult;
import com.jingcheng.cms.util.JWTUtil;
import com.jingcheng.cms.util.LogUtils;
@ -22,15 +24,12 @@ import javax.servlet.http.HttpServletResponse;
@Api("后台登录API")
@RestController
@CrossOrigin
public class CaseIndexController {
public class LoginController {
Logger logger = LogUtils.getBussinessLogger();
String mofang = "876215850057f8245d2bd82554bd7e7c";
String erp = "cb472ab819ba7209e37fbf0e501a2964";
@Resource
private CaseUsersService caseUsersService;
@Resource
private UsersService usersService;
@RequiresAuthentication
@ -40,56 +39,32 @@ public class CaseIndexController {
AjaxResult ajaxResult = new AjaxResult();
ajaxResult.setRetcode(AjaxResult.SUCCESS);
CaseUsers caseUsers = caseUsersService.currentUser();
ajaxResult.setData(caseUsers);
Users users = usersService.currentUser();
ajaxResult.setData(users);
return ajaxResult;
}
@ApiOperation(value = "微信登录", notes = "微信登录")
@ApiImplicitParams({
@ApiImplicitParam(name = "code", value = "微信授权code")
})
@PostMapping("autologin")
public AjaxResult autoLogin(String params) {
AjaxResult ajaxResult = new AjaxResult();
try {
String token = caseUsersService.autoLogin(params);
ajaxResult.setRetcode(AjaxResult.SUCCESS);
ajaxResult.setData(token);
ajaxResult.setRetmsg("自动登录成功");
} catch (RuntimeException e) {
e.printStackTrace();
ajaxResult.setRetmsg("自动登录失败:" + e.getMessage());
ajaxResult.setRetcode(AjaxResult.FAILED);
}
return ajaxResult;
}
@ApiOperation(value = "后台登录", notes = "后台登录")
@ApiImplicitParams({
@ApiImplicitParam(name = "userName", value = "用户名"),
@ApiImplicitParam(name = "password", value = "密码")
})
@PostMapping("adminlogin")
@PostMapping("/api/login")
public AjaxResult adminLogin(@RequestBody JSONObject params) {
AjaxResult ajaxResult = new AjaxResult();
try {
String userName = params.getString("userName");
String userNo = params.getString("userNo");
String password = params.getString("password");
if (null == userName) {
if (null == userNo) {
ajaxResult.setRetmsg("登录失败, 用户名或密码错误!");
ajaxResult.setRetcode(AjaxResult.FAILED);
} else {
CaseUsers caseUsers = caseUsersService.findUser(userName, password);
ajaxResult.setData(JWTUtil.sign(caseUsers.getUserNo()));
Users users = usersService.findUser(userNo, password);
ajaxResult.setData(JWTUtil.sign(users.getUserNo()));
ajaxResult.setRetmsg("登录成功");
ajaxResult.setRetcode(AjaxResult.SUCCESS);
}
@ -140,7 +115,7 @@ public class CaseIndexController {
}
@RequestMapping("/401")
@RequestMapping("/api/401")
@ResponseStatus(HttpStatus.UNAUTHORIZED)
public AjaxResult unauthorized(HttpServletResponse servletResponse) {
@ -150,24 +125,5 @@ public class CaseIndexController {
return ajaxResult;
}
@RequestMapping("wxconfig")
public AjaxResult wxconfig(String url) {
AjaxResult ajaxResult = new AjaxResult();
try {
JSONObject jsonObject = WechatAccessUtils.share(url);
ajaxResult.setData(jsonObject);
ajaxResult.setRetcode(AjaxResult.SUCCESS);
ajaxResult.setRetmsg("获取微信配置成功");
} catch (Exception e) {
e.printStackTrace();
ajaxResult.setRetmsg("自动登录失败:" + e.getMessage());
ajaxResult.setRetcode(AjaxResult.FAILED);
}
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;
}

@ -43,9 +43,7 @@ public class BaseEntity {
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
private Date createDateTime;
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
private Date updateDateTime;
private Long createBy;
private Long updateBy;

@ -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;
}
}

@ -3,8 +3,7 @@ package com.jingcheng.cms.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jingcheng.cms.constants.Constants;
import com.bsd.cases.mapper.*;
import com.bsd.cases.model.*;
import com.jingcheng.cms.mapper.*;
import com.jingcheng.cms.model.*;
import com.jingcheng.cms.service.CaseContentService;

@ -7,10 +7,8 @@ import com.jingcheng.cms.mapper.CaseAreaMapper;
import com.jingcheng.cms.mapper.CaseCompanyMapper;
import com.jingcheng.cms.mapper.CaseStoreMapper;
import com.jingcheng.cms.mapper.CaseUsersMapper;
import com.bsd.cases.model.*;
import com.jingcheng.cms.model.*;
import com.jingcheng.cms.service.CaseUsersService;
import com.bsd.cases.util.*;
import com.github.pagehelper.PageHelper;
import com.jingcheng.cms.util.*;
import org.apache.poi.hssf.usermodel.HSSFRow;

@ -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;
}
}

@ -1,5 +1,6 @@
package com.jingcheng.cms.util;
import tk.mybatis.mapper.common.BaseMapper;
import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.common.MySqlMapper;
@ -9,7 +10,7 @@ import tk.mybatis.mapper.common.MySqlMapper;
* @author
* @since 2015-09-06 21:53
*/
public interface CommonMapper<T> extends Mapper<T>, MySqlMapper<T> {
public interface CommonMapper<T> extends Mapper<T>, MySqlMapper<T>{
//TODO
//FIXME 特别注意,该接口不能被扫描到,否则会出错
}

@ -1,7 +1,8 @@
package com.jingcheng.cms.util;
import com.jingcheng.cms.model.CaseUsers;
import com.jingcheng.cms.service.CaseUsersService;
import com.jingcheng.cms.model.Users;
import com.jingcheng.cms.service.UsersService;
import com.jingcheng.cms.shiro.JWTToken;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
@ -20,7 +21,7 @@ public class CommonRealm extends AuthorizingRealm {
@Resource
private CaseUsersService caseUsersService;
private UsersService usersService;
/**
* Shiro
@ -37,9 +38,9 @@ public class CommonRealm extends AuthorizingRealm {
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
String key = JWTUtil.getKey(principals.toString());
CaseUsers caseUsers = caseUsersService.selectByUserNoOrOpenId(key);
Users users = usersService.selectByUserNo(key);
SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo();
simpleAuthorizationInfo.addRole(caseUsers.getRole().toString());
// simpleAuthorizationInfo.addRole(caseUsers.getRole().toString());
// Set<String> permission = new HashSet<>(Arrays.asList(caseUsers.getPermission().split(",")));
// simpleAuthorizationInfo.addStringPermissions(permission);
return simpleAuthorizationInfo;
@ -57,11 +58,11 @@ public class CommonRealm extends AuthorizingRealm {
throw new AuthenticationException("token invalid");
}
CaseUsers userBean = caseUsersService.selectByUserNoOrOpenId(username);
if (userBean == null) {
Users users = usersService.selectByUserNo(username);
if (users == null) {
throw new AuthenticationException("User didn't existed!");
}
String key = userBean.getUserNo() == null ? userBean.getUserNo() : userBean.getOpenId();
String key = users.getUserNo();
if (!JWTUtil.verify(token, key)) {
throw new AuthenticationException("Username or password error");

@ -42,6 +42,8 @@ mybatis:
mapper-locations: classpath:mapper/*.xml
configuration:
map-underscore-to-camel-case: true
global-config:
db-type: sqlite
mapper:
mappers: com.jingcheng.cms.util.CommonMapper
not-empty: false

@ -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…
Cancel
Save