From f78c1d5feb1b800b5afdf743821bf4c8672843a6 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期五, 13 三月 2026 11:45:02 +0800
Subject: [PATCH] refactor: 代码回退
---
src/main/java/com/ruoyi/production/service/impl/ProductMaterialServiceImpl.java | 124 +++++++++++++++++++++++++++++++++--------
1 files changed, 100 insertions(+), 24 deletions(-)
diff --git a/src/main/java/com/ruoyi/production/service/impl/ProductMaterialServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/ProductMaterialServiceImpl.java
index 76a52d3..0caf06a 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductMaterialServiceImpl.java
+++ b/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,31 +348,97 @@
}
@Override
- public List<ProductMaterialGroupDto> ProductMaterialList(String materialName) {
+ 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<>();
+ }
+ 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));
+ }
- List<ProductMaterialConfig> materialConfigList = productMaterialConfigService.list(new LambdaQueryWrapper<ProductMaterialConfig>()
+ for (ProductMaterialConfig config : configList) {
+ ProductMaterialGroupDto dto = new ProductMaterialGroupDto();
+ 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 result;
+ }
+
+
+ @Override
+ public List<ProductMaterialGroupDto> productMaterialListByQuery(String materialName, Integer materialTypeId) {
+
+ if (StringUtils.isEmpty(materialName) && materialTypeId == null) {
+ return new ArrayList<>();
+ }
+
+ 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> productMaterialMap = new ArrayList<>();
- if (materialConfigList == null || materialConfigList.isEmpty()) {
- 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);
+ List<ProductMaterialGroupDto> result = new ArrayList<>();
+ for (ProductMaterialConfig config : configList) {
+ List<ProductMaterialDto> dtoList = map.get(config.getId());
+ if (CollectionUtils.isEmpty(dtoList)) {
+ continue;
}
+ ProductMaterialGroupDto dto = new ProductMaterialGroupDto();
+ dto.setConfigId(config.getId());
+ dto.setConfigName(config.getConfigName());
+ dto.setMaterialList(dtoList);
+ result.add(dto);
}
- return productMaterialMap;
+
+ 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
--
Gitblit v1.9.3