|
|
@@ -3,6 +3,7 @@ package com.izouma.nineth.service;
|
|
|
import com.alibaba.excel.util.StringUtils;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.google.zxing.WriterException;
|
|
|
+import com.izouma.nineth.config.GeneralProperties;
|
|
|
import com.izouma.nineth.config.RedisKeys;
|
|
|
import com.izouma.nineth.domain.Asset;
|
|
|
import com.izouma.nineth.domain.DomainOrder;
|
|
|
@@ -24,6 +25,7 @@ import com.sun.xml.bind.v2.TODO;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
|
+import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
|
|
import org.springframework.cache.annotation.Cacheable;
|
|
|
import org.springframework.data.annotation.Transient;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
@@ -68,6 +70,8 @@ public class DomainOrderService {
|
|
|
private RedisTemplate<String, Object> redisTemplate;
|
|
|
private CacheService cacheService;
|
|
|
private UserBalanceService userBalanceService;
|
|
|
+ private GeneralProperties generalProperties;
|
|
|
+ private RocketMQTemplate rocketMQTemplate;
|
|
|
|
|
|
public Page<DomainOrder> all(PageQuery pageQuery) {
|
|
|
return domainOrderRepo
|
|
|
@@ -305,12 +309,12 @@ public class DomainOrderService {
|
|
|
@Transient
|
|
|
public void notify(Long id, PayMethod payMethod, String transactionId) throws FontFormatException, IOException, WriterException {
|
|
|
// 取消订单与订单回调不能同时进行,需要抢锁
|
|
|
-// if (!getOrderLock(id)) {
|
|
|
-// log.info("订单回调失败 orderId: {} redis锁定, 重新发送到队列", orderId);
|
|
|
-// rocketMQTemplate.syncSend(generalProperties.getOrderNotifyTopic(),
|
|
|
-// new OrderNotifyEvent(id, payMethod, transactionId, System.currentTimeMillis()));
|
|
|
-// return;
|
|
|
-// }
|
|
|
+ if (!getOrderLock(id)) {
|
|
|
+ log.info("订单回调失败 orderId: {} redis锁定, 重新发送到队列", id);
|
|
|
+ rocketMQTemplate.syncSend(generalProperties.getOrderNotifyTopic(),
|
|
|
+ new OrderNotifyEvent(id, payMethod, transactionId, System.currentTimeMillis()));
|
|
|
+ return;
|
|
|
+ }
|
|
|
DomainOrder domainOrder = domainOrderRepo.findById(id).orElseThrow(new BusinessException("未找到星图"));
|
|
|
if (!domainOrder.getOrderStatus().equals(OrderStatus.NOT_PAID)) {
|
|
|
throw new BusinessException("订单已经处理");
|
|
|
@@ -336,15 +340,24 @@ public class DomainOrderService {
|
|
|
domainOrderRepo.save(domainOrder);
|
|
|
|
|
|
rockRecordService.addRock(domainOrder.getUserId(), domainOrder.getPrice(), "购买");
|
|
|
+
|
|
|
+ releaseOrderLock(id);
|
|
|
}
|
|
|
|
|
|
public void cancel(DomainOrder domainOrder) {
|
|
|
+ log.info("尝试取消订单 {}", domainOrder.getId());
|
|
|
+ // 取消订单与订单回调不能同时进行,需要抢锁
|
|
|
+ if (!getOrderLock(domainOrder.getId())) {
|
|
|
+ log.error("订单取消失败 {}, redis锁了", domainOrder.getId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
domainOrder.setOrderStatus(OrderStatus.CANCELLED);
|
|
|
domainOrder.setStatus(CollectionStatus.FAIL);
|
|
|
if (domainOrder.getPicName().length() < 5) {
|
|
|
decreaseCount(domainOrder);
|
|
|
}
|
|
|
domainOrderRepo.save(domainOrder);
|
|
|
+ releaseOrderLock(domainOrder.getId());
|
|
|
}
|
|
|
|
|
|
public Long createAsset(DomainOrder domainOrder) {
|
|
|
@@ -511,7 +524,8 @@ public class DomainOrderService {
|
|
|
assetRepo.save(asset1);
|
|
|
});
|
|
|
//退款
|
|
|
- userBalanceService.addBalance(domainOrder.getUserId(),domainOrder.getPrice(),domainOrder.getId(), BalanceType.REFUND);
|
|
|
+ userBalanceService.addBalance(domainOrder.getUserId(), domainOrder.getPrice(), domainOrder
|
|
|
+ .getId(), BalanceType.REFUND);
|
|
|
});
|
|
|
}
|
|
|
|