复制栏目
This commit is contained in:
parent
25cfb72798
commit
5c7ef73eec
|
@ -16,6 +16,7 @@ import net.mingsoft.basic.util.PinYinUtil;
|
||||||
import net.mingsoft.basic.util.StringUtil;
|
import net.mingsoft.basic.util.StringUtil;
|
||||||
import net.mingsoft.cms.biz.ICategoryBiz;
|
import net.mingsoft.cms.biz.ICategoryBiz;
|
||||||
import net.mingsoft.cms.entity.CategoryEntity;
|
import net.mingsoft.cms.entity.CategoryEntity;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
|
@ -27,7 +28,6 @@ import springfox.documentation.annotations.ApiIgnore;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分类管理控制层
|
* 分类管理控制层
|
||||||
|
@ -296,8 +296,13 @@ public class CategoryAction extends BaseAction {
|
||||||
@ApiOperation(value = "批量更新模版")
|
@ApiOperation(value = "批量更新模版")
|
||||||
@GetMapping("/updateTemplate")
|
@GetMapping("/updateTemplate")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
|
@RequiresPermissions("cms:category:update")
|
||||||
public ResultData updateTemplate(@ModelAttribute @ApiIgnore CategoryEntity category){
|
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 = categoryBiz.getById(category.getId());
|
||||||
|
|
||||||
List<CategoryEntity> childs = categoryBiz.queryChilds(category);
|
List<CategoryEntity> childs = categoryBiz.queryChilds(category);
|
||||||
//更新与父节点相同类型的子栏目的模板内容
|
//更新与父节点相同类型的子栏目的模板内容
|
||||||
for (int i =0; i < childs.size(); i++) {
|
for (int i =0; i < childs.size(); i++) {
|
||||||
|
@ -310,4 +315,16 @@ public class CategoryAction extends BaseAction {
|
||||||
return ResultData.build().success();
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,4 +34,6 @@ public interface ICategoryBiz extends IBaseBiz<CategoryEntity> {
|
||||||
void update(CategoryEntity entity);
|
void update(CategoryEntity entity);
|
||||||
|
|
||||||
void delete(String categoryId);
|
void delete(String categoryId);
|
||||||
|
|
||||||
|
void copyCategory(CategoryEntity entity);
|
||||||
}
|
}
|
||||||
|
|
|
@ -244,4 +244,41 @@ public class CategoryBizImpl extends BaseBizImpl<ICategoryDao, CategoryEntity> i
|
||||||
}
|
}
|
||||||
entity.setTopId("0");
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,8 +75,11 @@
|
||||||
<@shiro.hasPermission name="cms:category:save">
|
<@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>
|
<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>
|
||||||
|
<@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">
|
<@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>
|
||||||
<@shiro.hasPermission name="cms:category:update">
|
<@shiro.hasPermission name="cms:category:update">
|
||||||
<el-link type="primary" :underline="false" @click="save(scope.row.id)">编辑</el-link>
|
<el-link type="primary" :underline="false" @click="save(scope.row.id)">编辑</el-link>
|
||||||
|
@ -146,11 +149,35 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
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;
|
var that = this;
|
||||||
ms.http.get(ms.manager + "/cms/category/updateTemplate.do", {
|
ms.http.get(ms.manager + "/cms/category/updateTemplate.do", {
|
||||||
id: row.id
|
id: id
|
||||||
}).then(function (res) {
|
}).then(function (res) {
|
||||||
if (res.result) {
|
if (res.result) {
|
||||||
that.$notify({
|
that.$notify({
|
||||||
|
|
Loading…
Reference in New Issue