diff --git a/pom.xml b/pom.xml
index 3dd634a..02ad5b0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -20,6 +20,13 @@
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
com.belerweb
pinyin4j
@@ -107,6 +114,22 @@
1.3.5
+
+ com.baomidou
+ mybatis-plus-boot-starter
+ 3.3.1
+
+
+ org.mybatis
+ mybatis-spring
+
+
+ org.springframework.boot
+ spring-boot-starter-jdbc
+
+
+
+
org.springframework.boot
spring-boot-starter-validation
@@ -219,6 +242,11 @@
weixin-java-miniapp
3.8.0
+
+ junit
+ junit
+ test
+
@@ -278,4 +306,4 @@
-
\ No newline at end of file
+
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/TbCallTableController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/TbCallTableController.java
new file mode 100644
index 0000000..73c86b4
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/TbCallTableController.java
@@ -0,0 +1,42 @@
+package com.chaozhanggui.system.cashierservice.controller;
+
+import com.chaozhanggui.system.cashierservice.entity.dto.TakeNumberDTO;
+import com.chaozhanggui.system.cashierservice.service.TbCallService;
+import com.chaozhanggui.system.cashierservice.sign.Result;
+import lombok.AllArgsConstructor;
+import org.springframework.http.ResponseEntity;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * 叫号
+ */
+@RestController
+@RequestMapping("/callTable")
+@AllArgsConstructor
+public class TbCallTableController {
+
+ private final TbCallService tbCallService;
+
+ @PostMapping("takeNumber")
+ public Result takeNumber(
+ @Validated @RequestBody TakeNumberDTO takeNumberDTO
+ ) {
+ return Result.successWithData(tbCallService.takeNumber(takeNumberDTO));
+ }
+
+ /**
+ * 排号列表
+ * @param openId openId
+ * @param shopId 店铺id
+ * @return data
+ */
+ @GetMapping
+ public Result get(
+ @RequestParam String openId,
+ @RequestParam Integer shopId
+ ) {
+ return Result.successWithData(tbCallService.getList(shopId, openId));
+ }
+
+}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbCashierCartMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbCashierCartMapper.java
index 4f2e299..f620062 100644
--- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbCashierCartMapper.java
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbCashierCartMapper.java
@@ -56,5 +56,6 @@ public interface TbCashierCartMapper {
List selectByOrderId(@Param("orderId") String orderId,@Param("status") String status);
void updateStatusByTableId(@Param("tableId")String tableId,@Param("status") String status);
+ void updateStatusByOrderIdForMini(@Param("tableId")String tableId,@Param("status") String status);
void updateStatusById(@Param("id")Integer id,@Param("status") String status);
-}
\ No newline at end of file
+}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbCallQueue.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbCallQueue.java
new file mode 100644
index 0000000..a57512d
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbCallQueue.java
@@ -0,0 +1,197 @@
+package com.chaozhanggui.system.cashierservice.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import java.io.Serializable;
+import java.util.Date;
+import lombok.Data;
+
+/**
+ *
+ * @TableName tb_call_queue
+ */
+@TableName(value ="tb_call_queue")
+@Data
+public class TbCallQueue implements Serializable {
+ /**
+ *
+ */
+ @TableId(type = IdType.AUTO)
+ private Integer id;
+
+ /**
+ * 叫号台桌类型id
+ */
+ private Integer callTableId;
+
+ /**
+ * 手机号
+ */
+ private String phone;
+
+ /**
+ * 姓名
+ */
+ private String name;
+
+ /**
+ * 店铺名称
+ */
+ private String shopName;
+
+ /**
+ * 店铺id
+ */
+ private Integer shopId;
+
+ /**
+ * -1已取消 0排队中 1叫号中 2已入座 3 已过号
+ */
+ private Integer state;
+
+ /**
+ * 排号时间
+ */
+ private Date createTime;
+
+ /**
+ * 叫号时间
+ */
+ private Date callTime;
+
+ /**
+ * 叫号次数
+ */
+ private Integer callCount;
+
+ /**
+ * 过号时间
+ */
+ private Date passTime;
+
+ /**
+ * 取消时间
+ */
+ private Date cancelTime;
+
+ /**
+ * 备注
+ */
+ private String note;
+
+ /**
+ *
+ */
+ private Integer userId;
+
+ /**
+ *
+ */
+ private String openId;
+
+ /**
+ * 订阅提醒 0未订阅 1已订阅
+ */
+ private Integer subState;
+
+ /**
+ * 确认时间
+ */
+ private Date confirmTime;
+
+ /**
+ * 叫号号码
+ */
+ private String callNum;
+
+ @TableField(exist = false)
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public boolean equals(Object that) {
+ if (this == that) {
+ return true;
+ }
+ if (that == null) {
+ return false;
+ }
+ if (getClass() != that.getClass()) {
+ return false;
+ }
+ TbCallQueue other = (TbCallQueue) that;
+ return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
+ && (this.getCallTableId() == null ? other.getCallTableId() == null : this.getCallTableId().equals(other.getCallTableId()))
+ && (this.getPhone() == null ? other.getPhone() == null : this.getPhone().equals(other.getPhone()))
+ && (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName()))
+ && (this.getShopName() == null ? other.getShopName() == null : this.getShopName().equals(other.getShopName()))
+ && (this.getShopId() == null ? other.getShopId() == null : this.getShopId().equals(other.getShopId()))
+ && (this.getState() == null ? other.getState() == null : this.getState().equals(other.getState()))
+ && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime()))
+ && (this.getCallTime() == null ? other.getCallTime() == null : this.getCallTime().equals(other.getCallTime()))
+ && (this.getCallCount() == null ? other.getCallCount() == null : this.getCallCount().equals(other.getCallCount()))
+ && (this.getPassTime() == null ? other.getPassTime() == null : this.getPassTime().equals(other.getPassTime()))
+ && (this.getCancelTime() == null ? other.getCancelTime() == null : this.getCancelTime().equals(other.getCancelTime()))
+ && (this.getNote() == null ? other.getNote() == null : this.getNote().equals(other.getNote()))
+ && (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId()))
+ && (this.getOpenId() == null ? other.getOpenId() == null : this.getOpenId().equals(other.getOpenId()))
+ && (this.getSubState() == null ? other.getSubState() == null : this.getSubState().equals(other.getSubState()))
+ && (this.getConfirmTime() == null ? other.getConfirmTime() == null : this.getConfirmTime().equals(other.getConfirmTime()))
+ && (this.getCallNum() == null ? other.getCallNum() == null : this.getCallNum().equals(other.getCallNum()));
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
+ result = prime * result + ((getCallTableId() == null) ? 0 : getCallTableId().hashCode());
+ result = prime * result + ((getPhone() == null) ? 0 : getPhone().hashCode());
+ result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
+ result = prime * result + ((getShopName() == null) ? 0 : getShopName().hashCode());
+ result = prime * result + ((getShopId() == null) ? 0 : getShopId().hashCode());
+ result = prime * result + ((getState() == null) ? 0 : getState().hashCode());
+ result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode());
+ result = prime * result + ((getCallTime() == null) ? 0 : getCallTime().hashCode());
+ result = prime * result + ((getCallCount() == null) ? 0 : getCallCount().hashCode());
+ result = prime * result + ((getPassTime() == null) ? 0 : getPassTime().hashCode());
+ result = prime * result + ((getCancelTime() == null) ? 0 : getCancelTime().hashCode());
+ result = prime * result + ((getNote() == null) ? 0 : getNote().hashCode());
+ result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode());
+ result = prime * result + ((getOpenId() == null) ? 0 : getOpenId().hashCode());
+ result = prime * result + ((getSubState() == null) ? 0 : getSubState().hashCode());
+ result = prime * result + ((getConfirmTime() == null) ? 0 : getConfirmTime().hashCode());
+ result = prime * result + ((getCallNum() == null) ? 0 : getCallNum().hashCode());
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append(getClass().getSimpleName());
+ sb.append(" [");
+ sb.append("Hash = ").append(hashCode());
+ sb.append(", id=").append(id);
+ sb.append(", callTableId=").append(callTableId);
+ sb.append(", phone=").append(phone);
+ sb.append(", name=").append(name);
+ sb.append(", shopName=").append(shopName);
+ sb.append(", shopId=").append(shopId);
+ sb.append(", state=").append(state);
+ sb.append(", createTime=").append(createTime);
+ sb.append(", callTime=").append(callTime);
+ sb.append(", callCount=").append(callCount);
+ sb.append(", passTime=").append(passTime);
+ sb.append(", cancelTime=").append(cancelTime);
+ sb.append(", note=").append(note);
+ sb.append(", userId=").append(userId);
+ sb.append(", openId=").append(openId);
+ sb.append(", subState=").append(subState);
+ sb.append(", confirmTime=").append(confirmTime);
+ sb.append(", callNum=").append(callNum);
+ sb.append(", serialVersionUID=").append(serialVersionUID);
+ sb.append("]");
+ return sb.toString();
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbCallTable.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbCallTable.java
new file mode 100644
index 0000000..a917dd6
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbCallTable.java
@@ -0,0 +1,149 @@
+package com.chaozhanggui.system.cashierservice.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import java.io.Serializable;
+import java.util.Date;
+import lombok.Data;
+
+/**
+ *
+ * @TableName tb_call_table
+ */
+@TableName(value ="tb_call_table")
+@Data
+public class TbCallTable implements Serializable {
+ /**
+ *
+ */
+ @TableId(type = IdType.AUTO)
+ private Integer id;
+
+ /**
+ * 名称
+ */
+ private String name;
+
+ /**
+ * 描述
+ */
+ private String note;
+
+ /**
+ * 等待时间分钟
+ */
+ private Integer waitTime;
+
+ /**
+ * 前缀
+ */
+ private String prefix;
+
+ /**
+ * 起始号码
+ */
+ private Integer start;
+
+ /**
+ * 临近几桌提醒
+ */
+ private Integer nearNum;
+
+ /**
+ * 0禁用 1使用
+ */
+ private Integer state;
+
+ /**
+ * 店铺id
+ */
+ private Integer shopId;
+
+ /**
+ * 二维码地址
+ */
+ private String qrcode;
+
+ /**
+ *
+ */
+ private Date createTime;
+
+ /**
+ *
+ */
+ private Date updateTime;
+
+ @TableField(exist = false)
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public boolean equals(Object that) {
+ if (this == that) {
+ return true;
+ }
+ if (that == null) {
+ return false;
+ }
+ if (getClass() != that.getClass()) {
+ return false;
+ }
+ TbCallTable other = (TbCallTable) that;
+ return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
+ && (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName()))
+ && (this.getNote() == null ? other.getNote() == null : this.getNote().equals(other.getNote()))
+ && (this.getWaitTime() == null ? other.getWaitTime() == null : this.getWaitTime().equals(other.getWaitTime()))
+ && (this.getPrefix() == null ? other.getPrefix() == null : this.getPrefix().equals(other.getPrefix()))
+ && (this.getStart() == null ? other.getStart() == null : this.getStart().equals(other.getStart()))
+ && (this.getNearNum() == null ? other.getNearNum() == null : this.getNearNum().equals(other.getNearNum()))
+ && (this.getState() == null ? other.getState() == null : this.getState().equals(other.getState()))
+ && (this.getShopId() == null ? other.getShopId() == null : this.getShopId().equals(other.getShopId()))
+ && (this.getQrcode() == null ? other.getQrcode() == null : this.getQrcode().equals(other.getQrcode()))
+ && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime()))
+ && (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime()));
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
+ result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
+ result = prime * result + ((getNote() == null) ? 0 : getNote().hashCode());
+ result = prime * result + ((getWaitTime() == null) ? 0 : getWaitTime().hashCode());
+ result = prime * result + ((getPrefix() == null) ? 0 : getPrefix().hashCode());
+ result = prime * result + ((getStart() == null) ? 0 : getStart().hashCode());
+ result = prime * result + ((getNearNum() == null) ? 0 : getNearNum().hashCode());
+ result = prime * result + ((getState() == null) ? 0 : getState().hashCode());
+ result = prime * result + ((getShopId() == null) ? 0 : getShopId().hashCode());
+ result = prime * result + ((getQrcode() == null) ? 0 : getQrcode().hashCode());
+ result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode());
+ result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode());
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append(getClass().getSimpleName());
+ sb.append(" [");
+ sb.append("Hash = ").append(hashCode());
+ sb.append(", id=").append(id);
+ sb.append(", name=").append(name);
+ sb.append(", note=").append(note);
+ sb.append(", waitTime=").append(waitTime);
+ sb.append(", prefix=").append(prefix);
+ sb.append(", start=").append(start);
+ sb.append(", nearNum=").append(nearNum);
+ sb.append(", state=").append(state);
+ sb.append(", shopId=").append(shopId);
+ sb.append(", qrcode=").append(qrcode);
+ sb.append(", createTime=").append(createTime);
+ sb.append(", updateTime=").append(updateTime);
+ sb.append(", serialVersionUID=").append(serialVersionUID);
+ sb.append("]");
+ return sb.toString();
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/BaseCallTableDTO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/BaseCallTableDTO.java
new file mode 100644
index 0000000..c431171
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/BaseCallTableDTO.java
@@ -0,0 +1,13 @@
+package com.chaozhanggui.system.cashierservice.entity.dto;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+
+@Data
+public class BaseCallTableDTO {
+ @NotNull
+ private Integer callTableId;
+ @NotNull
+ private Integer shopId;
+}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/TakeNumberDTO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/TakeNumberDTO.java
new file mode 100644
index 0000000..1f19574
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/TakeNumberDTO.java
@@ -0,0 +1,18 @@
+package com.chaozhanggui.system.cashierservice.entity.dto;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+
+@EqualsAndHashCode(callSuper = true)
+@Data
+public class TakeNumberDTO extends BaseCallTableDTO{
+ @NotNull
+ private String phone;
+ private String note;
+ private String name;
+ @NotBlank
+ private String openId;
+}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/CallQueueInfoVO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/CallQueueInfoVO.java
new file mode 100644
index 0000000..417f470
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/CallQueueInfoVO.java
@@ -0,0 +1,14 @@
+package com.chaozhanggui.system.cashierservice.entity.vo;
+
+import lombok.Data;
+
+@Data
+public class CallQueueInfoVO {
+ private Integer id;
+ private String tableName;
+ private String tableNote;
+ private Integer waitingCount;
+ private Integer waitTime;
+ private Integer state;
+ private String callNum;
+}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/mapper/TbCallQueueMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/mapper/TbCallQueueMapper.java
new file mode 100644
index 0000000..4acebd9
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/mapper/TbCallQueueMapper.java
@@ -0,0 +1,23 @@
+package com.chaozhanggui.system.cashierservice.mapper;
+
+import com.chaozhanggui.system.cashierservice.entity.TbCallQueue;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.chaozhanggui.system.cashierservice.entity.vo.CallQueueInfoVO;
+import org.apache.ibatis.annotations.Select;
+
+import java.util.List;
+
+/**
+* @author Administrator
+* @description 针对表【tb_call_queue】的数据库操作Mapper
+* @createDate 2024-09-13 13:44:26
+* @Entity com.chaozhanggui.system.cashierservice.entity.TbCallQueue
+*/
+public interface TbCallQueueMapper extends BaseMapper {
+
+ List selectInfoByOpenId(Integer shopId, String openId);
+}
+
+
+
+
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/mapper/TbCallTableMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/mapper/TbCallTableMapper.java
new file mode 100644
index 0000000..adefb7b
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/mapper/TbCallTableMapper.java
@@ -0,0 +1,18 @@
+package com.chaozhanggui.system.cashierservice.mapper;
+
+import com.chaozhanggui.system.cashierservice.entity.TbCallTable;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+* @author Administrator
+* @description 针对表【tb_call_table】的数据库操作Mapper
+* @createDate 2024-09-13 13:44:34
+* @Entity com.chaozhanggui.system.cashierservice.entity.TbCallTable
+*/
+public interface TbCallTableMapper extends BaseMapper {
+
+}
+
+
+
+
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisCst.java b/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisCst.java
index 45a477b..ea2cee9 100644
--- a/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisCst.java
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/redis/RedisCst.java
@@ -26,13 +26,31 @@ public class RedisCst {
public static final String CREATE_ORDER_LOCK = "CREATE_ORDER_LOCK:";
public static final String SEND_STOCK_WARN_MSG = "SEND_STOCK_WARN_MSG:";
public static final String SONG_PAY_LOCK = "song_pay_lock:";
- public static final String ORDER_PRINT_PRO = "ORDER_PRINT_PRODUCT:";
- public static final String ORDER_PRINT = "ORDER_PRINT:";
+ public static final String ORDER_PRINT_PRO = "ORDER_PRINT_PRODUCT:";
+ public static final String ORDER_PRINT = "ORDER_PRINT:";
- static String CURRENT_TABLE_ORDER = "CURRENT_TABLE_ORDER:";
+ static final String CURRENT_TABLE_ORDER = "CURRENT_TABLE_ORDER:";
+
+ // 排队取号全局号码
+ public static final String TABLE_CALL_NUMBER = "TABLE_CALL_NUMBER:";
+
+ // 全局锁
+ public static final String LOCK_KEY = "LOCK:";
public static String getCurrentOrderKey(String tableId, String shopId) {
return CURRENT_TABLE_ORDER + shopId + ":" + tableId;
}
+
+ public static String getTableCallNumKey(Integer shopId, Integer callTableId) {
+ return TABLE_CALL_NUMBER + shopId + ":" + callTableId;
+ }
+
+ public static String getLockKey(String sign, Object... args) {
+ StringBuilder key = new StringBuilder(LOCK_KEY + ":" + sign + ":");
+ for (Object arg : args) {
+ key.append(":").append(arg.toString());
+ }
+ return key.toString();
+ }
}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/TbCallQueueService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbCallQueueService.java
new file mode 100644
index 0000000..f124508
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbCallQueueService.java
@@ -0,0 +1,13 @@
+package com.chaozhanggui.system.cashierservice.service;
+
+import com.chaozhanggui.system.cashierservice.entity.TbCallQueue;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+* @author Administrator
+* @description 针对表【tb_call_queue】的数据库操作Service
+* @createDate 2024-09-13 13:44:26
+*/
+public interface TbCallQueueService extends IService {
+
+}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/TbCallService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbCallService.java
new file mode 100644
index 0000000..655f0e2
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbCallService.java
@@ -0,0 +1,9 @@
+package com.chaozhanggui.system.cashierservice.service;
+
+import com.chaozhanggui.system.cashierservice.entity.dto.TakeNumberDTO;
+
+public interface TbCallService {
+ Object takeNumber(TakeNumberDTO takeNumberDTO);
+
+ Object getList(Integer shopId, String openId);
+}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/TbCallTableService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbCallTableService.java
new file mode 100644
index 0000000..ba6dac5
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbCallTableService.java
@@ -0,0 +1,16 @@
+package com.chaozhanggui.system.cashierservice.service;
+
+import com.chaozhanggui.system.cashierservice.entity.TbCallTable;
+import com.baomidou.mybatisplus.extension.service.IService;
+import org.springframework.context.annotation.Primary;
+import org.springframework.stereotype.Service;
+
+/**
+* @author Administrator
+* @description 针对表【tb_call_table】的数据库操作Service
+* @createDate 2024-09-13 13:44:34
+*/
+@Service
+public interface TbCallTableService extends IService {
+
+}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbCallQueueServiceImpl.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbCallQueueServiceImpl.java
new file mode 100644
index 0000000..1f861de
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbCallQueueServiceImpl.java
@@ -0,0 +1,24 @@
+package com.chaozhanggui.system.cashierservice.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.chaozhanggui.system.cashierservice.entity.TbCallQueue;
+import com.chaozhanggui.system.cashierservice.service.TbCallQueueService;
+import com.chaozhanggui.system.cashierservice.mapper.TbCallQueueMapper;
+import org.springframework.context.annotation.Primary;
+import org.springframework.stereotype.Service;
+
+/**
+* @author Administrator
+* @description 针对表【tb_call_queue】的数据库操作Service实现
+* @createDate 2024-09-13 13:44:26
+*/
+@Service
+@Primary
+public class TbCallQueueServiceImpl extends ServiceImpl
+ implements TbCallQueueService{
+
+}
+
+
+
+
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbCallServiceImpl.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbCallServiceImpl.java
new file mode 100644
index 0000000..f0a260f
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbCallServiceImpl.java
@@ -0,0 +1,98 @@
+package com.chaozhanggui.system.cashierservice.service.impl;
+
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.StrUtil;
+import com.chaozhanggui.system.cashierservice.dao.TbShopInfoMapper;
+import com.chaozhanggui.system.cashierservice.entity.TbCallQueue;
+import com.chaozhanggui.system.cashierservice.entity.TbCallTable;
+import com.chaozhanggui.system.cashierservice.entity.TbShopInfo;
+import com.chaozhanggui.system.cashierservice.entity.dto.TakeNumberDTO;
+import com.chaozhanggui.system.cashierservice.exception.MsgException;
+import com.chaozhanggui.system.cashierservice.mapper.TbCallQueueMapper;
+import com.chaozhanggui.system.cashierservice.redis.RedisCst;
+import com.chaozhanggui.system.cashierservice.service.TbCallQueueService;
+import com.chaozhanggui.system.cashierservice.service.TbCallService;
+import com.chaozhanggui.system.cashierservice.service.TbCallTableService;
+import com.chaozhanggui.system.cashierservice.util.Utils;
+import lombok.AllArgsConstructor;
+import org.springframework.context.annotation.Primary;
+import org.springframework.data.redis.core.StringRedisTemplate;
+import org.springframework.stereotype.Service;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+@Service
+@AllArgsConstructor
+@Primary
+public class TbCallServiceImpl implements TbCallService {
+ private final TbCallQueueService callQueueService;
+ private final TbCallTableService callTableService;
+ private final TbShopInfoMapper shopInfoMapper;
+ private final TbCallQueueMapper callQueueMapper;
+ private final StringRedisTemplate redisTemplate;
+
+ private String getCallNumber(Integer shopId, TbCallTable callTable) {
+ return Utils.runFunAndCheckKey(() -> {
+ String callNumKey = RedisCst.getTableCallNumKey(shopId, callTable.getId());
+ String value = redisTemplate.opsForValue().get(callNumKey);
+ AtomicReference newVal = new AtomicReference<>("");
+ // 初始化
+ if (StrUtil.isBlank(value)) {
+ Boolean setFlag = Utils.runFunAndRetry(() -> redisTemplate.opsForValue().setIfAbsent(callNumKey, callTable.getStart().toString()), flag -> !flag,
+ r -> newVal.set(redisTemplate.opsForValue().get(callNumKey)));
+
+ if (setFlag) {
+ return callTable.getPrefix() + callTable.getStart();
+ }else if (StrUtil.isNotBlank(newVal.get())){
+ value = String.valueOf((Integer.parseInt(newVal.get()) + 1));
+ redisTemplate.opsForValue().set(callNumKey, value);
+ return callTable.getPrefix() + value;
+ }else {
+ throw new MsgException("生成排队号码失败");
+ }
+
+ }else {
+ value = String.valueOf((Integer.parseInt(value) + 1));
+ redisTemplate.opsForValue().set(callNumKey, value);
+ return callTable.getPrefix() + value;
+ }
+ }, redisTemplate, RedisCst.getLockKey("UPDATE_TABLE", shopId, callTable.getId()));
+ }
+
+ @Override
+ public Object takeNumber(TakeNumberDTO takeNumberDTO) {
+ TbShopInfo shopInfo = shopInfoMapper.selectByPrimaryKey(takeNumberDTO.getShopId());
+ if (shopInfo == null) {
+ throw new MsgException("店铺信息不存在");
+ }
+
+ TbCallTable callTable = callTableService.lambdaQuery()
+ .eq(TbCallTable::getShopId, takeNumberDTO.getShopId())
+ .eq(TbCallTable::getId, takeNumberDTO.getCallTableId()).one();
+ if (callTable == null) {
+ throw new MsgException("桌型不存在");
+ }
+
+ TbCallQueue callQueue = callQueueService.lambdaQuery()
+ .eq(TbCallQueue::getPhone, takeNumberDTO.getPhone())
+ .eq(TbCallQueue::getShopId, takeNumberDTO.getShopId())
+ .eq(TbCallQueue::getCallTableId, takeNumberDTO.getCallTableId()).one();
+ if (callQueue != null) {
+ throw new MsgException("您已取号,请勿重复取号");
+ }
+
+ callQueue = BeanUtil.copyProperties(takeNumberDTO, TbCallQueue.class);
+ callQueue.setSubState(1);
+ callQueue.setCreateTime(DateUtil.date());
+ callQueue.setShopId(shopInfo.getId());
+ callQueue.setShopName(shopInfo.getShopName());
+ callQueue.setCallNum(getCallNumber(takeNumberDTO.getShopId(), callTable));
+ return callQueueService.save(callQueue);
+ }
+
+ @Override
+ public Object getList(Integer shopId, String openId) {
+ return callQueueMapper.selectInfoByOpenId(shopId, openId);
+ }
+}
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbCallTableServiceImpl.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbCallTableServiceImpl.java
new file mode 100644
index 0000000..d702ee2
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbCallTableServiceImpl.java
@@ -0,0 +1,24 @@
+package com.chaozhanggui.system.cashierservice.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.chaozhanggui.system.cashierservice.entity.TbCallTable;
+import com.chaozhanggui.system.cashierservice.service.TbCallTableService;
+import com.chaozhanggui.system.cashierservice.mapper.TbCallTableMapper;
+import org.springframework.context.annotation.Primary;
+import org.springframework.stereotype.Service;
+
+/**
+* @author Administrator
+* @description 针对表【tb_call_table】的数据库操作Service实现
+* @createDate 2024-09-13 13:44:34
+*/
+@Service
+@Primary
+public class TbCallTableServiceImpl extends ServiceImpl
+ implements TbCallTableService{
+
+}
+
+
+
+
diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/Utils.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/Utils.java
new file mode 100644
index 0000000..3349961
--- /dev/null
+++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/Utils.java
@@ -0,0 +1,93 @@
+package com.chaozhanggui.system.cashierservice.util;
+
+import com.chaozhanggui.system.cashierservice.exception.MsgException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.data.redis.core.StringRedisTemplate;
+
+import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.function.Supplier;
+
+public class Utils {
+ public static int retryCount = 5;
+ private static final Logger log = LoggerFactory.getLogger(Utils.class);
+
+ public static void catchErrNoReturn(Supplier supplier) {
+ try {
+ supplier.get();
+ }catch (Exception e) {
+ log.error("执行方法出现异常", e);
+ }
+ }
+
+ public static void runFunAndRetryNoReturn(
+ Supplier function,
+ Function check, Consumer errFun) {
+ log.info("工具类开始执行函数");
+ R result = function.get();
+ boolean flag = check.apply(result);
+
+ log.info("执行结果: {}", result);
+
+ while (flag && retryCount-- > 0) {
+ log.info("执行函数失败, 剩余尝试次数{}", retryCount);
+ result = function.get();
+ log.info("执行结果: {}", result);
+ flag = check.apply(result);
+ }
+
+ if (flag) {
+ errFun.accept(result);
+ }
+ }
+
+ public static T runFunAndCheckKey(Supplier supplier, StringRedisTemplate redisTemplate, String lockKey) {
+ try{
+ // 创建线程id, 用作判断
+ String clientId = UUID.randomUUID().toString();
+ // 设置分布式锁
+ boolean lock = Boolean.TRUE.equals(redisTemplate.opsForValue().setIfAbsent(lockKey, clientId, 30, TimeUnit.MILLISECONDS));
+ int count = 0;
+ while (!lock) {
+ if (count++ > 100) {
+ throw new MsgException("系统繁忙, 稍后再试");
+ }
+ Thread.sleep(20);
+ lock = Boolean.TRUE.equals(redisTemplate.opsForValue().setIfAbsent(lockKey, clientId, 30, TimeUnit.MILLISECONDS));
+ }
+ return supplier.get();
+ } catch (RuntimeException e){
+ log.info("执行出错:{}", e.getMessage());
+ throw e;
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ } finally{
+ redisTemplate.delete(lockKey);
+ }
+ }
+
+ public static R runFunAndRetry(
+ Supplier function,
+ Function check, Consumer errFun) {
+ log.info("工具类开始执行函数");
+ R result = function.get();
+ boolean flag = check.apply(result);
+
+ log.info("执行结果: {}", result);
+
+ while (flag && retryCount-- > 0) {
+ log.info("执行函数失败, 剩余尝试次数{}", retryCount);
+ result = function.get();
+ log.info("执行结果: {}", result);
+ flag = check.apply(result);
+ }
+
+ if (flag) {
+ errFun.accept(result);
+ }
+ return result;
+ }
+}
diff --git a/src/main/resources/mapper/TbCallQueueMapper.xml b/src/main/resources/mapper/TbCallQueueMapper.xml
new file mode 100644
index 0000000..2734db4
--- /dev/null
+++ b/src/main/resources/mapper/TbCallQueueMapper.xml
@@ -0,0 +1,62 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ id,call_table_id,phone,
+ name,shop_name,shop_id,
+ state,create_time,call_time,
+ call_count,pass_time,cancel_time,
+ note,user_id,open_id,
+ sub_state,confirm_time
+
+
+
diff --git a/src/main/resources/mapper/TbCallTableMapper.xml b/src/main/resources/mapper/TbCallTableMapper.xml
new file mode 100644
index 0000000..2e1f86e
--- /dev/null
+++ b/src/main/resources/mapper/TbCallTableMapper.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ id,name,note,
+ wait_time,prefix,start,
+ near_num,state,shop_id,
+ qrcode,create_time,update_time
+
+
diff --git a/src/main/resources/mapper/TbCashierCartMapper.xml b/src/main/resources/mapper/TbCashierCartMapper.xml
index 50c4e1a..74ed684 100644
--- a/src/main/resources/mapper/TbCashierCartMapper.xml
+++ b/src/main/resources/mapper/TbCashierCartMapper.xml
@@ -369,6 +369,10 @@
update tb_cashier_cart set status = #{status} where table_id = #{tableId} and status = 'create'
+
+ update tb_cashier_cart set status = #{status} where table_id = #{tableId} and status = 'create' and master_id is null
+
+
update tb_cashier_cart set status = #{status} where id = #{id}
@@ -382,4 +386,4 @@
-
\ No newline at end of file
+