|
@@ -13,6 +13,15 @@ using Edge.Core.Processor.Dispatcher.Attributes;
|
|
|
using Edge.Core.IndustryStandardInterface.Pump;
|
|
|
using Edge.Core.IndustryStandardInterface.Pump.Fdc;
|
|
|
using Edge.Core.Processor;
|
|
|
+using Edge.Core.Core.database;
|
|
|
+using Edge.Core.Domain.FccStationInfo.Output;
|
|
|
+using Edge.Core.Domain.FccNozzleInfo;
|
|
|
+using Edge.Core.Domain.FccNozzleInfo.Output;
|
|
|
+using System.Net.Sockets;
|
|
|
+using Edge.Core.Domain.FccOrderInfo;
|
|
|
+using Microsoft.EntityFrameworkCore;
|
|
|
+using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;
|
|
|
+using static Microsoft.AspNetCore.Hosting.Internal.HostingApplication;
|
|
|
|
|
|
namespace HengshanPaymentTerminal
|
|
|
{
|
|
@@ -56,6 +65,13 @@ namespace HengshanPaymentTerminal
|
|
|
|
|
|
public Dictionary<int, List<int>> PumpSiteNozzleNoDict { get; private set; }
|
|
|
|
|
|
+ public MysqlDbContext MysqlDbContext { get; private set; }
|
|
|
+
|
|
|
+ public StationInfo stationInfo { get; set; }
|
|
|
+
|
|
|
+ public List<DetailsNozzleInfoOutput> nozzleInfoList { get; private set; }
|
|
|
+
|
|
|
+ public TcpClient? client { get; set; }
|
|
|
#endregion
|
|
|
|
|
|
#region Logger
|
|
@@ -112,7 +128,9 @@ namespace HengshanPaymentTerminal
|
|
|
this.pumpNozzles = pumpNozzles;
|
|
|
this.pumpSiteNozzleNos = pumpSiteNozzleNos;
|
|
|
this.nozzleLogicIds = nozzleLogicIds;
|
|
|
+ this.MysqlDbContext = new MysqlDbContext();
|
|
|
|
|
|
+ GetInfo();
|
|
|
AssociatedPumpIds = GetPumpIdList(pumpIds);
|
|
|
pumpIdSubAddressDict = InitializePumpSubAddressMapping();
|
|
|
PumpNozzlesDict = ParsePumpNozzlesList(pumpNozzles);
|
|
@@ -402,9 +420,12 @@ namespace HengshanPaymentTerminal
|
|
|
|
|
|
switch(context.Incoming.Message.Handle)
|
|
|
{
|
|
|
-
|
|
|
- case 0x55:
|
|
|
-
|
|
|
+
|
|
|
+ case 0x18:
|
|
|
+
|
|
|
+ OrderFromMachine message = (OrderFromMachine)context.Incoming.Message;
|
|
|
+ int row = UpLoadOrder(message);
|
|
|
+ logger.Info($"receive order from machine,database had ${row} count change");
|
|
|
break;
|
|
|
}
|
|
|
|
|
@@ -582,28 +603,207 @@ namespace HengshanPaymentTerminal
|
|
|
#region 二维码加油机相关方法
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+ private void GetInfo()
|
|
|
+ {
|
|
|
+ Edge.Core.Domain.FccStationInfo.FccStationInfo? fccStationInfo = MysqlDbContext.FccStationInfos.FirstOrDefault();
|
|
|
+ if(fccStationInfo != null) stationInfo = new StationInfo(fccStationInfo);
|
|
|
+ nozzleInfoList = MysqlDbContext.NozzleInfos.ToList().Select(n => new DetailsNozzleInfoOutput(n)).ToList();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public void SendQRCode()
|
|
|
+ {
|
|
|
+ string? smallProgram = stationInfo?.SmallProgram;
|
|
|
+ if (smallProgram == null)
|
|
|
+ {
|
|
|
+ logger.Info($"can not get smallProgram link");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ System.Net.EndPoint? remoteEndPoint = this.client?.Client.RemoteEndPoint;
|
|
|
+ if (remoteEndPoint == null)
|
|
|
+ {
|
|
|
+ logger.Info($"can not get client");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ string[] remoteAddr = remoteEndPoint.ToString().Split(":");
|
|
|
+ string ip = remoteAddr[0];
|
|
|
+
|
|
|
+ List<DetailsNozzleInfoOutput> nozzles = nozzleInfoList.FindAll(nozzle => nozzle.Ip == ip);
|
|
|
+ foreach (var item in nozzles)
|
|
|
+ {
|
|
|
+ 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());
|
|
|
+ this.client?.Client.Send(sendBytes);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public void SendActuallyPaid(FccOrderInfo orderInfo)
|
|
|
+ {
|
|
|
+ List<Byte> list = new List<Byte>();
|
|
|
+ byte[] commandAndNozzle = { 0x19, (byte)orderInfo.NozzleNum };
|
|
|
+ byte[] ttcBytes = NumberToByteArrayWithPadding(orderInfo.Ttc, 4);
|
|
|
+
|
|
|
+ byte[] amountPayableBytes = FormatDecimal(orderInfo.AmountPayable);
|
|
|
+ list.AddRange(commandAndNozzle);
|
|
|
+ list.AddRange(ttcBytes);
|
|
|
+ list.Add(0x21);
|
|
|
+ list.AddRange(amountPayableBytes);
|
|
|
+
|
|
|
+ list.AddRange(new byte[] { 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00 });
|
|
|
+ byte[] sendBytes = content2data(list.ToArray());
|
|
|
+ this.client?.Client.Send(sendBytes);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void SetTcpClinet(TcpClient? tcpClient)
|
|
|
+ {
|
|
|
+ this.client = tcpClient;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public int UpLoadOrder(OrderFromMachine order)
|
|
|
+ {
|
|
|
+ FccOrderInfo orderByMessage = order.ToComponent();
|
|
|
+ FccOrderInfo? fccOrderInfo = MysqlDbContext.fccOrderInfos.FirstOrDefault(fccOrder =>
|
|
|
+ fccOrder.NozzleNum == order.nozzleNum && fccOrder.Ttc == order.ttc);
|
|
|
+ if (fccOrderInfo == null)
|
|
|
+ {
|
|
|
+ logger.Info($"receive order from machine,find order from database is null");
|
|
|
+ MysqlDbContext.fccOrderInfos.Add(orderByMessage);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ logger.Info($"receive order from machine,padding data right now");
|
|
|
+ order.PaddingAuthorizationOrderData(fccOrderInfo);
|
|
|
+ }
|
|
|
+ return MysqlDbContext.SaveChanges();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
- private static Byte[] RemoveFA(Byte[] input)
|
|
|
+ public byte[] content2data(byte[] content)
|
|
|
+ {
|
|
|
+ List<byte> list = new List<byte>();
|
|
|
+
|
|
|
+ byte[] head = new byte[] { 0xFF, 0xE0, 0x01 };
|
|
|
+ byte[] length = Int2BCD(content.Length);
|
|
|
+ list.AddRange(head);
|
|
|
+ list.AddRange(length);
|
|
|
+ list.AddRange(content);
|
|
|
+ byte[] crc = HengshanCRC16.ComputeChecksumToBytes(list.ToArray());
|
|
|
+ list.AddRange(crc);
|
|
|
+ List<byte> addFAList = addFA(list);
|
|
|
+ addFAList.Insert(0, 0xFA);
|
|
|
+ return addFAList.ToArray();
|
|
|
+ }
|
|
|
+
|
|
|
+ public int Bcd2Int(byte byte1, byte byte2)
|
|
|
+ {
|
|
|
+
|
|
|
+ int digit1 = (byte1 >> 4) & 0x0F;
|
|
|
+ int digit2 = byte1 & 0x0F;
|
|
|
+
|
|
|
+
|
|
|
+ int digit3 = (byte2 >> 4) & 0x0F;
|
|
|
+ int digit4 = byte2 & 0x0F;
|
|
|
+
|
|
|
+
|
|
|
+ int result = digit1 * 1000 + digit2 * 100 + digit3 * 10 + digit4;
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public byte[] Int2BCD(int number)
|
|
|
+ {
|
|
|
+
|
|
|
+ int thousands = number / 1000;
|
|
|
+ int hundreds = (number / 100) % 10;
|
|
|
+ int tens = (number / 10) % 10;
|
|
|
+ int units = number % 10;
|
|
|
+
|
|
|
+
|
|
|
+ byte firstByte = (byte)((thousands * 16) + hundreds);
|
|
|
+
|
|
|
+
|
|
|
+ byte secondByte = (byte)((tens * 16) + units);
|
|
|
+
|
|
|
+
|
|
|
+ return new byte[] { firstByte, secondByte };
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<Byte> addFA(List<Byte> list)
|
|
|
{
|
|
|
- List<byte> resultList = new List<byte>();
|
|
|
+ List<byte> result = new List<byte>();
|
|
|
|
|
|
- for (int i = 0; i < input.Length; i++)
|
|
|
+ foreach (byte b in list)
|
|
|
{
|
|
|
- if (i < input.Length - 1 && input[i] == 0xFA && input[i + 1] == 0xFA)
|
|
|
+ if (b == 0xFA)
|
|
|
{
|
|
|
- resultList.Add(0xFA);
|
|
|
- i++;
|
|
|
+ result.Add(0xFA);
|
|
|
+ result.Add(0xFA);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- resultList.Add(input[i]);
|
|
|
+ result.Add(b);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return resultList.ToArray();
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static byte[] NumberToByteArrayWithPadding(int value, int length)
|
|
|
+ {
|
|
|
+ if (length < 0)
|
|
|
+ {
|
|
|
+ throw new ArgumentException("Length must be non-negative.");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ byte[] paddedBytes = new byte[length];
|
|
|
+
|
|
|
+
|
|
|
+ for (int i = 0; i < length && i < 4; i++)
|
|
|
+ {
|
|
|
+ paddedBytes[length - 1 - i] = (byte)(value >> (i * 8));
|
|
|
+ }
|
|
|
+
|
|
|
+ return paddedBytes;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static byte[] FormatDecimal(decimal value)
|
|
|
+ {
|
|
|
+
|
|
|
+ decimal roundedValue = Math.Round(value, 2, MidpointRounding.AwayFromZero);
|
|
|
+ int valueInt = (int)(roundedValue * 100m);
|
|
|
+ return NumberToByteArrayWithPadding(valueInt, 3); ;
|
|
|
}
|
|
|
|
|
|
|