/**
* 再来一单
* @param orders
* @return
*/
@PostMapping("/again")
public R<String> again(@RequestBody Orders orders){
//通过orderId查询具体订单明细
Long orderId = orders.getId();
Orders order = orderService.getById(orderId);
Long userId = order.getUserId();
LambdaQueryWrapper<OrderDetail> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(OrderDetail::getOrderId, orderId);
List<OrderDetail> details = orderDetailService.list(queryWrapper);
//将订单明细加入购物车
List<ShoppingCart> shoppingCarts = details.stream().map((item) -> {
ShoppingCart shoppingCart = new ShoppingCart();
BeanUtils.copyProperties(item, shoppingCart, "id");
shoppingCart.setUserId(userId);
shoppingCart.setCreateTime(LocalDateTime.now());
return shoppingCart;
}).collect(Collectors.toList());
shoppingCartService.saveBatch(shoppingCarts);
return R.success("再来一单");
}
标签:再来,orderId,return,queryWrapper,shoppingCart,一单,orders From: https://www.cnblogs.com/fxzm/p/17241720.html