fix 优化获取face速度
This commit is contained in:
@@ -4,6 +4,8 @@
|
|||||||
{
|
{
|
||||||
public Guid ShiftCode { get; set; }
|
public Guid ShiftCode { get; set; }
|
||||||
|
|
||||||
|
public string ShiftType { get; set; }
|
||||||
|
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
public TimeOnly Start { get; set; }
|
public TimeOnly Start { get; set; }
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ public class BusinessPlaceShiftService : IBusinessPlaceShiftService
|
|||||||
.Select((x, bt) => new MealShiftResponse
|
.Select((x, bt) => new MealShiftResponse
|
||||||
{
|
{
|
||||||
ShiftCode = x.ShiftCode,
|
ShiftCode = x.ShiftCode,
|
||||||
|
ShiftType = bt.Code,
|
||||||
Name = bt.Display,
|
Name = bt.Display,
|
||||||
Start = x.Start,
|
Start = x.Start,
|
||||||
End = x.End,
|
End = x.End,
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ using Kurisu.AspNetCore.Scope;
|
|||||||
using Kurisu.AspNetCore.UnifyResultAndValidation;
|
using Kurisu.AspNetCore.UnifyResultAndValidation;
|
||||||
using Kurisu.AspNetCore.Utils.Extensions;
|
using Kurisu.AspNetCore.Utils.Extensions;
|
||||||
using Kurisu.Core.DataAccess.Dto;
|
using Kurisu.Core.DataAccess.Dto;
|
||||||
using Kurisu.SqlSugar.Attributes;
|
|
||||||
using Kurisu.SqlSugar.Extensions;
|
using Kurisu.SqlSugar.Extensions;
|
||||||
using Kurisu.SqlSugar.Services;
|
using Kurisu.SqlSugar.Services;
|
||||||
using Mapster;
|
using Mapster;
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ using Dlhis.Entity.Basic.Enums;
|
|||||||
using Dlhis.Entity.Device.Enums;
|
using Dlhis.Entity.Device.Enums;
|
||||||
using Kurisu.AspNetCore.Scope;
|
using Kurisu.AspNetCore.Scope;
|
||||||
using Kurisu.AspNetCore.UnifyResultAndValidation;
|
using Kurisu.AspNetCore.UnifyResultAndValidation;
|
||||||
|
using Kurisu.AspNetCore.Utils;
|
||||||
using Kurisu.AspNetCore.Utils.Extensions;
|
using Kurisu.AspNetCore.Utils.Extensions;
|
||||||
using Kurisu.Core.DataAccess.Dto;
|
using Kurisu.Core.DataAccess.Dto;
|
||||||
using Kurisu.Core.User.Abstractions;
|
using Kurisu.Core.User.Abstractions;
|
||||||
using Kurisu.SqlSugar.Attributes;
|
|
||||||
using Kurisu.SqlSugar.Extensions;
|
using Kurisu.SqlSugar.Extensions;
|
||||||
using Kurisu.SqlSugar.Options;
|
using Kurisu.SqlSugar.Options;
|
||||||
using Kurisu.SqlSugar.Services;
|
using Kurisu.SqlSugar.Services;
|
||||||
@@ -26,18 +26,21 @@ public class GainfoService : IGainfoService
|
|||||||
private readonly IDbContext _dbContext;
|
private readonly IDbContext _dbContext;
|
||||||
private readonly ICurrentUser _currentUser;
|
private readonly ICurrentUser _currentUser;
|
||||||
private readonly IDevicePermissionService _devicePermissionService;
|
private readonly IDevicePermissionService _devicePermissionService;
|
||||||
|
private readonly RedisCache _redisCache;
|
||||||
private readonly ILogger<GainfoService> _logger;
|
private readonly ILogger<GainfoService> _logger;
|
||||||
|
|
||||||
public GainfoService(IGainfoStore gainfoStore,
|
public GainfoService(IGainfoStore gainfoStore,
|
||||||
IDbContext dbContext,
|
IDbContext dbContext,
|
||||||
ICurrentUser currentUser,
|
ICurrentUser currentUser,
|
||||||
IDevicePermissionService devicePermissionService,
|
IDevicePermissionService devicePermissionService,
|
||||||
|
RedisCache redisCache,
|
||||||
ILogger<GainfoService> logger)
|
ILogger<GainfoService> logger)
|
||||||
{
|
{
|
||||||
_gainfoStore = gainfoStore;
|
_gainfoStore = gainfoStore;
|
||||||
_dbContext = dbContext;
|
_dbContext = dbContext;
|
||||||
_currentUser = currentUser;
|
_currentUser = currentUser;
|
||||||
_devicePermissionService = devicePermissionService;
|
_devicePermissionService = devicePermissionService;
|
||||||
|
_redisCache = redisCache;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,6 +179,12 @@ public class GainfoService : IGainfoService
|
|||||||
var password = timeLimitedDataProtector.Unprotect(token);
|
var password = timeLimitedDataProtector.Unprotect(token);
|
||||||
var userCode = password.Split(':')[1];
|
var userCode = password.Split(':')[1];
|
||||||
|
|
||||||
|
var faceCache = await _redisCache.HashGetAsync("faces", userCode);
|
||||||
|
if (faceCache.HasValue)
|
||||||
|
{
|
||||||
|
return new FileContentResult(Convert.FromBase64String(faceCache), "image/png");
|
||||||
|
}
|
||||||
|
|
||||||
var configuration = sp.GetService<IConfiguration>();
|
var configuration = sp.GetService<IConfiguration>();
|
||||||
var faceConnectionString = configuration.GetSection("SqlSugarOptions:FaceConnectionString").Value;
|
var faceConnectionString = configuration.GetSection("SqlSugarOptions:FaceConnectionString").Value;
|
||||||
if (faceConnectionString.IsEmpty())
|
if (faceConnectionString.IsEmpty())
|
||||||
@@ -195,6 +204,8 @@ public class GainfoService : IGainfoService
|
|||||||
return new NotFoundResult();
|
return new NotFoundResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var limit = configuration.GetSection("FaceUrlOptions:Limit").Get<int>();
|
||||||
|
await _redisCache.HashSetAsync("faces", userCode, face.Face);
|
||||||
return new FileContentResult(Convert.FromBase64String(face.Face), "image/png");
|
return new FileContentResult(Convert.FromBase64String(face.Face), "image/png");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -227,6 +238,8 @@ public class GainfoService : IGainfoService
|
|||||||
var face = await dbContext.Queryable<GainfoFaceEntity>().Where(x => x.UserCode == gainfo.Code).SingleAsync();
|
var face = await dbContext.Queryable<GainfoFaceEntity>().Where(x => x.UserCode == gainfo.Code).SingleAsync();
|
||||||
|
|
||||||
var taskType = face == null ? DeviceTaskEnumType.Add : DeviceTaskEnumType.Update;
|
var taskType = face == null ? DeviceTaskEnumType.Add : DeviceTaskEnumType.Update;
|
||||||
|
|
||||||
|
await _redisCache.HashSetAsync("faces", gainfo.Code, request.Face);
|
||||||
if (face == null)
|
if (face == null)
|
||||||
{
|
{
|
||||||
face = new GainfoFaceEntity
|
face = new GainfoFaceEntity
|
||||||
@@ -274,6 +287,8 @@ public class GainfoService : IGainfoService
|
|||||||
var face = await dbContext.Queryable<GainfoFaceEntity>().Where(x => x.UserCode == gainfo.Code).SingleAsync();
|
var face = await dbContext.Queryable<GainfoFaceEntity>().Where(x => x.UserCode == gainfo.Code).SingleAsync();
|
||||||
|
|
||||||
var taskType = face == null ? DeviceTaskEnumType.Add : DeviceTaskEnumType.Update;
|
var taskType = face == null ? DeviceTaskEnumType.Add : DeviceTaskEnumType.Update;
|
||||||
|
|
||||||
|
await _redisCache.HashSetAsync("faces", gainfo.Code, request.Face);
|
||||||
if (face == null)
|
if (face == null)
|
||||||
{
|
{
|
||||||
face = new GainfoFaceEntity
|
face = new GainfoFaceEntity
|
||||||
@@ -302,8 +317,6 @@ public class GainfoService : IGainfoService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public async Task<string> GetFaceByUserCodeAsync(string userCode)
|
public async Task<string> GetFaceByUserCodeAsync(string userCode)
|
||||||
{
|
{
|
||||||
var gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.Code == userCode).SingleAsync();
|
var gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.Code == userCode).SingleAsync();
|
||||||
|
|||||||
19
Src/Dlhis.Basic/Packs/DataProtectionJob.cs
Normal file
19
Src/Dlhis.Basic/Packs/DataProtectionJob.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
using Kurisu.AspNetCore.Startup;
|
||||||
|
using Kurisu.AspNetCore.Utils;
|
||||||
|
using Microsoft.AspNetCore.DataProtection;
|
||||||
|
using StackExchange.Redis;
|
||||||
|
|
||||||
|
namespace Dlhis.Basic.Packs;
|
||||||
|
|
||||||
|
public class DataProtectionJobPack : BaseAppPack
|
||||||
|
{
|
||||||
|
public override bool IsBeforeUseRouting { get; }
|
||||||
|
|
||||||
|
public override void ConfigureServices(IServiceCollection services)
|
||||||
|
{
|
||||||
|
var redisConnection = ConnectionMultiplexer.Connect(Configuration.GetSection($"{nameof(RedisOptions)}:{nameof(RedisOptions.ConnectionString)}").Value);
|
||||||
|
services.AddDataProtection()
|
||||||
|
.SetApplicationName("basic")
|
||||||
|
.PersistKeysToStackExchangeRedis(redisConnection, "DataProtection-Keys");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
using Kurisu.AspNetCore.Startup;
|
using Kurisu.AspNetCore.Startup;
|
||||||
|
using Kurisu.AspNetCore.Utils.Extensions;
|
||||||
using Kurisu.Startup;
|
using Kurisu.Startup;
|
||||||
using Microsoft.AspNetCore.DataProtection;
|
|
||||||
using Microsoft.IdentityModel.Logging;
|
using Microsoft.IdentityModel.Logging;
|
||||||
using StackExchange.Redis;
|
|
||||||
|
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
@@ -22,11 +21,6 @@ public class Startup : DefaultStartup
|
|||||||
public override void ConfigureServices(IServiceCollection services)
|
public override void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
base.ConfigureServices(services);
|
base.ConfigureServices(services);
|
||||||
|
services.AddRedis();
|
||||||
//todo
|
|
||||||
var redis = ConnectionMultiplexer.Connect($"192.168.199.30:30115,defaultDatabase:1,password=dlhis123");
|
|
||||||
services.AddDataProtection()
|
|
||||||
.SetApplicationName("basic")
|
|
||||||
.PersistKeysToStackExchangeRedis(redis, "DataProtection-Keys");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -34,6 +34,9 @@
|
|||||||
"yikatong": "yikatong"
|
"yikatong": "yikatong"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"RedisOptions": {
|
||||||
|
"ConnectionString": "192.168.199.30:30115,defaultDatabase:1,password=dlhis123"
|
||||||
|
},
|
||||||
"IdentityServerOptions": {
|
"IdentityServerOptions": {
|
||||||
"Authority": "http://identity.oauth.svc.cluster.local",
|
"Authority": "http://identity.oauth.svc.cluster.local",
|
||||||
"RequireHttpsMetadata": false,
|
"RequireHttpsMetadata": false,
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ public class BalancesController : ControllerBase
|
|||||||
/// <param name="request"></param>
|
/// <param name="request"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost("obsoluteOutRecord")]
|
[HttpPost("obsoluteOutRecord")]
|
||||||
|
[Transactional]
|
||||||
public async Task ObsoluteAsync(BalanceRecordObsoluteRequest request)
|
public async Task ObsoluteAsync(BalanceRecordObsoluteRequest request)
|
||||||
{
|
{
|
||||||
await _balanceService.ObsoluteAsync(request);
|
await _balanceService.ObsoluteAsync(request);
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ public class OrdersController : ControllerBase
|
|||||||
/// <param name="request"></param>
|
/// <param name="request"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
|
[IgnoreTenant]
|
||||||
public async Task<OrderResultResponse> AddAsync(OrderAddRequest request)
|
public async Task<OrderResultResponse> AddAsync(OrderAddRequest request)
|
||||||
{
|
{
|
||||||
return await _orderService.AddAsync(request);
|
return await _orderService.AddAsync(request);
|
||||||
|
|||||||
@@ -516,7 +516,6 @@ public class BalanceService : IBalanceService
|
|||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Transactional]
|
|
||||||
public async Task ObsoluteAsync(BalanceRecordObsoluteRequest request)
|
public async Task ObsoluteAsync(BalanceRecordObsoluteRequest request)
|
||||||
{
|
{
|
||||||
var balanceRecord = await _dbContext.Queryable<BalanceRecordEntity>().Where(x => x.Id == request.Id).SingleAsync();
|
var balanceRecord = await _dbContext.Queryable<BalanceRecordEntity>().Where(x => x.Id == request.Id).SingleAsync();
|
||||||
@@ -731,10 +730,8 @@ public class BalanceService : IBalanceService
|
|||||||
throw new UserFriendlyException("操作失败,请重试");
|
throw new UserFriendlyException("操作失败,请重试");
|
||||||
}
|
}
|
||||||
|
|
||||||
[IgnoreTenant]
|
|
||||||
public async Task<Dictionary<string, string>> GetShiftCode()
|
public async Task<Dictionary<string, string>> GetShiftCode()
|
||||||
{
|
{
|
||||||
|
|
||||||
_dbContext.Client.QueryFilter.ClearAndBackup<ITenantId>();
|
_dbContext.Client.QueryFilter.ClearAndBackup<ITenantId>();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ using Kurisu.AspNetCore.Utils;
|
|||||||
using Kurisu.AspNetCore.Utils.Extensions;
|
using Kurisu.AspNetCore.Utils.Extensions;
|
||||||
using Kurisu.Core.CustomClass;
|
using Kurisu.Core.CustomClass;
|
||||||
using Kurisu.Core.DataAccess.Dto;
|
using Kurisu.Core.DataAccess.Dto;
|
||||||
using Kurisu.SqlSugar.Attributes;
|
|
||||||
using Kurisu.SqlSugar.Extensions;
|
using Kurisu.SqlSugar.Extensions;
|
||||||
using Kurisu.SqlSugar.Services;
|
using Kurisu.SqlSugar.Services;
|
||||||
using Mapster;
|
using Mapster;
|
||||||
@@ -54,35 +53,15 @@ public class OrderService : IOrderService
|
|||||||
uniqueNos.Contains(deviceUniqueNo).ThrowIfFalse("无消费权限");
|
uniqueNos.Contains(deviceUniqueNo).ThrowIfFalse("无消费权限");
|
||||||
}
|
}
|
||||||
|
|
||||||
[IgnoreTenant]
|
|
||||||
public async Task<OrderResultResponse> AddAsync(OrderAddRequest request)
|
public async Task<OrderResultResponse> AddAsync(OrderAddRequest request)
|
||||||
{
|
{
|
||||||
var card = string.Empty;
|
//尝试匹配userId
|
||||||
long userId = 0;
|
_ = long.TryParse(request.UserUniqueNo, out var userId);
|
||||||
if (request.Source == BalanceRecordSourceEnumType.Card)
|
|
||||||
{
|
//根据档案号
|
||||||
card = request.UserUniqueNo;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_ = long.TryParse(request.UserUniqueNo, out userId);
|
|
||||||
}
|
|
||||||
var gainfo = await _dbContext.Queryable<GainfoEntity>()
|
var gainfo = await _dbContext.Queryable<GainfoEntity>()
|
||||||
.Where(x => x.No == request.UserUniqueNo || x.Code == request.UserUniqueNo || x.Id == userId || x.CardNo == card)
|
.Where(x => x.No == request.UserUniqueNo || x.Code == request.UserUniqueNo || x.Id == userId || x.CardNo == request.UserUniqueNo)
|
||||||
.FirstAsync();
|
.FirstAsync();
|
||||||
|
|
||||||
|
|
||||||
// ....
|
|
||||||
{
|
|
||||||
////尝试匹配userId
|
|
||||||
//_ = long.TryParse(request.UserUniqueNo, out var userId);
|
|
||||||
|
|
||||||
////根据档案号
|
|
||||||
//var gainfo = await _dbContext.Queryable<GainfoEntity>()
|
|
||||||
// .Where(x => x.No == request.UserUniqueNo || x.Code == request.UserUniqueNo || x.Id == userId)
|
|
||||||
// .FirstAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
gainfo.ThrowIfNull($"用户{request.UserUniqueNo}不存在,无法操作");
|
gainfo.ThrowIfNull($"用户{request.UserUniqueNo}不存在,无法操作");
|
||||||
|
|
||||||
|
|||||||
@@ -7,14 +7,6 @@
|
|||||||
},
|
},
|
||||||
"dotnetRunMessages": true,
|
"dotnetRunMessages": true,
|
||||||
"applicationUrl": "http://localhost:5008"
|
"applicationUrl": "http://localhost:5008"
|
||||||
},
|
|
||||||
"Docker": {
|
|
||||||
"commandName": "Docker",
|
|
||||||
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
|
|
||||||
"environmentVariables": {
|
|
||||||
"ASPNETCORE_URLS": "http://+:80"
|
|
||||||
},
|
|
||||||
"publishAllPorts": true
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"$schema": "https://json.schemastore.org/launchsettings.json"
|
"$schema": "https://json.schemastore.org/launchsettings.json"
|
||||||
|
|||||||
19
Src/Dlhis.ScheduledTask/Packs/DataProtectionJob.cs
Normal file
19
Src/Dlhis.ScheduledTask/Packs/DataProtectionJob.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
using Kurisu.AspNetCore.Startup;
|
||||||
|
using Kurisu.AspNetCore.Utils;
|
||||||
|
using Microsoft.AspNetCore.DataProtection;
|
||||||
|
using StackExchange.Redis;
|
||||||
|
|
||||||
|
namespace Dlhis.ScheduledTask.Packs;
|
||||||
|
|
||||||
|
public class DataProtectionJobPack : BaseAppPack
|
||||||
|
{
|
||||||
|
public override bool IsBeforeUseRouting { get; }
|
||||||
|
|
||||||
|
public override void ConfigureServices(IServiceCollection services)
|
||||||
|
{
|
||||||
|
var redisConnection = ConnectionMultiplexer.Connect(Configuration.GetSection($"{nameof(RedisOptions)}:{nameof(RedisOptions.ConnectionString)}").Value);
|
||||||
|
services.AddDataProtection()
|
||||||
|
.SetApplicationName("scheduled")
|
||||||
|
.PersistKeysToStackExchangeRedis(redisConnection, "DataProtection-Keys");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,8 @@
|
|||||||
using System.Net.NetworkInformation;
|
|
||||||
using Kurisu.AspNetCore.Startup;
|
using Kurisu.AspNetCore.Startup;
|
||||||
|
using Kurisu.AspNetCore.Utils.Extensions;
|
||||||
using Kurisu.Startup;
|
using Kurisu.Startup;
|
||||||
using Microsoft.AspNetCore.DataProtection;
|
using Microsoft.AspNetCore.DataProtection;
|
||||||
using Microsoft.Extensions.Options;
|
|
||||||
using StackExchange.Redis;
|
using StackExchange.Redis;
|
||||||
using static StackExchange.Redis.Role;
|
|
||||||
|
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
@@ -23,16 +21,12 @@ public class Startup : DefaultStartup
|
|||||||
public override void ConfigureServices(IServiceCollection services)
|
public override void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
base.ConfigureServices(services);
|
base.ConfigureServices(services);
|
||||||
|
services.AddRedis();
|
||||||
services.AddSingleton<IConnectionMultiplexer>(sp =>
|
|
||||||
{
|
|
||||||
return ConnectionMultiplexer.Connect("192.168.199.30:30115,defaultDatabase:1,password=dlhis123");
|
|
||||||
});
|
|
||||||
|
|
||||||
//todo
|
//todo
|
||||||
var redis = ConnectionMultiplexer.Connect($"192.168.199.30:30115,defaultDatabase:1,password=dlhis123");
|
var redis = ConnectionMultiplexer.Connect($"192.168.199.30:30115,defaultDatabase:1,password=dlhis123");
|
||||||
services.AddDataProtection()
|
services.AddDataProtection()
|
||||||
.SetApplicationName("basic")
|
.SetApplicationName("scheduled")
|
||||||
.PersistKeysToStackExchangeRedis(redis, "DataProtection-Keys");
|
.PersistKeysToStackExchangeRedis(redis, "DataProtection-Keys");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -54,6 +54,9 @@
|
|||||||
"AttendanceUploadInterval": "30",
|
"AttendanceUploadInterval": "30",
|
||||||
"BeginSyncDate": "2020-5-1"
|
"BeginSyncDate": "2020-5-1"
|
||||||
},
|
},
|
||||||
|
"RedisOptions": {
|
||||||
|
"ConnectionString": "192.168.199.30:30115,defaultDatabase:1,password=dlhis123"
|
||||||
|
},
|
||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
"Serilog": {
|
"Serilog": {
|
||||||
"MinimumLevel": {
|
"MinimumLevel": {
|
||||||
|
|||||||
Reference in New Issue
Block a user