|
@@ -8,6 +8,7 @@ import cn.hutool.core.util.ReUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.poi.excel.ExcelUtil;
|
|
|
import cn.hutool.poi.excel.ExcelWriter;
|
|
|
+import cn.hutool.poi.excel.StyleSet;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.imed.costaccount.common.enums.CalcTypeEnum;
|
|
@@ -21,6 +22,9 @@ import com.imed.costaccount.model.vo.RelationVO;
|
|
|
import com.imed.costaccount.model.vo.ReportFormVO;
|
|
|
import com.imed.costaccount.service.*;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFCellStyle;
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFCellStyle;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
@@ -390,24 +394,54 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
|
|
|
// 得到所有责任中心的子节点
|
|
|
List<Responsibility> leafResp = responsibilityService.getLeafResp(hospId);
|
|
|
|
|
|
+ // 得到上一层的title子节点
|
|
|
ExcelWriter writer = ExcelUtil.getWriter();
|
|
|
- List<String> secondTitleList = leafResp.stream().map(Responsibility::getResponsibilityName).collect(Collectors.toList());
|
|
|
+ List<String> secondTitleListCode = leafResp.stream().map(Responsibility::getResponsibilityCode).collect(Collectors.toList());
|
|
|
writer.merge(leafResp.size() + 1, "全院损益计算导出 \n" + "制表时间:" + DateUtil.now());
|
|
|
+ // 得到两层结构
|
|
|
writer.setColumnWidth(-1, 20);
|
|
|
writer.passCurrentRow();
|
|
|
- writer.merge(2, 2, 0, 1, "项目", false);
|
|
|
- for (int i = 0; i < secondTitleList.size(); i++) {
|
|
|
- String str = secondTitleList.get(i);
|
|
|
+ writer.merge(2, 2, 0, 1, "项目", true);
|
|
|
+ int oldSize = 2;
|
|
|
+ Map<Long, Object> map = new HashMap<>();
|
|
|
+ for (int i = 0; i < leafResp.size(); i++) {
|
|
|
+ Responsibility responsibility = leafResp.get(i);
|
|
|
+ String str = responsibility.getResponsibilityName();
|
|
|
writer.writeCellValue(i + 2, 2, str);
|
|
|
+ // 写父亲层级
|
|
|
+ Long parentId = responsibility.getParentId();
|
|
|
+ if (map.get(parentId) != null) {
|
|
|
+ // 如果parentId = 0
|
|
|
+ if (parentId != 0L) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Responsibility byId = responsibilityService.getById(parentId);
|
|
|
+ String name = "";
|
|
|
+ if (byId != null) {
|
|
|
+ name = byId.getResponsibilityName();
|
|
|
+ }
|
|
|
+ int count = (int) leafResp.stream().filter(o -> o.getParentId().equals(parentId)).count();
|
|
|
+
|
|
|
+
|
|
|
+ if (count == 1) {
|
|
|
+ writer.writeCellValue(oldSize, 1, name);
|
|
|
+ } else {
|
|
|
+ writer.merge(1, 1, oldSize, oldSize + count - 1, name, false);
|
|
|
+ }
|
|
|
+ oldSize = oldSize + count;
|
|
|
+ map.put(parentId, oldSize);
|
|
|
+
|
|
|
}
|
|
|
// 得到全院损益报表处理 树状结构(only 2层)
|
|
|
List<ReportFormVO> allHospList = reportFormService.getAllHospList(hospId);
|
|
|
if (allHospList.isEmpty()) {
|
|
|
- return;
|
|
|
+ throw new CostException("请先设置全院损益报表");
|
|
|
}
|
|
|
// 查询所有的全院损益数据 内存溢出问题
|
|
|
List<HospProfitAndLoss> list = getAllDataByDate(year, month, hospId);
|
|
|
int lastRow = 3;
|
|
|
+ Sheet sheet = writer.getSheet();
|
|
|
for (int i = 0; i < allHospList.size(); i++) {
|
|
|
ReportFormVO parentFormVO = allHospList.get(i);
|
|
|
List<ReportFormVO> children = parentFormVO.getChildren();
|
|
@@ -420,15 +454,25 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
|
|
|
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++) {
|
|
|
+
|
|
|
+ String responsibilityCode = secondTitleListCode.get(k);
|
|
|
+ Integer num = childFormVO.getNum();
|
|
|
+ HospProfitAndLoss loss = list.stream().filter(o -> o.getReportNum().equals(num) && o.getResponsibilityCode().equals(responsibilityCode)).findAny()
|
|
|
+ .orElse(null);
|
|
|
+ BigDecimal bigDecimal = Objects.isNull(loss) ? BigDecimal.ZERO : loss.getAmount();
|
|
|
+ writer.writeCellValue(k + 2, lastRow + j, bigDecimal);
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
lastRow = lastRow + size;
|
|
|
}
|
|
|
|
|
|
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
|
|
|
- response.setHeader("Content-Disposition", "attachment;filename=" + year + month + ".xls");
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + "全院损益列表" + ".xls");
|
|
|
ServletOutputStream out = null;
|
|
|
|
|
|
try {
|
|
@@ -443,6 +487,12 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
|
|
|
|
|
|
}
|
|
|
|
|
|
+// private List<String> getLeafRespOnlyOne(Long hospId, List<Responsibility> leafResp) {
|
|
|
+// List<Long> parentIds = leafResp.stream().map(Responsibility::getParentId).collect(Collectors.toList());
|
|
|
+// responsibilityService.getById(pare)
|
|
|
+//
|
|
|
+// }
|
|
|
+
|
|
|
private List<HospProfitAndLoss> getAllDataByDate(int year, int month, Long hospId) {
|
|
|
return this.list(
|
|
|
new LambdaQueryWrapper<HospProfitAndLoss>()
|