|
|
@@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.uas.platform.b2b.constant.StringConstant;
|
|
|
import com.uas.platform.b2b.core.util.BoundedExecutor;
|
|
|
import com.uas.platform.b2b.core.util.ContextUtils;
|
|
|
+import com.uas.platform.b2b.core.util.SplitArray;
|
|
|
+import com.uas.platform.b2b.core.util.ThreadUtils;
|
|
|
import com.uas.platform.b2b.dao.CommonDao;
|
|
|
import com.uas.platform.b2b.dao.EnterpriseDao;
|
|
|
import com.uas.platform.b2b.dao.PurchaseApCheckDao;
|
|
|
@@ -63,6 +65,8 @@ import java.util.Set;
|
|
|
import java.util.concurrent.CountDownLatch;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.Executors;
|
|
|
+import java.util.concurrent.ScheduledThreadPoolExecutor;
|
|
|
+import java.util.concurrent.ThreadPoolExecutor;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -551,49 +555,88 @@ 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;
|
|
|
+ List<Vendor> resultVendors = vendors.stream().filter(customer -> null != customer.getApcheck() && customer.getApcheck() == 1).collect(Collectors.toList());
|
|
|
+ // 最大线程数
|
|
|
+ int maxRunSize = 10;
|
|
|
+ // 每组分发的List数量
|
|
|
+ int groupSize = (int) Math.ceil((double) resultVendors.size() / maxRunSize);
|
|
|
+ List<List<Vendor>> vendorsGroupList = SplitArray.splitAry(resultVendors, groupSize);
|
|
|
+ CountDownLatch threadsSignal = new CountDownLatch(vendorsGroupList.size());
|
|
|
+ vendorsGroupList.forEach(vendorList ->
|
|
|
+ vendorList.forEach(customer -> {
|
|
|
try {
|
|
|
- thisMonthTrades = getThisMonthTrade(enUU, customerUU, checkDate, fromDate, endDate);
|
|
|
+ executor.submitTask(() -> {
|
|
|
+ try {
|
|
|
+ this.countApCheck(customer, checkDate, fromDate, endDate);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ threadsSignal.countDown();
|
|
|
+ });
|
|
|
} 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();
|
|
|
- }
|
|
|
+ })
|
|
|
+ );
|
|
|
+ threadsSignal.await();
|
|
|
+ setVendorSPage(params, resultVendors, vendorSPage);
|
|
|
+ }
|
|
|
+ return vendorSPage;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 统计对账数据
|
|
|
+ *
|
|
|
+ * @param customer 客户信息
|
|
|
+ * @param checkDate 对账月份
|
|
|
+ * @param fromDate 起始时间
|
|
|
+ * @param endDate 截止时间
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void countApCheck(Vendor customer, String checkDate, Long fromDate, Long endDate) throws InterruptedException {
|
|
|
+ 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)) {
|
|
|
+ CountDownLatch threadsSignal = new CountDownLatch(2);
|
|
|
+ // 本月应收(未收)
|
|
|
+ executor.submitTask(() -> {
|
|
|
+ try {
|
|
|
+ List<ApCheckAmount> thisMonthTodoTrades = getThisMonthTodoTrade(vendorUU, customerUU, checkDate, fromDate, endDate);
|
|
|
customer.setThisMonthTodoCount(thisMonthTodoTrades);
|
|
|
- // 本月应收(已收)
|
|
|
- List<ApCheckAmount> thisMonthDoneTrades = null;
|
|
|
- try {
|
|
|
- thisMonthDoneTrades = getThisMonthDoneTrade(enUU, customerUU, checkDate, fromDate, endDate);
|
|
|
- } catch (InterruptedException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ threadsSignal.countDown();
|
|
|
+ });
|
|
|
+ // 本月应收(已收)
|
|
|
+ executor.submitTask(() -> {
|
|
|
+ try {
|
|
|
+ List<ApCheckAmount> thisMonthDoneTrades = getThisMonthDoneTrade(vendorUU, customerUU, checkDate, fromDate, endDate);
|
|
|
customer.setThisMonthDoneCount(thisMonthDoneTrades);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
+ threadsSignal.countDown();
|
|
|
});
|
|
|
- setVendorSPage(params, vendors, vendorSPage);
|
|
|
+ threadsSignal.await();
|
|
|
+ }
|
|
|
}
|
|
|
- return vendorSPage;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -606,16 +649,25 @@ public class PurchaseApCheckServiceImpl implements PurchaseApCheckService {
|
|
|
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(filterVendors)) {
|
|
|
+ // 起始序号
|
|
|
+ int startIndex = (params.getPage() - 1) * params.getCount();
|
|
|
+ // 截止序号
|
|
|
+ int endIndex = params.getPage() * params.getCount();
|
|
|
+ // 筛选后的总数
|
|
|
+ int totalCount = filterVendors.size();
|
|
|
+ // 筛选后的总页码
|
|
|
+ int totalPage = (int) Math.ceil((double) 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);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -671,7 +723,7 @@ public class PurchaseApCheckServiceImpl implements PurchaseApCheckService {
|
|
|
public List<ApCheckAmount> getThisMonthTodoTrade(Long enUU, Long customerUU, String checkDate, Long fromDate, Long endDate) throws InterruptedException {
|
|
|
DateFilter filter = erpProdIODetailService.initFilter(fromDate, endDate, checkDate);
|
|
|
List<ApCheckAmount> totalTrades = new ArrayList<>();
|
|
|
- final CountDownLatch threadsSignal = new CountDownLatch(5);
|
|
|
+ CountDownLatch threadsSignal = new CountDownLatch(5);
|
|
|
// 货款调账
|
|
|
executor.submitTask(() -> {
|
|
|
List<ApCheckAmount> trades = commonDao.query(ApCheckeTodoCountSqls.THISMONTH_ADJUSTMENT_COUNT_SQL, ApCheckAmount.class, enUU, customerUU, filter.getFromDate(), filter.getEndDate());
|
|
|
@@ -748,38 +800,38 @@ public class PurchaseApCheckServiceImpl implements PurchaseApCheckService {
|
|
|
public List<ApCheckAmount> getThisMonthDoneTrade(Long enUU, Long customerUU, String checkDate, Long fromDate, Long endDate) throws InterruptedException {
|
|
|
DateFilter filter = erpProdIODetailService.initFilter(fromDate, endDate, checkDate);
|
|
|
List<ApCheckAmount> totalTrades = new ArrayList<>();
|
|
|
- final CountDownLatch threadsSignal = new CountDownLatch(5);
|
|
|
// 货款调账
|
|
|
+ CountDownLatch finalThreadsSignal = new CountDownLatch(5);
|
|
|
executor.submitTask(() -> {
|
|
|
List<ApCheckAmount> trades = commonDao.query(ApCheckeDoneCountSqls.THISMONTH_ADJUSTMENT_COUNT_SQL, ApCheckAmount.class, enUU, customerUU, filter.getFromDate(), filter.getEndDate());
|
|
|
totalTrades.addAll(trades);
|
|
|
- threadsSignal.countDown();
|
|
|
+ finalThreadsSignal.countDown();
|
|
|
});
|
|
|
// 采购验收
|
|
|
executor.submitTask(() -> {
|
|
|
List<ApCheckAmount> trades = commonDao.query(ApCheckeDoneCountSqls.THISMONTH_SALE_ACCEPT_COUNT_SQL, ApCheckAmount.class, enUU, customerUU, filter.getFromDate(), filter.getEndDate());
|
|
|
totalTrades.addAll(trades);
|
|
|
- threadsSignal.countDown();
|
|
|
+ finalThreadsSignal.countDown();
|
|
|
});
|
|
|
// 采购验退
|
|
|
executor.submitTask(() -> {
|
|
|
List<ApCheckAmount> trades = commonDao.query(ApCheckeDoneCountSqls.THISMONTH_SALE_RETURN_COUNT_SQL, ApCheckAmount.class, enUU, customerUU, filter.getFromDate(), filter.getEndDate());
|
|
|
totalTrades.addAll(trades);
|
|
|
- threadsSignal.countDown();
|
|
|
+ finalThreadsSignal.countDown();
|
|
|
});
|
|
|
// 委外验收
|
|
|
executor.submitTask(() -> {
|
|
|
List<ApCheckAmount> trades = commonDao.query(ApCheckeDoneCountSqls.THISMONTH_MAKE_ACCEPT_COUNT_SQL, ApCheckAmount.class, enUU, customerUU, filter.getFromDate(), filter.getEndDate());
|
|
|
totalTrades.addAll(trades);
|
|
|
- threadsSignal.countDown();
|
|
|
+ finalThreadsSignal.countDown();
|
|
|
});
|
|
|
// 委外验退
|
|
|
executor.submitTask(() -> {
|
|
|
List<ApCheckAmount> trades = commonDao.query(ApCheckeDoneCountSqls.THISMONTH_MAKE_RETURN_COUNT_SQL, ApCheckAmount.class, enUU, customerUU, filter.getFromDate(), filter.getEndDate());
|
|
|
totalTrades.addAll(trades);
|
|
|
- threadsSignal.countDown();
|
|
|
+ finalThreadsSignal.countDown();
|
|
|
});
|
|
|
- threadsSignal.await();
|
|
|
+ finalThreadsSignal.await();
|
|
|
return groupCountByCurrency(totalTrades);
|
|
|
}
|
|
|
|