From d9812599955dbff7eccf8821416f8ab9d0887cbe Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Wed, 21 Aug 2024 13:29:30 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BB=A3=E5=AE=A2=E4=B8=8B=E5=8D=95=20?= =?UTF-8?q?=E6=8C=82=E5=8D=95=E4=B8=8D=E5=A2=9E=E5=8A=A0masterId?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/shopimpl/TbShopTableServiceImpl.java | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java index d6921f6a..a3e67612 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java @@ -290,7 +290,8 @@ public class TbShopTableServiceImpl implements TbShopTableService { if (shopTable == null) { throw new BadRequestException("桌码不存在,桌码" + tableId); } - if (!shopTable.getStatus().equals("opening") && !shopTable.getStatus().equals("idle")) { + if (!shopTable.getStatus().equals("using") && !shopTable.getStatus().equals("idle") + && !shopTable.getStatus().equals("pending")) { throw new BadRequestException("当前台桌非开台状态"); } return shopTable; @@ -663,6 +664,16 @@ public class TbShopTableServiceImpl implements TbShopTableService { return "DDPL" + date + randomNum; } + public synchronized void addGlobalCode(String day, String clientType, String shopId) { + String code = redisTemplate.opsForValue().get("SHOP:CODE:" + clientType + ":" + shopId + ":" + day); + if (StrUtil.isBlank(code)) { + redisTemplate.opsForValue().set("SHOP:CODE:" + clientType + ":" + shopId + ":" + day, "1"); + }else { + redisTemplate.opsForValue().get("SHOP:CODE:" + clientType + ":" + shopId + ":" + (Integer.parseInt(code) + 1)); + } + redisTemplate.opsForValue().setIfAbsent("SHOP:CODE:SET" + clientType + ":" + shopId + ":" + day, "1"); + } + public synchronized String generateOrderCode(String day, String clientType, String shopId) { String code = redisTemplate.opsForValue().get("SHOP:CODE:" + clientType + ":" + shopId + ":" + day); // 使用顺序递增的计数器生成取餐码 @@ -695,7 +706,8 @@ public class TbShopTableServiceImpl implements TbShopTableService { TbMerchantAccount merchantAccount = merchantAccountMapper.selectOne(new LambdaQueryWrapper().eq(TbMerchantAccount::getAccount, account)); String day = DateUtils.getDay(); JSONObject jsonObject = new JSONObject(); - String key = "SHOP:CODE:USER:pc" + ":" + shopId + ":" + day + ":" + shopId; + // 当前台桌码 + String key = "SHOP:CODE:USER:pc" + ":" + shopId + ":" + day + ":" + tableId; String userCode = redisTemplate.opsForValue().get(key); if (StringUtils.isEmpty(userCode) || "null".equals(userCode) || "#null".equals(userCode)) { @@ -839,7 +851,9 @@ public class TbShopTableServiceImpl implements TbShopTableService { cashierCart.setUpdatedAt(System.currentTimeMillis()); cashierCartMapper.updateById(cashierCart); } - + if (isFirst) { + addGlobalCode(day, "pc", String.valueOf(createOrderDTO.getShopId())); + } // 推送耗材信息 pushConsMsg(orderInfo, cashierCarts); @@ -1008,18 +1022,11 @@ public class TbShopTableServiceImpl implements TbShopTableService { orderInfo.setPayType("cash"); orderInfo.setStatus("closed"); orderInfo.setPayOrderNo("cash".concat(SnowFlakeUtil.generateOrderNo())); - String masterId = getMasterId(Integer.valueOf(orderInfo.getShopId()), Long.valueOf(orderInfo.getTableId()), null).toString(); - orderInfo.setMasterId(masterId); orderInfoMapper.updateById(orderInfo); - String day = DateUtils.getDay(); - String key = "SHOP:CODE:USER:pc" + ":" + payDTO.getShopId() + ":" + day + ":" + orderInfo.getTableId(); - - redisTemplate.delete(key); //更新购物车状态 TbCashierCart cashierCart = new TbCashierCart(); cashierCart.setStatus("final"); - cashierCart.setMasterId(masterId); int cartCount = cashierCartMapper.update(cashierCart, new LambdaUpdateWrapper() .eq(TbCashierCart::getOrderId, payDTO.getOrderId())); @@ -1051,6 +1058,9 @@ public class TbShopTableServiceImpl implements TbShopTableService { .eq(TbShopTable::getQrcode, orderInfo.getTableId()) .set(TbShopTable::getStatus, TableStateEnum.IDLE.getState())); + String day = DateUtils.getDay(); + String key = "SHOP:CODE:USER:pc" + ":" + payDTO.getShopId() + ":" + day + ":" + orderInfo.getTableId(); + redisTemplate.delete(key); return null; }