package com.imed.costaccount.service.impl; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 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.mapper.CostIncomeGroupMapper; import com.imed.costaccount.model.*; import com.imed.costaccount.model.vo.CostIncomeGroupAllAmountVO; import com.imed.costaccount.model.vo.CostIncomeGroupBeforeVO; import com.imed.costaccount.service.*; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; import java.math.BigDecimal; import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @Service("costIncomeGroupService") public class CostIncomeGroupServiceImpl extends ServiceImpl implements CostIncomeGroupService { private final DepartmentService departmentService; private final ResponsibilityService responsibilityService; private final ProductService productService; private final AccountingService accountingService; public CostIncomeGroupServiceImpl(DepartmentService departmentService, ResponsibilityService responsibilityService, ProductService productService, AccountingService accountingService) { this.departmentService = departmentService; this.responsibilityService = responsibilityService; this.productService = productService; this.accountingService = accountingService; } /** * 分页查询收入归集前的数据 * * @param current 当前页 * @param pageSize 当前页大小 * @param dateTime 年月 * @param responsibilityCode 责任中心代码 * @param accountCode 会计科目的Code * @param hospId 医院Id * @return */ @Override public PageUtils queryList(Integer current, Integer pageSize, String dateTime, String responsibilityCode, String accountCode, Long hospId) { int year = DateUtils.getYear(dateTime); int month=DateUtils.getMonth(dateTime); Page costIncomeGroupPage = new Page<>(current, pageSize); QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq("hosp_id",hospId); wrapper.eq("date_year",year); wrapper.eq("date_month",month); wrapper.like(!StringUtils.isEmpty(responsibilityCode),"open_responsibility_code",responsibilityCode) .or() .like(!StringUtils.isEmpty(responsibilityCode),"start_responsibility_code",responsibilityCode); wrapper.eq(!StringUtils.isEmpty(accountCode),"account_code",accountCode); Page pages = this.page(costIncomeGroupPage, wrapper); List records = pages.getRecords(); List costIncomeGroupBeforeVOList = BeanUtil.convertList(records, CostIncomeGroupBeforeVO.class); // 查询所有的责任中心 科室 会计科目 成本项目的数据 处理名字 setCodeName(hospId, costIncomeGroupBeforeVOList); // 进行金额合并 List costIncomeGroupAllAmountVoS =baseMapper.countMoney(costIncomeGroupBeforeVOList); // 对,的金额进行合并 costIncomeGroupAllAmountVoS.forEach(i->{ String allMoney = i.getAllMoney(); if (allMoney.contains(StrUtil.COMMA)){ // 存在,在进行求和 long sum; List list = Arrays.stream(allMoney.split(StrUtil.COMMA)).map(Long::valueOf).collect(Collectors.toList()); sum = list.stream().mapToLong(m -> m).sum(); i.setAmount(BigDecimal.valueOf(sum)); } }); PageUtils pageUtils = new PageUtils(pages); pageUtils.setList(costIncomeGroupAllAmountVoS); return pageUtils; } /** * 设置相关名称 * @param hospId * @param costIncomeGroupBeforeVOList */ private void setCodeName(Long hospId, List costIncomeGroupBeforeVOList) { List responsibilityList = responsibilityService.list(new QueryWrapper().lambda().eq(Responsibility::getHospId, hospId)); Map responsibilityMap = responsibilityList.stream().collect(Collectors.toMap(Responsibility::getResponsibilityCode,Responsibility::getResponsibilityName)); List departmentList = departmentService.list(new QueryWrapper().lambda().eq(Department::getHospId, hospId)); Map departmentMap = departmentList.stream().collect(Collectors.toMap(Department::getDepartmentCode,Department::getDepartmentName)); List productList = productService.list(new QueryWrapper().lambda().eq(Product::getHospId, hospId)); Map productMap = productList.stream().collect(Collectors.toMap(Product::getProductCode,Product::getProductName)); List accountingList = accountingService.list(new QueryWrapper().lambda().eq(Accounting::getHospId, hospId)); Map accountMap = accountingList.stream().collect(Collectors.toMap(Accounting::getAccountingCode,Accounting::getAccountingName)); costIncomeGroupBeforeVOList.forEach(i->{ // 以为这里的数据导入的 在导入的时候进行数据校验 // 设置开单科室名称 执行科室名称 开单责任中心名称 执行责任中心名称 成本项目的名称 会计科目名称 i.setOpenDepartmentCodeName("["+i.getOpenDepartmentCode()+"]"+departmentMap.get(i.getOpenDepartmentCode())); i.setOpenResponsibilityCodeName("["+i.getOpenResponsibilityCode()+"]"+responsibilityMap.get(i.getOpenResponsibilityCode())); i.setStartDepartmentCodeName("["+i.getStartDepartmentCode()+"]"+departmentMap.get(i.getStartDepartmentCode())); i.setStartResponsibilityCodeName("["+i.getStartResponsibilityCode()+"]"+responsibilityMap.get(i.getStartResponsibilityCode())); i.setProductCodeName("["+i.getProductCode()+"]"+productMap.get(i.getProductCode())); i.setAccountCodeName("["+i.getAccountCode()+"]"+accountMap.get(i.getAccountCode())); }); } /** * 收入归集数据的计算规则 */ }