| | |
| | | package com.panzhihua.service_community.service.impl; |
| | | |
| | | import static java.util.Objects.isNull; |
| | | import static java.util.Objects.nonNull; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Comparator; |
| | | import java.util.Date; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | |
| | | import com.panzhihua.common.model.dtos.community.convenient.DeleteConvenientProductDTO; |
| | | import com.panzhihua.common.model.dtos.community.convenient.OnShelfOrOffShelfProductDTO; |
| | | import com.panzhihua.common.model.dtos.community.convenient.PageConvenientProductDTO; |
| | | import com.panzhihua.common.model.dtos.community.convenient.PageMerchantProductDTO; |
| | | import com.panzhihua.common.model.dtos.community.convenient.PageSearchDTO; |
| | | import com.panzhihua.common.model.vos.R; |
| | | import com.panzhihua.common.model.vos.community.convenient.ConvenientProductLevelInfoVO; |
| | | import com.panzhihua.common.model.vos.community.convenient.ConvenientProductShelfVO; |
| | | import com.panzhihua.common.model.vos.community.convenient.ConvenientProductSpecificationVO; |
| | | import com.panzhihua.common.model.vos.community.convenient.ConvenientProductVO; |
| | | import com.panzhihua.service_community.dao.ConvenientProductCategoryDAO; |
| | |
| | | import com.panzhihua.service_community.model.dos.ConvenientProductDO; |
| | | import com.panzhihua.service_community.model.dos.ConvenientProductSpecificationDO; |
| | | import com.panzhihua.service_community.service.ConvenientProductService; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static java.util.Objects.isNull; |
| | | import static java.util.Objects.nonNull; |
| | | |
| | | /** |
| | | * @title: ConvenientProductServiceImpl |
| | |
| | | //图片填充 |
| | | if (!convenientProductVOList.isEmpty()) { |
| | | convenientProductVOList.forEach(product -> { |
| | | ConvenientProductSpecificationDO specificationDO = convenientProductSpecificationDAO.selectList(new LambdaQueryWrapper<ConvenientProductSpecificationDO>() |
| | | .eq(ConvenientProductSpecificationDO::getProductId, product.getId())).get(0); |
| | | product.setImage(specificationDO.getImage()); |
| | | List<ConvenientProductSpecificationDO> specificationDOList = convenientProductSpecificationDAO.selectList(new LambdaQueryWrapper<ConvenientProductSpecificationDO>() |
| | | .eq(ConvenientProductSpecificationDO::getProductId, product.getId()).isNotNull(ConvenientProductSpecificationDO::getImage)); |
| | | product.setImage(specificationDOList.isEmpty() ? null : specificationDOList.get(0).getImage()); |
| | | }); |
| | | } |
| | | return R.ok(productVOIPage); |
| | |
| | | |
| | | /** |
| | | * 小程序获取商家产品 |
| | | * @param pageMerchantProductDTO |
| | | * @param merchantId |
| | | * @return |
| | | */ |
| | | @Override |
| | | public R getMerchantProduct(PageMerchantProductDTO pageMerchantProductDTO) { |
| | | public R getMerchantProduct(Long merchantId) { |
| | | List<ConvenientProductVO> productVOList = this.baseMapper.getMerchantProduct(merchantId); |
| | | List<ConvenientProductSpecificationVO> specificationVOList = this.baseMapper.getProductSpecifications(merchantId); |
| | | List<ConvenientProductLevelInfoVO> levelInfoVOList = new ArrayList<>(); |
| | | if (!productVOList.isEmpty()) { |
| | | productVOList.forEach(productVO -> { |
| | | List<ConvenientProductSpecificationVO> currentProductSpecificationVOList = new ArrayList<>(); |
| | | specificationVOList.forEach(specificationVO -> { |
| | | if (productVO.getId().equals(specificationVO.getProductId())) { |
| | | currentProductSpecificationVOList.add(specificationVO); |
| | | } |
| | | }); |
| | | productVO.setProductSpecificationVOList(currentProductSpecificationVOList); |
| | | }); |
| | | //分类 |
| | | 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(); |
| | | ConvenientProductLevelInfoVO levelInfoVOLevelInfoVO = new ConvenientProductLevelInfoVO(); |
| | | levelInfoVOLevelInfoVO.setCategoryName(categoryName); |
| | | List<ConvenientProductVO> productVOS = levelGroup.get(categoryName); |
| | | List<ConvenientProductVO> sortedProductVOS = productVOS.stream() |
| | | .sorted(Comparator.comparing(ConvenientProductVO::getOnShelfAt).reversed()).collect(Collectors.toList()); |
| | | levelInfoVOLevelInfoVO.setProductVOList(sortedProductVOS); |
| | | levelInfoVOList.add(levelInfoVOLevelInfoVO); |
| | | } |
| | | } |
| | | return R.ok(levelInfoVOList); |
| | | } |
| | | |
| | | @Override |
| | | public R pageSearchProduct(PageSearchDTO pageSearchDTO) { |
| | | Page page = new Page<>(); |
| | | page.setSize(pageMerchantProductDTO.getPageSize()); |
| | | page.setCurrent(pageMerchantProductDTO.getPageNum()); |
| | | IPage<ConvenientProductVO> productVOIPage = this.baseMapper.getMerchantProduct(page, pageMerchantProductDTO); |
| | | return null; |
| | | page.setSize(pageSearchDTO.getPageSize()); |
| | | page.setCurrent(pageSearchDTO.getPageNum()); |
| | | IPage<ConvenientProductVO> productVOIPage = this.baseMapper.pageSearchProduct(page, pageSearchDTO); |
| | | List<ConvenientProductVO> records = productVOIPage.getRecords(); |
| | | 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)); |
| | | List<ConvenientProductSpecificationVO> specificationVOList = new ArrayList<>(); |
| | | if (!specificationDOS.isEmpty()) { |
| | | specificationDOS.forEach(specificationDO -> { |
| | | ConvenientProductSpecificationVO specificationVO = new ConvenientProductSpecificationVO(); |
| | | BeanUtils.copyProperties(specificationDO, specificationVO); |
| | | specificationVOList.add(specificationVO); |
| | | }); |
| | | Map<Long, List<ConvenientProductSpecificationVO>> collect = specificationVOList |
| | | .stream().collect(Collectors.groupingBy(ConvenientProductSpecificationVO::getProductId)); |
| | | Set<Long> keySet = collect.keySet(); |
| | | Iterator<Long> iterator = keySet.iterator(); |
| | | while (iterator.hasNext()) { |
| | | Long productId = iterator.next(); |
| | | records.forEach(record -> { |
| | | if (record.getId().equals(productId)) { |
| | | record.setProductSpecificationVOList(collect.get(productId)); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | return R.ok(productVOIPage); |
| | | } |
| | | |
| | | @Override |
| | | public R incrProductView(Long productId) { |
| | | this.baseMapper.incrProductView(productId); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @Override |
| | | public R getProductShelfNum(Long merchantId) { |
| | | int onShelfTotalNum = this.baseMapper.selectCount(new LambdaQueryWrapper<ConvenientProductDO>().eq(ConvenientProductDO::getMerchantId, merchantId) |
| | | .eq(ConvenientProductDO::getIsDel, false).eq(ConvenientProductDO::getOnShelf, true)); |
| | | int offShelfTotalNum = this.baseMapper.selectCount(new LambdaQueryWrapper<ConvenientProductDO>().eq(ConvenientProductDO::getMerchantId, merchantId) |
| | | .eq(ConvenientProductDO::getIsDel, false).eq(ConvenientProductDO::getOnShelf, false)); |
| | | ConvenientProductShelfVO convenientProductShelfVO = new ConvenientProductShelfVO(); |
| | | convenientProductShelfVO.setOnShelfTotalNum(onShelfTotalNum); |
| | | convenientProductShelfVO.setOffShelfTotalNum(offShelfTotalNum); |
| | | return R.ok(convenientProductShelfVO); |
| | | } |
| | | } |