|
@@ -382,6 +382,11 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
|
|
|
|
|
|
// 得到所有责任中心的子节点
|
|
|
List<Responsibility> leafResp = responsibilityService.getLeafResp(hospId);
|
|
|
+ List<CostOtherPaymentsData> byMonth = otherPaymentsDataService.getByMonth(year, month, hospId);
|
|
|
+ if (!byMonth.isEmpty()) {
|
|
|
+ Responsibility responsibility = new Responsibility("-1", "全院", -1L);
|
|
|
+ leafResp.add(responsibility);
|
|
|
+ }
|
|
|
|
|
|
// 得到上一层的title子节点
|
|
|
// ExcelWriter writer = ExcelUtil.getWriter();
|
|
@@ -416,12 +421,14 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
|
|
|
}
|
|
|
int count = (int) leafResp.stream().filter(o -> o.getParentId().equals(parentId)).count();
|
|
|
|
|
|
-
|
|
|
if (count == 1) {
|
|
|
writer.writeCellValue(oldSize, 1, name);
|
|
|
+ } else if (count == 0) {
|
|
|
+ writer.writeCellValue(oldSize, 1, "全院其他");
|
|
|
} else {
|
|
|
writer.merge(1, 1, oldSize, oldSize + count - 1, name, false);
|
|
|
}
|
|
|
+
|
|
|
oldSize = oldSize + count;
|
|
|
map.put(parentId, oldSize);
|
|
|
|
|
@@ -431,6 +438,16 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
|
|
|
if (allHospList.isEmpty()) {
|
|
|
throw new CostException("请先设置全院损益报表");
|
|
|
}
|
|
|
+
|
|
|
+ if (!byMonth.isEmpty()) {
|
|
|
+ // 构造假数据 生成全院其他收支
|
|
|
+ ReportFormVO vo = new ReportFormVO(-1L, -1, "全院其他收支", 0L, new ArrayList<>());
|
|
|
+ for (CostOtherPaymentsData data : byMonth) {
|
|
|
+ ReportFormVO reportFormVO = new ReportFormVO(-2L, (int) (-data.getId()), data.getPaymentsName(), -1L, null);
|
|
|
+ vo.getChildren().add(reportFormVO);
|
|
|
+ }
|
|
|
+ allHospList.add(allHospList.size() - 1, vo);
|
|
|
+ }
|
|
|
// 查询所有的全院损益数据 内存溢出问题
|
|
|
List<HospProfitAndLoss> list = getAllDataByDate(year, month, hospId);
|
|
|
int lastRow = 3;
|
|
@@ -441,16 +458,18 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
|
|
|
continue;
|
|
|
}
|
|
|
int size = children.size();
|
|
|
- if (size == 1) {
|
|
|
+ // 当最后一个的时候写上全院其他收支
|
|
|
+ if (allHospList.size() == 1) {
|
|
|
writer.writeCellValue(0, lastRow, parentFormVO.getReportName());
|
|
|
} else {
|
|
|
writer.merge(lastRow, lastRow + size - 1, 0, 0, parentFormVO.getReportName(), true);
|
|
|
}
|
|
|
+
|
|
|
// 具体的报表项目
|
|
|
for (int j = 0; j < size; j++) {
|
|
|
// todo 可以抽取出单独方法
|
|
|
ReportFormVO childFormVO = children.get(j);
|
|
|
-
|
|
|
+ // 第二列的数据
|
|
|
writer.writeCellValue(1, lastRow + j, childFormVO.getReportName());
|
|
|
// 单独计每个数据的责任中心对应的金额
|
|
|
for (int k = 0; k < secondTitleListCode.size(); k++) {
|
|
@@ -461,6 +480,26 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
|
|
|
.orElse(null);
|
|
|
BigDecimal bigDecimal = Objects.isNull(loss) ? BigDecimal.ZERO : loss.getAmount();
|
|
|
writer.writeCellValue(k + 2, lastRow + j, bigDecimal);
|
|
|
+ if (k == secondTitleListCode.size() - 1) {
|
|
|
+ bigDecimal = list.stream().filter(o -> o.getReportNum().equals(num)).map(HospProfitAndLoss::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ writer.writeCellValue(k + 2, lastRow + j, bigDecimal);
|
|
|
+
|
|
|
+ if (j == size - 1 && i == allHospList.size() - 1) {
|
|
|
+ // 计算 其他
|
|
|
+ BigDecimal another = BigDecimal.ZERO;
|
|
|
+ for (CostOtherPaymentsData costOtherPaymentsData : byMonth) {
|
|
|
+ if (costOtherPaymentsData.getPaymentsType() == 1) {
|
|
|
+ another = another.add(costOtherPaymentsData.getTotalAmount());
|
|
|
+ } else {
|
|
|
+ another = another.subtract(costOtherPaymentsData.getTotalAmount());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ bigDecimal = bigDecimal.add(another);
|
|
|
+ writer.writeCellValue(k + 2, lastRow + j, bigDecimal);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -573,11 +612,10 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
|
|
|
if (!otherPaymentsDatas.isEmpty()) {
|
|
|
otherPaymentsDatas.forEach(ele -> {
|
|
|
HospProfitAndLoss loss = new HospProfitAndLoss();
|
|
|
- loss.setDateYear(year).setDateMonth(month).setReportName(ele.getPaymentsName()).setReportNum(ele.getId().intValue())
|
|
|
- .setCreateTime(System.currentTimeMillis()).setAmount(ele.getTotalAmount()).setHospId(hospId);
|
|
|
-// if (ele.getPaymentsType() == 2) {
|
|
|
-// loss.setAmount(BigDecimal.ZERO.subtract(ele.getTotalAmount()));
|
|
|
-// }
|
|
|
+ loss.setDateYear(year).setDateMonth(month).setReportName(ele.getPaymentsName()).setReportNum((int) (-ele.getId()))
|
|
|
+ .setCreateTime(System.currentTimeMillis()).setAmount(ele.getTotalAmount()).setHospId(hospId)
|
|
|
+ .setResponsibilityName("全院").setResponsibilityCode("-1")
|
|
|
+ ;
|
|
|
list.add(loss);
|
|
|
});
|
|
|
}
|