Merge remote-tracking branch 'origin/master'

This commit is contained in:
Tankaikai
2025-02-26 16:57:54 +08:00
24 changed files with 544 additions and 77 deletions

View File

@@ -0,0 +1,14 @@
package com.czg.service.account.mapper;
import com.mybatisflex.core.BaseMapper;
import com.czg.account.entity.ShopAd;
/**
* 店铺广告 映射层。
*
* @author zs
* @since 2025-02-26
*/
public interface ShopAdMapper extends BaseMapper<ShopAd> {
}

View File

@@ -1,5 +1,6 @@
package com.czg.service.account.print;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ArrayUtil;
@@ -78,7 +79,7 @@ public abstract class PrinterHandler {
@Accessors(chain = true)
public static class PrintDetailInfo {
private boolean isPrint;
// private boolean isReturn;
// private boolean isReturn;
private long orderId;
private long detailId;
private BigDecimal printNum;
@@ -145,31 +146,37 @@ public abstract class PrinterHandler {
}
protected List<OrderDetail> getCanPrintOrderDetails(boolean partPrint, Long orderId, List<OrderDetail> tbOrderDetailList, List<?> categoryIds) {
List<Object> detailList = redisService.lGet(RedisCst.getPrintOrderDetailKey(orderId), 0, -1);
Map<Long, PrintDetailInfo> detailMap = detailList.stream().collect(Collectors.toMap(i -> {
if (i instanceof PrintDetailInfo i2) {
return i2.getDetailId();
}
throw new RuntimeException("转换orderDetail失败");
}, i -> (PrintDetailInfo) i));
List<Long> productIds = tbOrderDetailList.stream().map(OrderDetail::getProductId).collect(Collectors.toList());
Map<Long, Boolean> canPrintProMap = partPrint || categoryIds.isEmpty() ? new HashMap<>() :
productService.list(new QueryWrapper().in(Product::getCategoryId, categoryIds).in(Product::getId, productIds))
.stream().collect(Collectors.toMap(com.czg.product.entity.Product::getId, i -> true));
.stream().collect(Collectors.toMap(com.czg.product.entity.Product::getId, i -> true));
ArrayList<OrderDetail> orderDetails = new ArrayList<>();
tbOrderDetailList.forEach(item -> {
PrintDetailInfo printDetailInfo = detailMap.get(item.getId());
if (item.getIsPrint() != null && item.getIsPrint() == 1 && (canPrintProMap.get(item.getProductId()) != null || !partPrint) &&
(printDetailInfo == null || item.getNum().subtract(printDetailInfo.getPrintNum()).compareTo(BigDecimal.ZERO) > 0)) {
Object o = redisService.get(RedisCst.getPrintOrderDetailKey(orderId, item.getId()));
if (item.getIsPrint() != null && item.getIsPrint() == 1 && (canPrintProMap.get(item.getProductId()) != null || !partPrint)) {
item.setReturnNum(item.getReturnNum() == null ? BigDecimal.ZERO : item.getReturnNum());
PrintDetailInfo printDetailInfo = o != null ? JSONObject.parseObject((String) o, PrintDetailInfo.class) : null;
if (printDetailInfo != null) {
if (item.getNum().compareTo(printDetailInfo.getPrintNum()) <= 0) {
log.info("此菜品已打印, {} {} {}", item.getProductName(), item.getSkuName(), printDetailInfo);
}
if (item.getReturnNum().compareTo(printDetailInfo.getPrintReturnNum()) <= 0) {
log.info("此退菜菜品已打印, {} {} {}", item.getProductName(), item.getSkuName(), printDetailInfo);
}
item.setNum(item.getNum().subtract(printDetailInfo.getPrintNum()));
item.setReturnNum(item.getReturnNum().subtract(printDetailInfo.getPrintNum()));
item.setReturnNum(item.getReturnNum().subtract(printDetailInfo.getPrintReturnNum()));
orderDetails.add(item);
}else {
orderDetails.add(item);
}
orderDetails.add(item);
} else {
log.info("此菜品不在打印分类或属于免打, {} {} {}", item.getProductName(), item.getSkuName(), item.getId());
}
});
@@ -200,7 +207,7 @@ public abstract class PrinterHandler {
}
default -> log.warn("未知打印类型: {}", printMethod);
}
}else {
} else {
log.info("准备开始打印叫号单");
if (StrUtil.isBlank(machine.getPrintType())) {
return;
@@ -241,10 +248,8 @@ public abstract class PrinterHandler {
}
// 已打印详情信息
ArrayList<PrintDetailInfo> printDetailInfos = new ArrayList<>();
Map<Long, OrderDetail> detailMap = tbOrderDetailList.stream().collect(Collectors.toMap(OrderDetail::getId, i -> i));
Map<Long, OrderDetail> detailMap = tbOrderDetailList.stream().map(item -> BeanUtil.copyProperties(item, OrderDetail.class)).collect(Collectors.toMap(OrderDetail::getId, i -> i));
tbOrderDetailList = getCanPrintOrderDetails("1".equals(machine.getClassifyPrint()), orderInfo.getId(), tbOrderDetailList, categoryIds);
String printKey = RedisCst.getPrintOrderDetailKey(orderInfo.getId());
tbOrderDetailList.parallelStream().filter(o -> ObjectUtil.defaultIfNull(o.getIsPrint(), 0) == 1).forEach(item -> {
log.info("开始打印菜品,商品名:{}", item.getProductName());
Integer isWaitCall = ObjectUtil.defaultIfNull(item.getIsWaitCall(), 0);
@@ -291,8 +296,8 @@ public abstract class PrinterHandler {
// 保存已打印信息
OrderDetail orderDetail = detailMap.get(item.getId());
redisService.leftPush(printKey, new PrintDetailInfo().setPrint(item.getIsPrint() == 1).setDetailId(item.getId())
.setPrintNum(orderDetail.getNum()).setPrintReturnNum(orderDetail.getReturnNum()));
redisService.set(RedisCst.getPrintOrderDetailKey(orderInfo.getId(), item.getId()), JSONObject.toJSONString(new PrintDetailInfo().setPrint(item.getIsPrint() == 1).setDetailId(item.getId())
.setPrintNum(orderDetail.getNum()).setPrintReturnNum(orderDetail.getReturnNum())), 3600 * 24);
});
@@ -383,10 +388,10 @@ public abstract class PrinterHandler {
CallTable tbCallTable = callTableService.getById(queue.getCallTableId());
ShopInfo shopInfo = shopInfoService.getById(queue.getShopId());
callNumPrint(machine, queue.getCallNum(), shopInfo.getShopName(), tbCallTable.getName(), tbCallTable.getNote(), String.valueOf(callQueueService.count(new QueryWrapper()
.eq(CallQueue::getShopId, queue.getShopId())
.eq(CallQueue::getCallTableId, queue.getCallTableId())
.lt(CallQueue::getId, queue.getId())
.in(CallQueue::getState, 0, 1))), callUrl == null ? "未配置页面" : StrUtil.format(callUrl, queue.getShopId(), queue.getId()), queue.getCreateTime(),
.eq(CallQueue::getShopId, queue.getShopId())
.eq(CallQueue::getCallTableId, queue.getCallTableId())
.lt(CallQueue::getId, queue.getId())
.in(CallQueue::getState, 0, 1))), callUrl == null ? "未配置页面" : StrUtil.format(callUrl, queue.getShopId(), queue.getId()), queue.getCreateTime(),
StrUtil.format("过号顺延{}桌 {}桌后需重新排号 谢谢理解!", tbCallTable.getPostponeNum(), tbCallTable.getPostponeNum()));
}
@@ -399,6 +404,7 @@ public abstract class PrinterHandler {
/**
* 根据订单信息判断是否是退单
*
* @param orderInfo 顶动感信息
* @return 是否退款
*/

View File

@@ -0,0 +1,18 @@
package com.czg.service.account.service.impl;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.account.entity.ShopAd;
import com.czg.account.service.ShopAdService;
import com.czg.service.account.mapper.ShopAdMapper;
import org.springframework.stereotype.Service;
/**
* 店铺广告 服务层实现。
*
* @author zs
* @since 2025-02-26
*/
@Service
public class ShopAdServiceImpl extends ServiceImpl<ShopAdMapper, ShopAd> implements ShopAdService{
}

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.czg.service.account.mapper.ShopAdMapper">
</mapper>

View File

@@ -35,7 +35,6 @@ import com.czg.service.RedisService;
import com.czg.service.order.dto.BigDecimalDTO;
import com.czg.service.order.enums.OrderStatusEnums;
import com.czg.service.order.mapper.OrderInfoMapper;
import com.czg.system.entity.SysParams;
import com.czg.utils.AssertUtil;
import com.czg.utils.CzgStrUtils;
import com.czg.utils.PageUtil;
@@ -131,13 +130,24 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
}
@Override
public HistoryOrderVo historyOrder(Long orderId) {
public HistoryOrderVo historyOrder(Long orderId, String tableCode) {
if (orderId == null && StrUtil.isBlank(tableCode)) {
throw new ValidateException("订单id或台桌码不可为空");
}
HistoryOrderVo historyOrderVo = new HistoryOrderVo();
OrderInfo orderInfo = getById(orderId);
OrderInfo orderInfo;
if (orderId == null) {
orderInfo = queryChain()
.select()
.eq(OrderInfo::getTableCode, tableCode)
.one();
} else {
orderInfo = getById(orderId);
}
AssertUtil.isNull(orderInfo, "订单不存在");
historyOrderVo.setInfo(orderInfo);
List<OrderDetail> orderDetails = orderDetailService.queryChain().select()
.eq(OrderDetail::getOrderId, orderId).list();
.eq(OrderDetail::getOrderId, orderInfo.getId()).list();
Map<Integer, List<OrderDetail>> resultMap = new HashMap<>();
// 遍历订单详情列表
for (OrderDetail orderDetail : orderDetails) {
@@ -208,6 +218,8 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
if ("after-pay".equals(orderInfo.getPayMode())) {
//发送打票信息
rabbitPublisher.sendOrderPrintMsg(orderInfo.getId().toString());
} else {
redisService.set(RedisCst.classKeyExpired.EXPIRED_ORDER + orderInfo.getId(), "", 60 * 15);
}
rabbitPublisher.sendOrderStockMsg(orderInfo.getId().toString());
return orderInfo;
@@ -216,6 +228,13 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
@Override
public OrderInfo checkOrderPay(CheckOrderPay param) {
OrderInfo orderInfo = getById(param.getOrderId());
if (!"after-pay".equals(orderInfo.getPayMode())) {
if (redisService.hasKey(RedisCst.classKeyExpired.EXPIRED_ORDER + param.getOrderId())) {
redisService.set(RedisCst.classKeyExpired.EXPIRED_ORDER + param.getOrderId(), "", 60 * 15);
} else {
throw new ValidateException("订单已过期,请重新下单");
}
}
log.info("订单信息:{},优惠信息:{}", JSONObject.toJSONString(orderInfo), JSONObject.toJSONString(param));
if (!orderInfo.getStatus().equals(OrderStatusEnums.UNPAID.getCode())) {
throw new ValidateException("生成支付订单失败,订单不可支付");
@@ -433,6 +452,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
}
upOrderInfo(orderInfo, new BigDecimal(czgCallBackDto.getAmount() / 100L),
DateUtil.parseLocalDateTime(czgCallBackDto.getPayTime()), payment.getId(), null);
redisService.del(RedisCst.classKeyExpired.EXPIRED_ORDER + orderInfo.getId());
} else if ("memberIn".equals(payment.getPayType())) {
ShopUser shopUser = shopUserService.getById(payment.getSourceId());
if (shopUser == null) {
@@ -525,6 +545,23 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
}
}
/**
* 订单到期
*/
@Override
@Transactional
public void expired(Long orderId) {
OrderInfo orderInfo = getById(orderId);
if (orderInfo.getStatus().equals(OrderStatusEnums.UNPAID.getCode())) {
updateChain().set(OrderInfo::getStatus, OrderStatusEnums.CANCELLED.getCode())
.where(OrderInfo::getId).eq(orderId)
.update();
rabbitPublisher.sendOrderCancelMsg(orderId.toString());
} else {
log.info("订单取消失败,订单Id:{},订状态:{}", orderInfo.getId(), orderInfo.getStatus());
}
}
/**
* 初始化订单信息
*/

View File

@@ -94,6 +94,7 @@ public class PayServiceImpl implements PayService {
OrderInfo orderInfo = checkPay(payParam.getCheckOrderPay());
orderInfoService.upOrderInfo(orderInfo, orderInfo.getOrderAmount(),
LocalDateTime.now(), null, PayEnums.CREDIT_PAY);
redisService.del(RedisCst.classKeyExpired.EXPIRED_ORDER + orderInfo.getId());
//TODO 挂账后续逻辑
return CzgResult.success();
}
@@ -104,6 +105,7 @@ public class PayServiceImpl implements PayService {
OrderInfo orderInfo = checkPay(payParam.getCheckOrderPay());
orderInfoService.upOrderInfo(orderInfo, orderInfo.getOrderAmount(),
LocalDateTime.now(), null, PayEnums.CASH_PAY);
redisService.del(RedisCst.classKeyExpired.EXPIRED_ORDER + orderInfo.getId());
return CzgResult.success();
}
@@ -152,6 +154,7 @@ public class PayServiceImpl implements PayService {
Long flowId = shopUserService.updateMoney(shopUser.getShopId(), shopUserMoneyEditDTO);
orderInfoService.upOrderInfo(orderInfo, orderInfo.getOrderAmount(),
LocalDateTime.now(), flowId, PayEnums.VIP_PAY);
redisService.del(RedisCst.classKeyExpired.EXPIRED_ORDER + orderInfo.getId());
return CzgResult.success();
}

View File

@@ -17,7 +17,7 @@
#{entity.couponNum}, #{entity.returnNum}, #{entity.refundNum}, #{entity.refundNo},
#{entity.discountSaleNote}, #{entity.status}, #{entity.placeNum}, #{entity.isTemporary}, #{entity.isPrint},
#{entity.isWaitCall}, #{entity.proGroupInfo}, #{entity.remark}, #{entity.refundRemark},
#{entity.createTime}, #{entity.updateTime})
now(), now())
</foreach>
</insert>
</mapper>