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.common.util.Result; import com.imed.costaccount.constants.NumberConstant; 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.model.vo.IncomeErrorMessage; import com.imed.costaccount.service.*; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; import java.util.*; import java.util.stream.Collectors; @Slf4j @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; private final ResponsibilityDepartmentService responsibilityDepartmentService; private final AccountingProductService accountingProductService; public CostIncomeGroupServiceImpl(DepartmentService departmentService, ResponsibilityService responsibilityService, ProductService productService, AccountingService accountingService, ResponsibilityDepartmentService responsibilityDepartmentService, AccountingProductService accountingProductService) { this.departmentService = departmentService; this.responsibilityService = responsibilityService; this.productService = productService; this.accountingService = accountingService; this.responsibilityDepartmentService = responsibilityDepartmentService; this.accountingProductService = accountingProductService; } /** * 分页查询收入归集前的数据 * * @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 = 0; int month=0; if (StrUtil.isNotBlank(dateTime)){ year = DateUtils.getYear(dateTime); month=DateUtils.getMonth(dateTime); } Page costIncomeGroupPage = new Page<>(current, pageSize); Page pages= this.page(costIncomeGroupPage,new QueryWrapper().lambda() .eq(Objects.nonNull(hospId),CostIncomeGroup::getHospId,hospId) .eq(!NumberConstant.ZERO.equals(year),CostIncomeGroup::getDateYear,year) .eq(!NumberConstant.ONE.equals(month),CostIncomeGroup::getDateMonth,month) .and(StrUtil.isNotBlank(responsibilityCode),i->i.like(CostIncomeGroup::getOpenResponsibilityCode,responsibilityCode) .or().like(CostIncomeGroup::getStartResponsibilityCode, responsibilityCode)) .like(StrUtil.isNotBlank(accountCode),CostIncomeGroup::getAccountCode,accountCode)); 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 list 输入的文件 * @param hospId 医院Id * @return */ @Override @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class) public Result importIncomeGroup(List> list, Long hospId) { // 移除前几行的抬头内容 list的大小对应的就是行数的大小 for (int i = list.size() - 1; i >= 0; i--) { if (i == NumberConstant.ZERO || i == NumberConstant.ONE || i == NumberConstant.TWO || i == NumberConstant.THREE) { list.remove(list.get(i)); } } log.info("读取的数据为:{}", list); List costIncomeGroupList = new ArrayList<>(); List incomeErrorMessageList = new ArrayList<>(); //获取所有的科室 成本项目 责任中心 会计科目 Map departmentMap = departmentService.list(new QueryWrapper().lambda().eq(Department::getHospId, hospId)).stream().collect(Collectors.toMap(k -> k.getDepartmentCode() + k.getDepartmentName(), synOe -> synOe)); Map productMap= productService.list(new QueryWrapper().lambda().eq(Product::getHospId, hospId)).stream().collect(Collectors.toMap(k -> k.getProductCode() + k.getProductName(), synOe -> synOe)); Map responsibilityMap = responsibilityService.list(new QueryWrapper().lambda().eq(Responsibility::getHospId, hospId)).stream().collect(Collectors.toMap(Responsibility::getId,synOe->synOe)); Map accountingMap = accountingService.list(new QueryWrapper().lambda().eq(Accounting::getHospId, hospId)).stream().collect(Collectors.toMap(Accounting::getId, synOe -> synOe)); for (int i = 0; i < list.size(); i++) { // 用来检验数据合理性的循环 IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage(); List data = list.get(i); log.info("用户输入的数据是{}",data); Object money = data.get(data.size() - 1); if (!Objects.isNull(money) && !NumberConstant.ZERO.equals(Integer.parseInt(money.toString()))){ // 要求这一行的数据必须全部填写 for (int j=0;j 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())); }); } /** * 收入数据导入 */ }