From 5c7ef73eeca1fd2abbefb0eef72bb808405cae6d Mon Sep 17 00:00:00 2001 From: xierz Date: Mon, 23 Nov 2020 14:10:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=8D=E5=88=B6=E6=A0=8F=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mingsoft/cms/action/CategoryAction.java | 19 +++++++++- .../net/mingsoft/cms/biz/ICategoryBiz.java | 2 + .../cms/biz/impl/CategoryBizImpl.java | 37 +++++++++++++++++++ .../WEB-INF/manager/cms/category/index.ftl | 33 +++++++++++++++-- 4 files changed, 87 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/mingsoft/cms/action/CategoryAction.java b/src/main/java/net/mingsoft/cms/action/CategoryAction.java index 1b35298b..f5b9addd 100644 --- a/src/main/java/net/mingsoft/cms/action/CategoryAction.java +++ b/src/main/java/net/mingsoft/cms/action/CategoryAction.java @@ -16,6 +16,7 @@ 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 org.apache.commons.lang3.StringUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; @@ -27,7 +28,6 @@ import springfox.documentation.annotations.ApiIgnore; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.List; -import java.util.Optional; /** * 分类管理控制层 @@ -296,8 +296,13 @@ public class CategoryAction extends BaseAction { @ApiOperation(value = "批量更新模版") @GetMapping("/updateTemplate") @ResponseBody + @RequiresPermissions("cms:category:update") public ResultData updateTemplate(@ModelAttribute @ApiIgnore CategoryEntity category){ + if (category ==null || StringUtils.isEmpty(category.getId())) { + return ResultData.build().error(getResString("err.error", this.getResString("id"))); + } category = categoryBiz.getById(category.getId()); + List childs = categoryBiz.queryChilds(category); //更新与父节点相同类型的子栏目的模板内容 for (int i =0; i < childs.size(); i++) { @@ -310,4 +315,16 @@ public class CategoryAction extends BaseAction { return ResultData.build().success(); } + @ApiOperation(value = "复制栏目") + @GetMapping("/copyCategory") + @ResponseBody + @RequiresPermissions("cms:category:save") + public ResultData copyCategory(@ModelAttribute @ApiIgnore CategoryEntity category){ + if (category == null || StringUtils.isEmpty(category.getId())) { + return ResultData.build().error(getResString("err.error", this.getResString("id"))); + } + categoryBiz.copyCategory(category); + return ResultData.build().success(); + } + } diff --git a/src/main/java/net/mingsoft/cms/biz/ICategoryBiz.java b/src/main/java/net/mingsoft/cms/biz/ICategoryBiz.java index 834667c5..f2bd198e 100644 --- a/src/main/java/net/mingsoft/cms/biz/ICategoryBiz.java +++ b/src/main/java/net/mingsoft/cms/biz/ICategoryBiz.java @@ -34,4 +34,6 @@ public interface ICategoryBiz extends IBaseBiz { void update(CategoryEntity entity); void delete(String categoryId); + + void copyCategory(CategoryEntity entity); } diff --git a/src/main/java/net/mingsoft/cms/biz/impl/CategoryBizImpl.java b/src/main/java/net/mingsoft/cms/biz/impl/CategoryBizImpl.java index 89e7f193..b052abf7 100644 --- a/src/main/java/net/mingsoft/cms/biz/impl/CategoryBizImpl.java +++ b/src/main/java/net/mingsoft/cms/biz/impl/CategoryBizImpl.java @@ -244,4 +244,41 @@ public class CategoryBizImpl extends BaseBizImpl i } entity.setTopId("0"); } + + @Override + public void copyCategory(CategoryEntity category) { + String oldId = category.getId(); + //先保存被复制第一层栏目,因为第一层栏目不需要变更父级栏目 + category = getById(oldId); + //id、拼音和路径按照原来的业务逻辑生成 + category.setId(null); + category.setCategoryPinyin(null); + category.setCategoryPath(null); + saveEntity(category); + //传入简要被复制子栏目的id和复制后的生成的id,复制的子栏目全部使用 + recursionCopyChilds(oldId, category.getId()); + } + + /* + * 递归复制子栏目 + * @param oldParentId:被复制的父级栏目id(需要数据库原来存在该数据) + * @param newParentId:复制栏目后新父级的id(新插入数据的id) + * */ + private void recursionCopyChilds(String oldParentId, String newParentId) { + CategoryEntity _category = new CategoryEntity(); + _category.setCategoryId(oldParentId); + List childs = query(_category); + for (CategoryEntity child : childs) { + String childId = child.getId(); + //id、拼音和路径按照原来的业务逻辑生成 + child.setId(null); + child.setCategoryPinyin(null); + child.setCategoryPath(null); + child.setCategoryId(newParentId); + saveEntity(child); + //如果该栏目下还有子栏目则继续复制该栏目里的子栏目 + recursionCopyChilds(childId, child.getId()); + } + } + } diff --git a/src/main/webapp/WEB-INF/manager/cms/category/index.ftl b/src/main/webapp/WEB-INF/manager/cms/category/index.ftl index 0de11ccd..a1f2218e 100644 --- a/src/main/webapp/WEB-INF/manager/cms/category/index.ftl +++ b/src/main/webapp/WEB-INF/manager/cms/category/index.ftl @@ -75,8 +75,11 @@ <@shiro.hasPermission name="cms:category:save"> 子栏目 + <@shiro.hasPermission name="cms:category:save"> + 复制栏目 + <@shiro.hasPermission name="cms:category:update"> - 应用子栏目 + 应用子栏目 <@shiro.hasPermission name="cms:category:update"> 编辑 @@ -146,11 +149,35 @@ } }, methods: { + //复制栏目 + copyCategory: function(id) { + var that = this; + ms.http.get(ms.manager + "/cms/category/copyCategory.do", { + id: id + }).then(function (res) { + if (res.result) { + that.$notify({ + title: '成功', + message: '复制成功', + type: 'success' + }); + that.list(); + } else { + that.$notify({ + title: '失败', + message: res.msg, + type: 'warning' + }); + } + }).catch(function (err) { + console.log(err); + }); + }, //应用子栏目模板 - updateTemplate: function(row) { + updateTemplate: function(id) { var that = this; ms.http.get(ms.manager + "/cms/category/updateTemplate.do", { - id: row.id + id: id }).then(function (res) { if (res.result) { that.$notify({