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

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

@ -62,7 +62,7 @@ public class TbPlaceController {
return new ResponseEntity<>(tbProductService.activateProduct(page, size, categoryId, shopId, productId), HttpStatus.OK);
}
public TbPlaceController(TbShopTableService tbShopTableService, TbProductService tbProductService,RabbitMsgUtils rabbitMsgUtils) {
public TbPlaceController(TbShopTableService tbShopTableService, TbProductService tbProductService, RabbitMsgUtils rabbitMsgUtils) {
this.tbShopTableService = tbShopTableService;
this.tbProductService = tbProductService;
this.rabbitMsgUtils = rabbitMsgUtils;
@ -144,7 +144,7 @@ public class TbPlaceController {
@PostMapping("/order")
@ApiOperation("代客下单 查询购物车 /shop/table")
public ResponseEntity<Object> createOrder(@RequestBody CreateOrderDTO createOrderDTO ) {
public ResponseEntity<Object> createOrder(@RequestBody CreateOrderDTO createOrderDTO) {
return ResponseEntity.ok(tbShopTableService.createOrder(createOrderDTO, !createOrderDTO.isPostPay(), true));
}
@ -170,7 +170,7 @@ public class TbPlaceController {
@ApiOperation("代客下单 支付订单")
public ResponseEntity<Object> pay(HttpServletRequest request, @Validated @RequestBody PayDTO payDTO) {
String token = tokenProvider.getToken(request);
JSONObject userInfo = JSON.parseObject(JSON.toJSONString(redisUtils.get("online-token-"+token)));
JSONObject userInfo = JSON.parseObject(JSON.toJSONString(redisUtils.get("online-token-" + token)));
String userName = userInfo.getString("userName");
String shopId = userInfo.getString("shopId");
TbPlussShopStaff shopStaff = staffRepository.queryByAccount(userName, shopId);
@ -191,10 +191,7 @@ public class TbPlaceController {
@PutMapping("/choseTable")
@ApiOperation("代客下单 选择台桌")
public ResponseEntity<Object> choseTable(
@Validated @RequestBody ChoseTableDTO choseTableDTO
) {
public ResponseEntity<Object> choseTable(@Validated @RequestBody ChoseTableDTO choseTableDTO) {
return ResponseEntity.ok(tbShopTableService.choseTable(choseTableDTO));
}
@ -213,9 +210,7 @@ public class TbPlaceController {
@PostMapping("/printOrder")
@ApiOperation("代客下单 打印订单")
public ResponseEntity<Object> printOrder(
@Validated @RequestBody BaseTableDTO baseTableDTO
) {
public ResponseEntity<Object> printOrder(@Validated @RequestBody BaseTableDTO baseTableDTO) {
return ResponseEntity.ok(tbShopTableService.printOrder(baseTableDTO));
}

View File

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

View File

@ -4,6 +4,8 @@ import cn.ysk.cashier.pojo.order.TbCashierCart;
import cn.ysk.cashier.pojo.order.TbOrderDetail;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/**
* (TbShopPermission)表服务接口
*
@ -12,5 +14,12 @@ import com.baomidou.mybatisplus.extension.service.IService;
*/
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 com.baomidou.mybatisplus.extension.service.IService;
import java.util.ArrayList;
import java.util.List;
/**
@ -24,5 +25,13 @@ public interface MpOrderDetailService extends IService<TbOrderDetail> {
* @return 影响数量
*/
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 对应的退款订单
*/
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;
import cn.ysk.cashier.enums.TableStateEnum;
import cn.ysk.cashier.pojo.shop.TbShopTable;
import com.baomidou.mybatisplus.extension.service.IService;
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;
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.TbOrderDetailMapper;
import cn.ysk.cashier.mybatis.service.MpCashierCartService;
import cn.ysk.cashier.mybatis.service.MpOrderDetailService;
import cn.ysk.cashier.pojo.order.TbCashierCart;
import cn.ysk.cashier.pojo.order.TbOrderDetail;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.List;
/**
* (TbShopPermission)表服务实现类
*
@ -17,6 +23,13 @@ import org.springframework.stereotype.Service;
*/
@Service
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 org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
@ -30,5 +31,12 @@ public class MpOrderDetailServiceImpl extends ServiceImpl<TbOrderDetailMapper, T
}
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.TbOrderInfo;
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 org.springframework.stereotype.Service;
@ -24,5 +25,13 @@ public class MpOrderInfoServiceImpl extends ServiceImpl<TbOrderInfoMapper, TbOrd
.eq(TbOrderInfo::getSource, orderId)
.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;
import cn.ysk.cashier.enums.TableStateEnum;
import cn.ysk.cashier.mapper.shop.TbShopTableMapper;
import cn.ysk.cashier.mybatis.entity.TagProductDepts;
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.TagProductDeptsService;
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 org.springframework.stereotype.Service;
@Service
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
.selectList(queryWrapper);
if (cashierCarts.isEmpty() || (shopEatTypeInfoDTO.isNeedSeatFee() && !shopEatTypeInfoDTO.isTakeout() && cashierCarts.size() < 2)) {
throw new BadRequestException("购物车为空或未选择餐位费,请先添加商品或选择餐位费");
}
@ -1728,50 +1729,41 @@ public class TbShopTableServiceImpl implements TbShopTableService {
@Override
public Object choseTable(ChoseTableDTO choseTableDTO) {
String masterId = getMasterId(choseTableDTO.getShopId(), choseTableDTO.getNewTableId(), null, null).getString("masterId");
TbShopTable shopTable = mpShopTableMapper.selectOne(new LambdaQueryWrapper<TbShopTable>()
.eq(TbShopTable::getQrcode, choseTableDTO.getNewTableId())
.eq(TbShopTable::getStatus, "idle"));
TbShopTable shopTable = mpShopTableService.selectByStateAndTableId(TableStateEnum.IDLE, choseTableDTO.getTableId(), choseTableDTO.getShopId());
if (shopTable == null) {
throw new BadRequestException("台桌不存在或空闲状态");
throw new BadRequestException("台桌不存在或不处于空闲状态");
}
ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(choseTableDTO.getShopId(), choseTableDTO.getNewTableId());
TbOrderInfo currentOrder = getCurrentOrder(shopEatTypeInfoDTO);
Integer currentOrderId = currentOrder == null ? null : currentOrder.getId();
List<TbCashierCart> tbCashierCarts = mpCashierCartService.selectTakeoutCart(choseTableDTO.getMasterId(), choseTableDTO.getShopId());
if (tbCashierCarts.isEmpty()) {
throw new BadRequestException("购物车为空");
}
ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(choseTableDTO.getShopId(), choseTableDTO.getTableId());
cashierCartMapper.update(null, new LambdaUpdateWrapper<TbCashierCart>()
.eq(TbCashierCart::getTableId, choseTableDTO.getOldTableId())
.in(TbCashierCart::getStatus, "create", "return")
.eq(TbCashierCart::getShopId, choseTableDTO.getShopId())
.and(q -> q.isNull(TbCashierCart::getOrderId)
.or()
.eq(TbCashierCart::getOrderId, currentOrderId))
.and(query2 -> query2.or(query3 -> query3.eq(TbCashierCart::getTradeDay, DateUtils.getDay())
.isNotNull(TbCashierCart::getMasterId))
.or((query4 -> query4.isNull(TbCashierCart::getTradeDay)
.isNull(TbCashierCart::getMasterId))))
.set(TbCashierCart::getMasterId, masterId)
.set(TbCashierCart::getTableId, choseTableDTO.getNewTableId()));
ArrayList<Integer> cartIds = new ArrayList<>();
Integer orderId = null;
for (TbCashierCart item : tbCashierCarts) {
item.setTableId(choseTableDTO.getTableId());
item.setUseType(shopEatTypeInfoDTO.getUseType());
cartIds.add(item.getId());
if (item.getOrderId() != null) {
orderId = item.getOrderId();
}
}
mpCashierCartService.updateBatchById(tbCashierCarts);
// 修改detail的用餐类型
mpOrderDetailService.updateUseTypeByCartIds(cartIds, shopEatTypeInfoDTO.getUseType());
mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
.eq(TbShopTable::getQrcode, choseTableDTO.getNewTableId())
.set(TbShopTable::getStatus, TableStateEnum.USING.getState()));
mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
.eq(TbShopTable::getQrcode, choseTableDTO.getOldTableId())
.set(TbShopTable::getStatus, TableStateEnum.IDLE.getState()));
// 将台桌redis数据迁移
String orderId = removeCurrentOrderId(choseTableDTO.getOldTableId(), choseTableDTO.getShopId().toString());
setCurrentOrderId(choseTableDTO.getNewTableId(), choseTableDTO.getShopId().toString(), orderId);
return orderInfoMapper.update(null, new LambdaUpdateWrapper<TbOrderInfo>()
.eq(TbOrderInfo::getId, currentOrderId)
.set(TbOrderInfo::getMasterId, masterId)
.set(TbOrderInfo::getTableId, choseTableDTO.getNewTableId()));
// 修改订单表台桌信息
if(orderId != null) {
mpOrderInfoService.updateTableIdAndUseTypeById(orderId, shopEatTypeInfoDTO.getUseType(), choseTableDTO.getTableId());
mpShopTableService.updateStateByTableId(TableStateEnum.USING, choseTableDTO.getTableId());
// 将台桌redis数据迁移
setCurrentOrderId(choseTableDTO.getTableId(), choseTableDTO.getShopId().toString(), orderId.toString());
}
return true;
}