2
0
Эх сурвалжийг харах

08 18 02 fix 报表辅助功能

hr 4 жил өмнө
parent
commit
78d61943de

+ 11 - 4
src/main/java/com/imed/costaccount/service/ShareParamValueService.java

@@ -16,7 +16,7 @@ import java.util.List;
  * 成本分摊参数值设置
  *
  * @author huangrui
- * @email 
+ * @email  fantaandcolo@gmail.com
  * @date 2021-08-17 10:03:48
  */
 public interface ShareParamValueService extends IService<ShareParamValue> {
@@ -34,8 +34,8 @@ public interface ShareParamValueService extends IService<ShareParamValue> {
 
     /**
      * 添加分摊参数值
-     * @param shareParamValueSaveDTO
-     * @param hospId
+     * @param shareParamValueSaveDTO {@link ShareParamValueSaveDTO}
+     * @param hospId 医院id
      */
     public void addData(ShareParamValueSaveDTO shareParamValueSaveDTO, Long hospId);
 
@@ -62,10 +62,17 @@ public interface ShareParamValueService extends IService<ShareParamValue> {
     /**
      * 编辑某条数据
      * @param shareParamValueEditDTO {@link ShareParamValueEditDTO}
-     * @param hospId
+     * @param hospId 医院id
      */
     void editParamValue(ShareParamValueEditDTO shareParamValueEditDTO, Long hospId);
 
 
+    /**
+     * 计算数值
+     *
+     * @param date 日期 yyyyMM
+     * @param hospId 医院id
+     */
+    void calcData(String date, Long hospId);
 }
 

+ 57 - 20
src/main/java/com/imed/costaccount/service/impl/ReportFormServiceImpl.java

@@ -10,6 +10,7 @@ import com.imed.costaccount.common.util.BeanUtil;
 import com.imed.costaccount.common.util.CommonUtil;
 import com.imed.costaccount.mapper.ReportFormMapper;
 import com.imed.costaccount.model.ReportForm;
+import com.imed.costaccount.model.ReportRelation;
 import com.imed.costaccount.model.User;
 import com.imed.costaccount.model.dto.CopyReportDTO;
 import com.imed.costaccount.model.dto.ReportFormEditDTO;
@@ -98,7 +99,7 @@ public class ReportFormServiceImpl extends ServiceImpl<ReportFormMapper, ReportF
     @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
     public void saveReport(ReportFormSaveDTO reportFormDTO, Long hospId) {
         ReportForm reportForm = BeanUtil.convertObj(reportFormDTO, ReportForm.class);
-        Integer num = this.createNum(hospId,reportFormDTO.getReportType());
+        Integer num = this.createNum(hospId, reportFormDTO.getReportType());
         reportForm.setHospId(hospId)
                 .setNum(num)
                 .setCreateTime(System.currentTimeMillis());
@@ -144,16 +145,17 @@ public class ReportFormServiceImpl extends ServiceImpl<ReportFormMapper, ReportF
             }
             if (reportForm.getCalcType() == 4) {
                 // 校验计算公式合法性 [7]+[11]-[22]
-                this.checkCalcFormula(reportForm.getCalcFormula(),hospId,reportForm.getReportType());
+                this.checkCalcFormula(reportForm.getCalcFormula(), hospId, reportForm.getReportType());
             }
         }
     }
 
     /**
      * 校验表达式中的内容是否存在
+     *
      * @param calcFormula 表达式 [7]+[11]-[22]
      */
-    private void checkCalcFormula(String calcFormula,Long hospId,Integer reportType) {
+    private void checkCalcFormula(String calcFormula, Long hospId, Integer reportType) {
         // 校验公式不存在单独的'[' 或 ']',中括号未闭合
         boolean flag = CommonUtil.whetherStringClose(calcFormula);
         if (!flag) {
@@ -214,15 +216,15 @@ public class ReportFormServiceImpl extends ServiceImpl<ReportFormMapper, ReportF
     /**
      * 创建最新的num 获取最大的num + 1
      *
-     * @param hospId 医院id
+     * @param hospId     医院id
      * @param reportType 计算类型
      * @return 返回本医院最新编号
      */
-    private Integer createNum(Long hospId,Integer reportType) {
+    private Integer createNum(Long hospId, Integer reportType) {
         ReportForm one = this.getOne(
                 new LambdaQueryWrapper<ReportForm>().select(ReportForm::getNum)
                         .eq(ReportForm::getHospId, hospId)
-                        .eq(ReportForm::getReportType,reportType)
+                        .eq(ReportForm::getReportType, reportType)
                         .orderByDesc(ReportForm::getNum).last(LIMIT_ONE)
         );
         if (Objects.isNull(one)) {
@@ -266,6 +268,7 @@ public class ReportFormServiceImpl extends ServiceImpl<ReportFormMapper, ReportF
 
     /**
      * 辅助数据
+     *  计算过于复杂建议多线程处理
      *
      * @param copyReportDTO {@link CopyReportDTO}
      * @param hospId        医院id
@@ -287,30 +290,44 @@ public class ReportFormServiceImpl extends ServiceImpl<ReportFormMapper, ReportF
         // 删除掉需要复制到的数据
         this.remove(new LambdaQueryWrapper<ReportForm>().eq(ReportForm::getHospId, hospId).eq(ReportForm::getReportType, toReportType));
 
-       // 先添加父层级数据
-       list.forEach(i -> {
-           if (i.getParentId() == 0) {
-               // 旧id
-               i.setOldId(i.getId());
-               i.setId(null);
-               i.setReportType(toReportType);
-               i.setCreateTime(System.currentTimeMillis());
-               // 父节点不存在计算公式问题
-               this.save(i);
-           }
-       });
+        // 先添加父层级数据
+        list.forEach(i -> {
+            if (i.getParentId() == 0) {
+                // 旧id
+                i.setOldId(i.getId());
+                i.setId(null);
+                i.setReportType(toReportType);
+                i.setCreateTime(System.currentTimeMillis());
+                // 父节点不存在计算公式问题
+                this.save(i);
+            }
+        });
 
-       // 处理子节点
+        // 处理子节点 以及子节点关联的关系
         List<ReportForm> childrenForms = list.stream().filter(i -> i.getParentId() != 0).collect(Collectors.toList());
         List<ReportForm> newParentForms = this.list(
                 new LambdaQueryWrapper<ReportForm>()
-                        .select(ReportForm::getOldId)
+                        .select(ReportForm::getOldId,ReportForm::getId)
                         .eq(ReportForm::getHospId, hospId)
                         .eq(ReportForm::getReportType, toReportType)
+                        .eq(ReportForm::getParentId, 0)
+        );
+        if (newParentForms.isEmpty()) {
+            return;
+        }
+        List<ReportRelation> relations = reportRelationService.list(
+                new LambdaQueryWrapper<ReportRelation>()
+                        .eq(ReportRelation::getHospId, hospId)
+                        .in(ReportRelation::getReportId, childrenForms.stream().map(ReportForm::getId).collect(Collectors.toList()))
         );
+        if (childrenForms.isEmpty()) {
+            return;
+        }
         childrenForms.forEach(i -> {
             newParentForms.forEach(j -> {
                 if (j.getOldId() != 0 && j.getOldId().equals(i.getParentId())) {
+                    i.setOldId(i.getId());
+                    i.setId(null);
                     i.setParentId(j.getId());
                     i.setCreateTime(System.currentTimeMillis());
                     i.setReportType(toReportType);
@@ -319,5 +336,25 @@ public class ReportFormServiceImpl extends ServiceImpl<ReportFormMapper, ReportF
             });
         });
 
+        // 得到新的子节点
+        List<ReportForm> newSonForms = this.list(
+                new LambdaQueryWrapper<ReportForm>()
+                        .select(ReportForm::getOldId,ReportForm::getId)
+                        .eq(ReportForm::getHospId, hospId)
+                        .eq(ReportForm::getReportType, toReportType)
+                        .ne(ReportForm::getParentId, 0)
+        );
+
+        if (relations.isEmpty() || newSonForms.isEmpty()) {
+            return;
+        }
+       newSonForms.forEach(i -> {
+           relations.forEach(j -> {
+               if (i.getOldId() != 0 && i.getOldId().equals(j.getReportId())) {
+                   j.setReportId(i.getId());
+                   reportRelationService.save(j);
+               }
+           });
+       });
     }
 }

+ 66 - 16
src/main/java/com/imed/costaccount/service/impl/ShareParamValueServiceImpl.java

@@ -19,10 +19,7 @@ import com.imed.costaccount.model.dto.ShareParamValueEditDTO;
 import com.imed.costaccount.model.dto.ShareParamValueSaveDTO;
 import com.imed.costaccount.model.dto.ShareParamValueVO;
 import com.imed.costaccount.model.vo.IncomeErrorMessage;
-import com.imed.costaccount.service.CostIncomeFileService;
-import com.imed.costaccount.service.CostShareParamService;
-import com.imed.costaccount.service.ResponsibilityService;
-import com.imed.costaccount.service.ShareParamValueService;
+import com.imed.costaccount.service.*;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
@@ -31,6 +28,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 import java.math.BigDecimal;
 import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.stream.Collectors;
 
 import static cn.hutool.core.date.DatePattern.PURE_DATE_PATTERN;
@@ -47,14 +45,18 @@ public class ShareParamValueServiceImpl extends ServiceImpl<ShareParamValueMappe
 
     private final ResponsibilityService responsibilityService;
 
+    private final IncomeCollectionService incomeCollectionService;
+
 
     public ShareParamValueServiceImpl(CostIncomeGroupServiceImpl costIncomeGroupService,
                                       CostShareParamService costShareParamService,
-                                      CostIncomeFileService costIncomeFileService, ResponsibilityService responsibilityService) {
+                                      CostIncomeFileService costIncomeFileService,
+                                      ResponsibilityService responsibilityService, IncomeCollectionService incomeCollectionService) {
         this.costIncomeGroupService = costIncomeGroupService;
         this.costShareParamService = costShareParamService;
         this.costIncomeFileService = costIncomeFileService;
         this.responsibilityService = responsibilityService;
+        this.incomeCollectionService = incomeCollectionService;
     }
 
 
@@ -75,7 +77,7 @@ public class ShareParamValueServiceImpl extends ServiceImpl<ShareParamValueMappe
             throw new CostException("本月已存在对应责任中心和分摊参数中心,请直接修改");
         }
         // 校验两个code是否存在
-        checkCodeIsExist(shareParamValueSaveDTO.getShareParamCode(), shareParamValueSaveDTO.getResponsibilityCode(),hospId);
+        checkCodeIsExist(shareParamValueSaveDTO.getShareParamCode(), shareParamValueSaveDTO.getResponsibilityCode(), hospId);
         paramValue.setCreateTime(System.currentTimeMillis())
                 .setDateYear(DateUtil.year(dateTime))
                 .setDateMonth(DateUtil.month(dateTime) + 1)
@@ -86,11 +88,12 @@ public class ShareParamValueServiceImpl extends ServiceImpl<ShareParamValueMappe
 
     /**
      * 校验两个code是否存在
-     * @param shareParamCode
-     * @param responsibilityCode
-     * @param hospId
+     *
+     * @param shareParamCode     成本分摊参数code
+     * @param responsibilityCode 责任中心代码
+     * @param hospId             医院id
      */
-    @Transactional(rollbackFor = Throwable.class,propagation = Propagation.REQUIRED)
+    @Transactional(rollbackFor = Throwable.class, propagation = Propagation.REQUIRED)
     public void checkCodeIsExist(String shareParamCode, String responsibilityCode, Long hospId) {
         List<CostShareParam> shareParams = costShareParamService.list(new LambdaQueryWrapper<CostShareParam>().select(CostShareParam::getId)
                 .eq(CostShareParam::getShareParamCode, shareParamCode).eq(CostShareParam::getHospId, hospId));
@@ -123,10 +126,7 @@ public class ShareParamValueServiceImpl extends ServiceImpl<ShareParamValueMappe
                         .eq(ShareParamValue::getDateYear, DateUtil.year(date))
                         .eq(ShareParamValue::getDateMonth, DateUtil.month(date) + 1)
         );
-        if (!list.isEmpty()) {
-            return true;
-        }
-        return false;
+        return !list.isEmpty();
     }
 
     /**
@@ -296,7 +296,7 @@ public class ShareParamValueServiceImpl extends ServiceImpl<ShareParamValueMappe
             i.setDataSourceType(1);
         });
         // 保存数据的唯一性
-        Map<String, List<ShareParamValue>> map = shareParamValues.stream().collect(Collectors.groupingBy(k -> k.getShareParamCode().trim() + "code" + k.getResponsibilityCode().trim()+k.getDateYear().toString().trim()+"code"+k.getDateMonth().toString().trim()
+        Map<String, List<ShareParamValue>> map = shareParamValues.stream().collect(Collectors.groupingBy(k -> k.getShareParamCode().trim() + "code" + k.getResponsibilityCode().trim() + k.getDateYear().toString().trim() + "code" + k.getDateMonth().toString().trim()
         ));
         LinkedList<ShareParamValue> realList = new LinkedList<>();
         Set<String> strings = map.keySet();
@@ -356,7 +356,7 @@ public class ShareParamValueServiceImpl extends ServiceImpl<ShareParamValueMappe
                 }
             }
             if (CollectionUtils.isEmpty(incomeErrorMessageList)) {
-                incomeErrorMessageList=new ArrayList<>();
+                incomeErrorMessageList = new ArrayList<>();
                 // 检验数据是否全为0
                 int zeroStatus = 0;
                 for (int j = 2; j < data.size(); j++) {
@@ -414,4 +414,54 @@ public class ShareParamValueServiceImpl extends ServiceImpl<ShareParamValueMappe
     }
 
 
+    /**
+     * 计算数值
+     *
+     * @param date   日期 yyyyMM
+     * @param hospId 医院id
+     */
+    @Override
+    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
+    public void calcData(String date, Long hospId) {
+        DateTime parse = DateUtil.parse(date, PURE_DATE_PATTERN);
+        int year = DateUtil.year(parse);
+        int month = DateUtil.month(parse) + 1;
+        // 拿到这些年月的数据
+        List<ShareParamValue> list = this.list(
+                new LambdaQueryWrapper<ShareParamValue>()
+                        .eq(ShareParamValue::getDateYear, year).eq(ShareParamValue::getDateMonth, month).eq(ShareParamValue::getHospId, hospId)
+        );
+        // 得到这些责任中心代码
+        List<String> responsibilityCodes = list.stream().map(ShareParamValue::getResponsibilityCode).distinct().collect(Collectors.toList());
+        List<IncomeCollection> incomeCollections = incomeCollectionService.list(
+                new LambdaQueryWrapper<IncomeCollection>()
+                        .eq(IncomeCollection::getYear, year)
+                        .eq(IncomeCollection::getMonth, month)
+                        .eq(IncomeCollection::getHospId, hospId)
+                        .in(IncomeCollection::getResponsibilityCode, responsibilityCodes)
+        );
+        if (incomeCollections.isEmpty()) {
+            throw new CostException("本月未归集数据,请先归集数据");
+        }
+
+        Map<String, List<IncomeCollection>> collectMap = incomeCollections.stream().collect(Collectors.groupingBy(IncomeCollection::getResponsibilityCode));
+        Set<String> strings = collectMap.keySet();
+        Map<String,BigDecimal> map = new ConcurrentHashMap<>();
+        for (String str : strings) {
+            List<IncomeCollection> collections = collectMap.get(str);
+            if (CollUtil.isNotEmpty(collections)) {
+                BigDecimal reduce = incomeCollections.stream().map(IncomeCollection::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
+                IncomeCollection incomeCollection = incomeCollections.get(0);
+                incomeCollection.setAmount(reduce);
+                map.put(str, reduce);
+            }
+        }
+        list.forEach(i -> {
+            BigDecimal bigDecimal = map.get(i);
+            if (Objects.nonNull(bigDecimal)) {
+                i.setValueNum(bigDecimal);
+            }
+        });
+        this.updateBatchById(list);
+    }
 }

+ 10 - 0
src/main/java/com/imed/costaccount/web/ShareParamValueController.java

@@ -86,4 +86,14 @@ public class ShareParamValueController extends AbstractController {
         return Result.ok();
     }
 
+    @ApiOperation("计算数值")
+    @PostMapping("/calcData")
+    public Result calcData(@RequestParam String date) {
+        if (date.length() == 6) {
+            date = date.concat("01");
+        }
+        shareParamValueService.calcData(date, getHospId());
+        return Result.ok();
+    }
+
 }