Эх сурвалжийг харах

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

hejq 7 жил өмнө
parent
commit
4044aed407

+ 1 - 1
src/main/java/com/uas/platform/b2b/controller/SaleApCheckController.java

@@ -211,7 +211,7 @@ public class SaleApCheckController {
      * @return 符合条件的客户信息
      */
     @RequestMapping(value = "/customer", method = RequestMethod.GET)
-    public SPage<Vendor> getCustomers(PageParams params, String keyword, String checkDate, String searchFilter) {
+    public SPage<Vendor> getCustomers(PageParams params, String keyword, String checkDate, String searchFilter) throws InterruptedException {
         logger.log("应收对账单", "获取客户信息", "获取所有符合条件的客户");
         SearchFilter filter = JSONObject.parseObject(searchFilter, SearchFilter.class);
         return purchaseApCheckService.getCustomerInfo(params, keyword, checkDate, filter.getFromDate(), filter.getEndDate());

+ 1 - 1
src/main/java/com/uas/platform/b2b/controller/SaleArCheckController.java

@@ -46,7 +46,7 @@ public class SaleArCheckController {
      * @return 符合条件的供应商
      */
     @RequestMapping(value = "/vendor", method = RequestMethod.GET)
-    public SPage<Vendor> getVendors(PageParams params, String keyword, String checkDate, String searchFilter) {
+    public SPage<Vendor> getVendors(PageParams params, String keyword, String checkDate, String searchFilter) throws InterruptedException {
         logger.log("应付对账单", "获取供应商信息", "获取所有符合条件的供应商");
         SearchFilter filter = JSONObject.parseObject(searchFilter, SearchFilter.class);
         return purchaseApBillService.getVendorInfo(params, keyword, checkDate, filter.getFromDate(), filter.getEndDate());

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

@@ -107,7 +107,7 @@ public interface PurchaseApBillService {
      * @param endDate 截止时间
      * @return 符合条件的供应商
      */
-    SPage<Vendor> getVendorInfo(PageParams params, String keyword, String checkDate, Long fromDate, Long endDate);
+    SPage<Vendor> getVendorInfo(PageParams params, String keyword, String checkDate, Long fromDate, Long endDate) throws InterruptedException;
 
     /**
      * 通过日期筛选,筛选出超出默认日期的单据

+ 12 - 1
src/main/java/com/uas/platform/b2b/service/PurchaseApCheckService.java

@@ -143,7 +143,7 @@ public interface PurchaseApCheckService {
      * @param endDate 截止时间
      * @return 搜索结果
      */
-    SPage<Vendor> getCustomerInfo(PageParams params, String keyword, String checkDate,  Long fromDate, Long endDate);
+    SPage<Vendor> getCustomerInfo(PageParams params, String keyword, String checkDate,  Long fromDate, Long endDate) throws InterruptedException;
 
     /**
      * 获取总的应收金额
@@ -187,6 +187,7 @@ public interface PurchaseApCheckService {
      * @param fromDate 开始时间
      * @param endDate 截止时间
      * @return 统计结果
+     * @throws InterruptedException 中断异常
      */
     List<ApCheckAmount> getThisMonthDoneTrade(Long enUU, Long customerUU, String checkDate, Long fromDate, Long endDate) throws InterruptedException;
 
@@ -205,4 +206,14 @@ public interface PurchaseApCheckService {
      * @param vendorSPage 分页处理
      */
     void setVendorSPage(PageParams params, List<Vendor> vendors, SPage<Vendor> vendorSPage);
+
+    /**
+     * 统计对账数据
+     *
+     * @param customer 客户信息
+     * @param checkDate 对账月份
+     * @param fromDate 起始时间
+     * @param endDate 截止时间
+     */
+    void countApCheck(Vendor customer, String checkDate, Long fromDate, Long endDate);
 }

+ 15 - 38
src/main/java/com/uas/platform/b2b/service/impl/PurchaseApBillServiceImpl.java

@@ -54,6 +54,7 @@ import java.util.List;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
+import java.util.stream.Collectors;
 
 /**
  * 采购发票
@@ -239,47 +240,23 @@ public class PurchaseApBillServiceImpl implements PurchaseApBillService {
      * @return 符合条件的供应商
      */
     @Override
-    public SPage<Vendor> getVendorInfo(com.uas.platform.core.model.PageParams params, String keyword, String checkDate, Long fromDate, Long endDate) {
+    public SPage<Vendor> getVendorInfo(com.uas.platform.core.model.PageParams params, String keyword, String checkDate, Long fromDate, Long endDate) throws InterruptedException {
         List<Vendor> vendors = findVendorByPage(params, keyword);
-        final Long enUU = SystemSession.getUser().getEnterprise().getUu();
         SPage<Vendor> vendorSPage = new SPage<>();
         if (!org.springframework.util.CollectionUtils.isEmpty(vendors)) {
-            vendors.stream().filter(customer -> null != customer.getApcheck() && customer.getApcheck() == 1)
-                .forEach(customer -> {
-                    Long vendorUU = customer.getVendEnUU();
-                    if (!com.uas.ps.core.util.StringUtils.isEmpty(customer.getTotalCountString())) {
-                        List<ApCheckAmount> tradeCounts = JSON.parseArray(customer.getTotalCountString(), ApCheckAmount.class);
-                        customer.setTotalCount(tradeCounts);
-                    }
-                    // 本月应付(总额)
-                    List<ApCheckAmount> thisMonthAllTrades = null;
-                    try {
-                        thisMonthAllTrades = purchaseApCheckService.getThisMonthTrade(vendorUU, enUU, checkDate, fromDate, endDate);
-                    } catch (InterruptedException e) {
-                        e.printStackTrace();
-                    }
-                    customer.setThisMonthCount(thisMonthAllTrades);
-                    // 本月应付存在再进行分类查询
-                    if (!CollectionUtil.isEmpty(thisMonthAllTrades)) {
-                        // 本月应付(未付)
-                        List<ApCheckAmount> thisMonthTodoTrades = null;
-                        try {
-                            thisMonthTodoTrades = purchaseApCheckService.getThisMonthTodoTrade(vendorUU, enUU, checkDate, fromDate, endDate);
-                        } catch (InterruptedException e) {
-                            e.printStackTrace();
-                        }
-                        customer.setThisMonthTodoCount(thisMonthTodoTrades);
-                        // 本月应付(已付)
-                        List<ApCheckAmount> thisMonthDoneTrades = null;
-                        try {
-                            thisMonthDoneTrades = purchaseApCheckService.getThisMonthDoneTrade(vendorUU, enUU, checkDate, fromDate, endDate);
-                        } catch (InterruptedException e) {
-                            e.printStackTrace();
-                        }
-                        customer.setThisMonthDoneCount(thisMonthDoneTrades);
-                    }
-
-                });
+            List<Vendor> filterVendors = 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();
+                    });
+                } catch (InterruptedException e) {
+                    e.printStackTrace();
+                }
+            });
+            threadsSignal.await();
             purchaseApCheckService.setVendorSPage(params, vendors, vendorSPage);
         }
         return vendorSPage;

+ 80 - 49
src/main/java/com/uas/platform/b2b/service/impl/PurchaseApCheckServiceImpl.java

@@ -551,51 +551,73 @@ public class PurchaseApCheckServiceImpl implements PurchaseApCheckService {
      * @return 搜索结果
      */
     @Override
-    public SPage<Vendor> getCustomerInfo(PageParams params, String keyword, String checkDate, Long fromDate, Long endDate) {
+    public SPage<Vendor> getCustomerInfo(PageParams params, String keyword, String checkDate, Long fromDate, Long endDate) throws InterruptedException {
         List<Vendor> vendors = findCustomerByPage(params, keyword);
-        final Long enUU = SystemSession.getUser().getEnterprise().getUu();
         SPage<Vendor> vendorSPage = new SPage<>();
         if (!CollectionUtils.isEmpty(vendors)) {
-            vendors.stream().filter(customer -> null != customer.getApcheck() && customer.getApcheck() == 1)
-                .forEach(customer -> {
-                    Long customerUU = customer.getMyEnUU();
-                    if (!StringUtils.isEmpty(customer.getTotalCountString())) {
-                        List<ApCheckAmount> tradeCounts = JSON.parseArray(customer.getTotalCountString(), ApCheckAmount.class);
-                        customer.setTotalCount(tradeCounts);
-                    }
-                    // 本月应收(总额)
-                    List<ApCheckAmount> thisMonthTrades = null;
-                    try {
-                        thisMonthTrades = getThisMonthTrade(enUU, customerUU, checkDate, fromDate, endDate);
-                    } catch (InterruptedException e) {
-                        e.printStackTrace();
-                    }
-                    customer.setThisMonthCount(thisMonthTrades);
-                    // 总额存在再进行其他查询
-                    if (!CollectionUtils.isEmpty(thisMonthTrades)) {
-                        // 本月应收(未收)
-                        List<ApCheckAmount> thisMonthTodoTrades = null;
-                        try {
-                            thisMonthTodoTrades = getThisMonthTodoTrade(enUU, customerUU, checkDate, fromDate, endDate);
-                        } catch (InterruptedException e) {
-                            e.printStackTrace();
-                        }
-                        customer.setThisMonthTodoCount(thisMonthTodoTrades);
-                        // 本月应收(已收)
-                        List<ApCheckAmount> thisMonthDoneTrades = null;
-                        try {
-                            thisMonthDoneTrades = getThisMonthDoneTrade(enUU, customerUU, checkDate, fromDate, endDate);
-                        } catch (InterruptedException e) {
-                            e.printStackTrace();
-                        }
-                        customer.setThisMonthDoneCount(thisMonthDoneTrades);
-                    }
-                });
+            List<Vendor> filterVendors = 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();
+                    });
+                } catch (InterruptedException e) {
+                    e.printStackTrace();
+                }
+            });
+            threadsSignal.await();
             setVendorSPage(params, vendors, vendorSPage);
         }
         return vendorSPage;
     }
 
+    /**
+     * 统计对账数据
+     *
+     * @param customer 客户信息
+     * @param checkDate 对账月份
+     * @param fromDate 起始时间
+     * @param endDate 截止时间
+     */
+    @Override
+    public void countApCheck(Vendor customer, String checkDate, Long fromDate, Long endDate) {
+        final Long customerUU = customer.getMyEnUU();
+        final Long vendorUU = customer.getVendEnUU();
+        if (!StringUtils.isEmpty(customer.getTotalCountString())) {
+            List<ApCheckAmount> tradeCounts = JSON.parseArray(customer.getTotalCountString(), ApCheckAmount.class);
+            customer.setTotalCount(tradeCounts);
+            // 本月应收(总额)
+            List<ApCheckAmount> thisMonthTrades = null;
+            try {
+                thisMonthTrades = getThisMonthTrade(vendorUU, customerUU, checkDate, fromDate, endDate);
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
+            customer.setThisMonthCount(thisMonthTrades);
+            // 总额存在再进行其他查询
+            if (!CollectionUtils.isEmpty(thisMonthTrades)) {
+                // 本月应收(未收)
+                List<ApCheckAmount> thisMonthTodoTrades = null;
+                try {
+                    thisMonthTodoTrades = getThisMonthTodoTrade(vendorUU, customerUU, checkDate, fromDate, endDate);
+                } catch (InterruptedException e) {
+                    e.printStackTrace();
+                }
+                customer.setThisMonthTodoCount(thisMonthTodoTrades);
+                // 本月应收(已收)
+                List<ApCheckAmount> thisMonthDoneTrades = null;
+                try {
+                    thisMonthDoneTrades = getThisMonthDoneTrade(vendorUU, customerUU, checkDate, fromDate, endDate);
+                } catch (InterruptedException e) {
+                    e.printStackTrace();
+                }
+                customer.setThisMonthDoneCount(thisMonthDoneTrades);
+            }
+        }
+    }
+
     /**
      * 设置供应商信息
      * @param params 分页参数
@@ -604,18 +626,27 @@ public class PurchaseApCheckServiceImpl implements PurchaseApCheckService {
      */
     @Override
     public void setVendorSPage(PageParams params, List<Vendor> vendors, SPage<Vendor> vendorSPage) {
-        List<Vendor> filterVendors = vendors.stream()
-            .filter(vendor -> (null != vendor.getThisMonthCount() && !CollectionUtils.isEmpty(vendor.getThisMonthCount()))).collect(Collectors.toList());
-        int startIndex = (params.getPage() - 1) * params.getCount();
-        int endIndex = params.getPage() * params.getCount();
-        int totalCount = filterVendors.size();
-        int totalPage = (int) Math.ceil(totalCount / params.getCount());
-        vendorSPage.setTotalElement(filterVendors.size());
-        vendorSPage.setTotalPage(totalPage);
-        vendorSPage.setPage(params.getPage());
-        vendorSPage.setSize(params.getCount());
-        List<Vendor> vendorList = filterVendors.subList(startIndex, endIndex > totalCount ? totalCount : endIndex);
-        vendorSPage.setContent(vendorList);
+        if (!CollectionUtils.isEmpty(vendors)) {
+            List<Vendor> filterVendors = vendors.stream()
+                .filter(vendor -> (null != vendor.getThisMonthCount() && !CollectionUtils.isEmpty(vendor.getThisMonthCount()))).collect(Collectors.toList());
+            // 起始序号
+            int startIndex = (params.getPage() - 1) * params.getCount();
+            // 截止序号
+            int endIndex = params.getPage() * params.getCount();
+            // 筛选后的总数
+            int totalCount = filterVendors.size();
+            // 筛选后的总页码
+            int totalPage = (int) Math.ceil(totalCount / params.getCount());
+            // 默认起始序号
+            int defaultIndex = totalPage * params.getCount();
+            vendorSPage.setTotalElement(filterVendors.size());
+            vendorSPage.setTotalPage(totalPage);
+            vendorSPage.setPage(params.getPage() > totalPage ? totalPage : params.getPage());
+            vendorSPage.setSize(params.getCount());
+            // 如果前端传入页码值过大,返回能取到的最大值页面及获取相关数据
+            List<Vendor> vendorList = filterVendors.subList(startIndex > totalCount ? defaultIndex : startIndex, endIndex > totalCount ? totalCount : endIndex);
+            vendorSPage.setContent(vendorList);
+        }
     }
 
     /**