就餐模式获取修改

This commit is contained in:
2024-09-29 13:57:11 +08:00
parent 688f73b4b3
commit caccb33016
2 changed files with 24 additions and 16 deletions

View File

@@ -3,11 +3,13 @@ package com.chaozhanggui.system.cashierservice.netty;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.entity.dto.ShopEatTypeInfoDTO;
import com.chaozhanggui.system.cashierservice.netty.config.NettyChannelHandlerAdapter;
import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer;
import com.chaozhanggui.system.cashierservice.redis.RedisCst;
import com.chaozhanggui.system.cashierservice.redis.RedisUtil;
import com.chaozhanggui.system.cashierservice.util.JSONUtil;
import com.chaozhanggui.system.cashierservice.util.ShopUtils;
import com.chaozhanggui.system.cashierservice.util.SpringUtils;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandler.Sharable;
@@ -17,6 +19,7 @@ import io.netty.handler.timeout.IdleState;
import io.netty.handler.timeout.IdleStateEvent;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
@@ -51,6 +54,9 @@ public class PushToAppChannelHandlerAdapter extends NettyChannelHandlerAdapter {
private RabbitProducer a;
//注入为空
public static RabbitProducer rabbitProducer;
@Autowired
private ShopUtils shopUtils;
@PostConstruct
public void b() {
rabbitProducer = this.a;
@@ -135,6 +141,8 @@ public class PushToAppChannelHandlerAdapter extends NettyChannelHandlerAdapter {
return;
}
ShopEatTypeInfoDTO eatModel = shopUtils.getEatModel(tableId, shopId);
tableId = !eatModel.isOpenTakeout() ? null : tableId;
String tableCartKey = RedisCst.getTableCartKey(shopId, tableId, Integer.valueOf(userId));
log.info("netty连接 接收到数据 建立连接参数 param:{}",jsonObject);
this.tableId=tableId;

View File

@@ -178,20 +178,20 @@ public class CartService {
}
String tableCartKey = RedisCst.getTableCartKey(shopId, tableId, userId);
TbCashierCart seatCartInfo = null;
// if (redisUtil.exists(tableCartKey)) {
// array = JSON.parseArray(redisUtil.getMessage(tableCartKey));
// for (int i = 0; i < array.size(); i++) {
// JSONObject object = array.getJSONObject(i);
// TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class);
// if (cashierCart.getNumber() > 0) {
// amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
// }
//
// if ("-999".equals(cashierCart.getProductId())) {
// seatCartInfo = cashierCart;
// }
// }
// } else {
if (redisUtil.exists(tableCartKey)) {
array = JSON.parseArray(redisUtil.getMessage(tableCartKey));
for (int i = 0; i < array.size(); i++) {
JSONObject object = array.getJSONObject(i);
TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class);
if (cashierCart.getNumber() > 0) {
amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
}
if ("-999".equals(cashierCart.getProductId())) {
seatCartInfo = cashierCart;
}
}
} else {
// 查询购物车所有信息
LambdaQueryWrapper<TbCashierCart> queryWrapper = new LambdaQueryWrapper<TbCashierCart>()
.eq(TbCashierCart::getShopId, shopId)
@@ -217,7 +217,7 @@ public class CartService {
}
redisUtil.saveMessage(tableCartKey, array.toString(), 60 * 60 * 12L);
}
// }
}
redisUtil.saveMessage(RedisCst.getCurrentTableSeatCount(shopEatTypeInfoDTO.getShopInfo().getId(), tableId), JSONObject.toJSONString(seatCartInfo), 60 * 60 * 12L);
@@ -485,7 +485,7 @@ public class CartService {
}
}
redisUtil.saveMessage(tableCartKey, jsonArray.toJSONString());
redisUtil.saveMessage(tableCartKey, jsonArray.toJSONString(), 60 * 60 * 12L);
// 餐位费
// Object seatCost = jsonArray.stream().findFirst().filter(info -> "-999".equals(((TbCashierCart) info).getProductId())).orElse(null);
TbCashierCart seatCost = cashierCartArrayList.stream().findFirst().filter(info -> "-999".equals(info.getProductId())).orElse(null);