无台桌模式选择台桌接口修改

This commit is contained in:
SongZhang 2024-10-23 17:32:45 +08:00
parent 24a80cb24a
commit d99771f8e7
11 changed files with 130 additions and 57 deletions

View File

@ -191,10 +191,7 @@ public class TbPlaceController {
@PutMapping("/choseTable") @PutMapping("/choseTable")
@ApiOperation("代客下单 选择台桌") @ApiOperation("代客下单 选择台桌")
public ResponseEntity<Object> choseTable( public ResponseEntity<Object> choseTable(@Validated @RequestBody ChoseTableDTO choseTableDTO) {
@Validated @RequestBody ChoseTableDTO choseTableDTO
) {
return ResponseEntity.ok(tbShopTableService.choseTable(choseTableDTO)); return ResponseEntity.ok(tbShopTableService.choseTable(choseTableDTO));
} }
@ -213,9 +210,7 @@ public class TbPlaceController {
@PostMapping("/printOrder") @PostMapping("/printOrder")
@ApiOperation("代客下单 打印订单") @ApiOperation("代客下单 打印订单")
public ResponseEntity<Object> printOrder( public ResponseEntity<Object> printOrder(@Validated @RequestBody BaseTableDTO baseTableDTO) {
@Validated @RequestBody BaseTableDTO baseTableDTO
) {
return ResponseEntity.ok(tbShopTableService.printOrder(baseTableDTO)); return ResponseEntity.ok(tbShopTableService.printOrder(baseTableDTO));
} }

View File

@ -2,19 +2,15 @@ package cn.ysk.cashier.dto.shoptable;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.Max; import javax.validation.constraints.*;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
@Data @Data
public class ChoseTableDTO { public class ChoseTableDTO {
@NotNull @NotNull
private Integer shopId; private Integer shopId;
private Integer orderId; @NotBlank
@NotNull private String masterId;
private String newTableId; @NotBlank
@NotEmpty private String tableId;
private String oldTableId;
} }

View File

@ -4,6 +4,8 @@ import cn.ysk.cashier.pojo.order.TbCashierCart;
import cn.ysk.cashier.pojo.order.TbOrderDetail; import cn.ysk.cashier.pojo.order.TbOrderDetail;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/** /**
* (TbShopPermission)表服务接口 * (TbShopPermission)表服务接口
* *
@ -12,5 +14,12 @@ import com.baomidou.mybatisplus.extension.service.IService;
*/ */
public interface MpCashierCartService extends IService<TbCashierCart> { public interface MpCashierCartService extends IService<TbCashierCart> {
/**
* 根据取餐码获取购物车信息
* @param masterId 取餐码
* @param shopId 店铺id
* @return 购物车信息
*/
List<TbCashierCart> selectTakeoutCart(String masterId, Integer shopId);
} }

View File

@ -5,6 +5,7 @@ import cn.ysk.cashier.enums.OrderStatusEnums;
import cn.ysk.cashier.pojo.order.TbOrderDetail; import cn.ysk.cashier.pojo.order.TbOrderDetail;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
@ -24,5 +25,13 @@ public interface MpOrderDetailService extends IService<TbOrderDetail> {
* @return 影响数量 * @return 影响数量
*/ */
boolean updateStatusByOrderIdAndIds(OrderStatusEnums oldOrderStatusEnums, OrderStatusEnums orderStatusEnums, Integer orderId, List<Integer> orderDetails); boolean updateStatusByOrderIdAndIds(OrderStatusEnums oldOrderStatusEnums, OrderStatusEnums orderStatusEnums, Integer orderId, List<Integer> orderDetails);
/**
* 根据购物车id修改用餐类型
* @param cartIds 购物车ids
* @param useType 用餐类型
* @return 是否成功
*/
boolean updateUseTypeByCartIds(ArrayList<Integer> cartIds, String useType);
} }

View File

@ -21,5 +21,13 @@ public interface MpOrderInfoService extends IService<TbOrderInfo> {
* @return 对应的退款订单 * @return 对应的退款订单
*/ */
TbOrderInfo selectReturnOrderByOrderId(Integer orderId); TbOrderInfo selectReturnOrderByOrderId(Integer orderId);
/**
* 修改订单的就餐类型和tableId
* @param orderId 订单id
* @param useType 就餐类型
* @return 是否成功
*/
boolean updateTableIdAndUseTypeById(Integer orderId, String useType, String tableId);
} }

View File

@ -1,7 +1,23 @@
package cn.ysk.cashier.mybatis.service; package cn.ysk.cashier.mybatis.service;
import cn.ysk.cashier.enums.TableStateEnum;
import cn.ysk.cashier.pojo.shop.TbShopTable; import cn.ysk.cashier.pojo.shop.TbShopTable;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
public interface MpShopTableService extends IService<TbShopTable> { public interface MpShopTableService extends IService<TbShopTable> {
/**
* 根据qrcode修改台桌状态
* @param tableStateEnum 状态枚举
* @param tableId qrcode
* @return 是否成功
*/
boolean updateStateByTableId(TableStateEnum tableStateEnum, String tableId);
/**
* 根据状态和id获取台桌信息
* @param tableStateEnum 台桌状态
* @param tableId 台桌id
* @return 台桌信息
*/
TbShopTable selectByStateAndTableId(TableStateEnum tableStateEnum, String tableId, Integer shopId);
} }

View File

@ -1,14 +1,20 @@
package cn.ysk.cashier.mybatis.service.impl; package cn.ysk.cashier.mybatis.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.ysk.cashier.enums.OrderUseTypeEnum;
import cn.ysk.cashier.mybatis.mapper.TbCashierCartMapper; import cn.ysk.cashier.mybatis.mapper.TbCashierCartMapper;
import cn.ysk.cashier.mybatis.mapper.TbOrderDetailMapper; import cn.ysk.cashier.mybatis.mapper.TbOrderDetailMapper;
import cn.ysk.cashier.mybatis.service.MpCashierCartService; import cn.ysk.cashier.mybatis.service.MpCashierCartService;
import cn.ysk.cashier.mybatis.service.MpOrderDetailService; import cn.ysk.cashier.mybatis.service.MpOrderDetailService;
import cn.ysk.cashier.pojo.order.TbCashierCart; import cn.ysk.cashier.pojo.order.TbCashierCart;
import cn.ysk.cashier.pojo.order.TbOrderDetail; import cn.ysk.cashier.pojo.order.TbOrderDetail;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.List;
/** /**
* (TbShopPermission)表服务实现类 * (TbShopPermission)表服务实现类
* *
@ -17,6 +23,13 @@ import org.springframework.stereotype.Service;
*/ */
@Service @Service
public class MpCashierCartServiceImpl extends ServiceImpl<TbCashierCartMapper, TbCashierCart> implements MpCashierCartService { public class MpCashierCartServiceImpl extends ServiceImpl<TbCashierCartMapper, TbCashierCart> implements MpCashierCartService {
@Override
public List<TbCashierCart> selectTakeoutCart(String masterId, Integer shopId) {
return list(new LambdaQueryWrapper<TbCashierCart>()
.eq(TbCashierCart::getShopId, shopId)
.eq(TbCashierCart::getMasterId, masterId)
.eq(TbCashierCart::getUseType, OrderUseTypeEnum.TAKEOUT.getValue())
.gt(TbCashierCart::getCreatedAt, DateUtil.offsetDay(DateUtil.date(), -1).getTime()));
}
} }

View File

@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
@ -30,5 +31,12 @@ public class MpOrderDetailServiceImpl extends ServiceImpl<TbOrderDetailMapper, T
} }
return update(wrapper); return update(wrapper);
} }
@Override
public boolean updateUseTypeByCartIds(ArrayList<Integer> cartIds, String useType) {
return update(new LambdaUpdateWrapper<TbOrderDetail>()
.in(TbOrderDetail::getCartId, cartIds)
.set(TbOrderDetail::getUseType, useType));
}
} }

View File

@ -7,6 +7,7 @@ import cn.ysk.cashier.mybatis.service.MpOrderInfoService;
import cn.ysk.cashier.pojo.order.TbCashierCart; import cn.ysk.cashier.pojo.order.TbCashierCart;
import cn.ysk.cashier.pojo.order.TbOrderInfo; import cn.ysk.cashier.pojo.order.TbOrderInfo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -24,5 +25,13 @@ public class MpOrderInfoServiceImpl extends ServiceImpl<TbOrderInfoMapper, TbOrd
.eq(TbOrderInfo::getSource, orderId) .eq(TbOrderInfo::getSource, orderId)
.eq(TbOrderInfo::getOrderType, "return")); .eq(TbOrderInfo::getOrderType, "return"));
} }
@Override
public boolean updateTableIdAndUseTypeById(Integer orderId, String useType, String tableId) {
return update(new LambdaUpdateWrapper<TbOrderInfo>()
.eq(TbOrderInfo::getId, orderId)
.set(TbOrderInfo::getUseType, useType)
.set(TbOrderInfo::getTableId, tableId));
}
} }

View File

@ -1,5 +1,6 @@
package cn.ysk.cashier.mybatis.service.impl; package cn.ysk.cashier.mybatis.service.impl;
import cn.ysk.cashier.enums.TableStateEnum;
import cn.ysk.cashier.mapper.shop.TbShopTableMapper; import cn.ysk.cashier.mapper.shop.TbShopTableMapper;
import cn.ysk.cashier.mybatis.entity.TagProductDepts; import cn.ysk.cashier.mybatis.entity.TagProductDepts;
import cn.ysk.cashier.mybatis.mapper.MpShopTableMapper; import cn.ysk.cashier.mybatis.mapper.MpShopTableMapper;
@ -7,9 +8,26 @@ import cn.ysk.cashier.mybatis.mapper.TagProductDeptsMapper;
import cn.ysk.cashier.mybatis.service.MpShopTableService; import cn.ysk.cashier.mybatis.service.MpShopTableService;
import cn.ysk.cashier.mybatis.service.TagProductDeptsService; import cn.ysk.cashier.mybatis.service.TagProductDeptsService;
import cn.ysk.cashier.pojo.shop.TbShopTable; import cn.ysk.cashier.pojo.shop.TbShopTable;
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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Service @Service
public class MpShopTableServiceImpl extends ServiceImpl<MpShopTableMapper, TbShopTable> implements MpShopTableService { public class MpShopTableServiceImpl extends ServiceImpl<MpShopTableMapper, TbShopTable> implements MpShopTableService {
@Override
public boolean updateStateByTableId(TableStateEnum tableStateEnum, String tableId) {
return update(new LambdaUpdateWrapper<TbShopTable>()
.eq(TbShopTable::getQrcode, tableId)
.set(TbShopTable::getStatus, tableStateEnum.getState()));
}
@Override
public TbShopTable selectByStateAndTableId(TableStateEnum tableStateEnum, String tableId, Integer shopId) {
return getOne(new LambdaQueryWrapper<TbShopTable>()
.eq(TbShopTable::getShopId, shopId)
.eq(TbShopTable::getStatus, tableStateEnum.getState())
.eq(TbShopTable::getQrcode, tableId));
}
} }

View File

@ -1098,6 +1098,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
List<TbCashierCart> cashierCarts = cashierCartMapper List<TbCashierCart> cashierCarts = cashierCartMapper
.selectList(queryWrapper); .selectList(queryWrapper);
if (cashierCarts.isEmpty() || (shopEatTypeInfoDTO.isNeedSeatFee() && !shopEatTypeInfoDTO.isTakeout() && cashierCarts.size() < 2)) { if (cashierCarts.isEmpty() || (shopEatTypeInfoDTO.isNeedSeatFee() && !shopEatTypeInfoDTO.isTakeout() && cashierCarts.size() < 2)) {
throw new BadRequestException("购物车为空或未选择餐位费,请先添加商品或选择餐位费"); throw new BadRequestException("购物车为空或未选择餐位费,请先添加商品或选择餐位费");
} }
@ -1728,50 +1729,41 @@ public class TbShopTableServiceImpl implements TbShopTableService {
@Override @Override
public Object choseTable(ChoseTableDTO choseTableDTO) { public Object choseTable(ChoseTableDTO choseTableDTO) {
String masterId = getMasterId(choseTableDTO.getShopId(), choseTableDTO.getNewTableId(), null, null).getString("masterId"); TbShopTable shopTable = mpShopTableService.selectByStateAndTableId(TableStateEnum.IDLE, choseTableDTO.getTableId(), choseTableDTO.getShopId());
TbShopTable shopTable = mpShopTableMapper.selectOne(new LambdaQueryWrapper<TbShopTable>()
.eq(TbShopTable::getQrcode, choseTableDTO.getNewTableId())
.eq(TbShopTable::getStatus, "idle"));
if (shopTable == null) { if (shopTable == null) {
throw new BadRequestException("台桌不存在或空闲状态"); throw new BadRequestException("台桌不存在或不处于空闲状态");
} }
ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(choseTableDTO.getShopId(), choseTableDTO.getNewTableId()); List<TbCashierCart> tbCashierCarts = mpCashierCartService.selectTakeoutCart(choseTableDTO.getMasterId(), choseTableDTO.getShopId());
TbOrderInfo currentOrder = getCurrentOrder(shopEatTypeInfoDTO); if (tbCashierCarts.isEmpty()) {
Integer currentOrderId = currentOrder == null ? null : currentOrder.getId(); throw new BadRequestException("购物车为空");
}
ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(choseTableDTO.getShopId(), choseTableDTO.getTableId());
cashierCartMapper.update(null, new LambdaUpdateWrapper<TbCashierCart>() ArrayList<Integer> cartIds = new ArrayList<>();
.eq(TbCashierCart::getTableId, choseTableDTO.getOldTableId()) Integer orderId = null;
.in(TbCashierCart::getStatus, "create", "return") for (TbCashierCart item : tbCashierCarts) {
.eq(TbCashierCart::getShopId, choseTableDTO.getShopId()) item.setTableId(choseTableDTO.getTableId());
.and(q -> q.isNull(TbCashierCart::getOrderId) item.setUseType(shopEatTypeInfoDTO.getUseType());
.or() cartIds.add(item.getId());
.eq(TbCashierCart::getOrderId, currentOrderId)) if (item.getOrderId() != null) {
.and(query2 -> query2.or(query3 -> query3.eq(TbCashierCart::getTradeDay, DateUtils.getDay()) orderId = item.getOrderId();
.isNotNull(TbCashierCart::getMasterId)) }
.or((query4 -> query4.isNull(TbCashierCart::getTradeDay) }
.isNull(TbCashierCart::getMasterId))))
.set(TbCashierCart::getMasterId, masterId)
.set(TbCashierCart::getTableId, choseTableDTO.getNewTableId()));
mpCashierCartService.updateBatchById(tbCashierCarts);
// 修改detail的用餐类型
mpOrderDetailService.updateUseTypeByCartIds(cartIds, shopEatTypeInfoDTO.getUseType());
mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>() // 修改订单表台桌信息
.eq(TbShopTable::getQrcode, choseTableDTO.getNewTableId()) if(orderId != null) {
.set(TbShopTable::getStatus, TableStateEnum.USING.getState())); mpOrderInfoService.updateTableIdAndUseTypeById(orderId, shopEatTypeInfoDTO.getUseType(), choseTableDTO.getTableId());
mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>() mpShopTableService.updateStateByTableId(TableStateEnum.USING, choseTableDTO.getTableId());
.eq(TbShopTable::getQrcode, choseTableDTO.getOldTableId())
.set(TbShopTable::getStatus, TableStateEnum.IDLE.getState()));
// 将台桌redis数据迁移 // 将台桌redis数据迁移
String orderId = removeCurrentOrderId(choseTableDTO.getOldTableId(), choseTableDTO.getShopId().toString()); setCurrentOrderId(choseTableDTO.getTableId(), choseTableDTO.getShopId().toString(), orderId.toString());
setCurrentOrderId(choseTableDTO.getNewTableId(), choseTableDTO.getShopId().toString(), orderId); }
return true;
return orderInfoMapper.update(null, new LambdaUpdateWrapper<TbOrderInfo>()
.eq(TbOrderInfo::getId, currentOrderId)
.set(TbOrderInfo::getMasterId, masterId)
.set(TbOrderInfo::getTableId, choseTableDTO.getNewTableId()));
} }