|
@@ -2,15 +2,14 @@ package edu.travel.commodity.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import edu.travel.commodity.entity.ShopProductSku;
|
|
|
-import edu.travel.commodity.entity.ShopSkuSpecValue;
|
|
|
-import edu.travel.commodity.entity.ShopSpec;
|
|
|
-import edu.travel.commodity.entity.ShopSpecValue;
|
|
|
import edu.travel.commodity.mapper.ShopProductSkuMapper;
|
|
|
import edu.travel.commodity.service.ShopProductSkuService;
|
|
|
import edu.travel.commodity.service.ShopSkuSpecValueService;
|
|
|
import edu.travel.commodity.service.ShopSpecService;
|
|
|
import edu.travel.commodity.service.ShopSpecValueService;
|
|
|
+import edu.travel.commodity.vo.SortSpecVo;
|
|
|
import edu.travel.commodity.vo.SpecValueVo;
|
|
|
+import edu.travel.commodity.vo.SpecVo;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -28,39 +27,19 @@ public class ShopProductSkuServiceImpl extends ServiceImpl<ShopProductSkuMapper,
|
|
|
private ShopSpecValueService shopSpecValueService;
|
|
|
@Autowired
|
|
|
private ShopSpecService shopSpecService;
|
|
|
+ @Autowired
|
|
|
+ private ShopProductSkuMapper shopProductSkuMapper;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询SKU下的规格和对应的规格值 规格 排序 规格值排序
|
|
|
+ * @param skuId
|
|
|
+ * @return {@link Map }<{@link String },{@link List }<{@link SpecVo }>>
|
|
|
+ */
|
|
|
@Override
|
|
|
- public Map<String,List<SpecValueVo>> getSkuValuesById(Set<String> skuId) {
|
|
|
- List<ShopSkuSpecValue> shopSkuSpecValues = shopSkuSpecValueService.listByIds(skuId);
|
|
|
- //规格值ID
|
|
|
- Set<Long> collect1 = shopSkuSpecValues.stream().map(ShopSkuSpecValue::getSpecValueId).collect(Collectors.toSet());
|
|
|
- //规格值对象
|
|
|
- List<ShopSpecValue> shopSpecValues = shopSpecValueService.listByIds(collect1);
|
|
|
- //规格ID
|
|
|
- Set<Long> collect2 = shopSpecValues.stream().map(ShopSpecValue::getSpecId).collect(Collectors.toSet());
|
|
|
- //规格对象
|
|
|
- List<ShopSpec> shopSpecs = shopSpecService.listByIds(collect2);
|
|
|
- HashMap<String, ShopSpec> specs = new HashMap<>();
|
|
|
- for (ShopSpec shopSpec : shopSpecs) {
|
|
|
- specs.put(shopSpec.getId().toString(),shopSpec);
|
|
|
- }
|
|
|
- HashMap<String, List<SpecValueVo>> map = new HashMap<>();
|
|
|
- for (String s : skuId) {
|
|
|
- ArrayList<SpecValueVo> list = new ArrayList<>();
|
|
|
- //当前sku拥有的规格值Ids
|
|
|
- List<String> collect = shopSkuSpecValues.stream().filter(item -> item.getSkuId().toString().equals(s)).map(item -> item.getSpecValueId().toString()).collect(Collectors.toList());
|
|
|
- List<ShopSpecValue> collect3 = shopSpecValues.stream().filter(item -> collect.contains(item.getId().toString())).collect(Collectors.toList());
|
|
|
- for (ShopSpecValue string : collect3) {
|
|
|
- SpecValueVo specValueVo = new SpecValueVo();
|
|
|
- specValueVo.setValueId(string.getId().toString());
|
|
|
- specValueVo.setValue(string.getSpecValue());
|
|
|
- specValueVo.setKeyId(string.getSpecId().toString());
|
|
|
- ShopSpec shopSpec1 = specs.get(string.getSpecId().toString());
|
|
|
- specValueVo.setKey(shopSpec1.getSpecName());
|
|
|
- list.add(specValueVo);
|
|
|
- }
|
|
|
- map.put(s,list);
|
|
|
- }
|
|
|
- return map;
|
|
|
+ public Map<String,List<SpecVo>> getSkuValuesById(Set<String> skuId) {
|
|
|
+ List<SpecVo> list=shopProductSkuMapper.getSkuValuesById(skuId);
|
|
|
+ return list.stream().collect(Collectors.groupingBy(SpecVo::getSkuId));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -69,25 +48,16 @@ public class ShopProductSkuServiceImpl extends ServiceImpl<ShopProductSkuMapper,
|
|
|
* @return {@link Map }<{@link String },{@link SpecValueVo }>
|
|
|
*/
|
|
|
@Override
|
|
|
- public Map<String,List<SpecValueVo>> getShopProductSkuId(Set<String> shopProductSkuIds) {
|
|
|
- List<ShopProductSku> shopProductSkus = shopProductSkuService.listByIds(shopProductSkuIds);
|
|
|
- //sku ids
|
|
|
- Set<String> collect = shopProductSkus.stream().map(item->item.getSkuId().toString()).collect(Collectors.toSet());
|
|
|
- //shopProductSkuIds ->sku
|
|
|
- HashMap<String, String> stringStringHashMap = new HashMap<>();
|
|
|
- for (ShopProductSku productSkus : shopProductSkus) {
|
|
|
- stringStringHashMap.put(productSkus.getId().toString(),productSkus.getSkuId().toString());
|
|
|
- }
|
|
|
-
|
|
|
- Map<String, List<SpecValueVo>> map = getSkuValuesById(collect);
|
|
|
-
|
|
|
- HashMap<String, List<SpecValueVo>> result = new HashMap<>();
|
|
|
- for (String shopProductSkuId : shopProductSkuIds) {
|
|
|
- String skuId = stringStringHashMap.get(shopProductSkuId);
|
|
|
- List<SpecValueVo> specValueVos = map.get(skuId);
|
|
|
- result.put(shopProductSkuId,specValueVos);
|
|
|
- }
|
|
|
-
|
|
|
- return result;
|
|
|
+ public Map<String,List<SortSpecVo>> getShopProductSkuId(Set<String> shopProductSkuIds) {
|
|
|
+ List<SortSpecVo> list=shopProductSkuMapper.getValuesByProductIds(shopProductSkuIds);
|
|
|
+ Map<String, List<SortSpecVo>> collect = list.stream().collect(Collectors.groupingBy(SortSpecVo::getSkuId));
|
|
|
+
|
|
|
+ collect.forEach((k,v)->
|
|
|
+ {
|
|
|
+ List<SortSpecVo> collect1 = v.stream().sorted(Comparator.comparing(SortSpecVo::getSpecOrder)
|
|
|
+ .thenComparing(SortSpecVo::getValueSort)).collect(Collectors.toList());
|
|
|
+ collect.put(k,collect1);
|
|
|
+ });
|
|
|
+ return collect;
|
|
|
}
|
|
|
}
|