From c166834a4aa5545a30115ea0195dab8dbab59fbd Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期三, 20 九月 2023 15:12:10 +0800
Subject: [PATCH] pp

---
 server/service/src/main/java/com/doumee/service/business/impl/GoodsServiceImpl.java |  157 ++++++++++++++++++++++++----------------------------
 1 files changed, 73 insertions(+), 84 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 e5d6640..8050175 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
@@ -175,6 +175,8 @@
             //  濡傛灉閫夋嫨骞冲彴鍟嗗搧鍜屾煡璇㈢粨鏋滃涓嶄笂锛屾彁绀洪敊璇�
             throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝璇锋纭�夋嫨骞冲彴鍟嗗搧锛�");
         }
+        List<Multifile> multifileList = new ArrayList<>();
+        List<GoodsParam> goodsParamList = new ArrayList<>();
         for(BaseGoods model : goodsList){
             //閬嶅巻骞冲彴鍟嗗搧淇℃伅锛岃繘琛屽晢鍝佷俊鎭悓姝�
             Goods goods = initGoodsPlatParam(user,model,param);
@@ -183,16 +185,21 @@
             }
             goodsMapper.insert(goods);
            //寮�濮嬪鐞嗛檮浠�
-            dealPlatMultifule(goods.getId(),user,model);
+            dealPlatMultifule(goods.getId(),user,model,multifileList);
             //寮�濮嬪鐞嗗弬鏁伴厤缃�
-            dealPlatGoodsParam(model,goods,user);
+            dealPlatGoodsParam(model,goods,user,goodsParamList);
         }
-
+        if(multifileList.size()>0){
+            multifileMapper.insertBatch(multifileList);
+        }
+        if(goodsParamList.size()>0){
+            goodsParamMapper.insertBatch(goodsParamList);
+        }
 
         return 1;
     }
 
-    private void dealPlatGoodsParam(BaseGoods model, Goods goods, LoginUserInfo user) {
+    private void dealPlatGoodsParam(BaseGoods model, Goods goods, LoginUserInfo user,List<GoodsParam> paramList) {
         BaseGoodsParam baseGoodsParam = new BaseGoodsParam();
         baseGoodsParam.setGoodsId(model.getId());
         baseGoodsParam.setIsdeleted(Constants.ZERO);
@@ -207,9 +214,9 @@
                         .eq("ISDELETED",Constants.ZERO)
                         .eq("STATUS",Constants.ZERO)
                         .last(" limit 1 "));
-                if(Objects.isNull(cateParam)){
-                    throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"浼佷笟鍒嗙被鏁版嵁鍚屾寮傚父璇疯仈绯荤鐞嗗憳");
-                }
+//                if(Objects.isNull(cateParam)){
+//                    throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"浼佷笟鍒嗙被鏁版嵁鍚屾寮傚父璇疯仈绯荤鐞嗗憳");
+//                }
                 GoodsParam goodsParam = new GoodsParam();
                 goodsParam.setCreator(user.getId());
                 goodsParam.setCreateDate(new Date());
@@ -219,24 +226,9 @@
                 goodsParam.setGoodsId(goods.getId());
                 goodsParam.setVal(bgParam.getVal());
                 goodsParam.setName(bgParam.getName());
-                goodsParam.setPramaId(cateParam.getId());
-                goodsParamMapper.insert(goodsParam);
-
-                //瀛樺偍 cate_param_select 鏌ヨ鏄惁宸插瓨鍦�
-                if(cateParamSelectMapper.selectCount(new QueryWrapper<CateParamSelect>()
-                        .eq("PARAM_ID",goodsParam.getPramaId()).eq("NAME",goodsParam.getName()))<=Constants.ZERO){
-                    CateParamSelect cateParamSelect = new CateParamSelect();
-                    cateParamSelect.setCreator(user.getId());
-                    cateParamSelect.setCreateDate(new Date());
-                    cateParamSelect.setName(goodsParam.getVal());
-                    cateParamSelect.setIsdeleted(Constants.ZERO);
-                    cateParamSelect.setStatus(Constants.ZERO);
-                    cateParamSelect.setParamId(goodsParam.getPramaId());
-                    cateParamSelect.setCategoryId(goods.getCategoryId());
-                    cateParamSelect.setStatus(Constants.ZERO);
-                    cateParamSelectMapper.insert(cateParamSelect);
-                };
-
+                goodsParam.setPramaId(Objects.isNull(cateParam)?null:cateParam.getId());
+                paramList.add(goodsParam);
+//                goodsParamMapper.insert(goodsParam);
             }
         }
     }
@@ -245,6 +237,7 @@
         Goods goods = new Goods();
         goods.setIsdeleted(Constants.ZERO);
         goods.setGoodsId(model.getId());
+        goods.setCompanyId(user.getCompanyId());
         if(goodsMapper.selectCount(new QueryWrapper<>(goods))>0){
             //濡傛灉宸茬粡鍚屾杩囷紝璺宠繃姝ゆ鍚屾
             return  null;
@@ -272,7 +265,7 @@
     /**
      *  寮�濮嬪鐞嗗钩鍙板晢鍝佸叧鑱旈檮浠讹紝澶嶅埗涓�濂楀埌浼佷笟鍟嗗搧涓�
      */
-    private void dealPlatMultifule(Integer id, LoginUserInfo user, BaseGoods model) {
+    private void dealPlatMultifule(Integer id, LoginUserInfo user, BaseGoods model,List<Multifile> fileList ) {
         Multifile f = new Multifile();
         f.setObjId(model.getId());
         f.setIsdeleted(Constants.ZERO);
@@ -291,7 +284,8 @@
                 multifile.setName(multifile.getName());
                 multifile.setSortnum(multifile.getSortnum());
                 multifile.setCompanyId(user.getCompanyId());
-                multifileMapper.insert(multifile);
+                fileList.add(multifile);
+//                multifileMapper.insert(multifile);
             }
         }
     }
@@ -300,16 +294,16 @@
         if(Constants.equalsInteger(Constants.ONE, param.getType())){
             for(PlatGoodsParam p: param.getGoodsParamList()){
                 if(Constants.equalsInteger(model.getId(),p.getGoodsId())){
-                    return p.getPrice();
+                    return p.getPrice().setScale(0,BigDecimal.ROUND_CEILING);
                 }
             }
         }
         //濡傛灉娌℃湁閰嶇疆鍏ユ墜浠凤紝瀹夎鍔犱环绯绘暟鏉ヨ绠�
-        if(model.getCateRatePrice()==null){
-            model.setCateRatePrice(systemDictDataBiz.getGoodsPriceRate());
-        }
-        //杩斿洖
-        return Constants.formatBigdecimal(model.getPrice()).multiply(model.getCateRatePrice()).multiply(param.getRate());
+//        if(model.getCateRatePrice()==null){
+//            model.setCateRatePrice(systemDictDataBiz.getGoodsPriceRate());
+//        }
+        //杩斿洖 .multiply(model.getCateRatePrice())
+        return (Constants.formatBigdecimal(model.getPrice()).multiply(param.getRate())).setScale(0,BigDecimal.ROUND_CEILING);
 
     }
 
@@ -345,6 +339,7 @@
                 multifile.setObjId(goods.getId());
                 multifile.setType(Constants.ZERO);
                 multifile.setObjType(Constants.ZERO);
+                multifile.setCompanyId(goods.getCompanyId());
                 multifileMapper.insert(multifile);
             }
         }
@@ -359,20 +354,6 @@
                 goodsParam.setSortnum(i+Constants.ONE);
                 goodsParam.setGoodsId(goods.getId());
                 goodsParamMapper.insert(goodsParam);
-                //瀛樺偍 cate_param_select 鏌ヨ鏄惁宸插瓨鍦�
-                if(cateParamSelectMapper.selectCount(new QueryWrapper<CateParamSelect>()
-                        .eq("PARAM_ID",goodsParam.getPramaId()).eq("NAME",goodsParam.getName()))<=Constants.ZERO){
-                    CateParamSelect cateParamSelect = new CateParamSelect();
-                    cateParamSelect.setCreator(user.getId());
-                    cateParamSelect.setCreateDate(new Date());
-                    cateParamSelect.setName(goodsParam.getVal());
-                    cateParamSelect.setIsdeleted(Constants.ZERO);
-                    cateParamSelect.setStatus(Constants.ZERO);
-                    cateParamSelect.setParamId(goodsParam.getPramaId());
-                    cateParamSelect.setCategoryId(goods.getCategoryId());
-                    cateParamSelect.setStatus(Constants.ZERO);
-                    cateParamSelectMapper.insert(cateParamSelect);
-                };
             }
         }
         return goods.getId();
@@ -457,7 +438,8 @@
         }else{
             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"褰撳墠鐧诲綍鐢ㄦ埛绫诲埆閿欒锛屾棤娉曡繘琛岃鎿嶄綔");
         }
-        if(goodsMapper.selectCount(new QueryWrapper<Goods>().eq("COMPANY_ID",user.getCompanyId()).eq("ISDELETED",Constants.ZERO).ne("id",goods.getId()).eq("name",goods.getName()))>0){
+        if(goodsMapper.selectCount(new QueryWrapper<Goods>().eq("COMPANY_ID",user.getCompanyId())
+                .eq("ISDELETED",Constants.ZERO).ne("id",goods.getId()).eq("name",goods.getName()))>0){
             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"銆�"+goods.getName()+"銆戝凡瀛樺湪");
         };
         goods.setStatus(Constants.ZERO);
@@ -469,7 +451,8 @@
         goods.setShortPinyin(PinYinUtil.getFirstSpell(goods.getName()));
         goodsMapper.updateById(goods);
 
-        multifileMapper.delete(new QueryWrapper<Multifile>().eq("OBJ_ID",goods.getId()));
+        multifileMapper.delete(new QueryWrapper<Multifile>().eq("OBJ_ID",goods.getId())
+                .eq("OBJ_TYPE",0).eq("COMPANY_ID",user.getCompanyId()));
         List<Multifile> multifileList = goods.getMultifileList();
         if(!Objects.isNull(multifileList)&&multifileList.size()>Constants.ZERO){
             for (int i = 0; i < multifileList.size(); i++) {
@@ -480,6 +463,7 @@
                 multifile.setSortnum(i+Constants.ONE);
                 multifile.setObjId(goods.getId());
                 multifile.setType(Constants.ZERO);
+                multifile.setCompanyId(goods.getCompanyId());
                 multifile.setObjType(Constants.ZERO);
                 multifileMapper.insert(multifile);
             }
@@ -497,19 +481,19 @@
                 goodsParam.setGoodsId(goods.getId());
                 goodsParamMapper.insert(goodsParam);
                 //瀛樺偍 cate_param_select 鏌ヨ鏄惁宸插瓨鍦�
-                if(cateParamSelectMapper.selectCount(new QueryWrapper<CateParamSelect>()
-                        .eq("PARAM_ID",goodsParam.getPramaId()).eq("NAME",goodsParam.getName()))<=Constants.ZERO){
-                    CateParamSelect cateParamSelect = new CateParamSelect();
-                    cateParamSelect.setCreator(user.getId());
-                    cateParamSelect.setCreateDate(new Date());
-                    cateParamSelect.setName(goodsParam.getVal());
-                    cateParamSelect.setIsdeleted(Constants.ZERO);
-                    cateParamSelect.setStatus(Constants.ZERO);
-                    cateParamSelect.setParamId(goodsParam.getPramaId());
-                    cateParamSelect.setCategoryId(goods.getCategoryId());
-                    cateParamSelect.setStatus(Constants.ZERO);
-                    cateParamSelectMapper.insert(cateParamSelect);
-                };
+//                if(cateParamSelectMapper.selectCount(new QueryWrapper<CateParamSelect>()
+//                        .eq("PARAM_ID",goodsParam.getPramaId()).eq("NAME",goodsParam.getName()))<=Constants.ZERO){
+//                    CateParamSelect cateParamSelect = new CateParamSelect();
+//                    cateParamSelect.setCreator(user.getId());
+//                    cateParamSelect.setCreateDate(new Date());
+//                    cateParamSelect.setName(goodsParam.getVal());
+//                    cateParamSelect.setIsdeleted(Constants.ZERO);
+//                    cateParamSelect.setStatus(Constants.ZERO);
+//                    cateParamSelect.setParamId(goodsParam.getPramaId());
+//                    cateParamSelect.setCategoryId(goods.getCategoryId());
+//                    cateParamSelect.setStatus(Constants.ZERO);
+//                    cateParamSelectMapper.insert(cateParamSelect);
+//                };
             }
         }
     }
@@ -534,7 +518,7 @@
             throw new BusinessException(ResponseStatus.DATA_EMPTY);
         }
         //鎷夊紡鍟嗗搧 涓� 涓婃灦鏃讹紝闇�瑕侀檺鍒� 骞冲彴鍟嗗搧鏄惁宸蹭笅鏋�
-        if(dbGoods.getType().equals(Constants.goodsType.PULL)&&goods.getStatus().equals(Constants.ZERO)){
+        if(dbGoods.getType().equals(Constants.goodsType.PULL.getValue())&&goods.getStatus().equals(Constants.ZERO)){
             BaseGoods baseGoods = baseGoodsMapper.selectById(dbGoods.getGoodsId());
             if(Objects.isNull(baseGoods)){
                 throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏈煡璇㈠埌骞冲彴鍟嗗搧淇℃伅");
@@ -572,7 +556,7 @@
                 continue;
             }
             //鎷夊紡鍟嗗搧 涓� 涓婃灦鏃讹紝闇�瑕侀檺鍒� 骞冲彴鍟嗗搧鏄惁宸蹭笅鏋�
-            if(dbGoods.getType().equals(Constants.goodsType.PULL)&&batchDisableDTO.getStatus().equals(Constants.ZERO)){
+            if(dbGoods.getType().equals(Constants.goodsType.PULL.getValue())&&batchDisableDTO.getStatus().equals(Constants.ZERO)){
                 BaseGoods baseGoods = baseGoodsMapper.selectById(dbGoods.getGoodsId());
                 if(Objects.isNull(baseGoods)||!baseGoods.getStatus().equals(Constants.ZERO)){
                     errNum++;
@@ -677,7 +661,9 @@
         if (pageWrap.getModel().getStatus() != null) {
             queryWrapper.eq(Goods::getStatus, pageWrap.getModel().getStatus());
         }
-
+        if (pageWrap.getModel().getType() != null) {
+            queryWrapper.eq(Goods::getType, pageWrap.getModel().getType());
+        }
         if (pageWrap.getModel().getCategoryId() != null) {
             queryWrapper.eq(Goods::getCategoryId, pageWrap.getModel().getCategoryId());
         }
@@ -693,10 +679,6 @@
                 + systemDictDataBiz.queryByCode(Constants.OSS, Constants.GOODS_IMG).getCode();
         goodsIPage.getRecords().forEach(i->{
             i.setPrefixUrl(prefixUrl);
-            if(i.getType().equals(Constants.ONE)){
-                i.setBasePrice(i.getBasePrice().multiply(i.getBasePriceRate()));
-            }
-
         });
         return PageData.from(goodsIPage);
     }
@@ -875,19 +857,19 @@
                     //鎻掑叆浜у搧鍙傛暟鍏宠仈琛�
                     goodsParamMapper.insert(gp);
                     //瀛樺偍 cate_param_select 鏌ヨ鏄惁宸插瓨鍦�
-                    if(cateParamSelectMapper.selectCount(new QueryWrapper<CateParamSelect>()
-                            .eq("PARAM_ID",gp.getPramaId()).eq("NAME",gp.getName()))<=Constants.ZERO){
-                        CateParamSelect cateParamSelect = new CateParamSelect();
-                        cateParamSelect.setCreator(user.getId());
-                        cateParamSelect.setCreateDate(new Date());
-                        cateParamSelect.setName(gp.getVal());
-                        cateParamSelect.setIsdeleted(Constants.ZERO);
-                        cateParamSelect.setStatus(Constants.ZERO);
-                        cateParamSelect.setParamId(gp.getPramaId());
-                        cateParamSelect.setCategoryId(newModel.getCategoryId());
-                        cateParamSelect.setStatus(Constants.ZERO);
-                        cateParamSelectMapper.insert(cateParamSelect);
-                    };
+//                    if(cateParamSelectMapper.selectCount(new QueryWrapper<CateParamSelect>()
+//                            .eq("PARAM_ID",gp.getPramaId()).eq("NAME",gp.getName()))<=Constants.ZERO){
+//                        CateParamSelect cateParamSelect = new CateParamSelect();
+//                        cateParamSelect.setCreator(user.getId());
+//                        cateParamSelect.setCreateDate(new Date());
+//                        cateParamSelect.setName(gp.getVal());
+//                        cateParamSelect.setIsdeleted(Constants.ZERO);
+//                        cateParamSelect.setStatus(Constants.ZERO);
+//                        cateParamSelect.setParamId(gp.getPramaId());
+//                        cateParamSelect.setCategoryId(newModel.getCategoryId());
+//                        cateParamSelect.setStatus(Constants.ZERO);
+//                        cateParamSelectMapper.insert(cateParamSelect);
+//                    };
                 }
             }
             if(mulFiles !=null && mulFiles.size()>0){
@@ -1090,9 +1072,13 @@
         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 ")));
+            i.setGoodsParamList(goodsParamMapper.selectList(new QueryWrapper<GoodsParam>()
+                    .eq("GOODS_ID",i.getId())
+                    .orderByAsc(" SORTNUM ")));
         });
         return PageData.from(goodsIPage);
     }
@@ -1134,7 +1120,10 @@
         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 ")));
+            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 ")));
         });
         return goodsList;
     }

--
Gitblit v1.9.3