|
@@ -2,6 +2,7 @@ package edu.travel.commodity.service.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
|
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
@@ -10,13 +11,13 @@ import edu.travel.commodity.dto.ProductSpecDto;
|
|
import edu.travel.commodity.entity.*;
|
|
import edu.travel.commodity.entity.*;
|
|
import edu.travel.commodity.mapper.ShopProductSpecMapper;
|
|
import edu.travel.commodity.mapper.ShopProductSpecMapper;
|
|
import edu.travel.commodity.service.*;
|
|
import edu.travel.commodity.service.*;
|
|
-import edu.travel.commodity.vo.ProductSkuVo;
|
|
|
|
-import edu.travel.commodity.vo.ProductSpecVo;
|
|
|
|
-import edu.travel.commodity.vo.SpecSortVo;
|
|
|
|
-import edu.travel.commodity.vo.SpecValueVo;
|
|
|
|
|
|
+import edu.travel.commodity.vo.*;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.web.context.request.RequestContextHolder;
|
|
|
|
+import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -29,21 +30,22 @@ public class ShopProductSpecServiceImpl extends ServiceImpl<ShopProductSpecMappe
|
|
@Autowired
|
|
@Autowired
|
|
private ShopProductSkuService shopProductSkuService;
|
|
private ShopProductSkuService shopProductSkuService;
|
|
@Autowired
|
|
@Autowired
|
|
- private ShopSkuSpecValueService shopSkuSpecValueService;
|
|
|
|
- @Autowired
|
|
|
|
- private ShopSpecService shopSpecService;
|
|
|
|
|
|
+ private ShopProductImageService shopProductImageService;
|
|
@Autowired
|
|
@Autowired
|
|
private ShopProductSpecService shopProductSpecService;
|
|
private ShopProductSpecService shopProductSpecService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ShopProductSpecMapper shopProductSpecMapper;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public ProductSpecVo getShopSpec(ProductSpecDto param) {
|
|
public ProductSpecVo getShopSpec(ProductSpecDto param) {
|
|
- LambdaQueryChainWrapper<ShopProduct> query = shopProductService.lambdaQuery().eq(ShopProduct::getId, param.getProductId())
|
|
|
|
|
|
+ LambdaQueryWrapper<ShopProduct> query = Wrappers.<ShopProduct>lambdaQuery().eq(ShopProduct::getId, param.getProductId())
|
|
.eq(ShopProduct::getCountryId, param.getCountryId());
|
|
.eq(ShopProduct::getCountryId, param.getCountryId());
|
|
//商品信息
|
|
//商品信息
|
|
ShopProduct one = shopProductService.getOne(query);
|
|
ShopProduct one = shopProductService.getOne(query);
|
|
if(ObjectUtil.isEmpty(one)){
|
|
if(ObjectUtil.isEmpty(one)){
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
+
|
|
List<ShopProductSku> list1 = shopProductSkuService.list(Wrappers.<ShopProductSku>lambdaQuery()
|
|
List<ShopProductSku> list1 = shopProductSkuService.list(Wrappers.<ShopProductSku>lambdaQuery()
|
|
.eq(ShopProductSku::getStatus, BaseConstant.BASIC_STATUS_NO_NUM)
|
|
.eq(ShopProductSku::getStatus, BaseConstant.BASIC_STATUS_NO_NUM)
|
|
.eq(ShopProductSku::getProductId, one.getId()));
|
|
.eq(ShopProductSku::getProductId, one.getId()));
|
|
@@ -51,59 +53,61 @@ public class ShopProductSpecServiceImpl extends ServiceImpl<ShopProductSpecMappe
|
|
if(ObjectUtil.isEmpty(list1)){
|
|
if(ObjectUtil.isEmpty(list1)){
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
+
|
|
ProductSpecVo bean = BeanUtil.toBean(one, ProductSpecVo.class);
|
|
ProductSpecVo bean = BeanUtil.toBean(one, ProductSpecVo.class);
|
|
|
|
+ //商品的全部图片
|
|
|
|
+ List<ShopProductImage> list = shopProductImageService.lambdaQuery()
|
|
|
|
+ .eq(ShopProductImage::getProductId, one.getId()).list();
|
|
|
|
+ List<ProductImageVo> productImageVos = BeanUtil.copyToList(list, ProductImageVo.class);
|
|
|
|
+
|
|
|
|
+ List<ProductImageVo> collect = productImageVos.stream().filter(item -> item.getIsDefault().equals(BaseConstant.BASIC_IS_DEFAULT_YES)).collect(Collectors.toList());
|
|
|
|
+ bean.setImages(collect);
|
|
|
|
+
|
|
|
|
+ Map<String, List<ProductImageVo>> imageMap = collect.stream().collect(Collectors.groupingBy(ProductImageVo::getSkuId));
|
|
//SKU
|
|
//SKU
|
|
- Set<Long> skus = list1.stream().map(ShopProductSku::getSkuId).collect(Collectors.toSet());
|
|
|
|
- //规格和规格对应的值
|
|
|
|
- List<ShopSkuSpecValue> skuValues = shopSkuSpecValueService.lambdaQuery().eq(ShopSkuSpecValue::getSkuId, skus).list();
|
|
|
|
- //规格值ID
|
|
|
|
- Set<Long> collect = skuValues.stream().map(ShopSkuSpecValue::getSpecValueId).collect(Collectors.toSet());
|
|
|
|
- List<ShopSpecValue> list2 = shopSpecValueService.list(Wrappers.<ShopSpecValue>lambdaQuery()
|
|
|
|
- .orderByAsc(ShopSpecValue::getSortOrder)
|
|
|
|
- .in(ShopSpecValue::getId, collect));
|
|
|
|
-
|
|
|
|
- //规格ID
|
|
|
|
- List<ShopProductSpec> list = shopProductSpecService.lambdaQuery().eq(ShopProductSpec::getProductId, one.getId())
|
|
|
|
- .orderByAsc(ShopProductSpec::getSortOrder).list();
|
|
|
|
- Set<Long> collect3 = list.stream().map(ShopProductSpec::getSpecId).collect(Collectors.toSet());
|
|
|
|
- Map<String, ShopSpec> specs = new HashMap<>();
|
|
|
|
- List<ShopSpec> list11 = shopSpecService.lambdaQuery().in(ShopSpec::getId, collect3).list();
|
|
|
|
-
|
|
|
|
- for (ShopSpec spec : list11) {
|
|
|
|
- specs.put(spec.getId().toString(), spec);
|
|
|
|
- }
|
|
|
|
- List<SpecSortVo> specSortVoList = new ArrayList<>();
|
|
|
|
- for (ShopProductSpec shopProductSpec : list) {
|
|
|
|
- SpecSortVo specSortVo = new SpecSortVo();
|
|
|
|
- specSortVo.setId(shopProductSpec.getSpecId().toString());
|
|
|
|
- specSortVo.setSpecName(shopProductSpec.getSpecName());
|
|
|
|
- }
|
|
|
|
|
|
+ Set<String> skus = list1.stream().map(item->item.getSkuId().toString()).collect(Collectors.toSet());
|
|
|
|
|
|
- bean.setSpecSortVoList(specSortVoList);
|
|
|
|
|
|
+ HttpServletRequest request = ((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getRequest();
|
|
|
|
+ String project = request.getHeader("project");
|
|
|
|
+
|
|
|
|
+ //sku规格和规格对应的值
|
|
|
|
+ List<ShopSkuSpecValueVo> skuValue=shopProductSpecMapper.getSkuValue(skus,project);
|
|
|
|
+ Map<String, List<ShopSkuSpecValueVo>> map = skuValue.stream().collect(Collectors.groupingBy(ShopSkuSpecValueVo::getSkuId));
|
|
|
|
|
|
- Set<Long> skuIds = skuValues.stream().map(ShopSkuSpecValue::getSkuId).collect(Collectors.toSet());
|
|
|
|
- //SKU -> ShopSpecValue
|
|
|
|
ArrayList<ProductSkuVo> productSkuVos = new ArrayList<>();
|
|
ArrayList<ProductSkuVo> productSkuVos = new ArrayList<>();
|
|
- for (Long skuId : skuIds) {
|
|
|
|
- List<Long> collect2 = skuValues.stream().filter(item -> item.getSkuId().equals(skuId)).map(ShopSkuSpecValue::getSpecValueId).collect(Collectors.toList());
|
|
|
|
- List<ShopSpecValue> collect1 = list2.stream().filter(item -> collect2.contains(item.getId())).collect(Collectors.toList());
|
|
|
|
-
|
|
|
|
- ProductSkuVo productSkuVo = new ProductSkuVo();
|
|
|
|
- List<SpecValueVo> specValueVos = new ArrayList<>();
|
|
|
|
- for (ShopSpecValue shopSpecValue : collect1) {
|
|
|
|
- SpecValueVo specValueVo = new SpecValueVo();
|
|
|
|
-// ShopSpec shopSpec = specs.get(shopSpecValue.getSpecId().toString());
|
|
|
|
-// specValueVo.setKeyId(shopSpecValue.getSpecId().toString());
|
|
|
|
-// specValueVo.setKey(shopSpec.getSpecName());
|
|
|
|
- specValueVo.setValueId(shopSpecValue.getId().toString());
|
|
|
|
- specValueVo.setValue(shopSpecValue.getSpecValue());
|
|
|
|
- specValueVos.add(specValueVo);
|
|
|
|
- }
|
|
|
|
- productSkuVo.setSpecValue(specValueVos);
|
|
|
|
- productSkuVos.add(productSkuVo);
|
|
|
|
|
|
+ for (ShopProductSku info : list1) {
|
|
|
|
+ ProductSkuVo infoVo = BeanUtil.toBean(info, ProductSkuVo.class);
|
|
|
|
+ infoVo.setDescription(one.getDescription());
|
|
|
|
+ infoVo.setProductName(one.getProductName());
|
|
|
|
+ bean.setImages(imageMap.get(info.getSkuId().toString()));
|
|
|
|
+ List<ShopSkuSpecValueVo> shopSkuSpecValueVos = map.get(info.getSkuId().toString());
|
|
|
|
+ infoVo.setSpecValue(shopSkuSpecValueVos);
|
|
|
|
+ productSkuVos.add(infoVo);
|
|
}
|
|
}
|
|
|
|
+ List<SpecSortVo> specSortVoList= getSpecSortVoList(param.getProductId());
|
|
|
|
+ bean.setSpecSortVoList(specSortVoList);
|
|
bean.setSkuList(productSkuVos);
|
|
bean.setSkuList(productSkuVos);
|
|
-
|
|
|
|
return bean;
|
|
return bean;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public List<SpecSortVo> getSpecSortVoList(String productId){
|
|
|
|
+ List<ShopProductSpec> specs = shopProductSpecService.lambdaQuery().eq(ShopProductSpec::getProductId, productId).orderByAsc(ShopProductSpec::getSortOrder).list();
|
|
|
|
+ List<SpecSortVo> list = BeanUtil.copyToList(specs, SpecSortVo.class);
|
|
|
|
+ if(ObjectUtil.isEmpty(list)){
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
|
|
+ Set<Long> collect = specs.stream().map(ShopProductSpec::getId).collect(Collectors.toSet());
|
|
|
|
+ List<ShopSpecValue> list1 = shopSpecValueService.lambdaQuery().in(ShopSpecValue::getProductSpecId, collect).list();
|
|
|
|
+ for (SpecSortVo spec : list) {
|
|
|
|
+ List<ShopSpecValue> collect1 = list1.stream().filter(item -> item.getProductSpecId().toString().equals(spec.getId()))
|
|
|
|
+ .sorted(Comparator.comparing(ShopSpecValue::getSortOrder)).collect(Collectors.toList());
|
|
|
|
+ List<SpecValueSortVo> specValueSortVos = BeanUtil.copyToList(collect1, SpecValueSortVo.class);
|
|
|
|
+ spec.setList(specValueSortVos);
|
|
|
|
+ }
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|