From cd916cd323fbe5058e77c873592f4b03e4a7fc6a Mon Sep 17 00:00:00 2001 From: "nodyang@aliyun.com" Date: Sat, 14 Sep 2024 11:02:54 +0800 Subject: [PATCH] demo --- SlnMesnac.TouchSocket/ScanLogSocket.cs | 2 +- .../SlnMesnac.TouchSocket.csproj | 1 + SlnMesnac.TouchSocket/TcpServer.cs | 28 ++++++++++++++++--- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/SlnMesnac.TouchSocket/ScanLogSocket.cs b/SlnMesnac.TouchSocket/ScanLogSocket.cs index a11f854..c0fa47d 100644 --- a/SlnMesnac.TouchSocket/ScanLogSocket.cs +++ b/SlnMesnac.TouchSocket/ScanLogSocket.cs @@ -20,7 +20,7 @@ public class ScanLogSocket public int data_type { get; set; } - public string ffid { get; set; } + public string rfid { get; set; } public string code { get; set; } diff --git a/SlnMesnac.TouchSocket/SlnMesnac.TouchSocket.csproj b/SlnMesnac.TouchSocket/SlnMesnac.TouchSocket.csproj index 94f69ee..ae8a9c3 100644 --- a/SlnMesnac.TouchSocket/SlnMesnac.TouchSocket.csproj +++ b/SlnMesnac.TouchSocket/SlnMesnac.TouchSocket.csproj @@ -12,6 +12,7 @@ + diff --git a/SlnMesnac.TouchSocket/TcpServer.cs b/SlnMesnac.TouchSocket/TcpServer.cs index 86b0710..8cfa253 100644 --- a/SlnMesnac.TouchSocket/TcpServer.cs +++ b/SlnMesnac.TouchSocket/TcpServer.cs @@ -4,6 +4,8 @@ using System.Collections.Generic; using System.Text; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using SlnMesnac.Model.domain; +using SlnMesnac.Repository.service.ScanLog; using TouchSocket.Core; using TouchSocket.Sockets; using JsonSerializer = System.Text.Json.JsonSerializer; @@ -36,6 +38,8 @@ namespace SlnMesnac.TouchSocket { private ILogger _logger; private readonly TcpService _service; + + private IScanLogService _scanService; /// /// 接收客户端指令委托 /// @@ -45,10 +49,11 @@ namespace SlnMesnac.TouchSocket public delegate void RefreshClientInfo(TcpService tcpService); public event RefreshClientInfo? RefreshClientInfoEvent; - public TcpServer(ILogger logger,TcpService tcpService) + public TcpServer(ILogger logger,TcpService tcpService, IScanLogService scan) { _logger = logger; _service = tcpService; + _scanService = scan; } public void Init(int serverPort) @@ -87,20 +92,35 @@ namespace SlnMesnac.TouchSocket if (dataType == 1) { - ScanStatusSocket scanStatus= JsonConvert.DeserializeObject(mes); + + ScanLogSocket scanStatus= JsonConvert.DeserializeObject(mes); + + _scanService.Insert(new ScanLogModel() + { + CreateTime = scanStatus.CreateTime, + DataType = scanStatus.data_type, + Code = scanStatus.code, + Rfid = scanStatus.rfid, + Ocr = scanStatus.ocr, + Url = scanStatus.url + + + }); + + } else { if (dataType == 2) { - ScanLogSocket scanStatus= JsonConvert.DeserializeObject(mes); + ScanStatusSocket scanStatus= JsonConvert.DeserializeObject(mes); } } // DateTimeOffset dateTimeOffset = DateTimeOffset.FromUnixTimeSeconds(timestamp); // DateTime dateTime = dateTimeOffset.UtcDateTime; - client.SendAsync(mes); + client.SendAsync(new Back().ToJsonString()); return EasyTask.CompletedTask; };