package com.imed.costaccount.model; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.imed.costaccount.common.exception.CostException; import com.imed.costaccount.service.*; import io.swagger.annotations.ApiModel; import lombok.Data; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.CollectionUtils; import java.util.List; import java.util.Map; import java.util.stream.Collectors; /** * @author 李加喜 * @Package com.imed.costaccount.model * @date 2021-08-10 17:15 */ @Data @ApiModel("获取数据") public class GetCheckData { @Autowired private DepartmentService departmentService; @Autowired private ResponsibilityService responsibilityService; @Autowired private ProductService productService; @Autowired private AccountingService accountingService; @Autowired private ResponsibilityDepartmentService responsibilityDepartmentService; @Autowired private AccountingProductService accountingProductService; private Long hospId; private Map departmentMap; private Map productMap; private Map responsibilityMap; private Map accountingMap; private Map responsibilityDepMap; private Map accountProMap; public GetCheckData(Long hospId) { this.hospId = hospId; } public Map getDepartmentMap() { return departmentMap; } public Map getProductMap() { return productMap; } public Map getResponsibilityMap() { return responsibilityMap; } public Map getAccountingMap() { return accountingMap; } public Map getResponsibilityDepMap() { return responsibilityDepMap; } public Map getAccountProMap() { return accountProMap; } public GetCheckData invoke() { departmentMap = departmentService.list(new QueryWrapper().lambda().eq(Department::getHospId, hospId)).stream().collect(Collectors.toMap(k -> k.getDepartmentCode() + k.getDepartmentName(), synOe -> synOe)); productMap = productService.list(new QueryWrapper().lambda().eq(Product::getHospId, hospId)).stream().collect(Collectors.toMap(k -> k.getProductCode() + k.getProductName(), synOe -> synOe)); responsibilityMap = responsibilityService.list(new QueryWrapper().lambda().eq(Responsibility::getHospId, hospId)).stream().collect(Collectors.toMap(Responsibility::getId, synOe -> synOe)); accountingMap = accountingService.list(new QueryWrapper().lambda().eq(Accounting::getHospId, hospId)).stream().collect(Collectors.toMap(Accounting::getId, synOe -> synOe)); List responsibilityDepartmentList = responsibilityDepartmentService.list(new QueryWrapper().lambda() .eq(ResponsibilityDepartment::getHospId, 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, "没有成本会计对照数据"); } responsibilityDepMap = responsibilityDepartmentList.stream().collect(Collectors.toMap(ResponsibilityDepartment::getDepartmentId, ResponsibilityDepartment::getResponsibilityId)); accountProMap = accountingProductList.stream().collect(Collectors.toMap(AccountingProduct::getProductId, AccountingProduct::getAccountingId)); return this; } }