From 4f5e96cb1e6540a35ce98687148e01403b5b1c2e Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期四, 21 九月 2023 17:59:38 +0800
Subject: [PATCH] 属性对比

---
 server/service/src/main/java/com/doumee/service/business/impl/GoodsServiceImpl.java |   87 +++++++++++++++++++++++++------------------
 1 files changed, 51 insertions(+), 36 deletions(-)

diff --git a/server/service/src/main/java/com/doumee/service/business/impl/GoodsServiceImpl.java b/server/service/src/main/java/com/doumee/service/business/impl/GoodsServiceImpl.java
index 553ced0..23499bd 100644
--- a/server/service/src/main/java/com/doumee/service/business/impl/GoodsServiceImpl.java
+++ b/server/service/src/main/java/com/doumee/service/business/impl/GoodsServiceImpl.java
@@ -18,6 +18,8 @@
 import com.doumee.dao.business.join.GoodsJoinMapper;
 import com.doumee.dao.business.model.*;
 import com.doumee.dao.business.model.dto.*;
+import com.doumee.dao.system.model.SystemDepartment;
+import com.doumee.service.CateParamSelectService;
 import com.doumee.service.business.BaseDataService;
 import com.doumee.service.business.GoodsService;
 import com.github.yulichang.wrapper.MPJLambdaWrapper;
@@ -45,6 +47,7 @@
 import java.net.URLEncoder;
 import java.nio.charset.Charset;
 import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * 鍟嗗搧淇℃伅琛⊿ervice瀹炵幇
@@ -66,6 +69,8 @@
     @Autowired
     private CategoryMapper categoryMapper;
     @Autowired
+    private BaseCategoryMapper baseCategoryMapper;
+    @Autowired
     private CateAttrMapper cateAttrMapper;
     @Autowired
     private CateParamMapper cateParamMapper;
@@ -81,8 +86,10 @@
 
     @Autowired
     private GoodsJoinMapper goodsJoinMapper;
+
+    @Lazy
     @Autowired
-    private CateParamSelectMapper cateParamSelectMapper;
+    private CateParamSelectService cateParamSelectService;
 
     @Autowired
     private RedisTemplate redisTemplate;
@@ -158,6 +165,11 @@
         if(category.getPlatCateId() == null){
             throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝璇峰墠寰�銆愮被鍒鐞嗐�戝厛鍏宠仈骞冲彴绫诲埆锛�");
         }
+        BaseCategory baseCategory = baseCategoryMapper.selectById(category.getPlatCateId());
+        if(baseCategory == null){
+            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝璇峰墠寰�銆愮被鍒鐞嗐�戝厛鍏宠仈骞冲彴绫诲埆锛�");
+        }
+
         BaseGoods bp = new BaseGoods();
         bp.setCategoryId(category.getPlatCateId());
         bp.setIsdeleted(Constants.ZERO);
@@ -185,6 +197,9 @@
         try{
             for(BaseGoods model : goodsList){
                 //閬嶅巻骞冲彴鍟嗗搧淇℃伅锛岃繘琛屽晢鍝佷俊鎭悓姝�
+                //鍒嗙被鍔犱环绯绘暟
+
+                model.setCateRatePrice(baseCategory.getPriceRate());
                 Goods goods = initGoodsPlatParam(user,model,param);
                 if(goods == null){
                     continue;
@@ -201,6 +216,7 @@
             if(goodsParamList.size()>0){
                 goodsParamMapper.insertBatch(goodsParamList);
             }
+            cateParamSelectService.dealCateParamSelect();
         }catch (Exception e){
            e.printStackTrace();
         }finally {
@@ -310,11 +326,11 @@
             throw new BusinessException(ResponseStatus.DATA_ERRO.getCode(),"鏁版嵁寮傚父璇峰埛鏂伴噸璇�");
         }
         //濡傛灉娌℃湁閰嶇疆鍏ユ墜浠凤紝瀹夎鍔犱环绯绘暟鏉ヨ绠�
-//        if(model.getCateRatePrice()==null){
-//            model.setCateRatePrice(systemDictDataBiz.getGoodsPriceRate());
-//        }
+        if(model.getCateRatePrice()==null){
+            model.setCateRatePrice(systemDictDataBiz.getGoodsPriceRate());
+        }
         //杩斿洖 .multiply(model.getCateRatePrice())
-        return (Constants.formatBigdecimal(model.getPrice()).multiply(param.getRate())).setScale(0,BigDecimal.ROUND_CEILING);
+        return (Constants.formatBigdecimal(model.getPrice()).multiply(model.getCateRatePrice()).multiply(param.getRate())).setScale(0,BigDecimal.ROUND_CEILING);
 
     }
 
@@ -391,7 +407,10 @@
         if (CollectionUtils.isEmpty(ids)) {
             return;
         }
-        goodsMapper.deleteBatchIds(ids);
+        for(Integer id : ids){
+            deleteById(id);
+        }
+//        goodsMapper.deleteBatchIds(ids);
     }
 
     @Override
@@ -633,13 +652,7 @@
                 Goods::getPrice,goods.getSPrice(),goods.getEPrice());
         queryWrapper.orderByDesc(Goods::getId);
         List<Goods> goodsList = goodsJoinMapper.selectJoinList(Goods.class,queryWrapper);
-        String prefixUrl = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()
-                + systemDictDataBiz.queryByCode(Constants.OSS, Constants.GOODS_IMG).getCode();
-        goodsList.forEach(i->{
-            i.setPrefixUrl(prefixUrl);
-            i.setMultifileList(multifileMapper.selectList(new QueryWrapper<Multifile>().eq("OBJ_ID",i.getId()).orderByAsc(" SORTNUM ")));
-            i.setGoodsParamList(goodsParamMapper.selectList(new QueryWrapper<GoodsParam>().eq("GOODS_ID",i.getId()).orderByAsc(" SORTNUM ")));
-        });
+        this.dealGoodsMsg(goodsList);
         return goodsList;
     }
 
@@ -1080,20 +1093,33 @@
                 .apply(!Objects.isNull(pageWrap.getModel()) && !Objects.isNull(pageWrap.getModel().getEPrice()), "  t.PRICE <=  "+pageWrap.getModel().getEPrice()+" ");
         queryWrapper.orderByDesc(Goods::getId);
         IPage<Goods> goodsIPage =  goodsJoinMapper.selectJoinPage(page, Goods.class, queryWrapper);
-        String prefixUrl = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()
-                + systemDictDataBiz.queryByCode(Constants.OSS, Constants.GOODS_IMG).getCode();
-        goodsIPage.getRecords().forEach(i->{
-            i.setCategoryImgurl(systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()
-                    + systemDictDataBiz.queryByCode(Constants.OSS, Constants.CATEGORY_IMG).getCode() + i.getCategoryImgurl());
-            i.setPrefixUrl(prefixUrl);
-            i.setMultifileList(multifileMapper.selectList(new QueryWrapper<Multifile>().eq("OBJ_ID",i.getId()).orderByAsc(" SORTNUM ")));
-            i.setGoodsParamList(goodsParamMapper.selectList(new QueryWrapper<GoodsParam>()
-                    .eq("GOODS_ID",i.getId())
-                    .orderByAsc(" SORTNUM ")));
-        });
+        if(!Objects.isNull(goodsIPage.getRecords())&&goodsIPage.getRecords().size()>Constants.ZERO){
+            this.dealGoodsMsg(goodsIPage.getRecords());
+        }
         return PageData.from(goodsIPage);
     }
 
+
+
+    public void dealGoodsMsg(List<Goods> goodsList){
+        String prefixUrl = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()
+                + systemDictDataBiz.queryByCode(Constants.OSS, Constants.GOODS_IMG).getCode();
+        String prefixUrlCategory = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()
+                + systemDictDataBiz.queryByCode(Constants.OSS, Constants.CATEGORY_IMG).getCode();
+        List<Integer> integerList = goodsList.stream().map(Goods::getId).collect(Collectors.toList());
+
+        List<Multifile> mFileList = multifileMapper.selectList(new QueryWrapper<Multifile>()
+                .in("OBJ_ID",integerList).eq("TYPE",Constants.ZERO));
+        List<GoodsParam> goodsParamList = goodsParamMapper.selectList(new QueryWrapper<GoodsParam>()
+                    .in("GOODS_ID",integerList)
+                    .orderByAsc(" SORTNUM "));
+        goodsList.forEach(i->{
+            i.setCategoryImgurl(prefixUrlCategory + i.getCategoryImgurl());
+            i.setPrefixUrl(prefixUrl);
+            i.setMultifileList(mFileList.stream().filter(s -> s.getObjId().equals(i.getId())).collect(Collectors.toList()));
+            i.setGoodsParamList(goodsParamList.stream().filter(s -> s.getGoodsId().equals(i.getId())).collect(Collectors.toList()));
+        });
+    }
 
     @Override
     public List<Goods> findListForH5(GoodsRequest goodsRequest) {
@@ -1126,18 +1152,7 @@
                 .apply(!Objects.isNull(goodsRequest) && !Objects.isNull(goodsRequest.getEPrice()), "  t.PRICE <=  "+goodsRequest.getEPrice()+" ");
         queryWrapper.orderByDesc(Goods::getId);
         List<Goods> goodsList = goodsJoinMapper.selectJoinList(Goods.class,queryWrapper);
-        String prefixUrl = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()
-                + systemDictDataBiz.queryByCode(Constants.OSS, Constants.GOODS_IMG).getCode();
-        goodsList.forEach(i->{
-            i.setCategoryImgurl(systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()
-                    + systemDictDataBiz.queryByCode(Constants.OSS, Constants.CATEGORY_IMG).getCode() + i.getCategoryImgurl());
-            i.setPrefixUrl(prefixUrl);
-            i.setMultifileList(multifileMapper.selectList(new QueryWrapper<Multifile>().eq("OBJ_ID",i.getId()).orderByAsc(" SORTNUM ")));
-            i.setGoodsParamList(goodsParamMapper.selectList(
-                    new QueryWrapper<GoodsParam>().eq("GOODS_ID",i.getId())
-                            .apply(" name in ( select cp.NAME from cate_param cp where cp.CATEGORY_ID = "+i.getCategoryId()+" and cp.ISSHOW = 1 and cp.ISDELETED = 0 and cp.STATUS = 0 ) ")
-                            .orderByAsc(" SORTNUM ")));
-        });
+        this.dealGoodsMsg(goodsList);
         return goodsList;
     }
 

--
Gitblit v1.9.3