台桌预订改造

This commit is contained in:
谭凯凯
2024-12-13 11:31:19 +08:00
committed by Tankaikai
parent 5c74380b42
commit d0543ac9dc
5 changed files with 60 additions and 3 deletions

View File

@@ -50,6 +50,7 @@ public class TbShopTableBookingController {
@ApiOperation("预订")
public ResponseEntity booking(@RequestBody TbShopTableBooking dto) {
String orderNo = tbShopTableBookingService.booking(dto);
tbShopTableBookingService.markSubscribe(dto.getShopTableId());
Map<String, Object> data = new HashMap<>(2);
data.put("id", dto.getId());
data.put("orderNo", orderNo);
@@ -60,6 +61,7 @@ public class TbShopTableBookingController {
@ApiOperation("修改预订信息")
public ResponseEntity update(@RequestBody TbShopTableBooking dto) {
boolean ret = tbShopTableBookingService.update(dto);
tbShopTableBookingService.markSubscribe(dto.getShopTableId());
return ResponseEntity.ok().body(ret);
}
@@ -67,6 +69,10 @@ public class TbShopTableBookingController {
@ApiOperation("修改预订状态")
public ResponseEntity markStatus(@RequestBody TbShopTableBooking dto) {
tbShopTableBookingService.markStatus(dto.getId(), dto.getStatus());
if(dto.getStatus() == -1){
TbShopTableBooking entity = tbShopTableBookingService.getById(dto.getId());
tbShopTableBookingService.cancelSubscribe(entity.getShopTableId());
}
return ResponseEntity.ok().build();
}

View File

@@ -38,6 +38,9 @@ public interface TbShopTableBookingService extends IService<TbShopTableBooking>
Map<String, Object> summary(Integer shopId,String[] phoneNos);
void markSubscribe(Integer shopTableId);
void cancelSubscribe(Integer shopTableId);
void batchTimeout();
void autoCancel();

View File

@@ -280,6 +280,53 @@ public class TbShopTableBookingServiceImpl extends ServiceImpl<TbShopTableBookin
return result;
}
@Override
public void markSubscribe(Integer shopTableId) {
String today = DateUtil.today();
LambdaQueryWrapper<TbShopTableBooking> wrapper = Wrappers.lambdaQuery();
wrapper.eq(TbShopTableBooking::getBookingDate, today);
wrapper.eq(shopTableId != null, TbShopTableBooking::getShopTableId, shopTableId);
wrapper.ne(TbShopTableBooking::getStatus, -1);
wrapper.eq(TbShopTableBooking::getDelFlag, 0);
List<TbShopTableBooking> list = super.list(wrapper);
if (CollUtil.isEmpty(list)) {
return;
}
Map<Integer, List<TbShopTableBooking>> groupMap = list.stream().collect(Collectors.groupingBy(TbShopTableBooking::getShopTableId));
groupMap.forEach((k, v) -> {
mpShopTableMapper.update(Wrappers.<TbShopTable>lambdaUpdate()
.set(TbShopTable::getStatus, "subscribe")
.eq(TbShopTable::getStatus, "idle")
.eq(TbShopTable::getId, k));
});
}
@Override
public void cancelSubscribe(Integer shopTableId) {
String today = DateUtil.today();
LambdaQueryWrapper<TbShopTableBooking> wrapper = Wrappers.lambdaQuery();
wrapper.eq(TbShopTableBooking::getBookingDate, today);
wrapper.eq(shopTableId != null, TbShopTableBooking::getShopTableId, shopTableId);
//wrapper.ne(TbShopTableBooking::getStatus, -1);
wrapper.eq(TbShopTableBooking::getDelFlag, 0);
List<TbShopTableBooking> list = super.list(wrapper);
if (CollUtil.isEmpty(list)) {
return;
}
Map<Integer, List<TbShopTableBooking>> groupMap = list.stream().collect(Collectors.groupingBy(TbShopTableBooking::getShopTableId));
groupMap.forEach((k, v) -> {
long count = v.stream().filter(item -> item.getStatus() == -1).count();
// 全部都取消了,则标记为空闲
if (v.size() == count) {
mpShopTableMapper.update(Wrappers.<TbShopTable>lambdaUpdate()
.set(TbShopTable::getStatus, "idle")
.eq(TbShopTable::getStatus, "subscribe")
.eq(TbShopTable::getId, k)
);
}
});
}
@Override
public void batchTimeout() {
baseMapper.update(Wrappers.<TbShopTableBooking>lambdaUpdate()
@@ -298,5 +345,4 @@ public class TbShopTableBookingServiceImpl extends ServiceImpl<TbShopTableBookin
.eq(TbShopTableBooking::getStatus, 999)
.last("and TIMESTAMPDIFF(MINUTE, booking_time, NOW()) >= timeout_minute+15"));
}
}

View File

@@ -106,6 +106,9 @@ public class TestTask {
public void cancelPointsExchangeOrder(){
log.info("积分商品订单取消定时任务执行");
tbPointsExchangeRecordService.authCancel();
log.info("当日预订台桌打标记-预订状态");
tbShopTableBookingService.markSubscribe(null);
tbShopTableBookingService.cancelSubscribe(null);
log.info("预定订单超时定时任务执行");
tbShopTableBookingService.batchTimeout();
log.info("预定订单取消定时任务执行");

View File

@@ -332,9 +332,8 @@ public class TbShopTableServiceImpl implements TbShopTableService {
itemMap.put("orderId", orderInfo == null ? null : orderInfo.getId());
itemMap.put("useType", orderInfo == null ? null : orderInfo.getUseType());
itemMap.put("masterId", orderInfo == null ? null : orderInfo.getMasterId());
Date bookingDate = DateUtil.date().toJdkDate();
LambdaQueryWrapper<TbShopTableBooking> wrapper = Wrappers.lambdaQuery();
wrapper.eq(TbShopTableBooking::getBookingDate, bookingDate);
wrapper.eq(TbShopTableBooking::getBookingDate, DateUtil.today());
wrapper.eq(TbShopTableBooking::getShopTableId, data.getId());
wrapper.ne(TbShopTableBooking::getStatus, -1);
wrapper.eq(TbShopTableBooking::getDelFlag, 0);