| | |
| | | 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; |
| | |
| | | import java.time.format.DateTimeParseException; |
| | | import java.util.*; |
| | | import java.util.concurrent.locks.ReentrantLock; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <br> |
| | |
| | | |
| | | 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++; |
| | |
| | | } |
| | | |
| | | @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 |