Commit 203d7cb3 by YG8999

订单、房间状态监控及修正

parent 56290163
......@@ -3,9 +3,11 @@ package share.quartz.task;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.bouncycastle.util.Store;
import org.slf4j.Logger;
......@@ -313,4 +315,56 @@ public class OrderTask {
}
}
/**
* 订单状态因未知原因导致时间结束未完成的,修改订单状态
* 房间状态因未知原因导致未有使用中订单而占用的,修改房间状态
*/
public void orderCompensate() {
// 订单状态处理
LambdaQueryWrapper<SOrder> queryWrapper = new LambdaQueryWrapper();
queryWrapper.le(SOrder::getEndDate, DateUtil.offset(DateUtil.date(), DateField.MINUTE, -5));
queryWrapper.in(SOrder::getStatus, OrderStatusEnum.UNUSED.getCode(),OrderStatusEnum.INUSE.getCode());
queryWrapper.eq(SOrder::getPayStatus, 1);
List<SOrder> orders = orderService.list(queryWrapper);
if (orders != null && orders.size() > 0) {
orders.forEach(order -> {
order.setStatus(OrderStatusEnum.USED.getCode());
order.setUpdateTime(new Date());
});
}
Boolean execute = transactionTemplate.execute(e -> {
orderService.updateBatchById(orders,orders.size());
return true;
});
if (execute) {
// 房间状态处理
LambdaQueryWrapper<SRoom> queryRoomWrapper = new LambdaQueryWrapper();
queryRoomWrapper.ne(SRoom::getStatus, RoomStatusEnum.HOLD.getValue());
List<SRoom> rooms = roomService.list(queryRoomWrapper);
if (rooms != null && rooms.size() > 0) {
List<Long> roomIds = rooms.stream().map(SRoom::getId).collect(Collectors.toList());
// 房间使用中订单
LambdaQueryWrapper<SOrder> queryOrderWrapper = new LambdaQueryWrapper();
queryOrderWrapper.eq(SOrder::getStatus, OrderStatusEnum.INUSE.getCode());
queryOrderWrapper.in(SOrder::getRoomId, roomIds);
queryOrderWrapper.eq(SOrder::getPayStatus, 1);
List<SOrder> orderList = orderService.list(queryOrderWrapper);
Map<Long,List<SOrder>> sOrderMap = Optional.ofNullable(orderList).orElse(new ArrayList<>()).stream().collect(Collectors.groupingBy(SOrder::getRoomId));
List<SRoom> roomList = new ArrayList<>();
rooms.forEach(room -> {
if (sOrderMap.get(room.getId()) == null || sOrderMap.get(room.getId()).size() == 0) {
room.setStatus(RoomStatusEnum.FREE.getValue());
room.setUpdateTime(new Date());
roomList.add(room);
}
});
Boolean execute2 = transactionTemplate.execute(e -> {
roomService.updateBatchById(roomList,roomList.size());
return true;
});
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment