| | |
| | | convenientProductDO.setUpdatedBy(updatedBy); |
| | | this.baseMapper.updateById(convenientProductDO); |
| | | List<ConvenientProductSpecificationDTO> productSpecificationDTOList = convenientProductDTO.getProductSpecificationDTOList(); |
| | | List<Long> notNeedDelIds = productSpecificationDTOList.stream().filter(specificationDTO -> nonNull(specificationDTO.getId())) |
| | | .map(ConvenientProductSpecificationDTO::getId).collect(Collectors.toList()); |
| | | List<Long> notNeedDelIds = new ArrayList<>(); |
| | | productSpecificationDTOList.forEach(specificationDTO -> { |
| | | Long specificationId = specificationDTO.getId(); |
| | | if (isNull(specificationId)) { |
| | |
| | | convenientProductSpecificationDO.setCreatedAt(nowDate); |
| | | convenientProductSpecificationDO.setCreatedBy(updatedBy); |
| | | convenientProductSpecificationDAO.insert(convenientProductSpecificationDO); |
| | | notNeedDelIds.add(convenientProductSpecificationDO.getId()); |
| | | } else { |
| | | //更新 |
| | | ConvenientProductSpecificationDO convenientProductSpecificationDO = convenientProductSpecificationDAO.selectById(specificationId); |
| | | BeanUtils.copyProperties(specificationDTO, convenientProductSpecificationDO); |
| | | convenientProductSpecificationDO.setUpdatedBy(updatedBy); |
| | | convenientProductSpecificationDAO.updateById(convenientProductSpecificationDO); |
| | | notNeedDelIds.add(specificationId); |
| | | } |
| | | }); |
| | | //删除已失去关联的规格 |
| | | convenientProductSpecificationDAO.deleteLoseRelationSpecifications(notNeedDelIds); |
| | | convenientProductSpecificationDAO.deleteLoseRelationSpecifications(notNeedDelIds, productId); |
| | | return R.ok(); |
| | | } |
| | | |
| | |
| | | List<ConvenientProductVO> productVOList = this.baseMapper.getMerchantProduct(merchantId); |
| | | List<ConvenientProductSpecificationVO> specificationVOList = this.baseMapper.getProductSpecifications(merchantId); |
| | | List<ConvenientProductLevelInfoVO> levelInfoVOList = new ArrayList<>(); |
| | | List<String> categoryList = new ArrayList<>(); |
| | | if (!productVOList.isEmpty()) { |
| | | productVOList.forEach(productVO -> { |
| | | List<ConvenientProductSpecificationVO> currentProductSpecificationVOList = new ArrayList<>(); |
| | |
| | | } |
| | | }); |
| | | productVO.setProductSpecificationVOList(currentProductSpecificationVOList); |
| | | if (!categoryList.contains(productVO.getCategoryName())) { |
| | | categoryList.add(productVO.getCategoryName()); |
| | | } |
| | | }); |
| | | //分类 |
| | | Map<String, List<ConvenientProductVO>> levelGroup = productVOList.stream() |
| | | .collect(Collectors.groupingBy(ConvenientProductVO::getCategoryName)); |
| | | Set<String> categoryNames = levelGroup.keySet(); |
| | | Iterator<String> iterator = categoryNames.iterator(); |
| | | while (iterator.hasNext()) { |
| | | String categoryName = iterator.next(); |
| | | categoryList.forEach(category -> { |
| | | ConvenientProductLevelInfoVO levelInfoVOLevelInfoVO = new ConvenientProductLevelInfoVO(); |
| | | levelInfoVOLevelInfoVO.setCategoryName(categoryName); |
| | | List<ConvenientProductVO> productVOS = levelGroup.get(categoryName); |
| | | levelInfoVOLevelInfoVO.setCategoryName(category); |
| | | List<ConvenientProductVO> productVOS = levelGroup.get(category); |
| | | List<ConvenientProductVO> sortedProductVOS = productVOS.stream() |
| | | .sorted(Comparator.comparing(ConvenientProductVO::getOnShelfAt).reversed()).collect(Collectors.toList()); |
| | | levelInfoVOLevelInfoVO.setProductVOList(sortedProductVOS); |
| | | levelInfoVOList.add(levelInfoVOLevelInfoVO); |
| | | } |
| | | }); |
| | | } |
| | | return R.ok(levelInfoVOList); |
| | | } |