|
@@ -252,35 +252,129 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
|
|
|
if (CollUtil.isEmpty(responsibilityList)){
|
|
|
throw new CostException(500,"责任中心不存在");
|
|
|
}
|
|
|
- // 所有的叶子
|
|
|
- Map<Long, List<Responsibility>> responsibilityMap = responsibilityList.stream().collect(Collectors.groupingBy(Responsibility::getParentId));
|
|
|
+ // 设置表头
|
|
|
+ Map<Long, List<Responsibility>> responsibilityMap = responsibilityList.stream().collect(Collectors.groupingBy(Responsibility::getId));
|
|
|
List<Responsibility> responsibilities = responsibilityList.stream().filter(i -> NumberConstant.TWO.equals(i.getIsGatherCenter()) && NumberConstant.ONE.equals(i.getResponsibilityType())).collect(Collectors.toList());
|
|
|
Map<Long, List<Responsibility>> responsibilityParentMap = responsibilities.stream().collect(Collectors.groupingBy(Responsibility::getParentId));
|
|
|
Set<Long> keySet = responsibilityParentMap.keySet();
|
|
|
+ int column=2;
|
|
|
for (Long parentId:keySet){
|
|
|
// 同一父节点的叶子节点数据
|
|
|
List<Responsibility> list = responsibilityParentMap.get(parentId);
|
|
|
-
|
|
|
+ for (int i=0;i<list.size();i++) {
|
|
|
+ String responsibilityName1 = list.get(i).getResponsibilityName();
|
|
|
+ // 父层级责任中心名称
|
|
|
+ List<Responsibility> responsibilityList1 = responsibilityMap.get(list.get(i).getParentId());
|
|
|
+ if (CollUtil.isEmpty(responsibilityList1)) {
|
|
|
+ writer.writeCellValue(column, 0, null);
|
|
|
+ } else {
|
|
|
+ // 父层级责任中心名称
|
|
|
+ String responsibilityName = responsibilityList1.get(0).getResponsibilityName();
|
|
|
+ // 子层级责任中心名称
|
|
|
+ writer.writeCellValue(column, 0, responsibilityName);
|
|
|
+ }
|
|
|
+ writer.writeCellValue(column, 1, responsibilityName1);
|
|
|
+ column++;
|
|
|
+ }
|
|
|
}
|
|
|
+ writer.merge(1,1,0,1,"项目",false);
|
|
|
DateTime dateTime = DateUtil.parse(date);
|
|
|
int year = DateUtil.year(dateTime);
|
|
|
int month = DateUtil.month(dateTime)+1;
|
|
|
- List<CostDepartmentProfit> costDepartmentProfitList = this.list(new QueryWrapper<CostDepartmentProfit>().lambda().eq(CostDepartmentProfit::getHospId, hospId).eq(StrUtil.isNotBlank(date), CostDepartmentProfit::getYear, year).eq(StrUtil.isNotBlank(date), CostDepartmentProfit::getMonth, month));
|
|
|
- // 16个责任中心名称
|
|
|
- List<String> responsibilityNameList = costDepartmentProfitList.stream().map(CostDepartmentProfit::getResponsibilityName).distinct().sorted().collect(Collectors.toList());
|
|
|
- Map<String, List<CostDepartmentProfit>> responsibilityNameMap = costDepartmentProfitList.stream().collect(Collectors.groupingBy(CostDepartmentProfit::getResponsibilityName));
|
|
|
- for (int i = 0; i < responsibilityNameList.size(); i++) {
|
|
|
- String responsibilityName = responsibilityNameList.get(i);
|
|
|
- List<CostDepartmentProfit> departmentProfits = responsibilityNameMap.get(responsibilityName);
|
|
|
- for (int j=0;j<departmentProfits.size();j++){
|
|
|
- String responsibilityName1 = departmentProfits.get(j).getResponsibilityName();
|
|
|
-// departmentProfits.get(j).get
|
|
|
- // 第一行
|
|
|
-// writer.writeCellValue(0,j+2,
|
|
|
+
|
|
|
+ // 设置列
|
|
|
+ List<CostDepartmentProfit> departmentProfits = this.list(new QueryWrapper<CostDepartmentProfit>().lambda()
|
|
|
+ .eq(CostDepartmentProfit::getHospId, hospId)
|
|
|
+ .eq(CostDepartmentProfit::getYear, year).eq(CostDepartmentProfit::getMonth, month));
|
|
|
+ // 用来筛选金额
|
|
|
+ Map<String, CostDepartmentProfit> profitMap = departmentProfits.stream().filter(i->i.getReportParentId()!=0L).collect(Collectors.toMap(k -> k.getReportName() + "cost" + k.getResponsibilityName(), synOne -> synOne));
|
|
|
+ // 报表的父层级报表
|
|
|
+ Map<Long, List<CostDepartmentProfit>> departmentParentReportMap = departmentProfits.stream().filter(i -> i.getReportParentId() == 0L)
|
|
|
+ .collect(Collectors.groupingBy(CostDepartmentProfit::getReportId)).entrySet().stream()
|
|
|
+ .sorted(Map.Entry.comparingByKey()).collect(
|
|
|
+ Collectors.toMap(
|
|
|
+ Map.Entry::getKey,
|
|
|
+ Map.Entry::getValue,
|
|
|
+ (oldVal, newVal) -> oldVal,
|
|
|
+ LinkedHashMap::new
|
|
|
+ )
|
|
|
+ );
|
|
|
+ // 不是父节点的所有叶子节点
|
|
|
+ Map<Long, List<CostDepartmentProfit>> listParentMap = departmentProfits.stream().filter(i -> i.getReportParentId() != 0L).collect(Collectors.groupingBy(CostDepartmentProfit::getReportParentId));
|
|
|
+ Set<Long> ids = departmentParentReportMap.keySet();
|
|
|
+ // 默认是在第二行开始的
|
|
|
+
|
|
|
+ int row=2;
|
|
|
+ int columnNum=0;
|
|
|
+ for (Long id:ids){
|
|
|
+ String reportParentName = departmentParentReportMap.get(id).get(0).getReportName();
|
|
|
+ List<CostDepartmentProfit> profitList = listParentMap.get(id);
|
|
|
+ Map<Integer, List<CostDepartmentProfit>> linkedHashMap = profitList.stream().collect(Collectors.groupingBy(CostDepartmentProfit::getReportNum)).entrySet().stream()
|
|
|
+ .sorted(Map.Entry.comparingByKey()).collect(
|
|
|
+ Collectors.toMap(
|
|
|
+ Map.Entry::getKey,
|
|
|
+ Map.Entry::getValue,
|
|
|
+ (oldVal, newVal) -> oldVal,
|
|
|
+ LinkedHashMap::new
|
|
|
+ ));
|
|
|
+ Set<Integer> reportNums = linkedHashMap.keySet();
|
|
|
+ for (Integer reportNum:reportNums){
|
|
|
+ // 这一行要显示的记录
|
|
|
+ List<CostDepartmentProfit> costDepartmentProfits = linkedHashMap.get(reportNum);
|
|
|
+ // 子层级扥报表名称
|
|
|
+ String reportName = costDepartmentProfits.get(0).getReportName();
|
|
|
+ for (int i=0;i<costDepartmentProfits.size();i++){
|
|
|
+ // 添加项目名称
|
|
|
+ columnNum++;
|
|
|
+ writer.writeCellValue(0,row,reportParentName);
|
|
|
+ writer.writeCellValue(1,row,reportName);
|
|
|
+ for (int j=0;j<column-2;j++){
|
|
|
+ // TODO 设置添加具体金额
|
|
|
+ // 获取表格对应的字段的值
|
|
|
+ String responsibilityTopName = sheet.getRow(1).getCell(j + 2).getStringCellValue();
|
|
|
+ String reportTopName = sheet.getRow(row).getCell(1).getStringCellValue();
|
|
|
+ BigDecimal amount = profitMap.get(reportTopName + "cost" + responsibilityTopName).getAmount();
|
|
|
+ writer.writeCellValue(j+2,row,amount);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ row++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // TODO 合并留在最后
|
|
|
+ int cc = 2;
|
|
|
+ // 合并行
|
|
|
+ for (int m = 2; m < column - 1; m++) {
|
|
|
+ String cellValue1 = sheet.getRow(0).getCell(m).getStringCellValue();
|
|
|
+ String cellValue2 = sheet.getRow(0).getCell(m + 1).getStringCellValue();
|
|
|
+ if (!cellValue1.equals(cellValue2)) {
|
|
|
+ if (cc!=m){
|
|
|
+ writer.merge(0, 0, cc, m, cellValue1, false);
|
|
|
+ }else {
|
|
|
+ writer.writeCellValue(cc,0,cellValue1);
|
|
|
+ }
|
|
|
+
|
|
|
+ cc = m + 1;
|
|
|
+ }else if (m == column - 2) {
|
|
|
+ writer.merge(0, 0, cc, m + 1, sheet.getRow(0).getCell(m + 1).getStringCellValue(), false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 合并列
|
|
|
+ int jj = 2;
|
|
|
+
|
|
|
+ for (int i = 2; i < row - 1; i++) {
|
|
|
+ String cellValue1 = sheet.getRow(i).getCell(0).getStringCellValue();
|
|
|
+ String cellValue2 = sheet.getRow(i + 1).getCell(0).getStringCellValue();
|
|
|
+ if (!cellValue1.equals(cellValue2)) {
|
|
|
+ if (jj != i){
|
|
|
+ writer.merge(jj, i, 0, 0, cellValue1, false);
|
|
|
+ }else {
|
|
|
+ writer.writeCellValue(0,jj,cellValue1);
|
|
|
+ }
|
|
|
+ jj = i + 1;
|
|
|
+ } else if (i == row - 2) {
|
|
|
+ writer.merge(jj, i + 1, 0, 0, cellValue1, false);
|
|
|
}
|
|
|
}
|
|
|
- // 合并留在最后
|
|
|
- System.out.println(responsibilityNameList);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -299,8 +393,8 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
|
|
|
// 查找在归集数据里面当前责任中心对应的这些会计科目的金额
|
|
|
List<IncomeCollection> incomeCollectionList = list.stream().filter(income -> income.getResponsibilityCode().equals(i.getResponsibilityCode()) && accountList.contains(income.getAccountingCode())).collect(Collectors.toList());
|
|
|
// 需要查询分摊后的表
|
|
|
- List<AllocationQueryReportVO> collect = allocationQueryReportVOList.stream().filter(m -> m.getResponsibilityCode().equals(i.getResponsibilityCode())).collect(Collectors.toList());
|
|
|
- List<AllocationQueryReportVO> collect1 = collect.stream().filter(m -> !Collections.disjoint(accountList, m.getAccountingCodes())).collect(Collectors.toList());
|
|
|
+// List<AllocationQueryReportVO> collect = allocationQueryReportVOList.stream().filter(m -> m.getResponsibilityCode().equals(i.getResponsibilityCode())).collect(Collectors.toList());
|
|
|
+// List<AllocationQueryReportVO> collect1 = collect.stream().filter(m -> !Collections.disjoint(accountList, m.getAccountingCodes())).collect(Collectors.toList());
|
|
|
List<AllocationQueryReportVO> reportVOList = allocationQueryReportVOList.stream().filter(m -> m.getResponsibilityCode().equals(i.getResponsibilityCode()) && !Collections.disjoint(accountList, m.getAccountingCodes())).collect(Collectors.toList());
|
|
|
if (CollUtil.isNotEmpty(incomeCollectionList)) {
|
|
|
incomeCollectionList.forEach(m -> {
|
|
@@ -314,7 +408,7 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
- i.setAmount(new BigDecimal(sum.toString()));
|
|
|
+// i.setAmount(new BigDecimal(sum.toString()));
|
|
|
// numMap.put(i.getReportNum()+i.getResponsibilityCode(),new BigDecimal(sum.toString()));
|
|
|
return sum.get();
|
|
|
}
|
|
@@ -340,7 +434,7 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- i.setAmount(new BigDecimal(sum.toString()));
|
|
|
+// i.setAmount(new BigDecimal(sum.toString()));
|
|
|
return sum.get();
|
|
|
}
|
|
|
|
|
@@ -366,7 +460,7 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- costDepartmentProfitVO.setAmount(new BigDecimal(sum.toString()));
|
|
|
+// costDepartmentProfitVO.setAmount(new BigDecimal(sum.toString()));
|
|
|
return sum.get();
|
|
|
}
|
|
|
|
|
@@ -386,7 +480,7 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
|
|
|
Long reportParentId = costDepartmentProfitVO.getReportParentId();
|
|
|
String responsibilityCode = costDepartmentProfitVO.getResponsibilityCode();
|
|
|
// 查询报表里面在当前父层级下的并且不是自己的报表项目
|
|
|
- List<CostDepartmentProfitVO> costDepartmentProfitVOS = profitVOS.stream().filter(i -> i.getReportParentId().equals(reportParentId) && i.getResponsibilityCode().equals(responsibilityCode) && !NumberConstant.THREE.equals(i.getCostType())).collect(Collectors.toList());
|
|
|
+ List<CostDepartmentProfitVO> costDepartmentProfitVOS = profitVOS.stream().filter(i -> i.getReportParentId().equals(reportParentId) && i.getResponsibilityCode().equals(responsibilityCode) && !NumberConstant.THREE.equals(i.getCalcType())).collect(Collectors.toList());
|
|
|
AtomicReference<BigDecimal> sum = new AtomicReference<>(new BigDecimal("0.0000"));
|
|
|
// 遍历数据 之前的已经经过了计算
|
|
|
costDepartmentProfitVOS.forEach(i -> {
|
|
@@ -395,10 +489,10 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
|
|
|
if (CollUtil.isEmpty(costDepartmentProfitVOS1)) {
|
|
|
throw new CostException(500, "报表未找到");
|
|
|
}
|
|
|
- BigDecimal amount = getAmount(profitVOS, costShareLevelList, responsibilityCode, list, allocationQueryReportVOList, reportRelationMap, allocationList, listMap);
|
|
|
+ BigDecimal amount = getAmount(costDepartmentProfitVOS1, costShareLevelList, responsibilityCode, list, allocationQueryReportVOList, reportRelationMap, allocationList, listMap);
|
|
|
sum.updateAndGet(v -> v.add(amount));
|
|
|
});
|
|
|
- costDepartmentProfitVO.setAmount(new BigDecimal(sum.toString()));
|
|
|
+// costDepartmentProfitVO.setAmount(new BigDecimal(sum.toString()));
|
|
|
return sum.get();
|
|
|
}
|
|
|
|
|
@@ -449,17 +543,17 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
|
|
|
List<CostDepartmentProfitVO> costDepartmentProfitVOS = profitVOS.stream().filter(i -> i.getResponsibilityCode().equals(responsibilityCode)).collect(Collectors.toList());
|
|
|
// 都一个就是
|
|
|
CostDepartmentProfitVO costDepartmentProfitVO = costDepartmentProfitVOS.get(0);
|
|
|
- Integer costType = costDepartmentProfitVO.getCostType();
|
|
|
- if (NumberConstant.ONE.equals(costType)) {
|
|
|
+ Integer calcType = costDepartmentProfitVO.getCalcType();
|
|
|
+ if (NumberConstant.ONE.equals(calcType)) {
|
|
|
// 调用计算的方法 按照会计科目
|
|
|
bigDecimal = setAccountReportData(costDepartmentProfitVO, list, allocationQueryReportVOList, reportRelationMap);
|
|
|
- } else if (NumberConstant.TWO.equals(costType)) {
|
|
|
+ } else if (NumberConstant.TWO.equals(calcType)) {
|
|
|
// 按照分摊层级
|
|
|
bigDecimal = setShareLevelReportData(costDepartmentProfitVO, costShareLevelList, reportRelationMap, allocationList);
|
|
|
- } else if (NumberConstant.THREE.equals(costType)) {
|
|
|
+ } else if (NumberConstant.THREE.equals(calcType)) {
|
|
|
// 小计
|
|
|
bigDecimal = setSubtotal(costDepartmentProfitVO, costShareLevelList, listMap, profitVOS, list, allocationQueryReportVOList, reportRelationMap, allocationList);
|
|
|
- } else if (NumberConstant.FIVE.equals(costType)) {
|
|
|
+ } else if (NumberConstant.FIVE.equals(calcType)) {
|
|
|
// 按照责任中心
|
|
|
bigDecimal = setResponsibilityCode(costDepartmentProfitVO, reportRelationMap, allocationList);
|
|
|
}
|