diff --git a/Src/Dlhis.Basic/Organization/Controllers/GainfoFacesController.cs b/Src/Dlhis.Basic/Organization/Controllers/GainfoFacesController.cs
new file mode 100644
index 00000000..843ecbe9
--- /dev/null
+++ b/Src/Dlhis.Basic/Organization/Controllers/GainfoFacesController.cs
@@ -0,0 +1,35 @@
+using Dlhis.Basic.Organization.Request;
+using Dlhis.Basic.Organization.Response;
+using Dlhis.Basic.Organization.Services;
+using Kurisu.AspNetCore.DataAccess.Dto;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc;
+
+namespace Dlhis.Basic.Organization.Controllers;
+
+///
+/// 档案人脸
+///
+[Authorize]
+[Route("api/[controller]")]
+[ApiController]
+public class GainfoFacesController : ControllerBase
+{
+ private readonly IGainfoFaceService _gainfoFaceService;
+
+ public GainfoFacesController(IGainfoFaceService gainfoFaceService)
+ {
+ _gainfoFaceService = gainfoFaceService;
+ }
+
+ ///
+ /// 人脸档案分页
+ ///
+ ///
+ ///
+ [HttpPost("page")]
+ public async Task GetPageAsync([FromQuery] GainfoFacePageRequest request)
+ {
+ return await _gainfoFaceService.GetPageAsync(request);
+ }
+}
\ No newline at end of file
diff --git a/Src/Dlhis.Basic/Organization/Request/GainfoFacePageRequest.cs b/Src/Dlhis.Basic/Organization/Request/GainfoFacePageRequest.cs
new file mode 100644
index 00000000..9f9c325d
--- /dev/null
+++ b/Src/Dlhis.Basic/Organization/Request/GainfoFacePageRequest.cs
@@ -0,0 +1,15 @@
+using System.ComponentModel.DataAnnotations;
+using Kurisu.AspNetCore.DataAccess.Dto;
+
+namespace Dlhis.Basic.Organization.Request;
+
+public class GainfoFacePageRequest : PageDto
+{
+ public bool? Exists { get; set; }
+
+ ///
+ /// 厂区
+ ///
+ [Required(ErrorMessage = "厂区不可为空")]
+ public string Factory { get; set; }
+}
\ No newline at end of file
diff --git a/Src/Dlhis.Basic/Organization/Response/GainfoFacePageResponse.cs b/Src/Dlhis.Basic/Organization/Response/GainfoFacePageResponse.cs
new file mode 100644
index 00000000..c105aa40
--- /dev/null
+++ b/Src/Dlhis.Basic/Organization/Response/GainfoFacePageResponse.cs
@@ -0,0 +1,32 @@
+using Kurisu.AspNetCore.DataAccess.Dto;
+
+namespace Dlhis.Basic.Organization.Response;
+
+public class GainfoFacePageSummaryResponse
+{
+ public int Total { get; set; }
+
+ public int Exists { get; set; }
+
+ public int Left => Total - Exists;
+
+ public Pagination Page { get; set; }
+}
+
+public class GainfoFacePageResponse
+{
+ ///
+ /// 工号
+ ///
+ public string UserCode { get; set; }
+
+ ///
+ /// 姓名
+ ///
+ public string UserName { get; set; }
+
+ ///
+ /// 是否存在人脸
+ ///
+ public bool Exists { get; set; }
+}
\ No newline at end of file
diff --git a/Src/Dlhis.Basic/Organization/Services/IGainfoFaceService.cs b/Src/Dlhis.Basic/Organization/Services/IGainfoFaceService.cs
index e4653c21..255fbaa4 100644
--- a/Src/Dlhis.Basic/Organization/Services/IGainfoFaceService.cs
+++ b/Src/Dlhis.Basic/Organization/Services/IGainfoFaceService.cs
@@ -1,10 +1,13 @@
using Dlhis.Basic.Organization.Request;
+using Dlhis.Basic.Organization.Response;
using Microsoft.AspNetCore.Mvc;
namespace Dlhis.Basic.Organization.Services;
public interface IGainfoFaceService : IScopeDependency
{
+ Task GetPageAsync(GainfoFacePageRequest request);
+
Task UploadExternalFaceAsync(GainfoUploadFaceRequest request);
Task GetExternalFaceAsync(string idno);
@@ -18,4 +21,4 @@ public interface IGainfoFaceService : IScopeDependency
Task GetFaceByUserCodeAsync(string userCode);
Task> GetFaceByUserCodesAsync(GetFaceByUserCodesRequest request);
-}
+}
\ No newline at end of file
diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoFaceService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoFaceService.cs
index 0482febb..36d48369 100644
--- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoFaceService.cs
+++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoFaceService.cs
@@ -1,12 +1,13 @@
using Dlhis.Basic.Device.Services;
using Dlhis.Basic.Organization.Request;
+using Dlhis.Basic.Organization.Response;
using Dlhis.Entity.Basic.Entity;
using Dlhis.Entity.Basic.Enums;
using Dlhis.Entity.Device.Enums;
using Kurisu.AspNetCore.Authentication.Abstractions;
using Kurisu.AspNetCore.CustomClass;
+using Kurisu.AspNetCore.DataAccess.Extensions;
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
-using Kurisu.AspNetCore.Utils;
using Kurisu.AspNetCore.Utils.Extensions;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Mvc;
@@ -17,9 +18,9 @@ public class GainfoFaceService : IGainfoFaceService
{
private readonly IGainfoStore _gainfoStore;
private readonly IDbContext _dbContext;
+ private readonly IDbContext _faceDbContext;
private readonly ILogger _logger;
private readonly IConfiguration _configuration;
- private readonly RedisCache _redisCache;
private readonly ICurrentUser _currentUser;
private readonly IDevicePermissionService _devicePermissionService;
private readonly IDataProtectionProvider _dataProtectionProvider;
@@ -28,21 +29,49 @@ public class GainfoFaceService : IGainfoFaceService
IDbContext dbContext,
ILogger logger,
IConfiguration configuration,
- RedisCache redisCache,
ICurrentUser currentUser,
IDevicePermissionService devicePermissionService,
IDataProtectionProvider dataProtectionProvider)
{
_gainfoStore = gainfoStore;
_dbContext = dbContext;
+ _faceDbContext = dbContext.ChangeDb("face");
_logger = logger;
_configuration = configuration;
- _redisCache = redisCache;
_currentUser = currentUser;
_devicePermissionService = devicePermissionService;
_dataProtectionProvider = dataProtectionProvider;
}
+
+ public async Task GetPageAsync(GainfoFacePageRequest request)
+ {
+ var userCodes = await _dbContext.Queryable().Where(x => x.Factory == request.Factory).Select(x => x.Code).ToListAsync();
+ var existsFaceCodes = await _faceDbContext.Queryable().Where(x => userCodes.Contains(x.UserCode)).Select(x => x.UserCode).ToListAsync();
+
+ var list = await _dbContext.Queryable()
+ .Where(x => x.Factory == request.Factory)
+ .WhereIF(request.Exists.HasValue && request.Exists.Value, x => existsFaceCodes.Contains(x.Code))
+ .WhereIF(request.Exists.HasValue && !request.Exists.Value, x => !existsFaceCodes.Contains(x.Code))
+ .Select(x => new GainfoFacePageResponse
+ {
+ UserCode = x.Code,
+ UserName = x.Name,
+ Exists = false
+ })
+ .ToListAsync();
+
+ var page = list.ToPage(request);
+ page.Data.ForEach(x => { x.Exists = existsFaceCodes.Contains(x.UserCode); });
+
+ return new GainfoFacePageSummaryResponse
+ {
+ Total = userCodes.Count,
+ Exists = existsFaceCodes.Count,
+ Page = page
+ };
+ }
+
public async Task UploadExternalFaceAsync(GainfoUploadFaceRequest request)
{
var protector = _dataProtectionProvider.CreateProtector("gainfo:external:idno");
@@ -60,8 +89,7 @@ public class GainfoFaceService : IGainfoFaceService
.FirstAsync();
gainfo.ThrowIfNull("人员信息不存在");
- var faceContext = _dbContext.ChangeDb("face");
- var face = await faceContext.Queryable().Where(x => x.UserCode == gainfo.Code).SingleAsync();
+ var face = await _faceDbContext.Queryable().Where(x => x.UserCode == gainfo.Code).SingleAsync();
if (face == null)
{
@@ -75,7 +103,7 @@ public class GainfoFaceService : IGainfoFaceService
ModifiedBy = 1
};
- await faceContext.InsertAsync(face);
+ await _faceDbContext.InsertAsync(face);
}
else
{
@@ -83,7 +111,7 @@ public class GainfoFaceService : IGainfoFaceService
face.ModifiedBy = 1;
face.ModifiedTime = DateTime.Now;
- await faceContext.UpdateAsync(face);
+ await _faceDbContext.UpdateAsync(face);
}
}
@@ -99,10 +127,9 @@ public class GainfoFaceService : IGainfoFaceService
throw new UserFriendlyException("凭证有误,无法获取人脸数");
}
- var dbContext = _dbContext.ChangeDb("face");
- var face = await dbContext.Queryable()
- .Where(x => x.UserCode == idno)
- .SingleAsync();
+ var face = await _faceDbContext.Queryable()
+ .Where(x => x.UserCode == idno)
+ .SingleAsync();
face.ThrowIfNull("人脸照片尚未录入");
@@ -126,18 +153,10 @@ public class GainfoFaceService : IGainfoFaceService
var password = timeLimitedDataProtector.Unprotect(token);
var userCode = password.Split(':')[1];
- var faceCache = await _redisCache.HashGetAsync("faces", userCode);
- if (faceCache.HasValue)
- {
- return new FileContentResult(Convert.FromBase64String(faceCache), "image/png");
- }
-
- var dbContext = _dbContext.ChangeDb("face");
- var face = await dbContext.Queryable().Where(x => x.UserCode == userCode).SingleAsync();
+ var face = await _faceDbContext.Queryable().Where(x => x.UserCode == userCode).SingleAsync();
if (face == null)
{
- _logger.LogWarning("学工号:{userCode}不存在人脸照片", userCode);
return new NotFoundResult();
}
@@ -157,12 +176,10 @@ public class GainfoFaceService : IGainfoFaceService
var userId = _currentUser.GetIntSubjectId();
- var faceContext = _dbContext.ChangeDb("face");
- var face = await faceContext.Queryable().Where(x => x.UserCode == gainfo.Code).SingleAsync();
+ var face = await _faceDbContext.Queryable().Where(x => x.UserCode == gainfo.Code).SingleAsync();
var taskType = face == null ? DeviceTaskEnumType.Add : DeviceTaskEnumType.Update;
- await _redisCache.HashSetAsync("faces", gainfo.Code, request.Face);
if (face == null)
{
face = new GainfoFaceEntity
@@ -175,7 +192,7 @@ public class GainfoFaceService : IGainfoFaceService
ModifiedBy = userId
};
- await faceContext.InsertAsync(face);
+ await _faceDbContext.InsertAsync(face);
}
else
{
@@ -188,7 +205,7 @@ public class GainfoFaceService : IGainfoFaceService
face.Face = request.Face;
face.ModifiedBy = userId;
face.ModifiedTime = DateTime.Now;
- await faceContext.UpdateAsync(face);
+ await _faceDbContext.UpdateAsync(face);
}
//生成任务
@@ -204,12 +221,10 @@ public class GainfoFaceService : IGainfoFaceService
gainfo.ThrowIfNull("人员档案信息不存在");
- var dbContext = _dbContext.ChangeDb("face");
- var face = await dbContext.Queryable().Where(x => x.UserCode == gainfo.Code).SingleAsync();
+ var face = await _faceDbContext.Queryable().Where(x => x.UserCode == gainfo.Code).SingleAsync();
var taskType = face == null ? DeviceTaskEnumType.Add : DeviceTaskEnumType.Update;
- await _redisCache.HashSetAsync("faces", gainfo.Code, request.Face);
if (face == null)
{
face = new GainfoFaceEntity
@@ -218,7 +233,7 @@ public class GainfoFaceService : IGainfoFaceService
Face = request.Face
};
- await dbContext.InsertAsync(face);
+ await _faceDbContext.InsertAsync(face);
}
else
{
@@ -229,7 +244,7 @@ public class GainfoFaceService : IGainfoFaceService
}
face.Face = request.Face;
- await dbContext.UpdateAsync(face);
+ await _faceDbContext.UpdateAsync(face);
}
//生成任务
@@ -240,13 +255,9 @@ public class GainfoFaceService : IGainfoFaceService
public async Task GetFaceByUserCodeAsync(string userCode)
{
- var gainfo = await _dbContext.Queryable().Where(x => x.Code == userCode).SingleAsync();
- gainfo.ThrowIfNull($"{userCode}人员信息不存在");
-
- var dbContext = _dbContext.ChangeDb("face");
- var face = await dbContext.Queryable()
- .Where(x => x.UserCode == userCode)
- .SingleAsync();
+ var face = await _faceDbContext.Queryable()
+ .Where(x => x.UserCode == userCode)
+ .SingleAsync();
face.ThrowIfNull("人脸照片尚未录入");
@@ -274,8 +285,10 @@ public class GainfoFaceService : IGainfoFaceService
}
catch (Exception)
{
+ //ignore
}
}
+
return faceDictionary;
}
-}
+}
\ No newline at end of file
diff --git a/Src/Dlhis.Basic/Summary/Controllers/SummariesController.cs b/Src/Dlhis.Basic/Summary/Controllers/SummariesController.cs
index 924f8d19..bfb8f69f 100644
--- a/Src/Dlhis.Basic/Summary/Controllers/SummariesController.cs
+++ b/Src/Dlhis.Basic/Summary/Controllers/SummariesController.cs
@@ -46,14 +46,4 @@ public class SummariesController : ControllerBase
{
return await _summaryService.GetDoorDataAsync();
}
-
- ///
- ///
- ///
- ///
- [HttpGet("faceRecordDetail")]
- public async Task