From 08e9a67dd679f311e79a27b04cd0c53a30b4bccf Mon Sep 17 00:00:00 2001
From: doum <doum>
Date: 星期四, 04 六月 2026 18:33:22 +0800
Subject: [PATCH] aaa

---
 server/service/src/main/java/com/doumee/service/business/impl/GoodsServiceImpl.java |  569 ++++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 402 insertions(+), 167 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 8050175..c1e1d93 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
@@ -1,5 +1,6 @@
 package com.doumee.service.business.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -18,6 +19,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;
@@ -29,6 +32,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;
@@ -43,6 +48,8 @@
 import java.net.URLEncoder;
 import java.nio.charset.Charset;
 import java.util.*;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
 
 /**
  * 鍟嗗搧淇℃伅琛⊿ervice瀹炵幇
@@ -64,6 +71,8 @@
     @Autowired
     private CategoryMapper categoryMapper;
     @Autowired
+    private BaseCategoryMapper baseCategoryMapper;
+    @Autowired
     private CateAttrMapper cateAttrMapper;
     @Autowired
     private CateParamMapper cateParamMapper;
@@ -79,10 +88,13 @@
 
     @Autowired
     private GoodsJoinMapper goodsJoinMapper;
+
+    @Lazy
     @Autowired
-    private CateParamSelectMapper cateParamSelectMapper;
+    private CateParamSelectService cateParamSelectService;
 
-
+    @Autowired
+    private RedisTemplate redisTemplate;
 
 
     @Override
@@ -130,6 +142,8 @@
 
         return goods.getId();
     }
+
+    @Async
     @Override
     @Transactional( rollbackFor = {Exception.class, BusinessException.class})
     public  Integer createPlat(GoodCreatePlatRequest param){
@@ -153,6 +167,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);
@@ -177,25 +196,34 @@
         }
         List<Multifile> multifileList = new ArrayList<>();
         List<GoodsParam> goodsParamList = new ArrayList<>();
-        for(BaseGoods model : goodsList){
-            //閬嶅巻骞冲彴鍟嗗搧淇℃伅锛岃繘琛屽晢鍝佷俊鎭悓姝�
-            Goods goods = initGoodsPlatParam(user,model,param);
-            if(goods == null){
-                continue;
-            }
-            goodsMapper.insert(goods);
-           //寮�濮嬪鐞嗛檮浠�
-            dealPlatMultifule(goods.getId(),user,model,multifileList);
-            //寮�濮嬪鐞嗗弬鏁伴厤缃�
-            dealPlatGoodsParam(model,goods,user,goodsParamList);
-        }
-        if(multifileList.size()>0){
-            multifileMapper.insertBatch(multifileList);
-        }
-        if(goodsParamList.size()>0){
-            goodsParamMapper.insertBatch(goodsParamList);
-        }
+        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);
+            }
+            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;
     }
 
@@ -268,7 +296,9 @@
     private void dealPlatMultifule(Integer id, LoginUserInfo user, BaseGoods model,List<Multifile> fileList ) {
         Multifile f = new Multifile();
         f.setObjId(model.getId());
+        f.setObjType(Constants.ONE);
         f.setIsdeleted(Constants.ZERO);
+        f.setObjType(Constants.ONE);
         List<Multifile> multifileList =multifileMapper.selectList(new QueryWrapper<>(f));
         if(!Objects.isNull(multifileList)&&multifileList.size()>Constants.ZERO){
             for (int i = 0; i < multifileList.size(); i++) {
@@ -297,13 +327,14 @@
                     return p.getPrice().setScale(0,BigDecimal.ROUND_CEILING);
                 }
             }
+            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);
 
     }
 
@@ -323,15 +354,18 @@
         goods.setCreateDate(new Date());
         goods.setCreator(user.getId());
         goods.setIsdeleted(Constants.ZERO);
-        //澶勭悊鎷奸煶闂
         goods.setPinyin(PinYinUtil.getFullSpell(goods.getName()));
         goods.setShortPinyin(PinYinUtil.getFirstSpell(goods.getName()));
+        this.validateSubCategory(goods);
         goodsMapper.insert(goods);
 
         List<Multifile> multifileList = goods.getMultifileList();
         if(!Objects.isNull(multifileList)&&multifileList.size()>Constants.ZERO){
             for (int i = 0; i < multifileList.size(); i++) {
                 Multifile multifile = multifileList.get(i);
+                if(StringUtils.isBlank(multifile.getFileurl())){
+                    continue;
+                }
                 multifile.setCreator(user.getId());
                 multifile.setCreateDate(new Date());
                 multifile.setIsdeleted(Constants.ZERO);
@@ -347,6 +381,7 @@
         if(!Objects.isNull(goodsParamList)&&goodsParamList.size()>0){
             for (int i = 0; i < goodsParamList.size(); i++) {
                 GoodsParam goodsParam = goodsParamList.get(i);
+                goodsParam.setId(null);
                 goodsParam.setCreator(user.getId());
                 goodsParam.setCreateDate(new Date());
                 goodsParam.setIsdeleted(Constants.ZERO);
@@ -380,7 +415,10 @@
         if (CollectionUtils.isEmpty(ids)) {
             return;
         }
-        goodsMapper.deleteBatchIds(ids);
+        for(Integer id : ids){
+            deleteById(id);
+        }
+//        goodsMapper.deleteBatchIds(ids);
     }
 
     @Override
@@ -446,9 +484,9 @@
         goods.setEditDate(new Date());
         goods.setEditor(user.getId());
         goods.setIsdeleted(Constants.ZERO);
-        //澶勭悊鎷奸煶闂
         goods.setPinyin(PinYinUtil.getFullSpell(goods.getName()));
         goods.setShortPinyin(PinYinUtil.getFirstSpell(goods.getName()));
+        this.validateSubCategory(goods);
         goodsMapper.updateById(goods);
 
         multifileMapper.delete(new QueryWrapper<Multifile>().eq("OBJ_ID",goods.getId())
@@ -473,6 +511,7 @@
         if(!Objects.isNull(goodsParamList)&&goodsParamList.size()>0){
             for (int i = 0; i < goodsParamList.size(); i++) {
                 GoodsParam goodsParam = goodsParamList.get(i);
+                goodsParam.setId(null);
                 goodsParam.setCreator(user.getId());
                 goodsParam.setCreateDate(new Date());
                 goodsParam.setIsdeleted(Constants.ZERO);
@@ -589,7 +628,7 @@
         if(!Objects.isNull(category)){
             goods.setCategoryName(category.getName());
         }
-        goods.setMultifileList(multifileMapper.selectList(new QueryWrapper<Multifile>().eq("OBJ_ID",id)));
+        goods.setMultifileList(multifileMapper.selectList(new QueryWrapper<Multifile>().eq("OBJ_TYPE",Constants.ZERO).eq("OBJ_ID",id)));
         return goods;
     }
 
@@ -611,6 +650,7 @@
         queryWrapper.leftJoin(Category.class, Category::getId, Goods::getCategoryId);
         queryWrapper.leftJoin(Brand.class, Brand::getId, Goods::getBrandId);
         queryWrapper.eq(Goods::getStatus,Constants.ZERO);
+        queryWrapper.eq(Goods::getCompanyId, goods.getCompanyId());
         queryWrapper.eq(Goods::getIsdeleted,Constants.ZERO);
         queryWrapper.like(StringUtils.isNotBlank(goods.getAttrFirstIds()),Goods::getAttrFirstIds,goods.getAttrFirstIds());
         queryWrapper.like(StringUtils.isNotBlank(goods.getAttrFirstNames()),Goods::getAttrFirstNames,goods.getAttrFirstNames());
@@ -621,14 +661,11 @@
         queryWrapper.between(!Objects.isNull(goods.getSPrice())&&!Objects.isNull(goods.getEPrice()),
                 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 ")));
-        });
+        List<Goods> goodsList =  this.goodsMapper.selectListByCollection(goods);
+      //  List<Goods> goodsList = goodsJoinMapper.selectJoinList(Goods.class,queryWrapper);
+        if(!Objects.isNull(goodsList)&&goodsList.size()>Constants.ZERO){
+            this.dealGoodsMsg(goodsList);
+        }
         return goodsList;
     }
 
@@ -679,6 +716,9 @@
                 + systemDictDataBiz.queryByCode(Constants.OSS, Constants.GOODS_IMG).getCode();
         goodsIPage.getRecords().forEach(i->{
             i.setPrefixUrl(prefixUrl);
+            if(i.getType().equals(Constants.ONE)){
+                i.setBasePrice(Constants.formatBigdecimal(i.getBasePrice()).multiply(Constants.formatBigdecimal(i.getBasePriceRate())).setScale(0,BigDecimal.ROUND_CEILING));
+            }
         });
         return PageData.from(goodsIPage);
     }
@@ -701,6 +741,265 @@
     @Override
     public Integer importBatch(MultipartFile file){
         LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
+        Boolean  isGrouping = (Boolean)redisTemplate.opsForValue().get(user.getCompanyId()+Constants.COMPANY_IMPORT_GOODS);
+        if(isGrouping!=null && isGrouping ){
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"褰撳墠宸插瓨鍦ㄤ骇鍝佸鍏ユ搷浣滐紝姝ゆ鎿嶄綔鏃犳晥锛岃绋嶅悗閲嶈瘯锛�");
+        }
+        redisTemplate.opsForValue().set(user.getCompanyId()+Constants.COMPANY_IMPORT_GOODS,true,30, TimeUnit.MINUTES);
+        int num =1,index =1;
+        try {
+            ExcelImporter ie =  new ExcelImporter(file,0,0);;
+            List<GoodsImport> dataList =ie.getDataList(GoodsImport.class,null);
+            if(dataList == null || dataList.size() ==0){
+                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝褰曞叆鏁版嵁涓虹┖锛�");
+            }
+            String proDir =systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.PROJECTS).getCode();
+            String path = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.GOODS_IMG_DIR).getCode() + proDir + File.separator + user.getCompanyId();
+            //鍝佺被鏁版嵁
+            List<Brand> brandList = brandMapper.selectList(new LambdaQueryWrapper<Brand>() .eq(Brand::getIsdeleted,Constants.ZERO)
+                    .and(wapper-> wapper.eq(Brand::getCompanyId ,user.getCompanyId()).or().eq(Brand::getType,Constants.ONE)));
+            //浼佷笟浜у搧鏁版嵁
+            List<Goods> goodsList = goodsMapper.selectList(new LambdaQueryWrapper<Goods>() .eq(Goods::getIsdeleted,Constants.ZERO)
+                    .eq(Goods::getCompanyId,user.getCompanyId()));
+            //鍝佺被鏁版嵁
+            List<Category> categoryList = categoryMapper.selectList(new LambdaQueryWrapper<Category>() .eq(Category::getIsdeleted,Constants.ZERO)
+                            .eq(Category::getCompanyId,user.getCompanyId()));
+            //鏌ヨ鍏ㄩ儴浜у搧鍙傛暟閰嶇疆
+            List<CateParam> allParamsList = cateParamMapper.selectList(new LambdaQueryWrapper<CateParam>().eq(CateParam::getIsdeleted,Constants.ZERO));
+            for(GoodsImport m: dataList){
+                if(StringUtils.isBlank(m.getName())
+                        &&StringUtils.isBlank(m.getCategory())
+                        &&StringUtils.isBlank(m.getZdPrice())
+                        &&StringUtils.isBlank(m.getPrice())
+                        &&StringUtils.isBlank(m.getId())
+                        &&StringUtils.isBlank(m.getBrand())){
+                   // 鍏ㄩ儴绌鸿锛岃烦杩囧鐞�;
+                    num++;
+                    continue;
+                }
+                if(StringUtils.isBlank(m.getName())
+                        ||StringUtils.isBlank(m.getCategory())
+                        ||StringUtils.isBlank(m.getZdPrice())
+                        ||StringUtils.isBlank(m.getPrice())
+                        ||StringUtils.isBlank(m.getId())
+                        ||StringUtils.isBlank(m.getBrand())){
+                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝绗��"+(num)+"銆戣鏁版嵁鏃犳晥锛岃妫�鏌ヨ緭鍏ワ紒");
+                }
+                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){
+                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝绗��"+(num)+"銆戣鍟嗗搧鍥剧墖鏂囦欢澶归噸澶嶏紝璇锋鏌ヨ緭鍏ワ紒");
+                }
+                Category cate = getCategroyByNameFromList(m.getCategory(),categoryList);
+                if(cate == null){
+                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝绗��"+(num)+"銆戣鍟嗗搧绫诲埆鏃犳晥锛岃妫�鏌ヨ緭鍏ワ紒");
+                }
+                Brand brand = getImportBrandByNameFromList(m.getBrand(),brandList);
+                if(brand == null){
+                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝绗��"+(num)+"銆戣鍟嗗搧鍝佺墝鏃犳晥锛岃妫�鏌ヨ緭鍏ワ紒");
+                }
+                if(findGoodsByNameFromList(m.getName(),goodsList) !=null){
+                        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);
+                try {
+                    newModel.setZdPrice(BigDecimal.valueOf(Double.parseDouble(m.getZdPrice())));
+                    newModel.setPrice(BigDecimal.valueOf(Double.parseDouble(m.getPrice())));
+                }catch (Exception e){
+
+                }
+                if(newModel.getZdPrice() == null){
+                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝绗��"+(num)+"銆戣鎸囧浠锋棤鏁堬紝璇锋鏌ヨ緭鍏ワ紒");
+                }
+                if(newModel.getPrice() == null){
+                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝绗��"+(num)+"銆戣鍏ユ墜浠锋棤鏁堬紝璇锋鏌ヨ緭鍏ワ紒");
+                }
+                newModel.setPinyin(PinYinUtil.getFullSpell(m.getName()));
+                newModel.setShortPinyin(PinYinUtil.getFirstSpell(m.getName()));
+                List<String> mulFiles =getGoodsImageFileList(newModel,path);
+                //鏌ヨ鍟嗗搧淇℃伅
+                goodsMapper.insert(newModel);
+                //鍔犲叆鍒板凡缁忓瓨鍦ㄧ殑浜у搧闆嗗悎涓紝鐢ㄤ簬涓嬩竴涓俊鎭幓閲嶅鐞�
+                goodsList.add(newModel);
+                //澶勭悊浜у搧灞炴�т笟鍔�
+                dealGoodsParamBiz(cate,newModel,m,allParamsList,num);
+                //澶勭悊浜у搧鍥剧墖璧勬簮涓氬姟
+                dealGoodsImagesBiz(mulFiles,newModel);
+
+                index++;//璁板綍瀵煎叆浜у搧鎴愬姛+1
+            }
+        }catch (BusinessException e){
+            throw e;
+        }catch (Exception e){
+            throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"瀵煎叆浜у搧鏁版嵁鍙戠敓寮傚父锛岃绋嶅悗閲嶈瘯锛�");
+        }finally {
+            redisTemplate.opsForValue().set(user.getCompanyId()+Constants.COMPANY_IMPORT_GOODS,false);
+        }
+        return  index;
+    }
+
+    private void dealGoodsImagesBiz(List<String> mulFiles, Goods newModel) {
+        if(mulFiles !=null && mulFiles.size()>0){
+            List<Multifile> multifileList = new ArrayList<>();
+            for(int i=0;i<mulFiles.size();i++){
+                String s = mulFiles.get(i);
+                Multifile f = new Multifile();
+                f.setObjType(Constants.ZERO);
+                f.setName(s);
+                f.setType(Constants.ZERO);
+                f.setObjId(newModel.getId());
+                f.setCreateDate(newModel.getCreateDate());
+                f.setCreator(newModel.getCreator());
+                f.setIsdeleted(Constants.ZERO);
+                f.setSortnum(i);
+                f.setCompanyId(newModel.getCompanyId());
+                f.setFileurl(s);
+                multifileList.add(f);
+            }
+            multifileMapper.insert(multifileList);
+        }
+    }
+
+    private List<String> getGoodsImageFileList(Goods newModel, String path) {
+        List<String> mulFiles = null;
+        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();
+                if(files!=null && files.length>0){
+                    for(File f:files){
+                        if(StringUtils.isBlank(newModel.getImgurl()) && isImgFile(f)){
+                            //鍙栫涓�寮犲浘鐗囦綔涓哄垪琛ㄥ浘
+                            newModel.setImgurl(baseDataService.getOssImgurl(ossModel,ossModel.getGoodsFolder(),f));
+                        }
+                        if((mulFiles ==null || mulFiles.size() == 0) && f.isDirectory()){
+                            //濡傛灉鏄枃浠跺す
+                            File[] fs = f.listFiles();
+                            if(fs!=null && fs.length>0){
+                                for(File mf : fs){
+                                    if(isImgFile(mf)){
+                                        if(mulFiles==null){
+                                            mulFiles = new ArrayList<>();
+                                        }
+                                        mulFiles.add(baseDataService.getOssImgurl(ossModel,ossModel.getGoodsFolder(),mf));
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        return mulFiles;
+    }
+
+    private void dealGoodsParamBiz(Category cate, Goods newModel, GoodsImport m, List<CateParam> allParamsList,int num) {
+        List<GoodsParam> paramList = new ArrayList<>();
+        String[] params =  StringUtils.defaultString(m.getParamStr(),"").split("\n");
+        //鏌ヨ鍏ㄩ儴浜у搧鍙傛暟閰嶇疆
+        List<CateParam> allParams =getCateParamByCateid(cate.getId(),allParamsList);
+        if(params.length > 0){
+            for(String s : params){
+                if(StringUtils.isBlank(s)){
+                    continue;
+                }
+                s = s.replace("锛�",":");
+                String[] ts = s.split(":");
+                if(ts.length == 0){
+                    continue;
+                }
+                //鏌ヨ灞炴�ц鏍煎璞�
+                CateParam ta = getCateParamByName(ts[0], allParams);
+                if(ta == null){
+                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝绗��"+(num)+"銆戣浜у搧鍙傛暟涓��"+s+"銆戞棤鏁堬紝璇锋鏌ヨ緭鍏ワ紒");
+                }
+                GoodsParam gp = new GoodsParam();
+                gp.setIsdeleted(Constants.ZERO);
+                gp.setCreator(newModel.getCreator());
+                gp.setCreateDate(newModel.getCreateDate());
+                gp.setGoodsId(newModel.getId());
+                gp.setName(ta.getName());
+                gp.setPramaId(ta.getId());
+                gp.setStatus(Constants.ZERO);
+                gp.setVal(ts.length>1?ts[1]:null);
+                gp.setSortnum(ta.getSortnum());
+                //鎻掑叆浜у搧鍙傛暟鍏宠仈琛�
+                paramList.add(gp);
+//                        goodsParamMapper.insert(gp);
+            }
+        }
+        if(paramList.size() >0){
+            goodsParamMapper.insert(paramList);
+        }
+
+    }
+
+    private Goods findGoodsByNameFromList(String name, List<Goods> goodsList) {
+        if(goodsList!=null){
+            for(Goods brand :goodsList){
+                if(StringUtils.equals(name.trim(),brand.getName())){
+                    return brand;
+                }
+            }
+        }
+        return null;
+    }
+
+    private List<CateParam> getCateParamByCateid(Integer cateid, List<CateParam> allParamsList) {
+        List<CateParam> list = null;
+
+        if(allParamsList!=null){
+            for(CateParam brand :allParamsList){
+                if(Constants.equalsInteger(cateid,brand.getCategoryId())){
+                   if(list == null){
+                       list = new ArrayList<>();
+                   }
+                   list.add(brand);
+                }
+            }
+        }
+        return list;
+    }
+    private Category getCategroyByNameFromList(String name, List<Category> categoryList) {
+        if(categoryList!=null){
+            for(Category brand :categoryList){
+                if(StringUtils.equals(name.trim(),brand.getName())){
+                    return brand;
+                }
+            }
+        }
+        return null;
+    }
+
+    private Brand getImportBrandByNameFromList(String name, List<Brand> brandList) {
+        if(brandList!=null){
+            for(Brand brand :brandList){
+                if(StringUtils.equals(name.trim(),brand.getName())){
+                    return brand;
+                }
+            }
+        }
+        return null;
+    }
+
+    @Transactional(rollbackFor = {Exception.class, BusinessException.class})
+    @Override
+    public Integer importBatchImg(MultipartFile file){
+        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
         ExcelImporter ie = null;
         List<GoodsImport> dataList =null;
         try {
@@ -715,21 +1014,8 @@
 
         int num =1;
         for(GoodsImport m: dataList){
-            if(StringUtils.isBlank(m.getName())
-                    &&StringUtils.isBlank(m.getCategory())
-                    &&StringUtils.isBlank(m.getZdPrice())
-                    &&StringUtils.isBlank(m.getPrice())
-                    &&StringUtils.isBlank(m.getId())
-                    &&StringUtils.isBlank(m.getBrand())){
+            if(  StringUtils.isBlank(m.getId()) ){
                 continue;
-            }
-            if(StringUtils.isBlank(m.getName())
-                    ||StringUtils.isBlank(m.getCategory())
-                    ||StringUtils.isBlank(m.getZdPrice())
-                    ||StringUtils.isBlank(m.getPrice())
-                    ||StringUtils.isBlank(m.getId())
-                    ||StringUtils.isBlank(m.getBrand())){
-                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝绗��"+(num)+"銆戣鏁版嵁鏃犳晥锛岃妫�鏌ヨ緭鍏ワ紒");
             }
             Goods g = new Goods();
             g.setIsdeleted(Constants.ZERO);
@@ -737,55 +1023,14 @@
             g.setCompanyId(user.getCompanyId());
             //鍝佺被鏁版嵁
             g = goodsMapper.selectOne(new QueryWrapper<>(g).last(" limit 1"));
-            if(g != null){
-                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝绗��"+(num)+"銆戣鍟嗗搧鍥剧墖鏂囦欢澶归噸澶嶏紝璇锋鏌ヨ緭鍏ワ紒");
+            if(g == null){
+                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝绗��"+(num)+"銆戣鍟嗗搧涓嶅瓨鍦紝璇锋鏌ヨ緭鍏ワ紒");
             }
-            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){
-                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝绗��"+(num)+"銆戣鍟嗗搧绫诲埆鏃犳晥锛岃妫�鏌ヨ緭鍏ワ紒");
-            }
-            Brand brand = new Brand();
-            brand.setIsdeleted(Constants.ZERO);
-            brand.setName(m.getBrand());
-            //鍝佺被鏁版嵁
-            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()+"銆戝凡瀛樺湪");
-            };
-            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);
-            try {
-                newModel.setZdPrice(BigDecimal.valueOf(Double.parseDouble(m.getZdPrice())));
-                newModel.setPrice(BigDecimal.valueOf(Double.parseDouble(m.getPrice())));
-            }catch (Exception e){
 
-            }
-            if(newModel.getZdPrice() == null){
-                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝绗��"+(num)+"銆戣鎸囧浠锋棤鏁堬紝璇锋鏌ヨ緭鍏ワ紒");
-            }
-            if(newModel.getPrice() == null){
-                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝绗��"+(num)+"銆戣鍏ユ墜浠锋棤鏁堬紝璇锋鏌ヨ緭鍏ワ紒");
-            }
-            newModel.setPinyin(PinYinUtil.getFullSpell(m.getName()));
-            newModel.setShortPinyin(PinYinUtil.getFirstSpell(m.getName()));
+            Goods newModel = new Goods();
+            newModel.setId(g.getId());
+            newModel.setEditor(user.getId());
+            newModel.setEditDate(new Date());
 
             String[] params =  StringUtils.defaultString(m.getParamStr(),"").split("\n");
             List<String> mulFiles = null;
@@ -823,56 +1068,13 @@
                 }
             }
             //鏌ヨ鍟嗗搧淇℃伅
-            goodsMapper.insert(newModel);
-            CateParam cp = new CateParam();
-            cp.setIsdeleted(Constants.ZERO);
-            cp.setCategoryId(cate.getId());
-            //鏌ヨ鍏ㄩ儴浜у搧鍙傛暟閰嶇疆
-            List<CateParam> allParams = cateParamMapper.selectList(new QueryWrapper<>(cp));
-            if(params.length > 0){
-                for(String s : params){
-                    if(StringUtils.isBlank(s)){
-                        continue;
-                    }
-                    s = s.replace("锛�",":");
-                    String[] ts = s.split(":");
-                    if(ts.length == 0){
-                        continue;
-                    }
-                    //鏌ヨ灞炴�ц鏍煎璞�
-                    CateParam ta = getCateParamByName(ts[0], allParams);
-                    if(ta == null){
-                        throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝绗��"+(num)+"銆戣浜у搧鍙傛暟涓��"+s+"銆戞棤鏁堬紝璇锋鏌ヨ緭鍏ワ紒");
-                    }
-                    GoodsParam gp = new GoodsParam();
-                    gp.setIsdeleted(Constants.ZERO);
-                    gp.setCreator(user.getId());
-                    gp.setCreateDate(newModel.getCreateDate());
-                    gp.setGoodsId(newModel.getId());
-                    gp.setName(ta.getName());
-                    gp.setPramaId(ta.getId());
-                    gp.setStatus(Constants.ZERO);
-                    gp.setVal(ts.length>1?ts[1]:null);
-                    gp.setSortnum(ta.getSortnum());
-                    //鎻掑叆浜у搧鍙傛暟鍏宠仈琛�
-                    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);
-//                    };
-                }
-            }
+            goodsMapper.updateById(newModel);
             if(mulFiles !=null && mulFiles.size()>0){
+                multifileMapper.update(null,new UpdateWrapper<Multifile>().lambda()
+                        .set(Multifile::getIsdeleted,Constants.ONE)
+                        .eq(Multifile::getIsdeleted,Constants.ZERO)
+                        .eq(Multifile::getObjId,g.getId())
+                        .eq(Multifile::getType,Constants.ZERO));
                 for(int i=0;i<mulFiles.size();i++){
                     String s = mulFiles.get(i);
                     Multifile f = new Multifile();
@@ -1053,6 +1255,7 @@
         queryWrapper.eq(Goods::getIsdeleted,Constants.ZERO);
 
         queryWrapper.eq(!Objects.isNull(pageWrap.getModel()) && !Objects.isNull(pageWrap.getModel().getCategoryId()), Goods::getCategoryId, pageWrap.getModel().getCategoryId())
+                .eq(!Objects.isNull(pageWrap.getModel()) && !Objects.isNull(pageWrap.getModel().getSubCategoryId()), Goods::getSubCategoryId, pageWrap.getModel().getSubCategoryId())
                 .eq(!Objects.isNull(pageWrap.getModel()) && !Objects.isNull(pageWrap.getModel().getBrandId()), Goods::getBrandId, pageWrap.getModel().getBrandId())
                 .and(!Objects.isNull(pageWrap.getModel()) && StringUtils.isNotBlank(pageWrap.getModel().getKeyword()),
                         i->i.like(Goods::getPinyin,pageWrap.getModel().getKeyword())
@@ -1069,20 +1272,46 @@
                 .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);
     }
 
+    private void validateSubCategory(Goods goods) {
+        if (goods.getSubCategoryId() == null) {
+            return;
+        }
+        Category sub = categoryMapper.selectById(goods.getSubCategoryId());
+        if (sub == null || sub.getParentId() == null || !sub.getParentId().equals(goods.getCategoryId())) {
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "浜岀骇绫诲埆蹇呴』灞炰簬鎵�閫変竴绾у搧绫�");
+        }
+    }
+
+
+
+    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>()
+                .lambda().in(Multifile::getObjId,integerList)
+                .eq(Multifile::getType,Constants.ZERO)
+                .eq(Multifile::getIsdeleted,Constants.ZERO)
+                .eq(Multifile::getObjType,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) {
@@ -1103,6 +1332,7 @@
         queryWrapper.eq(Goods::getIsdeleted,Constants.ZERO);
         queryWrapper.eq(Goods::getCompanyId,loginUserInfo.getCompanyId());
         queryWrapper.eq(!Objects.isNull(goodsRequest) && !Objects.isNull(goodsRequest.getCategoryId()), Goods::getCategoryId, goodsRequest.getCategoryId())
+                .eq(!Objects.isNull(goodsRequest) && !Objects.isNull(goodsRequest.getSubCategoryId()), Goods::getSubCategoryId, goodsRequest.getSubCategoryId())
                 .eq(!Objects.isNull(goodsRequest) && !Objects.isNull(goodsRequest.getBrandId()), Goods::getBrandId, goodsRequest.getBrandId())
                 .and(!Objects.isNull(goodsRequest) && StringUtils.isNotBlank(goodsRequest.getKeyword()),
                         i->i.like(Goods::getPinyin,goodsRequest.getKeyword())
@@ -1115,18 +1345,23 @@
                 .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())
-                            .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 ")));
-        });
+        if(!Objects.isNull(goodsList)&&goodsList.size()>Constants.ZERO){
+            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