puhanshu
2021-09-27 a5b5a3569f673661f74089f157aefb3c7d683adb
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ConvenientProductServiceImpl.java
@@ -106,8 +106,7 @@
        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)) {
@@ -118,16 +117,18 @@
                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();
    }
@@ -215,6 +216,7 @@
        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<>();
@@ -224,22 +226,22 @@
                    }
                });
                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);
    }