|
|
@@ -15,7 +15,6 @@ import com.izouma.nineth.config.AlipayProperties;
|
|
|
import com.izouma.nineth.config.GeneralProperties;
|
|
|
import com.izouma.nineth.enums.PayMethod;
|
|
|
import com.izouma.nineth.event.OrderNotifyEvent;
|
|
|
-import com.izouma.nineth.repo.ErrorOrder;
|
|
|
import com.izouma.nineth.repo.ErrorOrderRepo;
|
|
|
import com.izouma.nineth.service.AssetService;
|
|
|
import com.izouma.nineth.service.GiftOrderService;
|
|
|
@@ -25,16 +24,19 @@ import com.izouma.nineth.utils.SnowflakeIdWorker;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections.MapUtils;
|
|
|
-import org.apache.rocketmq.client.producer.SendResult;
|
|
|
-import org.apache.rocketmq.client.producer.SendStatus;
|
|
|
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
|
|
+import org.springframework.core.env.Environment;
|
|
|
+import org.springframework.data.redis.core.BoundSetOperations;
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
import static com.alibaba.fastjson.serializer.SerializerFeature.PrettyFormat;
|
|
|
|
|
|
@@ -44,16 +46,18 @@ import static com.alibaba.fastjson.serializer.SerializerFeature.PrettyFormat;
|
|
|
@AllArgsConstructor
|
|
|
public class OrderNotifyController {
|
|
|
|
|
|
- private final AlipayProperties alipayProperties;
|
|
|
- private final OrderService orderService;
|
|
|
- private final WxPayService wxPayService;
|
|
|
- private final AssetService assetService;
|
|
|
- private final GiftOrderService giftOrderService;
|
|
|
- private final SnowflakeIdWorker snowflakeIdWorker;
|
|
|
- private final RocketMQTemplate rocketMQTemplate;
|
|
|
- private final GeneralProperties generalProperties;
|
|
|
- private final MintOrderService mintOrderService;
|
|
|
- private final ErrorOrderRepo errorOrderRepo;
|
|
|
+ private final AlipayProperties alipayProperties;
|
|
|
+ private final OrderService orderService;
|
|
|
+ private final WxPayService wxPayService;
|
|
|
+ private final AssetService assetService;
|
|
|
+ private final GiftOrderService giftOrderService;
|
|
|
+ private final SnowflakeIdWorker snowflakeIdWorker;
|
|
|
+ private final RocketMQTemplate rocketMQTemplate;
|
|
|
+ private final GeneralProperties generalProperties;
|
|
|
+ private final MintOrderService mintOrderService;
|
|
|
+ private final ErrorOrderRepo errorOrderRepo;
|
|
|
+ private final RedisTemplate<String, Object> redisTemplate;
|
|
|
+ private final Environment env;
|
|
|
|
|
|
@PostMapping("/order/alipay")
|
|
|
@ResponseBody
|
|
|
@@ -193,22 +197,12 @@ public class OrderNotifyController {
|
|
|
String id = jsonObject.getString("id");
|
|
|
PayMethod payMethod = channel.startsWith("wx") ? PayMethod.WEIXIN : PayMethod.ALIPAY;
|
|
|
|
|
|
- SendResult result = null;
|
|
|
- int count = 0;
|
|
|
- do {
|
|
|
- if (++count > 10) {
|
|
|
- log.error("发送订单通知失败,订单id:{}", orderId);
|
|
|
- errorOrderRepo.save(ErrorOrder.builder()
|
|
|
- .orderId(orderId)
|
|
|
- .transactionId(id)
|
|
|
- .payMethod(payMethod)
|
|
|
- .errorMessage("发送到回调队列失败")
|
|
|
- .build());
|
|
|
- break;
|
|
|
- }
|
|
|
- result = rocketMQTemplate.syncSend(generalProperties.getOrderNotifyTopic(),
|
|
|
- new OrderNotifyEvent(orderId, payMethod, id, System.currentTimeMillis()));
|
|
|
- } while (result != null && result.getSendStatus() == SendStatus.SEND_OK);
|
|
|
+ BoundSetOperations<String, Object> listOps = redisTemplate.boundSetOps("orderNotify::" + orderId);
|
|
|
+ listOps.add(id);
|
|
|
+ listOps.expire(7, TimeUnit.DAYS);
|
|
|
+
|
|
|
+ rocketMQTemplate.syncSend(generalProperties.getOrderNotifyTopic(),
|
|
|
+ new OrderNotifyEvent(orderId, payMethod, id, System.currentTimeMillis()));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -216,8 +210,13 @@ public class OrderNotifyController {
|
|
|
@PostMapping("/adapay/ordertest/{orderId}")
|
|
|
@ResponseBody
|
|
|
public void adapayNotifyTest(@PathVariable Long orderId, @RequestParam String transactionId) throws Exception {
|
|
|
- rocketMQTemplate.syncSend(generalProperties.getOrderNotifyTopic(),
|
|
|
- new OrderNotifyEvent(orderId, PayMethod.ALIPAY, transactionId, System.currentTimeMillis()));
|
|
|
+ if (Arrays.asList(env.getActiveProfiles()).contains("notifytest")) {
|
|
|
+ BoundSetOperations<String, Object> listOps = redisTemplate.boundSetOps("orderNotify::" + orderId);
|
|
|
+ listOps.add(transactionId);
|
|
|
+ listOps.expire(7, TimeUnit.DAYS);
|
|
|
+ rocketMQTemplate.syncSend(generalProperties.getOrderNotifyTopic(),
|
|
|
+ new OrderNotifyEvent(orderId, PayMethod.ALIPAY, transactionId, System.currentTimeMillis()));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@PostMapping("/adapay/giftOrder/{orderId}")
|