Commit 272b91b1 by 吕明尚

下单成功增加redis,自动更新订单状态自动任务改为从redis获取数据

parent a45f1f27
...@@ -6,7 +6,8 @@ public enum ReceiptRdeisEnum { ...@@ -6,7 +6,8 @@ public enum ReceiptRdeisEnum {
MT_SESSION_KEY(2, "MT_SESSION_KEY"), 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."), ORDER_NO_KEY(4, "ORDER_NO_KEY."),
ACCESS_TOKEN_KEY(5, "ACCESS_TOKEN_KEY."); ACCESS_TOKEN_KEY(5, "ACCESS_TOKEN_KEY."),
ORDER_NO(6, "ORDER_NO.");
private Integer code; private Integer code;
......
...@@ -9,6 +9,7 @@ import cn.hutool.json.JSONObject; ...@@ -9,6 +9,7 @@ import cn.hutool.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.support.TransactionTemplate; import org.springframework.transaction.support.TransactionTemplate;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
...@@ -62,6 +63,9 @@ public class OrderTask { ...@@ -62,6 +63,9 @@ public class OrderTask {
@Autowired @Autowired
private DeviceOpService deviceOpService; private DeviceOpService deviceOpService;
@Autowired
private RedisTemplate redisTemplate;
final int ZERO = 0; final int ZERO = 0;
public void autoCancel() { public void autoCancel() {
...@@ -209,10 +213,19 @@ public class OrderTask { ...@@ -209,10 +213,19 @@ public class OrderTask {
//预约订单到期自动更新订单状态,更新房间状态 //预约订单到期自动更新订单状态,更新房间状态
public void autoToStore() { public void autoToStore() {
//查询所有已支付的订单 //查询所有已支付的订单
List<SOrder> sOrders = orderService.validOrder(); Set<String> keys = redisTemplate.keys(ReceiptRdeisEnum.ORDER_NO.getValue() + "*");
if (CollectionUtils.isEmpty(sOrders)) { if (keys.size() == 0) {
return; return;
} }
List<SOrder> sOrders = new ArrayList<>();
keys.stream().forEach(o -> {
String value = redisUtil.get(String.valueOf(o));
JSONObject jsonObject = new JSONObject(value);
Date expirationTime = jsonObject.getDate("expirationTime");
if (expirationTime.getTime() < new Date().getTime()) {
sOrders.add(orderService.getByOrderNo(String.valueOf(o)));
}
});
List<Long> roomIds = sOrders.stream().map(SOrder::getRoomId).collect(Collectors.toList()); List<Long> roomIds = sOrders.stream().map(SOrder::getRoomId).collect(Collectors.toList());
List<SRoom> roomList = roomService.listByIds(roomIds); List<SRoom> roomList = roomService.listByIds(roomIds);
sOrders.stream().forEach(item -> { sOrders.stream().forEach(item -> {
......
...@@ -2,6 +2,7 @@ package share.system.mapper; ...@@ -2,6 +2,7 @@ package share.system.mapper;
import java.util.List; import java.util.List;
import share.system.domain.SConsumptionRecords; import share.system.domain.SConsumptionRecords;
import share.system.domain.vo.SConsumptionRecordsVo;
/** /**
* 消费记录Mapper接口 * 消费记录Mapper接口
...@@ -25,7 +26,7 @@ public interface SConsumptionRecordsMapper ...@@ -25,7 +26,7 @@ public interface SConsumptionRecordsMapper
* @param sConsumptionRecords 消费记录 * @param sConsumptionRecords 消费记录
* @return 消费记录集合 * @return 消费记录集合
*/ */
public List<SConsumptionRecords> selectSConsumptionRecordsList(SConsumptionRecords sConsumptionRecords); public List<SConsumptionRecordsVo> selectSConsumptionRecordsList(SConsumptionRecords sConsumptionRecords);
/** /**
* 新增消费记录 * 新增消费记录
......
...@@ -57,31 +57,27 @@ public class SConsumptionRecordsServiceImpl implements ISConsumptionRecordsServi ...@@ -57,31 +57,27 @@ public class SConsumptionRecordsServiceImpl implements ISConsumptionRecordsServi
@Override @Override
public List<SConsumptionRecordsVo> selectSConsumptionRecordsList(SConsumptionRecords sConsumptionRecords) public List<SConsumptionRecordsVo> selectSConsumptionRecordsList(SConsumptionRecords sConsumptionRecords)
{ {
List<SConsumptionRecords> sConsumptionRecordsList = sConsumptionRecordsMapper.selectSConsumptionRecordsList(sConsumptionRecords); List<SConsumptionRecordsVo> sConsumptionRecordsList = sConsumptionRecordsMapper.selectSConsumptionRecordsList(sConsumptionRecords);
//获取消费记录的用户id集合 //获取消费记录的用户id集合
List<Long> collect = sConsumptionRecordsList.stream().map(SConsumptionRecords::getConsumerId).collect(Collectors.toList()); List<Long> collect = sConsumptionRecordsList.stream().map(SConsumptionRecords::getConsumerId).collect(Collectors.toList());
//获取用户id集合的用户信息 //获取用户id集合的用户信息
List<SConsumer> sConsumers = sConsumerMapper.selectBatchIds(collect); List<SConsumer> sConsumers = sConsumerMapper.selectBatchIds(collect);
List<Long> oredrIds = sConsumptionRecordsList.stream().map(SConsumptionRecords::getOrderId).collect(Collectors.toList()); List<Long> oredrIds = sConsumptionRecordsList.stream().map(SConsumptionRecords::getOrderId).collect(Collectors.toList());
List<SOrder> sOrders = sOrderMapper.selectBatchIds(oredrIds); List<SOrder> sOrders = sOrderMapper.selectBatchIds(oredrIds);
List<SConsumptionRecordsVo> sConsumptionRecordsVoList = new ArrayList<>();
sConsumptionRecordsList.stream().forEach(item -> { sConsumptionRecordsList.stream().forEach(item -> {
SConsumptionRecordsVo sConsumptionRecordsVo = new SConsumptionRecordsVo();
BeanUtils.copyProperties(item, sConsumptionRecordsVo);
sConsumers.stream().forEach(vo -> { sConsumers.stream().forEach(vo -> {
if (sConsumptionRecordsVo.getConsumerId().equals(vo.getId())) { if (item.getConsumerId().equals(vo.getId())) {
sConsumptionRecordsVo.setNickName(vo.getNickName()); item.setNickName(vo.getNickName());
sConsumptionRecordsVo.setPhone(vo.getPhone()); item.setPhone(vo.getPhone());
} }
}); });
sOrders.stream().forEach(vo -> { sOrders.stream().forEach(vo -> {
if (sConsumptionRecordsVo.getOrderId().equals(vo.getId())) { if (item.getOrderId().equals(vo.getId())) {
sConsumptionRecordsVo.setOrderNo(vo.getOrderNo()); item.setOrderNo(vo.getOrderNo());
} }
}); });
sConsumptionRecordsVoList.add(sConsumptionRecordsVo);
}); });
return sConsumptionRecordsVoList; return sConsumptionRecordsList;
} }
/** /**
......
...@@ -628,6 +628,12 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -628,6 +628,12 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
map.put("expirationTime", sOrder.getEndDate().toString()); map.put("expirationTime", sOrder.getEndDate().toString());
JSONObject jsonObject = new JSONObject(map); JSONObject jsonObject = new JSONObject(map);
redisUtils.set(ReceiptRdeisEnum.ORDER_NO_KEY.getValue() + sOrder.getOrderNo(), jsonObject.toString()); redisUtils.set(ReceiptRdeisEnum.ORDER_NO_KEY.getValue() + sOrder.getOrderNo(), jsonObject.toString());
} else {
Map<String, String> map = new HashMap<>();
map.put("orderNo", sOrder.getOrderNo());
map.put("expirationTime", sOrder.getPreStartDate().toString());
JSONObject jsonObject = new JSONObject(map);
redisUtils.set(ReceiptRdeisEnum.ORDER_NO.getValue() + sOrder.getOrderNo(), jsonObject.toString());
} }
baseMapper.updateById(sOrder); baseMapper.updateById(sOrder);
Long couponId = sOrder.getCouponId(); Long couponId = sOrder.getCouponId();
......
...@@ -15,6 +15,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -15,6 +15,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="createTime" column="create_time" /> <result property="createTime" column="create_time" />
</resultMap> </resultMap>
<resultMap type="SConsumptionRecordsVo" id="SConsumptionRecordsResultVo">
<result property="id" column="id"/>
<result property="consumerId" column="consumer_id"/>
<result property="orderId" column="order_id"/>
<result property="name" column="name"/>
<result property="price" column="price"/>
<result property="payType" column="pay_type"/>
<result property="sign" column="sign"/>
<result property="createTime" column="create_time"/>
</resultMap>
<sql id="selectSConsumptionRecordsVo"> <sql id="selectSConsumptionRecordsVo">
select id, select id,
consumer_id, consumer_id,
...@@ -27,7 +38,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -27,7 +38,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
from s_consumption_records from s_consumption_records
</sql> </sql>
<select id="selectSConsumptionRecordsList" parameterType="SConsumptionRecords" resultMap="SConsumptionRecordsResult"> <select id="selectSConsumptionRecordsList" parameterType="SConsumptionRecords"
resultMap="SConsumptionRecordsResultVo">
<include refid="selectSConsumptionRecordsVo"/> <include refid="selectSConsumptionRecordsVo"/>
<where> <where>
<if test="name != null and name != ''"> and name = #{name}</if> <if test="name != null and name != ''"> and name = #{name}</if>
......
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