Prechádzať zdrojové kódy

Merge branch 'master' of huangrui/CostAccount into dev

lijiaxi 4 rokov pred
rodič
commit
eb0702ee5b

+ 6 - 6
pom.xml

@@ -78,12 +78,12 @@
 <!--            <optional>true</optional>-->
 <!--        </dependency>-->
 
-        <!--        <dependency>-->
-        <!--            <groupId>org.springframework.boot</groupId>-->
-        <!--            <artifactId>spring-boot-devtools</artifactId>-->
-        <!--            <scope>runtime</scope>-->
-        <!--            <optional>true</optional>-->
-        <!--        </dependency>-->
+<!--        <dependency>-->
+<!--            <groupId>org.springframework.boot</groupId>-->
+<!--            <artifactId>spring-boot-devtools</artifactId>-->
+<!--            <scope>runtime</scope>-->
+<!--            <optional>true</optional>-->
+<!--        </dependency>-->
 
 
         <!--mysql mybatis-plus等依赖-->

+ 2 - 0
src/main/java/com/imed/costaccount/service/AllocationQueryService.java

@@ -44,5 +44,7 @@ public interface AllocationQueryService extends IService<AllocationQuery> {
      * @return 分摊数据查询
      */
     List<AllocationQuery> getAllByDate(Long hospId, int year, int month);
+
+    List<AllocationQuery> getByDate(int year, int month, Long hospId, List<Integer> levelSorts);
 }
 

+ 6 - 0
src/main/java/com/imed/costaccount/service/ReportFormService.java

@@ -63,5 +63,11 @@ public interface ReportFormService extends IService<ReportForm> {
      * @return List
      */
     List<ReportForm> getByParentId(Long hospId, Long parentId);
+
+    /**
+     * 全院损益的树状结构
+     * @param hospId 医院id
+     */
+    List<ReportFormVO> getAllHospList( Long hospId);
 }
 

+ 11 - 0
src/main/java/com/imed/costaccount/service/impl/AllocationQueryServiceImpl.java

@@ -78,4 +78,15 @@ public class AllocationQueryServiceImpl extends ServiceImpl<AllocationQueryMappe
         );
         return list;
     }
+
+    @Override
+    public List<AllocationQuery> getByDate(int year, int month, Long hospId, List<Integer> levelSorts) {
+        return this.list(
+                new LambdaQueryWrapper<AllocationQuery>()
+                        .eq(AllocationQuery::getDateYear, year)
+                        .eq(AllocationQuery::getDateMonth, month)
+                        .eq(AllocationQuery::getHospId, hospId)
+                        .in(AllocationQuery::getLevelSort, levelSorts)
+        );
+    }
 }

+ 41 - 7
src/main/java/com/imed/costaccount/service/impl/HospProfitAndLossServiceImpl.java

@@ -19,6 +19,7 @@ import com.imed.costaccount.common.util.PageUtils;
 import com.imed.costaccount.model.*;
 import com.imed.costaccount.model.vo.HospProfitVO;
 import com.imed.costaccount.model.vo.RelationVO;
+import com.imed.costaccount.model.vo.ReportFormVO;
 import com.imed.costaccount.service.*;
 import org.springframework.stereotype.Service;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -302,16 +303,19 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
         if (CollUtil.isEmpty(shareLevelId)) {
             return null;
         }
+        // 分摊层级计算金额
+        // TODO: 2021/8/31  
+        
         List<CostShareLevel> costShareLevels = shareLevelService.listByIds(shareLevelId);
         if (costShareLevels.isEmpty()) {
             throw new CostException("医院分摊层级设置错误," + reportForm.getReportName());
         }
         List<Integer> levelSorts = costShareLevels.stream().map(CostShareLevel::getLeverSort).collect(Collectors.toList());
-        List<Allocation> allocations = allocationService.getByDate(year, month, hospId, levelSorts);
+        List<AllocationQuery> allocations = allocationQueryService.getByDate(year, month, hospId, levelSorts);
         if (allocations.isEmpty()) {
             throw new CostException("医院未分摊本月数据");
         }
-        BigDecimal reduce = allocations.stream().map(Allocation::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
+        BigDecimal reduce = allocations.stream().map(AllocationQuery::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
         HospProfitAndLoss loss = new HospProfitAndLoss();
         return loss.setReportName(reportForm.getReportName()).setReportNum(reportForm.getNum())
                 .setAmount(reduce).setCreateTime(System.currentTimeMillis()).setHospId(hospId);
@@ -379,7 +383,8 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
 
     /**
      * 导出全院损益计算
-     *  @param date yyyy-MM-dd
+     *
+     * @param date     yyyy-MM-dd
      * @param hospId
      * @param response
      */
@@ -390,11 +395,42 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
         int month = DateUtil.month(parse) + 1;
 
         // 得到所有责任中心的子节点
-        List<Responsibility> leafResp= responsibilityService.getLeafResp(hospId);
+        List<Responsibility> leafResp = responsibilityService.getLeafResp(hospId);
 
         ExcelWriter writer = ExcelUtil.getWriter();
-        writer.write(leafResp.stream().map(Responsibility::getResponsibilityName).collect(Collectors.toList()));
+        List<String> secondTitleList = leafResp.stream().map(Responsibility::getResponsibilityName).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.writeCellValue(i + 2, 2, str);
+        }
+        // 得到全院损益报表处理 树状结构(only 2层)
+        List<ReportFormVO> allHospList = reportFormService.getAllHospList(hospId);
+        if (allHospList.isEmpty()) {
+            return;
+        }
+        int lastRow = 3;
+        for (int i = 0; i < allHospList.size(); i++) {
+            ReportFormVO parentFormVO = allHospList.get(i);
+            List<ReportFormVO> children = parentFormVO.getChildren();
+            if (CollUtil.isEmpty(children)) {
+                continue;
+            }
+            int size = children.size();
+            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());
+                // 单独计每个数据的责任中心对应的金额
 
+            }
+            lastRow = lastRow + size;
+        }
 
         response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
         response.setHeader("Content-Disposition", "attachment;filename=" + year + month + ".xls");
@@ -410,7 +446,5 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
         IoUtil.close(out);
 
 
-
-
     }
 }

+ 25 - 0
src/main/java/com/imed/costaccount/service/impl/ReportFormServiceImpl.java

@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.imed.costaccount.common.enums.ReportTypeEnum;
 import com.imed.costaccount.common.exception.CostException;
 import com.imed.costaccount.common.util.BeanUtil;
 import com.imed.costaccount.common.util.CommonUtil;
@@ -398,4 +399,28 @@ public class ReportFormServiceImpl extends ServiceImpl<ReportFormMapper, ReportF
         );
         return list;
     }
+
+    /**
+     * 全院损益的树状结构
+     *
+     * @param hospId 医院id
+     */
+    @Override
+    public List<ReportFormVO> getAllHospList(Long hospId) {
+        List<ReportForm> list = this.list(
+                new LambdaQueryWrapper<ReportForm>()
+                        .eq(ReportForm::getReportType, ReportTypeEnum.HOSP_PROFIT_LOSS.getType())
+                        .eq(ReportForm::getHospId, hospId)
+                        .orderByAsc(ReportForm::getSort)
+        );
+        List<ReportFormVO> reportFormVOS = BeanUtil.convertList(list, ReportFormVO.class);
+        List<ReportFormVO> vos = reportFormVOS.stream().filter(i -> i.getParentId() == 0)
+                .peek(i -> i.setChildren(this.getSon(i, reportFormVOS)))
+                .collect(Collectors.toList());
+        return vos;
+    }
+
+    private List<ReportFormVO> getSon(ReportFormVO vo, List<ReportFormVO> reportFormVOS) {
+        return reportFormVOS.stream().filter(o -> vo.getId().equals(o.getParentId())).collect(Collectors.toList());
+    }
 }