Commit 39cd54f3 by 吕明尚

自动结束订单生成保洁订单

parent 2f03c536
package share.common.enums;
public enum ReceiptRdeisEnum {
//1:验劵准备 2:session换取
//1:验劵准备 2:session换取key 3:session刷新key
PREPARE(1, "TUANGOU.RECEIPT.PREPARE."),
MT_SESSION_KEY(2, "MT_SESSION_KEY"),
MT_SESSION_OBJECT_KEY(3, "MT_SESSION_OBJECT_KEY");
MT_SESSION_OBJECT_KEY(3, "MT_SESSION_OBJECT_KEY"),
ORDER_NO_KEY(4, "ORDER_NO_KEY.");
private Integer code;
......
......@@ -5,6 +5,7 @@ import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -22,9 +23,7 @@ import share.system.domain.SRoom;
import share.system.mapper.SRoomMapper;
import share.system.service.*;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.*;
import java.util.stream.Collectors;
/**
......@@ -57,6 +56,9 @@ public class OrderTask {
@Autowired
private ISRoomService roomService;
@Autowired
private RedisUtil redisUtils;
public void autoCancel() {
String redisKey = Constants.ORDER_AUTO_CANCEL_KEY;
Long size = redisUtil.getListSize(redisKey);
......@@ -210,12 +212,17 @@ public class OrderTask {
List<SRoom> roomList = roomService.listByIds(roomIds);
sOrders.stream().forEach(item -> {
//判断预约开始时间是否已到期
if ((Math.abs(item.getPreStartDate().getTime() - new Date().getTime())) / (60 * 1000) == 0) {
if (item.getPreStartDate().compareTo(new Date()) < 0) {
//更改订单状态,房间状态,开始时间,结束时间
item.setStatus(OrderStatusEnum.INUSE.getCode());
item.setUpdateTime(new Date());
item.setStartDate(item.getPreStartDate());
item.setEndDate(item.getPreEndDate());
Map<String, String> map = new HashMap<>();
map.put("orderNo", item.getOrderNo());
map.put("expirationTime", item.getStartDate().toString());
JSONObject jsonObject = new JSONObject(map);
redisUtils.set(ReceiptRdeisEnum.ORDER_NO_KEY.getValue() + item.getOrderNo(), jsonObject.toString());
orderService.updateSOrder(item);
roomList.stream().forEach( room -> {
if(room.getId().compareTo(item.getRoomId())==0) {
......
......@@ -5,9 +5,14 @@ import com.dianping.openapi.sdk.api.oauth.entity.CustomerRefreshTokenResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import share.common.core.redis.RedisUtil;
import share.common.enums.OrderStatusEnum;
import share.common.enums.ReceiptRdeisEnum;
import share.system.domain.SOrder;
import share.system.service.ISCleanRecordsService;
import share.system.service.ISConsumerCouponService;
import share.system.service.ISOrderService;
import share.system.service.QPService;
import java.util.Date;
......@@ -24,26 +29,32 @@ public class RedisTask {
private RedisTemplate redisTemplate;
@Autowired
private RedisUtil redisUtil;
@Autowired
private ISCleanRecordsService isCleanRecordsService;
@Autowired
private ISOrderService isOrderService;
public void AuToReceiptCode() {
//获取redis中所有以tuangou.receipt.prepare开头的key
Set<String> keys = redisTemplate.keys(ReceiptRdeisEnum.PREPARE.getValue() + "*");
if (keys.size() == 0) {
return;
}
//遍历key
keys.stream().forEach(o -> {
//获取key对应的value
JSONObject jsonObject = redisUtil.get(o);
//获取过期时间
String value = redisUtil.get(String.valueOf(o));
JSONObject jsonObject = new JSONObject(value);
Date expirationTime = jsonObject.getDate("expirationTime");
//判断是否过期
if (expirationTime.getTime() < new Date().getTime()) {
throw new RuntimeException("券码已过期");
}
//获取redis中的券码id
Long consumerCouponId = jsonObject.getLong("consumerCouponId");
//删除redis中的值
redisUtil.delete(o);
//删除数据库中的值
isConsumerCouponService.deleteSConsumerCouponById(consumerCouponId);
}
});
}
......@@ -58,4 +69,39 @@ public class RedisTask {
redisUtil.set(ReceiptRdeisEnum.MT_SESSION_KEY.getValue(), jsonObject.toString(), customerRefreshTokenResponse.getExpires_in() - 60 * 30, TimeUnit.SECONDS);
}
}
//自动添加保洁记录
public void AutoAddSCleanRecords() {
Set<String> keys = redisTemplate.keys(ReceiptRdeisEnum.ORDER_NO_KEY.getValue() + "*");
if (keys.size() == 0) {
return;
}
keys.stream().forEach(o -> {
//获取key对应的value
String value = redisUtil.get(String.valueOf(o));
JSONObject jsonObject = new JSONObject(value);
Date expirationTime = jsonObject.getDate("expirationTime");
//判断是否过期
if (expirationTime.getTime() < new Date().getTime()) {
//获取redis中的订单编号
String orderNo = jsonObject.getStr("orderNo");
SOrder sOrder = isOrderService.selectSOrderByOrderNo(orderNo);
//判断订单单是否存在
if (ObjectUtils.isEmpty(sOrder)) {
return;
}
//更改订单状态
sOrder.setStatus(OrderStatusEnum.USED.getCode());
isOrderService.updateById(sOrder);
//判断订单是否已经添加保洁记录
boolean b = isCleanRecordsService.addSCleanRecords(sOrder.getStoreId(), sOrder.getRoomId());
if (b) {
//删除redis中的值
redisUtil.delete(o);
}
}
});
}
}
......@@ -148,7 +148,8 @@ public class QPServiceImpl implements QPService {
//设置30分钟后的时间
Date date = DateUtils.addMinutes(new Date(), 30);
map.put("expirationTime", String.valueOf(date));
redisUtil.set(ReceiptRdeisEnum.PREPARE.getValue() + prepare.getReceipt_code(), new JSONObject(map));
JSONObject jsonObject = new JSONObject(map);
redisUtil.set(ReceiptRdeisEnum.PREPARE.getValue() + prepare.getReceipt_code(), jsonObject.toString());
SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String output1 = format2.format(prepare.getReceiptEndDate());
BeanUtils.copyProperties(prepare, response);
......
package share.system.service.impl;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.*;
import java.util.stream.Collectors;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
......@@ -82,6 +80,8 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
private DeviceOpService deviceOpService;
@Autowired
private QPService qpService;
@Autowired
private RedisUtil redisUtils;
/**
* 查询订单
......@@ -564,6 +564,11 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
sOrder.setStartDate(new Date());
//结束时间为开始时间+预约时长
sOrder.setEndDate(DateUtils.addHours(new Date(), bigDecimal.intValue()));
Map<String, String> map = new HashMap<>();
map.put("orderNo", sOrder.getOrderNo());
map.put("expirationTime", sOrder.getStartDate().toString());
JSONObject jsonObject = new JSONObject(map);
redisUtils.set(ReceiptRdeisEnum.ORDER_NO_KEY.getValue() + sOrder.getOrderNo(), jsonObject.toString());
sOrderMapper.updateById(sOrder);
//查询非当前用户,预约时间或使用时间为当前时间的订单,如果存在,房间不可开门
}
......
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