You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
3.0 KiB
C#
103 lines
3.0 KiB
C#
using HighWayIot.Repository.domain;
|
|
using HighWayIot.Repository.service;
|
|
using HighWayIot.Repository.service.Impl;
|
|
using HighWayIot.TouchSocket;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Web;
|
|
|
|
|
|
namespace RFIDSocket
|
|
{
|
|
/// <summary>
|
|
/// 数据解析类
|
|
/// </summary>
|
|
public class ServerDataAnalysis
|
|
{
|
|
private static readonly Lazy<ServerDataAnalysis> lazy = new Lazy<ServerDataAnalysis>(() => new ServerDataAnalysis());
|
|
|
|
public static ServerDataAnalysis Instance => lazy.Value;
|
|
|
|
public List<RFIDContent> rFIDContents = new List<RFIDContent>();
|
|
public List<RFIDHeartbeat> rFIDHeartbeats = new List<RFIDHeartbeat>();
|
|
public List<RFIDHeartbeat> HeartbeatsState = new List<RFIDHeartbeat>();
|
|
public List<RFIDState> rFIDStates = new List<RFIDState>();
|
|
public List<RFIDState> AlarmState = new List<RFIDState>();
|
|
public IContentService ContentService = new BaseContentServiceImpl();
|
|
public IHeartbeatService HeartbeatService = new BaseHeartbeatServiceImpl();
|
|
public IStateService StateService = new BaseStateServiceImpl();
|
|
|
|
/// <summary>
|
|
/// 获取数据解析
|
|
/// </summary>
|
|
public void GetData()
|
|
{
|
|
|
|
rFIDContents = ContentService.GetContentInfos().Reverse<RFIDContent>().Take(200).ToList();
|
|
|
|
rFIDStates = StateService.GetStateInfos();
|
|
|
|
var StateGroup = rFIDStates.GroupBy(x => x.DeviceNo);
|
|
|
|
AlarmState.Clear();
|
|
|
|
foreach(var a in StateGroup)
|
|
{
|
|
var b = a.LastOrDefault();
|
|
if (b.DeviceState)
|
|
{
|
|
AlarmState.Add(b);
|
|
}
|
|
}
|
|
|
|
rFIDHeartbeats = HeartbeatService.GetHeartbeatInfos();
|
|
|
|
var HeartBeatGroup = rFIDHeartbeats.GroupBy(x => x.DeviceNo);
|
|
|
|
HeartbeatsState.Clear();
|
|
|
|
foreach (var a in HeartBeatGroup)
|
|
{
|
|
var b = a.LastOrDefault();
|
|
if (DateTime.Now - b.BeatTime > TimeSpan.FromSeconds(10))
|
|
{
|
|
b.TimeSpan = SecondToTime(Convert.ToInt32((DateTime.Now - b.BeatTime).TotalSeconds));
|
|
HeartbeatsState.Add(b);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 清除报警
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool ClearAllError()
|
|
{
|
|
return StateService.SetAllNoError();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 秒转时间
|
|
/// </summary>
|
|
/// <param name="t"></param>
|
|
/// <returns></returns>
|
|
private string SecondToTime(int t)
|
|
{
|
|
int m = t / 60;
|
|
int s = t % 60;
|
|
if (m == 0)
|
|
{
|
|
return "00 分 " + s.ToString("00") + " 秒";
|
|
}
|
|
return m.ToString("00") + " 分 " + s.ToString("00") + " 秒";
|
|
}
|
|
|
|
|
|
}
|
|
}
|