test_class.declarator: orderService
test_class.modifier: @Autowired
      private
test_class.original_string: @Autowired
      private OrderServiceImpl orderService;
test_class.type: OrderServiceImpl
test_class.var_name: orderService
test_class.declarator: BUYER_OPENID = "abc123"
test_class.modifier: private final
test_class.original_string: private final String BUYER_OPENID = "abc123";
test_class.type: String
test_class.var_name: BUYER_OPENID
test_class.declarator: ORDER_ID = "1569052543479819643"
test_class.modifier: private final
test_class.original_string: private final String ORDER_ID = "1569052543479819643";
test_class.type: String
test_class.var_name: ORDER_ID
test_class.file: wechat_order_h/src/test/java/com/hhh/wechat_order/service/impl/OrderServiceImplTest.java
test_class.identifier: OrderServiceImplTest
test_case.body: @Test
      public void create() {
          OrderDTO orderDTO = new OrderDTO();
          orderDTO.setBuyerName("小芳");
          orderDTO.setBuyerAddress("嘉应学院");
          orderDTO.setBuyerPhone("12345678910");
          orderDTO.setBuyerOpenid(BUYER_OPENID);
          //购物车
          List<OrderDetail> orderDetailList = new ArrayList<>();
          OrderDetail o1 = new OrderDetail();
          o1.setProductId("123456");
          o1.setProductQuantity(1);
          orderDetailList.add(o1);
  
          OrderDetail o2 = new OrderDetail();
          o2.setProductId("111");
          o2.setProductQuantity(1);
          orderDetailList.add(o2);
  
          //错误测试，商品不存在的测试
  //        OrderDetail o1 = new OrderDetail();
  //        o1.setProductId("123");
  //        o1.setProductQuantity(2);
  //        orderDetailList.add(o1);
  
          orderDTO.setOrderDetailList(orderDetailList);
          OrderDTO result = orderService.create(orderDTO);
          log.info("【创建订单】 result={}",result);
          Assert.assertNotNull(result);
      }
test_case.class_method_signature: OrderServiceImplTest.create()
test_case.full_signature: @Test public void create()
test_case.identifier: create
test_case.invocations: setBuyerName setBuyerAddress setBuyerPhone setBuyerOpenid setProductId setProductQuantity add setProductId setProductQuantity add setOrderDetailList create info assertNotNull
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void create()
focal_class.declarator: productService
focal_class.modifier: @Autowired
      private
focal_class.original_string: @Autowired
      private ProductService productService;
focal_class.type: ProductService
focal_class.var_name: productService
focal_class.declarator: orderDetailRepository
focal_class.modifier: @Autowired
      private
focal_class.original_string: @Autowired
      private OrderDetailRepository orderDetailRepository;
focal_class.type: OrderDetailRepository
focal_class.var_name: orderDetailRepository
focal_class.declarator: orderMasterRepository
focal_class.modifier: @Autowired
      private
focal_class.original_string: @Autowired
      private OrderMasterRepository orderMasterRepository;
focal_class.type: OrderMasterRepository
focal_class.var_name: orderMasterRepository
focal_class.declarator: payService
focal_class.modifier: @Autowired
      private
focal_class.original_string: @Autowired
      private PayService payService;
focal_class.type: PayService
focal_class.var_name: payService
focal_class.declarator: webSocket
focal_class.modifier: @Autowired
      private
focal_class.original_string: @Autowired
      private WebSocket webSocket;
focal_class.type: WebSocket
focal_class.var_name: webSocket
focal_class.file: wechat_order_h/src/main/java/com/hhh/wechat_order/service/impl/OrderServiceImpl.java
focal_class.identifier: OrderServiceImpl
focal_class.interfaces: implements OrderService
focal_class.class_method_signature: OrderServiceImpl.create(OrderDTO orderDTO)
focal_class.full_signature: @Override @Transactional public OrderDTO create(OrderDTO orderDTO)
focal_class.identifier: create
focal_class.modifiers: @Override @Transactional public
focal_class.parameters: (OrderDTO orderDTO)
focal_class.return: OrderDTO
focal_class.signature: OrderDTO create(OrderDTO orderDTO)
focal_class.class_method_signature: OrderServiceImpl.findOne(String orderId)
focal_class.full_signature: @Override public OrderDTO findOne(String orderId)
focal_class.identifier: findOne
focal_class.modifiers: @Override public
focal_class.parameters: (String orderId)
focal_class.return: OrderDTO
focal_class.signature: OrderDTO findOne(String orderId)
focal_class.class_method_signature: OrderServiceImpl.findList(String buyerOpenid, Pageable pageable)
focal_class.full_signature: @Override public Page<OrderDTO> findList(String buyerOpenid, Pageable pageable)
focal_class.identifier: findList
focal_class.modifiers: @Override public
focal_class.parameters: (String buyerOpenid, Pageable pageable)
focal_class.return: Page<OrderDTO>
focal_class.signature: Page<OrderDTO> findList(String buyerOpenid, Pageable pageable)
focal_class.class_method_signature: OrderServiceImpl.findList(Pageable pageable)
focal_class.full_signature: @Override public Page<OrderDTO> findList(Pageable pageable)
focal_class.identifier: findList
focal_class.modifiers: @Override public
focal_class.parameters: (Pageable pageable)
focal_class.return: Page<OrderDTO>
focal_class.signature: Page<OrderDTO> findList(Pageable pageable)
focal_class.class_method_signature: OrderServiceImpl.findOrderMastersByCreateTimeDesc(Pageable pageable)
focal_class.full_signature: @Override public Page<OrderDTO> findOrderMastersByCreateTimeDesc(Pageable pageable)
focal_class.identifier: findOrderMastersByCreateTimeDesc
focal_class.modifiers: @Override public
focal_class.parameters: (Pageable pageable)
focal_class.return: Page<OrderDTO>
focal_class.signature: Page<OrderDTO> findOrderMastersByCreateTimeDesc(Pageable pageable)
focal_class.class_method_signature: OrderServiceImpl.findListStats(String buyerOpenid, Integer orderStatus)
focal_class.full_signature: @Override public List<OrderDTO> findListStats(String buyerOpenid, Integer orderStatus)
focal_class.identifier: findListStats
focal_class.modifiers: @Override public
focal_class.parameters: (String buyerOpenid, Integer orderStatus)
focal_class.return: List<OrderDTO>
focal_class.signature: List<OrderDTO> findListStats(String buyerOpenid, Integer orderStatus)
focal_class.class_method_signature: OrderServiceImpl.cancel(OrderDTO orderDTO)
focal_class.full_signature: @Override @Transactional public OrderDTO cancel(OrderDTO orderDTO)
focal_class.identifier: cancel
focal_class.modifiers: @Override @Transactional public
focal_class.parameters: (OrderDTO orderDTO)
focal_class.return: OrderDTO
focal_class.signature: OrderDTO cancel(OrderDTO orderDTO)
focal_class.class_method_signature: OrderServiceImpl.finish(OrderDTO orderDTO)
focal_class.full_signature: @Override @Transactional public OrderDTO finish(OrderDTO orderDTO)
focal_class.identifier: finish
focal_class.modifiers: @Override @Transactional public
focal_class.parameters: (OrderDTO orderDTO)
focal_class.return: OrderDTO
focal_class.signature: OrderDTO finish(OrderDTO orderDTO)
focal_class.class_method_signature: OrderServiceImpl.paid(OrderDTO orderDTO)
focal_class.full_signature: @Override @Transactional public OrderDTO paid(OrderDTO orderDTO)
focal_class.identifier: paid
focal_class.modifiers: @Override @Transactional public
focal_class.parameters: (OrderDTO orderDTO)
focal_class.return: OrderDTO
focal_class.signature: OrderDTO paid(OrderDTO orderDTO)
focal_method.body: @Override
      @Transactional
      public OrderDTO create(OrderDTO orderDTO) {
  
          String orderId = KeyUtil.genUniqueKey();
          BigDecimal orderAmount = new BigDecimal(BigInteger.ZERO);
          
          //查询商品(数量 ， 价格)
          for(OrderDetail orderDetail : orderDTO.getOrderDetailList()){
              Optional<ProductInfo> productInfo = productService.findById(orderDetail.getProductId());
              if(!productInfo.isPresent() ){
                  throw new SellException(ResultEnum.PRODUCT_NOT_EXIST);
              }
  
              //计算订单总价
              orderAmount = productInfo.get().getProductPrice()
                      .multiply(new BigDecimal(orderDetail.getProductQuantity()))
                      .add(orderAmount);
  
              //写入订单数据库(orderDetail)
              orderDetail.setDetailId(KeyUtil.genUniqueKey());
              orderDetail.setOrderId(orderId);
              BeanUtils.copyProperties(productInfo.get() , orderDetail);
              orderDetailRepository.save(orderDetail);
  
          }
  
          //写入订单数据库(orderMaster)
          OrderMaster orderMaster = new OrderMaster();
          orderDTO.setOrderId(orderId);
          BeanUtils.copyProperties(orderDTO , orderMaster);
          orderMaster.setOrderAmount(orderAmount);
          orderMaster.setOrderStatus(OrderStatusEnum.NEW_PAYED.getCode());
          orderMaster.setPayStatus(PayStatusEnum.SUCCESS.getCode());
          orderMasterRepository.save(orderMaster);
  
          //减库存
          List<CartDTO> cartDTOList = orderDTO.getOrderDetailList().stream().map(e ->
                  new CartDTO(e.getProductId() , e.getProductQuantity()))
                  .collect(Collectors.toList());
          productService.decreaseStock(cartDTOList);
  
          //发送websocket消息
          webSocket.sendMessage(orderDTO.getOrderId());
          
          return orderDTO;
      }
focal_method.class_method_signature: OrderServiceImpl.create(OrderDTO orderDTO)
focal_method.full_signature: @Override @Transactional public OrderDTO create(OrderDTO orderDTO)
focal_method.identifier: create
focal_method.invocations: genUniqueKey getOrderDetailList findById getProductId isPresent add multiply getProductPrice get getProductQuantity setDetailId genUniqueKey setOrderId copyProperties get save setOrderId copyProperties setOrderAmount setOrderStatus getCode setPayStatus getCode save collect map stream getOrderDetailList getProductId getProductQuantity toList decreaseStock sendMessage getOrderId
focal_method.modifiers: @Override @Transactional public
focal_method.parameters: (OrderDTO orderDTO)
focal_method.return: OrderDTO
focal_method.signature: OrderDTO create(OrderDTO orderDTO)