feat 档案人脸分页状态

This commit is contained in:
2024-06-11 12:32:31 +08:00
parent 02e3e5c63b
commit 51b0397763
9 changed files with 140 additions and 71 deletions

View File

@@ -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;
/// <summary>
/// 档案人脸
/// </summary>
[Authorize]
[Route("api/[controller]")]
[ApiController]
public class GainfoFacesController : ControllerBase
{
private readonly IGainfoFaceService _gainfoFaceService;
public GainfoFacesController(IGainfoFaceService gainfoFaceService)
{
_gainfoFaceService = gainfoFaceService;
}
/// <summary>
/// 人脸档案分页
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpPost("page")]
public async Task<GainfoFacePageSummaryResponse> GetPageAsync([FromQuery] GainfoFacePageRequest request)
{
return await _gainfoFaceService.GetPageAsync(request);
}
}

View File

@@ -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; }
/// <summary>
/// 厂区
/// </summary>
[Required(ErrorMessage = "厂区不可为空")]
public string Factory { get; set; }
}

View File

@@ -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<GainfoFacePageResponse> Page { get; set; }
}
public class GainfoFacePageResponse
{
/// <summary>
/// 工号
/// </summary>
public string UserCode { get; set; }
/// <summary>
/// 姓名
/// </summary>
public string UserName { get; set; }
/// <summary>
/// 是否存在人脸
/// </summary>
public bool Exists { get; set; }
}

View File

@@ -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<GainfoFacePageSummaryResponse> GetPageAsync(GainfoFacePageRequest request);
Task UploadExternalFaceAsync(GainfoUploadFaceRequest request);
Task<string> GetExternalFaceAsync(string idno);
@@ -18,4 +21,4 @@ public interface IGainfoFaceService : IScopeDependency
Task<string> GetFaceByUserCodeAsync(string userCode);
Task<Dictionary<string, string>> GetFaceByUserCodesAsync(GetFaceByUserCodesRequest request);
}
}

View File

@@ -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<GainfoFaceService> _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<GainfoFaceService> 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<GainfoFacePageSummaryResponse> GetPageAsync(GainfoFacePageRequest request)
{
var userCodes = await _dbContext.Queryable<GainfoEntity>().Where(x => x.Factory == request.Factory).Select(x => x.Code).ToListAsync();
var existsFaceCodes = await _faceDbContext.Queryable<GainfoFaceEntity>().Where(x => userCodes.Contains(x.UserCode)).Select(x => x.UserCode).ToListAsync();
var list = await _dbContext.Queryable<GainfoEntity>()
.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<GainfoFaceEntity>().Where(x => x.UserCode == gainfo.Code).SingleAsync();
var face = await _faceDbContext.Queryable<GainfoFaceEntity>().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<GainfoFaceEntity>()
.Where(x => x.UserCode == idno)
.SingleAsync();
var face = await _faceDbContext.Queryable<GainfoFaceEntity>()
.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<GainfoFaceEntity>().Where(x => x.UserCode == userCode).SingleAsync();
var face = await _faceDbContext.Queryable<GainfoFaceEntity>().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<GainfoFaceEntity>().Where(x => x.UserCode == gainfo.Code).SingleAsync();
var face = await _faceDbContext.Queryable<GainfoFaceEntity>().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<GainfoFaceEntity>().Where(x => x.UserCode == gainfo.Code).SingleAsync();
var face = await _faceDbContext.Queryable<GainfoFaceEntity>().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<string> GetFaceByUserCodeAsync(string userCode)
{
var gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.Code == userCode).SingleAsync();
gainfo.ThrowIfNull($"{userCode}人员信息不存在");
var dbContext = _dbContext.ChangeDb("face");
var face = await dbContext.Queryable<GainfoFaceEntity>()
.Where(x => x.UserCode == userCode)
.SingleAsync();
var face = await _faceDbContext.Queryable<GainfoFaceEntity>()
.Where(x => x.UserCode == userCode)
.SingleAsync();
face.ThrowIfNull("人脸照片尚未录入");
@@ -274,8 +285,10 @@ public class GainfoFaceService : IGainfoFaceService
}
catch (Exception)
{
//ignore
}
}
return faceDictionary;
}
}
}

View File

@@ -46,14 +46,4 @@ public class SummariesController : ControllerBase
{
return await _summaryService.GetDoorDataAsync();
}
/// <summary>
///
/// </summary>
/// <returns></returns>
[HttpGet("faceRecordDetail")]
public async Task<object> GetCurrentFactoryFaceDetailAsync()
{
return await _summaryService.GetCurrentFactoryFaceDetailAsync();
}
}

View File

@@ -9,6 +9,4 @@ public interface ISummaryService : IScopeDependency
Task<DoorHomeDataResponse> GetDoorHomeDataAsync();
Task<DoorDataResponse> GetDoorDataAsync();
Task<object> GetCurrentFactoryFaceDetailAsync();
}

View File

@@ -13,7 +13,6 @@ namespace Dlhis.Basic.Summary.Services.Implements;
public class SummaryService : ISummaryService
{
private readonly IDbContext _dbContext;
private readonly IDbContext _faceDbContext;
private readonly IGainfoStore _gainfoStore;
private readonly ICurrentUser _currentUser;
@@ -22,8 +21,6 @@ public class SummaryService : ISummaryService
_dbContext = dbContext;
_gainfoStore = gainfoStore;
_currentUser = currentUser;
_faceDbContext = dbContext.ChangeDb("face");
}
public async Task<AttendanceSummaryResponse> GetAttendanceSummaryAsync()
@@ -152,20 +149,6 @@ public class SummaryService : ISummaryService
};
}
/// <inheritdoc />
public async Task<object> GetCurrentFactoryFaceDetailAsync()
{
var currentTenantId = _currentUser.GetStringTenantId();
var userCodes = await _dbContext.Queryable<GainfoEntity>().Where(x => x.Factory == currentTenantId).Select(x => x.Code).ToListAsync();
var total = userCodes.Count;
var exists = await _faceDbContext.Queryable<GainfoFaceEntity>().Where(x => userCodes.Contains(x.UserCode)).CountAsync();
return new
{
total, exists
};
}
private static List<TrendDto> FixTrend(IEnumerable<TrendDto> dtos, DateTime start, DateTime end)
{
var result = dtos.ToList();

View File

@@ -14,7 +14,7 @@ public class JinkoSapService : IJinkoSapService
private readonly IDbContext _dbContext;
private readonly IHttpClientFactory _httpClientFactory;
public JinkoSapService(IHttpClientFactory httpClientFactory, ILogger<JinkoSapService> logger, IDbContext dbContext)
public JinkoSapService(IHttpClientFactory httpClientFactory, IDbContext dbContext)
{
_dbContext = dbContext;
_httpClientFactory = httpClientFactory;
@@ -26,7 +26,7 @@ public class JinkoSapService : IJinkoSapService
httpClient.BaseAddress = new Uri("http://sappipap01.jinkosolar.cn:50100");
httpClient.Timeout = TimeSpan.FromMinutes(10);
var credentials = $"{"EHS_USER"}:{"y3R1hd2h*RICAC"}";
const string credentials = $"{"EHS_USER"}:{"y3R1hd2h*RICAC"}";
var headerValue = Convert.ToBase64String(Encoding.UTF8.GetBytes(credentials));
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", headerValue);