From 4e87ad22c167404370eb844712349dd22d78e845 Mon Sep 17 00:00:00 2001 From: lifenlong Date: Sat, 19 Jun 2021 14:31:56 +0800 Subject: [PATCH] =?UTF-8?q?=E8=99=9A=E6=8B=9F=E8=AE=A2=E5=8D=95=EF=BC=8C?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E6=A0=B8=E9=AA=8C=E7=A0=81=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=B8=BA8=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/impl/VerificationOrderExecute.java | 42 +++++++++++++++---- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/consumer/src/main/java/cn/lili/event/impl/VerificationOrderExecute.java b/consumer/src/main/java/cn/lili/event/impl/VerificationOrderExecute.java index 22526529..95e2e3a8 100644 --- a/consumer/src/main/java/cn/lili/event/impl/VerificationOrderExecute.java +++ b/consumer/src/main/java/cn/lili/event/impl/VerificationOrderExecute.java @@ -1,34 +1,62 @@ package cn.lili.event.impl; +import cn.hutool.core.util.RandomUtil; import cn.lili.common.utils.CommonUtil; import cn.lili.event.OrderStatusChangeEvent; import cn.lili.modules.order.order.entity.dos.Order; import cn.lili.modules.order.order.entity.dto.OrderMessage; import cn.lili.modules.order.order.entity.enums.OrderStatusEnum; import cn.lili.modules.order.order.service.OrderService; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** * 虚拟商品 + * * @author Bulbasaur * @date: 2021/5/29 9:17 上午 - * */ @Component public class VerificationOrderExecute implements OrderStatusChangeEvent { @Autowired private OrderService orderService; + @Override public void orderChange(OrderMessage orderMessage) { //订单状态为待核验,添加订单添加核验码 - if(orderMessage.getNewStatus().equals(OrderStatusEnum.TAKE)) { - String code = CommonUtil.getRandomNum(); - orderService.update(new LambdaUpdateWrapper() - .set(Order::getVerificationCode, code) - .eq(Order::getSn, orderMessage.getOrderSn())); - } + if (orderMessage.getNewStatus().equals(OrderStatusEnum.TAKE)) { + //获取订单信息 + Order order = orderService.getBySn(orderMessage.getOrderSn()); + //获取随机数,判定是否存在 + String code = getCode(order.getStoreId()); + //设置订单验证码 + orderService.update(new LambdaUpdateWrapper() + .set(Order::getVerificationCode, code) + .eq(Order::getSn, orderMessage.getOrderSn())); + } + } + + /** + * 获取随机数 + * 判断当前店铺下是否使用验证码,如果已使用则重新获取 + * + * @param storeId 店铺ID + * @return + */ + private String getCode(String storeId) { + //获取八位验证码 + String code = Long.toString(RandomUtil.randomLong(10000000, 99999999)); + + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper() + .eq(Order::getVerificationCode, code) + .eq(Order::getStoreId, storeId); + if (orderService.getOne(lambdaQueryWrapper) == null) { + return code; + } else { + return this.getCode(storeId); + } } }