diff --git a/src/main/java/net/mingsoft/cms/action/CategoryAction.java b/src/main/java/net/mingsoft/cms/action/CategoryAction.java index 5d7eb8fb..ce9ae216 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; @@ -180,7 +181,7 @@ public class CategoryAction extends BaseAction { } /** - * @param category 分类实体 + * @param categorys 分类实体 */ @ApiOperation(value = "批量删除分类列表接口") @PostMapping("/delete") @@ -295,12 +296,35 @@ public class CategoryAction extends BaseAction { @ApiOperation(value = "批量更新模版") @GetMapping("/updateTemplate") @ResponseBody - public ResultData updateTemplate(@ModelAttribute @ApiIgnore CategoryEntity category, HttpServletResponse response, HttpServletRequest request, @ApiIgnore ModelMap model){ - - //父栏目是列表 - - //父栏目是封面 - + @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()); + category.setCategoryParentId(null); + List childs = categoryBiz.queryChilds(category); + //更新与父节点相同类型的子栏目的模板内容 + for (int i =0; i < childs.size(); i++) { + if (childs.get(i).getCategoryType().equals(category.getCategoryType())) { + childs.get(i).setCategoryUrl(category.getCategoryUrl()); + childs.get(i).setCategoryListUrl(category.getCategoryListUrl()); + categoryBiz.updateEntity(childs.get(i)); + } + } 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 4edf39be..b052abf7 100644 --- a/src/main/java/net/mingsoft/cms/biz/impl/CategoryBizImpl.java +++ b/src/main/java/net/mingsoft/cms/biz/impl/CategoryBizImpl.java @@ -202,7 +202,7 @@ public class CategoryBizImpl extends BaseBizImpl i Assert.notNull(entity); CategoryEntity categoryEntity = getById(entity.getId()); //如果父级不为空并且修改了父级则需要更新父级 - if(!entity.getCategoryId().equals(categoryEntity.getCategoryId())){ + if(entity.getCategoryId() != null && !entity.getCategoryId().equals(categoryEntity.getCategoryId())){ //更新旧的父级 if(StrUtil.isNotBlank(categoryEntity.getCategoryId())&&!"0".equals(categoryEntity.getCategoryId())){ CategoryEntity parent = getById(categoryEntity.getCategoryId()); @@ -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 2e404c36..455ccf9d 100644 --- a/src/main/webapp/WEB-INF/manager/cms/category/index.ftl +++ b/src/main/webapp/WEB-INF/manager/cms/category/index.ftl @@ -75,6 +75,12 @@ <@shiro.hasPermission name="cms:category:save"> 子栏目 + <@shiro.hasPermission name="cms:category:save"> + 克隆 + +<#-- <@shiro.hasPermission name="cms:category:update">--> +<#-- 应用子栏目--> +<#-- --> <@shiro.hasPermission name="cms:category:update"> 编辑 @@ -143,6 +149,54 @@ } }, 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(id) { + var that = this; + ms.http.get(ms.manager + "/cms/category/updateTemplate.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); + }); + }, //根据字典数据值获取字典标签名 getDictLabel: function (v) { var that = this;