Sfoglia il codice sorgente

08 20 01 计算数值修改

hr 4 anni fa
parent
commit
6456911eef

+ 56 - 50
src/main/java/com/imed/costaccount/model/ShareParamValue.java

@@ -1,22 +1,24 @@
 package com.imed.costaccount.model;
 
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableLogic;
 import com.baomidou.mybatisplus.annotation.TableName;
-
-import java.math.BigDecimal;
-import java.io.Serializable;
-import java.util.Date;
-
 import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 import lombok.experimental.Accessors;
 
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.Map;
+
 /**
  * 成本分摊参数值设置
- * 
+ *
  * @author huangrui
- * @email 
+ * @email
  * @date 2021-08-17 10:03:48
  */
 @Data
@@ -25,50 +27,54 @@ import lombok.experimental.Accessors;
 @NoArgsConstructor
 @TableName("cost_share_param_value")
 public class ShareParamValue implements Serializable {
-	private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 主键
+     */
+    @TableId
+    private Long id;
+    /**
+     * 年
+     */
+    private Integer dateYear;
+    /**
+     * 月
+     */
+    private Integer dateMonth;
+    /**
+     * 分摊参数代码
+     */
+    private String shareParamCode;
+    /**
+     * 责任中心代码
+     */
+    private String responsibilityCode;
+    /**
+     * 数值
+     */
+    private BigDecimal valueNum;
+    /**
+     * 医院id
+     */
+    private Long hospId;
+    /**
+     * 数据来源类型 0.手动输入,1.文件导入,2.全部
+     */
+    private Integer dataSourceType;
 
-	/**
-	 * 主键
-	 */
-	@TableId
-	private Long id;
-	/**
-	 * 年
-	 */
-	private Integer dateYear;
-	/**
-	 * 月
-	 */
-	private Integer dateMonth;
-	/**
-	 * 分摊参数代码
-	 */
-	private String shareParamCode;
-	/**
-	 * 责任中心代码
-	 */
-	private String responsibilityCode;
-	/**
-	 * 数值
-	 */
-	private BigDecimal valueNum;
-	/**
-	 * 医院id
-	 */
-	private Long hospId;
-	/**
-	 * 数据来源类型 0.手动输入,1.文件导入,2.全部
-	 */
-	private Integer dataSourceType;
+    private Long fileId;
+    /**
+     *
+     */
+    private Long createTime;
+    /**
+     * 删除时间(逻辑删除)
+     */
+    @TableLogic(value = "0", delval = "UNIX_TIMESTAMP(NOW()) * 1000")
+    private Long deleteTime;
 
-	private Long fileId;
-	/**
-	 * 
-	 */
-	private Long createTime;
-	/**
-	 * 删除时间(逻辑删除)
-	 */
-	private Long deleteTime;
+    @TableField(exist = false)
+    private List<String> calcList;
 
 }

+ 41 - 14
src/main/java/com/imed/costaccount/service/impl/ShareParamValueServiceImpl.java

@@ -20,6 +20,7 @@ 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.*;
+import io.lettuce.core.Limit;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
@@ -32,6 +33,7 @@ import java.util.concurrent.ConcurrentHashMap;
 import java.util.stream.Collectors;
 
 import static cn.hutool.core.date.DatePattern.PURE_DATE_PATTERN;
+import static com.imed.costaccount.common.constants.Constant.LIMIT;
 
 
 @Service("shareParamValueService")
@@ -431,26 +433,51 @@ public class ShareParamValueServiceImpl extends ServiceImpl<ShareParamValueMappe
                 new LambdaQueryWrapper<ShareParamValue>()
                         .eq(ShareParamValue::getDateYear, year).eq(ShareParamValue::getDateMonth, month).eq(ShareParamValue::getHospId, hospId)
         );
-        if (list.isEmpty()){
-            throw new CostException(500,parse+"数据未录入");
+        if (list.isEmpty()) {
+            throw new CostException(500, parse + "数据未录入");
         }
-        // 得到这些责任中心代码
-        List<String> responsibilityCodes = list.stream().map(ShareParamValue::getResponsibilityCode).distinct().collect(Collectors.toList());
+        // 得到这些会计科目代码
+        List<String> accountCodes = new ArrayList<>();
+        list.forEach(i -> {
+            String shareParamCode = i.getShareParamCode();
+            CostShareParam one = costShareParamService.getOne(
+                    new LambdaQueryWrapper<CostShareParam>()
+                            .eq(CostShareParam::getHospId, hospId)
+                            .eq(CostShareParam::getShareParamCode, shareParamCode)
+                            .last(LIMIT)
+            );
+            if (Objects.isNull(one)) {
+                return;
+            }
+            String accountingCodes = one.getAccountingCodes();
+            if (StrUtil.isBlank(accountingCodes)) {
+                return;
+            }
+            String[] split = StrUtil.split(accountingCodes, StrUtil.COMMA);
+            ArrayList<String> accountCodeList = CollUtil.newArrayList(split);
+            accountCodes.addAll(accountCodeList);
+            List<String> calcList = new ArrayList<>();
+            accountCodeList.forEach(j -> {
+                calcList.add(i.getResponsibilityCode() + "cost" + j);
+            });
+            i.setCalcList(calcList);
+        });
         List<IncomeCollection> incomeCollections = incomeCollectionService.list(
                 new LambdaQueryWrapper<IncomeCollection>()
                         .eq(IncomeCollection::getYear, year)
                         .eq(IncomeCollection::getMonth, month)
                         .eq(IncomeCollection::getHospId, hospId)
-                        .in(IncomeCollection::getResponsibilityCode, responsibilityCodes)
+                        .in(IncomeCollection::getAccountingCode, accountCodes)
         );
         if (incomeCollections.isEmpty()) {
             throw new CostException("本月未归集数据,请先归集数据");
         }
 
-        Map<String, List<IncomeCollection>> collectMap = incomeCollections.stream().collect(Collectors.groupingBy(IncomeCollection::getResponsibilityCode));
+        Map<String, List<IncomeCollection>> collectMap = incomeCollections.stream()
+                .collect(Collectors.groupingBy(i->i.getResponsibilityCode() + "cost" + i.getAccountingCode()));
         Set<String> strings = collectMap.keySet();
-        Map<String,BigDecimal> map = new ConcurrentHashMap<>();
-        for (String str : strings) {
+        Map<String, BigDecimal> map = new ConcurrentHashMap<>();
+        strings.forEach(str -> {
             List<IncomeCollection> collections = collectMap.get(str);
             if (CollUtil.isNotEmpty(collections)) {
                 BigDecimal reduce = incomeCollections.stream().map(IncomeCollection::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
@@ -458,13 +485,13 @@ public class ShareParamValueServiceImpl extends ServiceImpl<ShareParamValueMappe
                 incomeCollection.setAmount(reduce);
                 map.put(str, reduce);
             }
-        }
+        });
         list.forEach(i -> {
-            // TODO: 2021/8/19
-            BigDecimal bigDecimal = map.get(i.getResponsibilityCode());
-            if (Objects.nonNull(bigDecimal)) {
-                i.setValueNum(bigDecimal);
-            }
+            map.keySet().forEach(j -> {
+                if (CollUtil.isNotEmpty(i.getCalcList()) && i.getCalcList().contains(j)) {
+                    i.setValueNum(map.get(j));
+                }
+            });
         });
         this.updateBatchById(list);
     }