| | |
| | | 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> |
| | |
| | | } |
| | | |
| | | @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())); |
| | |
| | | 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); |