فهرست منبع

个人产品库批量导入方法修改

dongbw 8 سال پیش
والد
کامیت
11a466af5f

+ 41 - 0
src/main/java/com/uas/platform/b2b/ps/ProductUtils.java

@@ -133,6 +133,47 @@ public class ProductUtils {
         return map;
     }
 
+    /**
+     * 分页批量更新物料并添加到个人产品库
+     *
+     * @author dongbw
+     * @param  products 要保存的物料信息
+     * @return map结果
+     * @throws Exception
+     */
+    public static ModelMap paginationUpdateAndAddToProductUser(List<Product> products) throws Exception {
+        ModelMap map = new ModelMap();
+        int result = 0;
+        if (!CollectionUtils.isEmpty(products)) {
+            if (products.size() <= ONE_TIME_DATA_SIZE) {
+                map = updateProdInfoAndAddToProductUser(products);
+            } else {
+                List<Product> pageContent = new ArrayList<>();
+                int i = 1;
+                for (Product product : products) {
+                    pageContent.add(product);
+                    if (i++ % ONE_TIME_DATA_SIZE == 0) {
+                        ModelMap modelMap = updateProdInfoAndAddToProductUser(pageContent);
+                        if ("false".equals(modelMap.get("success")) && null != modelMap.get("message")) {
+                            map.put("message", modelMap.get("message"));
+                        }
+                        result += (int) (null != modelMap.get("result") ? modelMap.get("result") : 0);
+                        pageContent = new ArrayList<>();
+                    }
+                }
+                if (!pageContent.isEmpty()) {
+                    ModelMap modelMap = updateProdInfoAndAddToProductUser(pageContent);
+                    if ("false".equals(modelMap.get("success")) && null != modelMap.get("message")) {
+                        map.put("message", modelMap.get("message"));
+                    }
+                    result += (int) (null != modelMap.get("result") ? modelMap.get("result") : 0);
+                }
+            }
+        }
+        map.put("result", result);
+        return map;
+    }
+
 
     /**
      * 批量更新个人物料

+ 1 - 1
src/main/java/com/uas/platform/b2b/service/impl/ProductUsersServiceImpl.java

@@ -342,7 +342,7 @@ public class ProductUsersServiceImpl implements ProductUsersService {
             start = System.currentTimeMillis();
             try {
                 // 更新物料并插入个人物料
-                ModelMap map = ProductUtils.updateProdInfoAndAddToProductUser(products);
+                ModelMap map = ProductUtils.paginationUpdateAndAddToProductUser(products);
                 System.out.println("更新物料:" + (System.currentTimeMillis() - start));
                 if ("true".equals(map.get("success"))) {
                     modelMap.put("success", null != map.get("result") ? map.get("result") : 0);