|
@@ -15,6 +15,7 @@ import cn.rankin.data.api.product.vo.SupportItemVo;
|
|
|
import cn.rankin.data.api.product.vo.TrainingItemVo;
|
|
|
import cn.rankin.productservice.repository.*;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -168,7 +169,7 @@ public class ItemService {
|
|
|
}
|
|
|
List<String> productIdList = new ArrayList<>();
|
|
|
relationList.forEach(relation -> productIdList.add(relation.getSupportId()));
|
|
|
- List<ItemVo> itemVoList = this.findByIds(merchantId, productIdList);
|
|
|
+ List<ItemVo> itemVoList = this.findByPids(merchantId, productIdList);
|
|
|
return itemVoList;
|
|
|
}
|
|
|
|
|
@@ -188,7 +189,76 @@ public class ItemService {
|
|
|
*/
|
|
|
|
|
|
|
|
|
- public List<ItemVo> findByIds(String merchantId, List<String> productIdList) {
|
|
|
+ public ItemVo findByPid(String merchantId, String pid) {
|
|
|
+ if (StringUtils.isBlank(pid)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ MerchantProduct merchantProduct = merchantProductRepository.findByPidAndMerchantId(pid, merchantId);
|
|
|
+
|
|
|
+ if(null == merchantProduct){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ // 拿产品信息
|
|
|
+ Map<String, ItemVo> itemVoMap = new HashMap<>();
|
|
|
+ ProductTypeEnum type = merchantProduct.getType();
|
|
|
+ if (type.equals(ProductTypeEnum.COURSE)) {
|
|
|
+ Course course = courseRepository.find(pid);
|
|
|
+ ItemVo itemVo = convert(course);
|
|
|
+ itemVoMap.put(pid, itemVo);
|
|
|
+ } else if (type.equals(ProductTypeEnum.SUPPORT)) {
|
|
|
+ Support support = supportRepository.find(pid);
|
|
|
+ ItemVo itemVo = convert(support);
|
|
|
+ itemVoMap.put(pid, itemVo);
|
|
|
+ } else if (type.equals(ProductTypeEnum.TRAINING)){
|
|
|
+ Training training = trainingRepository.find(pid);
|
|
|
+ ItemVo itemVo = convert(training);
|
|
|
+ itemVoMap.put(pid, itemVo);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 取商品信息
|
|
|
+ List<Goods> goodsList = goodsRepository.findByPidAndMerchantId(pid, merchantId);
|
|
|
+ Map<String, List<Goods>> goodsMap = new HashMap<>();
|
|
|
+ for (Goods goods : goodsList) {
|
|
|
+ String productId = goods.getPid();
|
|
|
+ if (!goodsMap.containsKey(productId)) {
|
|
|
+ List<Goods> tmpList = new ArrayList<>();
|
|
|
+ tmpList.add(goods);
|
|
|
+ goodsMap.put(productId, tmpList);
|
|
|
+ }else {
|
|
|
+ List<Goods> tmpList = goodsMap.get(productId);
|
|
|
+ tmpList.add(goods);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 开始组装返回数据了啊
|
|
|
+ ItemVo itemVo = itemVoMap.get(pid);
|
|
|
+ if (itemVo == null) {
|
|
|
+ log.error("item not exists, pid={}", pid);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ List<Goods> tmpList = goodsMap.get(pid);
|
|
|
+ List<ItemGoodsVo> itemGoodsVoList = new ArrayList<>();
|
|
|
+ if (null == tmpList){
|
|
|
+ log.error("productId not Found in goodsMap, pid={}", pid);
|
|
|
+ }else{
|
|
|
+ tmpList.sort(new Comparator<Goods>() {
|
|
|
+ @Override
|
|
|
+ public int compare(Goods o1, Goods o2) {
|
|
|
+ return o1.getSort() - o2.getSort();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ for (Goods goods : tmpList) {
|
|
|
+ ItemGoodsVo itemGoodsVo = convert(goods);
|
|
|
+ itemGoodsVoList.add(itemGoodsVo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ itemVo.setGoods(itemGoodsVoList);
|
|
|
+
|
|
|
+ return itemVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<ItemVo> findByPids(String merchantId, List<String> productIdList) {
|
|
|
if (CollectionUtils.isEmpty(productIdList)) {
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
@@ -302,7 +372,7 @@ public class ItemService {
|
|
|
currentIdList.add(productId);
|
|
|
}
|
|
|
|
|
|
- List<ItemVo> itemVoList = findByIds(merchantId, currentIdList);
|
|
|
+ List<ItemVo> itemVoList = findByPids(merchantId, currentIdList);
|
|
|
page.setList(itemVoList);
|
|
|
return APIResult.ok(page);
|
|
|
}
|
|
@@ -329,7 +399,7 @@ public class ItemService {
|
|
|
String productId = merchantProductTagRelation.getPid();
|
|
|
productIdList.add(productId);
|
|
|
}
|
|
|
- List<ItemVo> itemVoList = this.findByIds(merchantId, productIdList);
|
|
|
+ List<ItemVo> itemVoList = this.findByPids(merchantId, productIdList);
|
|
|
page.setList(itemVoList);
|
|
|
return APIResult.ok(page);
|
|
|
}
|
|
@@ -357,7 +427,7 @@ public class ItemService {
|
|
|
String productId = merchantProductTagRelation.getPid();
|
|
|
productIdList.add(productId);
|
|
|
}
|
|
|
- result = this.findByIds(merchantId, productIdList);
|
|
|
+ result = this.findByPids(merchantId, productIdList);
|
|
|
return result;
|
|
|
}
|
|
|
|