فهرست منبع

Merge branch 'master' of huangrui/CostAccount into dev

lijiaxi 4 سال پیش
والد
کامیت
dc9bfb3063
1فایلهای تغییر یافته به همراه21 افزوده شده و 19 حذف شده
  1. 21 19
      src/main/java/com/imed/costaccount/service/impl/CostDepartmentProfitServiceImpl.java

+ 21 - 19
src/main/java/com/imed/costaccount/service/impl/CostDepartmentProfitServiceImpl.java

@@ -3,6 +3,7 @@ package com.imed.costaccount.service.impl;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.StrUtil;
+import cn.hutool.poi.excel.ExcelWriter;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -10,6 +11,7 @@ import com.imed.costaccount.common.exception.CostException;
 import com.imed.costaccount.common.util.BeanUtil;
 import com.imed.costaccount.common.util.DateUtils;
 import com.imed.costaccount.common.util.PageUtils;
+import com.imed.costaccount.common.util.UserContext;
 import com.imed.costaccount.constants.NumberConstant;
 import com.imed.costaccount.common.enums.DateStyleEnum;
 import com.imed.costaccount.mapper.CostDepartmentProfitMapper;
@@ -17,6 +19,7 @@ import com.imed.costaccount.model.*;
 import com.imed.costaccount.model.vo.AllocationQueryReportVO;
 import com.imed.costaccount.model.vo.CostDepartmentProfitVO;
 import com.imed.costaccount.service.*;
+import org.apache.poi.ss.usermodel.Sheet;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
@@ -78,7 +81,7 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
                 .eq(CostDepartmentProfit::getHospId, hospId)
                 .eq(StrUtil.isNotBlank(responsibilityCode), CostDepartmentProfit::getResponsibilityCode, responsibilityCode)
                 .eq(StrUtil.isNotBlank(date), CostDepartmentProfit::getYear, year)
-                .eq(StrUtil.isNotBlank(date), CostDepartmentProfit::getMonth, month).ne(CostDepartmentProfit::getCalcType,NumberConstant.ZERO));
+                .eq(StrUtil.isNotBlank(date), CostDepartmentProfit::getMonth, month).ne(CostDepartmentProfit::getCalcType, NumberConstant.ZERO));
         List<CostDepartmentProfit> records = pages.getRecords();
         List<CostDepartmentProfitVO> costDepartmentProfitVOList = BeanUtil.convertList(records, CostDepartmentProfitVO.class);
         PageUtils pageUtils = new PageUtils(pages);
@@ -181,7 +184,7 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
                     break;
                 case 4:
                     // TODO 按照计算公式进行计算
-                    i.setAmount(setCalculation(i,list, costShareLevelList, listMap, incomeList, allocationQueryReportVOList, reportRelationMap, allocationList));
+                    i.setAmount(setCalculation(i, list, costShareLevelList, listMap, incomeList, allocationQueryReportVOList, reportRelationMap, allocationList));
                     break;
                 case 5:
                     // TODO  按照责任中心进行计算
@@ -193,11 +196,8 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
             }
         });
         // 删除这个年月的数据
-        List<CostDepartmentProfit> list1 = this.list(new QueryWrapper<CostDepartmentProfit>().lambda().eq(CostDepartmentProfit::getHospId, hospId)
+        this.remove(new QueryWrapper<CostDepartmentProfit>().lambda().eq(CostDepartmentProfit::getHospId, hospId)
                 .eq(CostDepartmentProfit::getYear, year).eq(CostDepartmentProfit::getMonth, month));
-        if (CollUtil.isNotEmpty(list1)){
-            this.removeByIds(list1);
-        }
         // 添加数据
         List<CostDepartmentProfit> costDepartmentProfits = BeanUtil.convertList(list, CostDepartmentProfit.class);
         long l = System.currentTimeMillis();
@@ -232,7 +232,7 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
             // 成本减
             if (CollUtil.isNotEmpty(reportVOList)) {
                 reportVOList.forEach(m -> {
-                    sum.updateAndGet(v -> v.subtract(m.getAmount()));
+                    sum.updateAndGet(v -> v.add(m.getAmount()));
                 });
             }
         }
@@ -327,24 +327,26 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
     /***
      * 按照计算方式进行计算
      */
-    public BigDecimal setCalculation(CostDepartmentProfitVO costDepartmentProfitVO, List<CostDepartmentProfitVO> costDepartmentProfitVOList ,List<CostShareLevel> costShareLevelList, Map<Long, List<CostDepartmentProfitVO>> listMap, List<IncomeCollection> list, List<AllocationQueryReportVO> allocationQueryReportVOList, Map<Long, List<ReportRelation>> reportRelationMap, List<Allocation> allocationList) {
-        // 获取当前报表的计算方式  [1]+[2]类型
+    public BigDecimal setCalculation(CostDepartmentProfitVO costDepartmentProfitVO, List<CostDepartmentProfitVO> costDepartmentProfitVOList, List<CostShareLevel> costShareLevelList, Map<Long, List<CostDepartmentProfitVO>> listMap, List<IncomeCollection> list, List<AllocationQueryReportVO> allocationQueryReportVOList, Map<Long, List<ReportRelation>> reportRelationMap, List<Allocation> allocationList) {
+        // 获取当前报表的计算方式  [1]+[2]类型/ [1]-[2]
         String calcFormula = costDepartmentProfitVO.getCalcFormula();
         String responsibilityCode = costDepartmentProfitVO.getResponsibilityCode();
-        String replace = calcFormula.replace("[", "").replace("]", "").replace("+", ",").replace("-",",");
+        String replace = calcFormula.replace("[", "").replace("]", "").replace("+", ",").replace("-", ",");
         List<Integer> calcFormulaList = Arrays.stream(replace.split(StrUtil.COMMA)).map(Integer::valueOf).collect(Collectors.toList());
         // 查询这个编号集合的报表
-        List<Long> reportIdList = costDepartmentProfitVOList.stream().filter(i -> i.getResponsibilityCode().equals(responsibilityCode) && calcFormulaList.contains(i.getReportNum())).map(CostDepartmentProfitVO::getReportParentId).collect(Collectors.toList());
+        List<Long> reportIdList = costDepartmentProfitVOList.stream().filter(i -> i.getResponsibilityCode().equals(responsibilityCode) && calcFormulaList.contains(i.getReportNum())).map(CostDepartmentProfitVO::getReportId).collect(Collectors.toList());
 
         AtomicReference<BigDecimal> bigDecimal = new AtomicReference<>(new BigDecimal("0.0000"));
-        reportIdList.forEach(i -> {
-            List<CostDepartmentProfitVO> profitVOS = listMap.get(i);
-            if (CollUtil.isEmpty(profitVOS)) {
-                throw new CostException(500, "报表未找到");
-            }
-            BigDecimal amount = getAmount(profitVOS, costShareLevelList, responsibilityCode, list, allocationQueryReportVOList, reportRelationMap, allocationList, listMap);
-            bigDecimal.updateAndGet(v -> v.add(amount));
-        });
+        if (CollUtil.isNotEmpty(reportIdList)) {
+            reportIdList.forEach(i -> {
+                List<CostDepartmentProfitVO> profitVOS = listMap.get(i);
+                if (CollUtil.isEmpty(profitVOS)) {
+                    throw new CostException(500, "报表未找到");
+                }
+                BigDecimal amount = getAmount(profitVOS, costShareLevelList, responsibilityCode, list, allocationQueryReportVOList, reportRelationMap, allocationList, listMap);
+                bigDecimal.updateAndGet(v -> v.add(amount));
+            });
+        }
         return bigDecimal.get();
     }