小程序叫号相关

This commit is contained in:
张松 2025-03-20 14:53:08 +08:00
parent 8f46ce129e
commit baabf01e51
8 changed files with 220 additions and 8 deletions

View File

@ -136,8 +136,8 @@ public class CallTableController {
*/
@SaAdminCheckPermission(value = "callTable:queue:list", name = "获取叫号队列")
@GetMapping("queue")
public CzgResult<Page<CallQueue>> getQueue(Long callTableId, Integer state) {
return CzgResult.success(callTableService.getQueue(StpKit.USER.getShopId(), callTableId, state));
public CzgResult<Page<CallQueue>> getQueue(Long callTableId, Integer state, String openId) {
return CzgResult.success(callTableService.getQueue(StpKit.USER.getShopId(), openId, callTableId, state));
}

View File

@ -0,0 +1,77 @@
package com.czg.controller.user;
import com.czg.account.dto.calltable.CallSubMsgDTO;
import com.czg.account.dto.calltable.CallTableNumDTO;
import com.czg.account.dto.calltable.CallTablePage;
import com.czg.account.dto.calltable.TakeNumberDTO;
import com.czg.account.entity.CallQueue;
import com.czg.account.service.CallTableService;
import com.czg.annotation.SaAdminCheckPermission;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.mybatisflex.core.paginate.Page;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
/**
* 小程序叫号管理
* @author Administrator
*/
@RestController
@RequestMapping("/user/callTable")
public class UCallTableController {
@Resource
private CallTableService callTableService;
/**
* 获取叫号号码
*/
@PostMapping("takeNumber")
public CzgResult<CallTableNumDTO> takeNumber(@Validated @RequestBody TakeNumberDTO takeNumberDTO) {
return CzgResult.success(callTableService.takeNumber(StpKit.USER.getShopId(), takeNumberDTO));
}
/**
* 获取叫号队列
*
* @param callTableId 桌型id
* @param state 状态 -1已取消 0排队中 1叫号中 2已入座 3 已过号
* @return 分页数据
*/
// @GetMapping("queue")
public CzgResult<Page<CallQueue>> getQueue(@RequestParam String openId, Long callTableId, Integer state) {
return CzgResult.success(callTableService.getQueue(StpKit.USER.getShopId(), openId, callTableId, state));
}
/**
* 叫号桌型获取
*
* @param callTableId 叫号桌型id
* @param state 0禁用 1使用
* @return 分页数据
*/
@GetMapping
public CzgResult<CallTablePage> get(Long callTableId, Integer state) {
return CzgResult.success(callTableService.get(StpKit.USER.getShopId(), callTableId, state));
}
/**
* 根据店铺id和openId获取当前叫号号码
* @param queueId 队列id
* @return 状态
*/
@GetMapping("status")
public CzgResult<?> getStatus(@RequestParam String openId, @RequestParam(required = false) Long queueId) {
return CzgResult.success(callTableService.getStatus(StpKit.USER.getShopId(), openId, queueId));
}
@PostMapping("subMsg")
public CzgResult<Boolean> subMsg(
@Validated @RequestBody CallSubMsgDTO subMsgDTO
) {
return CzgResult.success(callTableService.subMsg(subMsgDTO));
}
}

View File

@ -30,4 +30,8 @@ public class TakeNumberDTO extends BaseCallTableDTO{
* 姓名
*/
private String name;
/**
* openId
*/
private String openId;
}

View File

@ -29,7 +29,7 @@ public interface CallTableService extends IService<CallTable> {
boolean updateInfo(Long shopId, UpdateCallQueueDTO updateCallQueueDTO);
Page<CallQueue> getQueue(Long shopId, Long callTableId, Integer state);
Page<CallQueue> getQueue(Long shopId, String openId, Long callTableId, Integer state);
Page<CallRecordVO> getCallRecord(Long shopId, Integer callTableId);
@ -38,4 +38,6 @@ public interface CallTableService extends IService<CallTable> {
boolean updateConfig(Long shopId, UpdateConfigDTO configDTO);
boolean subMsg(CallSubMsgDTO subMsgDTO);
Object getStatus(Long shopId, String openId, Long queueId);
}

View File

@ -0,0 +1,47 @@
package com.czg.account.vo;
import lombok.Data;
/**
* @author Administrator
*/
@Data
public class CallQueueInfoVO {
/**
* 叫号队列idqueueId
*/
private Long id;
/**
* 桌型名称
*/
private String tableName;
/**
* 桌型备注
*/
private String tableNote;
/**
* 等待人数
*/
private Integer waitingCount;
/**
* 等待时间
*/
private Integer waitTime;
/**
* -1已取消 0排队中 1叫号中 2已入座 3 已过号
*/
private Integer state;
/**
* 叫号号码
*/
private String callNum;
private String shopState;
/**
* 店铺名称
*/
private String shopName;
/**
* logo
*/
private String logo;
}

View File

@ -1,9 +1,13 @@
package com.czg.service.account.mapper;
import com.czg.account.dto.calltable.CallRecordVO;
import com.czg.account.vo.CallQueueInfoVO;
import com.mybatisflex.core.BaseMapper;
import com.czg.account.entity.CallQueue;
import com.mybatisflex.core.paginate.Page;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 叫号排号队列表 映射层
@ -16,4 +20,5 @@ public interface CallQueueMapper extends BaseMapper<CallQueue> {
Page<CallRecordVO> selectCallRecord();
long selectCallRecord_COUNT();
List<CallQueueInfoVO> selectInfoByOpenId(@Param("shopId") Long shopId, @Param("openId") String openId, @Param("today") String today, @Param("queueId") Long queueId);
}

View File

@ -8,6 +8,7 @@ import cn.hutool.extra.qrcode.QrConfig;
import com.czg.account.dto.calltable.*;
import com.czg.account.entity.*;
import com.czg.account.service.*;
import com.czg.account.vo.CallQueueInfoVO;
import com.czg.config.RabbitPublisher;
import com.czg.config.RedisCst;
import com.czg.exception.ApiNotPrintException;
@ -29,10 +30,7 @@ import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.data.redis.core.StringRedisTemplate;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Collections;
import java.util.List;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
@ -467,7 +465,7 @@ public class CallTableServiceImpl extends ServiceImpl<CallTableMapper, CallTable
}
@Override
public Page<CallQueue> getQueue(Long shopId, Long callTableId, Integer state) {
public Page<CallQueue> getQueue(Long shopId, String openId, Long callTableId, Integer state) {
List<Long> tableIds;
if (callTableId != null) {
tableIds = Collections.singletonList(callTableId);
@ -491,6 +489,10 @@ public class CallTableServiceImpl extends ServiceImpl<CallTableMapper, CallTable
query.in(CallQueue::getState, 0, 1);
}
if (StrUtil.isNotBlank(openId)) {
query.eq(CallQueue::getOpenId, openId);
}
Page<CallQueue> pageInfo = callQueueService.page(PageUtil.buildPage(), query
.orderBy(CallQueue::getCreateTime, true)
.orderBy(CallQueue::getState, false));
@ -591,4 +593,24 @@ public class CallTableServiceImpl extends ServiceImpl<CallTableMapper, CallTable
queue.setOpenId(subMsgDTO.getOpenId());
return callQueueService.updateById(queue);
}
@Override
public Object getStatus(Long shopId, String openId, Long queueId) {
List<CallQueueInfoVO> callQueueInfoVOS = callQueueMapper.selectInfoByOpenId(shopId, openId, DateUtil.date().toString("yyyy-MM-dd"), null);
if (callQueueInfoVOS.isEmpty()) {
callQueueInfoVOS = callQueueMapper.selectInfoByOpenId(shopId, openId, DateUtil.date().toString("yyyy-MM-dd"), queueId);
}
if (!callQueueInfoVOS.isEmpty()) {
CallQueueInfoVO callQueueInfoVO = callQueueInfoVOS.getFirst();
CallQueue callQueue = new CallQueue();
callQueue.setOpenId(openId);
callQueue.setId(callQueueInfoVO.getId());
callQueueService.updateById(callQueue);
}
ShopInfo shopInfo = shopInfoService.getById(shopId);
HashMap<String, Object> data = new HashMap<>();
data.put("shopInfo", shopInfo);
data.put("queueInfo", callQueueInfoVOS.isEmpty() ? null : callQueueInfoVOS.getFirst());
return data;
}
}

View File

@ -17,4 +17,59 @@
left join tb_call_table on tb_call_queue.call_table_id = tb_call_table.id
${qwSql}
</select>
<select id="selectInfoByOpenId" resultType="com.czg.account.vo.CallQueueInfoVO">
SELECT
d.shop_name,
d.logo,
d.status AS shop_state,
a.call_num,
a.id, -- 用户的排队记录ID
a.state,
a.user_id, -- 用户ID
b.name AS table_name, -- 桌子名称
b.note AS table_note, -- 桌子备注
(
SELECT COUNT(1)
FROM tb_call_queue c
WHERE
c.call_table_id = a.call_table_id
and c.shop_id=a.shop_id -- 同一张桌子
AND c.create_time &lt; a.create_time -- 在当前用户之前排队
AND c.state IN (0, 1) -- 排队中或等待中的人
AND c.create_day=#{today}
) AS waiting_count, -- 前面有几个人
(
SELECT COUNT(1) * b.wait_time
FROM tb_call_queue c
WHERE
c.call_table_id = a.call_table_id
AND c.shop_id=a.shop_id -- 同一张桌子
AND c.create_time &lt; a.create_time -- 在当前用户之前排队
AND c.state IN (0, 1) -- 排队中或等待中的人
AND c.create_day=#{today}
) AS wait_time -- 预计等待时间
FROM
tb_call_queue a
LEFT JOIN
tb_shop_info d ON a.shop_id = d.id
LEFT JOIN
tb_call_table b ON a.call_table_id = b.id
WHERE
a.shop_id = #{shopId}
AND a.create_day = #{today} -- 替换为目标日期
<if test="queueId != null">
and a.id = #{queueId} and (a.open_id = #{openId} or a.open_id is null)
</if>
<if test="queueId == null">
and a.open_id = #{openId} -- 替换为目标用户的 open_id
</if>
and a.state in (0, 1)
GROUP BY
a.id, a.user_id, b.name, b.note, b.wait_time
ORDER BY
a.create_time asc
</select>
</mapper>