From 691cbf9350a6e98bfeb3cc2274906da75466bf1d Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期五, 22 九月 2023 09:08:16 +0800
Subject: [PATCH] 销售价

---
 server/service/src/main/java/com/doumee/service/business/impl/GoodsServiceImpl.java |  349 +++++++++++++++++++++++++++++----------------------------
 1 files changed, 178 insertions(+), 171 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 1023bb5..3546e9e 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
@@ -17,12 +17,13 @@
 import com.doumee.dao.business.*;
 import com.doumee.dao.business.join.GoodsJoinMapper;
 import com.doumee.dao.business.model.*;
-import com.doumee.dao.business.model.dto.BatchDisableDTO;
-import com.doumee.dao.business.model.dto.GoodCreatePlatRequest;
-import com.doumee.dao.business.model.dto.GoodsRequest;
-import com.doumee.dao.business.model.dto.PlatGoodsParam;
+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;
+import io.swagger.v3.oas.annotations.callbacks.Callback;
 import lombok.extern.java.Log;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.poi.ss.usermodel.*;
@@ -30,6 +31,8 @@
 import org.apache.shiro.SecurityUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Lazy;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
@@ -44,6 +47,7 @@
 import java.net.URLEncoder;
 import java.nio.charset.Charset;
 import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * 鍟嗗搧淇℃伅琛⊿ervice瀹炵幇
@@ -56,11 +60,16 @@
     @Autowired
     private GoodsMapper goodsMapper;
     @Autowired
+    @Lazy
+    private BaseDataService baseDataService;
+    @Autowired
     private BaseGoodsMapper baseGoodsMapper;
     @Autowired
     private BaseGoodsParamMapper baseGoodsParamMapper;
     @Autowired
     private CategoryMapper categoryMapper;
+    @Autowired
+    private BaseCategoryMapper baseCategoryMapper;
     @Autowired
     private CateAttrMapper cateAttrMapper;
     @Autowired
@@ -77,10 +86,13 @@
 
     @Autowired
     private GoodsJoinMapper goodsJoinMapper;
+
+    @Lazy
     @Autowired
-    private CateParamSelectMapper cateParamSelectMapper;
+    private CateParamSelectService cateParamSelectService;
 
-
+    @Autowired
+    private RedisTemplate redisTemplate;
 
 
     @Override
@@ -128,7 +140,10 @@
 
         return goods.getId();
     }
+
+    @Async
     @Override
+    @Transactional( rollbackFor = {Exception.class, BusinessException.class})
     public  Integer createPlat(GoodCreatePlatRequest param){
         LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
         if(!Constants.equalsInteger(user.getType(), Constants.UserType.COMPANY.getKey())){
@@ -150,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);
@@ -172,24 +192,40 @@
             //  濡傛灉閫夋嫨骞冲彴鍟嗗搧鍜屾煡璇㈢粨鏋滃涓嶄笂锛屾彁绀洪敊璇�
             throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝璇锋纭�夋嫨骞冲彴鍟嗗搧锛�");
         }
-        for(BaseGoods model : goodsList){
-            //閬嶅巻骞冲彴鍟嗗搧淇℃伅锛岃繘琛屽晢鍝佷俊鎭悓姝�
-            Goods goods = initGoodsPlatParam(user,model,param);
-            if(goods == null){
-                continue;
+        List<Multifile> multifileList = new ArrayList<>();
+        List<GoodsParam> goodsParamList = new ArrayList<>();
+        try{
+            for(BaseGoods model : goodsList){
+                //閬嶅巻骞冲彴鍟嗗搧淇℃伅锛岃繘琛屽晢鍝佷俊鎭悓姝�
+                //鍒嗙被鍔犱环绯绘暟
+
+                model.setCateRatePrice(baseCategory.getPriceRate());
+                Goods goods = initGoodsPlatParam(user,model,param);
+                if(goods == null){
+                    continue;
+                }
+                goodsMapper.insert(goods);
+                //寮�濮嬪鐞嗛檮浠�
+                dealPlatMultifule(goods.getId(),user,model,multifileList);
+                //寮�濮嬪鐞嗗弬鏁伴厤缃�
+                dealPlatGoodsParam(model,goods,user,goodsParamList);
             }
-            goodsMapper.insert(goods);
-           //寮�濮嬪鐞嗛檮浠�
-            dealPlatMultifule(goods.getId(),user,model);
-            //寮�濮嬪鐞嗗弬鏁伴厤缃�
-            dealPlatGoodsParam(model,goods,user);
+            if(multifileList.size()>0){
+                multifileMapper.insertBatch(multifileList);
+            }
+            if(goodsParamList.size()>0){
+                goodsParamMapper.insertBatch(goodsParamList);
+            }
+            cateParamSelectService.dealCateParamSelect();
+        }catch (Exception e){
+           e.printStackTrace();
+        }finally {
+            redisTemplate.opsForValue().set(user.getCompanyId()+Constants.OPEN_SYNC_SWITCH,false);
         }
-
-
         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);
@@ -197,6 +233,16 @@
         if(!Objects.isNull(goodsParamList)&&goodsParamList.size()>0){
             for (int i = 0; i < goodsParamList.size(); i++) {
                 BaseGoodsParam bgParam = goodsParamList.get(i);
+                //鏍规嵁骞冲彴鍟嗗搧閰嶇疆鐨勫钩鍙板弬鏁颁俊鎭煡璇紒涓氱粦瀹氱殑鍙傛暟淇℃伅 杩涜瀛樺偍鍒� 浼佷笟鍟嗗搧鍙傛暟鍐�
+                CateParam cateParam = cateParamMapper.selectOne(new QueryWrapper<CateParam>()
+                        .eq("CATEGORY_ID",goods.getCategoryId())
+                        .eq("BASE_CATE_PARAM_ID",bgParam.getPramaId())
+                        .eq("ISDELETED",Constants.ZERO)
+                        .eq("STATUS",Constants.ZERO)
+                        .last(" limit 1 "));
+//                if(Objects.isNull(cateParam)){
+//                    throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"浼佷笟鍒嗙被鏁版嵁鍚屾寮傚父璇疯仈绯荤鐞嗗憳");
+//                }
                 GoodsParam goodsParam = new GoodsParam();
                 goodsParam.setCreator(user.getId());
                 goodsParam.setCreateDate(new Date());
@@ -206,7 +252,9 @@
                 goodsParam.setGoodsId(goods.getId());
                 goodsParam.setVal(bgParam.getVal());
                 goodsParam.setName(bgParam.getName());
-                goodsParamMapper.insert(goodsParam);
+                goodsParam.setPramaId(Objects.isNull(cateParam)?null:cateParam.getId());
+                paramList.add(goodsParam);
+//                goodsParamMapper.insert(goodsParam);
             }
         }
     }
@@ -215,6 +263,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;
@@ -242,7 +291,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);
@@ -261,7 +310,8 @@
                 multifile.setName(multifile.getName());
                 multifile.setSortnum(multifile.getSortnum());
                 multifile.setCompanyId(user.getCompanyId());
-                multifileMapper.insert(multifile);
+                fileList.add(multifile);
+//                multifileMapper.insert(multifile);
             }
         }
     }
@@ -270,16 +320,17 @@
         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);
                 }
             }
+            throw new BusinessException(ResponseStatus.DATA_ERRO.getCode(),"鏁版嵁寮傚父璇峰埛鏂伴噸璇�");
         }
         //濡傛灉娌℃湁閰嶇疆鍏ユ墜浠凤紝瀹夎鍔犱环绯绘暟鏉ヨ绠�
         if(model.getCateRatePrice()==null){
             model.setCateRatePrice(systemDictDataBiz.getGoodsPriceRate());
         }
-        //杩斿洖
-        return Constants.formatBigdecimal(model.getPrice()).multiply(model.getCateRatePrice()).multiply(param.getRate());
+        //杩斿洖 .multiply(model.getCateRatePrice())
+        return (Constants.formatBigdecimal(model.getPrice()).multiply(model.getCateRatePrice()).multiply(param.getRate())).setScale(0,BigDecimal.ROUND_CEILING);
 
     }
 
@@ -315,6 +366,7 @@
                 multifile.setObjId(goods.getId());
                 multifile.setType(Constants.ZERO);
                 multifile.setObjType(Constants.ZERO);
+                multifile.setCompanyId(goods.getCompanyId());
                 multifileMapper.insert(multifile);
             }
         }
@@ -329,20 +381,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();
@@ -369,7 +407,10 @@
         if (CollectionUtils.isEmpty(ids)) {
             return;
         }
-        goodsMapper.deleteBatchIds(ids);
+        for(Integer id : ids){
+            deleteById(id);
+        }
+//        goodsMapper.deleteBatchIds(ids);
     }
 
     @Override
@@ -427,7 +468,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);
@@ -439,7 +481,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++) {
@@ -450,6 +493,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);
             }
@@ -467,19 +511,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);
+//                };
             }
         }
     }
@@ -504,7 +548,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(),"鏈煡璇㈠埌骞冲彴鍟嗗搧淇℃伅");
@@ -542,7 +586,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++;
@@ -608,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;
     }
 
@@ -647,7 +685,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());
         }
@@ -663,10 +703,7 @@
                 + 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()));
-            }
-
+            i.setBasePrice(Constants.formatBigdecimal(i.getBasePrice()).multiply(Constants.formatBigdecimal(i.getBasePriceRate())));
         });
         return PageData.from(goodsIPage);
     }
@@ -722,6 +759,7 @@
             Goods g = new Goods();
             g.setIsdeleted(Constants.ZERO);
             g.setRemark(m.getId());
+            g.setCompanyId(user.getCompanyId());
             //鍝佺被鏁版嵁
             g = goodsMapper.selectOne(new QueryWrapper<>(g).last(" limit 1"));
             if(g != null){
@@ -730,6 +768,7 @@
             Category cate = new Category();
             cate.setIsdeleted(Constants.ZERO);
             cate.setName(m.getCategory());
+            cate.setCompanyId(user.getCompanyId());
             //鍝佺被鏁版嵁
             cate = categoryMapper.selectOne(new QueryWrapper<>(cate).last(" limit 1"));
             if(cate == null){
@@ -739,19 +778,22 @@
             brand.setIsdeleted(Constants.ZERO);
             brand.setName(m.getBrand());
             //鍝佺被鏁版嵁
-            brand = brandMapper.selectOne(new QueryWrapper<>(brand).last(" limit 1"));
+            QueryWrapper<Brand> qwrapper = new QueryWrapper<>(brand);
+            qwrapper.lambda().and(wapper-> wapper.eq(Brand::getCompanyId ,user.getCompanyId()).or().eq(Brand::getType,Constants.ONE));
+            brand = brandMapper.selectOne(qwrapper.last(" limit 1"));
             if(brand == null){
                 throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝绗��"+(num)+"銆戣鍟嗗搧鍝佺墝鏃犳晥锛岃妫�鏌ヨ緭鍏ワ紒");
             }
             if(goodsMapper.selectCount(new QueryWrapper<Goods>().eq("ISDELETED",Constants.ZERO).eq("name",m.getName()))>0){
-                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"銆�"+m.getName()+"銆戝凡瀛樺湪");
-            };
+                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"绗��"+(num)+"銆戣銆�"+m.getName()+"銆戝凡瀛樺湪");
+            }
             Goods newModel = new Goods();
             newModel.setRemark(m.getId());
             newModel.setCategoryId(cate.getId());
             newModel.setBrandId(brand.getId());
             newModel.setIsdeleted(Constants.ZERO);
             newModel.setCreator(user.getId());
+            newModel.setCompanyId(user.getCompanyId());
             newModel.setCreateDate(new Date());
             newModel.setName(m.getName());
             newModel.setStatus(Constants.ZERO);
@@ -770,67 +812,14 @@
             newModel.setPinyin(PinYinUtil.getFullSpell(m.getName()));
             newModel.setShortPinyin(PinYinUtil.getFirstSpell(m.getName()));
 
-            CateAttr ca = new CateAttr();
-            ca.setCategoryId(cate.getId());
-            ca.setIsdeleted(Constants.ZERO);
-            //鏌ヨ鍏ㄩ儴灞炴��1鍜屽睘鎬�2瑙勬牸鍊�
-            List<CateAttr> allAttr = cateAttrMapper.selectList(new QueryWrapper<>(ca));
-            //灞炴��1闆嗗悎
-//            String[] attrs = StringUtils.defaultString(m.getAttrFirstNames(),"").split("\n");
-            //灞炴��2闆嗗悎
-//            String[] attrs2 = StringUtils.defaultString(m.getAttrSecodNames(),"").split("\n");
-            //浜у搧鍙傛暟闆嗗悎
             String[] params =  StringUtils.defaultString(m.getParamStr(),"").split("\n");
-//            if(attrs.length > 0){
-//                String attrids="" ,attrNames="";
-//                for(String s : attrs){
-//                    if(StringUtils.isBlank(s)){
-//                        continue;
-//                    }
-//                    //鏌ヨ灞炴�ц鏍煎璞�
-//                    CateAttr ta = getCateAttrByName(s,Constants.ZERO,allAttr);
-//                    if(ta == null){
-//                        throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝绗��"+(num)+"銆戣灞炴��1涓��"+s+"銆戞棤鏁堬紝璇锋鏌ヨ緭鍏ワ紒");
-//                    }
-//                    if(StringUtils.isNotBlank(attrids)){
-//                        attrids += ",";
-//                        attrNames += ",";
-//                    }
-//                    attrids+= ta.getId();
-//                    attrNames+= ta.getName();
-//                }
-//                newModel.setAttrFirstIds(attrids);
-//                newModel.setAttrFirstNames(attrNames);
-//            }
-//            if(attrs2.length > 0){
-//                String attrids="" ,attrNames="";
-//                for(String s : attrs2){
-//                    if(StringUtils.isBlank(s)){
-//                        continue;
-//                    }
-//                    //鏌ヨ灞炴�ц鏍煎璞�
-//                    CateAttr ta = getCateAttrByName(s,Constants.ONE,allAttr);
-//                    if(ta == null){
-//                        throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝绗��"+(num)+"銆戣灞炴��1涓��"+s+"銆戞棤鏁堬紝璇锋鏌ヨ緭鍏ワ紒");
-//                    }
-//                    if(StringUtils.isNotBlank(attrids)){
-//                        attrids += ",";
-//                        attrNames += ",";
-//                    }
-//                    attrids+= ta.getId();
-//                    attrNames+= ta.getName();
-//                }
-//                newModel.setAttrSecodIds(attrids);
-//                newModel.setAttrSecodNames(attrNames);
-//
-//            }
             List<String> mulFiles = null;
             String proDir =systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.PROJECTS).getCode();
 
-            String tf = proDir.substring(0,proDir.length()-1);
             String path = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.GOODS_IMG_DIR).getCode()
-                    + proDir;
+                    + proDir + File.separator + user.getCompanyId();
             if(StringUtils.isNotBlank(path)){
+                OssModel ossModel = baseDataService.initOssModel();
                 File dir =new File(path+File.separator+newModel.getRemark()+File.separator);
                 if(dir!=null && dir.isDirectory()){
                     File[]  files = dir.listFiles();
@@ -838,16 +827,8 @@
                         for(File f:files){
                             if(StringUtils.isBlank(newModel.getImgurl()) && isImgFile(f)){
                                 //鍙栫涓�寮犲浘鐗囦綔涓哄垪琛ㄥ浘
-                                String imgdir =f.getPath().substring(f.getPath().indexOf(tf)+tf.length()+1);
-                                newModel.setImgurl(imgdir.replace(File.separator,"/"));
-//                                 newModel.setImgurl(f.getPath().replace(path.replace(File.separator,"/"),""));
+                                newModel.setImgurl(baseDataService.getOssImgurl(ossModel,ossModel.getGoodsFolder(),f));
                             }
-//                             else{
-//                                 if(mulFiles==null){
-//                                     mulFiles = new ArrayList<>();
-//                                 }
-//                                 mulFiles.add(f.getPath().replace(path.replace("/",File.separator),""));
-//                             }
                             if((mulFiles ==null || mulFiles.size() == 0) && f.isDirectory()){
                                 //濡傛灉鏄枃浠跺す
                                 File[] fs = f.listFiles();
@@ -857,12 +838,7 @@
                                             if(mulFiles==null){
                                                 mulFiles = new ArrayList<>();
                                             }
-
-                                            String imgdir =mf.getPath().substring(mf.getPath().indexOf(tf)+tf.length()+1);
-                                            mulFiles.add(imgdir.replace(File.separator,"/"));
-//                                             newModel.setImgurl(imgdir);
-////                                             mulFiles.add(mf.getName());
-//                                             mulFiles.add(mf.getPath().replace(path.replace(File.separator,"/"),""));
+                                            mulFiles.add(baseDataService.getOssImgurl(ossModel,ossModel.getGoodsFolder(),mf));
                                         }
                                     }
                                 }
@@ -906,19 +882,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){
@@ -933,6 +909,7 @@
                     f.setCreator(newModel.getCreator());
                     f.setIsdeleted(Constants.ZERO);
                     f.setSortnum(i);
+                    f.setCompanyId(user.getCompanyId());
                     f.setFileurl(s);
                     multifileMapper.insert(f);
                 }
@@ -942,6 +919,9 @@
         return  num;
 
     }
+
+
+
 
     private boolean isImgFile(File f) {
         if(f!=null && f.isFile() ){
@@ -1104,22 +1084,43 @@
                                 .or().like(Goods::getShortPinyin,pageWrap.getModel().getKeyword())
                                 .or().like(Goods::getName,pageWrap.getModel().getKeyword())
                 )
-                .apply(!Objects.isNull(pageWrap.getModel()) && !Objects.isNull(pageWrap.getModel().getAttrFirst()), " find_in_set('"+pageWrap.getModel().getAttrFirst()+"',t.ATTR_FIRST_IDS) ")
-                .apply(!Objects.isNull(pageWrap.getModel()) && !Objects.isNull(pageWrap.getModel().getAttrSecond()), " find_in_set('"+pageWrap.getModel().getAttrSecond()+"',t.ATTR_SECOD_IDS) ")
+//                .apply(!Objects.isNull(pageWrap.getModel()) && !Objects.isNull(pageWrap.getModel().getAttrFirst()), " find_in_set('"+pageWrap.getModel().getAttrFirst()+"',t.ATTR_FIRST_IDS) ")
+//                .apply(!Objects.isNull(pageWrap.getModel()) && !Objects.isNull(pageWrap.getModel().getAttrSecond()), " find_in_set('"+pageWrap.getModel().getAttrSecond()+"',t.ATTR_SECOD_IDS) ")
+                .apply(!Objects.isNull(pageWrap.getModel()) && !Objects.isNull(pageWrap.getModel().getAttrFirst()), " t.id in ( SELECT  gp.GOODS_ID   FROM  cate_param_select cps  ,  goods_param gp where     gp.PRAMA_ID = cps.PARAM_ID     and gp.VAL = cps.`NAME`  " +
+                        " and cps.ID = '"+pageWrap.getModel().getAttrFirst()+"' ) ")
+                .apply(!Objects.isNull(pageWrap.getModel()) && !Objects.isNull(pageWrap.getModel().getAttrSecond()), " t.id in ( SELECT  gp.GOODS_ID   FROM  cate_param_select cps  ,  goods_param gp where     gp.PRAMA_ID = cps.PARAM_ID     and gp.VAL = cps.`NAME`  " +
+                        " and cps.ID = '"+pageWrap.getModel().getAttrSecond()+"' ) ")
                 .apply(!Objects.isNull(pageWrap.getModel()) && !Objects.isNull(pageWrap.getModel().getSPrice()), "  t.PRICE >=  "+pageWrap.getModel().getSPrice()+" ")
                 .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.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) {
@@ -1152,15 +1153,21 @@
                 .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.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;
     }
 
+
+
+    @Override
+    @Transactional
+    public  void openSyncSwitch() {
+        LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
+        Boolean  openSyncSwitch = (Boolean)redisTemplate.opsForValue().get(loginUserInfo.getCompanyId()+Constants.OPEN_SYNC_SWITCH);
+        if(openSyncSwitch!=null && openSyncSwitch ){
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鏁版嵁鍚屾涓紝璇风◢鍚庡埛鏂伴噸璇�");
+        }
+        redisTemplate.opsForValue().set(loginUserInfo.getCompanyId()+Constants.OPEN_SYNC_SWITCH,true);
+    }
 }
 

--
Gitblit v1.9.3