Commit e862f373 by 吕明尚

优化自动添加保洁任务的自动任务

parent 7e3f31d4
......@@ -71,10 +71,6 @@ public class RedisTask {
@Autowired
private SConsumerService sConsumerService;
//30分钟的常量
final long THIRTY_MINUTES = 60 * 30;
//29分钟的常量
final long THIRTY_NINE_MINUTES = 60 * 29;
//15分钟的常量
final long FIFTEEN_MINUTES = 60 * 15;
//14分钟的常量
......@@ -136,7 +132,6 @@ public class RedisTask {
//查询所有待使用订单和使用中的订单
LambdaQueryWrapper<SOrder> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.in(SOrder::getStatus, new ArrayList<Integer>() {{
add(OrderStatusEnum.UNUSED.getCode());
add(OrderStatusEnum.INUSE.getCode());
}});
List<SOrder> sOrders = isOrderService.list();
......@@ -146,11 +141,17 @@ public class RedisTask {
JSONObject jsonObject = new JSONObject(value);
Date expirationTime = jsonObject.getDate("expirationTime");
SOrder sOrder = sOrders.stream().filter(item -> item.getOrderNo().equals(jsonObject.getStr("orderNo"))).findFirst().orElse(null);
if (ObjectUtils.isEmpty(sOrder)) {
redisUtil.delete(o);
throw new BaseException("订单不存在!");
}
long expire = (expirationTime.getTime() - new Date().getTime()) / 1000;
//判断时间是否在15分钟到14分钟
if (expire < FIFTEEN_MINUTES && expire > FOURTEEN_MINUTES) {
//语音
getResult(o, jsonObject, VoiceEnum.RENEWAL_REMINDER1.getCode());
if (extracted(o, sOrders, sOrder)) return;
deviceOpService.actionExecute(sOrder.getRoomId(), sOrder.getConsumerPhone(), VoiceEnum.RENEWAL_REMINDER1.getCode(),
DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN),
DateUtil.format(DateUtil.offsetMinute(new Date(), 1), DatePattern.NORM_DATETIME_PATTERN), "1");
//从门店集合中判断门店id相同的门店对象
SStore sStore = sStoreList.stream().filter(item -> item.getId().equals(sOrder.getStoreId())).findFirst().orElse(null);
//从房间集合中判断房间id相同的房间对象
......@@ -167,8 +168,10 @@ public class RedisTask {
}
//判断时间是否在5分钟到4分钟
if (expire < FIVE_MINUTES && expire > FOUR_MINUTES) {
getResult(o, jsonObject, VoiceEnum.RENEWAL_REMINDER2.getCode());
return;
if (extracted(o, sOrders, sOrder)) return;
deviceOpService.actionExecute(sOrder.getRoomId(), sOrder.getConsumerPhone(), VoiceEnum.RENEWAL_REMINDER2.getCode(),
DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN),
DateUtil.format(DateUtil.offsetMinute(new Date(), 1), DatePattern.NORM_DATETIME_PATTERN), "1");
}
//判断是否过期
if (expirationTime.getTime() < new Date().getTime()) {
......@@ -177,21 +180,7 @@ public class RedisTask {
redisUtil.delete(o);
throw new BaseException("订单不存在!");
}
//循环判断sOrders 门店相同,房间相同,用户id相同,订单为续单,订单状态为使用中
List<SOrder> sOrders1 = sOrders.stream().filter(item ->
item.getStoreId().equals(sOrder.getStoreId()) &&
item.getRoomId().equals(sOrder.getRoomId()) &&
item.getConsumerId().equals(sOrder.getConsumerId()) &&
item.getOrderType().equals(OrderTypeEnum.RENEW.getCode()) &&
item.getStatus().equals(OrderStatusEnum.INUSE.getCode())).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(sOrders1)) {
//删除当前的订单
redisUtil.delete(o);
//更改订单状态
sOrder.setStatus(OrderStatusEnum.USED.getCode());
isOrderService.updateById(sOrder);
return;
}
if (extracted(o, sOrders, sOrder)) return;
//更改订单状态
sOrder.setStatus(OrderStatusEnum.USED.getCode());
isOrderService.updateById(sOrder);
......@@ -220,45 +209,22 @@ public class RedisTask {
}
private void getResult(String o, JSONObject jsonObject, String value) {
String orderNo = jsonObject.getStr("orderNo");
SOrder sOrder = isOrderService.selectSOrderByOrderNo(orderNo);
//判断订单单是否存在
if (ObjectUtils.isEmpty(sOrder)) {
redisUtil.delete(o);
throw new BaseException("订单不存在!");
}
SOrder order = new SOrder();
order.setStoreId(sOrder.getStoreId());
order.setRoomId(sOrder.getRoomId());
order.setConsumerId(sOrder.getConsumerId());
order.setOrderType(OrderTypeEnum.RENEW.getCode());
order.setStatus(OrderStatusEnum.UNUSED.getCode());
//查询当前订单下是否存在未使用的续费订单
List<SOrder> sOrders = isOrderService.selectSOrderList(order);
if (!CollectionUtils.isEmpty(sOrders)) {
private boolean extracted(String o, List<SOrder> sOrders, SOrder sOrder) {
List<SOrder> sOrders1 = sOrders.stream().filter(item ->
item.getStoreId().equals(sOrder.getStoreId()) &&
item.getRoomId().equals(sOrder.getRoomId()) &&
item.getConsumerId().equals(sOrder.getConsumerId()) &&
item.getOrderType().equals(OrderTypeEnum.RENEW.getCode()) &&
item.getStatus().equals(OrderStatusEnum.INUSE.getCode())).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(sOrders1)) {
//删除当前的订单
redisUtil.delete(o);
//更改订单状态
sOrder.setStatus(OrderStatusEnum.USED.getCode());
isOrderService.updateById(sOrder);
return;
return true;
}
deviceOpService.actionExecute(sOrder.getRoomId(), sOrder.getConsumerPhone(), value,
DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN),
DateUtil.format(DateUtil.offsetMinute(new Date(), 1), DatePattern.NORM_DATETIME_PATTERN), "1");
}
private static class Result {
public final SOrder sOrder;
public final Device device;
public Result(SOrder sOrder, Device device) {
this.sOrder = sOrder;
this.device = device;
}
return false;
}
public void yvying(Long roomId) {
......
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