From 9abdd470fad3176e2e47eb259812f7939bcae0f1 Mon Sep 17 00:00:00 2001
From: k94314517 <8417338+k94314517@user.noreply.gitee.com>
Date: 星期三, 20 九月 2023 14:44:38 +0800
Subject: [PATCH] 基础字段
---
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/company/src/main/java/com/doumee/config/shiro/ShiroConfig.java | 14 +++---
server/service/src/main/java/com/doumee/service/business/GoodsService.java | 3 +
6 files changed, 58 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 42a7b24..800d123 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/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/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