package com.imed.costaccount.service.impl; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; 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.exception.CostException; import com.imed.costaccount.common.util.*; import com.imed.costaccount.constants.NumberConstant; import com.imed.costaccount.enums.DateStyleEnum; import com.imed.costaccount.enums.ErrorCodeEnum; 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.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import org.springframework.web.multipart.MultipartFile; import java.io.File; import java.io.IOException; import java.math.BigDecimal; import java.util.*; import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; @Slf4j @Service("costIncomeGroupService") public class CostIncomeGroupServiceImpl extends ServiceImpl implements CostIncomeGroupService { @Value("${file.serverPath}") private String fileTempPath; @Value("${file.serverUrl}") private String FILE_PATH; private final DepartmentService departmentService; private final ResponsibilityService responsibilityService; private final ProductService productService; private final AccountingService accountingService; private final ResponsibilityDepartmentService responsibilityDepartmentService; private final AccountingProductService accountingProductService; private final CostIncomeFileService costIncomeFileService; private final CostIncomeGroupSetService costIncomeGroupSetService; public CostIncomeGroupServiceImpl(DepartmentService departmentService, ResponsibilityService responsibilityService, ProductService productService, AccountingService accountingService, ResponsibilityDepartmentService responsibilityDepartmentService, AccountingProductService accountingProductService, CostIncomeFileService costIncomeFileService, CostIncomeGroupSetService costIncomeGroupSetService) { this.departmentService = departmentService; this.responsibilityService = responsibilityService; this.productService = productService; this.accountingService = accountingService; this.responsibilityDepartmentService = responsibilityDepartmentService; this.accountingProductService = accountingProductService; this.costIncomeFileService = costIncomeFileService; this.costIncomeGroupSetService = costIncomeGroupSetService; } /** * 分页查询收入归集前的数据 * * @param current 当前页 * @param pageSize 当前页大小 * @param dateTime 年月 * @param responsibilityCode 责任中心代码 * @param productCode 会计科目的Code * @param hospId 医院Id * @return */ @Override public PageUtils queryList(Integer current, Integer pageSize, String dateTime, String responsibilityCode, String productCode, Long hospId) { // 先检验当前年月是否存在数据 int year = 0; int month = 0; Date date = DateUtils.StringToDate(dateTime, DateStyleEnum.YYYY_MM); if (StrUtil.isNotBlank(dateTime)) { year = DateUtil.year(date); month = DateUtil.month(date) + 1; } 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.ZERO.equals(month), CostIncomeGroup::getDateMonth, month) .and(StrUtil.isNotBlank(responsibilityCode), i -> i.like(CostIncomeGroup::getOpenResponsibilityCode, responsibilityCode) .or().like(CostIncomeGroup::getStartResponsibilityCode, responsibilityCode)) .like(StrUtil.isNotBlank(productCode), CostIncomeGroup::getProductCode, productCode)); List records = pages.getRecords(); List costIncomeGroupBeforeVOList = BeanUtil.convertList(records, CostIncomeGroupBeforeVO.class); if (CollectionUtils.isEmpty(costIncomeGroupBeforeVOList)) { PageUtils pageUtils = new PageUtils(pages); pageUtils.setList(null); pageUtils.setTotalAmount(new BigDecimal(0.0000)); return pageUtils; } // 进行金额合并 List idList = costIncomeGroupBeforeVOList.stream().map(CostIncomeGroupBeforeVO::getId).collect(Collectors.toList()); List costIncomeGroupAllAmountVoS = baseMapper.countMoney(idList); // 查询所有的责任中心 科室 会计科目 成本项目的数据 处理名字 setCodeName(costIncomeGroupAllAmountVoS); // 对,的金额进行合并 AtomicReference totalAmount = new AtomicReference<>(new BigDecimal("0.0000")); costIncomeGroupAllAmountVoS.forEach(i -> { String allMoney = i.getAllMoney(); if (StrUtil.isNotBlank(allMoney) && allMoney.contains(StrUtil.COMMA)) { // 存在,在进行求和 double sum; List list = Arrays.stream(allMoney.split(StrUtil.COMMA)).map(Double::valueOf).collect(Collectors.toList()); sum = list.stream().mapToDouble(m -> m).sum(); i.setAmount(BigDecimal.valueOf(sum)); } //TODO 统计总金额 totalAmount.updateAndGet(v -> v.add(i.getAmount())); }); PageUtils pageUtils = new PageUtils(pages); pageUtils.setList(costIncomeGroupAllAmountVoS); pageUtils.setTotalAmount(totalAmount.get()); return pageUtils; } /** * 批量导入收入数据 * * @param list 输入的文件 * @param user 用户 * @param file * @return */ @Override @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public Result importIncomeGroup(List> list, User user, MultipartFile file, String dateTime, Integer fileType) { // 先检验当前年月是否存在数据 int year = 0; int month = 0; Date date = DateUtils.StringToDate(dateTime, DateStyleEnum.YYYY_MM); if (StrUtil.isNotBlank(dateTime)) { year = DateUtil.year(date); month = DateUtil.month(date) + 1; } Long hospId = user.getHospId(); List groups = this.list(new QueryWrapper().lambda().eq(CostIncomeGroup::getHospId, hospId) .eq(CostIncomeGroup::getDateYear, year).eq(CostIncomeGroup::getDateMonth, month)); if (!CollectionUtils.isEmpty(groups)) { throw new CostException(500, year + "年" + month + "月数据已存在"); } // 移除前几行的抬头内容 list的大小对应的就是行数的大小 removeTitle(list); log.info("读取的数据为:{}", list); List incomeErrorMessageList = new ArrayList<>(); //获取所有的科室 成本项目 责任中心 会计科目 // Map departmentMap = getDepartmentByCodeNameMap(hospId); Map productMap = getProductByCodeNameMap(hospId); Map responsibilityMap = getResponsibilityIdResponsibilityMap(hospId); Map accountingMap = getAccountIdAccountingMap(hospId); List responsibilityDepartmentList = getResponsibilityDepartments(hospId); if (CollectionUtils.isEmpty(responsibilityDepartmentList)) { throw new CostException(500, "没有科室责任中心对照数据"); } List accountingProductList = accountingProductService.list(new QueryWrapper().lambda().eq(AccountingProduct::getHospId, hospId)); if (CollectionUtils.isEmpty(accountingProductList)) { throw new CostException(500, "没有成本会计对照数据"); } Map responsibilityDepMap = getDepartmentIdResponsibilityIdMap(responsibilityDepartmentList); Map accountProMap = getProductIdAccountIdMap(accountingProductList); List costIncomeGroupArrayList = new ArrayList<>(); // 检验数据 checkImportData(list, incomeErrorMessageList, costIncomeGroupArrayList, departmentMap, productMap, responsibilityMap, accountingMap, responsibilityDepMap, accountProMap, hospId, year, month); // 文件上传 String uploadFile = uploadFile(file, UserContext.getCurrentUser()); // 上传记录保存 if (StrUtil.isBlank(uploadFile)) { throw new CostException(500, "文件上传异常"); } // 记录文件上传记录 CostIncomeFile costIncomeFile = costIncomeFileService.saveCostIncomeFile(list, user, file, hospId, incomeErrorMessageList, uploadFile, fileType, year, month); Long id = costIncomeFile.getId(); costIncomeGroupArrayList.forEach(i -> { // 设置文件Id i.setFileId(id); }); if (CollectionUtils.isEmpty(incomeErrorMessageList)) { this.saveBatch(costIncomeGroupArrayList); return Result.build(200, "数据导入成功", null); } else { return Result.build(200, "数据未成功导入", null); } } private void removeTitle(List> 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)); } } } /** * 返回成本会计对照数据 Key 成本项目Id Value 会计科目Id * * @param accountingProductList * @return */ public Map getProductIdAccountIdMap(List accountingProductList) { return accountingProductList.stream().collect(Collectors.toMap(AccountingProduct::getProductId, AccountingProduct::getAccountingId)); } /** * Map类型 * Key DepartmentId * Value ResponsibilityId * * @param responsibilityDepartmentList * @return */ public Map getDepartmentIdResponsibilityIdMap(List responsibilityDepartmentList) { return responsibilityDepartmentList.stream().collect(Collectors.toMap(ResponsibilityDepartment::getDepartmentId, ResponsibilityDepartment::getResponsibilityId)); } public List getResponsibilityDepartments(Long hospId) { return responsibilityDepartmentService.list(new QueryWrapper().lambda() .eq(ResponsibilityDepartment::getHospId, hospId)); } /** * Key AccountId * Value Accounting对象 * * @param hospId * @return */ public Map getAccountIdAccountingMap(Long hospId) { return accountingService.list(new QueryWrapper().lambda().eq(Accounting::getHospId, hospId)).stream().collect(Collectors.toMap(Accounting::getId, synOe -> synOe)); } /** * Key responsibilityId 责任中心Id * Value Responsibility对象 * * @param hospId * @return */ public Map getResponsibilityIdResponsibilityMap(Long hospId) { return responsibilityService.list(new QueryWrapper().lambda().eq(Responsibility::getHospId, hospId)).stream().collect(Collectors.toMap(Responsibility::getId, synOe -> synOe)); } /** * Key 成本项目Code+Name * Value 成本项目对象 * * @param hospId * @return */ public Map getProductByCodeNameMap(Long hospId) { return productService.list(new QueryWrapper().lambda().eq(Product::getHospId, hospId)).stream().collect(Collectors.toMap(k -> k.getProductCode() + k.getProductName(), synOe -> synOe)); } /** * Key 科室项目Code+Name * Value 科室对象 * * @param hospId * @return */ public Map getDepartmentByCodeNameMap(Long hospId) { return departmentService.list(new QueryWrapper().lambda().eq(Department::getHospId, hospId)).stream().collect(Collectors.toMap(k -> k.getDepartmentCode() + k.getDepartmentName(), synOe -> synOe)); } /** * 导入收入数据 * * @param read 读取到的初始数据 * @param user 当前登录用户 * @param file 导入的文件 * @param year 年 * @param month 月 * @return {@link Result} */ @Override public Result importDataByIncomeData(List> read, User user, MultipartFile file, Integer year, Integer month) { // 去头 this.removeTitle(read); return null; } /** * 检验数据 * * @param list 表单数据 * @param incomeErrorMessageList 存储错误信息的集合 * @param costIncomeGroupArrayList * @param departmentMap 科室Map * @param productMap 成本项目map * @param responsibilityMap 责任中心Map * @param accountingMap 会计科目Map * @param responsibilityDepMap 责任中心科室对照Map * @param accountProMap 责任中心Map * @param hospId */ private void checkImportData(List> list, List incomeErrorMessageList, List costIncomeGroupArrayList, Map departmentMap, Map productMap, Map responsibilityMap, Map accountingMap, Map responsibilityDepMap, Map accountProMap, Long hospId, Integer year, Integer month) { for (int i = 0; i < list.size(); i++) { int row = i + 5; CostIncomeGroup costIncomeGroup = new CostIncomeGroup(); AfterIncomegroup afterIncomegroup = new AfterIncomegroup(); // 用来检验数据合理性的循环 List data = list.get(i); log.info("用户输入的数据是{}", data); // 成本项目的代码和名称 String productCode = data.get(0).toString().trim(); String productName = data.get(1).toString().trim(); // 开单科室 执行科室的代码和名称 String openDepartmentName = data.get(2).toString().trim(); String openDepartmentCode = data.get(3).toString().trim(); String startDepartmentName = data.get(4).toString().trim(); String startDepartmentCode = data.get(5).toString().trim(); if (StrUtil.isBlank(openDepartmentCode) && StrUtil.isBlank(openDepartmentName) && StrUtil.isBlank(startDepartmentCode) && StrUtil.isBlank(startDepartmentName)) { continue; } BigDecimal beforeMoney = BigDecimal.valueOf(Double.parseDouble(("0".equals(data.get(15).toString()) || StrUtil.isBlank(data.get(15).toString())) ? "0.00" : data.get(15).toString())); boolean checkNull = StrUtil.isNotBlank(data.get(15).toString()); boolean checkOne = "0".equals(data.get(15).toString()); // TODO 为0的时候这一行是否可以输入空的 if (checkNull || checkOne) { // 不为空要求这一行全部输入 前6列数据不能为空 for (int j = 0; j < NumberConstant.SIX; j++) { if (StrUtil.isBlank(data.get(j).toString())) { IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage(); incomeErrorMessage.setTotal(row); int column = j + 1; incomeErrorMessage.setErrMessage("第{" + row + "}行第{" + column + "}列数据为空"); incomeErrorMessageList.add(incomeErrorMessage); } } } // 检验收入成本项目数据是否存在 Product product = productMap.get(productCode.trim() + productName.trim()); Department department = departmentMap.get(openDepartmentCode.trim() + openDepartmentName.trim()); Department department1 = departmentMap.get(startDepartmentCode.trim() + startDepartmentName.trim()); if (StrUtil.isNotBlank(productCode) && StrUtil.isNotBlank(productName)) { if (Objects.isNull(product)) { IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage(); incomeErrorMessage.setTotal(row); incomeErrorMessage.setErrMessage("成本项目代码:" + productCode + " 名称:" + productName + "不存在"); incomeErrorMessageList.add(incomeErrorMessage); } else { // 检验对应的会计科目是否存在 Long id = product.getId(); Long accountId = accountProMap.get(id); if (Objects.isNull(accountingMap.get(accountId))) { IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage(); incomeErrorMessage.setTotal(row); incomeErrorMessage.setErrMessage("成本项目代码:" + productCode + " 名称:" + productName + "对应的会计科目不存在"); incomeErrorMessageList.add(incomeErrorMessage); } else { costIncomeGroup.setProductCode(productCode); costIncomeGroup.setProductName(productName); costIncomeGroup.setAccountCode(accountingMap.get(accountId).getAccountingCode()); costIncomeGroup.setAccountName(accountingMap.get(accountId).getAccountingName()); } } } else { costIncomeGroup.setProductCode(null); costIncomeGroup.setProductName(null); costIncomeGroup.setAccountCode(null); costIncomeGroup.setAccountName(null); } // 检验开单科室 if (StrUtil.isNotBlank(openDepartmentCode) && StrUtil.isNotBlank(openDepartmentName)) { // 开单科室 if (Objects.isNull(department)) { IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage(); incomeErrorMessage.setTotal(row); incomeErrorMessage.setErrMessage("开单科室代码:" + openDepartmentCode + " 科室名称:" + openDepartmentName + "不存在"); incomeErrorMessageList.add(incomeErrorMessage); } else { Long id = department.getId(); Long responsibilityId = responsibilityDepMap.get(id); if (Objects.isNull(responsibilityMap.get(responsibilityId))) { IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage(); incomeErrorMessage.setTotal(row); incomeErrorMessage.setErrMessage("开单科室代码代码:" + openDepartmentCode + " 科室名称:" + openDepartmentName + "对应的责任中心不存在"); incomeErrorMessageList.add(incomeErrorMessage); } else { Responsibility responsibility = responsibilityMap.get(responsibilityId); costIncomeGroup.setOpenDepartmentCode(openDepartmentCode); costIncomeGroup.setOpenDepartmentName(openDepartmentName); costIncomeGroup.setOpenResponsibilityCode(responsibility.getResponsibilityCode()); costIncomeGroup.setOpenResponsibilityName(responsibility.getResponsibilityName()); afterIncomegroup.setOpenDepartmentCode(openDepartmentCode); afterIncomegroup.setOpenDepartmentName(openDepartmentName); afterIncomegroup.setOpenDepartmentStatus(responsibility.getResponsibilityType()); afterIncomegroup.setOpenResponsibilityCode(responsibility.getResponsibilityCode()); afterIncomegroup.setOpenResponsibilityName(responsibility.getResponsibilityName()); } } } else { costIncomeGroup.setOpenDepartmentCode(null); costIncomeGroup.setOpenDepartmentName(null); costIncomeGroup.setOpenResponsibilityCode(null); costIncomeGroup.setOpenResponsibilityName(null); } // 检验执行科室 if (StrUtil.isNotBlank(startDepartmentCode) && StrUtil.isNotBlank(startDepartmentName)) { //执行科室 if (Objects.isNull(department1)) { IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage(); incomeErrorMessage.setTotal(row); incomeErrorMessage.setErrMessage("执行科室代码:" + startDepartmentCode + " 科室名称:" + startDepartmentName + "科室不存在"); incomeErrorMessageList.add(incomeErrorMessage); } else { Long id = department1.getId(); Long responsibilityId = responsibilityDepMap.get(id); if (Objects.isNull(responsibilityMap.get(responsibilityId))) { IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage(); incomeErrorMessage.setTotal(row); incomeErrorMessage.setErrMessage("执行科室代码:" + startDepartmentCode + " 名称:" + startDepartmentCode + "对应的责任中心不存在"); incomeErrorMessageList.add(incomeErrorMessage); } else { Responsibility responsibility = responsibilityMap.get(responsibilityId); costIncomeGroup.setStartDepartmentCode(startDepartmentCode); costIncomeGroup.setStartDepartmentName(startDepartmentName); costIncomeGroup.setStartResponsibilityCode(responsibility.getResponsibilityCode()); costIncomeGroup.setStartResponsibilityName(responsibility.getResponsibilityName()); afterIncomegroup.setStartDepartmentCode(startDepartmentCode); afterIncomegroup.setStartDepartmentName(startDepartmentName); afterIncomegroup.setStartDepartmentStatus(responsibility.getResponsibilityType()); afterIncomegroup.setStartResponsibilityCode(responsibility.getResponsibilityCode()); afterIncomegroup.setStartResponsibilityName(responsibility.getResponsibilityName()); } } } else { costIncomeGroup.setStartDepartmentCode(null); costIncomeGroup.setStartDepartmentName(null); costIncomeGroup.setStartResponsibilityCode(null); costIncomeGroup.setStartResponsibilityName(null); } costIncomeGroup.setDoctorNumber(StrUtil.isBlank(data.get(6).toString()) ? null : Long.parseLong(data.get(6).toString())).setDoctorName(data.get(7).toString()) .setPatientId(StrUtil.isBlank(data.get(8).toString()) ? null : Long.parseLong(data.get(8).toString())).setOutpatientId(StrUtil.isBlank(data.get(9).toString()) ? null : Long.parseLong(data.get(9).toString())) .setPatientName(data.get(10).toString()).setPatientFee(data.get(11).toString()).setReceiptFee(data.get(12).toString()) .setTotalNumber(StrUtil.isBlank(data.get(13).toString()) ? null : Integer.parseInt(data.get(13).toString())).setUnit(data.get(14).toString()) .setFeeDatetime(StrUtil.isBlank(data.get(16).toString()) ? null : DateUtils.StringToDate(data.get(16).toString(), DateStyleEnum.YYYY_MM_DD_HH_MM_SS)); costIncomeGroup.setHospId(hospId); costIncomeGroup.setCreateTime(System.currentTimeMillis()); costIncomeGroup.setDateYear(year); costIncomeGroup.setDateMonth(month); costIncomeGroup.setAmount(beforeMoney); // 检验数据 getAfterData(hospId, costIncomeGroup, afterIncomegroup, beforeMoney); costIncomeGroupArrayList.add(costIncomeGroup); } } /** * 封装需要的数据 * * @param hospId * @param costIncomeGroup * @param afterIncomegroup * @param beforeMoney */ private void getAfterData(Long hospId, CostIncomeGroup costIncomeGroup, AfterIncomegroup afterIncomegroup, BigDecimal beforeMoney) { Integer openDepartmentStatus = afterIncomegroup.getOpenDepartmentStatus(); Integer startDepartmentStatus = afterIncomegroup.getStartDepartmentStatus(); if (Objects.nonNull(openDepartmentStatus) && Objects.nonNull(startDepartmentStatus)) { Map incomeGroupSetMap = costIncomeGroupSetService.list(new QueryWrapper().lambda().eq(CostIncomeGroupSet::getHospId, hospId)).stream().collect(Collectors.toMap(k -> k.getOpenDepartmentStatus().toString() + k.getStartDepartmentStatus().toString(), synOe -> synOe)); CostIncomeGroupSet costIncomeGroupSet = incomeGroupSetMap.get(openDepartmentStatus.toString() + startDepartmentStatus.toString()); if (Objects.nonNull(costIncomeGroupSet)) { Map map = responsibilityService.list(new QueryWrapper().lambda().eq(Responsibility::getHospId, hospId)).stream().collect(Collectors.toMap(Responsibility::getResponsibilityCode, synOe -> synOe)); // 开单科室比例 BigDecimal openDepartmentProportion = new BigDecimal(costIncomeGroupSet.getOpenDepartmentProportion().toString()); // 执行科室比例 BigDecimal startDepartmentProportion = new BigDecimal(costIncomeGroupSet.getStartDepartmentProportion().toString()); // beforeMoney afterIncomegroup.setOpenDepartmentDecimal(beforeMoney.multiply(openDepartmentProportion).divide(new BigDecimal(100), 4, BigDecimal.ROUND_HALF_UP)); afterIncomegroup.setStartDepartmentDecimal(beforeMoney.multiply(startDepartmentProportion).divide(new BigDecimal(100), 4, BigDecimal.ROUND_HALF_UP)); String responsibilityCodes = costIncomeGroupSet.getResponsibilityCodes(); if (NumberConstant.TWO.equals(costIncomeGroupSet.getOpenDepartmentStatus()) && NumberConstant.TWO.equals(costIncomeGroupSet.getStartDepartmentStatus()) && StrUtil.isNotBlank(responsibilityCodes)) { // /拼接的 afterIncomegroup.setDirectStatus(NumberConstant.TWO); String responsibilityCode = responsibilityCodes.split(StrUtil.SLASH)[responsibilityCodes.split(StrUtil.SLASH).length - 1]; Responsibility responsibility = map.get(responsibilityCode); if (Objects.nonNull(responsibility)) { afterIncomegroup.setResponsibilityCode(responsibility.getResponsibilityCode()); afterIncomegroup.setResponsibilityName(responsibility.getResponsibilityName()); } } costIncomeGroup.setAfterIncomeGroup(JSON.toJSONString(afterIncomegroup)); } } } /** * 设置相关名称 * * @param costIncomeGroupAllAmountVOList */ private void setCodeName(List costIncomeGroupAllAmountVOList) { // 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)); costIncomeGroupAllAmountVOList.forEach(i -> { // 以为这里的数据导入的 在导入的时候进行数据校验 // 设置开单科室名称 执行科室名称 开单责任中心名称 执行责任中心名称 成本项目的名称 会计科目名称 i.setOpenDepartmentCodeName("[" + i.getOpenDepartmentCode() + "]" + i.getOpenDepartmentName()); i.setOpenResponsibilityCodeName("[" + i.getOpenResponsibilityCode() + "]" + i.getOpenResponsibilityName()); i.setStartDepartmentCodeName("[" + i.getStartDepartmentCode() + "]" + i.getStartDepartmentName()); i.setStartResponsibilityCodeName("[" + i.getStartResponsibilityCode() + "]" + i.getStartResponsibilityName()); i.setProductCodeName("[" + i.getProductCode() + "]" + i.getProductName()); i.setAccountCodeName("[" + i.getAccountCode() + "]" + i.getAccountName()); }); } /** * 文件上传 */ public String uploadFile(MultipartFile file, User user) { Long hospId = user.getHospId(); String fileName = file.getOriginalFilename().substring(0, file.getOriginalFilename().lastIndexOf(".")) + System.currentTimeMillis() + ".xsl"; String localFilePath = fileTempPath + StrUtil.SLASH + hospId + StrUtil.SLASH; File tempFile = new File(localFilePath); if (!tempFile.exists()) { tempFile.mkdirs(); } localFilePath = localFilePath + fileName; try { file.transferTo(new File(localFilePath)); } catch (IOException e) { log.error("【文件上传至本地】失败,绝对路径:{}", e.getMessage()); throw new CostException(ErrorCodeEnum.FILE_UPLOAD_ERROR); } finally { } return FILE_PATH + hospId + StrUtil.SLASH + fileName; } }