diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java index 75c3c77..b31672d 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java @@ -3,18 +3,15 @@ package com.chaozhanggui.system.cashierservice.controller; import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson.JSONObject; import com.chaozhanggui.system.cashierservice.annotation.LimitSubmit; -import com.chaozhanggui.system.cashierservice.entity.TbShopTable; -import com.chaozhanggui.system.cashierservice.entity.dto.OrderDto; +import com.chaozhanggui.system.cashierservice.redis.RedisCst; import com.chaozhanggui.system.cashierservice.service.CartService; import com.chaozhanggui.system.cashierservice.service.OrderService; import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.util.Utils; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.web.bind.annotation.*; -import javax.annotation.Resource; import java.io.IOException; import java.text.ParseException; import java.util.Map; @@ -25,24 +22,23 @@ import java.util.Map; @RequestMapping("/order") public class OrderController { - @Resource - private OrderService orderService; + private final OrderService orderService; private final CartService cartService; - @Autowired - private StringRedisTemplate stringRedisTemplate; + private final StringRedisTemplate stringRedisTemplate; - public OrderController(CartService cartService) { + public OrderController(OrderService orderService, CartService cartService, StringRedisTemplate stringRedisTemplate) { + this.orderService = orderService; this.cartService = cartService; + this.stringRedisTemplate = stringRedisTemplate; } /** * 添加订单 * @return */ - @LimitSubmit(key = "memeberIn:%s") @PostMapping("/creatOrder") public Result createOrder(@RequestBody JSONObject jsonObject){ - return cartService.createOrder(jsonObject); + return Utils.runFunAndCheckKey(() -> cartService.createOrder(jsonObject), stringRedisTemplate, RedisCst.getLockKey("CREATE_ORDER_KEY")); // return orderService.createOrder(shopTable.getTableId(),shopTable.getShopId(),shopTable.getUserId()); }