打印逻辑修改
This commit is contained in:
@@ -69,7 +69,14 @@ public interface RabbitConstants {
|
||||
|
||||
public static final String BALANCE_ROUTINGKEY_PUT="balance_routingkey_put";
|
||||
|
||||
|
||||
// 菜品打印
|
||||
String EXCHANGE_PRINT = "exchange.print";
|
||||
String ROUTING_KEY_PRINT_DISHES = "routing.dishes.print";
|
||||
|
||||
// 订单打印
|
||||
String QUEUE_PRINT_PLACE = "queue.place.order.print";
|
||||
String ROUTING_KEY_PRINT_PLACE = "routing.place.order.print";
|
||||
|
||||
// 排队小票打印
|
||||
String QUEUE_PRINT_CALL_TABLE = "queue.print.call.table";
|
||||
|
||||
@@ -121,6 +121,8 @@ public class CartService {
|
||||
private MpOrderDetailMapper mpOrderDetailMapper;
|
||||
@Autowired
|
||||
private MpShopTableMapper mpShopTableMapper;
|
||||
@Autowired
|
||||
private MQUtils mQUtils;
|
||||
|
||||
public CartService(TbUserShopMsgMapper tbUserShopMsgMapper, WechatUtil wechatUtil, WxAccountUtil wxAccountUtil, TbShopOpenIdMapper shopOpenIdMapper, ProductService productService, TbProductMapper tbProductMapper, RedisTemplate<String, Object> redisTemplate, StringRedisTemplate stringRedisTemplate, ShopUtils shopUtils) {
|
||||
this.tbUserShopMsgMapper = tbUserShopMsgMapper;
|
||||
@@ -687,6 +689,10 @@ public class CartService {
|
||||
seatNum = tbCashierCart.getNumber();
|
||||
seatCost = tbCashierCart.getTotalAmount();
|
||||
}
|
||||
|
||||
if (StringUtils.isNotEmpty(tbCashierCart.getOrderId())) {
|
||||
orderId = Integer.valueOf(tbCashierCart.getOrderId());
|
||||
}
|
||||
}
|
||||
|
||||
// 校验是否选择人数
|
||||
@@ -718,13 +724,22 @@ public class CartService {
|
||||
boolean isVip= tbShopUser != null && tbShopUser.getIsVip().equals((byte) 1);
|
||||
|
||||
// 查询历史orderDetail
|
||||
Integer finalOrderId = orderId;
|
||||
List<TbOrderDetail> oldOrderDetailList = mpOrderDetailMapper.selectList(new LambdaQueryWrapper<TbOrderDetail>()
|
||||
.in(TbOrderDetail::getCartId, cashierIds)
|
||||
.and(q -> q.in(TbOrderDetail::getCartId, cashierIds).or().eq(TbOrderDetail::getOrderId, finalOrderId))
|
||||
.eq(TbOrderDetail::getShopId, shopId));
|
||||
HashMap<String, TbOrderDetail> oldOrderDetailMap = new HashMap<>();
|
||||
oldOrderDetailList.forEach(item -> oldOrderDetailMap.put(item.getOrderId().toString() + item.getCartId(), item));
|
||||
|
||||
ArrayList<TbOrderDetail> removeOrderDetailList = new ArrayList<>();
|
||||
ArrayList<TbOrderDetail> addOrderDetail = new ArrayList<>();
|
||||
|
||||
oldOrderDetailList.forEach(item -> {
|
||||
oldOrderDetailMap.put(item.getOrderId().toString() + item.getCartId(), item);
|
||||
if (cashierCartList.contains(item.getCartId())) {
|
||||
oldOrderDetailMap.put(item.getOrderId().toString() + item.getCartId(), item);
|
||||
} else {
|
||||
removeOrderDetailList.add(item);
|
||||
}
|
||||
});
|
||||
boolean hasNewInfo = false;
|
||||
|
||||
//校验 库存 耗材
|
||||
@@ -817,6 +832,7 @@ public class CartService {
|
||||
if (orderDetail == null) {
|
||||
orderDetail = new TbOrderDetail();
|
||||
hasNewInfo = true;
|
||||
addOrderDetail.add(orderDetail);
|
||||
}
|
||||
orderDetail.setCreateTime(new Date());
|
||||
orderDetail.setNum(cart.getNumber());
|
||||
@@ -920,8 +936,6 @@ public class CartService {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (orderInfo != null) {
|
||||
log.info("订单状态:" + orderInfo.getStatus());
|
||||
if (!"unpaid".equals(orderInfo.getStatus())) {
|
||||
@@ -1001,6 +1015,7 @@ public class CartService {
|
||||
mpOrderDetailMapper.insert(orderDetail);
|
||||
}
|
||||
}
|
||||
|
||||
List<TbActivateOutRecord> outRecords = new ArrayList<>();
|
||||
for (TbCashierCart cashierCart : cashierCartList) {
|
||||
if (cashierCart.getIsVip().equals((byte) 1)) {
|
||||
@@ -1035,6 +1050,19 @@ public class CartService {
|
||||
|
||||
if(!CollectionUtils.isEmpty(outRecords)) outRecordMapper.insertBatch(outRecords);
|
||||
|
||||
// 打印票据
|
||||
if (!addOrderDetail.isEmpty() && shopEatTypeInfoDTO.isDineInAfter()) {
|
||||
mQUtils.printDishesTicket(orderInfo.getId(), false, addOrderDetail.toArray(new TbOrderDetail[0]));
|
||||
}
|
||||
|
||||
if (!removeOrderDetailList.isEmpty()) {
|
||||
// 退单票
|
||||
mpOrderDetailMapper.deleteBatchIds(removeOrderDetailList.stream().map(tbOrderDetail -> tbOrderDetail.getId()).collect(Collectors.toList()));
|
||||
if (shopEatTypeInfoDTO.isDineInAfter()) {
|
||||
mQUtils.printDishesTicket(orderInfo.getId(), true, removeOrderDetailList.toArray(new TbOrderDetail[0]));
|
||||
}
|
||||
}
|
||||
|
||||
// 发送mq消息
|
||||
JSONObject jsonObject2 = new JSONObject();
|
||||
jsonObject2.put("orderId", orderInfo.getId());
|
||||
@@ -1051,7 +1079,6 @@ public class CartService {
|
||||
redisUtil.deleteByKey(tableCartKey);
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(responseData.toString(), tableCartKey, jsonObject.getString("userId"), true);
|
||||
|
||||
|
||||
responseData.put("status", "success");
|
||||
responseData.put("msg", "成功");
|
||||
responseData.put("type", "order");
|
||||
@@ -1060,7 +1087,6 @@ public class CartService {
|
||||
// PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject12.toString(), jsonObject.getString("tableId").concat("-").concat(shopId), "", false);
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(responseData.toString(), tableCartKey, jsonObject.getString("userId"));
|
||||
|
||||
|
||||
redisUtil.saveMessage(RedisCst.ORDER_EXPIRED.concat(orderId.toString()), orderId.toString(), 60 * 16L);
|
||||
ThreadUtil.execAsync(() -> {
|
||||
ThreadUtil.sleep(5, TimeUnit.SECONDS);
|
||||
|
||||
@@ -5,11 +5,14 @@ import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.chaozhanggui.system.cashierservice.dao.*;
|
||||
import com.chaozhanggui.system.cashierservice.entity.*;
|
||||
import com.chaozhanggui.system.cashierservice.entity.dto.ReturnGroupOrderDto;
|
||||
import com.chaozhanggui.system.cashierservice.entity.dto.ShopEatTypeInfoDTO;
|
||||
import com.chaozhanggui.system.cashierservice.entity.vo.ShopUserListVo;
|
||||
import com.chaozhanggui.system.cashierservice.exception.MsgException;
|
||||
import com.chaozhanggui.system.cashierservice.mapper.MpOrderDetailMapper;
|
||||
import com.chaozhanggui.system.cashierservice.model.PayReq;
|
||||
import com.chaozhanggui.system.cashierservice.model.TradeQueryReq;
|
||||
import com.chaozhanggui.system.cashierservice.netty.PushToClientChannelHandlerAdapter;
|
||||
@@ -162,6 +165,10 @@ public class PayService {
|
||||
private MQUtils mQUtils;
|
||||
@Autowired
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
@Autowired
|
||||
private ShopUtils shopUtils;
|
||||
@Autowired
|
||||
private MpOrderDetailMapper mpOrderDetailMapper;
|
||||
|
||||
public PayService(@Qualifier("tbShopSongOrderServiceImpl") TbShopSongOrderService shopSongOrderService) {
|
||||
this.shopSongOrderService = shopSongOrderService;
|
||||
@@ -468,7 +475,16 @@ public class PayService {
|
||||
|
||||
producer.putOrderCollect(jsonObject.toJSONString());
|
||||
|
||||
producer.printMechine(orderId);
|
||||
ShopEatTypeInfoDTO shopEatTypeInfoDTO = shopUtils.checkEatModel(orderInfo.getShopId(), orderInfo.getTableId());
|
||||
// 打印消息
|
||||
if (!shopEatTypeInfoDTO.isDineInAfter()) {
|
||||
List<TbOrderDetail> detailList = mpOrderDetailMapper.selectList(new LambdaQueryWrapper<TbOrderDetail>()
|
||||
.eq(TbOrderDetail::getOrderId, orderInfo.getId())
|
||||
.eq(TbOrderDetail::getStatus, "closed"));
|
||||
mQUtils.printDishesTicket(orderInfo.getId(), false, detailList.toArray(new TbOrderDetail[0]));
|
||||
}
|
||||
mQUtils.printPlaceTicket(orderInfo.getId(), false);
|
||||
// producer.printMechine(orderId);
|
||||
sendOrderToClient(orderInfo);
|
||||
|
||||
// 发送mq消息并保存库存记录
|
||||
@@ -783,7 +799,16 @@ public class PayService {
|
||||
|
||||
|
||||
log.info("发送打印数据");
|
||||
producer.printMechine(orderInfo.getId() + "");
|
||||
ShopEatTypeInfoDTO shopEatTypeInfoDTO = shopUtils.checkEatModel(orderInfo.getShopId(), orderInfo.getTableId());
|
||||
// 打印消息
|
||||
if (!shopEatTypeInfoDTO.isDineInAfter()) {
|
||||
List<TbOrderDetail> detailList = mpOrderDetailMapper.selectList(new LambdaQueryWrapper<TbOrderDetail>()
|
||||
.eq(TbOrderDetail::getOrderId, orderInfo.getId())
|
||||
.eq(TbOrderDetail::getStatus, "closed"));
|
||||
mQUtils.printDishesTicket(orderInfo.getId(), false, detailList.toArray(new TbOrderDetail[0]));
|
||||
}
|
||||
mQUtils.printPlaceTicket(orderInfo.getId(), false);
|
||||
// producer.printMechine(orderInfo.getId() + "");
|
||||
|
||||
return Result.success(CodeEnum.SUCCESS, orderId);
|
||||
case "2": //退款成功
|
||||
@@ -836,7 +861,16 @@ public class PayService {
|
||||
|
||||
|
||||
log.info("发送打印数据");
|
||||
producer.printMechine(orderInfo.getId() + "");
|
||||
ShopEatTypeInfoDTO shopEatTypeInfoDTO = shopUtils.checkEatModel(orderInfo.getShopId(), orderInfo.getTableId());
|
||||
// 打印消息
|
||||
if (!shopEatTypeInfoDTO.isDineInAfter()) {
|
||||
List<TbOrderDetail> detailList = mpOrderDetailMapper.selectList(new LambdaQueryWrapper<TbOrderDetail>()
|
||||
.eq(TbOrderDetail::getOrderId, orderInfo.getId())
|
||||
.eq(TbOrderDetail::getStatus, "closed"));
|
||||
mQUtils.printDishesTicket(orderInfo.getId(), false, detailList.toArray(new TbOrderDetail[0]));
|
||||
}
|
||||
mQUtils.printPlaceTicket(orderInfo.getId(), false);
|
||||
// producer.printMechine(orderInfo.getId() + "");
|
||||
sendOrderToClient(orderInfo);
|
||||
redisUtil.deleteByKey(RedisCst.ORDER_EXPIRED.concat(orderInfo.getId().toString()));
|
||||
return Result.success(CodeEnum.SUCCESS, orderId);
|
||||
@@ -985,7 +1019,16 @@ public class PayService {
|
||||
producer.putOrderCollect(jsonObject.toJSONString());
|
||||
|
||||
log.info("发送打印数据");
|
||||
producer.printMechine(orderInfo.getId() + "");
|
||||
ShopEatTypeInfoDTO shopEatTypeInfoDTO = shopUtils.checkEatModel(orderInfo.getShopId(), orderInfo.getTableId());
|
||||
// 打印消息
|
||||
if (!shopEatTypeInfoDTO.isDineInAfter()) {
|
||||
List<TbOrderDetail> detailList = mpOrderDetailMapper.selectList(new LambdaQueryWrapper<TbOrderDetail>()
|
||||
.eq(TbOrderDetail::getOrderId, orderInfo.getId())
|
||||
.eq(TbOrderDetail::getStatus, "closed"));
|
||||
mQUtils.printDishesTicket(orderInfo.getId(), false, detailList.toArray(new TbOrderDetail[0]));
|
||||
}
|
||||
mQUtils.printPlaceTicket(orderInfo.getId(), false);
|
||||
// producer.printMechine(orderInfo.getId() + "");
|
||||
sendOrderToClient(orderInfo);
|
||||
redisUtil.deleteByKey(RedisCst.ORDER_EXPIRED.concat(orderInfo.getId().toString()));
|
||||
|
||||
@@ -1039,7 +1082,16 @@ public class PayService {
|
||||
producer.putOrderCollect(jsonObject.toJSONString());
|
||||
|
||||
log.info("发送打印数据");
|
||||
producer.printMechine(orderInfo.getId() + "");
|
||||
ShopEatTypeInfoDTO shopEatTypeInfoDTO = shopUtils.checkEatModel(orderInfo.getShopId(), orderInfo.getTableId());
|
||||
// 打印消息
|
||||
if (!shopEatTypeInfoDTO.isDineInAfter()) {
|
||||
List<TbOrderDetail> detailList = mpOrderDetailMapper.selectList(new LambdaQueryWrapper<TbOrderDetail>()
|
||||
.eq(TbOrderDetail::getOrderId, orderInfo.getId())
|
||||
.eq(TbOrderDetail::getStatus, "closed"));
|
||||
mQUtils.printDishesTicket(orderInfo.getId(), false, detailList.toArray(new TbOrderDetail[0]));
|
||||
}
|
||||
mQUtils.printPlaceTicket(orderInfo.getId(), false);
|
||||
// producer.printMechine(orderInfo.getId() + "");
|
||||
JSONObject coupons = new JSONObject();
|
||||
coupons.put("type", "buy");
|
||||
coupons.put("orderId", orderInfo.getId().toString());
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
package com.chaozhanggui.system.cashierservice.util;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbOrderDetail;
|
||||
import com.chaozhanggui.system.cashierservice.entity.dto.CallNumPrintDTO;
|
||||
import com.chaozhanggui.system.cashierservice.rabbit.RabbitConstants;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.rabbit.connection.CorrelationData;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class MQUtils {
|
||||
@@ -20,6 +24,12 @@ public class MQUtils {
|
||||
log.info("开始发送{}mq消息, exchange: {}, routingKey: {}, data: {}", note, exchange, routingKey, data);
|
||||
rabbitTemplate.convertAndSend(exchange, routingKey, JSONObject.toJSONString(data));
|
||||
}
|
||||
private <T> void sendMsg(String exchange, String routingKey, T data, String note, boolean isJson) {
|
||||
CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString());
|
||||
log.info("开始发送{}mq消息, msgId: {}, exchange: {}, routingKey: {}, data: {}", note, correlationId.getId(), exchange, routingKey, data);
|
||||
rabbitTemplate.convertAndSend(exchange, routingKey, isJson ? JSONObject.toJSONString(data) : data, correlationId);
|
||||
}
|
||||
|
||||
|
||||
public <T> void sendStockSaleMsg(T data) {
|
||||
sendMsg(RabbitConstants.EXCHANGE_STOCK_RECORD, RabbitConstants.ROUTING_STOCK_RECORD_SALE, data, "商品售出增加库存记录");
|
||||
@@ -31,4 +41,20 @@ public class MQUtils {
|
||||
printDTO.setShopId(shopId);
|
||||
sendMsg(RabbitConstants.EXCHANGE_PRINT, RabbitConstants.ROUTING_KEY_CALL_TABLE, printDTO, "排号小票打印");
|
||||
}
|
||||
|
||||
public void printDishesTicket(Integer orderId, boolean isReturn, TbOrderDetail... detailOrderIds) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("orderId", orderId);
|
||||
jsonObject.put("orderDetailIds", detailOrderIds);
|
||||
jsonObject.put("isReturn", isReturn);
|
||||
sendMsg(RabbitConstants.EXCHANGE_PRINT, RabbitConstants.ROUTING_KEY_PRINT_DISHES, jsonObject, "菜品打印", true);
|
||||
}
|
||||
|
||||
public void printPlaceTicket(Integer id, boolean isReturn) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("orderId", id);
|
||||
jsonObject.put("isReturn", isReturn);
|
||||
sendMsg(RabbitConstants.EXCHANGE_PRINT, RabbitConstants.ROUTING_KEY_PRINT_PLACE, jsonObject, "订单打印", true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user