瀏覽代碼

08 20 02 计算数值修改

hr 4 年之前
父節點
當前提交
6fcc5fc172

+ 4 - 0
src/main/java/com/imed/costaccount/model/Allocation.java

@@ -81,6 +81,10 @@ public class Allocation implements Serializable {
 	private String targetResponsibilityName;
 	private String shareParamCode;
 	private String shareParamName;
+	private BigDecimal shareParamValueNum;
+	private BigDecimal totalAmount;
+	private BigDecimal shareParamRate;
+
 	/**
 	 * 
 	 */

+ 1 - 6
src/main/java/com/imed/costaccount/service/CostCostingGroupService.java

@@ -52,12 +52,7 @@ public interface CostCostingGroupService extends IService<CostCostingGroup> {
      */
     PageUtils queryAllocation(Integer current, Integer pageSize, String date, Long hospId);
 
-    /**
-     * 开始归集代码
-     * @param startDTO {@link StartDTO}
-     * @param hospId 医院id
-     */
-    void startAllocation(StartDTO startDTO, Long hospId);
+
 
     /**
      * 得到这个月的所有导入的成本数据

+ 4 - 9
src/main/java/com/imed/costaccount/service/impl/AllocationServiceImpl.java

@@ -19,7 +19,6 @@ import org.springframework.transaction.annotation.Transactional;
 import java.math.BigDecimal;
 import java.util.*;
 import java.util.stream.Collectors;
-import java.util.stream.Stream;
 
 
 @Service("allocationService")
@@ -137,11 +136,6 @@ public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocat
                         // 本次的分摊比例计算
                         BigDecimal thisAmount = rate.multiply(totalAmount);
 
-//                        Allocation allocation = new Allocation();
-//                        allocation.setDateMonth(startDTO.getMonth()).setDateYear(startDTO.getYear()).setLevelSort(shareLevelVO.getLeverSort())
-//                                .setLevelName(shareLevelVO.getShareName()).setHospId(hospId).setResponsibilityCode(responsibilityCode).setResponsibilityName(responsibility.getResponsibilityName())
-//                                .setAccountShareId(accountShareId).setAmount(thisAmount).setCreateTime(System.currentTimeMillis());
-//                        allocations.add(allocation);
 
                         // 得到目标层级责任中心列表
                         List<Responsibility> targetResponsibilities = this.getTargetResponsibility(targetLevel, hospId, shareLevelVO.getLeverSort());
@@ -168,7 +162,8 @@ public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocat
                                     .setLevelName(shareLevelVO.getShareName()).setHospId(hospId).setResponsibilityCode(responsibility.getResponsibilityCode())
                                     .setResponsibilityName(responsibility.getResponsibilityName()).setAccountShareId(accountShareId).setAmount(targetAmount)
                                     .setCreateTime(System.currentTimeMillis()).setTargetResponsibilityCode(valueResponsibilityCode).setTargetResponsibilityName(targetRespName)
-                                    .setShareParamCode(paramValue.getShareParamCode()).setShareParamName(shareParamName)
+                                    .setShareParamCode(paramValue.getShareParamCode()).setShareParamName(shareParamName).setTotalAmount(totalAmount).setShareParamValueNum(paramValue.getValueNum())
+                                    .setShareParamRate(numerator.divide(reduce, 4))
                             ;
                             // todo 目标分摊层级责任中心 就是当前列个表中的责任中心
                             allocations.add(targetAllocation);
@@ -203,7 +198,7 @@ public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocat
      *
      * @return
      */
-    private BigDecimal getCostAmount(CostAccountShare accountShare, Integer calcType, Map<String, List<CostCostingGroup>> map,List<Allocation> costList) {
+    private BigDecimal getCostAmount(CostAccountShare accountShare, Integer calcType, Map<String, List<CostCostingGroup>> map, List<Allocation> costList) {
         // 是否包含分摊成本 0不包含 1 包含
         Integer isShareCost = accountShare.getIsShareCost();
         String accountingCodes = accountShare.getAccountingCodes();
@@ -214,7 +209,7 @@ public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocat
         }
         // 计算方式 0是合并计算  1是分开计算
         BigDecimal costAmount = BigDecimal.ZERO;
-        List<Allocation> all=new ArrayList<>();
+        List<Allocation> all = new ArrayList<>();
         if (!costList.isEmpty()) {
             all = costList.stream().filter(i -> i.getTargetResponsibilityCode().equals(responsibilityCode)).collect(Collectors.toList());
 //            Stream<Allocation> allocationStream = costList.stream().filter(i -> i.getTargetResponsibilityCode().equals(responsibilityCode));

+ 7 - 201
src/main/java/com/imed/costaccount/service/impl/CostCostingGroupServiceImpl.java

@@ -1,6 +1,5 @@
 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.util.StrUtil;
@@ -12,9 +11,9 @@ import com.imed.costaccount.common.exception.CostException;
 import com.imed.costaccount.common.util.*;
 import com.imed.costaccount.constants.NumberConstant;
 import com.imed.costaccount.enums.DateStyleEnum;
+import com.imed.costaccount.mapper.AllocationMapper;
 import com.imed.costaccount.mapper.CostCostingGroupMapper;
 import com.imed.costaccount.model.*;
-import com.imed.costaccount.model.dto.StartDTO;
 import com.imed.costaccount.model.vo.*;
 import com.imed.costaccount.service.*;
 import lombok.extern.slf4j.Slf4j;
@@ -26,7 +25,6 @@ import org.springframework.web.multipart.MultipartFile;
 
 import java.math.BigDecimal;
 import java.util.*;
-import java.util.stream.Collectors;
 
 
 @Service("costCostingGroupService")
@@ -43,36 +41,20 @@ public class CostCostingGroupServiceImpl extends ServiceImpl<CostCostingGroupMap
 
     private final ResponsibilityService responsibilityService;
 
-    private final CostCostingCollectionService costingCollectionService;
+    private final AllocationMapper allocationMapper;
 
-    private final CostShareLevelService shareLevelService;
-
-    private final CostAccountShareService accountShareService;
-
-    private final ShareParamValueService shareParamValueService;
-
-    private final CostShareParamService shareParamService;
 
     public CostCostingGroupServiceImpl(CostIncomeGroupServiceImpl costIncomeGroupService,
                                        AccountingService accountingService,
                                        AccountingProductService accountingProductService,
                                        CostIncomeFileService costIncomeFileService,
-                                       ResponsibilityService responsibilityService,
-                                       CostCostingCollectionService costingCollectionService,
-                                       CostShareLevelService shareLevelService,
-                                       CostAccountShareService accountShareService,
-                                       ShareParamValueService shareParamValueService,
-                                       CostShareParamService shareParamService) {
+                                       ResponsibilityService responsibilityService, AllocationMapper allocationMapper) {
         this.costIncomeGroupService = costIncomeGroupService;
         this.accountingService = accountingService;
         this.accountingProductService = accountingProductService;
         this.costIncomeFileService = costIncomeFileService;
         this.responsibilityService = responsibilityService;
-        this.costingCollectionService = costingCollectionService;
-        this.shareLevelService = shareLevelService;
-        this.accountShareService = accountShareService;
-        this.shareParamValueService = shareParamValueService;
-        this.shareParamService = shareParamService;
+        this.allocationMapper = allocationMapper;
     }
 
     /**
@@ -130,9 +112,9 @@ public class CostCostingGroupServiceImpl extends ServiceImpl<CostCostingGroupMap
 
         List<AllocationVO> list = baseMapper.queryAllocation(startIndex, pageSize, year, month, hospId);
         list.forEach(i -> {
-            List<CostCostingCollection> collections = costingCollectionService.list(new LambdaQueryWrapper<CostCostingCollection>().eq(CostCostingCollection::getYear, i.getYear())
-                    .eq(CostCostingCollection::getMonth, i.getMonth())
-                    .eq(CostCostingCollection::getHospId, hospId)
+            List<Allocation> collections = allocationMapper.selectList(new LambdaQueryWrapper<Allocation>().eq(Allocation::getDateYear, i.getYear())
+                    .eq(Allocation::getDateMonth, i.getMonth())
+                    .eq(Allocation::getHospId, hospId)
             );
             if (!collections.isEmpty()) {
                 i.setIsAllocation(true);
@@ -142,182 +124,6 @@ public class CostCostingGroupServiceImpl extends ServiceImpl<CostCostingGroupMap
         return new PageUtils(list, count, pageSize, current);
     }
 
-    /**
-     * 开始成本分摊
-     *
-     * @param startDTO {@link StartDTO}
-     * @param hospId   医院id
-     */
-    @Override
-    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
-    public void startAllocation(StartDTO startDTO, Long hospId) {
-        // 这个月成本数据数据
-        List<CostCostingGroup> list = this.list(
-                new LambdaQueryWrapper<CostCostingGroup>()
-                        .eq(CostCostingGroup::getDateYear, startDTO.getYear())
-                        .eq(CostCostingGroup::getDateMonth, startDTO.getMonth())
-                        .eq(CostCostingGroup::getHospId, hospId)
-        );
-        // 没有重新导入
-        if (list.isEmpty()) {
-            throw new CostException("本月成本数据暂未导入");
-        }
-
-        Map<String, List<CostCostingGroup>> responsibilityCodeMap = list.stream().collect(Collectors.groupingBy(CostCostingGroup::getResponsibilityCode));
-        Set<String> responsibilityCodes = responsibilityCodeMap.keySet();
-        for (String responsibilityCode : responsibilityCodes) {
-
-        }
-
-
-//        // 得到这个月导入的成本分摊参数值数据
-//        List<ShareParamValue> shareParamValues = shareParamValueService.list(
-//                new LambdaQueryWrapper<ShareParamValue>()
-//                        .eq(ShareParamValue::getHospId, hospId)
-//                        .eq(ShareParamValue::getDateYear, startDTO.getYear())
-//                        .eq(ShareParamValue::getDateMonth, startDTO.getMonth())
-//        );
-//        // 没有重新导入
-//        if (shareParamValues.isEmpty()) {
-//            throw new CostException("本月分摊参数值数据未导入");
-//        }
-//        // 通过会计科目聚合月成本数据
-//        Map<String, List<CostCostingGroup>> accountMap = list.stream().collect(Collectors.groupingBy(CostCostingGroup::getAccountCode));
-//
-//        // 删除该年月已经过的数据
-//        costingCollectionService.remove(
-//                new LambdaQueryWrapper<CostCostingCollection>()
-//                        .eq(CostCostingCollection::getYear, startDTO.getYear())
-//                        .eq(CostCostingCollection::getMonth, startDTO.getMonth())
-//                        .eq(CostCostingCollection::getHospId, hospId)
-//        );
-//        // 得到这个医院所有的分摊层级(通过sort_level正序排序的数据)
-//        List<CostShareLevelVO> shareLevelVOs = shareLevelService.getAll(hospId);
-//        if (CollUtil.isEmpty(shareLevelVOs)) {
-//            throw new CostException("请先设置医院分摊层级");
-//        }
-//        List<CostCostingCollection> costingCollections = new ArrayList<>();
-//        // 遍历这个医院的分摊层级
-//        for (int i = 0; i < shareLevelVOs.size(); i++) {
-//            // 最后一层不分摊
-//            if (i == shareLevelVOs.size() - 1) {
-//                break;
-//            }
-//            // 通过分摊层级id 得到对应的责任中心
-//            CostShareLevelVO shareLevelVO = shareLevelVOs.get(i);
-//            Responsibility responsibility = responsibilityService.getByLevelId(shareLevelVO.getId(), hospId);
-//            // 如果这个分摊层级没有责任中心那么不分摊
-//            if (Objects.isNull(responsibility)) {
-//                continue;
-//            }
-//            // 通过责任中心code去得到分摊参数对应信息 并得到对应的会计科目和对应的分摊参数比例等信息
-//            List<CostAccountShare> accountShares = accountShareService.getByResponsibility(responsibility.getResponsibilityCode(), hospId);
-//            if (accountShares.isEmpty()) {
-//                continue;
-//            }
-//            // 遍历分摊参数对应信息
-//            for (CostAccountShare accountShare : accountShares) {
-//                // 得到对应的会计中心code
-//                String accountingCodes = accountShare.getAccountingCodes();
-//                // 没有会计中心,合并计算未设置好分摊参数比例
-//                if (StrUtil.isBlank(accountingCodes) && shareLevelVO.getCalcType().equals(1)) {
-//                    throw new CostException("责任中心:" + accountShare.getResponsibilityName() + ";会计中心为:" + accountShare.getAccountingNames() + ";未设置分摊参数比例");
-//                }
-//                // 会计科目不存在且是合并计算,这种情况直接分摊下去
-//                String paramList = accountShare.getParamList();
-//                if (StrUtil.isBlank(paramList)) {
-//                    throw new CostException("责任中心:" + accountShare.getResponsibilityName() + ";会计中心为:" + accountShare.getAccountingNames() + (";未设置分摊参数比例值"));
-//                }
-//                // 分摊参数以及比例集合
-//                List<AccountShareVO> accountShareVOs = JacksonUtil.str2ObjList(paramList, List.class, AccountShareVO.class);
-//                // 没有会计中心直接分摊的情况
-//                if (StrUtil.isBlank(accountingCodes) && shareLevelVO.getCalcType().equals(0)) {
-//                    // 直接分摊到责任中心去 这情况只有一个分摊计划
-//                    AccountShareVO accountShareVO = accountShareVOs.get(0);
-//                    Long shareParamId = accountShareVO.getId();
-//                    CostShareParam shareParam = shareParamService.getByIdAndCalcType(shareParamId);
-//                    if (Objects.isNull(shareParam)) {
-//                        continue;
-//                    }
-//                    String accountCodeStr = shareParam.getAccountingCodes();
-//                    if (StrUtil.isBlank(accountCodeStr)) {
-//                        throw new CostException("成本分摊参数:" + shareParam.getShareParamName() + ";设置会计科目不存在");
-//                    }
-//                    ArrayList<String> accountCodes = CollUtil.newArrayList(accountCodeStr.split(StrUtil.COMMA));
-//                    String shareParamPout = accountShareVO.getShareParamPopout();
-//                    BigDecimal rate = new BigDecimal("1");
-//                    if (!"100".equals(shareParamPout)) {
-//                        rate = new BigDecimal("0." + shareParamPout);
-//                    }
-//                    // 计算分摊数值
-//                    BigDecimal valueNum = shareParamValues.stream().map(ShareParamValue::getValueNum).reduce(BigDecimal.ZERO, BigDecimal::add);
-//                    for (String accountCode : accountCodes) {
-//                        Accounting account = this.getAccountByCode(accountCode, hospId);
-//                        List<CostCostingGroup> costCostingGroups = accountMap.get(accountCode);
-//                        if (CollUtil.isEmpty(costCostingGroups)) {
-//                            continue;
-//                        }
-//                        BigDecimal accountCodeAmount = costCostingGroups.stream().map(CostCostingGroup::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
-//                        CostCostingCollection collection = new CostCostingCollection();
-//                        collection.setYear(startDTO.getYear()).setMonth(startDTO.getMonth()).setResponsibilityCode(accountShare.getResponsibilityCode())
-//                                .setResponsibilityName(accountShare.getResponsibilityName()).setLeverSort(shareLevelVO.getLeverSort())
-//                                .setShareLevelName(shareLevelVO.getShareName()).setAccountCode(accountCode).setAccountName(account.getAccountingName())
-//                                .setIsBaseCost(account.getIsBaseCost()).setAmount(accountCodeAmount).setCreateTime(System.currentTimeMillis())
-//                                .setHospId(hospId).setShareParam(accountShareVO.getShareParamName()).setShareParamProportion(rate.toString())
-//                                .setShareValue(valueNum)
-//                                // 目标分摊层级暂不处理
-//                                //.setTargetResponsibilityCode().setTargetResponsibilityName()
-//                                .setShareAmount(rate.multiply(accountCodeAmount));
-//                        costingCollections.add(collection);
-//                    }
-//                    continue;
-//                }
-//                // 责任中心对应的会计科目代码列表
-//                ArrayList<String> accountCodeList = CollUtil.newArrayList(accountingCodes.split(StrUtil.COMMA));
-//                for (String accountCode : accountCodeList) {
-//                    // 分摊前数据 通过会计科目得到
-//                    List<CostCostingGroup> costCostingGroups = accountMap.get(accountCode);
-//
-//                    if (CollUtil.isEmpty(costCostingGroups)) {
-//                        continue;
-//                    }
-//                    BigDecimal accountCodeAmount = costCostingGroups.stream().map(CostCostingGroup::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
-//                    Accounting accounting = this.getAccountByCode(accountCode, hospId);
-//                    if (StrUtil.isBlank(paramList)) {
-//                        throw new CostException("未设置分摊参数比例值");
-//                    }
-//                    // 分摊比例相关数据
-//                    if (CollUtil.isEmpty(accountShareVOs)) {
-//                        throw new CostException("分摊参数对应比例错误");
-//                    }
-//                    for (AccountShareVO accountShareVO : accountShareVOs) {
-//                        CostCostingCollection collection = new CostCostingCollection();
-//                        String shareParamPout = accountShareVO.getShareParamPopout();
-//                        BigDecimal rate = new BigDecimal("1");
-//                        if (!"100".equals(shareParamPout)) {
-//                            rate = new BigDecimal("0." + shareParamPout);
-//                        }
-//                        // 计算分摊数值
-//                        BigDecimal valueNum = shareParamValues.stream().map(ShareParamValue::getValueNum).reduce(BigDecimal.ZERO, BigDecimal::add);
-//                        collection.setYear(startDTO.getYear()).setMonth(startDTO.getMonth()).setResponsibilityCode(accountShare.getResponsibilityCode())
-//                                .setResponsibilityName(accountShare.getResponsibilityName()).setLeverSort(shareLevelVO.getLeverSort())
-//                                .setShareLevelName(shareLevelVO.getShareName()).setAccountCode(accountCode).setAccountName(accounting.getAccountingName())
-//                                .setIsBaseCost(accounting.getIsBaseCost()).setAmount(accountCodeAmount).setCreateTime(System.currentTimeMillis())
-//                                .setHospId(hospId).setShareParam(accountShareVO.getShareParamName()).setShareParamProportion(rate.toString())
-//                                .setShareValue(valueNum)
-//                                // 目标分摊层级暂不处理
-//                                //.setTargetResponsibilityCode().setTargetResponsibilityName()
-//                                .setShareAmount(rate.multiply(accountCodeAmount));
-//                        costingCollections.add(collection);
-////                        costingCollectionService.save(collection);
-//                    }
-//
-//                }
-//            }
-//        }
-//        log.info("list:{}", costingCollections);
-//        costingCollectionService.saveBatch(costingCollections);
-    }
 
     /**
      * 通过code获取名称

+ 16 - 1
src/main/java/com/imed/costaccount/web/CostCostingGroupController.java

@@ -70,11 +70,26 @@ public class CostCostingGroupController extends AbstractController {
         return Result.ok(pageUtils);
     }
 
-    @ApiOperation("开始归集")
+    @ApiOperation("开始分摊")
     @PostMapping("/startAllocation")
     public Result startAllocation(@RequestBody @Valid StartDTO startDTO) {
 //        costCostingGroupService.startAllocation(startDTO, getHospId());
         allocationService.startAllocation(startDTO,getHospId());
         return Result.ok();
     }
+
+    @ApiOperation("分摊后列表")
+    @GetMapping("/queryAfterAllocation")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "year",value = "年月日(yyyy-MM-dd)"),
+            @ApiImplicitParam(name = "responsibilityCode",value = "年月日(yyyy-MM-dd)"),
+            @ApiImplicitParam(name = "year",value = "年月日(yyyy-MM-dd)"),
+            @ApiImplicitParam(name = "year",value = "年月日(yyyy-MM-dd)")
+    })
+    public Result queryAfterAllocation(@RequestParam(value = "year", required = false) String year,
+                                       @RequestParam(value = "responsibilityCode", required = false) String responsibilityCode,
+                                       @RequestParam(value = "current", defaultValue = "1", required = false) Integer current,
+                                       @RequestParam(value = "pageSize", defaultValue = "10", required = false) Integer pageSize) {
+        return null;
+    }
 }