Commit b0a0b6ca by 吕明尚

自动任务更改位置

parent 397361d5
......@@ -10,6 +10,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.support.TransactionTemplate;
import org.springframework.util.CollectionUtils;
import share.common.constant.Constants;
import share.common.core.redis.RedisUtil;
import share.common.enums.CouponStatusEnum;
......@@ -19,11 +20,14 @@ import share.common.exception.base.BaseException;
import share.system.domain.SConsumer;
import share.system.domain.SConsumerCoupon;
import share.system.domain.SOrder;
import share.system.domain.SRoom;
import share.system.mapper.SRoomMapper;
import share.system.service.ISConsumerCouponService;
import share.system.service.ISOrderService;
import share.system.service.ISysConfigService;
import share.system.service.SConsumerService;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
......@@ -55,6 +59,9 @@ public class OrderTask {
@Autowired
private TransactionTemplate transactionTemplate;
@Autowired
private SRoomMapper roomMapper;
public void autoCancel() {
String redisKey = Constants.ORDER_AUTO_CANCEL_KEY;
Long size = redisUtil.getListSize(redisKey);
......@@ -196,4 +203,32 @@ public class OrderTask {
return execute;
}
//预约订单到期自动更新订单状态,更新房间状态
public void autoToStore() {
//查询所有已支付的订单
SOrder order = new SOrder();
order.setPayStatus(1);
order.setStatus(0);
order.setRefundStatus(0);
List<SOrder> sOrders = orderService.selectSOrderList(order);
if (CollectionUtils.isEmpty(sOrders)) {
return;
}
sOrders.forEach(item -> {
//判断预约开始时间是否已到期
if ((Math.abs(item.getPreStartDate().getTime() - new Date().getTime())) / (60 * 1000) == 0) {
//更改订单状态,房间状态,开始时间,结束时间
item.setStatus(1);
item.setUpdateTime(new Date());
item.setStartDate(item.getPreStartDate());
item.setEndDate(item.getPreEndDate());
orderService.updateSOrder(item);
SRoom sRoom = roomMapper.selectById(item.getRoomId());
sRoom.setStatus("2");
sRoom.setUpdateTime(new Date());
roomMapper.updateById(sRoom);
}
});
}
}
......@@ -25,10 +25,7 @@ import java.util.List;
@Component("ryTask")
public class RyTask
{
@Autowired
private ISOrderService orderService;
@Autowired
private SRoomMapper roomMapper;
public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i)
{
System.out.println(StringUtils.format("执行多参方法: 字符串类型{},布尔类型{},长整型{},浮点型{},整形{}", s, b, l, d, i));
......@@ -44,31 +41,5 @@ public class RyTask
System.out.println("执行无参方法");
}
//预约订单到期自动更新订单状态,更新房间状态
public void autoToStore() {
//查询所有已支付的订单
SOrder order = new SOrder();
order.setPayStatus(1);
order.setStatus(0);
order.setRefundStatus(0);
List<SOrder> sOrders = orderService.selectSOrderList(order);
if (CollectionUtils.isEmpty(sOrders)) {
return;
}
sOrders.forEach(item -> {
//判断预约开始时间是否已到期
if ((Math.abs(item.getPreStartDate().getTime() - new Date().getTime())) / (60 * 1000) == 0) {
//更改订单状态,房间状态,开始时间,结束时间
item.setStatus(1);
item.setUpdateTime(new Date());
item.setStartDate(item.getPreStartDate());
item.setEndDate(item.getPreEndDate());
orderService.updateSOrder(item);
SRoom sRoom = roomMapper.selectById(item.getRoomId());
sRoom.setStatus("2");
sRoom.setUpdateTime(new Date());
roomMapper.updateById(sRoom);
}
});
}
}
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