From bc1431d55206a8c5506bd3f2338852b5e2e9fc1d Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期三, 20 九月 2023 15:12:25 +0800
Subject: [PATCH] Merge branch 'dev' of http://139.186.142.91:10010/r/productDev/preselect into dev
---
 server/service/src/main/java/com/doumee/service/impl/CateParamSelectServiceImpl.java |    2 +
 server/company/src/main/java/com/doumee/api/business/GoodsController.java            |    3 +
 server/service/src/main/java/com/doumee/service/business/impl/GoodsServiceImpl.java  |   63 +++++++++++++++++++++----------
 server/service/src/main/java/com/doumee/core/utils/Constants.java                    |    1 
 server/service/src/main/java/com/doumee/dao/business/model/Brand.java                |    3 +
 server/company/src/main/java/com/doumee/config/shiro/ShiroConfig.java                |   14 +++---
 server/service/src/main/java/com/doumee/service/business/GoodsService.java           |    3 +
 server/service/src/main/java/com/doumee/service/business/impl/BrandServiceImpl.java  |    2 +
 8 files changed, 63 insertions(+), 28 deletions(-)
diff --git a/server/company/src/main/java/com/doumee/api/business/GoodsController.java b/server/company/src/main/java/com/doumee/api/business/GoodsController.java
index 1273ad4..08ef511 100644
--- a/server/company/src/main/java/com/doumee/api/business/GoodsController.java
+++ b/server/company/src/main/java/com/doumee/api/business/GoodsController.java
@@ -66,9 +66,10 @@
     @PostMapping("/createPlat")
     @RequiresPermissions("business:goods:create")
     public ApiResponse createPlat(@RequestBody GoodCreatePlatRequest param) {
+        goodsService.openSyncSwitch();
         goodsService.createPlat(param);
         cateParamSelectService.dealCateParamSelect();
-        return ApiResponse.success("鎿嶄綔鎴愬姛");
+        return ApiResponse.success("鍚屾鎿嶄綔鎴愬姛锛岃绋嶅悗鍒锋柊鏌ョ湅鍟嗗搧鍚屾淇℃伅");
     }
 
     @ApiOperation("鏍规嵁ID鍒犻櫎")
diff --git a/server/company/src/main/java/com/doumee/config/shiro/ShiroConfig.java b/server/company/src/main/java/com/doumee/config/shiro/ShiroConfig.java
index c9bee5f..fdd05c9 100644
--- a/server/company/src/main/java/com/doumee/config/shiro/ShiroConfig.java
+++ b/server/company/src/main/java/com/doumee/config/shiro/ShiroConfig.java
@@ -107,13 +107,13 @@
         map.put("/public/uploadLocal","anon");
 
 
-        map.put("/business/company/register", "anon");
-        map.put("/business/labels/page","anon");
-        map.put("/business/*/list","anon");
-        map.put("/business/goods/goodsPage","anon");
-        map.put("/business/goods/h5Image","anon");
-        map.put("/business/goods/export","anon");
-        map.put("/business/goods/listForH5","anon");
+//        map.put("/business/company/register", "anon");
+//        map.put("/business/labels/page","anon");
+//        map.put("/business/*/list","anon");
+//        map.put("/business/goods/goodsPage","anon");
+//        map.put("/business/goods/h5Image","anon");
+//        map.put("/business/goods/export","anon");
+//        map.put("/business/goods/listForH5","anon");
 
 
         // - 鏀捐swagger
diff --git a/server/service/src/main/java/com/doumee/core/utils/Constants.java b/server/service/src/main/java/com/doumee/core/utils/Constants.java
index 26b3869..4d777fa 100644
--- a/server/service/src/main/java/com/doumee/core/utils/Constants.java
+++ b/server/service/src/main/java/com/doumee/core/utils/Constants.java
@@ -30,6 +30,7 @@
     public static final String PK_IMG = "PK_IMG";
     public static final String RANGE_SIZE = "RANGE_SIZE";
     public static final String CATE_PARAM_OPEN = "_CATE_PARAM_OPEN";
+    public static final String OPEN_SYNC_SWITCH = "OPEN_SYNC_SWITCH";
 
 
     public static final String SYSTEM ="SYSTEM";
diff --git a/server/service/src/main/java/com/doumee/dao/business/model/Brand.java b/server/service/src/main/java/com/doumee/dao/business/model/Brand.java
index 38d8d31..0869843 100644
--- a/server/service/src/main/java/com/doumee/dao/business/model/Brand.java
+++ b/server/service/src/main/java/com/doumee/dao/business/model/Brand.java
@@ -77,4 +77,7 @@
     @TableField(exist = false)
     private String imgfullurl;
 
+    @ApiModelProperty(value = "鍒嗙被涓婚敭")
+    @TableField(exist = false)
+    private Integer categoryId;
 }
diff --git a/server/service/src/main/java/com/doumee/service/business/GoodsService.java b/server/service/src/main/java/com/doumee/service/business/GoodsService.java
index 7be8af6..59d7ac4 100644
--- a/server/service/src/main/java/com/doumee/service/business/GoodsService.java
+++ b/server/service/src/main/java/com/doumee/service/business/GoodsService.java
@@ -123,4 +123,7 @@
     List<Goods> findListForH5(GoodsRequest goodsRequest);
 
     Integer createPlat(GoodCreatePlatRequest param);
+
+    void openSyncSwitch();
+
 }
diff --git a/server/service/src/main/java/com/doumee/service/business/impl/BrandServiceImpl.java b/server/service/src/main/java/com/doumee/service/business/impl/BrandServiceImpl.java
index 0dd7643..9db3591 100644
--- a/server/service/src/main/java/com/doumee/service/business/impl/BrandServiceImpl.java
+++ b/server/service/src/main/java/com/doumee/service/business/impl/BrandServiceImpl.java
@@ -161,6 +161,8 @@
         if (Constants.equalsInteger(user.getType(), Constants.UserType.SYSTEM.getKey())) {
             wrapper.lambda().eq(Brand::getType,Constants.ONE);
         }else {
+            wrapper.lambda().exists(!Objects.isNull(brand.getCategoryId())," select 1 from goods g where g.brand_id = brand.id and g.category_id = "+brand.getCategoryId()+" and  g.COMPANY_ID = "+user.getCompanyId()+" " +
+                    " and g.STATUS = 0 and g.ISDELETED = 0  ");
             wrapper.lambda().and(i->i.eq(Brand::getCompanyId,user.getCompanyId())
                             .or().eq(Brand::getType,Constants.ONE)
             );
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..f5de5ee 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
@@ -29,6 +29,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;
@@ -82,7 +84,8 @@
     @Autowired
     private CateParamSelectMapper cateParamSelectMapper;
 
-
+    @Autowired
+    private RedisTemplate redisTemplate;
 
 
     @Override
@@ -130,6 +133,8 @@
 
         return goods.getId();
     }
+
+    @Async
     @Override
     @Transactional( rollbackFor = {Exception.class, BusinessException.class})
     public  Integer createPlat(GoodCreatePlatRequest param){
@@ -177,25 +182,30 @@
         }
         List<Multifile> multifileList = new ArrayList<>();
         List<GoodsParam> goodsParamList = new ArrayList<>();
-        for(BaseGoods model : goodsList){
-            //閬嶅巻骞冲彴鍟嗗搧淇℃伅锛岃繘琛屽晢鍝佷俊鎭悓姝�
-            Goods goods = initGoodsPlatParam(user,model,param);
-            if(goods == null){
-                continue;
+        try{
+            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);
             }
-            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);
+            }
+        }catch (Exception e){
+           e.printStackTrace();
+        }finally {
+            redisTemplate.opsForValue().set(user.getCompanyId()+Constants.OPEN_SYNC_SWITCH,false);
         }
-        if(multifileList.size()>0){
-            multifileMapper.insertBatch(multifileList);
-        }
-        if(goodsParamList.size()>0){
-            goodsParamMapper.insertBatch(goodsParamList);
-        }
-
         return 1;
     }
 
@@ -297,6 +307,7 @@
                     return p.getPrice().setScale(0,BigDecimal.ROUND_CEILING);
                 }
             }
+            throw new BusinessException(ResponseStatus.DATA_ERRO.getCode(),"鏁版嵁寮傚父璇峰埛鏂伴噸璇�");
         }
         //濡傛灉娌℃湁閰嶇疆鍏ユ墜浠凤紝瀹夎鍔犱环绯绘暟鏉ヨ绠�
 //        if(model.getCateRatePrice()==null){
@@ -760,8 +771,8 @@
                 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());
@@ -1128,5 +1139,17 @@
         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);
+    }
 }
 
diff --git a/server/service/src/main/java/com/doumee/service/impl/CateParamSelectServiceImpl.java b/server/service/src/main/java/com/doumee/service/impl/CateParamSelectServiceImpl.java
index 59d7d66..62bd13a 100644
--- a/server/service/src/main/java/com/doumee/service/impl/CateParamSelectServiceImpl.java
+++ b/server/service/src/main/java/com/doumee/service/impl/CateParamSelectServiceImpl.java
@@ -173,4 +173,6 @@
             redisTemplate.opsForValue().set(loginUserInfo.getCompanyId()+Constants.CATE_PARAM_OPEN,false);
         }
     }
+
+
 }
--
Gitblit v1.9.3