|
@@ -3,10 +3,12 @@ package com.fire.setcallback.service.impl;
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.fire.common.auth.SupplierAuth;
|
|
|
+import com.fire.common.redis.RedisAmountScript;
|
|
|
import com.fire.common.redis.RedisPriorityQueueScript;
|
|
|
import com.fire.dto.ChannelSupplier;
|
|
|
import com.fire.dto.FlowOrderInfo;
|
|
|
import com.fire.dto.MobileFlowDispatchRec;
|
|
|
+import com.fire.dto.TransactionFlow;
|
|
|
import com.fire.setcallback.data.DataPool;
|
|
|
import com.fire.setcallback.request.SetCallbackParam;
|
|
|
import com.fire.setcallback.service.SetCallbackService;
|
|
@@ -20,13 +22,15 @@ import javax.annotation.Resource;
|
|
|
import java.util.Date;
|
|
|
|
|
|
import static com.fire.common.constants.RocketTags.SUCCESS_TAG;
|
|
|
-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.OrderStatus.ORDER_SUCCESS;
|
|
|
import static com.fire.common.constants.RocketTags.FAIL_TAG;
|
|
|
+import static com.fire.dto.enums.RedisKey.*;
|
|
|
+import static com.fire.dto.enums.RedisKey.GLOBAL_ID_INCR;
|
|
|
+import static com.fire.dto.enums.RelationType.RELATION_SUPPLIER;
|
|
|
+import static com.fire.dto.enums.ServiceType.SERVICE_ORDER_ADD;
|
|
|
|
|
|
/**
|
|
|
* 客户查询定单状态
|
|
@@ -49,6 +53,9 @@ public class SetCallbackServiceImpl implements SetCallbackService {
|
|
|
@Resource
|
|
|
private RocketMQTemplate rocketMQTemplate;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private RedisAmountScript redisAmountScript;
|
|
|
+
|
|
|
@Override
|
|
|
public String setCallback(SetCallbackParam setCallbackParam) {
|
|
|
//查询redis 获取数据
|
|
@@ -57,28 +64,33 @@ public class SetCallbackServiceImpl implements SetCallbackService {
|
|
|
String childStr = jedisCluster.hget(CHILD_ORDER_INFO.key() + hKey, orderNo);
|
|
|
ObjectMapper om = new ObjectMapper();
|
|
|
MobileFlowDispatchRec mobileFlowDispatchRec = null;
|
|
|
+ ChannelSupplier channelSupplier;
|
|
|
try {
|
|
|
mobileFlowDispatchRec = om.readValue(childStr, MobileFlowDispatchRec.class);
|
|
|
Long ChannelId = mobileFlowDispatchRec.getChannelId();
|
|
|
-// //查询运营商
|
|
|
-// ChannelSupplier channelSupplier = DataPool.supplierHashMap.get(ChannelId);
|
|
|
-// String pwd = channelSupplier.getPasswd();
|
|
|
-// //校验参数 创建Header
|
|
|
-// RequestHeader header = new RequestHeader();
|
|
|
-// header.setOrgCode(channelSupplier.getAppKey());
|
|
|
-// header.setPartnerId(Long.valueOf(channelSupplier.getAccount()));
|
|
|
-// header.setTimestamp(setCallbackParam.getTimestamp());
|
|
|
-// header.setSign("MD5");
|
|
|
-// String sign = setCallbackParam.getSign();
|
|
|
-// String version1Sign = supplierAuth.version1Sign(pwd, header);
|
|
|
+ //查询运营商
|
|
|
+ channelSupplier = DataPool.supplierHashMap.get(ChannelId);
|
|
|
+ if (channelSupplier == null){
|
|
|
+ log.error("orderId:"+ orderNo + ";运营通道未找到!");
|
|
|
+ return "failed";
|
|
|
+ }
|
|
|
+ String pwd = channelSupplier.getPasswd();
|
|
|
+ //校验参数 创建Header
|
|
|
+ RequestHeader header = new RequestHeader();
|
|
|
+ header.setOrgCode(channelSupplier.getAppKey());
|
|
|
+ header.setPartnerId(Long.valueOf(channelSupplier.getAccount()));
|
|
|
+ header.setTimestamp(setCallbackParam.getTimestamp());
|
|
|
+ header.setSign("MD5");
|
|
|
+ String sign = setCallbackParam.getSign();
|
|
|
+ String version1Sign = supplierAuth.version1Sign(pwd, header);
|
|
|
//校验失败
|
|
|
-// if (!sign.equals(version1Sign)){
|
|
|
-// log.error("sign校验失败");
|
|
|
-// return "failed";
|
|
|
-// }
|
|
|
+ if (!sign.equals(version1Sign)){
|
|
|
+ log.error("orderId:"+ orderNo + ";sign校验失败");
|
|
|
+ return "failed";
|
|
|
+ }
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
- log.error(e.toString());
|
|
|
+ log.error("orderId:"+ orderNo , e);
|
|
|
return "failed";
|
|
|
}
|
|
|
//查询订单信息
|
|
@@ -90,7 +102,7 @@ public class SetCallbackServiceImpl implements SetCallbackService {
|
|
|
try {
|
|
|
flowOrderInfo = orderOm.readValue(orderStr, FlowOrderInfo.class);
|
|
|
} catch (JsonProcessingException e) {
|
|
|
- log.error(e.toString());
|
|
|
+ log.error("orderId:"+ orderNo , e);
|
|
|
return "failed";
|
|
|
}
|
|
|
//状态失败 主订单重入队列 分发订单置状态失败
|
|
@@ -99,6 +111,45 @@ public class SetCallbackServiceImpl implements SetCallbackService {
|
|
|
mobileFlowDispatchRec.setCallbackTime(new Date(setCallbackParam.getTimestamp()* 1000L));
|
|
|
//TODO 其他错误信息置状态
|
|
|
|
|
|
+ Long recId = mobileFlowDispatchRec.getRecId();
|
|
|
+ hKey = recId / 10000000;
|
|
|
+ //判断失败加款
|
|
|
+ try {
|
|
|
+ String newChildOrderStr = jedisCluster.hget(CHILD_ORDER_INFO.key() + hKey, String.valueOf(recId));
|
|
|
+ MobileFlowDispatchRec newChildOrder = om.readValue(newChildOrderStr, MobileFlowDispatchRec.class);
|
|
|
+ //如果当前是最终态 直接返回
|
|
|
+ if (ORDER_FAIL.status().equals(newChildOrder.getSendStatus()) || ORDER_SUCCESS.status().equals(newChildOrder.getSendStatus())) {
|
|
|
+ log.info("orderId:"+ orderNo + ";最终状态,不进行操作");
|
|
|
+ return "success";
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("orderId:"+ orderNo + ";实时子订单信息获取异常:", e);
|
|
|
+ }
|
|
|
+ //子订单加款
|
|
|
+ Long afterAmount = redisAmountScript.changeAmount(SUPPLIER_AMOUNT.key(), channelSupplier.getSupplierId(), ADD.oper(), mobileFlowDispatchRec.getOperatorBalancePrice(), 100000000000L);
|
|
|
+ Long transSeq = jedisCluster.incr(GLOBAL_ID_INCR.key());
|
|
|
+ TransactionFlow transaction = TransactionFlow.builder()
|
|
|
+ .afterAmount(afterAmount)
|
|
|
+ .beforeAmount(afterAmount + mobileFlowDispatchRec.getOperatorBalancePrice())
|
|
|
+ .createTime(new Date())
|
|
|
+ .distinguish(RELATION_SUPPLIER.type())
|
|
|
+ .extorderId(String.valueOf(mobileFlowDispatchRec.getRecId()))
|
|
|
+ .orderId(mobileFlowDispatchRec.getOrderId())
|
|
|
+ .name(channelSupplier.getSupplierName())
|
|
|
+ .note("订单失败退款")
|
|
|
+ .operatorName("system")
|
|
|
+ .operatingAmount(mobileFlowDispatchRec.getOperatorBalancePrice())
|
|
|
+ .serviceType(SERVICE_ORDER_ADD.type())
|
|
|
+ .relationId(channelSupplier.getSupplierId())
|
|
|
+ .seqNo(transSeq)
|
|
|
+ .build();
|
|
|
+ try {
|
|
|
+ //流水入队列
|
|
|
+ String transactionStr = om.writeValueAsString(transaction);
|
|
|
+ rocketMQTemplate.syncSend(TRANSACTION_TOPIC, MessageBuilder.withPayload(transactionStr).build());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("orderId:"+ orderNo + ";供应商下单扣减异常:", e);
|
|
|
+ }
|
|
|
//重加入优先级队列
|
|
|
redisPriorityQueueScript.addContent(orderId,orderStr);
|
|
|
//rides分发订单改状态
|
|
@@ -106,13 +157,14 @@ public class SetCallbackServiceImpl implements SetCallbackService {
|
|
|
try {
|
|
|
childStr = om.writeValueAsString(mobileFlowDispatchRec);
|
|
|
jedisCluster.hset(CHILD_ORDER_INFO.key() + hKey, orderNo, childStr);
|
|
|
+ //rocketMq发送消息
|
|
|
+ rocketMQTemplate.syncSendOrderly(CHILD_ORDER_TOPIC + ":" + FAIL_TAG, MessageBuilder.withPayload(childStr).build(), String.valueOf(mobileFlowDispatchRec.getRecId()));
|
|
|
+ log.info(orderId + "订单 FAILED");
|
|
|
} catch (Exception e) {
|
|
|
- log.error(e.toString());
|
|
|
+ log.error("orderId:"+ orderNo ,e);
|
|
|
return "failed";
|
|
|
}
|
|
|
- //rocketMq发送消息
|
|
|
- rocketMQTemplate.syncSendOrderly(CHILD_ORDER_TOPIC + ":" + FAIL_TAG, MessageBuilder.withPayload(childStr).build(), String.valueOf(mobileFlowDispatchRec.getRecId()));
|
|
|
- log.info(orderId + "订单 FAILED");
|
|
|
+
|
|
|
//状态成功 主订单置成功 分发订单置成功
|
|
|
}else if("SUCCESS".equals(setCallbackParam.getStatus())){
|
|
|
mobileFlowDispatchRec.setSendStatus(ORDER_SUCCESS.status());
|
|
@@ -139,7 +191,7 @@ public class SetCallbackServiceImpl implements SetCallbackService {
|
|
|
rocketMQTemplate.syncSendOrderly(CHILD_ORDER_TOPIC + ":" + SUCCESS_TAG, MessageBuilder.withPayload(childStr).build(), String.valueOf(mobileFlowDispatchRec.getRecId()));
|
|
|
log.info(orderId + "订单 SUCCESS");
|
|
|
} catch (Exception e) {
|
|
|
- log.error(e.toString());
|
|
|
+ log.error("orderId:"+ orderNo ,e);
|
|
|
return "failed";
|
|
|
}
|
|
|
}else{
|