From 4bc382582d4f3f6f687f71fc4dafa934cd6dbe01 Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Sun, 29 Sep 2024 17:34:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=88=9B=E5=BB=BA=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=20=E5=88=87=E6=8D=A2=E5=B0=B1=E9=A4=90=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/OrderController.java | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) 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()); }