Procházet zdrojové kódy

Merge branch 'master' of huangrui/CostAccount into dev

lijiaxi před 4 roky
rodič
revize
932b78923b

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

@@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
 import com.imed.costaccount.common.util.PageUtils;
 import com.imed.costaccount.model.HospProfitAndLoss;
 
+import javax.servlet.http.HttpServletResponse;
+
 /**
  * 全院损益表
  *
@@ -31,5 +33,14 @@ public interface HospProfitAndLossService extends IService<HospProfitAndLoss> {
      * @return PageUtils
      */
     PageUtils getHospProfits(Integer current, Integer pageSize, String date, Long hospId);
+
+    /**
+     * 导出全院损益计算
+     * @param date yyyy-MM-dd
+     * @param hospId
+     * @param response
+     */
+    void hospProfitReport(String date, Long hospId, HttpServletResponse response);
+
 }
 

+ 7 - 0
src/main/java/com/imed/costaccount/service/ResponsibilityService.java

@@ -102,5 +102,12 @@ public interface ResponsibilityService extends IService<Responsibility> {
     String getByCode(String valueResponsibilityCode, Long hospId);
 
     Long getLevelIdByCode(String responsibilityCode, Long hospId);
+
+    /**
+     * 获取某个医院所有叶子节点的收益中心的责任中心
+     * @param hospId 医院id
+     * @return List
+     */
+    List<Responsibility> getLeafResp(Long hospId);
 }
 

+ 7 - 2
src/main/java/com/imed/costaccount/service/impl/AccountingProductServiceImpl.java

@@ -25,6 +25,7 @@ import org.springframework.transaction.annotation.Transactional;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.Objects;
 import java.util.stream.Collectors;
 
 
@@ -52,7 +53,7 @@ public class AccountingProductServiceImpl extends ServiceImpl<AccountingProductM
         List<Accounting> list = accountingMapper.selectList(
                 new LambdaQueryWrapper<Accounting>()
                         .eq(Accounting::getHospId, user.getHospId())
-                        .eq(Accounting::getAccountingType,accountType)
+                        .eq(Accounting::getAccountingType, accountType)
                         .orderByDesc(Accounting::getCreateTime)
         );
 
@@ -128,8 +129,12 @@ public class AccountingProductServiceImpl extends ServiceImpl<AccountingProductM
         Long accountId = accountProductSaveDTO.getId();
         // 删除所有原来的关系
         this.remove(new LambdaQueryWrapper<AccountingProduct>().eq(AccountingProduct::getAccountingId, accountId));
-        Long hospId = UserContext.getHospId();
+        Long hospId = user.getHospId();
         List<Long> products = accountProductSaveDTO.getProducts();
+        // 如果是空表示解绑,不处理更新保存逻辑
+        if (Objects.isNull(products)) {
+            return;
+        }
         List<AccountingProduct> accountingProducts = products.stream().map(i -> {
             AccountingProduct accountingProduct = new AccountingProduct();
             accountingProduct.setAccountingId(accountId)

+ 47 - 1
src/main/java/com/imed/costaccount/service/impl/HospProfitAndLossServiceImpl.java

@@ -3,8 +3,12 @@ package com.imed.costaccount.service.impl;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.io.IoUtil;
+import cn.hutool.core.util.RandomUtil;
 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 com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.imed.costaccount.common.enums.CalcTypeEnum;
@@ -23,6 +27,9 @@ import com.imed.costaccount.mapper.HospProfitAndLossMapper;
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
 import java.math.BigDecimal;
 import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
@@ -41,6 +48,7 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
     private final ReportRelationService reportRelationService;
     private final CostShareLevelService shareLevelService;
     private final CostOtherPaymentsDataService otherPaymentsDataService;
+    private final ResponsibilityService responsibilityService;
 
     public HospProfitAndLossServiceImpl(ReportFormService reportFormService,
                                         IncomeCollectionService collectionService,
@@ -48,7 +56,7 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
                                         AllocationService allocationService,
                                         ReportRelationService reportRelationService,
                                         CostShareLevelService shareLevelService,
-                                        CostOtherPaymentsDataService otherPaymentsDataService) {
+                                        CostOtherPaymentsDataService otherPaymentsDataService, ResponsibilityService responsibilityService) {
         this.reportFormService = reportFormService;
         this.collectionService = collectionService;
         this.allocationQueryService = allocationQueryService;
@@ -56,6 +64,7 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
         this.reportRelationService = reportRelationService;
         this.shareLevelService = shareLevelService;
         this.otherPaymentsDataService = otherPaymentsDataService;
+        this.responsibilityService = responsibilityService;
     }
 
 
@@ -366,5 +375,42 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
         PageUtils pageUtils = new PageUtils(pages);
         pageUtils.setList(hospProfitVOS);
         return pageUtils;
+    }
+
+    /**
+     * 导出全院损益计算
+     *  @param date yyyy-MM-dd
+     * @param hospId
+     * @param response
+     */
+    @Override
+    public void hospProfitReport(String date, Long hospId, HttpServletResponse response) {
+        DateTime parse = DateUtil.parse(date);
+        int year = DateUtil.year(parse);
+        int month = DateUtil.month(parse) + 1;
+
+        // 得到所有责任中心的子节点
+        List<Responsibility> leafResp= responsibilityService.getLeafResp(hospId);
+
+        ExcelWriter writer = ExcelUtil.getWriter();
+        writer.write(leafResp.stream().map(Responsibility::getResponsibilityName).collect(Collectors.toList()));
+
+
+        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
+        response.setHeader("Content-Disposition", "attachment;filename=" + year + month + ".xls");
+        ServletOutputStream out = null;
+
+        try {
+            out = response.getOutputStream();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        writer.flush(out, true);
+        writer.close();
+        IoUtil.close(out);
+
+
+
+
     }
 }

+ 5 - 3
src/main/java/com/imed/costaccount/service/impl/ReportFormServiceImpl.java

@@ -141,7 +141,7 @@ public class ReportFormServiceImpl extends ServiceImpl<ReportFormMapper, ReportF
             reportForm.setReportType(byId.getReportType());
             // 如果子节点 小计只能存在一个
             if (reportForm.getCalcType() == 3) {
-                this.isSubtotal(parentId, hospId);
+                this.isSubtotal(parentId, hospId, reportForm.getId());
             }
             if (reportForm.getCalcType() == 4) {
                 // 校验计算公式合法性 [7]+[11]-[22]
@@ -202,14 +202,16 @@ public class ReportFormServiceImpl extends ServiceImpl<ReportFormMapper, ReportF
      * 子类型中小计计算类型只能存在一个
      * 判断是否存在小计的计算类型,存在抛出异常
      *
+     * @param id
      * @param parentId 父级id
      * @param hospId   医院id
      */
-    private void isSubtotal(Long parentId, Long hospId) {
+    private void isSubtotal(Long id, Long parentId, Long hospId) {
         List<ReportForm> list = this.list(
                 new LambdaQueryWrapper<ReportForm>().select(ReportForm::getId)
                         .eq(ReportForm::getParentId, parentId).eq(ReportForm::getHospId, hospId).eq(ReportForm::getCalcType, THREE)
-        );
+        ).stream().filter(i -> !i.getId().equals(id)).collect(Collectors.toList());
+
         if (list.isEmpty()) {
             return;
         }

+ 17 - 0
src/main/java/com/imed/costaccount/service/impl/ResponsibilityServiceImpl.java

@@ -534,4 +534,21 @@ public class ResponsibilityServiceImpl extends ServiceImpl<ResponsibilityMapper,
         }
         return one.getShareId();
     }
+
+    /**
+     * 获取某个医院所有叶子节点的收益中心的责任中心
+     *
+     * @param hospId 医院id
+     * @return List
+     */
+    @Override
+    public List<Responsibility> getLeafResp(Long hospId) {
+        List<Responsibility> list = this.list(
+                new LambdaQueryWrapper<Responsibility>()
+                        .eq(Responsibility::getHospId, hospId)
+                        .eq(Responsibility::getIsGatherCenter, 2)
+                        .eq(Responsibility::getResponsibilityType, 1)
+        );
+        return list;
+    }
 }

+ 8 - 0
src/main/java/com/imed/costaccount/web/HospProfitAndLossController.java

@@ -8,6 +8,8 @@ import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpServletResponse;
+
 @Api(tags = "全院损益相关")
 @RestController
 @RequestMapping("/costAccount/hospProfitAndLoss")
@@ -35,4 +37,10 @@ public class HospProfitAndLossController extends AbstractController {
         PageUtils pageUtils = hospProfitAndLossService.getHospProfits(current, pageSize, date, getHospId());
         return Result.ok(pageUtils);
     }
+
+    @ApiOperation("全院损益计算输出")
+    @PostMapping("/report")
+    public void hospProfitReport(@RequestParam String date, HttpServletResponse response) {
+        hospProfitAndLossService.hospProfitReport(date,getHospId(),response);
+    }
 }