复制栏目

This commit is contained in:
xierz 2020-11-23 14:10:44 +08:00
parent 25cfb72798
commit 5c7ef73eec
4 changed files with 87 additions and 4 deletions

View File

@ -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<CategoryEntity> 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();
}
}

View File

@ -34,4 +34,6 @@ public interface ICategoryBiz extends IBaseBiz<CategoryEntity> {
void update(CategoryEntity entity);
void delete(String categoryId);
void copyCategory(CategoryEntity entity);
}

View File

@ -244,4 +244,41 @@ public class CategoryBizImpl extends BaseBizImpl<ICategoryDao, CategoryEntity> 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<CategoryEntity> 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());
}
}
}

View File

@ -75,8 +75,11 @@
<@shiro.hasPermission name="cms:category:save">
<el-link type="primary" :underline="false" @click="save(scope.row.id, scope.row.id)"><i class="el-icon-plus"></i>子栏目</el-link>
</@shiro.hasPermission>
<@shiro.hasPermission name="cms:category:save">
<el-link type="primary" :underline="false" @click="copyCategory(scope.row.id)">复制栏目</el-link>
</@shiro.hasPermission>
<@shiro.hasPermission name="cms:category:update">
<el-link type="primary" :underline="false" v-if="scope.row.categoryType == '1' || scope.row.categoryType == '2'" @click="updateTemplate(scope.row)">应用子栏目</el-link>
<el-link type="primary" :underline="false" v-if="scope.row.categoryType == '1' || scope.row.categoryType == '2'" @click="updateTemplate(scope.row.id)">应用子栏目</el-link>
</@shiro.hasPermission>
<@shiro.hasPermission name="cms:category:update">
<el-link type="primary" :underline="false" @click="save(scope.row.id)">编辑</el-link>
@ -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({