1.代客下单 商品数量减少增加打印退单票据

This commit is contained in:
2024-08-30 15:06:56 +08:00
parent e0b62b66d4
commit 83d3aa444f
6 changed files with 280 additions and 109 deletions

View File

@@ -0,0 +1,6 @@
package com.chaozhanggui.system.cashierservice.bean;
public class PrintProductInfo {
private Integer orderDetailId;
private Integer num;
}

View File

@@ -34,6 +34,15 @@ public class TbPrintMachine implements Serializable {
private String vendorId;
private String productId;
private String config;
public String getConfig() {
return config;
}
public void setConfig(String config) {
this.config = config;
}
private static final long serialVersionUID = 1L;
@@ -164,4 +173,4 @@ public class TbPrintMachine implements Serializable {
public void setProductId(String productId) {
this.productId = productId == null ? null : productId.trim();
}
}
}

View File

@@ -0,0 +1,8 @@
package com.chaozhanggui.system.cashierservice.mybatis;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.chaozhanggui.system.cashierservice.entity.TbCashierCart;
import com.chaozhanggui.system.cashierservice.entity.TbPrintMachine;
public interface MpPrintMachineMapper extends BaseMapper<TbPrintMachine> {
}

View File

@@ -3,24 +3,25 @@ package com.chaozhanggui.system.cashierservice.rabbit;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.model.CategoryInfo;
import com.chaozhanggui.system.cashierservice.model.OrderDetailPO;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
import com.chaozhanggui.system.cashierservice.sign.Result;
import com.chaozhanggui.system.cashierservice.mybatis.MpPrintMachineMapper;
import com.chaozhanggui.system.cashierservice.util.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.annotation.RabbitListeners;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
@Slf4j
@Component
@@ -51,6 +52,14 @@ public class PrintMechineConsumer {
private RedisUtil redisUtils;
private final RedisTemplate<String, Object> redisTemplate;
@Autowired
private MpPrintMachineMapper mpPrintMachineMapper;
public PrintMechineConsumer(RedisTemplate<String, Object> redisTemplate) {
this.redisTemplate = redisTemplate;
}
@RabbitHandler
public void listener(String message) {
@@ -81,15 +90,15 @@ public class PrintMechineConsumer {
}
list.parallelStream().forEach(it->{
list.parallelStream().forEach(it -> {
if (!"network".equals(it.getConnectionType())) {
log.error("非网络打印机:{},{}",it.getAddress(),it.getConnectionType());
log.error("非网络打印机:{},{}", it.getAddress(), it.getConnectionType());
return;
}
if (!"1".equals(it.getStatus().toString())) {
log.error("打印机状态异常:{},{}",it.getAddress(),it.getStatus());
log.error("打印机状态异常:{},{}", it.getAddress(), it.getStatus());
return;
}
@@ -101,37 +110,37 @@ public class PrintMechineConsumer {
String feet = config.getString("feet");
String autoCut = config.getString("autoCut");
List<CategoryInfo> categoryInfos=JSONUtil.parseJSONStr2TList(config.getJSONArray("categoryList").toString(),CategoryInfo.class);
List<CategoryInfo> categoryInfos = JSONUtil.parseJSONStr2TList(config.getJSONArray("categoryList").toString(), CategoryInfo.class);
switch (it.getContentType()){
switch (it.getContentType()) {
case "yxyPrinter":
yxyPrinter(it,model,orderInfo,shopInfo,printerNum,categoryInfos);
yxyPrinter(it, model, orderInfo, shopInfo, printerNum, categoryInfos);
break;
case "fePrinter":
fePrinter(it,model,orderInfo,shopInfo,printerNum,categoryInfos);
fePrinter(it, model, orderInfo, shopInfo, printerNum, categoryInfos);
break;
}
});
}catch (Exception e){
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 博时结云打印机
* 博时结云打印机
*
* @param tbPrintMachineWithBLOBs
* @param model
* @param orderInfo
* @param shopInfo
* @param printerNum
*/
private void yxyPrinter(TbPrintMachineWithBLOBs tbPrintMachineWithBLOBs,String model,
TbOrderInfo orderInfo,TbShopInfo shopInfo,String printerNum, List<CategoryInfo> categoryInfos){
String orderId=orderInfo.getId().toString();
private void yxyPrinter(TbPrintMachineWithBLOBs tbPrintMachineWithBLOBs, String model,
TbOrderInfo orderInfo, TbShopInfo shopInfo, String printerNum, List<CategoryInfo> categoryInfos) {
String orderId = orderInfo.getId().toString();
switch (tbPrintMachineWithBLOBs.getSubType()) {
@@ -142,17 +151,17 @@ public class PrintMechineConsumer {
case "normal": //普通出单
if("return".equals(orderInfo.getOrderType())){
List<TbOrderDetail> tbOrderDetails=tbOrderDetailMapper.selectAllByOrderId(Integer.valueOf(orderId));
if(ObjectUtil.isNotEmpty(tbOrderDetails)&&tbOrderDetails.size()>0){
if ("return".equals(orderInfo.getOrderType())) {
List<TbOrderDetail> tbOrderDetails = tbOrderDetailMapper.selectAllByOrderId(Integer.valueOf(orderId));
if (ObjectUtil.isNotEmpty(tbOrderDetails) && tbOrderDetails.size() > 0) {
List<OrderDetailPO.Detail> detailList = new ArrayList<>();
tbOrderDetails.parallelStream().forEach(it->{
String categoryId= tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId();
tbOrderDetails.parallelStream().forEach(it -> {
String categoryId = tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId();
Long count= categoryInfos.stream().filter(c->
Long count = categoryInfos.stream().filter(c ->
c.getId().toString().equals(categoryId)
).count();
log.info("获取当前类别是否未打印类别:{}",count);
log.info("获取当前类别是否未打印类别:{}", count);
TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByPrimaryKey(Integer.valueOf(it.getProductSkuId()));
@@ -174,14 +183,14 @@ public class PrintMechineConsumer {
}
if(ObjectUtil.isNotEmpty(detailList)&&detailList.size()>0){
OrderDetailPO detailPO = new OrderDetailPO(shopInfo.getShopName(), "普通打印", ObjectUtil.isEmpty(orderInfo.getMasterId())||ObjectUtil.isNull(orderInfo.getMasterId())?orderInfo.getTableName():orderInfo.getMasterId(), orderInfo.getOrderNo(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), "【POS-1】001", orderInfo.getOrderAmount().toPlainString(), balance, orderInfo.getPayType(), "0", detailList,orderInfo.getRemark(),null,null);
if (ObjectUtil.isNotEmpty(detailList) && detailList.size() > 0) {
OrderDetailPO detailPO = new OrderDetailPO(shopInfo.getShopName(), "普通打印", ObjectUtil.isEmpty(orderInfo.getMasterId()) || ObjectUtil.isNull(orderInfo.getMasterId()) ? orderInfo.getTableName() : orderInfo.getMasterId(), orderInfo.getOrderNo(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), "【POS-1】001", orderInfo.getOrderAmount().toPlainString(), balance, orderInfo.getPayType(), "0", detailList, orderInfo.getRemark(), null, null);
String printType="退款单";
String printType = "退款单";
String data= PrinterUtils.getCashPrintData(detailPO,printType,"return");
String data = PrinterUtils.getCashPrintData(detailPO, printType, "return");
String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}";
PrinterUtils.printTickets(voiceJson,1, Integer.valueOf(printerNum), tbPrintMachineWithBLOBs.getAddress(), data);
PrinterUtils.printTickets(voiceJson, 1, Integer.valueOf(printerNum), tbPrintMachineWithBLOBs.getAddress(), data);
}
}
@@ -192,8 +201,8 @@ public class PrintMechineConsumer {
&& (!orderInfo.getStatus().equals("closed"))) {
return;
}
List<TbOrderDetail> tbOrderDetails=tbOrderDetailMapper.selectAllByOrderId(Integer.valueOf(orderId));
if(ObjectUtil.isNotEmpty(tbOrderDetails)&&tbOrderDetails.size()>0) {
List<TbOrderDetail> tbOrderDetails = tbOrderDetailMapper.selectAllByOrderId(Integer.valueOf(orderId));
if (ObjectUtil.isNotEmpty(tbOrderDetails) && tbOrderDetails.size() > 0) {
List<OrderDetailPO.Detail> detailList = new ArrayList<>();
tbOrderDetails.stream().forEach(it -> {
String categoryId = tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId();
@@ -224,21 +233,21 @@ public class PrintMechineConsumer {
if (ObjectUtil.isNotEmpty(detailList) && detailList.size() > 0) {
OrderDetailPO detailPO = new OrderDetailPO(shopInfo.getShopName(), "普通打印",
orderInfo.getOrderType().equals("miniapp") ? orderInfo.getTableName() : orderInfo.getMasterId(),
orderInfo.getOrderNo(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())),
"【POS-1】001", orderInfo.getOrderAmount().toPlainString(), balance,
(ObjectUtil.isEmpty(orderInfo.getPayType()) || ObjectUtil.isNull(orderInfo.getPayType()) ? "" : orderInfo.getPayType()),
"0", detailList, orderInfo.getRemark(), orderInfo.getDiscountAmount() != null ? orderInfo.getDiscountAmount().toPlainString() : null,
orderInfo.getDiscountRatio() != null ? orderInfo.getDiscountRatio().toPlainString() : null);
OrderDetailPO detailPO = new OrderDetailPO(shopInfo.getShopName(), "普通打印",
orderInfo.getOrderType().equals("miniapp") ? orderInfo.getTableName() : orderInfo.getMasterId(),
orderInfo.getOrderNo(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())),
"【POS-1】001", orderInfo.getOrderAmount().toPlainString(), balance,
(ObjectUtil.isEmpty(orderInfo.getPayType()) || ObjectUtil.isNull(orderInfo.getPayType()) ? "" : orderInfo.getPayType()),
"0", detailList, orderInfo.getRemark(), orderInfo.getDiscountAmount() != null ? orderInfo.getDiscountAmount().toPlainString() : null,
orderInfo.getDiscountRatio() != null ? orderInfo.getDiscountRatio().toPlainString() : null);
// OrderDetailPO detailPO = new OrderDetailPO(shopInfo.getShopName(), "普通打印", orderInfo.getMasterId(), orderInfo.getOrderNo(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), "【POS-1】001", orderInfo.getOrderAmount().toPlainString(), balance, orderInfo.getPayType(), "0", detailList);
detailPO.setOutNumber(orderInfo.getOutNumber());
String printType = "结算单";
detailPO.setOutNumber(orderInfo.getOutNumber());
String printType = "结算单";
String data = PrinterUtils.getCashPrintData(detailPO, printType, orderInfo.getOrderType());
String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}";
String data = PrinterUtils.getCashPrintData(detailPO, printType, orderInfo.getOrderType());
String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}";
PrinterUtils.printTickets(voiceJson, 3, Integer.valueOf(printerNum), tbPrintMachineWithBLOBs.getAddress(), data);
PrinterUtils.printTickets(voiceJson, 3, 1, tbPrintMachineWithBLOBs.getAddress(), data);
}
}
@@ -249,10 +258,10 @@ public class PrintMechineConsumer {
&& (!orderInfo.getStatus().equals("unpaid"))) {
return;
}
if("return".equals(orderInfo.getOrderType())){
if ("return".equals(orderInfo.getOrderType())) {
printReturnTicket(tbPrintMachineWithBLOBs, orderInfo, printerNum, categoryInfos, orderId);
return;
}else {
} else {
printTicket(Integer.valueOf(orderId), categoryInfos, tbPrintMachineWithBLOBs, orderInfo);
// printNormalTicket(tbPrintMachineWithBLOBs, orderInfo, printerNum, categoryInfos, orderId);
}
@@ -270,8 +279,11 @@ public class PrintMechineConsumer {
private void printTicket(Integer orderId, List<CategoryInfo> categoryInfos, TbPrintMachineWithBLOBs tbPrintMachineWithBLOBs, TbOrderInfo orderInfo) {
List<TbOrderDetail> tbOrderDetails = tbOrderDetailMapper.selectAllByOrderId(orderId);
if (!tbOrderDetails.isEmpty()) {
tbOrderDetails.parallelStream().forEach(it -> {
String printKey = RedisCst.ORDER_PRINT_PRO + orderId;
AtomicReference<Set<Object>> printProductSet = new AtomicReference<>(redisTemplate.opsForSet().members(printKey));
// 重置打印数据
redisTemplate.delete(printKey);
tbOrderDetails.forEach(it -> {
log.info("开始打印一菜一品票据,:{}", it.getProductName());
String categoryId = tbProductMapper.selectByPrimaryKey(it.getProductId()).getCategoryId();
@@ -280,7 +292,7 @@ public class PrintMechineConsumer {
).count();
log.info("获取当前类别是否未打印类别:{}", count);
if(count>0){
if (count > 0) {
// 统计已打数量
int printerNum = 0;
@@ -288,21 +300,40 @@ public class PrintMechineConsumer {
String key = RedisCst.ORDER_PRINT + orderId + ":" + it.getProductId() + ":" + it.getProductSkuId();
String info = redisUtils.getMessage(key);
redisUtils.saveMessage(key, String.valueOf(it.getNum()), 60 * 60 * 24);
// 删除已打印数据
if (printProductSet.get() != null) {
printProductSet.set(printProductSet.get().stream().filter(r -> {
TbOrderDetail detail = (TbOrderDetail) r;
return !detail.getProductSkuId().equals(it.getProductSkuId()) || !detail.getProductId().equals(it.getProductId());
}).collect(Collectors.toSet()));
}
if (info != null) {
isReturn = it.getNum() - Integer.parseInt(info) < 0;
printerNum = it.getNum() - Integer.parseInt(info);
}else {
printerNum = it.getNum();
}
TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByPrimaryKey(it.getProductSkuId());
String remark = "";
if (ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs) && ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs.getSpecSnap())) {
remark = tbProductSkuWithBLOBs.getSpecSnap();
}
// 将已打印信息加入redis
it.setRemark(remark);
redisTemplate.opsForSet().add(printKey, it);
redisTemplate.expire(printKey, 24, TimeUnit.HOURS);
// 已打印不再打印
if (info != null && it.getNum() - Integer.parseInt(info) == 0) {
return;
}
TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByPrimaryKey(Integer.valueOf(it.getProductSkuId()));
String remark = "";
if (ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs) && ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs.getSpecSnap())) {
remark = tbProductSkuWithBLOBs.getSpecSnap();
}
String data;
String voiceJson;
if (isReturn) {
@@ -311,27 +342,114 @@ public class PrintMechineConsumer {
StrUtil.isBlank(orderInfo.getTableName()) ? orderInfo.getMasterId() : orderInfo.getTableName(),
DateUtils.getTime(new Date(orderInfo.getCreatedAt())), it.getProductName(), it.getNum(), remark);
voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔退款订单,请及时处理\"}";
PrinterUtils.printTickets(voiceJson,3, 2, tbPrintMachineWithBLOBs.getAddress(), data);
PrinterUtils.printTickets(voiceJson, 3, 1, tbPrintMachineWithBLOBs.getAddress(), data);
}else {
} else {
data = PrinterUtils.getPrintData("", orderInfo.getMasterId(),
DateUtils.getTime(new Date(orderInfo.getCreatedAt())), it.getProductName(),
it.getNum(), remark);
voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}";
PrinterUtils.printTickets(voiceJson,3, 1, tbPrintMachineWithBLOBs.getAddress(), data);
PrinterUtils.printTickets(voiceJson, 3, 1, tbPrintMachineWithBLOBs.getAddress(), data);
}
// PrinterUtils.printTickets(voiceJson,3, printerNum, tbPrintMachineWithBLOBs.getAddress(), data);
}
});
// 已删除的商品打印退款信息
if (printProductSet.get() != null) {
printProductSet.get().forEach(item -> {
log.info("已删除订单,打印退款票据, {}", item);
TbOrderDetail orderDetail = (TbOrderDetail) item;
String data = PrinterUtils.getPrintData("return",
StrUtil.isBlank(orderInfo.getTableName()) ? orderInfo.getMasterId() : orderInfo.getTableName(),
DateUtils.getTime(new Date(orderInfo.getCreatedAt())), orderDetail.getProductName(), orderDetail.getNum(), orderDetail.getRemark());
String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔退款订单,请及时处理\"}";
PrinterUtils.printTickets(voiceJson, 3, 1, tbPrintMachineWithBLOBs.getAddress(), data);
String key = RedisCst.ORDER_PRINT + orderId + ":" + orderDetail.getProductId() + ":" + orderDetail.getProductSkuId();
log.info("删除商品数量记录key, {}", key);
redisUtils.deleteByKey(key);
});
}
}
}
/**
* 打印退款订单
* @param orderId 订单id
* @param tbOrderDetails 现有订单
*/
public void printReturnTicket(Integer orderId, List<TbOrderDetail> tbOrderDetails) {
TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(orderId);
List<TbPrintMachine> list = mpPrintMachineMapper.selectList(new LambdaUpdateWrapper<TbPrintMachine>()
.eq(TbPrintMachine::getContentType, "yxyPrinter")
.eq(TbPrintMachine::getConnectionType, "network")
.eq(TbPrintMachine::getSubType, "cash")
.eq(TbPrintMachine::getStatus, 1)
.eq(TbPrintMachine::getShopId, orderInfo.getShopId()));
String printKey = RedisCst.ORDER_PRINT_PRO + orderId;
Set<Object> printProductSet = redisTemplate.opsForSet().members(printKey);
Set<Object> printProductSetCopy = redisTemplate.opsForSet().members(printKey);
log.info("-------------------开始打印退款订单,打印机列表: {}", list);
log.info("-------------------待打印数据: {}", printProductSet);
if (printProductSet != null && !printProductSet.isEmpty()) {
// 过滤出已经删除的订单
if (tbOrderDetails != null && !tbOrderDetails.isEmpty()) {
for (TbOrderDetail it : tbOrderDetails) {
printProductSet = printProductSet.stream().filter(r -> {
TbOrderDetail detail = (TbOrderDetail) r;
return !detail.getProductSkuId().equals(it.getProductSkuId()) || !detail.getProductId().equals(it.getProductId());
}).collect(Collectors.toSet());
printProductSetCopy = printProductSet.stream().filter(r -> {
TbOrderDetail detail = (TbOrderDetail) r;
return detail.getProductSkuId().equals(it.getProductSkuId()) && detail.getProductId().equals(it.getProductId());
}).collect(Collectors.toSet());
}
redisTemplate.delete(printKey);
for (Object o : printProductSetCopy) {
redisTemplate.opsForSet().add(printKey, o);
}
}else if (tbOrderDetails != null) {
redisTemplate.delete(printKey);
}
log.info("-------------------打印机数量{}", list.size());
for (TbPrintMachine machine : list) {
String config = machine.getConfig();
if (config != null) {
JSONObject jsonObject = JSONObject.parseObject(config);
if (!"one".equals(jsonObject.getString("model"))) {
continue;
}
}
log.info("-------------------商品数量{}", printProductSet.size());
printProductSet.forEach(item -> {
log.info("已删除订单,打印退款票据, {}", item);
TbOrderDetail orderDetail = (TbOrderDetail) item;
String data = PrinterUtils.getPrintData("return",
StrUtil.isBlank(orderInfo.getTableName()) ? orderInfo.getMasterId() : orderInfo.getTableName(),
DateUtils.getTime(new Date(orderInfo.getCreatedAt())), orderDetail.getProductName(), orderDetail.getNum(), orderDetail.getRemark());
String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔退款订单,请及时处理\"}";
PrinterUtils.printTickets(voiceJson, 3, 1, machine.getAddress(), data);
String key = RedisCst.ORDER_PRINT + orderId + ":" + orderDetail.getProductId() + ":" + orderDetail.getProductSkuId();
log.info("删除商品数量记录key, {}", key);
redisUtils.deleteByKey(key);
});
}
}
}
/**
* 普通出菜单打印
*/
@@ -352,7 +470,7 @@ public class PrintMechineConsumer {
).count();
log.info("获取当前类别是否未打印类别:{}", count);
if(count>0){
if (count > 0) {
TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByPrimaryKey(Integer.valueOf(it.getProductSkuId()));
String remark = "";
if (ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs) && ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs.getSpecSnap())) {
@@ -362,7 +480,7 @@ public class PrintMechineConsumer {
DateUtils.getTime(new Date(orderInfo.getCreatedAt())), it.getProductName(),
it.getNum(), remark);
String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}";
PrinterUtils.printTickets(voiceJson,3, Integer.valueOf(printerNum), tbPrintMachineWithBLOBs.getAddress(), data);
PrinterUtils.printTickets(voiceJson, 3, 1, tbPrintMachineWithBLOBs.getAddress(), data);
}
});
}
@@ -372,25 +490,25 @@ public class PrintMechineConsumer {
* 退款单打印
*/
private void printReturnTicket(TbPrintMachineWithBLOBs tbPrintMachineWithBLOBs, TbOrderInfo orderInfo, String printerNum, List<CategoryInfo> categoryInfos, String orderId) {
List<TbOrderDetail> details= tbOrderDetailMapper.selectAllByOrderId(Integer.valueOf(orderId));
if(ObjectUtil.isNotEmpty(details)&&details.size()>0){
details.parallelStream().forEach(it->{
List<TbOrderDetail> details = tbOrderDetailMapper.selectAllByOrderId(Integer.valueOf(orderId));
if (ObjectUtil.isNotEmpty(details) && details.size() > 0) {
details.parallelStream().forEach(it -> {
String categoryId= tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId();
Long count= categoryInfos.stream().filter(c->
String categoryId = tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId();
Long count = categoryInfos.stream().filter(c ->
c.getId().toString().equals(categoryId)
).count();
if(count>0){
if (count > 0) {
TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByPrimaryKey(Integer.valueOf(it.getProductSkuId()));
String remark = "";
if (ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs) && ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs.getSpecSnap())) {
remark = tbProductSkuWithBLOBs.getSpecSnap();
}
String data = PrinterUtils.getPrintData("return", orderInfo.getPayType().equals("wx_lite")? orderInfo.getTableName(): orderInfo.getMasterId(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), it.getProductName(), it.getNum(), remark);
String data = PrinterUtils.getPrintData("return", orderInfo.getPayType().equals("wx_lite") ? orderInfo.getTableName() : orderInfo.getMasterId(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), it.getProductName(), it.getNum(), remark);
String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔退款订单,请及时处理\"}";
PrinterUtils.printTickets(voiceJson,3, Integer.valueOf(printerNum), tbPrintMachineWithBLOBs.getAddress(), data);
PrinterUtils.printTickets(voiceJson, 3, 1, tbPrintMachineWithBLOBs.getAddress(), data);
}
});
}
@@ -399,9 +517,10 @@ public class PrintMechineConsumer {
/**
* 判断商品是否已打票
*
* @return true 已打 false 未打
*/
private boolean isPrint(TbOrderDetail orderDetail, Integer orderId) {
private boolean isPrint(TbOrderDetail orderDetail, Integer orderId) {
String key = RedisCst.ORDER_PRINT + orderId + ":" + orderDetail.getProductId() + ":" + orderDetail.getProductSkuId();
String info = redisUtils.getMessage(key);
redisUtils.saveMessage(key, String.valueOf(orderDetail.getNum()), 60 * 60 * 24);
@@ -413,38 +532,36 @@ public class PrintMechineConsumer {
}
private void fePrinter(TbPrintMachineWithBLOBs tbPrintMachineWithBLOBs,String model,TbOrderInfo orderInfo,TbShopInfo shopInfo,String printerNum, List<CategoryInfo> categoryInfos){
String orderId=orderInfo.getId().toString();
private void fePrinter(TbPrintMachineWithBLOBs tbPrintMachineWithBLOBs, String model, TbOrderInfo orderInfo, TbShopInfo shopInfo, String printerNum, List<CategoryInfo> categoryInfos) {
String orderId = orderInfo.getId().toString();
switch (tbPrintMachineWithBLOBs.getSubType()) {
case "label": //标签打印机
List<TbCashierCart> cashierCarts = tbCashierCartMapper.selectByOrderId(orderInfo.getId().toString(),"final");
List<TbCashierCart> cashierCarts = tbCashierCartMapper.selectByOrderId(orderInfo.getId().toString(), "final");
if (ObjectUtil.isNotEmpty(cashierCarts) && cashierCarts.size() > 0) {
cashierCarts.parallelStream().forEach(it->{
cashierCarts.parallelStream().forEach(it -> {
String categoryId;
if(ObjectUtil.isEmpty(it.getCategoryId())){
categoryId= tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId();
if (ObjectUtil.isEmpty(it.getCategoryId())) {
categoryId = tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId();
} else {
categoryId = it.getCategoryId();
}
Long count= categoryInfos.stream().filter(c->
Long count = categoryInfos.stream().filter(c ->
c.getId().toString().equals(categoryId)
).count();
log.info("获取当前类别是否未打印类别:{}",count);
log.info("获取当前类别是否未打印类别:{}", count);
if(count>0) {
if (count > 0) {
TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByPrimaryKey(Integer.valueOf(it.getSkuId()));
String remark = "";
if (ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs) && ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs.getSpecSnap())) {
remark = tbProductSkuWithBLOBs.getSpecSnap();
}
for(int i=0;i<it.getNumber();i++){
for (int i = 0; i < it.getNumber(); i++) {
FeieyunPrintUtil.printLabelMsg(tbPrintMachineWithBLOBs.getAddress(), orderInfo.getTableName(), it.getName(), 1, DateUtils.getTimes(new Date(orderInfo.getCreatedAt())), it.getSalePrice().toPlainString(), remark);
}
}
@@ -456,17 +573,17 @@ public class PrintMechineConsumer {
switch (model) {
case "normal": //普通出单
if("return".equals(orderInfo.getOrderType())){
List<TbOrderDetail> tbOrderDetails=tbOrderDetailMapper.selectAllByOrderId(Integer.valueOf(orderId));
if(ObjectUtil.isNotEmpty(tbOrderDetails)&&tbOrderDetails.size()>0){
if ("return".equals(orderInfo.getOrderType())) {
List<TbOrderDetail> tbOrderDetails = tbOrderDetailMapper.selectAllByOrderId(Integer.valueOf(orderId));
if (ObjectUtil.isNotEmpty(tbOrderDetails) && tbOrderDetails.size() > 0) {
List<OrderDetailPO.Detail> detailList = new ArrayList<>();
tbOrderDetails.parallelStream().forEach(it->{
String categoryId= tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId();
tbOrderDetails.parallelStream().forEach(it -> {
String categoryId = tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId();
Long count= categoryInfos.stream().filter(c->
Long count = categoryInfos.stream().filter(c ->
c.getId().toString().equals(categoryId)
).count();
log.info("获取当前类别是否未打印类别:{}",count);
log.info("获取当前类别是否未打印类别:{}", count);
TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByPrimaryKey(Integer.valueOf(it.getProductSkuId()));
@@ -488,20 +605,20 @@ public class PrintMechineConsumer {
}
if(ObjectUtil.isNotEmpty(detailList)&&detailList.size()>0){
if (ObjectUtil.isNotEmpty(detailList) && detailList.size() > 0) {
// OrderDetailPO detailPO = new OrderDetailPO(shopInfo.getShopName(), "普通打印", orderInfo.getMasterId(), orderInfo.getOrderNo(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), "【POS-1】001", orderInfo.getOrderAmount().toPlainString(), balance, orderInfo.getPayType(), "0", detailList);
OrderDetailPO detailPO = new OrderDetailPO(shopInfo.getShopName(), "普通打印", ObjectUtil.isEmpty(orderInfo.getMasterId())||ObjectUtil.isNull(orderInfo.getMasterId())?orderInfo.getTableName():orderInfo.getMasterId(), orderInfo.getOrderNo(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), "【POS-1】001", orderInfo.getOrderAmount().toPlainString(), balance, orderInfo.getPayType(), "0", detailList,orderInfo.getRemark(),orderInfo.getDiscountAmount().toPlainString(),orderInfo.getDiscountRatio().toPlainString());
OrderDetailPO detailPO = new OrderDetailPO(shopInfo.getShopName(), "普通打印", ObjectUtil.isEmpty(orderInfo.getMasterId()) || ObjectUtil.isNull(orderInfo.getMasterId()) ? orderInfo.getTableName() : orderInfo.getMasterId(), orderInfo.getOrderNo(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), "【POS-1】001", orderInfo.getOrderAmount().toPlainString(), balance, orderInfo.getPayType(), "0", detailList, orderInfo.getRemark(), orderInfo.getDiscountAmount().toPlainString(), orderInfo.getDiscountRatio().toPlainString());
String printType="退款单";
String printType = "退款单";
String data= PrinterUtils.getCashPrintData(detailPO,printType,"return");
String data = PrinterUtils.getCashPrintData(detailPO, printType, "return");
// String voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}";
// PrinterUtils.printTickets(voiceJson,1, Integer.valueOf(printerNum), tbPrintMachineWithBLOBs.getAddress(), data);
}
}
}else {
} else {
cashierCarts = cashierCarts = tbCashierCartMapper.selectByOrderId(orderInfo.getId().toString(), "final");
if (ObjectUtil.isNotEmpty(cashierCarts) && cashierCarts.size() > 0) {
@@ -540,7 +657,7 @@ public class PrintMechineConsumer {
}
}
if (ObjectUtil.isNotEmpty(detailList) && detailList.size() > 0) {
OrderDetailPO detailPO = new OrderDetailPO(shopInfo.getShopName(), "普通打印", orderInfo.getOrderType().equals("miniapp") ? orderInfo.getTableName() : orderInfo.getMasterId(), orderInfo.getOrderNo(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), "【POS-1】001", orderInfo.getOrderAmount().toPlainString(), balance, (ObjectUtil.isEmpty(orderInfo.getPayType()) || ObjectUtil.isNull(orderInfo.getPayType()) ? "" : orderInfo.getPayType()), "0", detailList, orderInfo.getRemark(),null,null);
OrderDetailPO detailPO = new OrderDetailPO(shopInfo.getShopName(), "普通打印", orderInfo.getOrderType().equals("miniapp") ? orderInfo.getTableName() : orderInfo.getMasterId(), orderInfo.getOrderNo(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), "【POS-1】001", orderInfo.getOrderAmount().toPlainString(), balance, (ObjectUtil.isEmpty(orderInfo.getPayType()) || ObjectUtil.isNull(orderInfo.getPayType()) ? "" : orderInfo.getPayType()), "0", detailList, orderInfo.getRemark(), null, null);
String printType = "结算单";
if ("return".equals(orderInfo.getOrderType())) {
@@ -561,24 +678,24 @@ public class PrintMechineConsumer {
return;
}
cashierCarts = tbCashierCartMapper.selectByOrderId(orderId,"final");
cashierCarts = tbCashierCartMapper.selectByOrderId(orderId, "final");
if (ObjectUtil.isNotEmpty(cashierCarts) && cashierCarts.size() > 0) {
cashierCarts.parallelStream().forEach(it -> {
String categoryId;
if(ObjectUtil.isEmpty(it.getCategoryId())){
categoryId= tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId();
if (ObjectUtil.isEmpty(it.getCategoryId())) {
categoryId = tbProductMapper.selectByPrimaryKey(Integer.valueOf(it.getProductId())).getCategoryId();
} else {
categoryId = it.getCategoryId();
}
Long count= categoryInfos.stream().filter(c->
Long count = categoryInfos.stream().filter(c ->
c.getId().toString().equals(categoryId)
).count();
if(count>0){
if (count > 0) {
TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByPrimaryKey(Integer.valueOf(it.getSkuId()));
String remark = "";
if (ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs) && ObjectUtil.isNotEmpty(tbProductSkuWithBLOBs.getSpecSnap())) {
@@ -586,8 +703,7 @@ public class PrintMechineConsumer {
}
FeieyunPrintUtil.getPrintData(tbPrintMachineWithBLOBs.getAddress(),orderInfo.getMasterId(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), it.getName(), it.getNumber(), remark);
FeieyunPrintUtil.getPrintData(tbPrintMachineWithBLOBs.getAddress(), orderInfo.getMasterId(), DateUtils.getTime(new Date(orderInfo.getCreatedAt())), it.getName(), it.getNumber(), remark);
}
});
}

View File

@@ -19,6 +19,7 @@ import com.chaozhanggui.system.cashierservice.entity.vo.CartVo;
import com.chaozhanggui.system.cashierservice.exception.MsgException;
import com.chaozhanggui.system.cashierservice.mybatis.MPCashierCartMapper;
import com.chaozhanggui.system.cashierservice.mybatis.MpShopTableMapper;
import com.chaozhanggui.system.cashierservice.rabbit.PrintMechineConsumer;
import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
import com.chaozhanggui.system.cashierservice.sign.Result;
@@ -28,6 +29,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -91,20 +93,28 @@ public class OrderService {
@Autowired
TbConsInfoMapper tbConsInfoMapper;
private final TbCashierCartMapper tbCashierCartMapper;
private static ConcurrentHashMap<String, HashSet<Integer>> codeMap = new ConcurrentHashMap<>();
private static ConcurrentHashMap<String, HashSet<String>> userMap = new ConcurrentHashMap<>();
@Autowired
private ProductService productService;
@Qualifier("printMechineConsumer")
@Autowired
private PrintMechineConsumer printMechineConsumer;
@Qualifier("tbOrderDetailMapper")
@Autowired
private TbOrderDetailMapper tbOrderDetailMapper;
public OrderService(WxAccountUtil wxAccountUtil, MPCashierCartMapper mpCashierCartMapper, WechatUtil wechatUtil, TbUserShopMsgMapper tbUserShopMsgMapper, TbShopOpenIdMapper shopOpenIdMapper, MpShopTableMapper mpShopTableMapper) {
public OrderService(WxAccountUtil wxAccountUtil, MPCashierCartMapper mpCashierCartMapper, WechatUtil wechatUtil, TbUserShopMsgMapper tbUserShopMsgMapper, TbShopOpenIdMapper shopOpenIdMapper, MpShopTableMapper mpShopTableMapper, TbCashierCartMapper tbCashierCartMapper) {
this.wxAccountUtil = wxAccountUtil;
this.mpCashierCartMapper = mpCashierCartMapper;
this.wechatUtil = wechatUtil;
this.tbUserShopMsgMapper = tbUserShopMsgMapper;
this.shopOpenIdMapper = shopOpenIdMapper;
this.mpShopTableMapper = mpShopTableMapper;
this.tbCashierCartMapper = tbCashierCartMapper;
}
@Transactional(rollbackFor = Exception.class)
@@ -203,6 +213,7 @@ public class OrderService {
tbOrderInfoMapper.deleteByPrimaryKey(Integer.valueOf(finalCart.getOrderId()));
}
}
return Result.success(CodeEnum.SUCCESS, masterId);
}
@@ -343,6 +354,14 @@ public class OrderService {
redisUtil.saveMessage("SHOP:CODE:SET" + clientType + ":" + shopId + ":" + DateUtils.getDay(),masterId.substring(1,masterId.length()));
TbCashierCart finalCart1 = cart;
ThreadUtil.execute(() -> {
ThreadUtil.sleep(1, TimeUnit.SECONDS);
if (finalCart1.getOrderId() != null && finalCart1.getTableId() != null) {
log.info("购物车数量改变,开始校验订单是否为空");
printMechineConsumer.printReturnTicket(Integer.valueOf(finalCart1.getOrderId()), tbOrderDetailMapper.selectAllByOrderId(Integer.valueOf(finalCart1.getOrderId())));
}
});
return Result.success(CodeEnum.SUCCESS, masterId);
}
@@ -546,7 +565,13 @@ public class OrderService {
if (list.isEmpty()) {
tbOrderInfoMapper.deleteByPrimaryKey(Integer.valueOf(cashierCart.getOrderId()));
ThreadUtil.execute(() -> {
log.info("购物车数量改变,开始校验订单是否为空");
printMechineConsumer.printReturnTicket(Integer.valueOf(cashierCart.getOrderId()), null);
});
}
}
return Result.success(CodeEnum.SUCCESS);
@@ -1213,6 +1238,12 @@ public class OrderService {
.eq(TbShopTable::getQrcode, cartVo.getTableId())
.set(TbShopTable::getStatus, TableStateEnum.IDLE.getState()));
// 打印退款票据
int finalOrderId = orderId;
ThreadUtil.execute(() -> {
printMechineConsumer.printReturnTicket(finalOrderId, null);
});
return Result.success(CodeEnum.SUCCESS);
}

View File

@@ -21,4 +21,5 @@ public class RedisCst {
public static final String ORDER_PRODUCT_NUM = "ORDER_NUM:";
public static final String ORDER_CART_EXISTS = "ORDER_CART_EXISTS:";
public static final String ORDER_PRINT = "ORDER_PRINT:";
public static final String ORDER_PRINT_PRO = "ORDER_PRINT_PRODUCT:";
}