From 290b988beed71e28d6272cf763e9074887e977f6 Mon Sep 17 00:00:00 2001 From: HH Date: Wed, 27 Jul 2022 19:42:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=AC=E5=8F=B8=E9=85=8D=E4=BB=B6=E7=B1=BB?= =?UTF-8?q?=E7=9B=AE=E4=B8=8E=E6=9C=8D=E5=8A=A1=E7=B1=BB=E7=9B=AE=E5=88=86?= =?UTF-8?q?=E5=BC=80=E4=B8=A4=E4=B8=AA=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../goods/GoodsCategoryController.java | 4 +- .../goods/GoodsDeptCategoryController.java | 26 +-- .../templates/goods/deptcategory/add.html | 5 +- .../goods/deptcategory/deptcategory.html | 4 +- .../goods/deptcategory/deptservecategory.html | 162 ++++++++++++++++++ .../ghy/goods/domain/DeptGoodsCategory.java | 3 + .../goods/service/GoodsCategoryService.java | 5 +- .../impl/DeptGoodsCategoryServiceImpl.java | 10 +- .../impl/GoodsCategoryServiceImpl.java | 6 +- .../mapper/goods/DeptGoodsCategoryMapper.xml | 7 +- .../mapper/goods/GoodsCategoryMapper.xml | 3 + 11 files changed, 211 insertions(+), 24 deletions(-) create mode 100644 ghy-admin/src/main/resources/templates/goods/deptcategory/deptservecategory.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 5717ff48..424902f3 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 @@ -138,9 +138,9 @@ public class GoodsCategoryController extends BaseController { @GetMapping("/tree") @ResponseBody - public List tree() { + public List tree(Integer type) { Long deptId = ShiroUtils.getSysUser().getDept().getParentId(); - return goodsCategoryService.tree(deptId); + return goodsCategoryService.tree(deptId, type); } /** diff --git a/ghy-admin/src/main/java/com/ghy/web/controller/goods/GoodsDeptCategoryController.java b/ghy-admin/src/main/java/com/ghy/web/controller/goods/GoodsDeptCategoryController.java index 1947bc7f..54fa8707 100644 --- a/ghy-admin/src/main/java/com/ghy/web/controller/goods/GoodsDeptCategoryController.java +++ b/ghy-admin/src/main/java/com/ghy/web/controller/goods/GoodsDeptCategoryController.java @@ -11,12 +11,12 @@ import com.ghy.common.utils.ShiroUtils; import com.ghy.goods.domain.DeptGoodsCategory; import com.ghy.goods.service.DeptGoodsCategoryService; import com.ghy.web.pojo.vo.AppCategoryRequest; -import org.apache.commons.lang3.StringUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; +import org.springframework.web.servlet.ModelAndView; import javax.annotation.Resource; import java.util.ArrayList; @@ -33,17 +33,23 @@ public class GoodsDeptCategoryController extends BaseController { @RequiresPermissions("goods:deptcategory:view") @GetMapping() - public String DeptGoodsCategory() { + public String deptGoodsCategory() { return PREFIX + "/deptcategory"; } - @RequiresPermissions("goods:deptcategory:add") - @GetMapping("/add/1") - public String add() { + @GetMapping("/add/{type}") + public String add(@PathVariable("type") Integer type, ModelMap mmap) { + mmap.put("type", type); return PREFIX + "/add"; } + @RequiresPermissions("goods:deptservecategory:view") + @GetMapping("serve") + public String deptServeCategory() { + return PREFIX + "/deptservecategory"; + } + @RequiresPermissions("goods:deptcategory:add") @PostMapping("/add") @ResponseBody @@ -58,7 +64,7 @@ public class GoodsDeptCategoryController extends BaseController { public AjaxResult listByStep(@RequestBody DeptGoodsCategory deptGoodsCategory) { try { return AjaxResult.success(deptGoodsCategoryService.listByStep(deptGoodsCategory)); - }catch (Exception e){ + } catch (Exception e) { logger.error(e.getMessage()); return AjaxResult.error(ExceptionUtil.getExceptionMessage(e)); } @@ -68,7 +74,7 @@ public class GoodsDeptCategoryController extends BaseController { @PostMapping("/app/listByStep") @ResponseBody public AjaxResult appListByStep(@RequestBody DeptGoodsCategory deptGoodsCategory) { - List resList = new ArrayList(); + List resList = new ArrayList<>(); try { if (deptGoodsCategory.getIsAllNode() == null || !deptGoodsCategory.getIsAllNode()) { List list = deptGoodsCategoryService.listByStep(deptGoodsCategory); @@ -81,7 +87,7 @@ public class GoodsDeptCategoryController extends BaseController { } } return AjaxResult.success(resList); - }catch (Exception e){ + } catch (Exception e) { logger.error(e.getMessage()); return AjaxResult.error(ExceptionUtil.getExceptionMessage(e)); } @@ -132,11 +138,11 @@ public class GoodsDeptCategoryController extends BaseController { @PostMapping("/app/category") @ResponseBody - public AjaxResult appCategory(@RequestBody AppCategoryRequest request){ + public AjaxResult appCategory(@RequestBody AppCategoryRequest request) { try { return AjaxResult.success(); - }catch (Exception e){ + } catch (Exception e) { e.printStackTrace(); return AjaxResult.error(e.getMessage()); } diff --git a/ghy-admin/src/main/resources/templates/goods/deptcategory/add.html b/ghy-admin/src/main/resources/templates/goods/deptcategory/add.html index 7d04fa75..3477efa6 100644 --- a/ghy-admin/src/main/resources/templates/goods/deptcategory/add.html +++ b/ghy-admin/src/main/resources/templates/goods/deptcategory/add.html @@ -25,8 +25,11 @@ + + \ No newline at end of file diff --git a/ghy-goods/src/main/java/com/ghy/goods/domain/DeptGoodsCategory.java b/ghy-goods/src/main/java/com/ghy/goods/domain/DeptGoodsCategory.java index 991545a9..78d946a5 100644 --- a/ghy-goods/src/main/java/com/ghy/goods/domain/DeptGoodsCategory.java +++ b/ghy-goods/src/main/java/com/ghy/goods/domain/DeptGoodsCategory.java @@ -48,6 +48,9 @@ public class DeptGoodsCategory extends GoodsCategory { @Excel(name = "截留金额", cellType = Excel.ColumnType.STRING) private BigDecimal retainMoney; + @Excel(name = "类别类型. 1.服务类 2.商品类", cellType = Excel.ColumnType.STRING) + private Integer type; + private Long parentCategoryId; private List child; 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 eb56a2eb..8301b671 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,12 +1,10 @@ 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.Collection; import java.util.List; -import java.util.Set; /** * @author clunt @@ -81,6 +79,7 @@ public interface GoodsCategoryService { * 获取所有的商品类目,并标记出当前公司拥有的类目 * * @param deptId 分公司ID + * @param type 类目类型 */ - List tree(Long deptId); + List tree(Long deptId, Integer type); } diff --git a/ghy-goods/src/main/java/com/ghy/goods/service/impl/DeptGoodsCategoryServiceImpl.java b/ghy-goods/src/main/java/com/ghy/goods/service/impl/DeptGoodsCategoryServiceImpl.java index 72105923..78beade6 100644 --- a/ghy-goods/src/main/java/com/ghy/goods/service/impl/DeptGoodsCategoryServiceImpl.java +++ b/ghy-goods/src/main/java/com/ghy/goods/service/impl/DeptGoodsCategoryServiceImpl.java @@ -9,9 +9,11 @@ import com.ghy.goods.domain.DeptGoodsCategory; import com.ghy.goods.domain.GoodsCategory; import com.ghy.goods.mapper.DeptGoodsCategoryMapper; import com.ghy.goods.service.DeptGoodsCategoryService; +import com.ghy.goods.service.GoodsCategoryService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.Assert; import javax.annotation.Resource; import java.util.*; @@ -25,6 +27,8 @@ import java.util.stream.Collectors; @Service public class DeptGoodsCategoryServiceImpl implements DeptGoodsCategoryService { + @Resource + private GoodsCategoryService goodsCategoryService; @Resource private DeptGoodsCategoryMapper deptGoodsCategoryMapper; @@ -107,9 +111,11 @@ public class DeptGoodsCategoryServiceImpl implements DeptGoodsCategoryService { @Override @Transactional(rollbackFor = Exception.class) public AjaxResult batchAdd(Long parentId, Long[] checked) { + GoodsCategory goodsCategory = goodsCategoryService.selectById(checked[0]); + Assert.notNull(goodsCategory, "不存在该类目: " + checked[0]); List oldList = deptGoodsCategoryMapper.selectByDeptId(parentId); - Map oldMap = oldList.stream().collect(Collectors.toMap(GoodsCategory::getGoodsCategoryId, - DeptGoodsCategory::getDeptGoodsCategoryId)); + Map oldMap = oldList.stream().filter(x -> x.getType().equals(goodsCategory.getType())) + .collect(Collectors.toMap(GoodsCategory::getGoodsCategoryId, DeptGoodsCategory::getDeptGoodsCategoryId)); HashSet newSet = new HashSet<>(Arrays.asList(checked)); Set intersection = oldList.stream().map(DeptGoodsCategory::getGoodsCategoryId).collect(Collectors.toSet()); intersection.addAll(Arrays.asList(checked)); 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 01e6ce00..c494f3b8 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 @@ -92,8 +92,10 @@ public class GoodsCategoryServiceImpl implements GoodsCategoryService { } @Override - public List tree(Long deptId) { - List goodsCategoryList = goodsCategoryMapper.selectGoodsCategoryList(null); + public List tree(Long deptId, Integer type) { + GoodsCategory goodsCategory = new GoodsCategory(); + goodsCategory.setType(type); + List goodsCategoryList = goodsCategoryMapper.selectGoodsCategoryList(goodsCategory); DeptGoodsCategory category = new DeptGoodsCategory(); category.setDeptId(deptId); Set usedSet = deptGoodsCategoryService.list(category).stream() diff --git a/ghy-goods/src/main/resources/mapper/goods/DeptGoodsCategoryMapper.xml b/ghy-goods/src/main/resources/mapper/goods/DeptGoodsCategoryMapper.xml index 0baef0f4..172f5c3b 100644 --- a/ghy-goods/src/main/resources/mapper/goods/DeptGoodsCategoryMapper.xml +++ b/ghy-goods/src/main/resources/mapper/goods/DeptGoodsCategoryMapper.xml @@ -140,6 +140,9 @@ AND dgc.is_hot = #{isHot} + + AND gc.type = #{type} + @@ -154,7 +157,7 @@ diff --git a/ghy-goods/src/main/resources/mapper/goods/GoodsCategoryMapper.xml b/ghy-goods/src/main/resources/mapper/goods/GoodsCategoryMapper.xml index e1aee2aa..c1e7262d 100644 --- a/ghy-goods/src/main/resources/mapper/goods/GoodsCategoryMapper.xml +++ b/ghy-goods/src/main/resources/mapper/goods/GoodsCategoryMapper.xml @@ -39,6 +39,9 @@ AND status = #{status} + + AND type = #{type} +