Browse Source

no message

FengChaoYu 2 weeks ago
parent
commit
c1c1e214c1

+ 24 - 7
mall-server-api/src/main/java/com/gree/mall/manager/controller/material/stock/WebsitStockController.java

@@ -7,12 +7,11 @@ import com.gree.mall.manager.bean.listvo.material.WebsitStockAccPVO;
 import com.gree.mall.manager.bean.listvo.material.WebsitStockAccVO;
 import com.gree.mall.manager.bean.listvo.material.WebsitStockPVO;
 import com.gree.mall.manager.bean.listvo.material.WebsitStockVO;
-import com.gree.mall.manager.bean.material.base.MaterialCategoryVO;
-import com.gree.mall.manager.bean.material.base.WebsitGoodsMVO;
+import com.gree.mall.manager.constant.Constant;
 import com.gree.mall.manager.enums.material.WebsitGoodsTypeEnum;
+import com.gree.mall.manager.exception.RemoteServiceException;
 import com.gree.mall.manager.helper.ResponseHelper;
 import com.gree.mall.manager.logic.material.stock.WebsitStockLogic;
-import com.gree.mall.manager.plus.entity.WebsitStockAcc;
 import com.gree.mall.manager.utils.excel.ExcelUtils;
 import com.gree.mall.manager.zfire.bean.ZfireParamBean;
 import com.gree.mall.manager.zfire.util.FieldUtils;
@@ -20,6 +19,7 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.integration.redis.util.RedisLockRegistry;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -27,10 +27,13 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.util.List;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Lock;
 
 @Slf4j
 @RestController
@@ -41,6 +44,8 @@ public class WebsitStockController {
 
     @Autowired
     WebsitStockLogic websitStockLogic;
+    @Resource
+    RedisLockRegistry redisLockRegistry;
 
     @ZfireList
     @PostMapping("list")
@@ -93,10 +98,22 @@ public class WebsitStockController {
 
     @PostMapping("importM")
     @ApiOperation("辅材网点库存-导入(模板名称:辅材网点库存.xlsx)")
-    public ResponseHelper importData(MultipartFile file) throws IOException {
-        List<Object> objects = ExcelUtils.importExcel(file);
-        websitStockLogic.importData(objects, WebsitGoodsTypeEnum.M);
-        return ResponseHelper.success();
+    public ResponseHelper importData(MultipartFile file) throws Exception {
+        Lock obtain = redisLockRegistry.obtain(Constant.RedisPrefix.LOCK_ORDER + 1);
+        if (!obtain.tryLock(10, TimeUnit.SECONDS)) {
+            throw new RemoteServiceException("导入冻结中");
+        }
+        try {
+            List<Object> objects = ExcelUtils.importExcel(file);
+            websitStockLogic.importData(objects, WebsitGoodsTypeEnum.M);
+            return ResponseHelper.success();
+        } catch (Exception e) {
+            log.error("【导入处理】失败", e);
+            throw e;
+        } finally {
+            obtain.unlock();
+        }
+
     }
 
 

+ 2 - 0
mall-server-api/src/main/java/com/gree/mall/manager/logic/material/stock/WebsitStockLogic.java

@@ -26,6 +26,7 @@ import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
 import java.util.*;
@@ -103,6 +104,7 @@ public class WebsitStockLogic {
      * 导入网点库存(各个商品只能导第一次)
      * @param datas
      */
+    @Transactional
     public void importData(List<Object> datas, WebsitGoodsTypeEnum websitGoodsTypeEnum){
         AdminUserCom adminUser = commonLogic.getAdminUser();
         List<WebsitStock> websitStocks = new ArrayList<>();