1.排队取号 取号打印小票,增加订阅接口

This commit is contained in:
2024-09-19 15:11:18 +08:00
parent 039f7efec3
commit 6ce85b1d10
9 changed files with 97 additions and 16 deletions

View File

@@ -1,6 +1,8 @@
package com.chaozhanggui.system.cashierservice.controller;
import cn.hutool.core.util.StrUtil;
import com.chaozhanggui.system.cashierservice.entity.dto.BaseCallTableDTO;
import com.chaozhanggui.system.cashierservice.entity.dto.CallSubMsgDTO;
import com.chaozhanggui.system.cashierservice.entity.dto.CancelCallQueueDTO;
import com.chaozhanggui.system.cashierservice.entity.dto.TakeNumberDTO;
import com.chaozhanggui.system.cashierservice.service.TbCallService;
@@ -35,10 +37,14 @@ public class TbCallTableController {
*/
@GetMapping("queue")
public Result get(
@RequestParam String openId,
@RequestParam Integer shopId
@RequestParam(required = false) String openId,
@RequestParam Integer shopId,
@RequestParam(required = false) Integer queueId
) {
return Result.successWithData(tbCallService.getList(shopId, openId));
if (StrUtil.isBlank(openId) && queueId == null) {
return Result.fail("shopId和queueId不能同时为空");
}
return Result.successWithData(tbCallService.getList(shopId, openId, queueId));
}
@GetMapping
@@ -57,10 +63,21 @@ public class TbCallTableController {
@GetMapping("state")
public Result getState(
@RequestParam String openId,
@RequestParam Integer shopId
@RequestParam(required = false) String openId,
@RequestParam Integer shopId,
@RequestParam(required = false) Integer queueId
) {
return Result.successWithData(tbCallService.getState(openId, shopId));
if (StrUtil.isBlank(openId) && queueId == null) {
return Result.fail("shopId和queueId不能同时为空");
}
return Result.successWithData(tbCallService.getState(openId, shopId, queueId));
}
@PutMapping("subMsg")
public Result subMsg(
@RequestBody CallSubMsgDTO subMsgDTO
) {
return Result.successWithData(tbCallService.subMsg(subMsgDTO));
}
}

View File

@@ -0,0 +1,9 @@
package com.chaozhanggui.system.cashierservice.entity.dto;
import lombok.Data;
@Data
public class CallNumPrintDTO {
private Integer callQueueId;
private Integer shopId;
}

View File

@@ -0,0 +1,10 @@
package com.chaozhanggui.system.cashierservice.entity.dto;
import lombok.Data;
@Data
public class CallSubMsgDTO {
private Integer queueId;
private String openId;
private Integer shopId;
}

View File

@@ -14,7 +14,7 @@ import java.util.List;
*/
public interface TbCallQueueMapper extends BaseMapper<TbCallQueue> {
List<CallQueueInfoVO> selectInfoByOpenId(Integer shopId, String openId, String today);
List<CallQueueInfoVO> selectInfoByOpenId(Integer shopId, String openId, String today, Integer queueId);
}

View File

@@ -68,4 +68,10 @@ public interface RabbitConstants {
public static final String BALANCE_QUEUE_PUT="balance_queue_put";
public static final String BALANCE_ROUTINGKEY_PUT="balance_routingkey_put";
String EXCHANGE_PRINT = "exchange.print";
// 排队小票打印
String QUEUE_PRINT_CALL_TABLE = "queue.print.call.table";
String ROUTING_KEY_CALL_TABLE = "routing.call.table";
}

View File

@@ -1,16 +1,19 @@
package com.chaozhanggui.system.cashierservice.service;
import com.chaozhanggui.system.cashierservice.entity.dto.CallSubMsgDTO;
import com.chaozhanggui.system.cashierservice.entity.dto.CancelCallQueueDTO;
import com.chaozhanggui.system.cashierservice.entity.dto.TakeNumberDTO;
public interface TbCallService {
Object takeNumber(TakeNumberDTO takeNumberDTO);
Object getList(Integer shopId, String openId);
Object getList(Integer shopId, String openId, Integer queueId);
Object getAllInfo(Integer shopId);
Object cancel(CancelCallQueueDTO cancelCallQueueDTO);
Object getState(String openId, Integer shopId);
Object getState(String openId, Integer shopId, Integer queueId);
Object subMsg(CallSubMsgDTO subMsgDTO);
}

View File

@@ -3,10 +3,12 @@ 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.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.CallSubMsgDTO;
import com.chaozhanggui.system.cashierservice.entity.dto.CancelCallQueueDTO;
import com.chaozhanggui.system.cashierservice.entity.dto.TakeNumberDTO;
import com.chaozhanggui.system.cashierservice.entity.vo.CallQueueInfoVO;
@@ -16,6 +18,7 @@ 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.MQUtils;
import com.chaozhanggui.system.cashierservice.util.Utils;
import lombok.AllArgsConstructor;
import org.springframework.context.annotation.Primary;
@@ -35,6 +38,7 @@ public class TbCallServiceImpl implements TbCallService {
private final TbShopInfoMapper shopInfoMapper;
private final TbCallQueueMapper callQueueMapper;
private final StringRedisTemplate redisTemplate;
private final MQUtils mQUtils;
private String getCallNumber(Integer shopId, TbCallTable callTable) {
return Utils.runFunAndCheckKey(() -> {
@@ -96,12 +100,17 @@ public class TbCallServiceImpl implements TbCallService {
callQueue.setShopName(shopInfo.getShopName());
callQueue.setCallNum(getCallNumber(takeNumberDTO.getShopId(), callTable));
callQueue.setCreateDay(DateUtil.today());
return callQueueService.save(callQueue);
boolean save = callQueueService.save(callQueue);
// 打印排号票信息
if (save) {
mQUtils.printCallNumTicket(callQueue.getId(), callQueue.getShopId());
}
return save;
}
@Override
public Object getList(Integer shopId, String openId) {
return callQueueMapper.selectInfoByOpenId(shopId, openId, DateUtil.today());
public Object getList(Integer shopId, String openId, Integer queueId) {
return callQueueMapper.selectInfoByOpenId(shopId, openId, DateUtil.today(), queueId);
}
@Override
@@ -120,12 +129,26 @@ public class TbCallServiceImpl implements TbCallService {
@Override
public Object getState(String openId, Integer shopId) {
List<CallQueueInfoVO> callQueueInfoVOS = callQueueMapper.selectInfoByOpenId(shopId, openId, DateUtil.today());
public Object getState(String openId, Integer shopId, Integer queueId) {
List<CallQueueInfoVO> callQueueInfoVOS = callQueueMapper.selectInfoByOpenId(shopId, openId, DateUtil.today(), queueId);
TbShopInfo shopInfo = shopInfoMapper.selectByPrimaryKey(shopId);
HashMap<String, Object> data = new HashMap<>();
data.put("shopInfo", shopInfo);
data.put("queueInfo", callQueueInfoVOS.isEmpty() ? null : callQueueInfoVOS.get(0));
return data;
}
@Override
public Object subMsg(CallSubMsgDTO subMsgDTO) {
TbCallQueue queue = callQueueMapper.selectOne(new LambdaQueryWrapper<TbCallQueue>()
.eq(TbCallQueue::getShopId, subMsgDTO.getShopId())
.eq(TbCallQueue::getId, subMsgDTO.getQueueId()));
if (queue == null) {
throw new MsgException("您未排号请先排号");
}
queue.setSubState(1);
queue.setOpenId(subMsgDTO.getOpenId());
return callQueueMapper.updateById(queue);
}
}

View File

@@ -1,6 +1,7 @@
package com.chaozhanggui.system.cashierservice.util;
import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.entity.dto.CallNumPrintDTO;
import com.chaozhanggui.system.cashierservice.rabbit.RabbitConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
@@ -23,4 +24,11 @@ public class MQUtils {
public <T> void sendStockSaleMsg(T data) {
sendMsg(RabbitConstants.EXCHANGE_STOCK_RECORD, RabbitConstants.ROUTING_STOCK_RECORD_SALE, data, "商品售出增加库存记录");
}
public void printCallNumTicket(Integer id, Integer shopId) {
CallNumPrintDTO printDTO = new CallNumPrintDTO();
printDTO.setCallQueueId(id);
printDTO.setShopId(shopId);
sendMsg(RabbitConstants.EXCHANGE_PRINT, RabbitConstants.ROUTING_KEY_CALL_TABLE, printDTO, "排号小票打印");
}
}

View File

@@ -69,9 +69,14 @@
LEFT JOIN
tb_call_table b ON a.call_table_id = b.id
WHERE
a.open_id = #{openId} -- 替换为目标用户的 open_id
AND a.shop_id = #{shopId}
a.shop_id = #{shopId}
AND a.create_day = #{today} -- 替换为目标日期
<if test="openId != null and openId != ''">
and a.open_id = #{openId} -- 替换为目标用户的 open_id
</if>
<if test="queueId != null">
and a.id = #{queueId} -- 替换为目标用户的 open_id
</if>
GROUP BY
a.id, a.user_id, b.name, b.note, b.wait_time
ORDER BY