gongchunyi
昨天 49f390c11c7e6d8efdeab17b384c88ab8071fd5c
src/main/java/com/ruoyi/production/service/impl/ProductMaterialServiceImpl.java
@@ -4,11 +4,13 @@
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.framework.config.AliDingConfig;
import com.ruoyi.production.dto.ProductMaterialDto;
import com.ruoyi.production.dto.ProductMaterialGroupDto;
import com.ruoyi.production.enums.MaterialConfigTypeEnum;
import com.ruoyi.production.mapper.ProductMaterialMapper;
@@ -31,6 +33,7 @@
import java.time.format.DateTimeParseException;
import java.util.*;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
/**
 * <br>
@@ -302,10 +305,17 @@
        for (ProductMaterialSku sku : list) {
            ProductMaterialSku exist =
                    productMaterialSkuService.getOne(new LambdaQueryWrapper<ProductMaterialSku>()
                            .eq(ProductMaterialSku::getMaterialId, sku.getMaterialId())
                            .eq(ProductMaterialSku::getSpecification, sku.getSpecification()));
            LambdaQueryWrapper<ProductMaterialSku> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(ProductMaterialSku::getMaterialId, sku.getMaterialId())
                    .eq(ProductMaterialSku::getSpecification, sku.getSpecification());
            if (StringUtils.isNotEmpty(sku.getMaterialCode())) {
                wrapper.eq(ProductMaterialSku::getMaterialCode, sku.getMaterialCode());
            } else {
                wrapper.isNull(ProductMaterialSku::getMaterialCode);
            }
            ProductMaterialSku exist = productMaterialSkuService.getOne(wrapper);
            if (exist == null) {
                productMaterialSkuService.save(sku);
                affected++;
@@ -338,7 +348,7 @@
    }
    @Override
    public List<ProductMaterialGroupDto> ProductMaterialList(String materialName) {
    public List<ProductMaterialGroupDto> ProductMaterialList() {
        List<ProductMaterialConfig> materialConfigList = productMaterialConfigService.list(new LambdaQueryWrapper<ProductMaterialConfig>()
                .eq(ProductMaterialConfig::getConfigType, MaterialConfigTypeEnum.MATERIAL_TYPE.name()));
@@ -348,24 +358,70 @@
            return productMaterialMap;
        }
        for (ProductMaterialConfig materialConfig : materialConfigList) {
            LambdaQueryWrapper<ProductMaterial> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(ProductMaterial::getMaterialTypeId, materialConfig.getId())
                    .select(ProductMaterial::getId, ProductMaterial::getMaterialName)
                    .like(materialName != null && !materialName.isEmpty(), ProductMaterial::getMaterialName, materialName);
            List<ProductMaterial> productMaterialList = list(wrapper);
            if (productMaterialList != null && !productMaterialList.isEmpty()) {
                ProductMaterialGroupDto dto = new ProductMaterialGroupDto();
                dto.setConfigId(materialConfig.getId());
                dto.setConfigName(materialConfig.getConfigName());
                dto.setMaterialList(productMaterialList);
                productMaterialMap.add(dto);
            }
            ProductMaterialGroupDto dto = new ProductMaterialGroupDto();
            dto.setConfigId(materialConfig.getId());
            dto.setConfigName(materialConfig.getConfigName());
            productMaterialMap.add(dto);
        }
        return productMaterialMap;
    }
    @Override
    public List<ProductMaterialGroupDto> productMaterialListByQuery(String materialName, Integer materialTypeId) {
        if (StringUtils.isEmpty(materialName) && materialTypeId == null) {
            return new ArrayList<>(0);
        }
        // 查询物料类型配置
        List<ProductMaterialConfig> materialConfigList = 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)) {
                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.setMaterialList(dtoList);
            result.add(dto);
        }
        return result;
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addProductMaterial(ProductMaterial productMaterial) {
        validateProductMaterial(productMaterial, false);