Commit 98874ec0 by 吕明尚

订单取消支付修改为定时任务

parent aeae67dd
...@@ -12,6 +12,7 @@ public enum ReceiptRdeisEnum { ...@@ -12,6 +12,7 @@ public enum ReceiptRdeisEnum {
TIKTOK_CLIENT_TOKEN_KEY(8, "TIKTOK_CLIENT_TOKEN_KEY"), TIKTOK_CLIENT_TOKEN_KEY(8, "TIKTOK_CLIENT_TOKEN_KEY"),
//房间15分钟过期 //房间15分钟过期
ROOM_EXPIRE_TIME(9, "ROOM_EXPIRE_TIME."), ROOM_EXPIRE_TIME(9, "ROOM_EXPIRE_TIME."),
ORDER_CANCEL_PAY(10, "ORDER_CANCEL_PAY."),
; ;
......
...@@ -28,6 +28,7 @@ import share.system.domain.*; ...@@ -28,6 +28,7 @@ import share.system.domain.*;
import share.system.domain.vo.MqttxVo; import share.system.domain.vo.MqttxVo;
import share.system.service.*; import share.system.service.*;
import java.math.BigDecimal;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -403,4 +404,26 @@ public class RedisTask { ...@@ -403,4 +404,26 @@ public class RedisTask {
}); });
} }
public void AutoOrderCancelPay() {
Set<String> keys = redisTemplate.keys(ReceiptRdeisEnum.ORDER_CANCEL_PAY + "*");
if (keys.size() == 0) {
return;
}
keys.stream().forEach(key -> {
String value = redisUtil.get(String.valueOf(key));
JSONObject jsonObject = new JSONObject(value);
Date expirationTime = jsonObject.getDate("expirationTime");
String orderNo = jsonObject.getStr("orderNo");
if (expirationTime.getTime() < new Date().getTime()) {
SOrder byOrderNo = orderService.getByOrderNo(orderNo);
if (ObjectUtils.isEmpty(byOrderNo.getPayTime()) && byOrderNo.getPayPrice().compareTo(BigDecimal.ZERO) > 0) {
orderService.removeById(byOrderNo.getId());
redisUtil.delete(key);
} else {
redisUtil.delete(key);
}
}
});
}
} }
...@@ -1272,11 +1272,12 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -1272,11 +1272,12 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
@Override @Override
public boolean cancelPay(String orderNo) { public boolean cancelPay(String orderNo) {
SOrder order = getByOrderNo(orderNo); Map<String, String> map = new HashMap<>();
if (Objects.isNull(order)) { map.put("orderNo", orderNo);
throw new BaseException("订单不存在!"); Date date = DateUtils.addMinutes(new Date(), 5);
} map.put("expirationTime", date.toString());
removeById(order.getId()); JSONObject jsonObject = new JSONObject(map);
redisUtil.set(ReceiptRdeisEnum.ORDER_CANCEL_PAY.getValue() + orderNo, jsonObject);
return true; return true;
} }
......
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