feat 批量上传人脸接口
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
using Dlhis.Basic.Organization.Request;
|
||||
using Dlhis.Basic.Organization.Response;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
@@ -22,6 +21,8 @@ public interface IGainfoService : IScopeDependency
|
||||
|
||||
Task UploadFaceAsync(GainfoUploadFaceRequest request);
|
||||
|
||||
Task UploadFacesAsync(List<GainfoUploadFaceRequest> request);
|
||||
|
||||
Task<IActionResult> GetFaceAsync(string token);
|
||||
|
||||
Task<string> GetFaceByUserCodeAsync(string userCode);
|
||||
|
||||
@@ -255,6 +255,54 @@ public class GainfoService : IGainfoService
|
||||
});
|
||||
}
|
||||
|
||||
public async Task UploadFacesAsync(List<GainfoUploadFaceRequest> requests)
|
||||
{
|
||||
foreach (var request in requests)
|
||||
{
|
||||
var gainfo = await _gainfoStore.Queryable(GainfoStatusEnumType.Working).Where(x => x.No == request.UserNo).FirstAsync();
|
||||
gainfo ??= await _gainfoStore.Queryable(GainfoStatusEnumType.External).Where(x => x.No == request.UserNo).FirstAsync();
|
||||
|
||||
gainfo.ThrowIfNull("人员档案信息不存在");
|
||||
|
||||
await Scoped.Request.Value.CreateAsync(async (sp) =>
|
||||
{
|
||||
var configuration = sp.GetService<IConfiguration>();
|
||||
var faceConnectionString = configuration.GetSection("SqlSugarOptions:FaceConnectionString").Value;
|
||||
|
||||
var dbContext = sp.GetService<IDbContext>();
|
||||
//todo 切换连接字符串
|
||||
dbContext.Client.CurrentConnectionConfig.ConnectionString = faceConnectionString;
|
||||
var face = await dbContext.Queryable<GainfoFaceEntity>().Where(x => x.UserCode == gainfo.Code).SingleAsync();
|
||||
|
||||
var taskType = face == null ? DeviceTaskEnumType.Add : DeviceTaskEnumType.Update;
|
||||
if (face == null)
|
||||
{
|
||||
face = new GainfoFaceEntity
|
||||
{
|
||||
UserCode = gainfo.Code,
|
||||
Face = request.Face
|
||||
};
|
||||
|
||||
await dbContext.InsertAsync(face);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (face.Face == request.Face)
|
||||
{
|
||||
_logger.LogWarning("相同的人脸照片更新忽略");
|
||||
return;
|
||||
}
|
||||
|
||||
face.Face = request.Face;
|
||||
await dbContext.UpdateAsync(face);
|
||||
}
|
||||
|
||||
//生成任务
|
||||
await _devicePermissionService.GenerateDeviceTasksAsync(gainfo.No, taskType);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async Task<string> GetFaceByUserCodeAsync(string userCode)
|
||||
|
||||
Reference in New Issue
Block a user