gongchunyi
昨天 49f390c11c7e6d8efdeab17b384c88ab8071fd5c
fix: 物料数据类别数据集合接口优化
已添加1个文件
已修改4个文件
126 ■■■■■ 文件已修改
src/main/java/com/ruoyi/production/controller/ProductMaterialController.java 16 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/production/dto/ProductMaterialDto.java 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/production/dto/ProductMaterialGroupDto.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/production/service/ProductMaterialService.java 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/production/service/impl/ProductMaterialServiceImpl.java 65 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/production/controller/ProductMaterialController.java
@@ -43,10 +43,18 @@
    }
    @GetMapping("/list")
    @ApiOperation("物料数据")
    @Log(title = "物料数据", businessType = BusinessType.OTHER)
    public AjaxResult productMaterialList(String materialName) {
        List<ProductMaterialGroupDto> productMaterialMap = productMaterialService.ProductMaterialList(materialName);
    @ApiOperation("物料数据类别数据集合")
    @Log(title = "物料数据类别数据集合", businessType = BusinessType.OTHER)
    public AjaxResult productMaterialList() {
        List<ProductMaterialGroupDto> productMaterialMap = productMaterialService.ProductMaterialList();
        return AjaxResult.success(productMaterialMap);
    }
    @GetMapping("/listQuery")
    @ApiOperation("物料数据类别子类数据集合")
    @Log(title = "物料数据类别子类数据集合", businessType = BusinessType.OTHER)
    public AjaxResult productMaterialListByQuery(@RequestParam(value = "materialName", required = false) String materialName, @RequestParam(value = "materialTypeId", required = false) Integer materialTypeId) {
        List<ProductMaterialGroupDto> productMaterialMap = productMaterialService.productMaterialListByQuery(materialName, materialTypeId);
        return AjaxResult.success(productMaterialMap);
    }
src/main/java/com/ruoyi/production/dto/ProductMaterialDto.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,39 @@
package com.ruoyi.production.dto;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.time.LocalDateTime;
/**
 * <br>
 * äº§å“ç‰©æ–™ä¿¡æ¯ Dto
 * </br>
 *
 * @author deslrey
 * @version 1.0
 * @since 2026/03/13 10:50
 */
@Data
@ApiModel(value = "ProductMaterialDto", description = "物料主表Dto")
public class ProductMaterialDto {
    @ApiModelProperty("主键ID")
    private Long id;
    @ApiModelProperty("物料类型ID")
    private Integer materialTypeId;
    @ApiModelProperty("存货类别ID")
    private Integer inventoryCategoryId;
    @ApiModelProperty("物料名称")
    private String materialName;
}
src/main/java/com/ruoyi/production/dto/ProductMaterialGroupDto.java
@@ -26,5 +26,5 @@
    private String configName;
    @ApiModelProperty("物料列表")
    private List<ProductMaterial> materialList;
    private List<ProductMaterialDto> materialList;
}
src/main/java/com/ruoyi/production/service/ProductMaterialService.java
@@ -21,11 +21,13 @@
    void syncProductMaterialJob();
    List<ProductMaterialGroupDto> ProductMaterialList(String materialName);
    List<ProductMaterialGroupDto> ProductMaterialList();
    void addProductMaterial(ProductMaterial productMaterial);
    void updateProductMaterial(ProductMaterial productMaterial);
    void deleteProductMaterial(List<Long> ids);
    List<ProductMaterialGroupDto> productMaterialListByQuery(String materialName, Integer materialTypeId);
}
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>
@@ -345,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()));
@@ -355,20 +358,70 @@
            return productMaterialMap;
        }
        for (ProductMaterialConfig materialConfig : materialConfigList) {
            LambdaQueryWrapper<ProductMaterial> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(ProductMaterial::getMaterialTypeId, materialConfig.getId())
                    .like(materialName != null && !materialName.isEmpty(), ProductMaterial::getMaterialName, materialName);
            List<ProductMaterial> productMaterialList = list(wrapper);
            ProductMaterialGroupDto dto = new ProductMaterialGroupDto();
            dto.setConfigId(materialConfig.getId());
            dto.setConfigName(materialConfig.getConfigName());
            dto.setMaterialList(productMaterialList);
            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);