src/main/java/com/ruoyi/production/service/impl/ProductMaterialServiceImpl.java
@@ -348,72 +348,83 @@
    }
    @Override
    public List<ProductMaterialGroupDto> ProductMaterialList() {
        List<ProductMaterialConfig> materialConfigList = productMaterialConfigService.list(new LambdaQueryWrapper<ProductMaterialConfig>()
                .eq(ProductMaterialConfig::getConfigType, MaterialConfigTypeEnum.MATERIAL_TYPE.name()));
        List<ProductMaterialGroupDto> productMaterialMap = new ArrayList<>();
        if (materialConfigList == null || materialConfigList.isEmpty()) {
            return productMaterialMap;
    public List<ProductMaterialGroupDto> ProductMaterialList(Integer type) {
        List<ProductMaterialConfig> configList = productMaterialConfigService.list(new LambdaQueryWrapper<ProductMaterialConfig>()
                .eq(ProductMaterialConfig::getConfigType, MaterialConfigTypeEnum.MATERIAL_TYPE.name())
        );
        if (CollectionUtils.isEmpty(configList)) {
            return new ArrayList<>();
        }
        for (ProductMaterialConfig materialConfig : materialConfigList) {
        List<ProductMaterialGroupDto> result = new ArrayList<>();
        Map<Integer, List<ProductMaterialDto>> materialMap = new HashMap<>();
        if (type != null && type == 2) {
            List<ProductMaterial> materialList = this.list(new LambdaQueryWrapper<ProductMaterial>()
                    .select(
                            ProductMaterial::getId,
                            ProductMaterial::getMaterialTypeId,
                            ProductMaterial::getInventoryCategoryId,
                            ProductMaterial::getMaterialName
                    )
            );
            materialMap = materialList.stream()
                    .map(this::convert)
                    .collect(Collectors.groupingBy(ProductMaterialDto::getMaterialTypeId));
        }
        for (ProductMaterialConfig config : configList) {
            ProductMaterialGroupDto dto = new ProductMaterialGroupDto();
            dto.setConfigId(materialConfig.getId());
            dto.setConfigName(materialConfig.getConfigName());
            productMaterialMap.add(dto);
            dto.setConfigId(config.getId());
            dto.setConfigName(config.getConfigName());
            if (type != null && type == 2) {
                dto.setMaterialList(materialMap.getOrDefault(config.getId(), new ArrayList<>()));
            }
            result.add(dto);
        }
        return productMaterialMap;
        return result;
    }
    @Override
    public List<ProductMaterialGroupDto> productMaterialListByQuery(String materialName, Integer materialTypeId) {
        if (StringUtils.isEmpty(materialName) && materialTypeId == null) {
            return new ArrayList<>(0);
            return new ArrayList<>();
        }
        // 查询物料类型配置
        List<ProductMaterialConfig> materialConfigList = productMaterialConfigService.list(new LambdaQueryWrapper<ProductMaterialConfig>()
        LambdaQueryWrapper<ProductMaterial> wrapper = new LambdaQueryWrapper<>();
        //  只查询需要的字段数据
        wrapper.select(
                ProductMaterial::getId,
                ProductMaterial::getMaterialTypeId,
                ProductMaterial::getInventoryCategoryId,
                ProductMaterial::getMaterialName
        );
        if (StringUtils.isNotEmpty(materialName)) {
            wrapper.like(ProductMaterial::getMaterialName, materialName);
        }
        if (materialTypeId != null) {
            wrapper.eq(ProductMaterial::getMaterialTypeId, materialTypeId);
        }
        List<ProductMaterial> materials = this.list(wrapper);
        if (CollectionUtils.isEmpty(materials)) {
            return new ArrayList<>();
        }
        Map<Integer, List<ProductMaterialDto>> map = materials.stream()
                .map(this::convert)
                .collect(Collectors.groupingBy(ProductMaterialDto::getMaterialTypeId));
        List<ProductMaterialConfig> configList = productMaterialConfigService.list(new LambdaQueryWrapper<ProductMaterialConfig>()
                .eq(ProductMaterialConfig::getConfigType, MaterialConfigTypeEnum.MATERIAL_TYPE.name()));
        List<ProductMaterialGroupDto> result = new ArrayList<>();
        if (CollectionUtils.isEmpty(materialConfigList)) {
            return result;
        }
        LambdaQueryWrapper<ProductMaterial> wrapper;
        for (ProductMaterialConfig materialConfig : materialConfigList) {
            wrapper = new LambdaQueryWrapper<>();
            //  指定需要的字段
            wrapper.select(
                    ProductMaterial::getId,
                    ProductMaterial::getMaterialTypeId,
                    ProductMaterial::getInventoryCategoryId,
                    ProductMaterial::getMaterialName
            );
            if (StringUtils.isNotEmpty(materialName)) {
                wrapper.eq(ProductMaterial::getMaterialTypeId, materialConfig.getId())
                        .like(ProductMaterial::getMaterialName, materialName);
            } else {
                if (!materialConfig.getId().equals(materialTypeId)) {
                    continue;
                }
                wrapper.eq(ProductMaterial::getMaterialTypeId, materialTypeId);
            }
            List<ProductMaterial> materialList = list(wrapper);
            if (CollectionUtils.isEmpty(materialList)) {
        for (ProductMaterialConfig config : configList) {
            List<ProductMaterialDto> dtoList = map.get(config.getId());
            if (CollectionUtils.isEmpty(dtoList)) {
                continue;
            }
            List<ProductMaterialDto> dtoList = materialList.stream().map(m -> {
                ProductMaterialDto dto = new ProductMaterialDto();
                dto.setId(m.getId());
                dto.setMaterialTypeId(m.getMaterialTypeId());
                dto.setInventoryCategoryId(m.getInventoryCategoryId());
                dto.setMaterialName(m.getMaterialName());
                return dto;
            }).collect(Collectors.toList());
            ProductMaterialGroupDto dto = new ProductMaterialGroupDto();
            dto.setConfigId(materialConfig.getId());
            dto.setConfigName(materialConfig.getConfigName());
            dto.setConfigId(config.getId());
            dto.setConfigName(config.getConfigName());
            dto.setMaterialList(dtoList);
            result.add(dto);
        }
@@ -421,6 +432,15 @@
        return result;
    }
    private ProductMaterialDto convert(ProductMaterial m) {
        ProductMaterialDto dto = new ProductMaterialDto();
        dto.setId(m.getId());
        dto.setMaterialName(m.getMaterialName());
        dto.setMaterialTypeId(m.getMaterialTypeId());
        dto.setInventoryCategoryId(m.getInventoryCategoryId());
        return dto;
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addProductMaterial(ProductMaterial productMaterial) {