|
|
@@ -13,6 +13,11 @@ using System.Threading.Channels; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using NearCardAttendance.Model; |
|
|
|
using Microsoft.Extensions.Options; |
|
|
|
using TelpoDataService.Util.Entities.GpsCard; |
|
|
|
using TelpoDataService.Util; |
|
|
|
using TelpoDataService.Util.Clients; |
|
|
|
using TelpoDataService.Util.Models; |
|
|
|
using TelpoDataService.Util.QueryObjects; |
|
|
|
|
|
|
|
namespace NearCardAttendance.Service.TcpServer.Handler |
|
|
|
{ |
|
|
@@ -22,15 +27,17 @@ namespace NearCardAttendance.Service.TcpServer.Handler |
|
|
|
private readonly HttpHelper _httpHelper = default!; |
|
|
|
private readonly IDisposable _loggerScope = default!; |
|
|
|
private readonly ServiceConfig _configService; |
|
|
|
private readonly GpsCardAccessorClient<GpsDeviceConfig> _deviceConfigApiClient; |
|
|
|
|
|
|
|
//private readonly TcpClientsManager _managerTcpClients; |
|
|
|
//private readonly ScheduleResendManager _managerScheduleResend; |
|
|
|
|
|
|
|
public RegisterHandler(ILogger<RegisterHandler> logger,HttpHelper httpHelper, IOptions<ServiceConfig> configService) |
|
|
|
public RegisterHandler(ILogger<RegisterHandler> logger, GpsCardAccessorClient<GpsDeviceConfig> deviceConfigApiClient,HttpHelper httpHelper, IOptions<ServiceConfig> configService) |
|
|
|
{ |
|
|
|
_logger = logger; |
|
|
|
_httpHelper = httpHelper; |
|
|
|
_configService = configService.Value; |
|
|
|
_deviceConfigApiClient= deviceConfigApiClient; |
|
|
|
} |
|
|
|
|
|
|
|
public override void ChannelActive(IChannelHandlerContext context) |
|
|
@@ -232,15 +239,49 @@ namespace NearCardAttendance.Service.TcpServer.Handler |
|
|
|
var startTime = parser.Data.Substring(54, 14).TrimEnd(); |
|
|
|
// Push card attendance information to third-party platform |
|
|
|
//var url = "https://midplat.xinhualeyu.com/dev-api/user/electronicCardAttendance/receiveTbAttendanceRecord"; |
|
|
|
var url = _configService.XinHuaLeYuUrl; |
|
|
|
var data = new |
|
|
|
{ |
|
|
|
attendanceStatus = 2, //考勤状态: 0.进 1.出 2.未知 |
|
|
|
attendanceTime = DateTime.TryParse(startTime, out DateTime time) ? time.ToString("yyyy-MM-dd HH:mm:ss") : DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), |
|
|
|
imei = deviceId |
|
|
|
}; |
|
|
|
var res=await _httpHelper.HttpToPostAsync(url, data); |
|
|
|
_logger.LogInformation($"{nameof(HandleSignRecsAsync)} 推送 {JsonConvert.SerializeObject(data)} 结果,{res}"); |
|
|
|
|
|
|
|
#region IC卡转换为IMEI |
|
|
|
var config= await _deviceConfigApiClient.GetFirstAsync(new GeneralParam |
|
|
|
{ |
|
|
|
Filters = new List<QueryFilterCondition> |
|
|
|
{ |
|
|
|
new QueryFilterCondition |
|
|
|
{ |
|
|
|
Key=nameof(GpsDeviceConfig.IdNumber), |
|
|
|
Value=cardId, |
|
|
|
ValueType=QueryValueTypeEnum.String, |
|
|
|
Operator=QueryOperatorEnum.Equal |
|
|
|
} |
|
|
|
}, |
|
|
|
OrderBys=new List<OrderByCondition> |
|
|
|
{ |
|
|
|
new OrderByCondition |
|
|
|
{ |
|
|
|
IsDesc=true, |
|
|
|
Key=nameof(GpsDeviceConfig.LastUpdate), |
|
|
|
} |
|
|
|
} |
|
|
|
}, new RequestHeader { RequestId = parser.SeqNo }).ConfigureAwait(false); |
|
|
|
|
|
|
|
#endregion |
|
|
|
|
|
|
|
if (config!=null) |
|
|
|
{ |
|
|
|
var url = _configService.XinHuaLeYuUrl; |
|
|
|
var data = new |
|
|
|
{ |
|
|
|
attendanceStatus = 2, //考勤状态: 0.进 1.出 2.未知 |
|
|
|
attendanceTime = DateTime.TryParse(startTime, out DateTime time) ? time.ToString("yyyy-MM-dd HH:mm:ss") : DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), |
|
|
|
imei = config.Imei |
|
|
|
}; |
|
|
|
var res = await _httpHelper.HttpToPostAsync(url, data); |
|
|
|
_logger.LogInformation($"{nameof(HandleSignRecsAsync)} 推送 {JsonConvert.SerializeObject(data)} 结果,{res}"); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
_logger.LogInformation("找不到IC卡转换为IMEI的对应关系"); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
@@ -260,17 +301,47 @@ namespace NearCardAttendance.Service.TcpServer.Handler |
|
|
|
var studentId = parser.Data.Substring(36, 18).TrimEnd(); |
|
|
|
var startTime = parser.Data.Substring(54, 14).TrimEnd(); |
|
|
|
var optType = parser.Data.Substring(68, 1).TrimEnd(); |
|
|
|
#region IC卡转换为IMEI |
|
|
|
var config = await _deviceConfigApiClient.GetFirstAsync(new GeneralParam |
|
|
|
{ |
|
|
|
Filters = new List<QueryFilterCondition> |
|
|
|
{ |
|
|
|
new QueryFilterCondition |
|
|
|
{ |
|
|
|
Key=nameof(GpsDeviceConfig.IdNumber), |
|
|
|
Value=cardId, |
|
|
|
ValueType=QueryValueTypeEnum.String, |
|
|
|
Operator=QueryOperatorEnum.Equal |
|
|
|
} |
|
|
|
}, |
|
|
|
OrderBys = new List<OrderByCondition> |
|
|
|
{ |
|
|
|
new OrderByCondition |
|
|
|
{ |
|
|
|
IsDesc=true, |
|
|
|
Key=nameof(GpsDeviceConfig.LastUpdate), |
|
|
|
} |
|
|
|
} |
|
|
|
}, new RequestHeader { RequestId = parser.SeqNo }).ConfigureAwait(false); |
|
|
|
|
|
|
|
//var url = "https://midplat.xinhualeyu.com/dev-api/user/electronicCardAttendance/receiveTbAttendanceRecord"; |
|
|
|
var url = _configService.XinHuaLeYuUrl; |
|
|
|
var data = new |
|
|
|
#endregion |
|
|
|
if (config != null) |
|
|
|
{ |
|
|
|
//var url = "https://midplat.xinhualeyu.com/dev-api/user/electronicCardAttendance/receiveTbAttendanceRecord"; |
|
|
|
var url = _configService.XinHuaLeYuUrl; |
|
|
|
var data = new |
|
|
|
{ |
|
|
|
attendanceStatus = int.TryParse(optType, out int type) ? type : 0, |
|
|
|
attendanceTime = DateTime.TryParse(startTime, out DateTime time) ? time.ToString("yyyy-MM-dd HH:mm:ss") : DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), |
|
|
|
imei = config.Imei |
|
|
|
}; |
|
|
|
var res = await _httpHelper.HttpToPostAsync(url, data); |
|
|
|
_logger.LogInformation($"{nameof(HandleStdtSchoolRecsAsync)} 推送 {JsonConvert.SerializeObject(data)} 结果,{res}"); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
attendanceStatus = int.TryParse(optType,out int type) ? type : 0, |
|
|
|
attendanceTime = DateTime.TryParse(startTime, out DateTime time) ? time.ToString("yyyy-MM-dd HH:mm:ss") : DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), |
|
|
|
imei = deviceId |
|
|
|
}; |
|
|
|
var res = await _httpHelper.HttpToPostAsync(url, data); |
|
|
|
_logger.LogInformation($"{nameof(HandleStdtSchoolRecsAsync)} 推送 {JsonConvert.SerializeObject(data)} 结果,{res}"); |
|
|
|
_logger.LogInformation("找不到IC卡转换为IMEI的对应关系"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |