Quellcode durchsuchen

添加雪花主键

sgjj vor 5 Jahren
Ursprung
Commit
4682b0ca51

+ 4 - 1
doc/5.2-patch.sql

@@ -11,4 +11,7 @@ ALTER TABLE `mdiy_dict`
 ADD COLUMN `dict_enable`  varchar(11) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT '1' COMMENT '启用状态' AFTER `is_child`;
 
 ALTER TABLE `cms_category` ADD COLUMN `leaf`  bigint(1) NULL DEFAULT NULL COMMENT '是否是叶子节点' AFTER `category_pinyin`;
-ALTER TABLE `cms_category` ADD COLUMN `top_id`  int(11) NULL DEFAULT NULL COMMENT '顶级id' AFTER `leaf`;
+ALTER TABLE `cms_category` ADD COLUMN `top_id`  bigint(20) NULL DEFAULT NULL COMMENT '顶级id' AFTER `leaf`;
+ALTER TABLE `cms_category` MODIFY COLUMN `id`  bigint(20) UNSIGNED NOT NULL FIRST ;
+ALTER TABLE `cms_content` MODIFY COLUMN `id`  bigint(20) UNSIGNED NOT NULL FIRST ;
+ALTER TABLE `system_log` MODIFY COLUMN `id`  bigint(20) UNSIGNED NOT NULL FIRST ;

+ 6 - 0
pom.xml

@@ -36,6 +36,12 @@
 
 	<dependencies>
 		<dependency>
+			<groupId>dm</groupId>
+			<artifactId>dm.jdbc.driver</artifactId>
+			<version>7.0.1</version>
+		</dependency>
+
+		<dependency>
 			<groupId>net.mingsoft</groupId>
 			<artifactId>ms-mpeople</artifactId>
 		</dependency>

+ 1 - 1
src/main/java/net/mingsoft/MSApplication.java

@@ -13,7 +13,7 @@ import java.util.Locale;
 
 @SpringBootApplication
 @ComponentScan(basePackages = {"net.mingsoft"})
-@MapperScan(basePackages={"**.dao"})
+@MapperScan(basePackages={"**.dao","**.mapper"})
 @ServletComponentScan(basePackages = {"net.mingsoft"})
 public class MSApplication {
 	public static void main(String[] args) {

+ 11 - 15
src/main/java/net/mingsoft/cms/action/CategoryAction.java

@@ -4,16 +4,15 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
-import net.mingsoft.base.entity.BaseEntity;
 import net.mingsoft.base.entity.ResultData;
 import net.mingsoft.basic.annotation.LogAnn;
 import net.mingsoft.basic.bean.EUListBean;
 import net.mingsoft.basic.constant.e.BusinessTypeEnum;
 import net.mingsoft.basic.util.BasicUtil;
+import net.mingsoft.basic.util.PinYinUtil;
 import net.mingsoft.basic.util.StringUtil;
 import net.mingsoft.cms.biz.ICategoryBiz;
 import net.mingsoft.cms.entity.CategoryEntity;
-import net.mingsoft.basic.util.PinYinUtil;
 import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
@@ -25,6 +24,7 @@ import springfox.documentation.annotations.ApiIgnore;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.util.List;
+
 /**
  * 分类管理控制层
  * @author 铭飞开发团队
@@ -34,7 +34,7 @@ import java.util.List;
 @Api(value = "分类接口")
 @Controller("cmsCategoryAction")
 @RequestMapping("/${ms.manager.path}/cms/category")
-public class CategoryAction extends BaseAction{
+public class CategoryAction extends BaseAction {
 
 
 	/**
@@ -84,23 +84,19 @@ public class CategoryAction extends BaseAction{
     })
 	@RequestMapping("/list")
 	@ResponseBody
-	public ResultData list(@ModelAttribute @ApiIgnore CategoryEntity category,HttpServletResponse response, HttpServletRequest request,@ApiIgnore ModelMap model,BindingResult result) {
+	public ResultData list(@ModelAttribute @ApiIgnore CategoryEntity category, HttpServletResponse response, HttpServletRequest request, @ApiIgnore ModelMap model, BindingResult result) {
 		category.setAppId(BasicUtil.getAppId());
 		BasicUtil.startPage();
 		List categoryList = categoryBiz.query(category);
-		return ResultData.build().success(new EUListBean(categoryList,(int)BasicUtil.endPage(categoryList).getTotal()));
+		return ResultData.build().success(new EUListBean(categoryList,(int) BasicUtil.endPage(categoryList).getTotal()));
 	}
 
 	/**
 	 * 返回编辑界面category_form
 	 */
 	@GetMapping("/form")
-	public String form(@ModelAttribute CategoryEntity category,HttpServletResponse response,HttpServletRequest request,ModelMap model){
-		if(category.getId()!=null){
-			BaseEntity categoryEntity = categoryBiz.getEntity(Integer.parseInt(category.getId()));
-			model.addAttribute("categoryEntity",categoryEntity);
-		}
-		model.addAttribute("appId",BasicUtil.getAppId());
+	public String form(@ModelAttribute CategoryEntity category, HttpServletResponse response, HttpServletRequest request, ModelMap model){
+		model.addAttribute("appId", BasicUtil.getAppId());
 		return "/cms/category/form";
 	}
 
@@ -112,12 +108,12 @@ public class CategoryAction extends BaseAction{
     @ApiImplicitParam(name = "id", value = "编号", required =true,paramType="query")
 	@GetMapping("/get")
 	@ResponseBody
-	public ResultData get(@ModelAttribute @ApiIgnore CategoryEntity category,HttpServletResponse response, HttpServletRequest request,@ApiIgnore ModelMap model){
+	public ResultData get(@ModelAttribute @ApiIgnore CategoryEntity category, HttpServletResponse response, HttpServletRequest request, @ApiIgnore ModelMap model){
 		if(category.getId()==null) {
 			return ResultData.build().error();
 		}
 		category.setAppId(BasicUtil.getAppId());
-		CategoryEntity _category = (CategoryEntity)categoryBiz.getEntity(Integer.parseInt(category.getId()));
+		CategoryEntity _category = (CategoryEntity)categoryBiz.getById(category.getId());
 		return ResultData.build().success(_category);
 	}
 
@@ -187,7 +183,7 @@ public class CategoryAction extends BaseAction{
 	@ResponseBody
 	@LogAnn(title = "删除分类", businessType = BusinessTypeEnum.DELETE)
 	@RequiresPermissions("cms:category:del")
-	public ResultData delete(@RequestBody List<CategoryEntity> categorys,HttpServletResponse response, HttpServletRequest request) {
+	public ResultData delete(@RequestBody List<CategoryEntity> categorys, HttpServletResponse response, HttpServletRequest request) {
 		for(int i = 0;i<categorys.size();i++){
 			categoryBiz.delete(Integer.parseInt(categorys.get(i).getId()));
 		}
@@ -230,7 +226,7 @@ public class CategoryAction extends BaseAction{
 	@LogAnn(title = "更新分类", businessType = BusinessTypeEnum.UPDATE)
 	@RequiresPermissions("cms:category:update")
 	public ResultData update(@ModelAttribute @ApiIgnore CategoryEntity category, HttpServletResponse response,
-			HttpServletRequest request) {
+                             HttpServletRequest request) {
 		//验证栏目管理名称的值是否合法
 		if(StringUtil.isBlank(category.getCategoryTitle())){
 			return ResultData.build().error(getResString("err.empty", this.getResString("category.title")));

+ 11 - 15
src/main/java/net/mingsoft/cms/action/ContentAction.java

@@ -4,7 +4,6 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
-import net.mingsoft.base.entity.BaseEntity;
 import net.mingsoft.base.entity.ResultData;
 import net.mingsoft.basic.annotation.LogAnn;
 import net.mingsoft.basic.bean.EUListBean;
@@ -24,6 +23,7 @@ import springfox.documentation.annotations.ApiIgnore;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.util.List;
+
 /**
  * 文章管理控制层
  * @author 铭飞开发团队
@@ -33,7 +33,7 @@ import java.util.List;
 @Api(value = "文章接口")
 @Controller("cmsContentAction")
 @RequestMapping("/${ms.manager.path}/cms/content")
-public class ContentAction extends BaseAction{
+public class ContentAction extends BaseAction {
 	
 	
 	/**
@@ -86,23 +86,19 @@ public class ContentAction extends BaseAction{
     })
 	@RequestMapping("/list")
 	@ResponseBody
-	public ResultData list(@ModelAttribute @ApiIgnore ContentEntity content,HttpServletResponse response, HttpServletRequest request,@ApiIgnore ModelMap model,BindingResult result) {
+	public ResultData list(@ModelAttribute @ApiIgnore ContentEntity content, HttpServletResponse response, HttpServletRequest request, @ApiIgnore ModelMap model, BindingResult result) {
 		content.setAppId(BasicUtil.getAppId());
 		BasicUtil.startPage();
 		List contentList = contentBiz.query(content);
-		return ResultData.build().success(new EUListBean(contentList,(int)BasicUtil.endPage(contentList).getTotal()));
+		return ResultData.build().success(new EUListBean(contentList,(int) BasicUtil.endPage(contentList).getTotal()));
 	}
 	
 	/**
 	 * 返回编辑界面content_form
 	 */
 	@GetMapping("/form")
-	public String form(@ModelAttribute ContentEntity content,HttpServletResponse response,HttpServletRequest request,ModelMap model){
-		if(content.getId()!=null){
-			BaseEntity contentEntity = contentBiz.getEntity(Integer.parseInt(content.getId()));			
-			model.addAttribute("contentEntity",contentEntity);
-		}
-		model.addAttribute("appId",BasicUtil.getAppId());
+	public String form(@ModelAttribute ContentEntity content, HttpServletResponse response, HttpServletRequest request, ModelMap model){
+		model.addAttribute("appId", BasicUtil.getAppId());
 		return "/cms/content/form";
 	}
 
@@ -114,12 +110,12 @@ public class ContentAction extends BaseAction{
     @ApiImplicitParam(name = "id", value = "编号", required =true,paramType="query")
 	@GetMapping("/get")
 	@ResponseBody
-	public ResultData get(@ModelAttribute @ApiIgnore ContentEntity content,HttpServletResponse response, HttpServletRequest request,@ApiIgnore ModelMap model){
+	public ResultData get(@ModelAttribute @ApiIgnore ContentEntity content, HttpServletResponse response, HttpServletRequest request, @ApiIgnore ModelMap model){
 		if(content.getId()==null) {
 			return ResultData.build().error();
 		}
 		content.setAppId(BasicUtil.getAppId());
-		ContentEntity _content = (ContentEntity)contentBiz.getEntity(Integer.parseInt(content.getId()));
+		ContentEntity _content = contentBiz.getById(content.getId());
 		return ResultData.build().success(_content);
 	}
 	
@@ -177,7 +173,7 @@ public class ContentAction extends BaseAction{
 			return ResultData.build().error(getResString("err.length", this.getResString("content.url"), "0", "200"));
 		}
 		content.setAppId(BasicUtil.getAppId());
-		contentBiz.saveEntity(content);
+		contentBiz.save(content);
 		return ResultData.build().success(content);
 	}
 	
@@ -189,7 +185,7 @@ public class ContentAction extends BaseAction{
 	@ResponseBody
 	@LogAnn(title = "删除文章", businessType = BusinessTypeEnum.DELETE)
 	@RequiresPermissions("cms:content:del")
-	public ResultData delete(@RequestBody List<ContentEntity> contents,HttpServletResponse response, HttpServletRequest request) {
+	public ResultData delete(@RequestBody List<ContentEntity> contents, HttpServletResponse response, HttpServletRequest request) {
 		int[] ids = new int[contents.size()];
 		for(int i = 0;i<contents.size();i++){
 			ids[i] =Integer.parseInt(contents.get(i).getId()) ;
@@ -230,7 +226,7 @@ public class ContentAction extends BaseAction{
 	@LogAnn(title = "更新文章", businessType = BusinessTypeEnum.UPDATE)
 	@RequiresPermissions("cms:content:update")
 	public ResultData update(@ModelAttribute @ApiIgnore ContentEntity content, HttpServletResponse response,
-			HttpServletRequest request) {
+                             HttpServletRequest request) {
 		//验证文章标题的值是否合法			
 		if(StringUtil.isBlank(content.getContentTitle())){
 			return ResultData.build().error(getResString("err.empty", this.getResString("content.title")));

+ 14 - 17
src/main/java/net/mingsoft/cms/action/web/MCmsAction.java

@@ -26,9 +26,7 @@ import cn.hutool.core.util.PageUtil;
 import freemarker.core.ParseException;
 import freemarker.template.MalformedTemplateNameException;
 import freemarker.template.TemplateNotFoundException;
-import net.bytebuddy.implementation.bytecode.Throw;
 import net.mingsoft.base.constant.Const;
-import net.mingsoft.basic.exception.BusinessException;
 import net.mingsoft.basic.util.BasicUtil;
 import net.mingsoft.basic.util.StringUtil;
 import net.mingsoft.cms.bean.CategoryBean;
@@ -107,8 +105,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
 	 * 动态列表页
 	 */
 	@GetMapping("/index.do")
-	@ResponseBody
-	public String index(HttpServletRequest req, HttpServletResponse resp) {
+	public void index(HttpServletRequest req, HttpServletResponse resp) {
 		Map map = BasicUtil.assemblyRequestMap();
 		map.forEach((k,v)->{
             map.put(k,v.toString().replaceAll("('|\"|\\\\)","\\\\$1"));
@@ -132,7 +129,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
 		} catch (IOException e) {
 			e.printStackTrace();
 		}
-		return content;
+		this.outString(resp, content);
 	}
 
 	/**
@@ -140,9 +137,8 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
 	 * @param req
 	 * @param resp
 	 */
-	@ResponseBody
 	@GetMapping("/list.do")
-	public String list(HttpServletRequest req, HttpServletResponse resp) {
+	public void list(HttpServletRequest req, HttpServletResponse resp) {
 		Map map = BasicUtil.assemblyRequestMap();
 		map.forEach((k,v)->{
 			map.put(k,v.toString().replaceAll("('|\"|\\\\)","\\\\$1"));
@@ -156,7 +152,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
 		List<CategoryBean> columnArticles = contentBiz.queryIdsByCategoryIdForParser(contentBean);
 		//判断栏目下是否有文章
 		if(columnArticles.size()==0){
-			return "";
+			this.outJson(resp, false);
 		}
 		//设置分页类
 		PageBean page = new PageBean();
@@ -189,7 +185,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
 		} catch (IOException e) {
 			e.printStackTrace();
 		}
-		return content;
+		this.outString(resp, content);
 	}
 
 	/**
@@ -197,17 +193,18 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
 	 * @param id 文章编号
 	 */
 	@GetMapping("/view.do")
-	@ResponseBody
-	public String view(String orderby,String order,HttpServletRequest req, HttpServletResponse resp) {
+	public void view(String orderby,String order,HttpServletRequest req, HttpServletResponse resp) {
 		//参数文章编号
 		ContentEntity article = (ContentEntity) contentBiz.getEntity(BasicUtil.getInt(ParserUtil.ID));
 		if(ObjectUtil.isNull(article)){
-			throw new BusinessException(this.getResString("err.empty", this.getResString("id"))) ;
+			this.outJson(resp, null,false,getResString("err.empty", this.getResString("id")));
+			return;
 		}
 		if(StringUtils.isNotBlank(order)){
 			//防注入
 			if(!order.toLowerCase().equals("asc")&&!order.toLowerCase().equals("desc")){
-				throw new BusinessException(this.getResString("err.error", this.getResString("order")));
+				this.outJson(resp, null,false,getResString("err.error", this.getResString("order")));
+				return;
 			}
 		}
 
@@ -242,7 +239,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
 		ModelEntity contentModel = null;
 		for (int artId = 0; artId < articleIdList.size();) {
 			//如果不是当前文章则跳过
-			if(articleIdList.get(artId).getArticleId() != Integer.parseInt(article.getId())){
+			if(!articleIdList.get(artId).getArticleId().equals(article.getId())){
 				artId++;
 				continue;
 			}
@@ -292,7 +289,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
 		} catch (IOException e) {
 			e.printStackTrace();
 		}
-		return content;
+		this.outString(resp, content);
 	}
 
 
@@ -306,7 +303,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
 	 */
 	@RequestMapping(value = "search")
 	@ResponseBody
-	public String search(HttpServletRequest request, HttpServletResponse response) throws IOException {
+	public void search(HttpServletRequest request, HttpServletResponse response) throws IOException {
 
 		Map<String, Object> map = new HashMap<>();
 		// 读取请求字段
@@ -450,7 +447,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
 		} catch (IOException e) {
 			e.printStackTrace();
 		}
-		return content;
+		this.outString(response, content);
 	}
 
 	// 清除路径中的转义字符

+ 3 - 3
src/main/java/net/mingsoft/cms/bean/CategoryBean.java

@@ -13,16 +13,16 @@ public class CategoryBean extends CategoryEntity {
 	/**
 	 * 文章编号
 	 */
-	private int articleId;
+	private String articleId;
 
 
 
 
-	public int getArticleId() {
+	public String getArticleId() {
 		return articleId;
 	}
 
-	public void setArticleId(int articleId) {
+	public void setArticleId(String articleId) {
 		this.articleId = articleId;
 	}
 }

+ 1 - 1
src/main/java/net/mingsoft/cms/biz/ICategoryBiz.java

@@ -12,7 +12,7 @@ import java.util.List;
  * 创建日期:2019-11-28 15:12:32<br/>
  * 历史修订:<br/>
  */
-public interface ICategoryBiz extends IBaseBiz {
+public interface ICategoryBiz extends IBaseBiz<CategoryEntity> {
 
     /**
      * 查询当前分类下的所有子分类

+ 2 - 1
src/main/java/net/mingsoft/cms/biz/IContentBiz.java

@@ -3,6 +3,7 @@ package net.mingsoft.cms.biz;
 import net.mingsoft.base.biz.IBaseBiz;
 import net.mingsoft.cms.bean.CategoryBean;
 import net.mingsoft.cms.bean.ContentBean;
+import net.mingsoft.cms.entity.ContentEntity;
 import net.mingsoft.mdiy.entity.ModelEntity;
 
 import java.util.List;
@@ -15,7 +16,7 @@ import java.util.Map;
  * 创建日期:2019-11-28 15:12:32<br/>
  * 历史修订:<br/>
  */
-public interface IContentBiz extends IBaseBiz {
+public interface IContentBiz extends IBaseBiz<ContentEntity> {
 
     /**
      * 根据文章属性查询

+ 75 - 8
src/main/java/net/mingsoft/cms/biz/impl/CategoryBizImpl.java

@@ -21,18 +21,21 @@ The MIT License (MIT) * Copyright (c) 2019 铭飞科技
 
 package net.mingsoft.cms.biz.impl;
 
+import cn.hutool.core.lang.Assert;
 import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
 import net.mingsoft.base.biz.impl.BaseBizImpl;
 import net.mingsoft.base.dao.IBaseDao;
 import net.mingsoft.basic.util.BasicUtil;
+import net.mingsoft.basic.util.PinYinUtil;
 import net.mingsoft.cms.biz.ICategoryBiz;
 import net.mingsoft.cms.dao.ICategoryDao;
 import net.mingsoft.cms.dao.IContentDao;
 import net.mingsoft.cms.entity.CategoryEntity;
-import net.mingsoft.basic.util.PinYinUtil;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.List;
 
@@ -43,7 +46,8 @@ import java.util.List;
  * 历史修订:<br/>
  */
  @Service("cmscategoryBizImpl")
-public class CategoryBizImpl extends BaseBizImpl implements ICategoryBiz {
+ @Transactional(rollbackFor = RuntimeException.class)
+public class CategoryBizImpl extends BaseBizImpl<ICategoryDao, CategoryEntity> implements ICategoryBiz {
 
 
 	@Autowired
@@ -74,25 +78,36 @@ public class CategoryBizImpl extends BaseBizImpl implements ICategoryBiz {
 		Object categoryBizEntity = getEntity(category);
 		setParentId(categoryEntity);
 		categoryEntity.setCategoryPinyin(pingYin);
-		super.saveEntity(categoryEntity);
+		//更新新的父级
+		if(StrUtil.isNotBlank(categoryEntity.getCategoryId())&&!"0".equals(categoryEntity.getCategoryId())){
+			CategoryEntity parent = getById(categoryEntity.getCategoryId());
+			//如果之前是叶子节点就更新
+			if(parent.getLeaf()){
+				parent.setLeaf(false);
+				updateById(parent);
+			}
+		}
+		categoryEntity.setLeaf(false);
+		super.save(categoryEntity);
 		//拼音存在则拼接id
 		if(categoryBizEntity!=null){
 			categoryEntity.setCategoryPinyin(pingYin+categoryEntity.getId());
 		}
 		CategoryEntity parentCategory = null;
 		if (StringUtils.isNotBlank(categoryEntity.getCategoryId())) {
-			parentCategory = (CategoryEntity)categoryDao.getEntity(Integer.parseInt(categoryEntity.getCategoryId()));
+			parentCategory = (CategoryEntity)getById(categoryEntity.getCategoryId());
 		}
 		//保存链接地址
 		String path=ObjectUtil.isNotNull(parentCategory)?parentCategory.getCategoryPath():"";
 		categoryEntity.setCategoryPath( path+"/" + categoryEntity.getCategoryPinyin());
-		super.updateEntity(categoryEntity);
+		setTopId(categoryEntity);
+		super.updateById(categoryEntity);
 	}
 
 	private void setParentId(CategoryEntity categoryEntity) {
 		String path = "";
-		if(StringUtils.isNotEmpty(categoryEntity.getCategoryId())&&Integer.parseInt(categoryEntity.getCategoryId())>0) {
-			CategoryEntity category = (CategoryEntity)categoryDao.getEntity(Integer.parseInt(categoryEntity.getCategoryId()));
+		if(StringUtils.isNotEmpty(categoryEntity.getCategoryId())&&Long.parseLong(categoryEntity.getCategoryId())>0) {
+			CategoryEntity category = (CategoryEntity)getById(categoryEntity.getCategoryId());
 			path = category.getCategoryPath();
 			if(StringUtils.isEmpty(category.getCategoryParentId())) {
 				categoryEntity.setCategoryParentId(category.getId());
@@ -138,7 +153,9 @@ public class CategoryBizImpl extends BaseBizImpl implements ICategoryBiz {
 		if(categoryBizEntity!=null&&!categoryBizEntity.getId().equals(entity.getId())){
 			entity.setCategoryPinyin(pingYin+entity.getId());
 		}
-		super.updateEntity(entity);
+		setParentLeaf(entity);
+		setTopId(entity);
+		super.updateById(entity);
 		setChildParentId(entity);
 	}
 
@@ -165,4 +182,54 @@ public class CategoryBizImpl extends BaseBizImpl implements ICategoryBiz {
 			contentDao.deleteEntityByCategoryIds(ids);
 		}
 	}
+
+	/**
+	 * 设置父级叶子节点
+	 * @param entity
+	 */
+	private void setParentLeaf(CategoryEntity entity){
+		Assert.notNull(entity);
+		CategoryEntity categoryEntity = getById(entity.getId());
+		//如果父级不为空并且修改了父级则需要更新父级
+		if(!entity.getCategoryId().equals(categoryEntity.getId())){
+			//更新旧的父级
+			if(StrUtil.isNotBlank(categoryEntity.getCategoryId())&&!"0".equals(categoryEntity.getCategoryId())){
+				CategoryEntity parent = getById(categoryEntity.getCategoryId());
+				//如果修改了父级则需要判断父级是否还有子节点
+				boolean leaf = parent.getLeaf();
+				//查找不等于当前更新的分类子集,有则不是叶子节点
+				parent.setLeaf(count(lambdaQuery().eq(CategoryEntity::getCategoryId,parent.getId()).ne(CategoryEntity::getId,entity.getId()))==0);
+				if(leaf!=parent.getLeaf()){
+					updateById(parent);
+				}
+
+			}
+			//更新新的父级
+			if(StrUtil.isNotBlank(entity.getCategoryId())&&!"0".equals(entity.getCategoryId())){
+				CategoryEntity parent = getById(entity.getCategoryId());
+				//如果之前是叶子节点就更新
+				if(parent.getLeaf()){
+					parent.setLeaf(false);
+					updateById(parent);
+				}
+			}
+		}
+	}
+
+	/**
+	 * 设置顶级id
+	 * @param entity
+	 */
+	private void setTopId(CategoryEntity entity){
+		String categoryParentId = entity.getCategoryParentId();
+		if(StrUtil.isNotBlank(categoryParentId)){
+			String[] ids = categoryParentId.split(",");
+			//如果有ParentId就取第一个
+			if(ids.length>0){
+				entity.setTopId(ids[0]);
+				return;
+			}
+		}
+		entity.setTopId("0");
+	}
 }

+ 9 - 181
src/main/java/net/mingsoft/cms/biz/impl/ContentBizImpl.java

@@ -21,35 +21,20 @@ The MIT License (MIT) * Copyright (c) 2019 铭飞科技
 
 package net.mingsoft.cms.biz.impl;
 
-import cn.hutool.core.bean.BeanUtil;
-import cn.hutool.core.bean.copier.CopyOptions;
-import cn.hutool.core.date.DateUtil;
-import cn.hutool.core.io.FileUtil;
-import net.mingsoft.base.constant.Const;
-import net.mingsoft.basic.holder.DataHolder;
+import net.mingsoft.base.biz.impl.BaseBizImpl;
+import net.mingsoft.base.dao.IBaseDao;
 import net.mingsoft.basic.util.BasicUtil;
 import net.mingsoft.cms.bean.CategoryBean;
 import net.mingsoft.cms.bean.ContentBean;
-import net.mingsoft.cms.dao.ICategoryDao;
-import net.mingsoft.cms.entity.CategoryEntity;
-import net.mingsoft.cms.util.CmsParserUtil;
-import net.mingsoft.mdiy.bean.AttributeBean;
-import net.mingsoft.mdiy.bean.PageBean;
+import net.mingsoft.cms.biz.IContentBiz;
+import net.mingsoft.cms.dao.IContentDao;
+import net.mingsoft.cms.entity.ContentEntity;
 import net.mingsoft.mdiy.entity.ModelEntity;
-import net.mingsoft.mdiy.util.ParserUtil;
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import net.mingsoft.base.biz.impl.BaseBizImpl;
-import net.mingsoft.base.dao.IBaseDao;
-
-import java.io.IOException;
-import java.util.*;
 
-import net.mingsoft.cms.biz.IContentBiz;
-import net.mingsoft.cms.dao.IContentDao;
+import java.util.List;
+import java.util.Map;
 
 /**
  * 文章管理持久化层
@@ -58,20 +43,11 @@ import net.mingsoft.cms.dao.IContentDao;
  * 历史修订:<br/>
  */
  @Service("cmscontentBizImpl")
-public class ContentBizImpl extends BaseBizImpl implements IContentBiz {
-
-	/*
-	 * log4j日志记录
-	 */
-	protected final Logger LOG = LoggerFactory.getLogger(this.getClass());
+public class ContentBizImpl extends BaseBizImpl<IContentDao, ContentEntity> implements IContentBiz {
 
+	
 	@Autowired
 	private IContentDao contentDao;
-	/**
-	 * 栏目管理业务层
-	 */
-	@Autowired
-	private ICategoryDao categoryDao;
 	
 	
 	@Override
@@ -93,152 +69,4 @@ public class ContentBizImpl extends BaseBizImpl implements IContentBiz {
 		}
 		return contentDao.getSearchCount(null,null,whereMap, appId,categoryIds);
 	}
-
-	/*
-	 * 任务调度静态化任务
-	 */
-	public void staticizeTask(Integer appId, String tmpFileName, String generateFileName) {
-		LOG.info("定时静态化任务", new Date());
-		try {
-			//将任务采集传过来的appId导入到线程变量中
-			//当前线程使用appId时优先使用此数据
-			DataHolder.set(ParserUtil.APP_ID, appId);
-			//调用三种静态化
-			genernateColumn();
-			generaterIndex(tmpFileName, generateFileName);
-			//生成文章日期默认为执行日期的上一天
-			generateArticle(DateUtil.format(DateUtil.yesterday(), "yyyy-MM-dd"));
-			LOG.info("静态化完成", new Date());
-		} catch (IOException e) {
-			LOG.info("静态化失败", new Date());
-			e.printStackTrace();
-		}
-	}
-
-	/*
-	 * 生成文章逻辑
-	 */
-	private void generateArticle(String dateTime) throws IOException {
-		// 网站风格物理路径
-		List<CategoryBean> articleIdList = null;
-		List<CategoryEntity> categoryList = null;
-		AttributeBean attributeBean = new AttributeBean();
-		ContentBean contentBean = new ContentBean();
-		contentBean.setBeginTime(dateTime);
-		Map<String, Object> map = new HashMap<>();
-		map.put(ParserUtil.APP_ID, BasicUtil.getAppId());
-		PageBean page = new PageBean();
-		map.put(ParserUtil.HTML, ParserUtil.HTML);
-		map.put(ParserUtil.URL, BasicUtil.getUrl());
-		map.put(ParserUtil.PAGE, page);
-
-		CategoryEntity categoryEntity = new CategoryEntity();
-		categoryList = categoryDao.query(categoryEntity);
-		for(CategoryEntity category : categoryList){
-			contentBean.setContentCategoryId(category.getId());
-			// 分类是列表
-			if(category.getCategoryType().equals("1")){
-				// 判断模板文件是否存在
-				if (!FileUtil.exist(ParserUtil.buildTempletPath(category.getCategoryListUrl())) || StringUtils.isEmpty(category.getCategoryListUrl())) {
-					LOG.error("模板不存在:{}",category.getCategoryUrl());
-					continue;
-				}
-				// 获取文章列表表属性
-				ParserUtil.read(category.getCategoryListUrl(),map, page,attributeBean);
-				contentBean.setFlag(attributeBean.getFlag());
-				contentBean.setNoflag(attributeBean.getNoflag());
-				contentBean.setOrder(attributeBean.getOrder());
-				contentBean.setOrderBy(attributeBean.getOrderby());
-			}
-			articleIdList = queryIdsByCategoryIdForParser(contentBean);
-			// 有符合条件的就更新
-			if (articleIdList.size() > 0) {
-				CmsParserUtil.generateBasic(articleIdList);
-			}
-		}
-	}
-
-	/*
-	 * 生成栏目逻辑
-	 */
-	private void genernateColumn() throws IOException {
-		List<CategoryEntity> columns = new ArrayList<>();
-		// 获取所有的内容管理栏目
-		CategoryEntity categoryEntity=new CategoryEntity();
-		categoryEntity.setAppId(BasicUtil.getAppId());
-		columns = categoryDao.query(categoryEntity);
-		List<CategoryBean> articleIdList = null;
-		// 1、设置模板文件夹路径
-		// 获取栏目列表模版
-		for (CategoryEntity column : columns) {
-			ContentBean contentBean = new ContentBean();
-			contentBean.setContentCategoryId(column.getId());
-			// 分类是列表
-			if(column.getCategoryType().equals("1")) {
-				// 判断模板文件是否存在
-				if (!FileUtil.exist(ParserUtil.buildTempletPath(column.getCategoryListUrl()))) {
-					LOG.error("模板不存在:{}", column.getCategoryUrl());
-					continue;
-				}
-				//获取模板中列表标签中的条件
-				Map<String, Object> map = new HashMap<>();
-				map.put(ParserUtil.APP_ID, BasicUtil.getAppId());
-				PageBean page = new PageBean();
-				map.put(ParserUtil.HTML, ParserUtil.HTML);
-				map.put(ParserUtil.URL, BasicUtil.getUrl());
-				map.put(ParserUtil.PAGE, page);
-				AttributeBean attributeBean = new AttributeBean();
-				// 获取文章列表模板标签属性
-				ParserUtil.read(column.getCategoryListUrl(), map, page, attributeBean);
-				contentBean.setFlag(attributeBean.getFlag());
-				contentBean.setNoflag(attributeBean.getNoflag());
-				contentBean.setOrder(attributeBean.getOrder());
-				contentBean.setOrderBy(attributeBean.getOrderby());
-			}
-			articleIdList = contentDao.queryIdsByCategoryIdForParser(contentBean);
-			// 判断列表类型
-			switch (column.getCategoryType()) {
-				//TODO 暂时先用字符串代替
-				case "1": // 列表
-					CmsParserUtil.generateList(column, articleIdList.size());
-					break;
-				case "2":// 单页
-					if(articleIdList.size()==0){
-						CategoryBean columnArticleIdBean=new CategoryBean();
-						CopyOptions copyOptions=CopyOptions.create();
-						copyOptions.setIgnoreError(true);
-						BeanUtil.copyProperties(column,columnArticleIdBean,copyOptions);
-						articleIdList.add(columnArticleIdBean);
-					}
-					CmsParserUtil.generateBasic(articleIdList);
-					break;
-			}
-		}
-	}
-
-	/*
-	 * 生成主页逻辑
-	 */
-	private void generaterIndex(String templatePath, String targetPath) throws IOException {
-		if (!FileUtil.exist(ParserUtil.buildTempletPath())) {
-			LOG.info("模板文件不存在");
-			return;
-		}
-		Map<String, Object> map = new HashMap<String, Object>();
-		map.put(ParserUtil.IS_DO, false);
-		CategoryEntity column = new CategoryEntity();
-		//内容管理栏目编码
-		map.put(ParserUtil.COLUMN, column);
-		//如果单站点,就废弃站点地址
-		if (ParserUtil.IS_SINGLE) {
-			map.put(ParserUtil.URL, BasicUtil.getUrl());
-		}
-		//设置生成的路径
-		map.put(ParserUtil.HTML, ParserUtil.HTML);
-		//设置站点编号
-		map.put(ParserUtil.APP_ID, BasicUtil.getAppId());
-		String read = ParserUtil.read(templatePath, map);
-		FileUtil.writeString(read, ParserUtil.buildHtmlPath(targetPath), Const.UTF8);
-	}
-
 }

+ 4 - 5
src/main/java/net/mingsoft/cms/dao/ICategoryDao.java

@@ -1,12 +1,11 @@
 package net.mingsoft.cms.dao;
 
 import net.mingsoft.base.dao.IBaseDao;
-import java.util.*;
-
 import net.mingsoft.cms.entity.CategoryEntity;
-import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Component;
 
+import java.util.List;
+
 /**
  * 分类持久层
  * @author 铭飞开发团队
@@ -14,13 +13,13 @@ import org.springframework.stereotype.Component;
  * 历史修订:<br/>
  */
 @Component("cmsCategoryDao")
-public interface ICategoryDao extends IBaseDao {
+public interface ICategoryDao extends IBaseDao<CategoryEntity> {
 
     /**
      * 查询当前分类下面的所有子分类
      * @param category 必须存在categoryId categoryParentId
      * @return
      */
-    public List<net.mingsoft.cms.entity.CategoryEntity> queryChildren(CategoryEntity category);
+    public List<CategoryEntity> queryChildren(CategoryEntity category);
 
 }

+ 6 - 4
src/main/java/net/mingsoft/cms/dao/IContentDao.java

@@ -1,19 +1,21 @@
 package net.mingsoft.cms.dao;
 
 import net.mingsoft.base.dao.IBaseDao;
-import java.util.*;
-
 import net.mingsoft.cms.bean.CategoryBean;
 import net.mingsoft.cms.bean.ContentBean;
+import net.mingsoft.cms.entity.ContentEntity;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.List;
+import java.util.Map;
+
 /**
  * 文章持久层
  * @author 铭飞开发团队
  * 创建日期:2019-11-28 15:12:32<br/>
  * 历史修订:<br/>
  */
-public interface IContentDao extends IBaseDao {
+public interface IContentDao extends IBaseDao<ContentEntity> {
 
     /**
      * 查询文章编号集合
@@ -32,7 +34,7 @@ public interface IContentDao extends IBaseDao {
      *            list[2]:是否是等值查询 list[3]:字段的值
      * @return 文章实体总数
      */
-    int getSearchCount(@Param("tableName") String tableName, @Param("diyList") List diyList,@Param("map") Map<String, Object> map,
+    int getSearchCount(@Param("tableName") String tableName, @Param("diyList") List diyList, @Param("map") Map<String, Object> map,
                        @Param("websiteId") int websiteId, @Param("ids") String ids);
 
     /**

+ 1 - 1
src/main/java/net/mingsoft/cms/dao/IContentDao.xml

@@ -245,7 +245,7 @@
 			<if test="updateBy &gt; 0"> and ct.update_by=#{updateBy} </if>
 			<if test="updateDate != null"> and update_date=#{updateDate} </if>
 		</where>
-		)ct ORDER BY date_format(ct.content_datetime,'%Y-%m-%d') desc,content_sort desc
+		)ct ORDER BY ct.content_datetime desc,content_sort desc
 	</select>
 
 	<sql id="queryWhereCategoryId" databaseId="mysql">

+ 39 - 2
src/main/java/net/mingsoft/cms/entity/CategoryEntity.java

@@ -4,16 +4,20 @@ import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.annotation.JSONField;
-import org.springframework.format.annotation.DateTimeFormat;
+import com.baomidou.mybatisplus.annotation.TableName;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import net.mingsoft.base.entity.BaseEntity;
+import org.springframework.format.annotation.DateTimeFormat;
+
 import java.util.Date;
+
 /**
 * 分类实体
 * @author 铭飞开发团队
 * 创建日期:2019-11-28 15:12:32<br/>
 * 历史修订:<br/>
 */
+@TableName("cms_category")
 public class CategoryEntity extends BaseEntity {
 
 private static final long serialVersionUID = 1574925152750L;
@@ -98,6 +102,31 @@ private static final long serialVersionUID = 1574925152750L;
 	*/
 	private String categoryParentId;
 
+	/**
+	 * 叶子节点
+	 */
+	private Boolean leaf;
+
+	/**
+	 * 顶级id
+	 */
+	private String topId;
+
+	public Boolean getLeaf() {
+		return leaf;
+	}
+
+	public void setLeaf(Boolean leaf) {
+		this.leaf = leaf;
+	}
+
+	public String getTopId() {
+		return topId;
+	}
+
+	public void setTopId(String topId) {
+		this.topId = topId;
+	}
 
 	/**
 	* 设置栏目管理名称
@@ -395,6 +424,14 @@ private static final long serialVersionUID = 1574925152750L;
 	 * 获取栏目图片 (标签使用)
 	 */
 	public String getTypelitpic() {
-		return categoryImg;
+		if(StrUtil.isNotBlank(categoryImg)){
+			try{
+				JSONArray objects = JSON.parseArray(categoryImg);
+				return objects.getJSONObject(0).getString("path");
+			}catch (Exception e){
+
+			}
+		}
+		return "";
 	}
 }

+ 5 - 1
src/main/java/net/mingsoft/cms/entity/ContentEntity.java

@@ -1,16 +1,20 @@
 package net.mingsoft.cms.entity;
 
 import com.alibaba.fastjson.annotation.JSONField;
-import org.springframework.format.annotation.DateTimeFormat;
+import com.baomidou.mybatisplus.annotation.TableName;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import net.mingsoft.base.entity.BaseEntity;
+import org.springframework.format.annotation.DateTimeFormat;
+
 import java.util.Date;
+
 /**
 * 文章实体
 * @author 铭飞开发团队
 * 创建日期:2019-11-28 15:12:32<br/>
 * 历史修订:<br/>
 */
+@TableName("cms_content")
 public class ContentEntity extends BaseEntity {
 
 private static final long serialVersionUID = 1574925152617L;

+ 3 - 6
src/main/java/net/mingsoft/cms/util/CmsParserUtil.java

@@ -7,7 +7,6 @@ import freemarker.core.ParseException;
 import freemarker.template.MalformedTemplateNameException;
 import freemarker.template.TemplateNotFoundException;
 import net.mingsoft.base.constant.Const;
-import net.mingsoft.basic.holder.DataHolder;
 import net.mingsoft.basic.util.BasicUtil;
 import net.mingsoft.basic.util.SpringUtil;
 import net.mingsoft.cms.bean.CategoryBean;
@@ -161,15 +160,15 @@ public class CmsParserUtil extends ParserUtil {
 		Map<Object, Object> contentModelMap = new HashMap<Object, Object>();
 		ModelEntity contentModel = null;
 		// 记录已经生成了文章编号
-		List<Integer> generateIds = new ArrayList<>();
-		ExecutorService pool=SpringUtil.getBean(ExecutorService.class);
+		List<String> generateIds = new ArrayList<>();
+		ExecutorService pool= SpringUtil.getBean(ExecutorService.class);
 		// 生成文章
 		for (int artId = 0; artId < articleIdList.size();) {
 			String writePath = null;
 			//设置分页类
 			PageBean page = new PageBean();
 			// 文章编号
-			int articleId = articleIdList.get(artId).getArticleId();
+			String articleId = articleIdList.get(artId).getArticleId();
 			// 文章的栏目路径
 			String articleColumnPath = articleIdList.get(artId).getCategoryPath();
 			// 该文章相关分类
@@ -245,12 +244,10 @@ public class CmsParserUtil extends ParserUtil {
 			HashMap<Object, Object> cloneMap = CollUtil.newHashMap();
 			cloneMap.putAll(parserParams);
             HttpServletRequest request = SpringUtil.getRequest();
-            Integer appId = (Integer) DataHolder.get("appId");
             pool.execute(() -> {
 				String content = null;
 				try {
 					SpringUtil.setRequest(request);
-					DataHolder.set("appId", appId);
 					content = CmsParserUtil.generate(columnUrl, cloneMap);
 					FileUtil.writeString(content, finalWritePath, Const.UTF8);
 				} catch (IOException e) {

+ 25 - 0
src/main/java/net/mingsoft/config/WebConfig.java

@@ -1,11 +1,17 @@
 package net.mingsoft.config;
 
 import java.io.File;
+import java.sql.SQLException;
 import java.util.List;
 import java.util.concurrent.*;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import com.baomidou.mybatisplus.annotation.DbType;
+import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
+import com.baomidou.mybatisplus.extension.toolkit.JdbcUtils;
+import net.mingsoft.interceptor.DMInnerInterceptor;
+import net.mingsoft.interceptor.MysqlInnerInterceptor;
 import org.springframework.aop.Advisor;
 import net.mingsoft.basic.filter.XSSEscapeFilter;
 import org.springframework.aop.support.DefaultPointcutAdvisor;
@@ -37,6 +43,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 import net.mingsoft.basic.interceptor.ActionInterceptor;
 import net.mingsoft.basic.util.BasicUtil;
 
+import javax.sql.DataSource;
+
 @Configuration
 public class WebConfig implements WebMvcConfigurer {
 
@@ -59,6 +67,23 @@ public class WebConfig implements WebMvcConfigurer {
 	}
 
 
+	@Bean
+	public MybatisPlusInterceptor mybatisPlusInterceptor(DataSource dataSource) {
+		MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
+		try {
+			//mysql 添加转换sql
+			DbType dbType = JdbcUtils.getDbType(dataSource.getConnection().getMetaData().getURL());
+			if(DbType.MYSQL==dbType){
+				interceptor.addInnerInterceptor(new MysqlInnerInterceptor());
+			}else if(DbType.DM==dbType){
+				interceptor.addInnerInterceptor( new DMInnerInterceptor());
+			}
+		} catch (SQLException e) {
+			e.printStackTrace();
+		}
+
+		return interceptor;
+	}
 	/**
 	 * 增加对rest api鉴权的spring mvc拦截器
 	 */

+ 61 - 0
src/main/java/net/mingsoft/interceptor/DMInnerInterceptor.java

@@ -0,0 +1,61 @@
+package net.mingsoft.interceptor;
+
+import com.baomidou.mybatisplus.core.plugins.InterceptorIgnoreHelper;
+import com.baomidou.mybatisplus.core.toolkit.PluginUtils;
+import com.baomidou.mybatisplus.core.toolkit.TableNameParser;
+import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor;
+import org.apache.ibatis.executor.Executor;
+import org.apache.ibatis.executor.statement.StatementHandler;
+import org.apache.ibatis.mapping.BoundSql;
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.mapping.SqlCommandType;
+import org.apache.ibatis.session.ResultHandler;
+import org.apache.ibatis.session.RowBounds;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class DMInnerInterceptor  implements InnerInterceptor {
+
+    @Override
+    public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException {
+        PluginUtils.MPBoundSql mpBs = PluginUtils.mpBoundSql(boundSql);
+        if (InterceptorIgnoreHelper.willIgnoreDynamicTableName(ms.getId())) return;
+        mpBs.sql(this.changeTable(mpBs.sql()));
+    }
+
+    @Override
+    public void beforePrepare(StatementHandler sh, Connection connection, Integer transactionTimeout) {
+        PluginUtils.MPStatementHandler mpSh = PluginUtils.mpStatementHandler(sh);
+        MappedStatement ms = mpSh.mappedStatement();
+        SqlCommandType sct = ms.getSqlCommandType();
+        if (sct == SqlCommandType.INSERT || sct == SqlCommandType.UPDATE || sct == SqlCommandType.DELETE) {
+            if (InterceptorIgnoreHelper.willIgnoreDynamicTableName(ms.getId())) return;
+            PluginUtils.MPBoundSql mpBs = mpSh.mPBoundSql();
+            mpBs.sql(this.changeTable(mpBs.sql()));
+        }
+    }
+
+    protected String changeTable(String sql) {
+        TableNameParser parser = new TableNameParser(sql);
+        List<TableNameParser.SqlToken> names = new ArrayList<>();
+        parser.accept(names::add);
+        StringBuilder builder = new StringBuilder();
+        int last = 0;
+        for (TableNameParser.SqlToken name : names) {
+            int start = name.getStart();
+            if (start != last) {
+                builder.append(sql, last, start);
+                String value = name.getValue();
+                builder.append(String.format("\"%s\"",value));
+            }
+            last = name.getEnd();
+        }
+        if (last != sql.length()) {
+            builder.append(sql.substring(last));
+        }
+        return builder.toString();
+    }
+}

+ 45 - 0
src/main/java/net/mingsoft/interceptor/MysqlInnerInterceptor.java

@@ -0,0 +1,45 @@
+package net.mingsoft.interceptor;
+
+import com.baomidou.mybatisplus.core.plugins.InterceptorIgnoreHelper;
+import com.baomidou.mybatisplus.core.toolkit.PluginUtils;
+import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor;
+import org.apache.ibatis.executor.Executor;
+import org.apache.ibatis.executor.statement.StatementHandler;
+import org.apache.ibatis.mapping.BoundSql;
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.mapping.SqlCommandType;
+import org.apache.ibatis.session.ResultHandler;
+import org.apache.ibatis.session.RowBounds;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+/**
+ * Mysql 适配通用拦截器,主要处理不支持的sql语句
+ */
+public class MysqlInnerInterceptor implements InnerInterceptor {
+
+    @Override
+    public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException {
+        PluginUtils.MPBoundSql mpBs = PluginUtils.mpBoundSql(boundSql);
+        if (InterceptorIgnoreHelper.willIgnoreDynamicTableName(ms.getId())) return;
+        mpBs.sql(this.changeSql(mpBs.sql()));
+    }
+
+    @Override
+    public void beforePrepare(StatementHandler sh, Connection connection, Integer transactionTimeout) {
+        PluginUtils.MPStatementHandler mpSh = PluginUtils.mpStatementHandler(sh);
+        MappedStatement ms = mpSh.mappedStatement();
+        SqlCommandType sct = ms.getSqlCommandType();
+        if (sct == SqlCommandType.INSERT || sct == SqlCommandType.UPDATE || sct == SqlCommandType.DELETE) {
+            if (InterceptorIgnoreHelper.willIgnoreDynamicTableName(ms.getId())) return;
+            PluginUtils.MPBoundSql mpBs = mpSh.mPBoundSql();
+            mpBs.sql(this.changeSql(mpBs.sql()));
+        }
+    }
+
+    protected String changeSql(String sql) {
+        //替换所有"为`
+        return sql.replaceAll("\"","`");
+    }
+}

+ 1 - 1
src/main/webapp/WEB-INF/manager/cms/category/form.ftl

@@ -249,7 +249,7 @@
                     // 栏目管理名称
                     categoryTitle: '',
                     // 所属栏目
-                    categoryId: '',
+                    categoryId: null,
                     // 栏目管理属性
                     categoryType: '1',
                     // 自定义顺序