소스 검색

科室损益计算

ljx 4 년 전
부모
커밋
4f066140bc

+ 8 - 0
src/main/java/com/imed/costaccount/service/DepartmentProfitFileService.java

@@ -22,5 +22,13 @@ public interface DepartmentProfitFileService extends IService<DepartmentProfitFi
      * @return
      */
     PageUtils queryList(Integer current, Integer pageSize, String date, String reportName, Long hospId);
+
+    /**
+     * 添加科室损益记录
+     * @param date 时间
+     * @param reportType 报表类型
+     * @param hospId 医院ID
+     */
+    void addDepartmentProfitFile(String date, Integer reportType, Long hospId);
 }
 

+ 16 - 6
src/main/java/com/imed/costaccount/service/impl/CostDepartmentProfitServiceImpl.java

@@ -120,6 +120,7 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
         if (CollUtil.isEmpty(costShareLevelList)) {
             throw new CostException(500, "分摊层级未设置");
         }
+        // TODO 可能多个
         Long id = costShareLevelList.get(0).getId();
         // 查询责任中心里面是这个层级的所有的收益中心
         List<Responsibility> responsibilityList = responsibilityService.list(new QueryWrapper<Responsibility>().lambda()
@@ -132,7 +133,7 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
             throw new CostException(500, "归集后数据不存在");
         }
         Map<Long, List<ReportRelation>> reportRelationMap = reportRelationService.list(new QueryWrapper<ReportRelation>().lambda().eq(ReportRelation::getHospId, hospId)).stream().collect(Collectors.groupingBy(ReportRelation::getReportId));
-        // 分摊后的数据getOriginType等于2说明是分摊后的数据
+        // 分摊后的数据说明是分摊后的数据
         List<AllocationQuery> allocationQueryList = allocationQueryService.list(new QueryWrapper<AllocationQuery>().lambda().eq(AllocationQuery::getHospId, hospId)
                 .eq(year > 0, AllocationQuery::getDateYear, year)
                 .eq(month > 0, AllocationQuery::getDateMonth, month)
@@ -376,6 +377,13 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
                 writer.merge(jj, i + 1, 0, 0, cellValue1, false);
             }
         }
+        // 设置列宽
+        for (int i = 0; i < 50; i++) {
+            // 调整每一列宽度
+            sheet.autoSizeColumn((short) i);
+            // 解决自动设置列宽中文失效的问题
+            sheet.setColumnWidth(i, sheet.getColumnWidth(i) * 14 / 10);
+        }
     }
 
     /**
@@ -457,9 +465,11 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
                 // 查询报表里面是当前分摊层级的数据
                 List<Allocation> allocations = allocationList.stream().filter(i -> i.getTargetResponsibilityCode().equals(costDepartmentProfitVO.getResponsibilityCode()) && responsibilityCodes.contains(i.getResponsibilityCode())).collect(Collectors.toList());
                 if (CollUtil.isNotEmpty(allocations)) {
-                    allocations.forEach(m -> {
-                        sum.updateAndGet(v -> v.add(m.getAmount()));
-                    });
+                    BigDecimal reduce = allocations.stream().map(Allocation::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
+                    sum.set(reduce);
+//                    allocations.forEach(m -> {
+//                        sum.updateAndGet(v -> v.add(m.getAmount()));
+//                    });
                 }
             }
         }
@@ -483,7 +493,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.getCalcType())).collect(Collectors.toList());
+        List<CostDepartmentProfitVO> costDepartmentProfitVOS = allList.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 -> {
@@ -493,7 +503,7 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
                 throw new CostException(500, "报表未找到");
             }
             BigDecimal amount = getAmount(costDepartmentProfitVOS1, costShareLevelList, responsibilityCode, list, allocationQueryReportVOList, reportRelationMap, allocationList, listMap,allList);
-            sum.updateAndGet(v -> v.add(amount));
+            sum.set(amount.add(sum.get()));;
         });
 //        costDepartmentProfitVO.setAmount(new BigDecimal(sum.toString()));
         return sum.get();

+ 34 - 3
src/main/java/com/imed/costaccount/service/impl/DepartmentProfitFileServiceImpl.java

@@ -13,6 +13,8 @@ import com.imed.costaccount.model.DepartmentProfitFile;
 import com.imed.costaccount.model.vo.DepartmentProfitFileVO;
 import com.imed.costaccount.service.DepartmentProfitFileService;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.List;
 
@@ -33,9 +35,14 @@ public class DepartmentProfitFileServiceImpl extends ServiceImpl<DepartmentProfi
      */
     @Override
     public PageUtils queryList(Integer current, Integer pageSize, String date, String reportName, Long hospId) {
-        DateTime dateTime = DateUtil.parse(date);
-        int dateYear = DateUtil.year(dateTime);
-        int month=DateUtil.month(dateTime)+1;
+        DateTime dateTime;
+        int dateYear = 0;
+        int month=0;
+        if (StrUtil.isNotBlank(date)){
+            dateTime = DateUtil.parse(date);
+            dateYear = DateUtil.year(dateTime);
+            month=DateUtil.month(dateTime)+1;
+        }
         Page<DepartmentProfitFile> profitFilePage = new Page<>(current, pageSize);
         Page<DepartmentProfitFile> pages = this.page(profitFilePage, new QueryWrapper<DepartmentProfitFile>()
                 .lambda()
@@ -51,4 +58,28 @@ public class DepartmentProfitFileServiceImpl extends ServiceImpl<DepartmentProfi
         return pageUtils;
     }
 
+    /**
+     * 添加科室损益记录
+     *
+     * @param date       时间
+     * @param reportType 报表类型
+     * @param hospId     医院ID
+     */
+    @Override
+    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
+    public void addDepartmentProfitFile(String date, Integer reportType, Long hospId) {
+        DepartmentProfitFile departmentProfitFile = new DepartmentProfitFile();
+        DateTime dateTime = DateUtil.parse(date);
+        int year = DateUtil.year(dateTime);
+        int month = DateUtil.month(dateTime)+1;
+        departmentProfitFile.setHospId(hospId);
+        departmentProfitFile.setYear(year);
+        departmentProfitFile.setMonth(month);
+        departmentProfitFile.setReportType(reportType);
+        String reportName=reportType==1?year+"年"+month+"月-损益表.xlsx":year+"年"+month+"月-其他表.xlsx";
+        departmentProfitFile.setReportName(reportName);
+        departmentProfitFile.setCreateTime(System.currentTimeMillis());
+        this.save(departmentProfitFile);
+    }
+
 }

+ 10 - 1
src/main/java/com/imed/costaccount/web/DepartmentProfitFileController.java

@@ -49,7 +49,16 @@ public class DepartmentProfitFileController {
         return Result.ok(pageUtils);
     }
 
-
+    /**
+     * 计算科室损益记录
+     */
+    @PostMapping("addDepartmentProfitFile")
+    @ApiOperation("添加科室损益记录")
+    public Result addDepartmentProfitFile(String date,Integer reportType){
+        Long hospId = UserContext.getHospId();
+        departmentProfitFileService.addDepartmentProfitFile(date,reportType,hospId);
+        return Result.ok();
+    }
     /**
      * 信息
      */