From 4f7505ec52a100ef3092c42dc5c04363a05a4a24 Mon Sep 17 00:00:00 2001 From: sxu <602087911@qq.com> Date: Thu, 20 Feb 2025 18:58:08 +0800 Subject: [PATCH] sync_pay_state --- .../impl/OrderDishesAndroidBusinessImpl.java | 12 +++ .../common/service/OrderInfoService.java | 2 +- .../service/impl/OrderInfoServiceImpl.java | 10 +- .../custom/OrderCustomPlaceBusiness.java | 5 +- .../com/bonus/core/order/utils/LeNumUtil.java | 95 ++++++++++++------- .../src/main/resources/bootstrap.yml | 3 + 6 files changed, 83 insertions(+), 44 deletions(-) diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/core/order/android/business/impl/OrderDishesAndroidBusinessImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/core/order/android/business/impl/OrderDishesAndroidBusinessImpl.java index 94597cef..e53f2776 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/core/order/android/business/impl/OrderDishesAndroidBusinessImpl.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/core/order/android/business/impl/OrderDishesAndroidBusinessImpl.java @@ -4,12 +4,14 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.ListUtil; import cn.hutool.core.text.CharSequenceUtil; import cn.hutool.core.util.ObjectUtil; +import com.bonus.core.allocation.api.AllocStallApi; import com.bonus.core.allocation.canteen.model.AllocStall; import com.bonus.core.customer.constants.OrderTypeEnum; import com.bonus.core.order.android.business.OrderDishesAndroidBusiness; import com.bonus.core.order.common.model.OrderInfo; import com.bonus.core.order.custom.OrderCustomBusiness; import com.bonus.core.order.utils.LeNumUtil; +import com.bonus.core.supermarket.api.SupermarketApi; import com.bonus.core.supermarket.model.SupermarketInfo; import org.redisson.api.RLock; import org.slf4j.Logger; @@ -35,6 +37,16 @@ public class OrderDishesAndroidBusinessImpl implements OrderDishesAndroidBusines @Lazy protected OrderCustomBusiness orderCustomBusiness; + @Autowired + @Lazy + protected AllocStallApi allocStallApi; + @Autowired + @Lazy + protected SupermarketApi supermarketApi; + @Lazy + @Autowired + protected LeNumUtil numUtil; + public void initOrderMealCode(OrderInfo orderInfo) { if (!CharSequenceUtil.isNotEmpty(orderInfo.getMealCode())) { String mealCode = this.createMealCode(orderInfo.getOrderType(), orderInfo.getCanteenId(), orderInfo.getStallId(), orderInfo.getOrderDate(), orderInfo.getMealtimeType()); diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/core/order/common/service/OrderInfoService.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/core/order/common/service/OrderInfoService.java index d737ab5a..96c11504 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/core/order/common/service/OrderInfoService.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/core/order/common/service/OrderInfoService.java @@ -38,7 +38,7 @@ public interface OrderInfoService { // // long existReserveOrderUnPrint(Long canteenId, Long stallId, Integer mealtimeType); // -// String getMaxMealCodeOfDate(@NotNull LocalDate orderDate, Integer mealtimeType, Long canteenId, Long stallId); + String getMaxMealCodeOfDate(@NotNull LocalDate orderDate, Integer mealtimeType, Long canteenId, Long stallId); // // OrderInfo getById(Long id, LocalDate... orderDates); diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/core/order/common/service/impl/OrderInfoServiceImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/core/order/common/service/impl/OrderInfoServiceImpl.java index 3a3a9446..5118bf04 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/core/order/common/service/impl/OrderInfoServiceImpl.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/core/order/common/service/impl/OrderInfoServiceImpl.java @@ -392,11 +392,11 @@ public class OrderInfoServiceImpl extends ServiceImpl getOrderSelectWrappers() { return Wrappers.lambdaQuery(OrderInfo.class).select(OrderInfo::getOrderId, OrderInfo::getCustId, OrderInfo::getSourceType, OrderInfo::getCanteenId, OrderInfo::getStallId, OrderInfo::getMealtimeType, OrderInfo::getCanteenName, OrderInfo::getStallName, OrderInfo::getMealtimeName, OrderInfo::getOrderDate, OrderInfo::getCouponId, OrderInfo::getPayableAmount, OrderInfo::getRealAmount, OrderInfo::getAccPayAmount, OrderInfo::getOutPayAmount, OrderInfo::getOrderTime, OrderInfo::getOrderType, OrderInfo::getOrderState, OrderInfo::getPayTime, OrderInfo::getPayType, OrderInfo::getPayState, OrderInfo::getDeliveryType, OrderInfo::getDishesState, OrderInfo::getOrderRefundState); diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/core/order/custom/OrderCustomPlaceBusiness.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/core/order/custom/OrderCustomPlaceBusiness.java index 89bafb44..c35ff04a 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/core/order/custom/OrderCustomPlaceBusiness.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/core/order/custom/OrderCustomPlaceBusiness.java @@ -8,6 +8,7 @@ import com.bonus.core.marketing.coupon.model.MktCouponPayModel; import com.bonus.core.marketing.v2.rule.price.dto.RulePriceDTO; import com.bonus.core.menu.dto.MenuRecipeChangeSurplusNum; import com.bonus.core.order.common.constants.ChangeDetailTypeEnum; +import com.bonus.core.order.common.dto.OrderDidPayInfoDTO; import com.bonus.core.order.common.model.*; import com.bonus.core.order.common.vo.OrderDeliveryResultVO; import com.bonus.core.order.mq.po.OrderSavePO; @@ -138,8 +139,8 @@ public class OrderCustomPlaceBusiness implements CustomBusiness { public void didCalcOrderRealAmount(List orderInfoList, List orderDetailList, BigDecimal payAmount, List channelDetailList, List orderAmountDetailList) { } -// public void didUpdateOrderFieldAfterPay(OrderInfo orderInfo, OrderDidPayInfoDTO didPayInfoDTO) { -// } + public void didUpdateOrderFieldAfterPay(OrderInfo orderInfo, OrderDidPayInfoDTO didPayInfoDTO) { + } public boolean willHandleOrderDidFailed(List orderInfoList, List orderDetailList, Integer payState, boolean orderExists) { diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/core/order/utils/LeNumUtil.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/core/order/utils/LeNumUtil.java index 2f663a64..793d15cc 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/core/order/utils/LeNumUtil.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/core/order/utils/LeNumUtil.java @@ -1,15 +1,28 @@ package com.bonus.core.order.utils; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.LocalDateTimeUtil; +import cn.hutool.core.text.CharSequenceUtil; +import cn.hutool.core.util.NumberUtil; +import cn.hutool.core.util.ObjectUtil; import com.bonus.constant.LeConstants; +import com.bonus.core.common.utils.TenantContextHolder; +import com.bonus.core.order.common.service.OrderInfoService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Lazy; +import org.springframework.data.redis.core.BoundValueOperations; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; - import java.math.BigDecimal; import java.math.RoundingMode; +import java.time.Duration; +import java.time.LocalDate; import java.time.LocalDateTime; import java.time.ZoneId; +import java.time.format.DateTimeFormatter; import java.util.*; import java.util.function.BiConsumer; import java.util.function.Function; @@ -18,6 +31,16 @@ import java.util.stream.Collectors; @Component public class LeNumUtil { private static final Logger log = LoggerFactory.getLogger(LeNumUtil.class); + + @Autowired + @Lazy + private OrderInfoService orderInfoService; + @Autowired + @Lazy + private RedisTemplate redisTemplate; + @Value("${system.order.call.max-num:}") + private Long callMaxNum; + private static final long EPOCH = LocalDateTime.of(2021, 12, 29, 9, 2).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); // @Autowired // @Lazy @@ -50,41 +73,41 @@ public class LeNumUtil { // // return differentFlag ? superNum + "-" + latestNum : superNum + latestNum; // } -// -// public String getMealCode(String prefix, Long canteenId, Long stallId, LocalDate orderDate, Integer mealtimeType) { -// if (!isValidId(canteenId) && !isValidId(stallId)) { -// return ""; -// } else if (LocalDate.now().isAfter(orderDate)) { -// return ""; -// } else { -// String callNumPrefix = CharSequenceUtil.isNotBlank(prefix) ? prefix : ""; -// Long merchantId = TenantContextHolder.getTenantId(); -// String dateStr = orderDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); -// String shopIdStr = isValidId(stallId) ? String.valueOf(stallId) : String.valueOf(canteenId); -// String mealtimeStr = isValidId(mealtimeType) ? String.valueOf(mealtimeType) : "-1"; -// String redisKey = CharSequenceUtil.format("yst:{}:meal-code:{}:{}:{}:{}", new Object[]{merchantId, shopIdStr, dateStr, mealtimeStr, callNumPrefix}); -// log.info("叫号缓存key:{}", redisKey); -// BoundValueOperations valueOperations = this.redisTemplate.boundValueOps(redisKey); -// Object s = valueOperations.get(); -// if (ObjectUtil.isNull(s)) { -// String maxMealCodeOfDate = this.orderInfoService.getMaxMealCodeOfDate(orderDate, mealtimeType, canteenId, stallId); -// log.info("当前最大叫号:{}", maxMealCodeOfDate); -// maxMealCodeOfDate = CharSequenceUtil.removePrefix(maxMealCodeOfDate, callNumPrefix); -// int currentNum = NumberUtil.isNumber(maxMealCodeOfDate) ? NumberUtil.parseInt(maxMealCodeOfDate) : 0; -// Duration expireDuration = LocalDateTimeUtil.between(LocalDateTimeUtil.now(), LocalDateTimeUtil.endOfDay(LocalDateTimeUtil.now())); -// valueOperations.setIfAbsent(currentNum, expireDuration); -// } -// -// Long increment = valueOperations.increment(1L); -// if (this.callMaxNum != null && increment != null && increment > this.callMaxNum) { -// increment = increment % this.callMaxNum; -// } -// -// String format = String.format("%03d", increment); -// log.info("叫的多少号{}", callNumPrefix + format); -// return callNumPrefix + format; -// } -// } + + public String getMealCode(String prefix, Long canteenId, Long stallId, LocalDate orderDate, Integer mealtimeType) { + if (!isValidId(canteenId) && !isValidId(stallId)) { + return ""; + } else if (LocalDate.now().isAfter(orderDate)) { + return ""; + } else { + String callNumPrefix = CharSequenceUtil.isNotBlank(prefix) ? prefix : ""; + Long merchantId = TenantContextHolder.getTenantId(); + String dateStr = orderDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); + String shopIdStr = isValidId(stallId) ? String.valueOf(stallId) : String.valueOf(canteenId); + String mealtimeStr = isValidId(mealtimeType) ? String.valueOf(mealtimeType) : "-1"; + String redisKey = CharSequenceUtil.format("yst:{}:meal-code:{}:{}:{}:{}", new Object[]{merchantId, shopIdStr, dateStr, mealtimeStr, callNumPrefix}); + log.info("叫号缓存key:{}", redisKey); + BoundValueOperations valueOperations = this.redisTemplate.boundValueOps(redisKey); + Object s = valueOperations.get(); + if (ObjectUtil.isNull(s)) { + String maxMealCodeOfDate = this.orderInfoService.getMaxMealCodeOfDate(orderDate, mealtimeType, canteenId, stallId); + log.info("当前最大叫号:{}", maxMealCodeOfDate); + maxMealCodeOfDate = CharSequenceUtil.removePrefix(maxMealCodeOfDate, callNumPrefix); + int currentNum = NumberUtil.isNumber(maxMealCodeOfDate) ? NumberUtil.parseInt(maxMealCodeOfDate) : 0; + Duration expireDuration = LocalDateTimeUtil.between(LocalDateTimeUtil.now(), LocalDateTimeUtil.endOfDay(LocalDateTimeUtil.now())); + valueOperations.setIfAbsent(currentNum, expireDuration); + } + + Long increment = valueOperations.increment(1L); + if (this.callMaxNum != null && increment != null && increment > this.callMaxNum) { + increment = increment % this.callMaxNum; + } + + String format = String.format("%03d", increment); + log.info("叫的多少号{}", callNumPrefix + format); + return callNumPrefix + format; + } + } public static boolean isValidId(Long id) { return id != null && id != -1L && id != 0L; diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/bootstrap.yml b/bonus-modules/bonus-smart-canteen/src/main/resources/bootstrap.yml index 149c891c..80f501d6 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/bootstrap.yml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/bootstrap.yml @@ -92,6 +92,9 @@ system: sqbqrapi: ${SQB_QR_API:https://qr.shouqianba.com/gateway} #收钱吧网关地址 alismsdomain: ${API_ALI_SMS_DOMAIN:dysmsapi.aliyuncs.com} #阿里云短信请求地址 feieapi: ${API_FEI_E:http://api.feieyun.cn} #飞鹅api + order: + call: + max-num: ${ORDER_CALL_MAX_NUM:999} data-config: sm4-key: ${SENSITIVE_SM4KEY:jY7bZz6Pjml+H/WZYfNSNA==}