|
@@ -3,11 +3,12 @@ package com.fire.dist.service.impl;
|
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.fire.common.redis.RedisAmountScript;
|
|
|
import com.fire.dist.service.OrderUpdateService;
|
|
|
import com.fire.dto.FlowOrderInfo;
|
|
|
import com.fire.dto.MobileFlowDispatchRec;
|
|
|
+import com.fire.dto.TransactionFlow;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.rocketmq.client.exception.MQBrokerException;
|
|
|
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
|
|
import org.springframework.messaging.MessagingException;
|
|
|
import org.springframework.messaging.support.MessageBuilder;
|
|
@@ -15,11 +16,14 @@ import org.springframework.stereotype.Service;
|
|
|
import redis.clients.jedis.JedisCluster;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.util.Date;
|
|
|
|
|
|
-import static com.fire.common.constants.RocketTopic.CHILD_ORDER_TOPIC;
|
|
|
-import static com.fire.common.constants.RocketTopic.ORDER_TOPIC;
|
|
|
-import static com.fire.dto.enums.RedisKey.CHILD_ORDER_INFO;
|
|
|
-import static com.fire.dto.enums.RedisKey.ORDER_INFO;
|
|
|
+import static com.fire.common.constants.RocketTopic.*;
|
|
|
+import static com.fire.dto.enums.AmountOper.ADD;
|
|
|
+import static com.fire.dto.enums.OrderStatus.ORDER_FAIL;
|
|
|
+import static com.fire.dto.enums.RedisKey.*;
|
|
|
+import static com.fire.dto.enums.RelationType.RELATION_CUSTOMER;
|
|
|
+import static com.fire.dto.enums.ServiceType.SERVICE_ORDER_ADD;
|
|
|
|
|
|
/**
|
|
|
* 订单更新实现层
|
|
@@ -34,6 +38,8 @@ public class OrderUpdateServiceImpl implements OrderUpdateService {
|
|
|
private JedisCluster jedisCluster;
|
|
|
@Resource
|
|
|
private RocketMQTemplate rocketMQTemplate;
|
|
|
+ @Resource
|
|
|
+ private RedisAmountScript redisAmountScript;
|
|
|
|
|
|
/**
|
|
|
* 订单更新
|
|
@@ -44,6 +50,35 @@ public class OrderUpdateServiceImpl implements OrderUpdateService {
|
|
|
@Override
|
|
|
public void updateOrder(FlowOrderInfo orderInfo, String tag) {
|
|
|
Long orderId = orderInfo.getOrderId();
|
|
|
+ //如果订单失败 客户退款
|
|
|
+ if(ORDER_FAIL.status().equals(orderInfo.getStatus())){
|
|
|
+ Long afterAmount = redisAmountScript.changeAmount(SUPPLIER_AMOUNT.key(), orderInfo.getCustomerId(), ADD.oper(), orderInfo.getPrice(), 100000000000L);
|
|
|
+ Long transSeq = jedisCluster.incr(GLOBAL_ID_INCR.key());
|
|
|
+ TransactionFlow transaction = TransactionFlow.builder()
|
|
|
+ .afterAmount(afterAmount)
|
|
|
+ .beforeAmount(afterAmount + orderInfo.getOperatorBalancePrice())
|
|
|
+ .createTime(new Date())
|
|
|
+ .distinguish(RELATION_CUSTOMER.type())
|
|
|
+ .extorderId(orderInfo.getExtorderId())
|
|
|
+ .orderId(orderInfo.getOrderId())
|
|
|
+ .name(orderInfo.getCustomerName())
|
|
|
+ .note("订单失败退款")
|
|
|
+ .operatorName("system")
|
|
|
+ .operatingAmount(orderInfo.getPrice())
|
|
|
+ .serviceType(SERVICE_ORDER_ADD.type())
|
|
|
+ .relationId(orderInfo.getCustomerId())
|
|
|
+ .seqNo(transSeq)
|
|
|
+ .build();
|
|
|
+ try {
|
|
|
+ ObjectMapper om = new ObjectMapper();
|
|
|
+ //流水入队列
|
|
|
+ String transactionStr = om.writeValueAsString(transaction);
|
|
|
+ rocketMQTemplate.syncSend(TRANSACTION_TOPIC, MessageBuilder.withPayload(transactionStr).build());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("供应商下单扣减异常:", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
String orderStr;
|
|
|
ObjectMapper om = new ObjectMapper();
|
|
|
try {
|