Răsfoiți Sursa

feat:1、fcc前端页面跨域问题导致无法访问fcc接口问题处理;2、发送二维码信息到油机外部枪号错误修改;3、添加日志输入文本

Zhenghanjv 3 luni în urmă
părinte
comite
d2853dd88c

+ 56 - 33
Edge.Core/Processor/Communicator/TcpServerCommunicator.cs

@@ -24,8 +24,8 @@ namespace Edge.Core.Processor.Communicator
         private CancellationTokenSource readAsyncCancellationTokenSource;
         private DateTime? lastReceiveMsgDataFromTcpClientDateTime;
         private System.Timers.Timer clientSideActiveDetectionByCheckingLongTimeNoSeeDataIncomingWatchTimer;
-        //protected static NLog.Logger logger = NLog.LogManager.LoadConfiguration("nlog.config").GetLogger("Communicator");
-        protected ILogger logger = NullLogger.Instance;
+        private static NLog.Logger logger = NLog.LogManager.LoadConfiguration("nlog.config").GetLogger("TcpServerCommunicator");
+        //protected ILogger logger = NullLogger.Instance;
         public static int tcpReceiveBufferSize = 1500;
 
         private Edge.Core.Parser.BinaryParser.ParserBase parser;
@@ -71,16 +71,17 @@ namespace Edge.Core.Processor.Communicator
             IServiceProvider services)
         {
             this.Identity = "*:" + localTcpServerTcpListeningPortNumber;
-            if (services != null)
-            {
-                var loggerFactory = services.GetRequiredService<ILoggerFactory>();
-                this.logger = loggerFactory.CreateLogger("Communicator");
-                if (!string.IsNullOrEmpty(customLoggerFileName))
-                    if (customLoggerFileName == "*")
-                        this.logger = loggerFactory.CreateLogger("DynamicPrivate_Comm_" + localTcpServerTcpListeningPortNumber);
-                    else
-                        this.logger = loggerFactory.CreateLogger("DynamicPrivate_Comm_" + customLoggerFileName);
-            }
+            //if (services != null)
+            //{
+            //    var loggerFactory = services.GetRequiredService<ILoggerFactory>();
+            //    this.logger = loggerFactory.CreateLogger("Communicator");
+            //    if (!string.IsNullOrEmpty(customLoggerFileName))
+            //        if (customLoggerFileName == "*")
+            //            this.logger = loggerFactory.CreateLogger("DynamicPrivate_Comm_" + localTcpServerTcpListeningPortNumber);
+            //        else
+            //            this.logger = loggerFactory.CreateLogger("DynamicPrivate_Comm_" + customLoggerFileName);
+            //}
+
 
             this.messageCutter = binaryMsgCutter;
 
@@ -92,7 +93,8 @@ namespace Edge.Core.Processor.Communicator
                 this.messageCutter.OnInvalidMessageRead += (____, ______) =>
                 {
                     var loggingStr = $"Bytes msg from tcp client: {exclusiveTcpClient_ClientRemoteEndPoint_Str} Read Invalid data, detail: {(______?.Message ?? "")}";
-                    this.logger.LogInformation(loggingStr);
+                    //this.logger.LogInformation(loggingStr);
+                    logger.Info(loggingStr);
                     this.OnErrorMessageRead?.Invoke(this, new CommunicatorErrorMessageReadEventArg(null, loggingStr));
                 };
                 this.messageCutter.OnMessageCut += (s, _) =>
@@ -103,14 +105,16 @@ namespace Edge.Core.Processor.Communicator
                     {
                         eventArg.Data = this.messageCutter.Message;
                         eventArg.Message = this.parser.Deserialize(this.messageCutter.Message.ToArray()) as T;
-                        if (logger.IsEnabled(LogLevel.Debug))
-                            this.logger.LogDebug("      Parsed: " + eventArg.Message.ToLogString());
+                        //if (logger.IsEnabled(LogLevel.Debug))
+                            //this.logger.LogDebug("      Parsed: " + eventArg.Message.ToLogString());
+                        logger.Debug("      Parsed: " + eventArg.Message.ToLogString());
                     }
                     catch (Exception ex)
                     {
                         var loggingStr = "Message from " + exclusiveTcpClient_ClientRemoteEndPoint_Str
                             + " exceptioned in deserilaizing bytes:\r\n 0x" + this.messageCutter.Message.ToHexLogString() + "\r\n exception detail:\r\n" + ex;
-                        this.logger.LogError(loggingStr);
+                        //this.logger.LogError(loggingStr);
+                        logger.Error(loggingStr);
                         this.OnErrorMessageRead?.Invoke(this, new CommunicatorErrorMessageReadEventArg(this.messageCutter.Message, loggingStr));
                         return;
                     }
@@ -121,7 +125,9 @@ namespace Edge.Core.Processor.Communicator
                     }
                     catch (Exception ex)
                     {
-                        this.logger.LogError("Message from " + exclusiveTcpClient_ClientRemoteEndPoint_Str
+                        //this.logger.LogError("Message from " + exclusiveTcpClient_ClientRemoteEndPoint_Str
+                        //    + " exceptioned in handle message:\r\n" + eventArg.Message.ToLogString() + "\r\n exceptioned detail: \r\n" + ex);
+                        logger.Error("Message from " + exclusiveTcpClient_ClientRemoteEndPoint_Str
                             + " exceptioned in handle message:\r\n" + eventArg.Message.ToLogString() + "\r\n exceptioned detail: \r\n" + ex);
                     }
                 };
@@ -138,7 +144,8 @@ namespace Edge.Core.Processor.Communicator
                     if (DateTime.Now.Subtract(this.lastReceiveMsgDataFromTcpClientDateTime ?? DateTime.MinValue).TotalSeconds >= enableClientSideActiveDetection
                         && this.exclusiveTcpClient != null)
                     {
-                        this.logger.LogInformation($"Long time no see data from tcp client with: { this.exclusiveTcpClient_ClientRemoteEndPoint_Str }, will actively disconnect it...");
+                        //this.logger.LogInformation($"Long time no see data from tcp client with: { this.exclusiveTcpClient_ClientRemoteEndPoint_Str }, will actively disconnect it...");
+                        logger.Info($"Long time no see data from tcp client with: { this.exclusiveTcpClient_ClientRemoteEndPoint_Str }, will actively disconnect it...");
                         this.readAsyncCancellationTokenSource?.Cancel();
                     }
                 };
@@ -173,18 +180,22 @@ namespace Edge.Core.Processor.Communicator
                 {
                     this.tcpListener = new TcpListener(IPAddress.Any, this.localTcpServerListeningPort);
                     this.tcpListener.Start();
-                    this.logger.LogInformation($"TcpListener listened on localPort: {this.localTcpServerListeningPort}");
+                    //this.logger.LogInformation($"TcpListener listened on localPort: {this.localTcpServerListeningPort}");
+                    logger.Info($"TcpListener listened on localPort: {this.localTcpServerListeningPort}");
                     var _ = Task.Run(async () =>
                     {
                         while (this.isStarted == 1)
                         {
-                            logger.LogInformation($"Waitting for connection on localPort: {this.localTcpServerListeningPort}");
+                            //logger.LogInformation($"Waitting for connection on localPort: {this.localTcpServerListeningPort}");
+                            logger.Info($"Waitting for connection on localPort: {this.localTcpServerListeningPort}");
                             var newTcpClient = await this.tcpListener.AcceptTcpClientAsync();
-                            this.logger.LogInformation($"   A tcp client with remote ip/port: {newTcpClient.Client.RemoteEndPoint} has connected in");
+                            //this.logger.LogInformation($"   A tcp client with remote ip/port: {newTcpClient.Client.RemoteEndPoint} has connected in");
+                            logger.Info($"   A tcp client with remote ip/port: {newTcpClient.Client.RemoteEndPoint} has connected in");
 
                             if (this.exclusiveTcpClient != null)
                             {
-                                logger.LogInformation($"    There's already a previous TcpClient established as exclusive, so close this new one with remote ip/port: {newTcpClient.Client.RemoteEndPoint}");
+                                //logger.LogInformation($"    There's already a previous TcpClient established as exclusive, so close this new one with remote ip/port: {newTcpClient.Client.RemoteEndPoint}");
+                                logger.Info($"    There's already a previous TcpClient established as exclusive, so close this new one with remote ip/port: {newTcpClient.Client.RemoteEndPoint}");
                                 try
                                 {
                                     newTcpClient.Close();
@@ -195,7 +206,8 @@ namespace Edge.Core.Processor.Communicator
 
                             this.exclusiveTcpClient = newTcpClient;
                             this.exclusiveTcpClient_ClientRemoteEndPoint_Str = this.exclusiveTcpClient.Client.RemoteEndPoint.ToString();
-                            this.logger.LogInformation($"   Tcp client with remote ip/port: {this.exclusiveTcpClient_ClientRemoteEndPoint_Str} has been chosen as exclusive");
+                            //this.logger.LogInformation($"   Tcp client with remote ip/port: {this.exclusiveTcpClient_ClientRemoteEndPoint_Str} has been chosen as exclusive");
+                            logger.Info($"   Tcp client with remote ip/port: {this.exclusiveTcpClient_ClientRemoteEndPoint_Str} has been chosen as exclusive");
                             var ___ = Task.Run(async () =>
                             {
 
@@ -231,12 +243,15 @@ namespace Edge.Core.Processor.Communicator
                                         bytesReadCount = await this.exclusiveTcpClient.GetStream().ReadAsync(buffer, this.readAsyncCancellationTokenSource.Token);
                                         if (bytesReadCount == 0)
                                             throw new Exception("tcp server received 0 count data indicates the connection is broken");
-                                        if (logger.IsEnabled(LogLevel.Debug))
-                                            this.logger.LogDebug($"TCP from { this.exclusiveTcpClient_ClientRemoteEndPoint_Str } <---Incoming: 0x" + buffer.Take(bytesReadCount).ToHexLogString());
+                                        //if (logger.IsEnabled(LogLevel.Debug))
+                                        //    this.logger.LogDebug($"TCP from { this.exclusiveTcpClient_ClientRemoteEndPoint_Str } <---Incoming: 0x" + buffer.Take(bytesReadCount).ToHexLogString());
+                                        
+                                        logger.Debug($"TCP from {this.exclusiveTcpClient_ClientRemoteEndPoint_Str} <---Incoming: 0x" + buffer.Take(bytesReadCount).ToHexLogString());
                                     }
                                     catch (Exception eeee)
                                     {
-                                        logger.LogError($"tcp client with remote ip/port: {this.exclusiveTcpClient_ClientRemoteEndPoint_Str} exceptioned in GetStream().ReadAsync(), treat as tcp disconnection, detail: {eeee}");
+                                        //logger.LogError($"tcp client with remote ip/port: {this.exclusiveTcpClient_ClientRemoteEndPoint_Str} exceptioned in GetStream().ReadAsync(), treat as tcp disconnection, detail: {eeee}");
+                                        logger.Error($"tcp client with remote ip/port: {this.exclusiveTcpClient_ClientRemoteEndPoint_Str} exceptioned in GetStream().ReadAsync(), treat as tcp disconnection, detail: {eeee}");
                                         try
                                         {
                                             this.exclusiveTcpClient.Close();
@@ -266,7 +281,8 @@ namespace Edge.Core.Processor.Communicator
                                     }
                                     catch (Exception ex)
                                     {
-                                        this.logger.LogError($"Exception in Parsing msg bytes: 0x{ buffer.Take(bytesReadCount).ToHexLogString()}, detail: {Environment.NewLine}{ ex.ToString()}");
+                                        //this.logger.LogError($"Exception in Parsing msg bytes: 0x{ buffer.Take(bytesReadCount).ToHexLogString()}, detail: {Environment.NewLine}{ ex.ToString()}");
+                                        logger.Error($"Exception in Parsing msg bytes: 0x{ buffer.Take(bytesReadCount).ToHexLogString()}, detail: {Environment.NewLine}{ ex.ToString()}");
                                     }
                                 }
                             });
@@ -277,7 +293,8 @@ namespace Edge.Core.Processor.Communicator
                 }
                 catch (Exception exxx)
                 {
-                    logger.LogError($"Start tcp listener on port: {this.localTcpServerListeningPort} exceptioned: {exxx}");
+                    //logger.LogError($"Start tcp listener on port: {this.localTcpServerListeningPort} exceptioned: {exxx}");
+                    logger.Error($"Start tcp listener on port: {this.localTcpServerListeningPort} exceptioned: {exxx}");
                     return Task.FromResult(false);
                 }
             }
@@ -302,7 +319,8 @@ namespace Edge.Core.Processor.Communicator
                 //rawData = this.parser.Serialize(message);
                 var arg = new CommunicatorEventArg<byte[], T>() { Data = rawData, Message = message, Continue = true };
                 this.OnRawDataWriting?.Invoke(this, arg);
-                if (this.exclusiveTcpClient == null || !arg.Continue) { this.logger.LogError("Write failed, this.tcpClient is null: " + (this.exclusiveTcpClient is null)); return false; }
+                //if (this.exclusiveTcpClient == null || !arg.Continue) { this.logger.LogError("Write failed, this.tcpClient is null: " + (this.exclusiveTcpClient is null)); return false; }
+                if (this.exclusiveTcpClient == null || !arg.Continue) { logger.Error("Write failed, this.tcpClient is null: " + (this.exclusiveTcpClient is null)); return false; }
             }
             catch (Exception exx)
             {
@@ -316,7 +334,8 @@ namespace Edge.Core.Processor.Communicator
                     msgLogStr = "exceptioned for get ToLogString()";
                 }
 
-                this.logger.LogError("Tcp Write failed in serialize or event raise for msg: " + message.GetType() + " -> " + msgLogStr + "\r\n detail: " + exx);
+                //this.logger.LogError("Tcp Write failed in serialize or event raise for msg: " + message.GetType() + " -> " + msgLogStr + "\r\n detail: " + exx);
+                logger.Error("Tcp Write failed in serialize or event raise for msg: " + message.GetType() + " -> " + msgLogStr + "\r\n detail: " + exx);
                 return false;
             }
 
@@ -324,15 +343,19 @@ namespace Edge.Core.Processor.Communicator
             {
                 try
                 {
-                    if (logger.IsEnabled(LogLevel.Debug))
-                        this.logger.LogDebug("TCP to " + (this.exclusiveTcpClient_ClientRemoteEndPoint_Str) + " Outgoing--->: " + message.ToLogString() + "\r\n     0x" + rawData.ToHexLogString());
+                    //if (logger.IsEnabled(LogLevel.Debug))
+                    //    this.logger.LogDebug("TCP to " + (this.exclusiveTcpClient_ClientRemoteEndPoint_Str) + " Outgoing--->: " + message.ToLogString() + "\r\n     0x" + rawData.ToHexLogString());
+                    if(rawData.Length>8 && rawData[6] != 0x55 && rawData[7] != 0x10)
+                        logger.Info("TCP to " + (this.exclusiveTcpClient_ClientRemoteEndPoint_Str) + " Outgoing--->: " + message.ToLogString() + "\r\n     0x" + rawData.ToHexLogString());
                     var sendCount = this.exclusiveTcpClient.Client.Send(rawData);
                     if (sendCount == 0)
                         throw new InvalidOperationException("the send count in this.exclusiveTcpClient.Client.Send is 0");
                 }
                 catch (Exception exx)
                 {
-                    this.logger.LogError("Send tcp msg to "
+                    //this.logger.LogError("Send tcp msg to "
+                    //    + (this.exclusiveTcpClient_ClientRemoteEndPoint_Str) + " Write(...) exceptioned, treat as a broken tcp connection, will cancel the data read as well, detail: " + exx);
+                    logger.Error("Send tcp msg to "
                         + (this.exclusiveTcpClient_ClientRemoteEndPoint_Str) + " Write(...) exceptioned, treat as a broken tcp connection, will cancel the data read as well, detail: " + exx);
                     try
                     {

+ 3 - 2
HengshanPaymentTerminal/HengshanPayTermHandler.cs

@@ -103,7 +103,7 @@ namespace HengshanPaymentTerminal
 
         #region Logger
 
-        private static NLog.Logger logger = NLog.LogManager.LoadConfiguration("NLog.config").GetLogger("IPosPlusApp");
+        private static NLog.Logger logger = NLog.LogManager.LoadConfiguration("nlog.config").GetLogger("HengshanPayTermHandler");
 
         #endregion
 
@@ -805,7 +805,7 @@ namespace HengshanPaymentTerminal
                 //list.AddRange(qrCodeBytes);
                 //byte[] sendBytes = content2data(list.ToArray(), null);
 
-                SendQrCode sendQrCode = new SendQrCode((int)item.CloundNozzleId, smallProgram, getFrame(null));
+                SendQrCode sendQrCode = new SendQrCode((int)item.CloundNozzleId,item.NozzleNum, smallProgram, getFrame(null));
                 byte[] commandAndNozzle = { sendQrCode.Handle, (byte)sendQrCode.NozzleNum };
 
                 Thread.Sleep(5000);
@@ -1111,6 +1111,7 @@ namespace HengshanPaymentTerminal
         /// <returns></returns>
         private async Task<CommonMessage> SendMessageToMaichine(string sendTag, Func<CommonMessage, CommonMessage, bool> responseCapture,CommonMessage sendMessage)
         {
+            logger.Info($"send request to machine:{sendTag}");
             int retryCount = 0;
             while (retryCount < 3)
             {

+ 8 - 2
HengshanPaymentTerminal/MessageEntity/Outgoing/SendQrCode.cs

@@ -12,6 +12,11 @@ namespace HengshanPaymentTerminal.MessageEntity.Outgoing
     /// </summary>
     public class SendQrCode : CommonMessage
     {
+        /// <summary>
+        /// 云端油枪id
+        /// </summary>
+        public long CloundNozzleId { get; set; }
+
         /// <summary>
         /// 油枪号
         /// </summary>
@@ -22,10 +27,11 @@ namespace HengshanPaymentTerminal.MessageEntity.Outgoing
         /// </summary>
         private string SmallProgram {  get; set; }
 
-        public SendQrCode(int nozzle,string samllProgram,byte frame)
+        public SendQrCode(long cloundNozzleId,int nozzle,string samllProgram,byte frame)
         {
             this.Handle = (byte)Command.SEND_QR_CODE;
             this.NozzleNum = nozzle;
+            this.CloundNozzleId = cloundNozzleId;
             this.SmallProgram = samllProgram;
             this.FrameNum = frame;
         }
@@ -34,7 +40,7 @@ namespace HengshanPaymentTerminal.MessageEntity.Outgoing
         {
             List<Byte> list = new List<Byte>();
             byte[] commandAndNozzle = { this.Handle, (byte)this.NozzleNum };
-            string qrCode = this.SmallProgram + "?id=" + this.NozzleNum;
+            string qrCode = this.SmallProgram + "?id=" + this.CloundNozzleId;
             byte[] qrCodeBytes = Encoding.ASCII.GetBytes(qrCode);
             list.AddRange(commandAndNozzle);
             list.Add((byte)qrCodeBytes.Length);

+ 1 - 1
HengshanPaymentTerminal/StateMachineMessageCutter.cs

@@ -40,7 +40,7 @@ namespace HengshanPaymentTerminal
 
         #region Logger
 
-        static NLog.Logger innerLogger = NLog.LogManager.LoadConfiguration("nlog.config").GetLogger("Communicator");
+        static NLog.Logger innerLogger = NLog.LogManager.LoadConfiguration("nlog.config").GetLogger("StateMachineMessageCutter");
 
         #endregion
 

+ 1 - 1
src/FccWeb/admin.ui.plus-master/src/api/api.ts

@@ -188,7 +188,7 @@ export const getOrderFilter =(data:any)=>{
 export const downloadAfterpayOrder = (data:any) => {
 	const send = axios.create({
 		timeout: 5000, // 超时
-		baseURL: '/api',
+		baseURL: import.meta.env.VITE_API_URL_FCC,
 	})
 	return send.post('/qrFueling/order/downloadOrderAfterPayOrderExcel', data, { responseType: 'arraybuffer' })
 }