From d8aa612cb1ff3e819412fd6c88f6821ccbdebe09 Mon Sep 17 00:00:00 2001
From: huanghongfa <huanghongfa123456>
Date: 星期二, 20 四月 2021 19:56:42 +0800
Subject: [PATCH] bug修复

---
 springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComShopGoodsServiceImpl.java |   65 +++++++++++++++++++-------------
 1 files changed, 39 insertions(+), 26 deletions(-)

diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComShopGoodsServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComShopGoodsServiceImpl.java
index fee1058..36c9e4b 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComShopGoodsServiceImpl.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComShopGoodsServiceImpl.java
@@ -19,11 +19,10 @@
 import com.panzhihua.service_community.dao.ComShopGoodsAttrDAO;
 import com.panzhihua.common.model.vos.shop.ComShopGoodsAttrVO;
 import com.panzhihua.common.model.vos.shop.ComShopGoodsVO;
-import com.panzhihua.common.model.vos.shop.ComShopStoreVO;
+import com.panzhihua.common.model.vos.shop.PageShopStoreVO;
 import com.panzhihua.service_community.dao.ComShopGoodsAttrDAO;
 import com.panzhihua.common.model.dtos.shop.PageComShopGoodsDTO;
-import com.panzhihua.common.model.vos.shop.ComShopStoreVO;
-import com.panzhihua.common.model.vos.shop.ShopGoodsVO;
+import com.panzhihua.common.model.vos.shop.PageShopStoreVO;
 import com.panzhihua.service_community.dao.ComShopGoodsDAO;
 import com.panzhihua.service_community.model.dos.ComShopGoodsAttrDO;
 import com.panzhihua.service_community.dao.ComShopStoreDAO;
@@ -106,7 +105,7 @@
         comShopStoreVOIPage.getRecords().forEach(vo -> {
             List<ComShopGoodsAttrDO> goodsAttrDOs = goodsAttrDOS.stream().filter(goodsAttr -> goodsAttr.getGoodsId().equals(vo.getId())).collect(Collectors.toList());
             ArrayList<AddShopGoodsAttrVO> goodsAttrVOList = Lists.newArrayList();
-            for (ComShopGoodsAttrDO oneGoodsAttrDO :goodsAttrDOs) {
+            for (ComShopGoodsAttrDO oneGoodsAttrDO : goodsAttrDOs) {
                 AddShopGoodsAttrVO goodsAttrVO = new AddShopGoodsAttrVO();
                 goodsAttrVO.setGoodsAttrId(oneGoodsAttrDO.getId());
                 goodsAttrVO.setGoodsAttr(oneGoodsAttrDO.getGoodsAttr());
@@ -161,68 +160,82 @@
 
     @Override
     public R deleteShopGoods(Long[] id) {
-        ComShopGoodsDO storeDO = new ComShopGoodsDO();
-        storeDO.setDeleteStatus(2);
-        LambdaQueryWrapper<ComShopGoodsDO> query = new LambdaQueryWrapper<ComShopGoodsDO>().eq(ComShopGoodsDO::getId, id);
-        int update = this.baseMapper.update(storeDO, query);
-        return update > 0 ? R.ok() : R.fail();
+        LambdaQueryWrapper<ComShopGoodsDO> query = new LambdaQueryWrapper<ComShopGoodsDO>().in(ComShopGoodsDO::getId, id);
+        List<ComShopGoodsDO> comShopGoodsDOS = this.baseMapper.selectList(query);
+        for (ComShopGoodsDO one : comShopGoodsDOS) {
+            one.setDeleteStatus(2);
+            this.baseMapper.updateById(one);
+        }
+        return R.ok();
     }
 
     @Override
     public R changeStatus(Long id, Integer status) {
         ComShopGoodsDO shopGoodsDO = this.baseMapper.selectById(id);
-        if(shopGoodsDO==null){
+        if (shopGoodsDO == null) {
             return R.fail("id有误!");
         }
         shopGoodsDO.setStatus(status);
         this.baseMapper.updateById(shopGoodsDO);
         return R.ok();
     }
+
     /**
      * 分页查询商品列表
-     * @param comShopGoodsDTO   请求参数
-     * @return  商品列表
+     *
+     * @param comShopGoodsDTO 请求参数
+     * @return 商品列表
      */
     @Override
     public R pageShopGoods(ComShopGoodsDTO comShopGoodsDTO){
         Page page = new Page<>(comShopGoodsDTO.getPageNum(),comShopGoodsDTO.getPageSize());
-        return R.ok(this.baseMapper.pageShopGoods(page,comShopGoodsDTO));
+        IPage<ComShopGoodsVO> goodsVOIPage = this.baseMapper.pageShopGoodByApps(page,comShopGoodsDTO);
+        if(!goodsVOIPage.getRecords().isEmpty()){
+            goodsVOIPage.getRecords().forEach(goodsVo -> {
+                List<ComShopGoodsAttrVO> goodsAttrList = shopGoodsAttrDAO.getGoodsAttr(goodsVo.getId());
+                if(!goodsAttrList.isEmpty()){
+                    goodsVo.setGoodsAttrList(goodsAttrList);
+                }
+            });
+        }
+        return R.ok(goodsVOIPage);
     }
 
     /**
      * 根据商品id查询商品信息
-     * @param goodsId   商品id
-     * @return  商品信息
+     *
+     * @param goodsId 商品id
+     * @return 商品信息
      */
     @Override
-    public R shopGoodsDetail(Long goodsId){
+    public R shopGoodsDetail(Long goodsId) {
 
         //根据id查询商品信息
         ComShopGoodsDO goodsDO = this.baseMapper.selectById(goodsId);
-        if(goodsDO == null || goodsDO.getDeleteStatus().equals(ComShopGoodsDO.deleteStatus.yes)){
-            return R.fail(403,"商品不存在");
+        if (goodsDO == null || goodsDO.getDeleteStatus().equals(ComShopGoodsDO.deleteStatus.yes)) {
+            return R.fail(403, "商品不存在");
         }
-        if(!goodsDO.getStatus().equals(ComShopGoodsDO.status.sell)){
-            return R.fail(405,"商品已下架");
+        if (!goodsDO.getStatus().equals(ComShopGoodsDO.status.sell)) {
+            return R.fail(405, "商品已下架");
         }
 
         //根据商品id查询商品规格信息
         List<ComShopGoodsAttrVO> goodsAttrList = new ArrayList<>();
-        List<ComShopGoodsAttrDO> goodsAttrDOS = shopGoodsAttrDAO.selectList(new QueryWrapper<ComShopGoodsAttrDO>().eq("goods_id",goodsId));
-        goodsAttrDOS.forEach(attrDO->{
+        List<ComShopGoodsAttrDO> goodsAttrDOS = shopGoodsAttrDAO.selectList(new QueryWrapper<ComShopGoodsAttrDO>().eq("goods_id", goodsId));
+        goodsAttrDOS.forEach(attrDO -> {
             ComShopGoodsAttrVO goodsAttrVO = new ComShopGoodsAttrVO();
-            BeanUtils.copyProperties(attrDO,goodsAttrVO);
+            BeanUtils.copyProperties(attrDO, goodsAttrVO);
             goodsAttrList.add(goodsAttrVO);
         });
 
         //查询商品店铺信息
         ComShopStoreDO shopStoreDO = shopStoreDAO.selectById(goodsDO.getStoreId());
-        ComShopStoreVO shopStoreVO = new ComShopStoreVO();
-        BeanUtils.copyProperties(shopStoreDO,shopStoreVO);
+        PageShopStoreVO shopStoreVO = new PageShopStoreVO();
+        BeanUtils.copyProperties(shopStoreDO, shopStoreVO);
 
         //设置值
         ComShopGoodsVO shopGoods = new ComShopGoodsVO();
-        BeanUtils.copyProperties(goodsDO,shopGoods);
+        BeanUtils.copyProperties(goodsDO, shopGoods);
         shopGoods.setGoodsAttrList(goodsAttrList);
         shopGoods.setShopStoreVO(shopStoreVO);
         return R.ok(shopGoods);

--
Gitblit v1.7.1