Browse Source

add code and name order goods

huodongdong 7 years ago
parent
commit
b1908c474c

+ 5 - 0
rankin-cms-web/src/main/java/cn/rankin/cmsweb/service/product/ProductService.java

@@ -6,6 +6,7 @@ import cn.rankin.common.utils.enums.ProductTypeEnum;
 import cn.rankin.data.api.product.dto.CourseDTO;
 import cn.rankin.data.api.product.dto.PackageDTO;
 import cn.rankin.data.api.product.dto.SupportDTO;
+import cn.rankin.data.api.product.entity.Product;
 import cn.rankin.data.api.product.vo.CourseVo;
 import cn.rankin.data.api.product.vo.PackageVo;
 import cn.rankin.data.api.product.vo.ProductVo;
@@ -13,6 +14,7 @@ import cn.rankin.data.api.product.vo.SupportVo;
 import org.springframework.cloud.netflix.feign.FeignClient;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.List;
 import java.util.Map;
 
 @FeignClient(name = "${service.product.name}")
@@ -44,4 +46,7 @@ public interface ProductService {
 
     @RequestMapping(value = "/product/{id}", method = RequestMethod.DELETE)
     APIResult delete(@PathVariable("id") String id);
+
+    @RequestMapping(value = "/product/ids", method = RequestMethod.GET)
+    APIResult<List<ProductVo>> findProductByIds(@RequestParam("id") List<String> ids);
 }

+ 34 - 1
rankin-cms-web/src/main/java/cn/rankin/cmsweb/service/trade/order/OrderService.java

@@ -2,6 +2,7 @@ package cn.rankin.cmsweb.service.trade.order;
 
 import cn.rankin.cmsweb.code.CmsWebAPICode;
 import cn.rankin.cmsweb.service.product.GoodsService;
+import cn.rankin.cmsweb.service.product.ProductService;
 import cn.rankin.cmsweb.service.user.CampusService;
 import cn.rankin.cmsweb.service.user.MerchantService;
 import cn.rankin.cmsweb.service.user.TerminalUserService;
@@ -16,6 +17,7 @@ import cn.rankin.data.api.cms.OrderSearchWebDTO;
 import cn.rankin.data.api.cms.OrderSnapshotWebSearchDTO;
 import cn.rankin.data.api.product.entity.Goods;
 import cn.rankin.data.api.product.vo.GoodsVo;
+import cn.rankin.data.api.product.vo.ProductVo;
 import cn.rankin.data.api.trade.dto.OrderDTO;
 import cn.rankin.data.api.trade.dto.OrderDetailSearchDTO;
 import cn.rankin.data.api.trade.dto.OrderGoodsDTO;
@@ -31,6 +33,7 @@ import cn.rankin.data.api.user.dto.CampusSearchDTO;
 import cn.rankin.data.api.user.dto.PayDTO;
 import cn.rankin.data.api.user.vo.CampusVo;
 import cn.rankin.data.api.user.vo.TerminalUserVo;
+import com.sun.tools.hat.internal.model.HackJavaValue;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -68,6 +71,9 @@ public class OrderService {
     @Autowired
     private MerchantService merchantService;
 
+    @Autowired
+    private ProductService productService;
+
     // 支付
     public APIResult<Boolean> pay(String orderId) {
         APIResult<Order> userOrderAPIResult = orderClient.getOrder(orderId);
@@ -268,14 +274,34 @@ public class OrderService {
     }
 
     public List<OrderGoodsVo> toOrderGoodsVo(List<OrderGoods> orderGoodsList) {
+        if (CollectionUtils.isEmpty(orderGoodsList)) {
+            return new ArrayList<>();
+        }
         List<String> goodsIdList = new ArrayList<>();
-        orderGoodsList.forEach(orderGoods -> goodsIdList.add(orderGoods.getGoodsId()));
+        List<String> productIdList = new ArrayList<>();
+        orderGoodsList.forEach(orderGoods -> {
+            goodsIdList.add(orderGoods.getGoodsId());
+            productIdList.add(orderGoods.getPid());
+        });
+
         APIResult<List<GoodsVo>> goodsAPIResult = goodsService.findByIds(goodsIdList);
         if (!goodsAPIResult.getSuccess()) {
             log.error("goods api error: {}", goodsAPIResult.getMessage());
             return null;
         }
 
+        APIResult<List<ProductVo>> productAPIResult = productService.findProductByIds(productIdList);
+        if (!productAPIResult.getSuccess()) {
+            log.error("product api error: {}", productAPIResult.getMessage());
+            return null;
+        }
+
+        List<ProductVo> productVoList = productAPIResult.getData();
+        Map<String, ProductVo> productVoMap = new HashMap<>();
+        for (ProductVo productVo : productVoList) {
+            productVoMap.put(productVo.getPid(), productVo);
+        }
+
         List<GoodsVo> goodsVoList = goodsAPIResult.getData();
         Map<String, GoodsVo> goodsVoMap = new HashMap<>();
         for (GoodsVo goodsVo : goodsVoList) {
@@ -285,6 +311,7 @@ public class OrderService {
         List<OrderGoodsVo> orderGoodsVoList = new ArrayList<>();
         for (OrderGoods orderGoods : orderGoodsList) {
             String goodsId = orderGoods.getGoodsId();
+            String productId = orderGoods.getPid();
 
             OrderGoodsVo orderGoodsVo = new OrderGoodsVo();
             BeanUtils.copyProperties(orderGoods, orderGoodsVo);
@@ -297,6 +324,12 @@ public class OrderService {
             BeanUtils.copyProperties(goodsVo, orderGoodsVo);
             goodsVo.setId(orderGoods.getId());
 
+            ProductVo productVo = productVoMap.get(productId);
+            if (productVo != null) {
+                orderGoodsVo.setName(productVo.getName());
+                orderGoodsVo.setCode(productVo.getCode());
+            }
+
             orderGoodsVoList.add(orderGoodsVo);
         }
         return orderGoodsVoList;

+ 4 - 0
rankin-data-api/src/main/java/cn/rankin/data/api/trade/vo/OrderGoodsVo.java

@@ -18,6 +18,10 @@ public class OrderGoodsVo implements Serializable {
 
     private String pid;
 
+    private String name;
+
+    private String code;
+
     private ProductTypeEnum type;
 
     private String merchantId;