From 94e6340c08240a117d8139bd143fc9fcbc5ad54b Mon Sep 17 00:00:00 2001 From: wayn <1669738430@qq.com> Date: Sat, 5 Dec 2020 02:08:14 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=90=8E=E5=8F=B0=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E6=A0=8F=E7=9B=AE=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 完善菜单 --- .../api/controller/shop/ColumnController.java | 42 ++++++++++++++++++ .../core/domain/shop/ColumnGoodsRelation.java | 4 +- .../common/core/mapper/shop/GoodsMapper.java | 4 ++ .../core/service/shop/IGoodsService.java | 8 +++- .../service/shop/impl/GoodsServiceImpl.java | 10 +++++ .../resources/mapper/shop/ColumnMapper.xml | 6 +++ .../resources/mapper/shop/GoodsMapper.xml | 44 +++++++++++++++++++ 7 files changed, 115 insertions(+), 3 deletions(-) diff --git a/waynboot-admin-api/src/main/java/com/wayn/admin/api/controller/shop/ColumnController.java b/waynboot-admin-api/src/main/java/com/wayn/admin/api/controller/shop/ColumnController.java index 8142d4c..991bd84 100644 --- a/waynboot-admin-api/src/main/java/com/wayn/admin/api/controller/shop/ColumnController.java +++ b/waynboot-admin-api/src/main/java/com/wayn/admin/api/controller/shop/ColumnController.java @@ -1,9 +1,15 @@ package com.wayn.admin.api.controller.shop; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.wayn.common.base.controller.BaseController; import com.wayn.common.core.domain.shop.Column; +import com.wayn.common.core.domain.shop.ColumnGoodsRelation; +import com.wayn.common.core.domain.shop.Goods; +import com.wayn.common.core.service.shop.IColumnGoodsRelationService; import com.wayn.common.core.service.shop.IColumnService; +import com.wayn.common.core.service.shop.IGoodsService; import com.wayn.common.util.R; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; @@ -11,6 +17,7 @@ import org.springframework.web.bind.annotation.*; import java.util.Date; import java.util.List; +import java.util.stream.Collectors; @RestController @RequestMapping("shop/column") @@ -19,6 +26,12 @@ public class ColumnController extends BaseController { @Autowired private IColumnService iColumnService; + @Autowired + private IColumnGoodsRelationService iColumnGoodsRelationService; + + @Autowired + private IGoodsService iGoodsService; + @GetMapping("/list") public R list(Column column) { Page page = getPage(); @@ -47,4 +60,33 @@ public class ColumnController extends BaseController { return R.result(iColumnService.removeByIds(columnIds)); } + @GetMapping("bindGoodsList") + public R bindGoodsList(Goods goods, Long columnId) { + Page page = getPage(); + List goodsRelationList = iColumnGoodsRelationService.list(new QueryWrapper() + .eq("column_id", columnId)); + List columnGoodsIds = goodsRelationList.stream().map(ColumnGoodsRelation::getGoodsId).collect(Collectors.toList()); + IPage listPage = iGoodsService.listColumnBindGoodsPage(page, goods, columnGoodsIds); + return R.success().add("page", listPage); + } + + @GetMapping("unBindGoodsList") + public R unBindGoodsList(Goods goods, Long columnId) { + Page page = getPage(); + List goodsRelationList = iColumnGoodsRelationService.list(new QueryWrapper() + .eq("column_id", columnId)); + List columnGoodsIds = goodsRelationList.stream().map(ColumnGoodsRelation::getGoodsId).collect(Collectors.toList()); + IPage listPage = iGoodsService.listColumnUnBindGoodsPage(page, goods, columnGoodsIds); + return R.success().add("page", listPage); + } + + @PostMapping("goods") + public R addGoods(@RequestBody ColumnGoodsRelation columnGoodsRelation) { + return R.result(iColumnGoodsRelationService.save(columnGoodsRelation)); + } + + @DeleteMapping("goods/{id}") + public R deleteGoods(@PathVariable Long id) { + return R.result(iColumnGoodsRelationService.removeById(id)); + } } diff --git a/waynboot-common/src/main/java/com/wayn/common/core/domain/shop/ColumnGoodsRelation.java b/waynboot-common/src/main/java/com/wayn/common/core/domain/shop/ColumnGoodsRelation.java index 51e1323..c723451 100644 --- a/waynboot-common/src/main/java/com/wayn/common/core/domain/shop/ColumnGoodsRelation.java +++ b/waynboot-common/src/main/java/com/wayn/common/core/domain/shop/ColumnGoodsRelation.java @@ -29,12 +29,12 @@ public class ColumnGoodsRelation implements Serializable { /** * 栏目ID */ - private Integer columnId; + private Long columnId; /** * 商品ID */ - private Integer goodsId; + private Long goodsId; } diff --git a/waynboot-common/src/main/java/com/wayn/common/core/mapper/shop/GoodsMapper.java b/waynboot-common/src/main/java/com/wayn/common/core/mapper/shop/GoodsMapper.java index 826e7bd..a503909 100644 --- a/waynboot-common/src/main/java/com/wayn/common/core/mapper/shop/GoodsMapper.java +++ b/waynboot-common/src/main/java/com/wayn/common/core/mapper/shop/GoodsMapper.java @@ -23,4 +23,8 @@ public interface GoodsMapper extends BaseMapper { IPage selectGoodsListPageByl2CateId(Page page, List cateList); List searchResult(Page page, SearchVO searchVO); + + IPage selectColumnBindGoodsListPage(Page page, Goods goods, List columnGoodsIds); + + IPage selectColumnUnBindGoodsListPage(Page page, Goods goods, List columnGoodsIds); } diff --git a/waynboot-common/src/main/java/com/wayn/common/core/service/shop/IGoodsService.java b/waynboot-common/src/main/java/com/wayn/common/core/service/shop/IGoodsService.java index e8163fd..935a3b3 100644 --- a/waynboot-common/src/main/java/com/wayn/common/core/service/shop/IGoodsService.java +++ b/waynboot-common/src/main/java/com/wayn/common/core/service/shop/IGoodsService.java @@ -31,6 +31,10 @@ public interface IGoodsService extends IService { */ IPage listPage(Page page, Goods goods); + IPage listColumnBindGoodsPage(Page page, Goods goods, List columnGoodsIds); + + IPage listColumnUnBindGoodsPage(Page page, Goods goods, List columnGoodsIds); + /** * 获取商品详情(包含货品,规格,属性,分类) * @@ -65,6 +69,7 @@ public interface IGoodsService extends IService { /** * 更新商品相关对象 + * * @param goodsSaveRelatedVO 商品保存关联VO对象 * @return R */ @@ -72,7 +77,8 @@ public interface IGoodsService extends IService { /** * 根据二级分类Id集合获取对应商品 - * @param page 分页对象 + * + * @param page 分页对象 * @param l2cateList 二级分类Id集合 * @return r */ diff --git a/waynboot-common/src/main/java/com/wayn/common/core/service/shop/impl/GoodsServiceImpl.java b/waynboot-common/src/main/java/com/wayn/common/core/service/shop/impl/GoodsServiceImpl.java index 548aa7a..ecbfc44 100644 --- a/waynboot-common/src/main/java/com/wayn/common/core/service/shop/impl/GoodsServiceImpl.java +++ b/waynboot-common/src/main/java/com/wayn/common/core/service/shop/impl/GoodsServiceImpl.java @@ -55,6 +55,16 @@ public class GoodsServiceImpl extends ServiceImpl implements return goodsMapper.selectGoodsListPage(page, goods); } + @Override + public IPage listColumnBindGoodsPage(Page page, Goods goods, List columnGoodsIds) { + return goodsMapper.selectColumnBindGoodsListPage(page, goods, columnGoodsIds); + } + + @Override + public IPage listColumnUnBindGoodsPage(Page page, Goods goods, List columnGoodsIds) { + return goodsMapper.selectColumnUnBindGoodsListPage(page, goods, columnGoodsIds); + } + @Override public Map getGoodsInfoById(Long goodsId) { Goods goods = goodsMapper.selectById(goodsId); diff --git a/waynboot-common/src/main/resources/mapper/shop/ColumnMapper.xml b/waynboot-common/src/main/resources/mapper/shop/ColumnMapper.xml index 4765028..1307f0c 100644 --- a/waynboot-common/src/main/resources/mapper/shop/ColumnMapper.xml +++ b/waynboot-common/src/main/resources/mapper/shop/ColumnMapper.xml @@ -24,6 +24,12 @@ AND name like concat('%', #{column.name}, '%') + + and DATE_FORMAT(create_time,'%Y-%m-%d') = ]]> DATE_FORMAT(#{column.startTime},'%Y-%m-%d') + + + and DATE_FORMAT(create_time,'%Y-%m-%d') DATE_FORMAT(#{column.endTime},'%Y-%m-%d') + order by create_time desc diff --git a/waynboot-common/src/main/resources/mapper/shop/GoodsMapper.xml b/waynboot-common/src/main/resources/mapper/shop/GoodsMapper.xml index 3f5a4ec..90c8dd8 100644 --- a/waynboot-common/src/main/resources/mapper/shop/GoodsMapper.xml +++ b/waynboot-common/src/main/resources/mapper/shop/GoodsMapper.xml @@ -93,4 +93,48 @@ + + + +