Commit e862f373 by 吕明尚

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

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