浏览代码

增加IC卡转换为IMEI

develop
H Vs 8 个月前
父节点
当前提交
f1425ab98d
共有 5 个文件被更改,包括 100 次插入22 次删除
  1. +1
    -0
      NearCardAttendance.Service/NearCardAttendance.Service.csproj
  2. +90
    -19
      NearCardAttendance.Service/TcpServer/Handler/RegisterHandler.cs
  3. +5
    -1
      NearCardAttendance.TcpServer/Program.cs
  4. +2
    -1
      NearCardAttendance.TcpServer/appsettings.debug.json
  5. +2
    -1
      NearCardAttendance.TcpServer/appsettings.test.json

+ 1
- 0
NearCardAttendance.Service/NearCardAttendance.Service.csproj 查看文件

@@ -15,6 +15,7 @@
<ItemGroup>
<ProjectReference Include="..\NearCardAttendance.Common\NearCardAttendance.Common.csproj" />
<ProjectReference Include="..\NearCardAttendance.Model\NearCardAttendance.Model.csproj" />
<PackageReference Include="TelpoDataService.Util" Version="1.6.9.24-beta1" />
</ItemGroup>

</Project>

+ 90
- 19
NearCardAttendance.Service/TcpServer/Handler/RegisterHandler.cs 查看文件

@@ -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的对应关系");
}
}
}
}

+ 5
- 1
NearCardAttendance.TcpServer/Program.cs 查看文件

@@ -13,6 +13,7 @@ using NearCardAttendance.TcpServer.Config;
using Serilog;
using NearCardAttendance.Model;
using System.Text;
using TelpoDataService.Util.Clients;

namespace NearCardAttendance.TcpServer
{
@@ -52,7 +53,10 @@ namespace NearCardAttendance.TcpServer
.UseSerilog()
.ConfigureServices((hostContext, services) => {
var configuration = hostContext.Configuration;

services.AddTelpoDataServices(opt =>
{
opt.TelpoDataUrl = configuration["ServiceConfig:TelpoDataUrl"];
});
#region 配置信息
services
.Configure<ServiceConfig>(configuration.GetSection("ServiceConfig"))


+ 2
- 1
NearCardAttendance.TcpServer/appsettings.debug.json 查看文件

@@ -1,6 +1,7 @@
{
"AllowedHosts": "*",
"ServiceConfig": {
"XinHuaLeYuUrl": "https://midplat.xinhualeyu.com/dev-api/user/electronicCardAttendance/receiveTbAttendanceRecord"
"XinHuaLeYuUrl": "https://midplat.xinhualeyu.com/dev-api/user/electronicCardAttendance/receiveTbAttendanceRecord",
"TelpoDataUrl": "https://ai.ssjlai.com/data"
}
}

+ 2
- 1
NearCardAttendance.TcpServer/appsettings.test.json 查看文件

@@ -1,6 +1,7 @@
{
"AllowedHosts": "*",
"ServiceConfig": {
"XinHuaLeYuUrl": "https://midplat.xinhualeyu.com/dev-api/user/electronicCardAttendance/receiveTbAttendanceRecord"
"XinHuaLeYuUrl": "https://midplat.xinhualeyu.com/dev-api/user/electronicCardAttendance/receiveTbAttendanceRecord",
"TelpoDataUrl": "https://ai.ssjlai.com/data"
}
}

正在加载...
取消
保存