Selaa lähdekoodia

增加STDT_SCHOOL_RECS 08 协议

develop
H Vs 9 kuukautta sitten
vanhempi
commit
e2648d2087
1 muutettua tiedostoa jossa 140 lisäystä ja 36 poistoa
  1. +140
    -36
      NearCardAttendance.Service/TcpServer/Handler/RegisterHandler.cs

+ 140
- 36
NearCardAttendance.Service/TcpServer/Handler/RegisterHandler.cs Näytä tiedosto

@@ -8,6 +8,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Channels;
using System.Threading.Tasks;

namespace NearCardAttendance.Service.TcpServer.Handler
@@ -59,44 +60,51 @@ namespace NearCardAttendance.Service.TcpServer.Handler
using (_logger.BeginScope(new Dictionary<string, object> { ["RequestId"] = parser.SeqNo }))
{
//认证
if (parser.FuncNo.Equals("10"))
{
#region 认证业务
// PHONE_AUTHEN
ProtocolWrapper phoneAuthWrapper = new(parser.FuncNo, parser.SeqNo, "1");
await SendToTcpClientAsync(phoneAuthWrapper, context.Channel);
// ABT_STATUS 延时3秒 给终端同步时间
await context.Channel.EventLoop.Schedule(async () =>
{
ProtocolWrapper abtStatusWrapper = new("82", parser.SeqNo, DateTime.Now.ToString("yyyyMMddHHmmss"));
await SendToTcpClientAsync(abtStatusWrapper, context.Channel);
},TimeSpan.FromSeconds(3));
#endregion
}
else if (parser.FuncNo.Equals("82"))
{
// 认证成功
_logger.LogInformation($"认证成功{parser.Data}.");
}
// 心跳
else if (parser.FuncNo.Equals("05"))
{
ProtocolWrapper stdtSignRecsWrapper = new(parser.FuncNo, parser.SeqNo,"");
await SendToTcpClientAsync(stdtSignRecsWrapper, context.Channel);
} // STDT_SIGN_RECS
else if (parser.FuncNo.Equals("04"))
{
// 回应设备
ProtocolWrapper stdtSignRecsWrapper = new(parser.FuncNo, parser.SeqNo,"1");
await SendToTcpClientAsync(stdtSignRecsWrapper, context.Channel);
// 刷卡考勤信息,需要推送给第三方平台
//if (parser.FuncNo.Equals("10"))
//{
// #region 认证业务
// // PHONE_AUTHEN
// ProtocolWrapper phoneAuthWrapper = new(parser.FuncNo, parser.SeqNo, "1");
// await SendToTcpClientAsync(phoneAuthWrapper, context.Channel);
// // ABT_STATUS 延时3秒 给终端同步时间
// await context.Channel.EventLoop.Schedule(async () =>
// {
// ProtocolWrapper abtStatusWrapper = new("82", parser.SeqNo, DateTime.Now.ToString("yyyyMMddHHmmss"));
// await SendToTcpClientAsync(abtStatusWrapper, context.Channel);
// },TimeSpan.FromSeconds(3));
// #endregion
//}
//else if (parser.FuncNo.Equals("82"))
//{
// // 认证成功
// _logger.LogInformation($"认证成功{parser.Data}.");
//}
//// 心跳
//else if (parser.FuncNo.Equals("05"))
//{
// ProtocolWrapper stdtSignRecsWrapper = new(parser.FuncNo, parser.SeqNo,"");
// await SendToTcpClientAsync(stdtSignRecsWrapper, context.Channel);
//} // STDT_SIGN_RECS
//else if (parser.FuncNo.Equals("04"))
//{
// // 回应设备
// ProtocolWrapper stdtSignRecsWrapper = new(parser.FuncNo, parser.SeqNo,"1");
// await SendToTcpClientAsync(stdtSignRecsWrapper, context.Channel);
// // 刷卡考勤信息,需要推送给第三方平台

//var url = "";
// //var url = "";

//await _httpHelper.HttpToPostAsync(url, new object());
}
// //await _httpHelper.HttpToPostAsync(url, new object());
//}
//// STDT_SCHOOL_RECS
//else if (parser.FuncNo.Equals("08"))
//{
// _logger.LogInformation($"接受STDT_SCHOOL_RECS 08 成功{parser.Data}.");
// ProtocolWrapper stdtSchoolRecsWrapper = new(parser.FuncNo, parser.SeqNo, "1");
// await SendToTcpClientAsync(stdtSchoolRecsWrapper, context.Channel);
//}


//switch (parser.FuncNo)
@@ -109,6 +117,28 @@ namespace NearCardAttendance.Service.TcpServer.Handler
// default:
// break;
//}

switch (parser.FuncNo)
{
case "10":
await HandleAuthenticationAsync(parser, context.Channel);
break;
case "82":
await HandleAuthenticationSuccessAsync(parser, context.Channel);
break;
case "05":
await SendHeartbeatAsync(parser, context.Channel);
break;
case "04":
await HandleSignRecsAsync(parser, context.Channel);
break;
case "08":
await HandleStdtSchoolRecsAsync(parser, context.Channel);
break;
default:
_logger.LogInformation($"未处理业务,func_no:{parser.FuncNo},seq_no{parser.SeqNo},data:{parser.Data}");
break;
}
}
}
catch (Exception ex)
@@ -138,5 +168,79 @@ namespace NearCardAttendance.Service.TcpServer.Handler
});
}

/// <summary>
/// 认证业务
/// </summary>
/// <param name="parser"></param>
/// <param name="channel"></param>
/// <returns></returns>
private async Task HandleAuthenticationAsync(ProtocolParser parser, IChannel channel)
{
ProtocolWrapper phoneAuthWrapper = new(parser.FuncNo, parser.SeqNo, "1");
await SendToTcpClientAsync(phoneAuthWrapper, channel);

await channel.EventLoop.Schedule(async () =>
{
ProtocolWrapper abtStatusWrapper = new("82", parser.SeqNo, DateTime.Now.ToString("yyyyMMddHHmmss"));
await SendToTcpClientAsync(abtStatusWrapper, channel);
}, TimeSpan.FromSeconds(3));
}

/// <summary>
/// 认证业务成功
/// </summary>
/// <param name="parser"></param>
/// <param name="channel"></param>
/// <returns></returns>
private async Task HandleAuthenticationSuccessAsync(ProtocolParser parser, IChannel channel)
{
_logger.LogInformation($"认证成功: func_no:{parser.FuncNo},seq_no{parser.SeqNo},data:{parser.Data}.");
await Task.CompletedTask;

}

/// <summary>
/// CONNECT_STATUS 网络连接状态查询[取值:05] (心跳业务)
/// </summary>
/// <param name="parser"></param>
/// <param name="channel"></param>
/// <returns></returns>
private async Task SendHeartbeatAsync(ProtocolParser parser, IChannel channel)
{
ProtocolWrapper stdtSignRecsWrapper = new(parser.FuncNo, parser.SeqNo, "");
await SendToTcpClientAsync(stdtSignRecsWrapper, channel);
}
/// <summary>
/// STDT_SIGN_RECS 学生签到记录[取值:04]
/// </summary>
/// <param name="parser"></param>
/// <param name="channel"></param>
/// <returns></returns>
private async Task HandleSignRecsAsync(ProtocolParser parser, IChannel channel)
{
ProtocolWrapper stdtSignRecsWrapper = new(parser.FuncNo, parser.SeqNo, "1");
await SendToTcpClientAsync(stdtSignRecsWrapper, channel);

// Push card attendance information to third-party platform
//var url = "https://midplat.xinhualeyu.com/dev-api/user/electronicCardAttendance/receiveTbAttendanceRecord";
//await _httpHelper.HttpToPostAsync(url, new object());
}
/// <summary>
/// STDT_SCHOOL_RECS 学生进校离校记录[取值:08]
/// </summary>
/// <param name="parser"></param>
/// <param name="channel"></param>
/// <returns></returns>
private async Task HandleStdtSchoolRecsAsync(ProtocolParser parser, IChannel channel)
{
_logger.LogInformation($"Received STDT_SCHOOL_RECS successfully: {parser.Data}.");
ProtocolWrapper stdtSchoolRecsWrapper = new(parser.FuncNo, parser.SeqNo, "1");
await SendToTcpClientAsync(stdtSchoolRecsWrapper, channel);

//var url = "https://midplat.xinhualeyu.com/dev-api/user/electronicCardAttendance/receiveTbAttendanceRecord";
//await _httpHelper.HttpToPostAsync(url, new object());
}
}
}

Loading…
Peruuta
Tallenna