master
nodyang@aliyun.com 2 months ago
parent 0c1214ff48
commit 55c2563e21

@ -19,4 +19,9 @@ public class ScanStatusSocket
public int is_alarm { get; set; }
public List<string> device_status { get; set; }
public List<string> status_txt { get; set; }
}

@ -1,10 +1,12 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using SlnMesnac.Model.domain;
using SlnMesnac.Repository.service;
using SlnMesnac.Repository.service.ScanLog;
using TouchSocket.Core;
using TouchSocket.Sockets;
@ -42,6 +44,8 @@ namespace SlnMesnac.TouchSocket
private readonly TcpService _service;
private readonly IScanLogService _scanService;
private readonly IBaseCodeService _baseCodeService;
// /// <summary>
// /// 接收客户端指令委托
// /// </summary>
@ -57,12 +61,12 @@ namespace SlnMesnac.TouchSocket
public Action<ScanStatusSocket> ScanStatusSocketAction;
public TcpServer(ILogger<TcpServer> logger,TcpService tcpService, IScanLogService scan)
public TcpServer(ILogger<TcpServer> logger,TcpService tcpService, IScanLogService scan, IBaseCodeService baseCodeService)
{
_logger = logger;
_service = tcpService;
_scanService = scan;
_baseCodeService = baseCodeService;
}
public void Init(int serverPort)
@ -102,7 +106,7 @@ namespace SlnMesnac.TouchSocket
if (dataType == 1)
{
ScanLogSocket scanStatus= JsonConvert.DeserializeObject<ScanLogSocket>(mes);
ScanLogSocket scanStatus= mes.FromJsonString<ScanLogSocket>();
ScanLogSocketAction?.Invoke(scanStatus);
_scanService.Insert(new ScanLogModel()
{
@ -122,8 +126,22 @@ namespace SlnMesnac.TouchSocket
{
if (dataType == 2)
{
ScanStatusSocket scanStatus= JsonConvert.DeserializeObject<ScanStatusSocket>(mes);
ScanStatusSocket scanStatus = mes.FromJsonString<ScanStatusSocket>();
ScanStatusSocketAction?.Invoke(scanStatus);
if (scanStatus.device_status != null && scanStatus.device_status.Count > 0)
{
List<string> ls = new List<string>();
var baseCodes = _baseCodeService.Query();
foreach (var baseCode in scanStatus.device_status)
{
var enBaseCode = baseCodes.FirstOrDefault(x=>x.Code==baseCode);
if (enBaseCode != null)
{
ls.Add(enBaseCode.State);
}
}
scanStatus.status_txt = ls;
}
}
}

Loading…
Cancel
Save