新增创建订单 切换就餐模式接口

This commit is contained in:
2024-09-29 15:45:48 +08:00
parent 70ad132780
commit 095773f62a
6 changed files with 87 additions and 31 deletions

View File

@@ -1,14 +1,17 @@
package com.chaozhanggui.system.cashierservice.controller;
import cn.hutool.core.util.ObjectUtil;
import com.chaozhanggui.system.cashierservice.entity.TbShopTable;
import com.chaozhanggui.system.cashierservice.entity.dto.OrderDto;
import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.annotation.LimitSubmit;
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.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;
@@ -19,19 +22,24 @@ import java.util.Map;
@RequestMapping("/order")
public class OrderController {
@Resource
private OrderService orderService;
private final OrderService orderService;
private final CartService cartService;
private final StringRedisTemplate stringRedisTemplate;
public OrderController(OrderService orderService, CartService cartService, StringRedisTemplate stringRedisTemplate) {
this.orderService = orderService;
this.cartService = cartService;
this.stringRedisTemplate = stringRedisTemplate;
}
/**
* 添加订单
* @return
*/
@PostMapping("/creatOrder")
public Result createOrder(@RequestBody OrderDto shopTable){
if (shopTable.getTableId() == null){
return Result.fail("台桌号有误");
}
return orderService.createOrder(shopTable.getTableId(),shopTable.getShopId(),shopTable.getUserId());
public Result createOrder(@RequestBody JSONObject jsonObject){
return Utils.runFunAndCheckKey(() -> cartService.createOrder(jsonObject), stringRedisTemplate, RedisCst.getLockKey("CREATE_ORDER_KEY"));
// return orderService.createOrder(shopTable.getTableId(),shopTable.getShopId(),shopTable.getUserId());
}
/**

View File

@@ -4,6 +4,7 @@ package com.chaozhanggui.system.cashierservice.controller;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.entity.TbCashierCart;
import com.chaozhanggui.system.cashierservice.entity.dto.ChoseCountDTO;
import com.chaozhanggui.system.cashierservice.entity.dto.ChoseEatModelDTO;
import com.chaozhanggui.system.cashierservice.entity.dto.QuerySpecDTO;
@@ -16,6 +17,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@CrossOrigin(origins = "*")
@@ -107,17 +111,21 @@ public class ProductController {
* @return 餐位费信息
*/
@PostMapping("/choseCount")
public Result choseCount(
@Validated @RequestBody ChoseCountDTO choseCountDTO
) {
public Result choseCount(@Validated @RequestBody ChoseCountDTO choseCountDTO) {
return Result.success(CodeEnum.SUCCESS, productService.choseCount(choseCountDTO));
}
@PostMapping("/choseEatModel")
public Result choseEatModel(
@Validated @RequestBody ChoseEatModelDTO choseEatModelDTO
) {
return Result.success(CodeEnum.SUCCESS, productService.choseEatModel(choseEatModelDTO));
public Result choseEatModel(@Validated @RequestBody ChoseEatModelDTO choseEatModelDTO) {
List<TbCashierCart> cashierCartList = cartService.choseEatModel(choseEatModelDTO);
BigDecimal amount = BigDecimal.ZERO;
for (TbCashierCart item : cashierCartList) {
amount = amount.add(item.getTotalAmount());
}
HashMap<String, Object> data = new HashMap<>();
data.put("amount", amount);
data.put("info", cashierCartList);
return Result.success(CodeEnum.SUCCESS, data);
}
@PostMapping("cleanCart")