ソースを参照

feat: 应收应付对账返回方法调整优化

hejq 7 年 前
コミット
e816324ba2

+ 18 - 0
src/main/java/com/uas/platform/b2b/core/util/BoundedExecutor.java

@@ -1,5 +1,7 @@
 package com.uas.platform.b2b.core.util;
 
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.Executor;
 import java.util.concurrent.RejectedExecutionException;
 import java.util.concurrent.Semaphore;
@@ -37,4 +39,20 @@ public class BoundedExecutor {
 			semaphore.release();
 		}
 	}
+
+
+    public void submitTasks(final List<Runnable> commands,  CountDownLatch threadsSignal)
+        throws InterruptedException {
+        semaphore.acquire();
+        commands.forEach(command -> {
+            executor.execute(() -> {
+                try {
+                    command.run();
+                } finally {
+                    semaphore.release();
+                    threadsSignal.countDown();
+                }
+            });
+        });
+    }
 }

+ 9 - 12
src/main/java/com/uas/platform/b2b/service/impl/PurchaseApBillServiceImpl.java

@@ -244,19 +244,16 @@ public class PurchaseApBillServiceImpl implements PurchaseApBillService {
         List<Vendor> vendors = findVendorByPage(params, keyword);
         SPage<Vendor> vendorSPage = new SPage<>();
         if (!org.springframework.util.CollectionUtils.isEmpty(vendors)) {
-            List<Vendor> filterVendors = vendors.stream().filter(customer -> null != customer.getApcheck() && customer.getApcheck() == 1).collect(Collectors.toList());
+            vendors.stream().filter(customer -> null != customer.getApcheck() && customer.getApcheck() == 1).collect(Collectors.toList());
             final CountDownLatch threadsSignal = new CountDownLatch(1);
-            filterVendors.forEach(customer -> {
-                try {
-                    executor.submitTask(() -> {
-                        purchaseApCheckService.countApCheck(customer, checkDate, fromDate, endDate);
-                        threadsSignal.countDown();
-                    });
-                    threadsSignal.await();
-                } catch (InterruptedException e) {
-                    e.printStackTrace();
-                }
-            });
+            List<Runnable> runnableList = new ArrayList<>();
+            vendors.forEach(customer ->
+                runnableList.add(() ->
+                    purchaseApCheckService.countApCheck(customer, checkDate, fromDate, endDate)
+                )
+            );
+            executor.submitTasks(runnableList, threadsSignal);
+            threadsSignal.await();
             purchaseApCheckService.setVendorSPage(params, vendors, vendorSPage);
         }
         return vendorSPage;

+ 9 - 12
src/main/java/com/uas/platform/b2b/service/impl/PurchaseApCheckServiceImpl.java

@@ -555,19 +555,16 @@ public class PurchaseApCheckServiceImpl implements PurchaseApCheckService {
         List<Vendor> vendors = findCustomerByPage(params, keyword);
         SPage<Vendor> vendorSPage = new SPage<>();
         if (!CollectionUtils.isEmpty(vendors)) {
-            List<Vendor> filterVendors = vendors.stream().filter(customer -> null != customer.getApcheck() && customer.getApcheck() == 1).collect(Collectors.toList());
+            vendors.stream().filter(customer -> null != customer.getApcheck() && customer.getApcheck() == 1).collect(Collectors.toList());
             final CountDownLatch threadsSignal = new CountDownLatch(1);
-            filterVendors.forEach(customer -> {
-                try {
-                    executor.submitTask(() -> {
-                        this.countApCheck(customer, checkDate, fromDate, endDate);
-                        threadsSignal.countDown();
-                    });
-                    threadsSignal.await();
-                } catch (InterruptedException e) {
-                    e.printStackTrace();
-                }
-            });
+            List<Runnable> runnableList = new ArrayList<>();
+            vendors.forEach(customer ->
+                runnableList.add(() ->
+                    this.countApCheck(customer, checkDate, fromDate, endDate)
+                )
+            );
+            executor.submitTasks(runnableList, threadsSignal);
+            threadsSignal.await();
             setVendorSPage(params, vendors, vendorSPage);
         }
         return vendorSPage;