feat 拍照对照片进行识别对比
This commit is contained in:
@@ -13,11 +13,17 @@ using Dlhis.Jip.Api.Requests;
|
||||
using Dlhis.Sys.Api;
|
||||
using Kurisu.AspNetCore.Authentication.Abstractions;
|
||||
using Kurisu.AspNetCore.CustomClass;
|
||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
using Kurisu.AspNetCore.DataAccess.Extensions;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using Kurisu.AspNetCore.UnifyResultAndValidation;
|
||||
using Kurisu.AspNetCore.UnifyResultAndValidation.Abstractions;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.DataProtection;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Dlhis.Basic.Organization.Services.Implements;
|
||||
|
||||
@@ -35,6 +41,7 @@ public class GainfoFaceService : IGainfoFaceService
|
||||
private readonly IInfoCheckApi _infoCheckApi;
|
||||
private readonly IJinkoJipApi _jinkoJipApi;
|
||||
private readonly ITenantApi _tenantApi;
|
||||
private readonly IHikService _hikService;
|
||||
private readonly IDataProtectionProvider _dataProtectionProvider;
|
||||
|
||||
public GainfoFaceService(IGainfoStore gainfoStore,
|
||||
@@ -48,6 +55,7 @@ public class GainfoFaceService : IGainfoFaceService
|
||||
IInfoCheckApi infoCheckApi,
|
||||
IJinkoJipApi jinkoJipApi,
|
||||
ITenantApi tenantApi,
|
||||
IHikService hikService,
|
||||
IDataProtectionProvider dataProtectionProvider)
|
||||
{
|
||||
_logger = logger;
|
||||
@@ -62,6 +70,7 @@ public class GainfoFaceService : IGainfoFaceService
|
||||
_infoCheckApi = infoCheckApi;
|
||||
_jinkoJipApi = jinkoJipApi;
|
||||
_tenantApi = tenantApi;
|
||||
_hikService = hikService;
|
||||
_dataProtectionProvider = dataProtectionProvider;
|
||||
}
|
||||
|
||||
@@ -80,6 +89,7 @@ public class GainfoFaceService : IGainfoFaceService
|
||||
.WhereIF(request.Exists.HasValue && request.Exists.Value, x => existsFaceCodes.Contains(x.Code))
|
||||
.WhereIF(request.Exists.HasValue && !request.Exists.Value, x => !existsFaceCodes.Contains(x.Code))
|
||||
.WhereIF(request.Search.IsPresent(), x => x.Code == request.Search)
|
||||
.OrderBy(x => x.CreateTime, OrderByType.Desc)
|
||||
.Select((x, d) => new GainfoFacePageResponse
|
||||
{
|
||||
UserCode = x.Code,
|
||||
@@ -210,7 +220,7 @@ public class GainfoFaceService : IGainfoFaceService
|
||||
}
|
||||
}
|
||||
|
||||
public async Task UploadFaceAsync(GainfoUploadFaceRequest request)
|
||||
public async Task<IApiResult> UploadFaceAsync(GainfoUploadFaceRequest request)
|
||||
{
|
||||
var gainfo = await _gainfoStore.Queryable().Where(x => x.No == request.UserNo || x.Code == request.UserNo).SingleAsync();
|
||||
gainfo.ThrowIfNull("人员档案信息不存在");
|
||||
@@ -235,7 +245,33 @@ public class GainfoFaceService : IGainfoFaceService
|
||||
if (face.Face == request.Face)
|
||||
{
|
||||
_logger.LogWarning("相同的人脸照片更新忽略");
|
||||
return;
|
||||
return DefaultApiResult.Success("操作成功");
|
||||
}
|
||||
|
||||
var faceSimilaritySetting = await _dbContext.Queryable<BasicTypeEntity>().Where(x => x.Type == "faceSimilarity").SingleAsync();
|
||||
if (faceSimilaritySetting != null)
|
||||
{
|
||||
var faceSimilarity = await _hikService.GetSimilarityAsync(new GainfoFaceValidateRequest
|
||||
{
|
||||
SrcFacePicBinaryData = face.Face,
|
||||
DistFacePicBinaryData = request.Face
|
||||
});
|
||||
var acceptSimilarity = faceSimilaritySetting.Code.Adapt<double>();
|
||||
|
||||
var isError = faceSimilarity < acceptSimilarity;
|
||||
await _dbContext.InsertAsync(new HikValidateResultEntity
|
||||
{
|
||||
UserCode = face.UserCode,
|
||||
Similarity = faceSimilarity,
|
||||
AcceptSimilarity = acceptSimilarity,
|
||||
CurrentFace = face.Face,
|
||||
UploadFace = request.Face
|
||||
});
|
||||
|
||||
if (isError)
|
||||
{
|
||||
return DefaultApiResult.Error($"系统检测非本人更新,请重试(相似度{faceSimilarity})");
|
||||
}
|
||||
}
|
||||
|
||||
face.Face = request.Face;
|
||||
@@ -278,6 +314,8 @@ public class GainfoFaceService : IGainfoFaceService
|
||||
|
||||
//生成任务
|
||||
await _devicePermissionService.GenerateDeviceTasksAsync(gainfo.No, taskType, "照片上传生成");
|
||||
|
||||
return DefaultApiResult.Success("操作成功");
|
||||
}
|
||||
|
||||
public async Task UploadFacesAsync(List<GainfoUploadFaceRequest> requests)
|
||||
@@ -364,6 +402,27 @@ public class GainfoFaceService : IGainfoFaceService
|
||||
return faceDictionary;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<Pagination<FaceValidationResponse>> GetUploadPageRecordsAsync(FaceValidationRequest request)
|
||||
{
|
||||
return await _dbContext.Queryable<HikValidateResultEntity>()
|
||||
.LeftJoin<GainfoEntity>((x, ga) => x.UserCode == ga.Code)
|
||||
.WhereIF(request.IsSuccess.HasValue && request.IsSuccess.Value, x => x.AcceptSimilarity >= x.Similarity)
|
||||
.WhereIF(request.IsSuccess is false, x => x.AcceptSimilarity < x.Similarity)
|
||||
.WhereIF(request.Search.IsPresent(), (x, ga) => x.UserCode == request.Search || ga.Name.Contains(request.Search))
|
||||
.Select((x, ga) => new FaceValidationResponse
|
||||
{
|
||||
UserCode = x.UserCode,
|
||||
UserName = ga.Name,
|
||||
Similarity = x.Similarity,
|
||||
AcceptSimilarity = x.AcceptSimilarity,
|
||||
CurrentFace = x.CurrentFace,
|
||||
UploadFace = x.UploadFace,
|
||||
CreateTime = x.CreateTime
|
||||
})
|
||||
.ToPageListAsync(request);
|
||||
}
|
||||
|
||||
//*********************************************************************************************************************************************
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user