|
@@ -22,6 +22,7 @@ import com.kcim.dao.model.*;
|
|
|
import com.kcim.dao.model.dto.StartDTO;
|
|
|
import com.kcim.dao.repository.CostAccountShareDetailRepository;
|
|
|
import com.kcim.dao.repository.CostAccountShareParamRepository;
|
|
|
+import com.kcim.dao.repository.CostAccountShareTargetRepository;
|
|
|
import com.kcim.dao.repository.ResponsibilityRepository;
|
|
|
import com.kcim.service.*;
|
|
|
import com.kcim.vo.*;
|
|
@@ -62,6 +63,7 @@ public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocat
|
|
|
|
|
|
private final CostAccountShareDetailRepository costAccountShareDetailRepository;
|
|
|
private final CostAccountShareParamRepository costAccountShareParamRepository;
|
|
|
+ private final CostAccountShareTargetRepository costAccountShareTargetRepository;
|
|
|
|
|
|
// public AllocationServiceImpl(CostCostingGroupService costCostingGroupService, CostShareLevelService shareLevelService, ResponsibilityService responsibilityService, CostAccountShareService accountShareService, ShareParamValueService shareParamValueService, CostShareParamService shareParamService, AllocationQueryService allocationQueryService, ResponsibilityRepository responsibilityRepository, CenterService centerService, SqlService sqlService) {
|
|
|
// this.costCostingGroupService = costCostingGroupService;
|
|
@@ -163,12 +165,20 @@ public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocat
|
|
|
if(!CollectionUtils.isEmpty(costAccountShareDetailList)) {
|
|
|
costAccountShareDetailMap=costAccountShareDetailList.stream().collect(Collectors.groupingBy(CostAccountShareDetail::getAccountShareId));
|
|
|
}
|
|
|
+
|
|
|
+ //分摊设置对应的目标责任中心
|
|
|
+ List<CostAccountShareTarget> costAccountShareTargetList = costAccountShareTargetRepository.getCostAccountShareTarget(null);
|
|
|
+ Map<Long, List<CostAccountShareTarget>> costAccountShareTargetMap =new HashMap<>();
|
|
|
+ //全部没有指定分摊时会有目标责任中心为空的情况
|
|
|
+ if(!CollectionUtils.isEmpty(costAccountShareTargetList)) {
|
|
|
+ costAccountShareTargetMap=costAccountShareTargetList.stream().collect(Collectors.groupingBy(CostAccountShareTarget::getAccountShareId));
|
|
|
+ }
|
|
|
//分摊成本列表
|
|
|
List<Allocation> allocationCostList=new ArrayList<>();
|
|
|
//逐级分摊
|
|
|
for (CostShareLevelVO shareLevelVO : shareLevelVOs) {
|
|
|
List<Allocation> shareLevelAllocationList = allocationShareLevelCost(startDTO, shareLevelVO, responsibilityList, responsibilityShareIdMap, respDirectCostMap, respParamValueList,
|
|
|
- accountShareResponsibilityMap, costAccountShareParamMap, costAccountShareDetailMap, allocationCostList, timeMillis);
|
|
|
+ accountShareResponsibilityMap, costAccountShareParamMap, costAccountShareDetailMap, costAccountShareTargetMap,allocationCostList, timeMillis);
|
|
|
allocationCostList.addAll(shareLevelAllocationList);
|
|
|
}
|
|
|
//没有任何分摊数据
|
|
@@ -207,6 +217,7 @@ public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocat
|
|
|
Map<String,List<CostAccountShare>> accountShareResponsibilityMap,
|
|
|
Map<Long, List<CostAccountShareParam>> costAccountShareParamMap,
|
|
|
Map<Long, List<CostAccountShareDetail>> costAccountShareDetailMap,
|
|
|
+ Map<Long, List<CostAccountShareTarget>> costAccountShareTargetMap,
|
|
|
List<Allocation> allocationCostList,
|
|
|
long timeMillis){
|
|
|
//分摊成本列表
|
|
@@ -229,6 +240,7 @@ public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocat
|
|
|
if (CollectionUtils.isEmpty(responsibilities)) {
|
|
|
return allocationList;
|
|
|
}
|
|
|
+
|
|
|
//目标责任中心列表
|
|
|
List<Responsibility> targetResponsibilityList = responsibilityList.stream().filter(responsibility -> targetLevelList.contains(String.valueOf(responsibility.getShareLevel()))).collect(Collectors.toList());
|
|
|
if (CollectionUtils.isEmpty(targetResponsibilityList)) {
|
|
@@ -238,7 +250,7 @@ public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocat
|
|
|
for (Responsibility responsibility : responsibilities) {
|
|
|
//分摊一个责任中心的成本
|
|
|
List<Allocation> allocationRespCosts = allocationResponsibilityCost(startDTO, shareLevelVO, responsibility, targetResponsibilityList, respDirectCostMap, respParamValueList,
|
|
|
- accountShareResponsibilityMap, costAccountShareParamMap, costAccountShareDetailMap, allocationCostList, timeMillis);
|
|
|
+ accountShareResponsibilityMap, costAccountShareParamMap, costAccountShareDetailMap,costAccountShareTargetMap, allocationCostList, timeMillis);
|
|
|
allocationList.addAll(allocationRespCosts);
|
|
|
}
|
|
|
return allocationList;
|
|
@@ -267,6 +279,7 @@ public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocat
|
|
|
Map<String,List<CostAccountShare>> accountShareResponsibilityMap,
|
|
|
Map<Long, List<CostAccountShareParam>> costAccountShareParamMap,
|
|
|
Map<Long, List<CostAccountShareDetail>> costAccountShareDetailMap,
|
|
|
+ Map<Long, List<CostAccountShareTarget>> costAccountShareTargetMap,
|
|
|
List<Allocation> allocationCostList,
|
|
|
long timeMillis){
|
|
|
//分摊结果列表
|
|
@@ -282,8 +295,6 @@ public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocat
|
|
|
if(NumberConstant.ZERO.equals(calcType) &&NumberConstant.ONE!=accountShares.size()){
|
|
|
throw new CostException(String.format("[%s-%s]的分摊设置有问题,合并计算的责任中心只允许设置一个分摊配置",responsibility.getResponsibilityCode(),responsibility.getResponsibilityName()));
|
|
|
}
|
|
|
- //所有目标责任中心的责任中心代码列表
|
|
|
- List<String> targetResponsibilityCodeList = targetResponsibilityList.stream().map(Responsibility::getResponsibilityCode).collect(Collectors.toList());
|
|
|
//间接成本
|
|
|
List<Allocation> respIndirectCostList = allocationCostList.stream().filter(allocationCost -> allocationCost.getTargetResponsibilityCode().equals(responsibility.getResponsibilityCode())).collect(Collectors.toList());
|
|
|
//直接成本
|
|
@@ -294,6 +305,10 @@ public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocat
|
|
|
List<CostCostingGroup> paramDirectCostList=new ArrayList<>();
|
|
|
//分摊设置对应的间接成本
|
|
|
List<Allocation> paramIndirectCostList=new ArrayList<>();
|
|
|
+ //获取分摊设置对应的目标责任中心
|
|
|
+ List<Responsibility> shareTargetRespCodeList = getShareTargetResponsibility(accountShare, targetResponsibilityList, costAccountShareTargetMap);
|
|
|
+ //所有目标责任中心的责任中心代码列表
|
|
|
+ List<String> targetResponsibilityCodeList = shareTargetRespCodeList.stream().map(Responsibility::getResponsibilityCode).collect(Collectors.toList());
|
|
|
//合并计算
|
|
|
if(NumberConstant.ZERO.equals(calcType)){
|
|
|
//合并计算时分摊参数的成本=责任中心的成本
|
|
@@ -322,7 +337,7 @@ public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocat
|
|
|
throw new CostException(String.format("[%s-%s]的目标责任中心找不到对应的参数数值,无法继续分摊",responsibility.getResponsibilityName(),shareParam.getShareParamName()));
|
|
|
}
|
|
|
//按分摊参数计算每个会计科目分摊到的金额
|
|
|
- List<Allocation> allocationParamCosts = allocationParamCostCalc(startDTO, shareLevelVO, responsibility, targetResponsibilityList, paramDirectCostList,
|
|
|
+ List<Allocation> allocationParamCosts = allocationParamCostCalc(startDTO, shareLevelVO, responsibility, shareTargetRespCodeList, paramDirectCostList,
|
|
|
paramIndirectCostList, accountShares.get(NumberConstant.ZERO), shareParam, targetResponsibilityParamList, timeMillis);
|
|
|
allocationList.addAll(allocationParamCosts);
|
|
|
}
|
|
@@ -330,6 +345,30 @@ public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocat
|
|
|
return allocationList;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取分摊设置的目标责任中心
|
|
|
+ * @param accountShare
|
|
|
+ * @param levelTargetResponsibility
|
|
|
+ * @param costAccountShareTargetMap
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<Responsibility> getShareTargetResponsibility(CostAccountShare accountShare,
|
|
|
+ List<Responsibility> levelTargetResponsibility,
|
|
|
+ Map<Long, List<CostAccountShareTarget>> costAccountShareTargetMap){
|
|
|
+ //获取分摊设置对应的目标责任中心
|
|
|
+ List<CostAccountShareTarget> shareTargetResponsibilityList=costAccountShareTargetMap.get(accountShare.getId());
|
|
|
+ if(CollectionUtils.isEmpty(shareTargetResponsibilityList)){
|
|
|
+ return levelTargetResponsibility;
|
|
|
+ }
|
|
|
+ //筛选出指定的目标责任中心
|
|
|
+ List<String> shareTargetRespCodeList = shareTargetResponsibilityList.stream().map(CostAccountShareTarget::getTargetResponsibilityCode).collect(Collectors.toList());
|
|
|
+ List<Responsibility> shareTargetRespList = levelTargetResponsibility.stream().filter(responsibility -> shareTargetRespCodeList.contains(responsibility.getResponsibilityCode())).collect(Collectors.toList());
|
|
|
+ if(CollectionUtils.isEmpty(shareTargetRespList)){
|
|
|
+ throw new CostException(String.format("[%s-%s]找不到对应的目标责任中心,无法继续分摊",accountShare.getResponsibilityName(),accountShare.getAlias()));
|
|
|
+ }
|
|
|
+ return shareTargetRespList;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 按分摊参数计算每个会计科目分摊到的金额
|