|
|
@@ -974,21 +974,41 @@ namespace HengshanPaymentTerminal
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ //发送授权结果给云端
|
|
|
+ SendAuthorizationResult sendAuthorizationResult = new SendAuthorizationResult();
|
|
|
+ sendAuthorizationResult.NozzleId = request.NozzleId;
|
|
|
+
|
|
|
//添加订单到数据库
|
|
|
- logger.Info($"[mqtt authorization order notice]:insert order");
|
|
|
DateTime authorizationTime = request.AuthorizationTime ?? DateTime.Now;
|
|
|
string paymentName = "未知类型";
|
|
|
if (request.PaymentMethod != null)
|
|
|
{
|
|
|
paymentName = stationPayment[request.PaymentMethod ?? 0] ?? "未知类型";
|
|
|
}
|
|
|
- FccOrderInfo fccOrderInfo = request.ToComponent(authorizationTime, paymentName,userName, phoneNumber);
|
|
|
- //if(fccOrderInfo == null)
|
|
|
- //{
|
|
|
- // logger.Error($"authorization find order by clound id:{request.Id} is null");
|
|
|
- // return;
|
|
|
- //}
|
|
|
- //fccOrderInfo.AuthorizationTime = authorizationTime;
|
|
|
+ FccOrderInfo? fccOrderInfo = await mysqlDbContext.FccOrderInfos.FirstOrDefaultAsync(order => order.CloundOrderId == request.Id);
|
|
|
+ if (fccOrderInfo != null && fccOrderInfo.AuthorizationStatus != 0)
|
|
|
+ {
|
|
|
+ sendAuthorizationResult.TransactionNumber = fccOrderInfo.Ttc.ToString();
|
|
|
+ sendAuthorizationResult.OilMachineStatus = OilMachineStatus.Success;
|
|
|
+ logger.Info($"订单已授权,发送授权结果:{JsonConvert.SerializeObject(sendAuthorizationResult)}");
|
|
|
+ HttpResponseMessage sendAuthorizationResponse = await httpClientUtil.SendAuthorizationResult(JsonConvert.SerializeObject(sendAuthorizationResult));
|
|
|
+ logger.Info($"订单已授权,发送授权结果响应:{JsonConvert.SerializeObject(sendAuthorizationResponse.Content.ReadAsStringAsync())}");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ bool isInsertOrder = true; //用于标记数据库应为插入或者更新
|
|
|
+ if(fccOrderInfo == null)
|
|
|
+ {
|
|
|
+ logger.Info($"[mqtt authorization order notice]:insert order");
|
|
|
+ isInsertOrder = true;
|
|
|
+ fccOrderInfo = request.ToComponent(authorizationTime, paymentName, userName, phoneNumber);
|
|
|
+ } else
|
|
|
+ {
|
|
|
+ logger.Info($"该订单已存在,但未授权,更新授权时间");
|
|
|
+ isInsertOrder = false;
|
|
|
+ fccOrderInfo.AuthorizationTime = authorizationTime;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
//发送授权申请到油机
|
|
|
SendAuthorization sendAuthorization = new SendAuthorization((int)request.NozzleId, authorizationTime, 1, request.OriginalAmount, getFrame(null));
|
|
|
@@ -1004,10 +1024,7 @@ namespace HengshanPaymentTerminal
|
|
|
}, sendAuthorization);
|
|
|
logger.Info($"获取到授权结果:{JsonConvert.SerializeObject(commonMessage)}");
|
|
|
|
|
|
- //发送授权结果给云端
|
|
|
- string authorizationResultJson = string.Empty;
|
|
|
- SendAuthorizationResult sendAuthorizationResult = new SendAuthorizationResult();
|
|
|
- sendAuthorizationResult.NozzleId = request.NozzleId;
|
|
|
+
|
|
|
|
|
|
if (commonMessage.IsError)
|
|
|
{
|
|
|
@@ -1050,7 +1067,11 @@ namespace HengshanPaymentTerminal
|
|
|
logger.Info($"send authorization result response:{JsonConvert.SerializeObject(httpResponseMessage.Content.ReadAsStringAsync())}");
|
|
|
|
|
|
//更新订单
|
|
|
- mysqlDbContext.FccOrderInfos.Add(fccOrderInfo);
|
|
|
+ if(isInsertOrder)
|
|
|
+ {
|
|
|
+ mysqlDbContext.FccOrderInfos.Add(fccOrderInfo);
|
|
|
+ }
|
|
|
+
|
|
|
mysqlDbContext.SaveChanges();
|
|
|
}
|
|
|
|
|
|
@@ -1129,7 +1150,7 @@ namespace HengshanPaymentTerminal
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- else if (!isUnauthorization)
|
|
|
+ else if (isUnauthorization)
|
|
|
{
|
|
|
//若已经未授权
|
|
|
sendUnAuthorizationResult.OilMachineStatus = OilMachineStatus.Success;
|
|
|
@@ -1139,6 +1160,7 @@ namespace HengshanPaymentTerminal
|
|
|
sendUnAuthorizationResult.OilMachineStatus = OilMachineStatus.TransactionNumberNotFound;
|
|
|
}
|
|
|
|
|
|
+ logger.Info($"send Unauthorization result:{JsonConvert.SerializeObject(sendUnAuthorizationResult)}");
|
|
|
HttpResponseMessage httpResponseMessage = await httpClientUtil.SendUnAuthorizationResult(JsonConvert.SerializeObject(sendUnAuthorizationResult));
|
|
|
logger.Info($"send Unauthorization result response:{JsonConvert.SerializeObject(httpResponseMessage.Content.ReadAsStringAsync())}");
|
|
|
}
|
|
|
@@ -1434,9 +1456,9 @@ namespace HengshanPaymentTerminal
|
|
|
sendUnAuthorizationResult.TransactionID = fccOrderInfo.CloundOrderId;
|
|
|
sendUnAuthorizationResult.TransactionNumber = fccOrderInfo.Ttc.ToString();
|
|
|
sendUnAuthorizationResult.OilMachineStatus = OilMachineStatus.Success;
|
|
|
- logger.Info($"0交易,取消授权:{JsonConvert.SerializeObject(sendUnAuthorizationResult)}");
|
|
|
+ logger.Info($"0交易,发送订单状态已为未授权:{JsonConvert.SerializeObject(sendUnAuthorizationResult)}");
|
|
|
HttpResponseMessage httpResponseMessage = await httpClientUtil.SendUnAuthorizationResult(JsonConvert.SerializeObject(sendUnAuthorizationResult));
|
|
|
- logger.Info($"手动取消授权:send Unauthorization result response:{JsonConvert.SerializeObject(httpResponseMessage.Content.ReadAsStringAsync())}");
|
|
|
+ logger.Info($"0交易,发送订单状态已为未授权响应:send Unauthorization result response:{JsonConvert.SerializeObject(httpResponseMessage.Content.ReadAsStringAsync())}");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -1448,12 +1470,12 @@ namespace HengshanPaymentTerminal
|
|
|
|
|
|
string param = JsonConvert.SerializeObject(redeem);
|
|
|
|
|
|
- logger.Info($"Redeem order:{param}");
|
|
|
+ logger.Info($"核销订单参数:{param}");
|
|
|
HttpResponseMessage httpResponseMessage = await httpClientUtil.Redeem(param);
|
|
|
|
|
|
string responseStr = await httpResponseMessage.Content.ReadAsStringAsync();
|
|
|
Response<CreateTransactionResponse>? response = JsonConvert.DeserializeObject<Response<CreateTransactionResponse>>(responseStr);
|
|
|
- logger.Info($"Redeem order response:{JsonConvert.SerializeObject(response)}");
|
|
|
+ logger.Info($"核销订单回复:{JsonConvert.SerializeObject(response)}");
|
|
|
|
|
|
//fccOrderInfo.CloundOrderId = response?.data?.Id;
|
|
|
//fccOrderInfo.UploadState = response?.data == null ? 0 : 1;
|
|
|
@@ -1464,7 +1486,7 @@ namespace HengshanPaymentTerminal
|
|
|
}
|
|
|
} catch(Exception ex)
|
|
|
{
|
|
|
- logger.Error($"出错:{JsonConvert.SerializeObject(ex)}");
|
|
|
+ logger.Error($"创建或核销订单出错:{JsonConvert.SerializeObject(ex)}");
|
|
|
}
|
|
|
|
|
|
|