فهرست منبع

09 01 01 全院损益计算

hr 4 سال پیش
والد
کامیت
695491d721

+ 6 - 0
src/main/java/com/imed/costaccount/model/Responsibility.java

@@ -88,4 +88,10 @@ public class Responsibility implements Serializable {
 	@Transient
 	private List<Responsibility> children;
 
+	public Responsibility(String responsibilityCode, String responsibilityName,Long parentId) {
+		this.responsibilityCode = responsibilityCode;
+		this.responsibilityName = responsibilityName;
+		this.parentId = parentId;
+	}
+
 }

+ 13 - 0
src/main/java/com/imed/costaccount/model/vo/ReportFormVO.java

@@ -1,13 +1,18 @@
 package com.imed.costaccount.model.vo;
 
 
+import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.fasterxml.jackson.annotation.JsonInclude;
 import io.swagger.annotations.ApiModel;
+import lombok.AllArgsConstructor;
 import lombok.Data;
+import lombok.NoArgsConstructor;
 
 import java.util.List;
 
 @Data
+@AllArgsConstructor
+@NoArgsConstructor
 @ApiModel("报表项目视图对象")
 public class ReportFormVO {
 
@@ -40,9 +45,17 @@ public class ReportFormVO {
     @JsonInclude(JsonInclude.Include.NON_NULL)
     private List<RelationVO> reportRelations;
 
+
     /**
      * 报表与诊次床日关联的状态
      */
     private Integer reportNumberSetStatus=0;
 
+    public ReportFormVO(Long id,Integer num, String reportName, Long parentId,List<ReportFormVO> children) {
+        this.num = num;
+        this.reportName = reportName;
+        this.parentId = parentId;
+        this.id = id;
+        this.children = children;
+    }
 }

+ 46 - 8
src/main/java/com/imed/costaccount/service/impl/HospProfitAndLossServiceImpl.java

@@ -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);
             });
         }