From 097965d7a006ad6980fee459ef3dcbcdcb5a405d Mon Sep 17 00:00:00 2001 From: clunt Date: Sat, 7 May 2022 17:16:36 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E7=B1=BB=E7=9B=AE=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E5=8D=8A=E6=88=90=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../goods/GoodsCategoryController.java | 47 ++++++ .../templates/goods/category/add.html | 118 +++++++++++++++ .../templates/goods/category/category.html | 2 +- .../templates/goods/category/edit.html | 141 ++++++++++++++++++ .../templates/goods/category/tree.html | 52 +++++++ .../ghy/common/constant/UserConstants.java | 6 + .../goods/service/GoodsCategoryService.java | 10 ++ .../impl/GoodsCategoryServiceImpl.java | 50 +++++++ .../mapper/goods/GoodsCategoryMapper.xml | 3 +- 9 files changed, 427 insertions(+), 2 deletions(-) create mode 100644 ghy-admin/src/main/resources/templates/goods/category/add.html create mode 100644 ghy-admin/src/main/resources/templates/goods/category/edit.html create mode 100644 ghy-admin/src/main/resources/templates/goods/category/tree.html diff --git a/ghy-admin/src/main/java/com/ghy/web/controller/goods/GoodsCategoryController.java b/ghy-admin/src/main/java/com/ghy/web/controller/goods/GoodsCategoryController.java index 2a89e0c9..cc6ecd91 100644 --- a/ghy-admin/src/main/java/com/ghy/web/controller/goods/GoodsCategoryController.java +++ b/ghy-admin/src/main/java/com/ghy/web/controller/goods/GoodsCategoryController.java @@ -4,6 +4,8 @@ import com.ghy.common.annotation.Log; import com.ghy.common.constant.UserConstants; import com.ghy.common.core.controller.BaseController; import com.ghy.common.core.domain.AjaxResult; +import com.ghy.common.core.domain.Ztree; +import com.ghy.common.core.domain.entity.SysDept; import com.ghy.common.core.page.TableDataInfo; import com.ghy.common.enums.BusinessType; import com.ghy.goods.domain.GoodsCategory; @@ -35,6 +37,17 @@ public class GoodsCategoryController extends BaseController { return PREFIX + "/category"; } + + /** + * 新增部门 + */ + @GetMapping("/add/{parentCategoryId}") + public String add(@PathVariable("parentCategoryId") Long parentCategoryId, ModelMap mmap) + { + mmap.put("goodsCategory", goodsCategoryService.selectById(parentCategoryId)); + return PREFIX + "/add"; + } + /** * 新增商品类别页面 */ @@ -102,6 +115,40 @@ public class GoodsCategoryController extends BaseController { return toAjax(goodsCategoryService.updateGoodsCategory(category)); } + /** + * 选择部门树 + * + * @param categoryId 类目ID + * @param excludeId 排除ID + */ + @GetMapping(value = { "/selectGoodsCategoryTree/{categoryId}", "/selectGoodsCategoryTree/{categoryId}/{excludeId}" }) + public String selectDeptTree(@PathVariable("categoryId") Long categoryId, + @PathVariable(value = "excludeId", required = false) String excludeId, ModelMap mmap) + { + mmap.put("goodsCategory", goodsCategoryService.selectById(categoryId)); + mmap.put("excludeId", excludeId); + return PREFIX + "/tree"; + } + + /** + * 加载部门列表树 + */ + @GetMapping("/treeData") + @ResponseBody + public List treeData() + { + return goodsCategoryService.selectCategoryTree(new GoodsCategory()); + } + + /** + * 加载部门列表树(排除下级) + */ + @GetMapping("/treeData/{excludeId}") + @ResponseBody + public List treeDataExcludeChild(@PathVariable(value = "excludeId", required = false) Long excludeId) + { + return goodsCategoryService.selectCategoryTree(new GoodsCategory()); + } /** * 商品类别表 */ diff --git a/ghy-admin/src/main/resources/templates/goods/category/add.html b/ghy-admin/src/main/resources/templates/goods/category/add.html new file mode 100644 index 00000000..8d174895 --- /dev/null +++ b/ghy-admin/src/main/resources/templates/goods/category/add.html @@ -0,0 +1,118 @@ + + + + + + +
+
+ +
+ +
+
+ + +
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
+ + +
+
+
+
+ +
+
+ + +
+
+
+
+
+ + + + diff --git a/ghy-admin/src/main/resources/templates/goods/category/category.html b/ghy-admin/src/main/resources/templates/goods/category/category.html index 96083cd2..f04d61af 100644 --- a/ghy-admin/src/main/resources/templates/goods/category/category.html +++ b/ghy-admin/src/main/resources/templates/goods/category/category.html @@ -29,7 +29,7 @@
- + 新增 diff --git a/ghy-admin/src/main/resources/templates/goods/category/edit.html b/ghy-admin/src/main/resources/templates/goods/category/edit.html new file mode 100644 index 00000000..93d6466c --- /dev/null +++ b/ghy-admin/src/main/resources/templates/goods/category/edit.html @@ -0,0 +1,141 @@ + + + + + + +
+
+ + +
+ +
+
+ + +
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
+ + +
+
+
+
+
+ + + + diff --git a/ghy-admin/src/main/resources/templates/goods/category/tree.html b/ghy-admin/src/main/resources/templates/goods/category/tree.html new file mode 100644 index 00000000..c15252b1 --- /dev/null +++ b/ghy-admin/src/main/resources/templates/goods/category/tree.html @@ -0,0 +1,52 @@ + + + + + + + + + + +
+ + + + + diff --git a/ghy-common/src/main/java/com/ghy/common/constant/UserConstants.java b/ghy-common/src/main/java/com/ghy/common/constant/UserConstants.java index 13c844b5..bb626203 100644 --- a/ghy-common/src/main/java/com/ghy/common/constant/UserConstants.java +++ b/ghy-common/src/main/java/com/ghy/common/constant/UserConstants.java @@ -30,6 +30,12 @@ public class UserConstants /** 部门正常状态 */ public static final String DEPT_NORMAL = "0"; + /** 类目正常状态 */ + public static final Integer CATEGORY_NORMAL = 0; + + /** 类目停用状态 */ + public static final Integer CATEGORY_DISABLE = 1; + /** 部门停用状态 */ public static final String DEPT_DISABLE = "1"; diff --git a/ghy-goods/src/main/java/com/ghy/goods/service/GoodsCategoryService.java b/ghy-goods/src/main/java/com/ghy/goods/service/GoodsCategoryService.java index c931cf56..bb9ba43b 100644 --- a/ghy-goods/src/main/java/com/ghy/goods/service/GoodsCategoryService.java +++ b/ghy-goods/src/main/java/com/ghy/goods/service/GoodsCategoryService.java @@ -1,5 +1,7 @@ package com.ghy.goods.service; +import com.ghy.common.core.domain.Ztree; +import com.ghy.common.core.domain.entity.SysDept; import com.ghy.goods.domain.GoodsCategory; import java.util.List; @@ -30,6 +32,14 @@ public interface GoodsCategoryService { List selectGoodsCategoryList(GoodsCategory goodsCategory); + /** + * 查询类目管理树 + * + * @param goodsCategory 类目信息 + * @return 所有类目信息 + */ + public List selectCategoryTree(GoodsCategory goodsCategory); + /** * @param goodsCategoryId 商品类别id * @return 商品类别 diff --git a/ghy-goods/src/main/java/com/ghy/goods/service/impl/GoodsCategoryServiceImpl.java b/ghy-goods/src/main/java/com/ghy/goods/service/impl/GoodsCategoryServiceImpl.java index 67731858..875b9898 100644 --- a/ghy-goods/src/main/java/com/ghy/goods/service/impl/GoodsCategoryServiceImpl.java +++ b/ghy-goods/src/main/java/com/ghy/goods/service/impl/GoodsCategoryServiceImpl.java @@ -1,6 +1,10 @@ package com.ghy.goods.service.impl; +import com.ghy.common.constant.UserConstants; +import com.ghy.common.core.domain.Ztree; +import com.ghy.common.core.domain.entity.SysDept; import com.ghy.common.core.text.Convert; +import com.ghy.common.utils.StringUtils; import com.ghy.goods.domain.Goods; import com.ghy.goods.domain.GoodsCategory; import com.ghy.goods.mapper.GoodsCategoryMapper; @@ -10,6 +14,7 @@ import org.springframework.stereotype.Service; import org.springframework.util.Assert; import javax.annotation.Resource; +import java.util.ArrayList; import java.util.List; /** @@ -39,6 +44,12 @@ public class GoodsCategoryServiceImpl implements GoodsCategoryService { return goodsCategoryMapper.selectGoodsCategoryList(goodsCategory); } + @Override + public List selectCategoryTree(GoodsCategory goodsCategory) { + List goodsCategoryList = goodsCategoryMapper.selectGoodsCategoryList(goodsCategory); + return initZtree(goodsCategoryList); + } + @Override public GoodsCategory selectById(Long goodsCategoryId) { return goodsCategoryMapper.selectById(goodsCategoryId); @@ -71,4 +82,43 @@ public class GoodsCategoryServiceImpl implements GoodsCategoryService { } return category.getGoodsCategoryId().equals(goodsCategory.getGoodsCategoryId()); } + + /** + * 对象转类目树 + * + * @param goodsCategoryList 类目列表 + * @return 树结构列表 + */ + public List initZtree(List goodsCategoryList) + { + return initZtree(goodsCategoryList, null); + } + + /** + * 对象转部门树 + * + * @param goodsCategoryList 类目列表 + * @param roleDeptList 该列表无需校验 + * @return 树结构列表 + */ + public List initZtree(List goodsCategoryList, List roleDeptList) + { + + List ztrees = new ArrayList(); + for (GoodsCategory goodsCategory : goodsCategoryList) + { + if (UserConstants.CATEGORY_NORMAL.equals(goodsCategory.getStatus())) + { + Ztree ztree = new Ztree(); + ztree.setId(goodsCategory.getGoodsCategoryId()); + ztree.setpId(goodsCategory.getParentCategoryId()); + ztree.setName(goodsCategory.getGoodsCategoryName()); + ztree.setTitle(goodsCategory.getGoodsCategoryName()); + ztrees.add(ztree); + } + } + return ztrees; + } + + } diff --git a/ghy-goods/src/main/resources/mapper/goods/GoodsCategoryMapper.xml b/ghy-goods/src/main/resources/mapper/goods/GoodsCategoryMapper.xml index 480b14da..91a3523b 100644 --- a/ghy-goods/src/main/resources/mapper/goods/GoodsCategoryMapper.xml +++ b/ghy-goods/src/main/resources/mapper/goods/GoodsCategoryMapper.xml @@ -9,6 +9,7 @@ + @@ -18,7 +19,7 @@ SELECT goods_category_id, goods_category_code, goods_category_name, parent_category_id, - level, type, create_by, create_time, remark + level, type, status, create_by, create_time, remark FROM goods_category