新增创建订单 切换就餐模式接口
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package com.chaozhanggui.system.cashierservice.controller;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbShopTable;
|
||||
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.sign.Result;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -21,17 +23,20 @@ public class OrderController {
|
||||
|
||||
@Resource
|
||||
private OrderService orderService;
|
||||
private final CartService cartService;
|
||||
|
||||
public OrderController(CartService cartService) {
|
||||
this.cartService = cartService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加订单
|
||||
* @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 cartService.createOrder(jsonObject);
|
||||
// return orderService.createOrder(shopTable.getTableId(),shopTable.getShopId(),shopTable.getUserId());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -107,17 +107,13 @@ 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));
|
||||
@PutMapping("/choseEatModel")
|
||||
public Result choseEatModel(@Validated @RequestBody ChoseEatModelDTO choseEatModelDTO) {
|
||||
return Result.success(CodeEnum.SUCCESS, cartService.choseEatModel(choseEatModelDTO));
|
||||
}
|
||||
|
||||
@PostMapping("cleanCart")
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.chaozhanggui.system.cashierservice.entity.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.Max;
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
@@ -12,5 +13,8 @@ public class ChoseEatModelDTO {
|
||||
private Integer shopId;
|
||||
private String tableId;
|
||||
@NotNull
|
||||
private Integer userId;
|
||||
@Max(0)
|
||||
@Min(1)
|
||||
// 0切换店内 1切换外带
|
||||
private Integer type;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,9 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
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<>();
|
||||
|
||||
@@ -239,7 +241,7 @@ public class PushToAppChannelHandlerAdapter extends NettyChannelHandlerAdapter {
|
||||
|
||||
@Async
|
||||
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);
|
||||
if (userFlag) {
|
||||
if (webSocketMap.containsKey(redisKey)) {
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.chaozhanggui.system.cashierservice.dao.*;
|
||||
import com.chaozhanggui.system.cashierservice.entity.*;
|
||||
import com.chaozhanggui.system.cashierservice.entity.Enum.*;
|
||||
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.exception.MsgException;
|
||||
import com.chaozhanggui.system.cashierservice.mapper.*;
|
||||
@@ -723,7 +724,7 @@ public class CartService {
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void createOrder(JSONObject jsonObject) {
|
||||
public Result createOrder(JSONObject jsonObject) {
|
||||
try {
|
||||
JSONObject responseData = new JSONObject();
|
||||
|
||||
@@ -795,7 +796,7 @@ public class CartService {
|
||||
responseData.put("msg", "购物车为空");
|
||||
responseData.put("data", new ArrayList<>());
|
||||
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("data", "");
|
||||
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", "");
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(responseData.toString(), tableCartKey, jsonObject.getString("userId"), true);
|
||||
log.info("消息推送");
|
||||
return;
|
||||
return Result.fail("优惠券已售空");
|
||||
}
|
||||
if (N.gt(systemCoupons.getCouponsAmount(), totalAmount)) {
|
||||
log.info("开始处理订单");
|
||||
@@ -1024,7 +1025,7 @@ public class CartService {
|
||||
responseData.put("data", "");
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(responseData.toString(), tableCartKey, jsonObject.getString("userId"), true);
|
||||
log.info("消息推送");
|
||||
return;
|
||||
return Result.fail("订单金额小于优惠价金额");
|
||||
}
|
||||
totalAmount = totalAmount.add(systemCoupons.getCouponsPrice()).subtract(systemCoupons.getCouponsAmount());
|
||||
originAmount = originAmount.add(systemCoupons.getCouponsPrice());
|
||||
@@ -1064,7 +1065,7 @@ public class CartService {
|
||||
responseData.put("data", "");
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(responseData.toString(), tableCartKey, jsonObject.getString("userId"), true);
|
||||
log.info("消息推送");
|
||||
return;
|
||||
return Result.fail("订单正在支付中,请稍后再试");
|
||||
}
|
||||
orderInfo.setUpdatedAt(System.currentTimeMillis());
|
||||
orderInfo.setSettlementAmount(totalAmount);
|
||||
@@ -1232,6 +1233,8 @@ public class CartService {
|
||||
log.info("长链接错误 createOrder{}", e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return Result.success(CodeEnum.SUCCESS);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -994,7 +994,6 @@ public class ProductService {
|
||||
|
||||
return mpCashierCartMapper.update(null, new LambdaUpdateWrapper<TbCashierCart>()
|
||||
.eq(TbCashierCart::getShopId, choseTableDTO.getShopId())
|
||||
.eq(TbCashierCart::getUserId, choseTableDTO.getUserId())
|
||||
.isNull(TbCashierCart::getUseType)
|
||||
.eq(TbCashierCart::getStatus, "create")
|
||||
.set(TbCashierCart::getUseType, shopEatTypeInfoDTO.getUseType())) ;
|
||||
|
||||
Reference in New Issue
Block a user