From 689f0a4a22dced34c3b7c9178a1708410a5a0541 Mon Sep 17 00:00:00 2001 From: manailin <261030956@qq.com> Date: 星期二, 28 九月 2021 17:06:15 +0800 Subject: [PATCH] Merge branch 'test' of http://gitlab.nhys.cdnhxx.com/root/zhihuishequ into test --- springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ConvenientProductServiceImpl.java | 36 +++++++++++++++++++++++------------- 1 files changed, 23 insertions(+), 13 deletions(-) diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ConvenientProductServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ConvenientProductServiceImpl.java index 147b533..0c51aed 100644 --- a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ConvenientProductServiceImpl.java +++ b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ConvenientProductServiceImpl.java @@ -66,6 +66,9 @@ ConvenientProductDO convenientProductDO = new ConvenientProductDO(); BeanUtils.copyProperties(convenientProductDTO, convenientProductDO); Date nowDate = new Date(); + if (convenientProductDTO.getOnShelf()) { + convenientProductDO.setOnShelfAt(nowDate); + } convenientProductDO.setCreatedAt(nowDate); this.baseMapper.insert(convenientProductDO); Long productId = convenientProductDO.getId(); @@ -91,18 +94,19 @@ Long productId = convenientProductDTO.getId(); Long updatedBy = convenientProductDTO.getUpdatedBy(); ConvenientProductDO convenientProductDO = this.baseMapper.selectById(productId); + Boolean isOnShelf = convenientProductDO.getOnShelf(); if (isNull(convenientProductDO)) { return R.fail("产品不存在"); } BeanUtils.copyProperties(convenientProductDTO, convenientProductDO); + Date nowDate = new Date(); + if (!isOnShelf && convenientProductDTO.getOnShelf()) { + convenientProductDO.setOnShelfAt(nowDate); + } 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()); - //删除已失去关联的规格 - convenientProductSpecificationDAO.deleteLoseRelationSpecifications(notNeedDelIds); - Date nowDate = new Date(); + List<Long> notNeedDelIds = new ArrayList<>(); productSpecificationDTOList.forEach(specificationDTO -> { Long specificationId = specificationDTO.getId(); if (isNull(specificationId)) { @@ -113,14 +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, productId); return R.ok(); } @@ -208,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<>(); @@ -217,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); } @@ -247,7 +256,8 @@ if (!records.isEmpty()) { List<Long> productIds = records.stream().map(ConvenientProductVO::getId).collect(Collectors.toList()); List<ConvenientProductSpecificationDO> specificationDOS = convenientProductSpecificationDAO - .selectList(new LambdaQueryWrapper<ConvenientProductSpecificationDO>().in(ConvenientProductSpecificationDO::getProductId, productIds)); + .selectList(new LambdaQueryWrapper<ConvenientProductSpecificationDO>() + .eq(ConvenientProductSpecificationDO::getIsDel, false).in(ConvenientProductSpecificationDO::getProductId, productIds)); List<ConvenientProductSpecificationVO> specificationVOList = new ArrayList<>(); if (!specificationDOS.isEmpty()) { specificationDOS.forEach(specificationDO -> { -- Gitblit v1.7.1