|
@@ -109,6 +109,8 @@ namespace HengshanPaymentTerminal
|
|
|
|
|
|
//记录油枪状态,key-枪号,value:01:离线 02:锁枪 03:空闲 04:提枪 06:开始加油 08:加油中
|
|
|
private ConcurrentDictionary<int, int> nozzleStatusDic = new ConcurrentDictionary<int, int>();
|
|
|
+ //记录需要更新二维码信息的油枪
|
|
|
+ private HashSet<int> needUpdateQRSet = new HashSet<int>();
|
|
|
#endregion
|
|
|
|
|
|
#region Logger
|
|
@@ -464,6 +466,7 @@ namespace HengshanPaymentTerminal
|
|
|
{
|
|
|
Task.Run(() => SendUnAuthorizationTimerAsync());
|
|
|
};
|
|
|
+ timer.Start();
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -472,7 +475,6 @@ namespace HengshanPaymentTerminal
|
|
|
|
|
|
public async Task Process(IContext<byte[], CommonMessage> context)
|
|
|
{
|
|
|
- logger.Info($"获取到信息:{JsonConvert.SerializeObject(context.Incoming.Message)}");
|
|
|
switch (context.Incoming.Message.Handle)
|
|
|
{
|
|
|
//心跳,带油枪状态信息
|
|
@@ -487,7 +489,6 @@ namespace HengshanPaymentTerminal
|
|
|
case 0x18:
|
|
|
{
|
|
|
//添加或修改数据库订单
|
|
|
- logger.Info($"订单信息");
|
|
|
OrderFromMachine orderFromMachine = (OrderFromMachine)context.Incoming.Message;
|
|
|
if(nozzlePumpCode.TryGetValue(orderFromMachine.nozzleNum, out string pumpCodeAndTTC))
|
|
|
{
|
|
@@ -778,33 +779,41 @@ namespace HengshanPaymentTerminal
|
|
|
/// <param name="message"></param>
|
|
|
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)
|
|
|
+ try
|
|
|
{
|
|
|
- logger.Error($"mqtt message turn on object fail,message:{message}");
|
|
|
- return;
|
|
|
- }
|
|
|
- if ($"authorization/{buildID}".Equals(topic))
|
|
|
- {
|
|
|
- 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);
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ if ($"authorization/{buildID}".Equals(topic))
|
|
|
+ {
|
|
|
+ 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);
|
|
|
+ }
|
|
|
}
|
|
|
- if ($"refund/{buildID}".Equals(topic))
|
|
|
+ catch (Exception ex)
|
|
|
{
|
|
|
- MqttRefundRequest? mqttRefundRequest = JsonConvert.DeserializeObject<MqttRefundRequest>(mqttRequest.data);
|
|
|
- await OnRecieveOrderRefund(mqttRefundRequest);
|
|
|
+ logger.Error($"mqtt have error:{JsonConvert.SerializeObject(ex)}");
|
|
|
}
|
|
|
+
|
|
|
//switch (mqttRequest.type)
|
|
|
//{
|
|
|
// case MQTT_TYPE.AUTHORIZATION:
|
|
@@ -851,15 +860,6 @@ namespace HengshanPaymentTerminal
|
|
|
|
|
|
foreach (var item in nozzleInfoList)
|
|
|
{
|
|
|
- //List<Byte> list = new List<Byte>();
|
|
|
- //byte[] commandAndNozzle = { 0x63, (byte)item.NozzleNum };
|
|
|
- //string qrCode = smallProgram + "/" + item.NozzleNum;
|
|
|
- //byte[] qrCodeBytes = Encoding.ASCII.GetBytes(qrCode);
|
|
|
- //list.AddRange(commandAndNozzle);
|
|
|
- //list.Add((byte)qrCodeBytes.Length);
|
|
|
- //list.AddRange(qrCodeBytes);
|
|
|
- //byte[] sendBytes = content2data(list.ToArray(), null);
|
|
|
-
|
|
|
SendQrCode sendQrCode = new SendQrCode((int)item.CloundNozzleId,item.NozzleNum, smallProgram, getFrame(null));
|
|
|
byte[] commandAndNozzle = { sendQrCode.Handle, (byte)sendQrCode.NozzleNum };
|
|
|
|
|
@@ -873,8 +873,6 @@ namespace HengshanPaymentTerminal
|
|
|
}
|
|
|
return false;
|
|
|
}, sendQrCode);
|
|
|
- //CommonMessage commonMessage = await SendMessageToMaichine("发送二维码", BitConverter.ToString(commandAndNozzle).Replace("-", ""), sendQrCode);
|
|
|
- //CommonMessage commonMessage = await SendRequestToMachine("发送二维码", BitConverter.ToString(commandAndNozzle).Replace("-", ""), sendBytes);
|
|
|
if (commonMessage.IsError && commonMessage.TheErrorType == CommonMessage.ErrorType.DISCONNECT) break;
|
|
|
}
|
|
|
|
|
@@ -919,18 +917,7 @@ namespace HengshanPaymentTerminal
|
|
|
logger.Info($"send actuallyPaid result response:{JsonConvert.SerializeObject(httpResponseMessage.Content.ReadAsStringAsync())}");
|
|
|
|
|
|
FccOrderInfo? fccOrderInfo = mysqlDbContext.FccOrderInfos.FirstOrDefault(order => order.CloundOrderId == request.Id);
|
|
|
- if (fccOrderInfo == 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
|
|
|
+ if (fccOrderInfo != null)
|
|
|
{
|
|
|
logger.Info($"[mqtt paid order notice]:find order,update order right now");
|
|
|
//后支付,这里更新支付信息
|
|
@@ -945,22 +932,23 @@ namespace HengshanPaymentTerminal
|
|
|
fccOrderInfo.UserName = userName ?? "";
|
|
|
fccOrderInfo.PhoneNumber = phoneNumber ?? string.Empty;
|
|
|
fccOrderInfo.PaymentStatus = 1;
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
- mysqlDbContext.SaveChanges();
|
|
|
+ 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)
|
|
|
+
|
|
|
+ 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) =>
|
|
|
{
|
|
|
- CommonAnswerBack commonAnswerBack = (CommonAnswerBack)response;
|
|
|
- return commonAnswerBack.Command == (byte)CommonMessage.Command.SEND_NEED_AMOUNT && commonAnswerBack.NozzleNum == sendActuallyPaid.NozzleNum;
|
|
|
- }
|
|
|
- return false;
|
|
|
- }, sendActuallyPaid);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -977,15 +965,42 @@ namespace HengshanPaymentTerminal
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ //发送授权结果给云端
|
|
|
+ SendAuthorizationResult sendAuthorizationResult = new SendAuthorizationResult();
|
|
|
+ sendAuthorizationResult.NozzleId = request.NozzleId;
|
|
|
+
|
|
|
//添加订单到数据库
|
|
|
- DateTime authorizationTime = request.AuthorizationTime ?? DateTime.Now;
|
|
|
+ //DateTime authorizationTime = request.AuthorizationTime ?? DateTime.Now;
|
|
|
+ DateTime authorizationTime = DateTime.Now;
|
|
|
+ string paymentName = "未知类型";
|
|
|
+ if (request.PaymentMethod != null)
|
|
|
+ {
|
|
|
+ paymentName = stationPayment[request.PaymentMethod ?? 0] ?? "未知类型";
|
|
|
+ }
|
|
|
FccOrderInfo? fccOrderInfo = await mysqlDbContext.FccOrderInfos.FirstOrDefaultAsync(order => order.CloundOrderId == request.Id);
|
|
|
- if(fccOrderInfo == null)
|
|
|
+ if (fccOrderInfo != null && fccOrderInfo.AuthorizationStatus != 0)
|
|
|
{
|
|
|
- logger.Error($"authorization find order by clound id:{request.Id} is null");
|
|
|
+ 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;
|
|
|
}
|
|
|
- fccOrderInfo.AuthorizationTime = authorizationTime;
|
|
|
+
|
|
|
+ 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));
|
|
@@ -1001,10 +1016,7 @@ namespace HengshanPaymentTerminal
|
|
|
}, sendAuthorization);
|
|
|
logger.Info($"获取到授权结果:{JsonConvert.SerializeObject(commonMessage)}");
|
|
|
|
|
|
- //发送授权结果给云端
|
|
|
- string authorizationResultJson = string.Empty;
|
|
|
- SendAuthorizationResult sendAuthorizationResult = new SendAuthorizationResult();
|
|
|
- sendAuthorizationResult.NozzleId = request.NozzleId;
|
|
|
+
|
|
|
|
|
|
if (commonMessage.IsError)
|
|
|
{
|
|
@@ -1047,6 +1059,11 @@ namespace HengshanPaymentTerminal
|
|
|
logger.Info($"send authorization result response:{JsonConvert.SerializeObject(httpResponseMessage.Content.ReadAsStringAsync())}");
|
|
|
|
|
|
//更新订单
|
|
|
+ if(isInsertOrder)
|
|
|
+ {
|
|
|
+ mysqlDbContext.FccOrderInfos.Add(fccOrderInfo);
|
|
|
+ }
|
|
|
+
|
|
|
mysqlDbContext.SaveChanges();
|
|
|
}
|
|
|
|
|
@@ -1078,6 +1095,8 @@ namespace HengshanPaymentTerminal
|
|
|
SendUnAuthorizationResult sendUnAuthorizationResult = new SendUnAuthorizationResult();
|
|
|
sendUnAuthorizationResult.NozzleId = request.NozzleId;
|
|
|
sendUnAuthorizationResult.OilMachineStatus = OilMachineStatus.Success;
|
|
|
+ sendUnAuthorizationResult.TransactionID = request.Id;
|
|
|
+ sendUnAuthorizationResult.TransactionNumber = ttc.ToString();
|
|
|
|
|
|
if (ttc != 0 && !isUnauthorization)
|
|
|
{
|
|
@@ -1124,7 +1143,7 @@ namespace HengshanPaymentTerminal
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- else if (!isUnauthorization)
|
|
|
+ else if (isUnauthorization)
|
|
|
{
|
|
|
//若已经未授权
|
|
|
sendUnAuthorizationResult.OilMachineStatus = OilMachineStatus.Success;
|
|
@@ -1134,6 +1153,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())}");
|
|
|
}
|
|
@@ -1283,8 +1303,7 @@ 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);
|
|
|
+ FccOrderInfo? fccOrderInfo = await mysqlDbContext.FccOrderInfos.FirstOrDefaultAsync(order => order.AuthorizationStatus == 1 && order.AuthorizationTime.AddMinutes(stationInfo.CheckOrderInterval) < DateTime.Now);
|
|
|
|
|
|
if (fccOrderInfo == null)
|
|
|
{
|
|
@@ -1293,6 +1312,8 @@ namespace HengshanPaymentTerminal
|
|
|
}
|
|
|
SendUnAuthorizationResult sendUnAuthorizationResult = new SendUnAuthorizationResult();
|
|
|
sendUnAuthorizationResult.NozzleId = fccOrderInfo.NozzleNum;
|
|
|
+ sendUnAuthorizationResult.TransactionID = fccOrderInfo.CloundOrderId;
|
|
|
+ sendUnAuthorizationResult.TransactionNumber = fccOrderInfo.Ttc.ToString();
|
|
|
sendUnAuthorizationResult.OilMachineStatus = OilMachineStatus.Success;
|
|
|
|
|
|
SendUnAuthorization sendUnAuthorization = new SendUnAuthorization(fccOrderInfo.NozzleNum, fccOrderInfo.AuthorizationTime, fccOrderInfo.Ttc, getFrame(null));
|
|
@@ -1340,6 +1361,7 @@ namespace HengshanPaymentTerminal
|
|
|
|
|
|
mysqlDbContext.SaveChanges();
|
|
|
|
|
|
+ logger.Info($"定时任务取消授权:发送结果:{JsonConvert.SerializeObject(sendUnAuthorizationResult)}");
|
|
|
HttpResponseMessage httpResponseMessage = await httpClientUtil.SendUnAuthorizationResult(JsonConvert.SerializeObject(sendUnAuthorizationResult));
|
|
|
logger.Info($"定时任务取消授权:send Unauthorization timer result response:{JsonConvert.SerializeObject(httpResponseMessage.Content.ReadAsStringAsync())}");
|
|
|
|
|
@@ -1386,61 +1408,83 @@ namespace HengshanPaymentTerminal
|
|
|
|
|
|
private async void CreateOrRedeemTransaction(FccOrderInfo fccOrderInfo)
|
|
|
{
|
|
|
- MysqlDbContext mysqlDbContext = new MysqlDbContext();
|
|
|
- if (fccOrderInfo.CloundOrderId == null)
|
|
|
+ try
|
|
|
{
|
|
|
- CreateTransaction createTransaction = new CreateTransaction(fccOrderInfo);
|
|
|
- logger.Info($"create transaction, {JsonConvert.SerializeObject(createTransaction)}");
|
|
|
- HttpResponseMessage httpResponseMessage = await httpClientUtil.CreateTransaction(JsonConvert.SerializeObject(createTransaction));
|
|
|
+ MysqlDbContext mysqlDbContext = new MysqlDbContext();
|
|
|
+ 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)}");
|
|
|
+ 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
|
|
|
- {
|
|
|
- //MysqlDbContext mysqlDbContext = new MysqlDbContext();
|
|
|
- if(fccOrderInfo.Amount == 0 && fccOrderInfo.Volume == 0)
|
|
|
- {
|
|
|
- //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())}");
|
|
|
+ FccOrderInfo? order = await mysqlDbContext.FccOrderInfos.FirstOrDefaultAsync(order => order.Id == fccOrderInfo.Id);
|
|
|
+ if (order != null)
|
|
|
+ {
|
|
|
+ order.CloundOrderId = response?.data?.Id;
|
|
|
+ order.UploadState = response?.data == null ? 0 : 1;
|
|
|
+ int v = await mysqlDbContext.SaveChangesAsync();
|
|
|
+ logger.Info($"修改行数{v}");
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- //核销
|
|
|
- Redeem redeem = new Redeem();
|
|
|
- redeem.trxId = (int)fccOrderInfo.CloundOrderId;
|
|
|
- redeem.OriginalQty = fccOrderInfo.Volume;
|
|
|
+ //MysqlDbContext mysqlDbContext = new MysqlDbContext();
|
|
|
+ if (fccOrderInfo.Amount == 0 && fccOrderInfo.Volume == 0)
|
|
|
+ {
|
|
|
+ //0交易订单,证明为取消授权后产生的订单,不走核销,而是在小程序上显示为授权失败,让其重新发起授权或退款
|
|
|
+ logger.Info("0交易,取消授权");
|
|
|
+ FccOrderInfo? order = await mysqlDbContext.FccOrderInfos.FirstOrDefaultAsync(order => order.Id == fccOrderInfo.Id);
|
|
|
+ if (order != null)
|
|
|
+ {
|
|
|
+ order.AuthorizationStatus = 0; //存在油机手动取消授权的情况,因此这里也要更新授权状态
|
|
|
+ int v = await mysqlDbContext.SaveChangesAsync();
|
|
|
+ logger.Info($"修改行数{v}");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ SendUnAuthorizationResult sendUnAuthorizationResult = new SendUnAuthorizationResult();
|
|
|
+ sendUnAuthorizationResult.NozzleId = fccOrderInfo.NozzleNum;
|
|
|
+ sendUnAuthorizationResult.TransactionID = fccOrderInfo.CloundOrderId;
|
|
|
+ sendUnAuthorizationResult.TransactionNumber = fccOrderInfo.Ttc.ToString();
|
|
|
+ sendUnAuthorizationResult.OilMachineStatus = OilMachineStatus.Success;
|
|
|
+ logger.Info($"0交易,发送订单状态已为未授权:{JsonConvert.SerializeObject(sendUnAuthorizationResult)}");
|
|
|
+ HttpResponseMessage httpResponseMessage = await httpClientUtil.SendUnAuthorizationResult(JsonConvert.SerializeObject(sendUnAuthorizationResult));
|
|
|
+ logger.Info($"0交易,发送订单状态已为未授权响应:send Unauthorization result response:{JsonConvert.SerializeObject(httpResponseMessage.Content.ReadAsStringAsync())}");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //核销
|
|
|
+ Redeem redeem = new Redeem();
|
|
|
+ redeem.trxId = (int)fccOrderInfo.CloundOrderId;
|
|
|
+ redeem.OriginalQty = fccOrderInfo.Volume;
|
|
|
+ redeem.FuelItemPumpTotalizerVolume = fccOrderInfo.PumpCode ?? 0m;
|
|
|
|
|
|
- string param = JsonConvert.SerializeObject(redeem);
|
|
|
+ string param = JsonConvert.SerializeObject(redeem);
|
|
|
|
|
|
- logger.Info($"Redeem order:{param}");
|
|
|
- HttpResponseMessage httpResponseMessage = await httpClientUtil.Redeem(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)}");
|
|
|
+ string responseStr = await httpResponseMessage.Content.ReadAsStringAsync();
|
|
|
+ Response<CreateTransactionResponse>? response = JsonConvert.DeserializeObject<Response<CreateTransactionResponse>>(responseStr);
|
|
|
+ logger.Info($"核销订单回复:{JsonConvert.SerializeObject(response)}");
|
|
|
+
|
|
|
+ //fccOrderInfo.CloundOrderId = response?.data?.Id;
|
|
|
+ //fccOrderInfo.UploadState = response?.data == null ? 0 : 1;
|
|
|
+ //mysqlDbContext.SaveChanges();
|
|
|
+ }
|
|
|
|
|
|
- //fccOrderInfo.CloundOrderId = response?.data?.Id;
|
|
|
- //fccOrderInfo.UploadState = response?.data == null ? 0 : 1;
|
|
|
//mysqlDbContext.SaveChanges();
|
|
|
}
|
|
|
-
|
|
|
- //mysqlDbContext.SaveChanges();
|
|
|
+ } catch(Exception ex)
|
|
|
+ {
|
|
|
+ logger.Error($"创建或核销订单出错:{JsonConvert.SerializeObject(ex)}");
|
|
|
}
|
|
|
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -1454,6 +1498,14 @@ namespace HengshanPaymentTerminal
|
|
|
List<int> fuelingNozzle = new List<int>();
|
|
|
foreach (var nozzleState in heartBeatMessage.NozzleStatus)
|
|
|
{
|
|
|
+ //油机UI重启,重发二维码
|
|
|
+ if (nozzleState.STATU == 1) needUpdateQRSet.Add(nozzleState.NozzleNum);
|
|
|
+ if (nozzleState.STATU == 3 && needUpdateQRSet.Contains(nozzleState.NozzleNum))
|
|
|
+ {
|
|
|
+ UpdateQRCode(nozzleState.NozzleNum);
|
|
|
+ needUpdateQRSet.Remove(nozzleState.NozzleNum);
|
|
|
+ }
|
|
|
+
|
|
|
if (nozzleStatusDic.TryGetValue(nozzleState.NozzleNum, out var value))
|
|
|
{
|
|
|
if (nozzleState.STATU == value) continue;
|
|
@@ -1507,6 +1559,41 @@ namespace HengshanPaymentTerminal
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 更新二维码信息
|
|
|
+ /// 油机ui进入配置后退出,会重启UI,此时需要重新发送二维码
|
|
|
+ /// </summary>
|
|
|
+ public async void UpdateQRCode(int nozzleNum)
|
|
|
+ {
|
|
|
+ string smallProgram = stationInfo?.SmallProgram ?? "";
|
|
|
+ if (string.IsNullOrEmpty(smallProgram))
|
|
|
+ {
|
|
|
+ logger.Info($"更新二维码信息:can not get smallProgram link");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ DetailsNozzleInfoOutput? item = nozzleInfoList.Find(nozzle => nozzle.NozzleNum == nozzleNum);
|
|
|
+ if (item == null)
|
|
|
+ {
|
|
|
+ logger.Error($"找不到{nozzleNum}号枪信息");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ SendQrCode sendQrCode = new SendQrCode((int)item.CloundNozzleId, item.NozzleNum, smallProgram, getFrame(null));
|
|
|
+ byte[] commandAndNozzle = { sendQrCode.Handle, (byte)sendQrCode.NozzleNum };
|
|
|
+
|
|
|
+ Thread.Sleep(5000);
|
|
|
+ CommonMessage commonMessage = await SendMessageToMaichine($"发送{sendQrCode.NozzleNum}号枪二维码", (request, response) =>
|
|
|
+ {
|
|
|
+ if (response.Handle == (byte)CommonMessage.Command.COMMON)
|
|
|
+ {
|
|
|
+ CommonAnswerBack commonAnswerBack = (CommonAnswerBack)response;
|
|
|
+ return commonAnswerBack.Command == (byte)CommonMessage.Command.SEND_QR_CODE && commonAnswerBack.NozzleNum == sendQrCode.NozzleNum;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }, sendQrCode);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 获取发送帧号
|
|
|
/// </summary>
|