再来一单
This commit is contained in:
parent
948ab55cd4
commit
38d61ee91a
|
@ -107,4 +107,17 @@ public class OrderController {
|
|||
orderService.userCancelById(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 再来一单
|
||||
*
|
||||
* @param id 订单id
|
||||
* @return Result
|
||||
*/
|
||||
@ApiOperation("再来一单")
|
||||
@PostMapping("/repetition/{id}")
|
||||
public Result<String> repetition(@PathVariable Long id) {
|
||||
orderService.repetition(id);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,4 +42,11 @@ public interface ShoppingCartMapper {
|
|||
* @param id 购物车中id
|
||||
*/
|
||||
void deleteById(Long id);
|
||||
|
||||
/**
|
||||
* 将购物车对象批量添加到数据库
|
||||
*
|
||||
* @param shoppingCartList List<ShoppingCart>
|
||||
*/
|
||||
void insertBatch(List<ShoppingCart> shoppingCartList);
|
||||
}
|
||||
|
|
|
@ -62,4 +62,11 @@ public interface OrderService {
|
|||
* @param id 订单id
|
||||
*/
|
||||
void userCancelById(Long id);
|
||||
|
||||
/**
|
||||
* 再来一单
|
||||
*
|
||||
* @param id 订单id
|
||||
*/
|
||||
void repetition(Long id);
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ import java.util.ArrayList;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
|
@ -270,6 +271,33 @@ public class OrderServiceImpl implements OrderService {
|
|||
orders.setCancelTime(LocalDateTime.now());
|
||||
orderMapper.update(orders);
|
||||
}
|
||||
|
||||
/**
|
||||
* 再来一单
|
||||
*
|
||||
* @param id 订单id
|
||||
*/
|
||||
@Override
|
||||
public void repetition(Long id) {
|
||||
// 查询当前用户id
|
||||
Long userId = BaseContext.getCurrentId();
|
||||
// 根据订单id查询当前订单详情
|
||||
List<OrderDetail> orderDetailList = orderDetailMapper.getByOrderId(id);
|
||||
// 将订单详情对象转换为购物车对象
|
||||
List<ShoppingCart> shoppingCartList = orderDetailList.stream().map(x -> {
|
||||
ShoppingCart shoppingCart = new ShoppingCart();
|
||||
|
||||
// 将原订单详情里面的菜品信息重新复制到购物车对象中
|
||||
BeanUtils.copyProperties(x, shoppingCart, "id");
|
||||
shoppingCart.setUserId(userId);
|
||||
shoppingCart.setCreateTime(LocalDateTime.now());
|
||||
|
||||
return shoppingCart;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
// 将购物车对象批量添加到数据库
|
||||
shoppingCartMapper.insertBatch(shoppingCartList);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -9,6 +9,16 @@
|
|||
#{createTime});
|
||||
</insert>
|
||||
|
||||
<!-- 将购物车对象批量添加到数据库 -->
|
||||
<insert id="insertBatch" parameterType="list">
|
||||
insert into shopping_cart
|
||||
(name, image, user_id, dish_id, setmeal_id, dish_flavor, number, amount, create_time)
|
||||
values
|
||||
<foreach collection="shoppingCartList" item="sc" separator=",">
|
||||
(#{sc.name},#{sc.image},#{sc.userId},#{sc.dishId},#{sc.setmealId},#{sc.dishFlavor},#{sc.number},#{sc.amount},#{sc.createTime})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<!-- 如果已经存在,只需要将数量+1即可-修改商品数量 -->
|
||||
<update id="updateNumberById">
|
||||
update shopping_cart
|
||||
|
|
Loading…
Reference in New Issue