feat 根据工号获取人脸链接
This commit is contained in:
@@ -112,5 +112,16 @@ public class GainfosController : ControllerBase
|
||||
{
|
||||
return await _gainfoService.GetFaceAsync(token);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取人脸照片
|
||||
/// </summary>
|
||||
/// <param name="userCode"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("face/{userCode}")]
|
||||
public async Task<string> GetFaceByUserCodeAsync(string userCode)
|
||||
{
|
||||
return await _gainfoService.GetFaceByUserCodeAsync(userCode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,4 +22,6 @@ public interface IGainfoService : IScopeDependency
|
||||
Task UploadFaceAsync(GainfoUploadFaceRequest request);
|
||||
|
||||
Task<IActionResult> GetFaceAsync(string token);
|
||||
|
||||
Task<string> GetFaceByUserCodeAsync(string userCode);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Dlhis.Basic.Organization.Request;
|
||||
using System.Threading.Tasks;
|
||||
using Dlhis.Basic.Organization.Request;
|
||||
using Dlhis.Basic.Organization.Response;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Basic.Enums;
|
||||
@@ -13,6 +14,8 @@ using Kurisu.SqlSugar.Services;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.DataProtection;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using NetTaste;
|
||||
|
||||
namespace Dlhis.Basic.Organization.Services.Implements;
|
||||
|
||||
@@ -266,4 +269,44 @@ public class GainfoService : IGainfoService
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<string> GetFaceByUserCodeAsync(string userCode)
|
||||
{
|
||||
var gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.Code == userCode).SingleAsync();
|
||||
gainfo.ThrowIfNull("人员信息不存在");
|
||||
|
||||
return await Scoped.Request.Value.CreateAsync<string>(async (sp) =>
|
||||
{
|
||||
var configuration = sp.GetService<IConfiguration>();
|
||||
|
||||
var faceConnectionString = configuration.GetSection("SqlSugarOptions:FaceConnectionString").Value;
|
||||
if (faceConnectionString.IsEmpty())
|
||||
{
|
||||
throw new UserFriendlyException("暂不支持获取人脸");
|
||||
}
|
||||
|
||||
var dbContext = sp.GetService<IDbContext>();
|
||||
//todo 切换连接字符串
|
||||
dbContext.Client.CurrentConnectionConfig.ConnectionString = faceConnectionString;
|
||||
|
||||
var face = await dbContext.Queryable<GainfoFaceEntity>()
|
||||
.Where(x => x.UserCode == userCode)
|
||||
.SingleAsync();
|
||||
|
||||
face.ThrowIfNull("人脸照片尚未录入");
|
||||
|
||||
var timeLimitedDataProtector = sp.GetService<IDataProtectionProvider>()
|
||||
.CreateProtector("down:face")
|
||||
.ToTimeLimitedDataProtector();
|
||||
|
||||
var faceUrl = configuration.GetSection("FaceUrlOptions:Url").Value;
|
||||
var limit = configuration.GetSection("FaceUrlOptions:Limit").Get<int>();
|
||||
var dataProtectionProvider = sp.GetService<IDataProtectionProvider>();
|
||||
|
||||
var key = $"face:{userCode}";
|
||||
var token = timeLimitedDataProtector.Protect(key, TimeSpan.FromSeconds(limit));
|
||||
|
||||
return faceUrl + token;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user