|
@@ -33,6 +33,9 @@ using Microsoft.IdentityModel.Tokens;
|
|
|
using Org.BouncyCastle.Asn1.Ocsp;
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
using System.Net;
|
|
|
+using Edge.Core.Domain.FccOrderInfo.Output;
|
|
|
+using Microsoft.AspNetCore.Mvc;
|
|
|
+using System.Timers;
|
|
|
|
|
|
namespace HengshanPaymentTerminal
|
|
|
{
|
|
@@ -82,6 +85,13 @@ namespace HengshanPaymentTerminal
|
|
|
|
|
|
public Dictionary<long,string> stationPayment = new Dictionary<long,string>();
|
|
|
|
|
|
+
|
|
|
+ public ConcurrentDictionary<int,string> nozzlePumpCode = new ConcurrentDictionary<int, string>();
|
|
|
+
|
|
|
+ public string buildID = "";
|
|
|
+
|
|
|
+ public bool isSendHeart = true;
|
|
|
+
|
|
|
public List<DetailsNozzleInfoOutput> nozzleInfoList { get; private set; }
|
|
|
|
|
|
public TcpClient? client { get; set; }
|
|
@@ -442,16 +452,28 @@ namespace HengshanPaymentTerminal
|
|
|
|
|
|
this.httpClientUtil = new HttpClientUtils();
|
|
|
|
|
|
+
|
|
|
this.serverPort = CommIdentity.Replace("*:", "").ToInt();
|
|
|
GetInfo();
|
|
|
+
|
|
|
+ if(stationInfo.CheckOrderInterval > 0)
|
|
|
+ {
|
|
|
+
|
|
|
+ System.Timers.Timer timer = new System.Timers.Timer(60000);
|
|
|
+ timer.Elapsed += (sender, eventArgs) =>
|
|
|
+ {
|
|
|
+ Task.Run(() => SendUnAuthorizationTimerAsync());
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public string CommIdentity { get; private set; }
|
|
|
|
|
|
public async Task Process(IContext<byte[], CommonMessage> context)
|
|
|
{
|
|
|
-
|
|
|
- switch(context.Incoming.Message.Handle)
|
|
|
+ logger.Info($"获取到信息:{JsonConvert.SerializeObject(context.Incoming.Message)}");
|
|
|
+ switch (context.Incoming.Message.Handle)
|
|
|
{
|
|
|
|
|
|
case 0x10:
|
|
@@ -465,7 +487,18 @@ namespace HengshanPaymentTerminal
|
|
|
case 0x18:
|
|
|
{
|
|
|
|
|
|
+ logger.Info($"订单信息");
|
|
|
OrderFromMachine orderFromMachine = (OrderFromMachine)context.Incoming.Message;
|
|
|
+ if(nozzlePumpCode.TryGetValue(orderFromMachine.nozzleNum, out string pumpCodeAndTTC))
|
|
|
+ {
|
|
|
+ if($"{orderFromMachine.pumpCode}_{orderFromMachine.ttc}".Equals(pumpCodeAndTTC))
|
|
|
+ {
|
|
|
+ logger.Info($"收到油机订单,泵码与流水号一致,为重复发送");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ logger.Info($"收到油机订单,泵码与流水号不一致,更新信息");
|
|
|
+ nozzlePumpCode[orderFromMachine.nozzleNum] = $"{orderFromMachine.pumpCode}_{orderFromMachine.ttc}";
|
|
|
FccOrderInfo fccOrderInfo = UpLoadOrder(orderFromMachine);
|
|
|
logger.Info($"receive order from machine,database had change");
|
|
|
CreateOrRedeemTransaction(fccOrderInfo);
|
|
@@ -527,9 +560,9 @@ namespace HengshanPaymentTerminal
|
|
|
*/
|
|
|
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
|
|
|
- if(context.Incoming.Message.Handle != 0x55) context.Outgoing.Write(context.Incoming.Message);
|
|
|
+ if (context.Incoming.Message.Handle != 0x55 && isSendHeart) context.Outgoing.Write(context.Incoming.Message);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -713,6 +746,7 @@ namespace HengshanPaymentTerminal
|
|
|
if(fccStationInfo != null)
|
|
|
{
|
|
|
stationInfo = new StationInfo(fccStationInfo);
|
|
|
+ buildID = stationInfo.BuildId;
|
|
|
string paymentType = stationInfo.PaymentType;
|
|
|
string[] paymentGround = paymentType.Split(",");
|
|
|
foreach (var item in paymentGround)
|
|
@@ -742,42 +776,63 @@ namespace HengshanPaymentTerminal
|
|
|
|
|
|
|
|
|
|
|
|
- public async void OnReceiveMqttMessage(string message)
|
|
|
+ public async void OnReceiveMqttMessage(string topic,string message)
|
|
|
{
|
|
|
+ logger.Info($"getMqtt topic:{topic},and message is {message}");
|
|
|
MqttRequest? mqttRequest = JsonConvert.DeserializeObject<MqttRequest>(message);
|
|
|
if (mqttRequest == null)
|
|
|
{
|
|
|
logger.Error($"mqtt message turn on object fail,message:{message}");
|
|
|
return;
|
|
|
}
|
|
|
- switch (mqttRequest.type)
|
|
|
+ if ($"authorization/{buildID}".Equals(topic))
|
|
|
{
|
|
|
- case MQTT_TYPE.AUTHORIZATION:
|
|
|
- {
|
|
|
-
|
|
|
- MqttAuthorizationRequest? mqttAuthorizationRequest = JsonConvert.DeserializeObject<MqttAuthorizationRequest>(mqttRequest.data);
|
|
|
- await SendAuthorizationAsync(mqttAuthorizationRequest);
|
|
|
- break;
|
|
|
- }
|
|
|
- case MQTT_TYPE.UNAUTHORIZATION:
|
|
|
- {
|
|
|
- MqttUnAhorizationRequest? mqttUnAhorizationRequest = JsonConvert.DeserializeObject<MqttUnAhorizationRequest>(mqttRequest.data);
|
|
|
- await SendUnAuthorizartion(mqttUnAhorizationRequest);
|
|
|
- break;
|
|
|
- }
|
|
|
- case MQTT_TYPE.PAID:
|
|
|
- {
|
|
|
- MqttPaidRequest? mqttPaidRequest = JsonConvert.DeserializeObject<MqttPaidRequest>(mqttRequest.data);
|
|
|
- await SendActuallyPaid(mqttPaidRequest, mqttRequest.UserName, mqttRequest.UserPhoneNumber);
|
|
|
- break;
|
|
|
- }
|
|
|
- case MQTT_TYPE.REFUND:
|
|
|
- {
|
|
|
- MqttRefundRequest? mqttRefundRequest = JsonConvert.DeserializeObject<MqttRefundRequest>(mqttRequest.data);
|
|
|
- await OnRecieveOrderRefund(mqttRefundRequest);
|
|
|
- break;
|
|
|
- }
|
|
|
+ MqttAuthorizationRequest? mqttAuthorizationRequest = JsonConvert.DeserializeObject<MqttAuthorizationRequest>(mqttRequest.data);
|
|
|
+ await SendAuthorizationAsync(mqttAuthorizationRequest, mqttRequest.UserName, mqttRequest.UserPhoneNumber);
|
|
|
+ }
|
|
|
+ if($"unAuthorization/{buildID}".Equals(topic))
|
|
|
+ {
|
|
|
+ MqttUnAhorizationRequest? mqttUnAhorizationRequest = JsonConvert.DeserializeObject<MqttUnAhorizationRequest>(mqttRequest.data);
|
|
|
+ await SendUnAuthorizartion(mqttUnAhorizationRequest);
|
|
|
}
|
|
|
+ if ($"paid/{buildID}".Equals (topic))
|
|
|
+ {
|
|
|
+ MqttPaidRequest? mqttPaidRequest = JsonConvert.DeserializeObject<MqttPaidRequest>(mqttRequest.data);
|
|
|
+ await SendActuallyPaid(mqttPaidRequest, mqttRequest.UserName, mqttRequest.UserPhoneNumber);
|
|
|
+ }
|
|
|
+ if ($"refund/{buildID}".Equals(topic))
|
|
|
+ {
|
|
|
+ MqttRefundRequest? mqttRefundRequest = JsonConvert.DeserializeObject<MqttRefundRequest>(mqttRequest.data);
|
|
|
+ await OnRecieveOrderRefund(mqttRefundRequest);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
@@ -860,43 +915,52 @@ namespace HengshanPaymentTerminal
|
|
|
Id = request.Id,
|
|
|
Result = 1
|
|
|
};
|
|
|
- await httpClientUtil.SendRecievePaidNotice(JsonConvert.SerializeObject(onGetPaidInfo));
|
|
|
+ HttpResponseMessage httpResponseMessage = await httpClientUtil.SendRecievePaidNotice(JsonConvert.SerializeObject(onGetPaidInfo));
|
|
|
+ logger.Info($"send actuallyPaid result response:{JsonConvert.SerializeObject(httpResponseMessage.Content.ReadAsStringAsync())}");
|
|
|
|
|
|
- FccOrderInfo? fccOrderInfo = mysqlDbContext.FccOrderInfos.FirstOrDefault(order =>
|
|
|
- order.NozzleNum == request.NozzleId
|
|
|
- && order.Ttc.ToString() == request.TransactionNumber
|
|
|
- && order.PumpCode == request.FuelItemPumpTotalizerVolume);
|
|
|
+ FccOrderInfo? fccOrderInfo = mysqlDbContext.FccOrderInfos.FirstOrDefault(order => order.CloundOrderId == request.Id);
|
|
|
if (fccOrderInfo == null)
|
|
|
{
|
|
|
- logger.Error($"[mqtt paid order notice]:can not find order by clounid:{request.Id}");
|
|
|
- return;
|
|
|
- }
|
|
|
- fccOrderInfo.CloundOrderId = request.Id;
|
|
|
- fccOrderInfo.AmountPayable = request.ActualPaymentAmount;
|
|
|
- fccOrderInfo.PaymentTime = request.TransactionTime;
|
|
|
- if(request.PaymentMethod != null)
|
|
|
+
|
|
|
+ logger.Info($"[mqtt paid order notice]:can not find order by clounid:{request.Id},is perpay");
|
|
|
+ string paymentName = "未知类型";
|
|
|
+ if (request.PaymentMethod != null)
|
|
|
+ {
|
|
|
+ paymentName = stationPayment[request.PaymentMethod ?? 0] ?? "未知类型";
|
|
|
+ }
|
|
|
+ fccOrderInfo = request.ToComponent(userName,phoneNumber, paymentName);
|
|
|
+ mysqlDbContext.Add(fccOrderInfo);
|
|
|
+ } else
|
|
|
{
|
|
|
- fccOrderInfo.PayType = (int)request.PaymentMethod;
|
|
|
- fccOrderInfo.PaymentName = stationPayment[request.PaymentMethod ?? 0] ?? "未知类型";
|
|
|
+ logger.Info($"[mqtt paid order notice]:find order,update order right now");
|
|
|
+
|
|
|
+ fccOrderInfo.AmountPayable = request.ActualPaymentAmount;
|
|
|
+ fccOrderInfo.VolumePayable = request.OriginalQty;
|
|
|
+ fccOrderInfo.PaymentTime = request.TransactionTime;
|
|
|
+ if (request.PaymentMethod != null)
|
|
|
+ {
|
|
|
+ fccOrderInfo.PayType = (int)request.PaymentMethod;
|
|
|
+ fccOrderInfo.PaymentName = stationPayment[request.PaymentMethod ?? 0] ?? "未知类型";
|
|
|
+ }
|
|
|
+ fccOrderInfo.UserName = userName ?? "";
|
|
|
+ fccOrderInfo.PhoneNumber = phoneNumber ?? string.Empty;
|
|
|
+ fccOrderInfo.PaymentStatus = 1;
|
|
|
}
|
|
|
- fccOrderInfo.UserName = userName??"";
|
|
|
- fccOrderInfo.PhoneNumber = phoneNumber ?? string.Empty;
|
|
|
- fccOrderInfo.PaymentStatus = 1;
|
|
|
+
|
|
|
|
|
|
mysqlDbContext.SaveChanges();
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ SendActuallyPaid sendActuallyPaid = new SendActuallyPaid(fccOrderInfo.NozzleNum, fccOrderInfo.Ttc, fccOrderInfo.AmountPayable ?? fccOrderInfo.Amount, getFrame(null));
|
|
|
+ byte[] commandAndNozzle = { sendActuallyPaid.Handle, (byte)sendActuallyPaid.NozzleNum };
|
|
|
+ await SendMessageToMaichine("发送实付金额", (request, response) =>
|
|
|
+ {
|
|
|
+ if (response.Handle == (byte)CommonMessage.Command.SEND_NEED_AMOUNT)
|
|
|
+ {
|
|
|
+ CommonAnswerBack commonAnswerBack = (CommonAnswerBack)response;
|
|
|
+ return commonAnswerBack.Command == (byte)CommonMessage.Command.SEND_NEED_AMOUNT && commonAnswerBack.NozzleNum == sendActuallyPaid.NozzleNum;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }, sendActuallyPaid);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -904,7 +968,7 @@ namespace HengshanPaymentTerminal
|
|
|
|
|
|
|
|
|
|
|
|
- public async Task SendAuthorizationAsync(MqttAuthorizationRequest? request)
|
|
|
+ public async Task SendAuthorizationAsync(MqttAuthorizationRequest? request, string? userName, string? phoneNumber)
|
|
|
{
|
|
|
MysqlDbContext mysqlDbContext = new MysqlDbContext();
|
|
|
if(request == null)
|
|
@@ -915,11 +979,16 @@ namespace HengshanPaymentTerminal
|
|
|
|
|
|
|
|
|
DateTime authorizationTime = request.AuthorizationTime ?? DateTime.Now;
|
|
|
- FccOrderInfo fccOrderInfo = request.ToComponent(authorizationTime);
|
|
|
- mysqlDbContext.FccOrderInfos.Add(fccOrderInfo);
|
|
|
+ FccOrderInfo? fccOrderInfo = await mysqlDbContext.FccOrderInfos.FirstOrDefaultAsync(order => order.CloundOrderId == request.Id);
|
|
|
+ if(fccOrderInfo == null)
|
|
|
+ {
|
|
|
+ logger.Error($"authorization find order by clound id:{request.Id} is null");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ fccOrderInfo.AuthorizationTime = authorizationTime;
|
|
|
|
|
|
|
|
|
- SendAuthorization sendAuthorization = new SendAuthorization((int)request.NozzleId, authorizationTime, 1,request.OriginalAmount, getFrame(null));
|
|
|
+ SendAuthorization sendAuthorization = new SendAuthorization((int)request.NozzleId, authorizationTime, 1, request.OriginalAmount, getFrame(null));
|
|
|
byte[] commandAndNozzle = { sendAuthorization.Handle, (byte)sendAuthorization.NozzleNum };
|
|
|
CommonMessage commonMessage = await SendMessageToMaichine("发送授权请求", (request, response) =>
|
|
|
{
|
|
@@ -930,6 +999,7 @@ namespace HengshanPaymentTerminal
|
|
|
}
|
|
|
return false;
|
|
|
}, sendAuthorization);
|
|
|
+ logger.Info($"获取到授权结果:{JsonConvert.SerializeObject(commonMessage)}");
|
|
|
|
|
|
|
|
|
string authorizationResultJson = string.Empty;
|
|
@@ -952,6 +1022,7 @@ namespace HengshanPaymentTerminal
|
|
|
else
|
|
|
{
|
|
|
AuthorizationResponse authorization = (AuthorizationResponse)commonMessage;
|
|
|
+
|
|
|
if (authorization.Result == 0)
|
|
|
{
|
|
|
sendAuthorizationResult.OilMachineStatus = OilMachineStatus.Failed;
|
|
@@ -960,11 +1031,20 @@ namespace HengshanPaymentTerminal
|
|
|
{
|
|
|
sendAuthorizationResult.OilMachineStatus = OilMachineStatus.Success;
|
|
|
sendAuthorizationResult.TransactionNumber = authorization.Ttc.ToString();
|
|
|
- fccOrderInfo.Ttc = authorization.Result;
|
|
|
+ fccOrderInfo.Ttc = authorization.Ttc;
|
|
|
+ fccOrderInfo.AuthorizationStatus = 1;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ logger.Info($"发送授权结果:{JsonConvert.SerializeObject(sendAuthorizationResult)}");
|
|
|
HttpResponseMessage httpResponseMessage = await httpClientUtil.SendAuthorizationResult(JsonConvert.SerializeObject(sendAuthorizationResult));
|
|
|
- logger.Info($"send authorization result response:{JsonConvert.SerializeObject(httpResponseMessage.Content)}");
|
|
|
+ logger.Info($"send authorization result response:{JsonConvert.SerializeObject(httpResponseMessage.Content.ReadAsStringAsync())}");
|
|
|
|
|
|
|
|
|
mysqlDbContext.SaveChanges();
|
|
@@ -983,29 +1063,28 @@ namespace HengshanPaymentTerminal
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
int ttc = 0;
|
|
|
DateTime authorizationTime = request.AuthorizationTime ?? DateTime.Now;
|
|
|
- bool ttsIntResult = int.TryParse(request.TransactionNumber, out ttc);
|
|
|
- if (request.AuthorizationTime == null || !ttsIntResult)
|
|
|
+ FccOrderInfo? fccOrderInfo = mysqlDbContext.FccOrderInfos.FirstOrDefault(order => order.CloundOrderId == request.Id);
|
|
|
+ bool isUnauthorization = false;
|
|
|
+ if (fccOrderInfo != null)
|
|
|
{
|
|
|
- FccOrderInfo? fccOrderInfo = mysqlDbContext.FccOrderInfos.FirstOrDefault(order => order.CloundOrderId == request.Id);
|
|
|
- if(fccOrderInfo != null)
|
|
|
- {
|
|
|
- ttc = fccOrderInfo.Ttc;
|
|
|
- authorizationTime = fccOrderInfo.AuthorizationTime;
|
|
|
- }
|
|
|
+ ttc = fccOrderInfo.Ttc;
|
|
|
+ authorizationTime = fccOrderInfo.AuthorizationTime;
|
|
|
+ isUnauthorization = fccOrderInfo.AuthorizationStatus == 0;
|
|
|
}
|
|
|
|
|
|
SendUnAuthorizationResult sendUnAuthorizationResult = new SendUnAuthorizationResult();
|
|
|
sendUnAuthorizationResult.NozzleId = request.NozzleId;
|
|
|
sendUnAuthorizationResult.OilMachineStatus = OilMachineStatus.Success;
|
|
|
|
|
|
- if (ttc != 0)
|
|
|
+ if (ttc != 0 && !isUnauthorization)
|
|
|
{
|
|
|
SendUnAuthorization sendUnAuthorization = new SendUnAuthorization((int)request.NozzleId, authorizationTime, ttc, getFrame(null));
|
|
|
byte[] commandAndNozzle = { sendUnAuthorization.Handle, (byte)sendUnAuthorization.NozzleNum };
|
|
|
|
|
|
+
|
|
|
CommonMessage commonMessage = await SendMessageToMaichine("发送取消授权请求", (request, response) =>
|
|
|
{
|
|
|
if (response.Handle == (byte)CommonMessage.Command.CANCEL_ACCREDIT)
|
|
@@ -1015,8 +1094,10 @@ namespace HengshanPaymentTerminal
|
|
|
}
|
|
|
return false;
|
|
|
}, sendUnAuthorization);
|
|
|
+
|
|
|
if (commonMessage.IsError)
|
|
|
{
|
|
|
+
|
|
|
ErrorMessage errorMessage = (ErrorMessage)commonMessage;
|
|
|
switch (errorMessage.TheErrorType)
|
|
|
{
|
|
@@ -1030,6 +1111,7 @@ namespace HengshanPaymentTerminal
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
+
|
|
|
UnAhorizationResponse unAuthorization = (UnAhorizationResponse)commonMessage;
|
|
|
if (unAuthorization.Result == 0)
|
|
|
{
|
|
@@ -1038,18 +1120,25 @@ namespace HengshanPaymentTerminal
|
|
|
else
|
|
|
{
|
|
|
sendUnAuthorizationResult.OilMachineStatus = OilMachineStatus.Success;
|
|
|
+ fccOrderInfo.AuthorizationStatus = 0;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- else
|
|
|
+ else if (!isUnauthorization)
|
|
|
{
|
|
|
+
|
|
|
+ sendUnAuthorizationResult.OilMachineStatus = OilMachineStatus.Success;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
sendUnAuthorizationResult.OilMachineStatus = OilMachineStatus.TransactionNumberNotFound;
|
|
|
}
|
|
|
|
|
|
HttpResponseMessage httpResponseMessage = await httpClientUtil.SendUnAuthorizationResult(JsonConvert.SerializeObject(sendUnAuthorizationResult));
|
|
|
- logger.Info($"send Unauthorization result response:{JsonConvert.SerializeObject(httpResponseMessage.Content)}");
|
|
|
+ logger.Info($"send Unauthorization result response:{JsonConvert.SerializeObject(httpResponseMessage.Content.ReadAsStringAsync())}");
|
|
|
}
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -1069,7 +1158,22 @@ namespace HengshanPaymentTerminal
|
|
|
Id = request.Id,
|
|
|
Result = 1
|
|
|
};
|
|
|
- await httpClientUtil.SendRecieveRefundNotice(JsonConvert.SerializeObject(onGetRefundInfo));
|
|
|
+ HttpResponseMessage httpResponseMessage = await httpClientUtil.SendRecieveRefundNotice(JsonConvert.SerializeObject(onGetRefundInfo));
|
|
|
+ logger.Info($"send refund result response:{JsonConvert.SerializeObject(httpResponseMessage.Content.ReadAsStringAsync())}");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ SendRefund sendRefund = new SendRefund((int)request.NozzleId, request.TransactionNumber, request.OriginalAmount, request.ActualPaymentAmount ?? 0m, request.RefundAmount ?? 0m, getFrame(null));
|
|
|
+ byte[] commandAndNozzle = { sendRefund.Handle, (byte)sendRefund.NozzleNum };
|
|
|
+ await SendMessageToMaichine("发送退款信息", (request, response) =>
|
|
|
+ {
|
|
|
+ if (response.Handle == (byte)CommonMessage.Command.SEND_NEED_AMOUNT)
|
|
|
+ {
|
|
|
+ CommonAnswerBack commonAnswerBack = (CommonAnswerBack)response;
|
|
|
+ return commonAnswerBack.Command == (byte)CommonMessage.Command.SEND_NEED_AMOUNT && commonAnswerBack.NozzleNum == sendRefund.NozzleNum;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }, sendRefund);
|
|
|
|
|
|
FccOrderInfo? fccOrderInfo = mysqlDbContext.FccOrderInfos.FirstOrDefault(order => order.CloundOrderId == request.Id);
|
|
|
if (fccOrderInfo == null)
|
|
@@ -1078,7 +1182,9 @@ namespace HengshanPaymentTerminal
|
|
|
return;
|
|
|
}
|
|
|
fccOrderInfo.AmountPayable = request.ActualPaymentAmount;
|
|
|
- fccOrderInfo.PaymentStatus = 2;
|
|
|
+ fccOrderInfo.RefundAmount = request.RefundAmount;
|
|
|
+ fccOrderInfo.PaymentStatus = (int)request.OrderStatus;
|
|
|
+ fccOrderInfo.RefundStatus = (int)request.RefundStatus;
|
|
|
mysqlDbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
@@ -1112,6 +1218,7 @@ namespace HengshanPaymentTerminal
|
|
|
private async Task<CommonMessage> SendMessageToMaichine(string sendTag, Func<CommonMessage, CommonMessage, bool> responseCapture,CommonMessage sendMessage)
|
|
|
{
|
|
|
logger.Info($"send request to machine:{sendTag}");
|
|
|
+ isSendHeart = false;
|
|
|
int retryCount = 0;
|
|
|
while (retryCount < 3)
|
|
|
{
|
|
@@ -1141,6 +1248,7 @@ namespace HengshanPaymentTerminal
|
|
|
|
|
|
}
|
|
|
Console.WriteLine("");
|
|
|
+ isSendHeart = true;
|
|
|
|
|
|
return (CommonMessage)response.Data;
|
|
|
}
|
|
@@ -1154,9 +1262,12 @@ namespace HengshanPaymentTerminal
|
|
|
if (retryCount >= 3)
|
|
|
{
|
|
|
logger.Info($"{sendTag}: is time out add retry 3 time");
|
|
|
+ isSendHeart = true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ isSendHeart = true;
|
|
|
return new ErrorMessage()
|
|
|
{
|
|
|
IsError = true,
|
|
@@ -1165,167 +1276,74 @@ namespace HengshanPaymentTerminal
|
|
|
};
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private async Task SendUnAuthorizationTimerAsync()
|
|
|
+ {
|
|
|
+ MysqlDbContext mysqlDbContext = new MysqlDbContext();
|
|
|
+ DateTime timeOut = DateTime.Now.AddMonths(stationInfo.CheckOrderInterval);
|
|
|
+ FccOrderInfo? fccOrderInfo = await mysqlDbContext.FccOrderInfos.FirstOrDefaultAsync(order => order.AuthorizationStatus == 1 && order.AuthorizationTime < timeOut);
|
|
|
|
|
|
-
|
|
|
+ if (fccOrderInfo == null)
|
|
|
+ {
|
|
|
+ logger.Info($"当前没有待取消授权的订单");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ SendUnAuthorizationResult sendUnAuthorizationResult = new SendUnAuthorizationResult();
|
|
|
+ sendUnAuthorizationResult.NozzleId = fccOrderInfo.NozzleNum;
|
|
|
+ sendUnAuthorizationResult.OilMachineStatus = OilMachineStatus.Success;
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ SendUnAuthorization sendUnAuthorization = new SendUnAuthorization(fccOrderInfo.NozzleNum, fccOrderInfo.AuthorizationTime, fccOrderInfo.Ttc, getFrame(null));
|
|
|
+ byte[] commandAndNozzle = { sendUnAuthorization.Handle, (byte)sendUnAuthorization.NozzleNum };
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+ CommonMessage commonMessage = await SendMessageToMaichine("定时发送取消授权请求", (request, response) =>
|
|
|
+ {
|
|
|
+ if (response.Handle == (byte)CommonMessage.Command.CANCEL_ACCREDIT)
|
|
|
+ {
|
|
|
+ UnAhorizationResponse unauthorization = (UnAhorizationResponse)response;
|
|
|
+ return unauthorization.NozzleNum == sendUnAuthorization.NozzleNum;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }, sendUnAuthorization);
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ if (commonMessage.IsError)
|
|
|
+ {
|
|
|
+
|
|
|
+ ErrorMessage errorMessage = (ErrorMessage)commonMessage;
|
|
|
+ switch (errorMessage.TheErrorType)
|
|
|
+ {
|
|
|
+ case CommonMessage.ErrorType.DISCONNECT:
|
|
|
+ sendUnAuthorizationResult.OilMachineStatus = OilMachineStatus.Disconnected;
|
|
|
+ break;
|
|
|
+ case CommonMessage.ErrorType.TIMEOUT:
|
|
|
+ sendUnAuthorizationResult.OilMachineStatus = OilMachineStatus.AuthorizationTimeout;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ UnAhorizationResponse unAuthorization = (UnAhorizationResponse)commonMessage;
|
|
|
+ if (unAuthorization.Result == 0)
|
|
|
+ {
|
|
|
+ sendUnAuthorizationResult.OilMachineStatus = OilMachineStatus.Failed;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sendUnAuthorizationResult.OilMachineStatus = OilMachineStatus.Success;
|
|
|
+ fccOrderInfo.AuthorizationStatus = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ mysqlDbContext.SaveChanges();
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ HttpResponseMessage httpResponseMessage = await httpClientUtil.SendUnAuthorizationResult(JsonConvert.SerializeObject(sendUnAuthorizationResult));
|
|
|
+ logger.Info($"定时任务取消授权:send Unauthorization timer result response:{JsonConvert.SerializeObject(httpResponseMessage.Content.ReadAsStringAsync())}");
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
@@ -1369,19 +1387,60 @@ namespace HengshanPaymentTerminal
|
|
|
private async void CreateOrRedeemTransaction(FccOrderInfo fccOrderInfo)
|
|
|
{
|
|
|
MysqlDbContext mysqlDbContext = new MysqlDbContext();
|
|
|
- CreateTransaction createTransaction = new CreateTransaction(fccOrderInfo);
|
|
|
- logger.Info($"create transaction, {JsonConvert.SerializeObject(createTransaction)}");
|
|
|
- HttpResponseMessage httpResponseMessage = await httpClientUtil.CreateTransaction(JsonConvert.SerializeObject(createTransaction));
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- string responseStr = await httpResponseMessage.Content.ReadAsStringAsync();
|
|
|
- Response<CreateTransactionResponse>? response = JsonConvert.DeserializeObject<Response<CreateTransactionResponse>>(responseStr);
|
|
|
- logger.Info($"reveice create transaction response:{JsonConvert.SerializeObject(response)}");
|
|
|
+ if (fccOrderInfo.CloundOrderId == null)
|
|
|
+ {
|
|
|
+ CreateTransaction createTransaction = new CreateTransaction(fccOrderInfo);
|
|
|
+ logger.Info($"create transaction, {JsonConvert.SerializeObject(createTransaction)}");
|
|
|
+ HttpResponseMessage httpResponseMessage = await httpClientUtil.CreateTransaction(JsonConvert.SerializeObject(createTransaction));
|
|
|
+
|
|
|
+ string responseStr = await httpResponseMessage.Content.ReadAsStringAsync();
|
|
|
+ Response<CreateTransactionResponse>? response = JsonConvert.DeserializeObject<Response<CreateTransactionResponse>>(responseStr);
|
|
|
+ logger.Info($"reveice create transaction response:{JsonConvert.SerializeObject(response)}");
|
|
|
+
|
|
|
+ fccOrderInfo.CloundOrderId = response?.data?.Id;
|
|
|
+ fccOrderInfo.UploadState = response?.data == null ? 0 : 1;
|
|
|
+ mysqlDbContext.SaveChanges();
|
|
|
+ } else
|
|
|
+ {
|
|
|
+
|
|
|
+ if(fccOrderInfo.Amount == 0 && fccOrderInfo.Volume == 0)
|
|
|
+ {
|
|
|
+
|
|
|
+ logger.Info("0交易,取消授权");
|
|
|
+ fccOrderInfo.AuthorizationStatus = 0;
|
|
|
+ mysqlDbContext.SaveChanges();
|
|
|
+
|
|
|
+ SendUnAuthorizationResult sendUnAuthorizationResult = new SendUnAuthorizationResult();
|
|
|
+ sendUnAuthorizationResult.NozzleId = fccOrderInfo.NozzleNum;
|
|
|
+ sendUnAuthorizationResult.TransactionNumber = fccOrderInfo.Ttc.ToString();
|
|
|
+ sendUnAuthorizationResult.OilMachineStatus = OilMachineStatus.Success;
|
|
|
+ HttpResponseMessage httpResponseMessage = await httpClientUtil.SendUnAuthorizationResult(JsonConvert.SerializeObject(sendUnAuthorizationResult));
|
|
|
+ logger.Info($"手动取消授权:send Unauthorization result response:{JsonConvert.SerializeObject(httpResponseMessage.Content.ReadAsStringAsync())}");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ Redeem redeem = new Redeem();
|
|
|
+ redeem.trxId = (int)fccOrderInfo.CloundOrderId;
|
|
|
+ redeem.OriginalQty = fccOrderInfo.Volume;
|
|
|
+
|
|
|
+ string param = JsonConvert.SerializeObject(redeem);
|
|
|
+
|
|
|
+ logger.Info($"Redeem order:{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)}");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
- fccOrderInfo.CloundOrderId = response?.data?.Id;
|
|
|
- fccOrderInfo.UploadState = response?.data == null ? 0 : 1;
|
|
|
- mysqlDbContext.SaveChanges();
|
|
|
}
|
|
|
|
|
|
|
|
@@ -1392,6 +1451,7 @@ namespace HengshanPaymentTerminal
|
|
|
{
|
|
|
|
|
|
List<SendNozzleStatu> sendNozzleStatus = new List<SendNozzleStatu>();
|
|
|
+ List<int> fuelingNozzle = new List<int>();
|
|
|
foreach (var nozzleState in heartBeatMessage.NozzleStatus)
|
|
|
{
|
|
|
if (nozzleStatusDic.TryGetValue(nozzleState.NozzleNum, out var value))
|
|
@@ -1400,6 +1460,7 @@ namespace HengshanPaymentTerminal
|
|
|
}
|
|
|
|
|
|
nozzleStatusDic[nozzleState.NozzleNum] = nozzleState.STATU;
|
|
|
+ if (nozzleState.STATU == 8) fuelingNozzle.Add(nozzleState.NozzleNum);
|
|
|
|
|
|
|
|
|
DetailsNozzleInfoOutput? detailsNozzleInfoOutput = nozzleInfoList.Find(nozzle => nozzle.NozzleNum == nozzleState.NozzleNum);
|
|
@@ -1408,24 +1469,41 @@ namespace HengshanPaymentTerminal
|
|
|
logger.Error($"can not find nozzleInfo from nozzleInfoList:{nozzleState.NozzleNum} ,send nozzle state fail");
|
|
|
continue;
|
|
|
}
|
|
|
- SendNozzleStatu sendNozzleStatu = new SendNozzleStatu(detailsNozzleInfoOutput.Id, nozzleState);
|
|
|
+ SendNozzleStatu sendNozzleStatu = new SendNozzleStatu(detailsNozzleInfoOutput.CloundNozzleId, nozzleState);
|
|
|
sendNozzleStatus.Add(sendNozzleStatu);
|
|
|
}
|
|
|
|
|
|
- if (sendNozzleStatus.IsNullOrEmpty()) return;
|
|
|
-
|
|
|
-
|
|
|
- string reuqestJson = JsonConvert.SerializeObject(sendNozzleStatus);
|
|
|
- logger.Info($"send nozzle state to cloud,{reuqestJson}");
|
|
|
- try
|
|
|
+
|
|
|
+ if (!sendNozzleStatus.IsNullOrEmpty())
|
|
|
{
|
|
|
- HttpResponseMessage httpResponseMessage = await httpClientUtil.SendNozzleStatu(reuqestJson);
|
|
|
- Response<object>? response = JsonConvert.DeserializeObject<Response<object>>(await httpResponseMessage.Content.ReadAsStringAsync());
|
|
|
- logger.Info($"reveice send nozzle state response:{JsonConvert.SerializeObject(response)}");
|
|
|
- } catch (Exception ex)
|
|
|
+
|
|
|
+ string reuqestJson = JsonConvert.SerializeObject(sendNozzleStatus);
|
|
|
+ logger.Info($"send nozzle state to cloud,{reuqestJson}");
|
|
|
+ try
|
|
|
+ {
|
|
|
+ HttpResponseMessage httpResponseMessage = await httpClientUtil.SendNozzleStatu(reuqestJson);
|
|
|
+ Response<object>? response = JsonConvert.DeserializeObject<Response<object>>(await httpResponseMessage.Content.ReadAsStringAsync());
|
|
|
+ logger.Info($"reveice send nozzle state response:{JsonConvert.SerializeObject(response)}");
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ logger.Error($"send nozzle stat fail:{ex.Message}");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ MysqlDbContext mysqlDbContext = new MysqlDbContext();
|
|
|
+ foreach(int nozzleNum in fuelingNozzle)
|
|
|
{
|
|
|
- logger.Error($"send nozzle stat fail:{ex.Message}");
|
|
|
+ FccOrderInfo? fccOrderInfo = await mysqlDbContext.FccOrderInfos
|
|
|
+ .OrderByDescending(order => order.AuthorizationTime)
|
|
|
+ .FirstOrDefaultAsync(order => order.NozzleNum == nozzleNum && order.AuthorizationStatus == 1);
|
|
|
+ if(fccOrderInfo != null)
|
|
|
+ {
|
|
|
+ fccOrderInfo.AuthorizationStatus = 3;
|
|
|
+ }
|
|
|
}
|
|
|
+ mysqlDbContext.SaveChanges();
|
|
|
|
|
|
}
|
|
|
|