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

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

View File

@@ -1,8 +1,10 @@
package com.chaozhanggui.system.cashierservice.controller; package com.chaozhanggui.system.cashierservice.controller;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.entity.TbShopTable; import com.chaozhanggui.system.cashierservice.entity.TbShopTable;
import com.chaozhanggui.system.cashierservice.entity.dto.OrderDto; import com.chaozhanggui.system.cashierservice.entity.dto.OrderDto;
import com.chaozhanggui.system.cashierservice.service.CartService;
import com.chaozhanggui.system.cashierservice.service.OrderService; import com.chaozhanggui.system.cashierservice.service.OrderService;
import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.sign.Result;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@@ -21,17 +23,20 @@ public class OrderController {
@Resource @Resource
private OrderService orderService; private OrderService orderService;
private final CartService cartService;
public OrderController(CartService cartService) {
this.cartService = cartService;
}
/** /**
* 添加订单 * 添加订单
* @return * @return
*/ */
@PostMapping("/creatOrder") @PostMapping("/creatOrder")
public Result createOrder(@RequestBody OrderDto shopTable){ public Result createOrder(@RequestBody JSONObject jsonObject){
if (shopTable.getTableId() == null){ return cartService.createOrder(jsonObject);
return Result.fail("台桌号有误"); // return orderService.createOrder(shopTable.getTableId(),shopTable.getShopId(),shopTable.getUserId());
}
return orderService.createOrder(shopTable.getTableId(),shopTable.getShopId(),shopTable.getUserId());
} }
/** /**

View File

@@ -107,17 +107,13 @@ public class ProductController {
* @return 餐位费信息 * @return 餐位费信息
*/ */
@PostMapping("/choseCount") @PostMapping("/choseCount")
public Result choseCount( public Result choseCount(@Validated @RequestBody ChoseCountDTO choseCountDTO) {
@Validated @RequestBody ChoseCountDTO choseCountDTO
) {
return Result.success(CodeEnum.SUCCESS, productService.choseCount(choseCountDTO)); return Result.success(CodeEnum.SUCCESS, productService.choseCount(choseCountDTO));
} }
@PostMapping("/choseEatModel") @PutMapping("/choseEatModel")
public Result choseEatModel( public Result choseEatModel(@Validated @RequestBody ChoseEatModelDTO choseEatModelDTO) {
@Validated @RequestBody ChoseEatModelDTO choseEatModelDTO return Result.success(CodeEnum.SUCCESS, cartService.choseEatModel(choseEatModelDTO));
) {
return Result.success(CodeEnum.SUCCESS, productService.choseEatModel(choseEatModelDTO));
} }
@PostMapping("cleanCart") @PostMapping("cleanCart")

View File

@@ -2,6 +2,7 @@ package com.chaozhanggui.system.cashierservice.entity.dto;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min; import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
@@ -12,5 +13,8 @@ public class ChoseEatModelDTO {
private Integer shopId; private Integer shopId;
private String tableId; private String tableId;
@NotNull @NotNull
private Integer userId; @Max(0)
@Min(1)
// 0切换店内 1切换外带
private Integer type;
} }

View File

@@ -39,7 +39,9 @@ import java.util.concurrent.ConcurrentHashMap;
public class PushToAppChannelHandlerAdapter extends NettyChannelHandlerAdapter { public class PushToAppChannelHandlerAdapter extends NettyChannelHandlerAdapter {
/** /**
* [tableID-shopId, [userId, ctx]] * 台桌下单为: TAKEOUT_TABLE_CART:shopId:tableID
* 店内自取为: DINE_IN_TABLE_CART:shopId:userId
* [shopId:tableID, [userId, ctx]]
*/ */
private static Map<String, ConcurrentHashMap<String, ChannelHandlerContext>> webSocketMap = new HashMap<>(); private static Map<String, ConcurrentHashMap<String, ChannelHandlerContext>> webSocketMap = new HashMap<>();
@@ -239,7 +241,7 @@ public class PushToAppChannelHandlerAdapter extends NettyChannelHandlerAdapter {
@Async @Async
public void AppSendInfo(String message, String redisKey,String userId, boolean userFlag) { public void AppSendInfo(String message, String redisKey,String userId, boolean userFlag) {
log.info("netty连接 发送消息 tableId:{} userId:{} userFlag:{} message:{}",redisKey,userId,userFlag, JSONUtil.toJSONString(message)); log.info("netty连接 发送消息 key:{} userId:{} userFlag:{} message:{}",redisKey,userId,userFlag, JSONUtil.toJSONString(message));
log.info("当前已连接队列信息: {}", webSocketMap); log.info("当前已连接队列信息: {}", webSocketMap);
if (userFlag) { if (userFlag) {
if (webSocketMap.containsKey(redisKey)) { if (webSocketMap.containsKey(redisKey)) {

View File

@@ -14,6 +14,7 @@ import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*; import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.Enum.*; import com.chaozhanggui.system.cashierservice.entity.Enum.*;
import com.chaozhanggui.system.cashierservice.entity.dto.ChoseCountDTO; import com.chaozhanggui.system.cashierservice.entity.dto.ChoseCountDTO;
import com.chaozhanggui.system.cashierservice.entity.dto.ChoseEatModelDTO;
import com.chaozhanggui.system.cashierservice.entity.dto.ShopEatTypeInfoDTO; import com.chaozhanggui.system.cashierservice.entity.dto.ShopEatTypeInfoDTO;
import com.chaozhanggui.system.cashierservice.exception.MsgException; import com.chaozhanggui.system.cashierservice.exception.MsgException;
import com.chaozhanggui.system.cashierservice.mapper.*; import com.chaozhanggui.system.cashierservice.mapper.*;
@@ -723,7 +724,7 @@ public class CartService {
} }
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void createOrder(JSONObject jsonObject) { public Result createOrder(JSONObject jsonObject) {
try { try {
JSONObject responseData = new JSONObject(); JSONObject responseData = new JSONObject();
@@ -795,7 +796,7 @@ public class CartService {
responseData.put("msg", "购物车为空"); responseData.put("msg", "购物车为空");
responseData.put("data", new ArrayList<>()); responseData.put("data", new ArrayList<>());
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(responseData.toString(), tableCartKey, jsonObject.getString("userId"), true); PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(responseData.toString(), tableCartKey, jsonObject.getString("userId"), true);
return; return Result.fail("购物车为空");
} }
// 就餐人数 // 就餐人数
@@ -829,7 +830,7 @@ public class CartService {
responseData.put("type", jsonObject.getString("type")); responseData.put("type", jsonObject.getString("type"));
responseData.put("data", ""); responseData.put("data", "");
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(responseData.toString(), tableCartKey, jsonObject.getString("userId"), true); PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(responseData.toString(), tableCartKey, jsonObject.getString("userId"), true);
return; return Result.fail(responseData.getString("msg"));
} }
@@ -1014,7 +1015,7 @@ public class CartService {
responseData.put("data", ""); responseData.put("data", "");
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(responseData.toString(), tableCartKey, jsonObject.getString("userId"), true); PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(responseData.toString(), tableCartKey, jsonObject.getString("userId"), true);
log.info("消息推送"); log.info("消息推送");
return; return Result.fail("优惠券已售空");
} }
if (N.gt(systemCoupons.getCouponsAmount(), totalAmount)) { if (N.gt(systemCoupons.getCouponsAmount(), totalAmount)) {
log.info("开始处理订单"); log.info("开始处理订单");
@@ -1024,7 +1025,7 @@ public class CartService {
responseData.put("data", ""); responseData.put("data", "");
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(responseData.toString(), tableCartKey, jsonObject.getString("userId"), true); PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(responseData.toString(), tableCartKey, jsonObject.getString("userId"), true);
log.info("消息推送"); log.info("消息推送");
return; return Result.fail("订单金额小于优惠价金额");
} }
totalAmount = totalAmount.add(systemCoupons.getCouponsPrice()).subtract(systemCoupons.getCouponsAmount()); totalAmount = totalAmount.add(systemCoupons.getCouponsPrice()).subtract(systemCoupons.getCouponsAmount());
originAmount = originAmount.add(systemCoupons.getCouponsPrice()); originAmount = originAmount.add(systemCoupons.getCouponsPrice());
@@ -1064,7 +1065,7 @@ public class CartService {
responseData.put("data", ""); responseData.put("data", "");
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(responseData.toString(), tableCartKey, jsonObject.getString("userId"), true); PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(responseData.toString(), tableCartKey, jsonObject.getString("userId"), true);
log.info("消息推送"); log.info("消息推送");
return; return Result.fail("订单正在支付中,请稍后再试");
} }
orderInfo.setUpdatedAt(System.currentTimeMillis()); orderInfo.setUpdatedAt(System.currentTimeMillis());
orderInfo.setSettlementAmount(totalAmount); orderInfo.setSettlementAmount(totalAmount);
@@ -1232,6 +1233,8 @@ public class CartService {
log.info("长链接错误 createOrder{}", e.getMessage()); log.info("长链接错误 createOrder{}", e.getMessage());
e.printStackTrace(); e.printStackTrace();
} }
return Result.success(CodeEnum.SUCCESS);
} }
private TbOrderInfo getOrder(BigDecimal totalAmount, BigDecimal packAMount, private TbOrderInfo getOrder(BigDecimal totalAmount, BigDecimal packAMount,
@@ -1578,4 +1581,17 @@ public class CartService {
} }
} }
public Object choseEatModel(ChoseEatModelDTO choseEatModelDTO) {
Integer userId = TokenUtil.getUserId();
// 查询购物车所有信息
LambdaQueryWrapper<TbCashierCart> queryWrapper = new LambdaQueryWrapper<TbCashierCart>()
.eq(TbCashierCart::getShopId, choseEatModelDTO.getShopId())
.gt(TbCashierCart::getCreatedAt, DateUtil.offsetDay(DateUtil.date(), -1).getTime())
.eq(TbCashierCart::getStatus, "create");
// 外带模式
queryWrapper.eq(TbCashierCart::getUserId, userId);
// 所有订单信息
return mpCashierCartMapper.selectList(queryWrapper);
}
} }

View File

@@ -994,7 +994,6 @@ public class ProductService {
return mpCashierCartMapper.update(null, new LambdaUpdateWrapper<TbCashierCart>() return mpCashierCartMapper.update(null, new LambdaUpdateWrapper<TbCashierCart>()
.eq(TbCashierCart::getShopId, choseTableDTO.getShopId()) .eq(TbCashierCart::getShopId, choseTableDTO.getShopId())
.eq(TbCashierCart::getUserId, choseTableDTO.getUserId())
.isNull(TbCashierCart::getUseType) .isNull(TbCashierCart::getUseType)
.eq(TbCashierCart::getStatus, "create") .eq(TbCashierCart::getStatus, "create")
.set(TbCashierCart::getUseType, shopEatTypeInfoDTO.getUseType())) ; .set(TbCashierCart::getUseType, shopEatTypeInfoDTO.getUseType())) ;