Bladeren bron

成本分摊报表添加当前层级分摊总金额的显示

JammeyJiang 8 maanden geleden
bovenliggende
commit
054005b166
1 gewijzigde bestanden met toevoegingen van 73 en 16 verwijderingen
  1. 73 16
      src/main/java/com/kcim/service/impl/AllocationServiceImpl.java

+ 73 - 16
src/main/java/com/kcim/service/impl/AllocationServiceImpl.java

@@ -492,6 +492,7 @@ public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocat
 //        Map<String, AllocationReportVO> allAliMap = allocationReportVOList.stream().collect(Collectors.toMap(k -> k.getResponsibilityName() + k.getAlias() + k.getTargetResponsibilityName() + k.getShareParamName(), synOne -> synOne));
         // 当前责任中心下面有几个会计科目  后面进行合并使用
         final int[] numResponsibility = new int[1];
+        levelSort=levelSort+1;
 //        // 从第几列开始编写数据
         final int[] column = {levelSort + 3};
         responsibilityMap.forEach((key,value)->{
@@ -598,15 +599,31 @@ public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocat
 //                    writer.merge(num, num + shareParamSize - 1, k + 1, k + 1, costCostingVO.getTargetShareMoneys().get(t++), false);
 //
 //                }
-                if(!CollectionUtils.isEmpty(targetShareMoneyList)){
-                    for (int k = 0; k < levelSort - 1; k++) {
-                        writer.merge(num, num + shareParamSize - 1, k + 1, k + 1, targetShareMoneyList.get(k), false);
-                    }
-                }else {
-                    for (int k = 0; k < levelSort - 1; k++) {
-                        writer.merge(num, num + shareParamSize - 1, k + 1, k + 1, "0.0000", false);
-                    }
+                for (int k = 0; k < levelSort - 1; k++) {
+                    Object allocationAmount = getAllocationAmount(levelSort, k, allocationReportVOS, targetShareMoneyList);
+                    writer.merge(num, num + shareParamSize - 1, k + 1, k + 1, allocationAmount, false);
                 }
+//                if(!CollectionUtils.isEmpty(targetShareMoneyList)){
+//                    for (int k = 0; k < levelSort - 1; k++) {
+//                        if(k==levelSort-2){
+//                            BigDecimal totalAmount = allocationReportVOS.stream().map(AllocationReportVO::getAmount)
+//                                    .reduce(BigDecimal.ZERO, BigDecimal::add);
+//                            writer.merge(num, num + shareParamSize - 1, k + 1, k + 1, totalAmount, false);
+//                        }else {
+//                            writer.merge(num, num + shareParamSize - 1, k + 1, k + 1, targetShareMoneyList.get(k), false);
+//                        }
+//                    }
+//                }else {
+//                    for (int k = 0; k < levelSort - 1; k++) {
+//                        if(k==levelSort-2){
+//                            BigDecimal totalAmount = allocationReportVOS.stream().map(AllocationReportVO::getAmount)
+//                                    .reduce(BigDecimal.ZERO, BigDecimal::add);
+//                            writer.merge(num, num + shareParamSize - 1, k + 1, k + 1, totalAmount, false);
+//                        }else {
+//                            writer.merge(num, num + shareParamSize - 1, k + 1, k + 1, "0.0000", false);
+//                        }
+//                    }
+//                }
 
                 // 设置对应的分摊参数值
                 Set<String> strings = linkedHashMap.keySet();
@@ -650,16 +667,33 @@ public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocat
 //                }
                 List<String> targetShareMoneyList = targetTotalMoneys.get(target);
 
-                if(!CollectionUtils.isEmpty(targetShareMoneyList)){
-                    for (int k = 0; k < levelSort - 1; k++) {
-                        writer.writeCellValue(k + 1, num, targetShareMoneyList.get(k));
-                    }
-                }else {
-                    for (int k = 0; k < levelSort - 1; k++) {
-                        writer.writeCellValue(k + 1, num, "0.0000");
-                    }
+                for (int k = 0; k < levelSort - 1; k++) {
+                    Object allocationAmount = getAllocationAmount(levelSort, k, allocationReportVOS, targetShareMoneyList);
+                    writer.writeCellValue(k + 1, num, allocationAmount);
                 }
 
+//                if(!CollectionUtils.isEmpty(targetShareMoneyList)){
+//                    for (int k = 0; k < levelSort - 1; k++) {
+//                        if(k==levelSort-2){
+//                            BigDecimal totalAmount = allocationReportVOS.stream().map(AllocationReportVO::getAmount)
+//                                    .reduce(BigDecimal.ZERO, BigDecimal::add);
+//                            writer.writeCellValue(k + 1, num, totalAmount);
+//                        }else {
+//                            writer.writeCellValue(k + 1, num, targetShareMoneyList.get(k));
+//                        }
+//                    }
+//                }else {
+//                    for (int k = 0; k < levelSort - 1; k++) {
+//                        if(k==levelSort-2){
+//                            BigDecimal totalAmount = allocationReportVOS.stream().map(AllocationReportVO::getAmount)
+//                                    .reduce(BigDecimal.ZERO, BigDecimal::add);
+//                            writer.writeCellValue(k + 1, num, totalAmount);
+//                        }else {
+//                            writer.writeCellValue(k + 1, num, "0.0000");
+//                        }
+//                    }
+//                }
+
                 writer.writeCellValue(levelSort, num, allocationReportVOS.get(0).getShareParamName());
                 writer.writeCellValue(levelSort + 1, num, allocationReportVOS.get(0).getShareParamValueNums());
                 writer.writeCellValue(levelSort + 2, num, allocationReportVOS.get(0).getShareParamRates());
@@ -739,6 +773,29 @@ public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocat
         return writer;
     }
 
+    /**
+     * 获取责任中心对应层级的分摊金额
+     * @param levelSort
+     * @param index
+     * @param allocationReportVOS
+     * @param targetShareMoneyList
+     * @return
+     */
+    public Object getAllocationAmount(int levelSort,int index,List<AllocationReportVO> allocationReportVOS,List<String> targetShareMoneyList){
+        //当前层级取分摊金额加总
+        if(index==levelSort-2){
+            BigDecimal totalAmount = allocationReportVOS.stream().map(AllocationReportVO::getAmount)
+                    .reduce(BigDecimal.ZERO, BigDecimal::add);
+            return totalAmount;
+        }
+        //取不到对应层级的分摊总金额
+        if(CollectionUtils.isEmpty(targetShareMoneyList)||targetShareMoneyList.size()<=index){
+            return  BigDecimal.valueOf(NumberConstant.ZERO,NumberConstant.FOUR);
+        }
+        //取对应层级的分摊总金额
+        return targetShareMoneyList.get(index);
+    }
+
     /**
      * 查询数据
      *