From 1b3d3358a872d80f3c88b2ff9dff530b1a519f06 Mon Sep 17 00:00:00 2001 From: wangjinlei <751475802@qq.com> Date: Wed, 20 Sep 2023 17:37:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ShopProductController.java | 48 +++++++++++++++++-- .../book/entity/ShopProductEntity.java | 3 ++ 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/peanut/modules/book/controller/ShopProductController.java b/src/main/java/com/peanut/modules/book/controller/ShopProductController.java index 9e7a2c05..128c8317 100644 --- a/src/main/java/com/peanut/modules/book/controller/ShopProductController.java +++ b/src/main/java/com/peanut/modules/book/controller/ShopProductController.java @@ -34,8 +34,12 @@ public class ShopProductController { private BuyOrderDetailService buyOrderDetailService; @Autowired private BookService bookService; - @Autowired - private ShopProudictBookService shopProudictBookService; + @Autowired + private ShopProudictBookService shopProudictBookService; + @Autowired + private ShopProductToLabelService shopProductToLabelService; + @Autowired + private ShopProductLabelService shopProductLabelService; /** * 精选商品 列表 @@ -275,11 +279,25 @@ public class ShopProductController { booklist.add(String.valueOf(bookId)); list.add(byId); } + + //添加获取标签逻辑 + List shopProductToLabelEntities = shopProductToLabelService.getBaseMapper().selectList(new QueryWrapper() + .eq("product_id",productId).eq("del_flag",0)); + List labelList = new ArrayList(); + for (ShopProductToLabelEntity sp : shopProductToLabelEntities){ + labelList.add(sp.getSplId()); + } + + shopProductEntity.setBookidsimages(list); shopProductEntity.setBookids(booklist); shopProductEntity.setShoproudIds(bookIdlist); - return R.ok().put("shopProduct", shopProductEntity); + return R.ok().put("shopProduct", shopProductEntity).put("labels",labelList); } + + + + /** * 根据传入商品id反向查询图书id,然后查询图书id下包含的商品 * @param productId @@ -380,6 +398,30 @@ public class ShopProductController { } } + + //对于标签的增和删 + List shopProductToLabelEntities_now = shopProductToLabelService.getBaseMapper().selectList(new QueryWrapper() + .eq("product_id", productId)); + List m_spl_ids = shopProduct.getShoproudLabels(); + //删除 + for (ShopProductToLabelEntity sn:shopProductToLabelEntities_now){ + if(!m_spl_ids.contains(sn.getSplId())){ + shopProductToLabelService.removeById(sn.getPtlId()); + } + } + //添加 + for (String m:m_spl_ids){ + Integer spl_id = Integer.valueOf(m); + ShopProductToLabelEntity byId = shopProductToLabelService.getBaseMapper().selectOne(new QueryWrapper() + .eq("spl_id",spl_id).eq("product_id",productId)); + if(byId==null){ + ShopProductToLabelEntity shopProductToLabelEntity = new ShopProductToLabelEntity(); + shopProductToLabelEntity.setProductId(productId); + shopProductToLabelEntity.setSplId(spl_id); + shopProductToLabelService.save(shopProductToLabelEntity); + } + } + shopProductService.updateById(shopProduct); return R.ok(); } diff --git a/src/main/java/com/peanut/modules/book/entity/ShopProductEntity.java b/src/main/java/com/peanut/modules/book/entity/ShopProductEntity.java index 83099b29..683f156c 100644 --- a/src/main/java/com/peanut/modules/book/entity/ShopProductEntity.java +++ b/src/main/java/com/peanut/modules/book/entity/ShopProductEntity.java @@ -163,6 +163,9 @@ public class ShopProductEntity implements Serializable { @TableField(exist = false) private List shoproudIds; + @TableField(exist = false) + private List shoproudLabels; + // private Object bookidsimages; //