From 6ce85b1d107329e458d8d7d2a6b1dd4a37fb274e Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Thu, 19 Sep 2024 15:11:18 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=8E=92=E9=98=9F=E5=8F=96=E5=8F=B7=20?= =?UTF-8?q?=E5=8F=96=E5=8F=B7=E6=89=93=E5=8D=B0=E5=B0=8F=E7=A5=A8=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=AE=A2=E9=98=85=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/TbCallTableController.java | 29 ++++++++++++---- .../entity/dto/CallNumPrintDTO.java | 9 +++++ .../entity/dto/CallSubMsgDTO.java | 10 ++++++ .../mapper/TbCallQueueMapper.java | 2 +- .../rabbit/RabbitConstants.java | 6 ++++ .../cashierservice/service/TbCallService.java | 7 ++-- .../service/impl/TbCallServiceImpl.java | 33 ++++++++++++++++--- .../system/cashierservice/util/MQUtils.java | 8 +++++ .../resources/mapper/TbCallQueueMapper.xml | 9 +++-- 9 files changed, 97 insertions(+), 16 deletions(-) create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/CallNumPrintDTO.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/CallSubMsgDTO.java diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/TbCallTableController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/TbCallTableController.java index 5c6fef1..b9632de 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/TbCallTableController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/TbCallTableController.java @@ -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)); } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/CallNumPrintDTO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/CallNumPrintDTO.java new file mode 100644 index 0000000..ac37d31 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/CallNumPrintDTO.java @@ -0,0 +1,9 @@ +package com.chaozhanggui.system.cashierservice.entity.dto; + +import lombok.Data; + +@Data +public class CallNumPrintDTO { + private Integer callQueueId; + private Integer shopId; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/CallSubMsgDTO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/CallSubMsgDTO.java new file mode 100644 index 0000000..c502e26 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/CallSubMsgDTO.java @@ -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; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/mapper/TbCallQueueMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/mapper/TbCallQueueMapper.java index f9601d2..ba394aa 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/mapper/TbCallQueueMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/mapper/TbCallQueueMapper.java @@ -14,7 +14,7 @@ import java.util.List; */ public interface TbCallQueueMapper extends BaseMapper { - List selectInfoByOpenId(Integer shopId, String openId, String today); + List selectInfoByOpenId(Integer shopId, String openId, String today, Integer queueId); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConstants.java b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConstants.java index 433333a..495fbc9 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConstants.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/RabbitConstants.java @@ -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"; } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/TbCallService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbCallService.java index e9100db..6fc2e2a 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/TbCallService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbCallService.java @@ -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); } 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 index 7b1e318..47ff1fc 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbCallServiceImpl.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbCallServiceImpl.java @@ -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 callQueueInfoVOS = callQueueMapper.selectInfoByOpenId(shopId, openId, DateUtil.today()); + public Object getState(String openId, Integer shopId, Integer queueId) { + List callQueueInfoVOS = callQueueMapper.selectInfoByOpenId(shopId, openId, DateUtil.today(), queueId); TbShopInfo shopInfo = shopInfoMapper.selectByPrimaryKey(shopId); HashMap 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() + .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); + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/MQUtils.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/MQUtils.java index d7178fd..0a87483 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/util/MQUtils.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/MQUtils.java @@ -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 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, "排号小票打印"); + } } diff --git a/src/main/resources/mapper/TbCallQueueMapper.xml b/src/main/resources/mapper/TbCallQueueMapper.xml index 9e03e10..7c6c41f 100644 --- a/src/main/resources/mapper/TbCallQueueMapper.xml +++ b/src/main/resources/mapper/TbCallQueueMapper.xml @@ -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} -- 替换为目标日期 + + and a.open_id = #{openId} -- 替换为目标用户的 open_id + + + and a.id = #{queueId} -- 替换为目标用户的 open_id + GROUP BY a.id, a.user_id, b.name, b.note, b.wait_time ORDER BY