1.添加mybatisPlus依赖
2.排队取号接口
This commit is contained in:
@@ -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<TbCallQueue> {
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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<TbCallTable> {
|
||||
|
||||
}
|
||||
@@ -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<TbCallQueueMapper, TbCallQueue>
|
||||
implements TbCallQueueService{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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<String> 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);
|
||||
}
|
||||
}
|
||||
@@ -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<TbCallTableMapper, TbCallTable>
|
||||
implements TbCallTableService{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user