|
@@ -37,9 +37,6 @@ import org.springframework.util.CollectionUtils;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.util.*;
|
|
|
-import java.util.concurrent.CountDownLatch;
|
|
|
-import java.util.concurrent.ExecutorService;
|
|
|
-import java.util.concurrent.Executors;
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -249,42 +246,10 @@ public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocat
|
|
|
if (CollectionUtils.isEmpty(targetResponsibilityList)) {
|
|
|
throw new CostException(String.format("[%s-%s]的分摊目标层级没有对应的责任中心",shareLevelVO.getLeverSort(),shareLevelVO.getShareName()));
|
|
|
}
|
|
|
- //按责任中心逐个开始分摊
|
|
|
- for (Responsibility responsibility : responsibilities) {
|
|
|
- //分摊一个责任中心的成本
|
|
|
- List<Allocation> allocationRespCosts = allocationResponsibilityCost(startDTO, shareLevelVO, responsibility, targetResponsibilityList, respDirectCostMap, respParamValueList,
|
|
|
- accountShareResponsibilityMap, costAccountShareParamMap, costAccountShareDetailMap,costAccountShareTargetMap, allocationCostList, timeMillis);
|
|
|
- allocationList.addAll(allocationRespCosts);
|
|
|
- }
|
|
|
- // 创建线程池
|
|
|
- ExecutorService executorService = Executors.newFixedThreadPool(responsibilities.size());
|
|
|
- CountDownLatch countDownLatch = new CountDownLatch(responsibilities.size());
|
|
|
-
|
|
|
- for (Responsibility responsibility : responsibilities) {
|
|
|
- executorService.submit(() -> {
|
|
|
- try {
|
|
|
- // 分摊一个责任中心的成本
|
|
|
- List<Allocation> allocationRespCosts = allocationResponsibilityCost(startDTO, shareLevelVO, responsibility, targetResponsibilityList, respDirectCostMap, respParamValueList,
|
|
|
- accountShareResponsibilityMap, costAccountShareParamMap, costAccountShareDetailMap, costAccountShareTargetMap, allocationCostList, timeMillis);
|
|
|
- synchronized (allocationList) {
|
|
|
- allocationList.addAll(allocationRespCosts);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("分摊责任中心成本时发生错误", e);
|
|
|
- } finally {
|
|
|
- countDownLatch.countDown();
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- try {
|
|
|
- countDownLatch.await();
|
|
|
- } catch (InterruptedException e) {
|
|
|
- log.error("等待所有分摊任务完成时发生中断", e);
|
|
|
- } finally {
|
|
|
- executorService.shutdown();
|
|
|
- }
|
|
|
|
|
|
+ // 按责任中心逐个开始分摊(并行)
|
|
|
+ allocationList = responsibilities.parallelStream().flatMap(responsibility -> allocationResponsibilityCost(startDTO, shareLevelVO, responsibility, targetResponsibilityList, respDirectCostMap, respParamValueList,
|
|
|
+ accountShareResponsibilityMap, costAccountShareParamMap, costAccountShareDetailMap,costAccountShareTargetMap, allocationCostList, timeMillis).stream()).collect(Collectors.toList());
|
|
|
return allocationList;
|
|
|
}
|
|
|
|