diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/config/MyBatisPlusConfig.java b/src/main/java/com/chaozhanggui/system/cashierservice/config/MyBatisPlusConfig.java new file mode 100644 index 0000000..253f70e --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/config/MyBatisPlusConfig.java @@ -0,0 +1,12 @@ +package com.chaozhanggui.system.cashierservice.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.Properties; + +@Configuration +public class MyBatisPlusConfig { + +} + diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/constant/TableConstant.java b/src/main/java/com/chaozhanggui/system/cashierservice/constant/TableConstant.java index 4a422df..46ebaf9 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/constant/TableConstant.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/constant/TableConstant.java @@ -1,6 +1,19 @@ package com.chaozhanggui.system.cashierservice.constant; -public interface TableConstant { +import lombok.Getter; +public interface TableConstant { String CART_SEAT_ID = "-999"; + + class ShopTable { + @Getter + public enum State { + IDLE("idle"), CLOSED("closed"), PAYING("paying"), PENDING("pending"), USING("using"), CLEANING("cleaning"); + private final String value; + + State(String value) { + this.value = value; + } + } + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java index 319da29..7f55c5c 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java @@ -175,14 +175,9 @@ public class UserContoller { /** * 获取订阅当前用户店库存预警消息的二维码 - * - * @param shopId - * @return */ @GetMapping("/subQrCode") - public Result getSubQrCode( - @RequestParam String shopId - ) throws Exception { + public Result getSubQrCode(@RequestParam String shopId) throws Exception { String url = userService.getSubQrCode(shopId); return Result.successWithData(url); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopTable.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopTable.java index cea6cbe..8d1dca6 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopTable.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopTable.java @@ -52,6 +52,8 @@ public class TbShopTable implements Serializable { @TableField(exist = false) private Integer seatNum; + private Integer autoClear; + } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/mpservice/MpShopTableService.java b/src/main/java/com/chaozhanggui/system/cashierservice/mpservice/MpShopTableService.java new file mode 100644 index 0000000..cd13742 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/mpservice/MpShopTableService.java @@ -0,0 +1,20 @@ +package com.chaozhanggui.system.cashierservice.mpservice; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.chaozhanggui.system.cashierservice.constant.TableConstant; +import com.chaozhanggui.system.cashierservice.entity.TbShopTable; + +public interface MpShopTableService extends IService { + /** + * 根据台桌id修改台桌状态 + * @param tableId qrcode + * @param state 状态 + */ + boolean updateStateByQrcode(String tableId, TableConstant.ShopTable.State state); + + /** + * 根据qrcode获取台桌 + * @param tableId qrcode + */ + TbShopTable selectByQrcode(String tableId); +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/mpservice/impl/MpShopTableServiceImpl.java b/src/main/java/com/chaozhanggui/system/cashierservice/mpservice/impl/MpShopTableServiceImpl.java new file mode 100644 index 0000000..85b7977 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/mpservice/impl/MpShopTableServiceImpl.java @@ -0,0 +1,28 @@ +package com.chaozhanggui.system.cashierservice.mpservice.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.chaozhanggui.system.cashierservice.constant.TableConstant; +import com.chaozhanggui.system.cashierservice.entity.TbShopTable; +import com.chaozhanggui.system.cashierservice.mapper.MpShopTableMapper; +import com.chaozhanggui.system.cashierservice.mpservice.MpShopTableService; +import org.springframework.context.annotation.Primary; +import org.springframework.stereotype.Service; + +@Service +@Primary +public class MpShopTableServiceImpl extends ServiceImpl implements MpShopTableService { + @Override + public boolean updateStateByQrcode(String tableId, TableConstant.ShopTable.State state) { + return update(new LambdaUpdateWrapper() + .eq(TbShopTable::getQrcode, tableId) + .set(TbShopTable::getStatus, state.getValue())); + } + + @Override + public TbShopTable selectByQrcode(String tableId) { + return getOne(new LambdaQueryWrapper() + .eq(TbShopTable::getQrcode, tableId)); + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java index 32c50c8..d6b5ece 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java @@ -20,6 +20,7 @@ import com.chaozhanggui.system.cashierservice.entity.dto.ChoseEatModelDTO; import com.chaozhanggui.system.cashierservice.entity.dto.ShopEatTypeInfoDTO; import com.chaozhanggui.system.cashierservice.exception.MsgException; import com.chaozhanggui.system.cashierservice.mapper.*; +import com.chaozhanggui.system.cashierservice.mpservice.MpShopTableService; import com.chaozhanggui.system.cashierservice.netty.PushToAppChannelHandlerAdapter; import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer; import com.chaozhanggui.system.cashierservice.redis.RedisCst; @@ -124,10 +125,12 @@ public class CartService { private MpOrderDetailMapper mpOrderDetailMapper; @Autowired private MpShopTableMapper mpShopTableMapper; + + private final MpShopTableService mpShopTableService; @Autowired private MQUtils mQUtils; - public CartService(TbUserShopMsgMapper tbUserShopMsgMapper, WechatUtil wechatUtil, WxAccountUtil wxAccountUtil, TbShopOpenIdMapper shopOpenIdMapper, ProductService productService, TbProductMapper tbProductMapper, RedisTemplate redisTemplate, StringRedisTemplate stringRedisTemplate, ShopUtils shopUtils) { + public CartService(TbUserShopMsgMapper tbUserShopMsgMapper, WechatUtil wechatUtil, WxAccountUtil wxAccountUtil, TbShopOpenIdMapper shopOpenIdMapper, ProductService productService, TbProductMapper tbProductMapper, RedisTemplate redisTemplate, StringRedisTemplate stringRedisTemplate, ShopUtils shopUtils, MpShopTableService mpShopTableService) { this.tbUserShopMsgMapper = tbUserShopMsgMapper; this.wechatUtil = wechatUtil; this.wxAccountUtil = wxAccountUtil; @@ -137,6 +140,7 @@ public class CartService { this.redisTemplate = redisTemplate; this.stringRedisTemplate = stringRedisTemplate; this.shopUtils = shopUtils; + this.mpShopTableService = mpShopTableService; } @@ -1162,6 +1166,11 @@ public class CartService { } } + // 修改台桌状态 + if (!shopEatTypeInfoDTO.isTakeout() && StrUtil.isNotBlank(tableId)) { + mpShopTableService.updateStateByQrcode(tableId, TableConstant.ShopTable.State.USING); + } + // 发送mq消息 JSONObject jsonObject2 = new JSONObject(); jsonObject2.put("orderId", orderInfo.getId()); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index 9c281b0..e689d7f 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -7,6 +7,7 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.chaozhanggui.system.cashierservice.constant.TableConstant; import com.chaozhanggui.system.cashierservice.dao.*; import com.chaozhanggui.system.cashierservice.entity.Enum.OrderUseTypeEnum; import com.chaozhanggui.system.cashierservice.entity.*; @@ -19,6 +20,7 @@ import com.chaozhanggui.system.cashierservice.mapper.MpOrderDetailMapper; import com.chaozhanggui.system.cashierservice.mapper.MpOrderInfoMapper; import com.chaozhanggui.system.cashierservice.model.PayReq; import com.chaozhanggui.system.cashierservice.model.TradeQueryReq; +import com.chaozhanggui.system.cashierservice.mpservice.MpShopTableService; import com.chaozhanggui.system.cashierservice.netty.PushToClientChannelHandlerAdapter; import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer; import com.chaozhanggui.system.cashierservice.redis.RedisCst; @@ -178,8 +180,11 @@ public class PayService { @Autowired private MpCashierCartMapper mpCashierCartMapper; - public PayService(@Qualifier("tbShopSongOrderServiceImpl") TbShopSongOrderService shopSongOrderService) { + private final MpShopTableService mpShopTableService; + + public PayService(@Qualifier("tbShopSongOrderServiceImpl") TbShopSongOrderService shopSongOrderService, MpShopTableService mpShopTableService) { this.shopSongOrderService = shopSongOrderService; + this.mpShopTableService = mpShopTableService; } @Transactional(rollbackFor = Exception.class) @@ -520,6 +525,15 @@ public class PayService { stringRedisTemplate.delete(currentOrderKey); } + // 重置台桌状态 + if (StrUtil.isNotBlank(orderInfo.getTableId())) { + TbShopTable shopTable = mpShopTableService.selectByQrcode(orderInfo.getTableId()); + if (shopTable.getAutoClear() != null && shopTable.getAutoClear() == 1) { + mpShopTableService.updateStateByQrcode(orderInfo.getTableId(), TableConstant.ShopTable.State.IDLE); + }else { + mpShopTableService.updateStateByQrcode(orderInfo.getTableId(), TableConstant.ShopTable.State.CLEANING); + } + } return Result.success(CodeEnum.SUCCESS, "1"); } @@ -1137,6 +1151,16 @@ public class PayService { data.put("orderId", orderInfo.getId()); data.put("plat", "miniApp"); mQUtils.sendStockSaleMsg(data); + + // 重置台桌状态 + if (StrUtil.isNotBlank(orderInfo.getTableId())) { + TbShopTable shopTable = mpShopTableService.selectByQrcode(orderInfo.getTableId()); + if (shopTable.getAutoClear() != null && shopTable.getAutoClear() == 1) { + mpShopTableService.updateStateByQrcode(orderInfo.getTableId(), TableConstant.ShopTable.State.IDLE); + }else { + mpShopTableService.updateStateByQrcode(orderInfo.getTableId(), TableConstant.ShopTable.State.CLEANING); + } + } return "SUCCESS"; }