From 293bdee572c9d51a93656f98da441ce31ac38d6e Mon Sep 17 00:00:00 2001
From: jiaosong <jiaosong6760@dingtalk.com>
Date: 星期二, 19 九月 2023 15:30:37 +0800
Subject: [PATCH] #联调修改

---
 server/service/src/main/java/com/doumee/service/business/impl/BaseGoodsServiceImpl.java |  129 +++++++++++++++++++-----------------------
 1 files changed, 58 insertions(+), 71 deletions(-)

diff --git a/server/service/src/main/java/com/doumee/service/business/impl/BaseGoodsServiceImpl.java b/server/service/src/main/java/com/doumee/service/business/impl/BaseGoodsServiceImpl.java
index db4a088..60ffc27 100644
--- a/server/service/src/main/java/com/doumee/service/business/impl/BaseGoodsServiceImpl.java
+++ b/server/service/src/main/java/com/doumee/service/business/impl/BaseGoodsServiceImpl.java
@@ -81,9 +81,9 @@
     @Override
     public Integer create(BaseGoodsCreateOrUpdateRequest baseGoods) {
         LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
-        if(baseGoodsMapper.selectCount(new QueryWrapper<BaseGoods>().eq("ISDELETED", Constants.ZERO).eq("name",baseGoods.getName()))>0){
-            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"銆�"+baseGoods.getName()+"銆戝凡瀛樺湪");
-        }
+//        if(baseGoodsMapper.selectCount(new QueryWrapper<BaseGoods>().eq("ISDELETED", Constants.ZERO).eq("name",baseGoods.getName()))>0){
+//            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"銆�"+baseGoods.getName()+"銆戝凡瀛樺湪");
+//        }
 
         Integer integer = baseGoodsMapper.selectCount(new QueryWrapper<BaseGoods>().eq("ISDELETED", Constants.ZERO));
         BaseGoods insert = new BaseGoods();
@@ -173,11 +173,11 @@
     public void update(BaseGoodsCreateOrUpdateRequest baseGoods) {
 
         LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
-        if(baseGoodsMapper.selectCount(new QueryWrapper<BaseGoods>()
-                .eq("ISDELETED",Constants.ZERO).ne("id",baseGoods.getId())
-                .eq("name",baseGoods.getName()))>0){
-            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"銆�"+baseGoods.getName()+"銆戝凡瀛樺湪");
-        }
+//        if(baseGoodsMapper.selectCount(new QueryWrapper<BaseGoods>()
+//                .eq("ISDELETED",Constants.ZERO).ne("id",baseGoods.getId())
+//                .eq("name",baseGoods.getName()))>0){
+//            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"銆�"+baseGoods.getName()+"銆戝凡瀛樺湪");
+//        }
 
         UpdateWrapper<BaseGoods> wrapper = new UpdateWrapper<>();
         wrapper.lambda()
@@ -373,21 +373,8 @@
 
 
     @Override
-    public PageData<BaseGoods> findCompanyPage(PageWrap<BaseGoods> pageWrap ,Integer companyId) {
-
-        //鏌ヨ浼佷笟宸茬粡瀛樺湪鐨勫晢鍝�
-        List<Integer> collect = new ArrayList<>();
-        if(Objects.nonNull(companyId)){
-            QueryWrapper<Goods> goodsQuery = new QueryWrapper<>();
-            goodsQuery.lambda().eq(Goods::getIsdeleted,Constants.ZERO)
-                    .eq(Goods::getCompanyId,companyId)
-                    .isNotNull(Goods::getGoodsId);
-            List<Goods> goods = goodsMapper.selectList(goodsQuery);
-            if (CollectionUtils.isEmpty(goods)){
-                 collect = goods.stream().map(s -> s.getGoodsId()).collect(Collectors.toList());
-            }
-        }
-
+    public PageData<BaseGoods> findCompanyPage(PageWrap<BaseGoods> pageWrap) {
+        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
         pageWrap.getModel().setIsdeleted(Constants.ZERO);
         IPage<BaseGoods> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
         MPJLambdaWrapper<BaseGoods> queryWrapper = new MPJLambdaWrapper<>();
@@ -404,8 +391,7 @@
                 .eq(pageWrap.getModel().getCategoryId()!=null,BaseGoods::getCategoryId, pageWrap.getModel().getCategoryId())
                 .eq(pageWrap.getModel().getBrandId()!=null,BaseGoods::getBrandId, pageWrap.getModel().getBrandId())
                 .eq(pageWrap.getModel().getStatus()!=null,BaseGoods::getStatus, pageWrap.getModel().getStatus())
-                .notIn(!CollectionUtils.isEmpty(collect),BaseGoods::getId, collect);
-
+                .notExists(user.getType().equals(Constants.UserType.COMPANY.getKey())," select 1 from goods g where g.GOODS_ID = t.id and g.TYPE = 1  and  g.company_id = "+user.getCompanyId()+"  ");
         queryWrapper.orderByDesc(Goods::getId);
         PageData<BaseGoods> pageData =PageData.from(baseGoodsJoinMapper.selectJoinPage(page,BaseGoods.class,queryWrapper));
         String prefixUrl = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()
@@ -434,32 +420,26 @@
             if(dataList == null || dataList.size() ==0){
                 throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝褰曞叆鏁版嵁涓虹┖锛�");
             }
-            List<String> comNameList = dataList.stream().map(s -> s.getName().trim()).distinct().collect(Collectors.toList());
-
-            if (!(dataList.size() == comNameList.size())){
-                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"鍟嗗搧鍚嶇О鏈夊凡瀛樺湪");
-            }
-
-//            List<String> collect1 = dataList.stream().filter(s->{
-//                if (StringUtils.isBlank(s.getBrandName())){
-//                    throw new BusinessException(ResponseStatus.BAD_REQUEST);
-//                }else {
-//                    return true;
-//                }
-//            }).map(s -> s.getCategoryName()).collect(Collectors.toList());
-//            QueryWrapper<BaseCategory> wrapper = new QueryWrapper<>();
-//            wrapper.lambda()
-//                    .in(BaseCategory::getName,collect1);
-//            List<BaseCategory> baseCategories = baseCategoryMapper.selectList(wrapper);
-
-            dataList.forEach(s->{
-
-                if(baseGoodsMapper.selectCount(new QueryWrapper<BaseGoods>().eq("ISDELETED", Constants.ZERO).eq("name",s.getName()))>0){
-                    throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"銆�"+s.getName()+"銆戝凡瀛樺湪");
+            //澶勭悊鎵归噺涓婁紶
+            String proDir =systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.PLATFORM).getCode();
+            String basePath = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.GOODS_IMG_DIR).getCode()
+                    + proDir + File.separator ;
+            OssModel ossModel = baseDataService.initOssModel();
+            for (int index = 0; index < dataList.size(); index++) {
+                BaseGoodsImportDTO  s = dataList.get(index);
+                if(existedIdInList(s.getId(),index,dataList)){
+                    throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"绗��"+(1+index)+"琛屻�戝晢鍝佺紪鍙枫��"+s.getId()+"銆戝湪琛ㄦ牸涓噸澶�");
+                }
+                if(baseGoodsMapper.selectCount(new QueryWrapper<BaseGoods>().lambda().eq(BaseGoods::getIsdeleted, Constants.ZERO)
+                        .eq(BaseGoods::getBaseDataId,s.getId())
+                        .eq(BaseGoods::getOrigin,Constants.BasegoodsOrigin.imported))>0){
+                    throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"绗��"+(1+index)+"琛屻�戝晢鍝佺紪鍙枫��"+s.getId()+"銆戝凡瀵煎叆锛�");
                 }
 
                 BaseGoods baseGoods = new BaseGoods();
                 baseGoods.setCreator(user.getId());
+                baseGoods.setOrigin(Constants.BasegoodsOrigin.imported);
+                baseGoods.setBaseDataId(s.getId());
                 baseGoods.setCreateDate(new Date());
                 baseGoods.setEditor(user.getId());
                 baseGoods.setEditDate(new Date());
@@ -469,33 +449,34 @@
                 baseGoods.setZdPrice(new BigDecimal(s.getZdPrice()));
                 baseGoods.setPrice(new BigDecimal(s.getPrice()));
                 if (StringUtils.isBlank(s.getCategoryName())){
-                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"鍟嗗搧绫诲埆涓嶅彲涓虹┖");
+                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"绗��"+(1+index)+"琛屻�戝晢鍝佺被鍒笉鍙负绌�");
                 }
                 QueryWrapper<BaseCategory> categoryQuery = new QueryWrapper<>();
                 categoryQuery.lambda()
                     .eq(BaseCategory::getName,s.getCategoryName());
-                BaseCategory baseCategory = baseCategoryMapper.selectOne(categoryQuery);
+                categoryQuery.lambda()
+                    .eq(BaseCategory::getIsdeleted,Constants.ZERO);
+                BaseCategory baseCategory = baseCategoryMapper.selectOne(categoryQuery.last(" limit 1"));
                 if (Objects.isNull(baseCategory)){
-                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"鍟嗗搧绫诲埆涓嶅瓨鍦�");
+                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"绗��"+(1+index)+"琛屻�戝晢鍝佺被鍒��"+s.getCategoryName()+"銆戜笉瀛樺湪");
                 }
 
                 QueryWrapper<Brand> brandQuery = new QueryWrapper<>();
                 brandQuery.lambda()
+                        .eq(Brand::getType,Constants.ONE)
                         .eq(Brand::getName,s.getBrandName());
-                Brand brand = brandMapper.selectOne(brandQuery);
+                brandQuery.lambda()
+                        .eq(Brand::getIsdeleted,Constants.ZERO);
+                brandQuery.lambda()
+                        .eq(Brand::getType,Constants.ONE);
+                Brand brand = brandMapper.selectOne(brandQuery.last("limit 1"));
 
                 if (Objects.isNull(brand)){
-                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"鍟嗗搧鍝佺墝涓嶅瓨鍦�");
+                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"绗��"+(1+index)+"琛屻�戝晢鍝佸搧鐗屻��"+s.getBrandName()+"銆戜笉瀛樺湪");
                 }
-                //澶勭悊鎵归噺涓婁紶
-                String proDir =systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.PLATFORM).getCode();
-
-                String path = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.GOODS_IMG_DIR).getCode()
-                        + proDir + File.separator + s.getId();
-
+                String path =basePath+ s.getId();
                 List<String> mulFiles = new ArrayList<>();
                 if(StringUtils.isNotBlank(path)){
-                    OssModel ossModel = baseDataService.initOssModel();
                     File dir =new File(path+File.separator);
                     if(dir!=null && dir.isDirectory()){
                         File[]  files = dir.listFiles();
@@ -523,8 +504,6 @@
                         }
                     }
                 }
-
-
 //                baseGoods.setImgurl();
                 baseGoods.setCategoryId(baseCategory.getId());
                 baseGoods.setBrandId(brand.getId());
@@ -551,14 +530,13 @@
                 String baseGoodsParamString = s.getBaseGoodsParamString();
                 List<List<String>> collect = Arrays.asList(baseGoodsParamString.split("\n"))
                         .stream().map(s1 -> Arrays.asList(s1.split("[锛�,:]")) ).collect(Collectors.toList());
-                if (!CollectionUtils.isEmpty(collect)){
-//                    Integer i = 0;
-                    for (int i = 0; i < collect.size(); i++){
-                        if (!CollectionUtils.isEmpty(baseCategory.getBaseCateParamList())){
+                if (!CollectionUtils.isEmpty(collect)) {
+                    for (int i = 0; i < collect.size(); i++) {
+                        if (!CollectionUtils.isEmpty(baseCategory.getBaseCateParamList())) {
                             List<String> s2 = collect.get(i);
                             BaseCateParam baseCateParam = baseCategory.getBaseCateParamList()
                                     .stream().filter(s3 -> s3.getName().equals(s2.get(0))).findFirst()
-                                    .orElseThrow(()->new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"閰嶇疆鍙傛暟涓嶅瓨鍦�"));
+                                    .orElseThrow(() -> new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "閰嶇疆鍙傛暟銆愩�戜笉瀛樺湪"));
                             BaseGoodsParam baseGoodsParam = new BaseGoodsParam();
                             baseGoodsParam.setCreator(user.getId());
                             baseGoodsParam.setCreateDate(new Date());
@@ -568,18 +546,18 @@
                             baseGoodsParam.setName(baseCateParam.getName());
                             baseGoodsParam.setRemark(baseCateParam.getRemark());
                             baseGoodsParam.setStatus(Constants.ZERO);
-                            baseGoodsParam.setSortnum(i+Constants.ONE);
+                            baseGoodsParam.setSortnum(i + Constants.ONE);
                             baseGoodsParam.setPramaId(baseCateParam.getId());
-                            baseGoodsParam.setVal(s2.size() > 1 ? s2.get(1) : null );
+                            baseGoodsParam.setVal(s2.size() > 1 ? s2.get(1) : null);
                             baseGoodsParam.setGoodsId(baseGoods.getId());
                             baseGoodsParamMapper.insert(baseGoodsParam);
 
                         }
-                    };
-
+                    }
+                    ;
                 }
 
-            });
+            }
         }catch (Exception e) {
             log.error(String.format("鎵归噺鎻掑叆寮傚父%s ",e.getMessage()));
             throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),e.getMessage());
@@ -589,6 +567,15 @@
         return null;
     }
 
+    private boolean existedIdInList(String id,int index, List<BaseGoodsImportDTO> dataList) {
+        for (int j = 0; j <dataList.size(); j++) {
+            if(index!=j && StringUtils.equals(id,dataList.get(j).getId())){
+                return true;
+            }
+        }
+        return false;
+    }
+
     private boolean isImgFile(File f) {
         if(f!=null && f.isFile() ){
             String name = f.getName();

--
Gitblit v1.9.3